File indexing completed on 2024-04-06 12:23:14
0001 #define MELaserPrim_cxx
0002 #include "MELaserPrim.hh"
0003 #include <cassert>
0004 #include <cstdlib>
0005
0006 TString MELaserPrim::apdpn_arrayName[MELaserPrim::iSizeArray_apdpn] = {"APD", "APDoPN", "APDoPNA", "APDoPNB" };
0007 TString MELaserPrim::apdpn_varName[MELaserPrim::iSize_apdpn] = { "Mean", "RMS", "Min", "Max", "Nevt" };
0008 TString MELaserPrim::apdpn_varUnit[MELaserPrim::iSizeArray_apdpn][MELaserPrim::iSize_apdpn] =
0009 { { " (ADC Counts)", " (ADC Counts)", " (ADC Counts)", " (ADC Counts)", "" },
0010 {"", "", "", "", ""},
0011 {"", "", "", "", ""},
0012 {"", "", "", "", ""} };
0013 TString MELaserPrim::apdpn_extraVarName[MELaserPrim::iSizeExtra_apdpn] = { "ShapeCor" };
0014 TString MELaserPrim::apdpn_extraVarUnit[MELaserPrim::iSizeExtra_apdpn] = { "" };
0015 TString MELaserPrim::ab_varName[MELaserPrim::iSize_ab] = { "alpha", "beta", "width", "chi2" };
0016 TString MELaserPrim::mtq_varName[MELaserPrim::iSize_mtq] = {"peak", "sigma", "fit", "ampl", "trise", "fwhm", "fw20", "fw80" };
0017 TString MELaserPrim::mtq_varUnit[MELaserPrim::iSize_mtq] =
0018 {"(nanoseconds)", "(nanoseconds)", "(nanoseconds)",
0019 "(ADC counts)", "(nanoseconds)",
0020 "(nanoseconds)", "(nanoseconds)", "(nanoseconds)" };
0021 TString MELaserPrim::separator = "__";
0022
0023 MELaserPrim::MELaserPrim( int dcc, int side, int color, int run, int ts,
0024 const char* inpath, const char* outpath )
0025 : _dcc(dcc), _side(side), _color(color), _run(run), _ts(ts), _inpath(inpath), _outpath(outpath)
0026 {
0027 apdpn_file =0;
0028 ab_file =0;
0029 pn_file =0;
0030 mtq_file =0;
0031 apdpn_tree =0;
0032 ab_tree =0;
0033 pn_tree =0;
0034 mtq_tree =0;
0035 ixmin =0;
0036 ixmax =0;
0037 iymin =0;
0038 iymax =0;
0039
0040 if( _dcc>600 ) _dcc-=600;
0041 assert( _dcc>0 && _dcc<55 );
0042
0043 _primStr = lmfLaserName( iLmfLaserPrim, _color )+separator;
0044 _pnPrimStr = lmfLaserName( iLmfLaserPnPrim, _color )+separator;
0045 _pulseStr = lmfLaserName( iLmfLaserPulse, _color )+separator;
0046
0047 if( _dcc>=10 && _dcc<=45 )
0048 {
0049 _detStr = "EB";
0050 _sm = _dcc-9;
0051 if( _sm<19 ) _detStr += "+";
0052 else _detStr += "-";
0053
0054 _sectorStr = _detStr;
0055 _sectorStr += "SM";
0056 if( _sm<10 ) _sectorStr += "0";
0057 _sectorStr += _sm;
0058
0059 }
0060 else
0061 {
0062 if( _dcc<10 )
0063 {
0064 _detStr = "EE-";
0065 _sm = _dcc+6;
0066 }
0067 else if( _dcc>45 )
0068 {
0069 _detStr = "EE+";
0070 _sm = _dcc-45+6;
0071 }
0072 if( _sm>9 ) _sm -= 9;
0073
0074 _sectorStr = _detStr;
0075 _sectorStr += "S";
0076 _sectorStr += _sm;
0077
0078
0079 if( _sm!=5 ) _side=0;
0080 }
0081 _regionStr = _sectorStr;
0082 _regionStr += "-"; _regionStr += _side;
0083
0084
0085
0086
0087
0088 }
0089
0090 void
0091 MELaserPrim::init()
0092 {
0093
0094 TString cur(_inpath);
0095 if( !cur.EndsWith("/") ) cur+="/";
0096
0097 TString _APDPN_fname =cur; _APDPN_fname+="APDPNLaser_Run"; _APDPN_fname+=_run; _APDPN_fname+=".root";
0098 TString _AB_fname =cur; _AB_fname+="AB-PerCrys-Run"; _AB_fname+=_run; _AB_fname+=".root";
0099 TString _MTQ_fname =cur; _MTQ_fname+="Matacq-Run"; _MTQ_fname+=_run; _MTQ_fname+=".root";
0100
0101 apdpn_file = TFile::Open( _APDPN_fname );
0102 ab_file = TFile::Open( _AB_fname );
0103 pn_file = apdpn_file;
0104 mtq_file = TFile::Open( _MTQ_fname );
0105
0106 TString apdpn_tree_name;
0107 TString ab_tree_name;
0108 TString pn_tree_name;
0109 TString mtq_tree_name = "MatacqShape";
0110
0111 switch ( _color )
0112 {
0113 case iIRed:
0114 apdpn_tree_name = "Red";
0115 ab_tree_name = "Red";
0116 pn_tree_name = "RedPN";
0117 break;
0118 case iBlue:
0119 apdpn_tree_name = "Blue";
0120 ab_tree_name = "Blue";
0121 pn_tree_name = "BluePN";
0122 break;
0123 default:
0124 cout << "MELaserPrim::init() -- Fatal Error -- Wrong Laser Color : " << _color << " ---- Abort " << endl;
0125 abort();
0126 }
0127
0128 apdpn_tree = (TTree*) apdpn_file->Get(apdpn_tree_name);
0129 assert( apdpn_tree!=0 );
0130 apdpn_tree->SetMakeClass(1);
0131 apdpn_tree->SetBranchAddress("dccID", &apdpn_dccID, &b_apdpn_dccID);
0132 apdpn_tree->SetBranchAddress("towerID", &apdpn_towerID, &b_apdpn_towerID);
0133 apdpn_tree->SetBranchAddress("channelID", &apdpn_channelID, &b_apdpn_channelID);
0134 apdpn_tree->SetBranchAddress("moduleID", &apdpn_moduleID, &b_apdpn_moduleID);
0135 apdpn_tree->SetBranchAddress("gainID", &apdpn_gainID, &b_apdpn_gainID);
0136 apdpn_tree->SetBranchAddress("ieta", &apdpn_ieta, &b_apdpn_ieta);
0137 apdpn_tree->SetBranchAddress("iphi", &apdpn_iphi, &b_apdpn_iphi);
0138 apdpn_tree->SetBranchAddress("flag", &apdpn_flag, &b_apdpn_flag);
0139 apdpn_tree->SetBranchAddress("ShapeCor", &apdpn_ShapeCor, &b_apdpn_ShapeCor);
0140 for( int jj=0; jj<iSizeArray_apdpn; jj++ )
0141 {
0142
0143 TString name_ = apdpn_arrayName[jj];
0144 name_.ReplaceAll("PNA","PN0");
0145 name_.ReplaceAll("PNB","PN1");
0146
0147 apdpn_tree->SetBranchAddress(name_, apdpn_apdpn[jj], &b_apdpn_apdpn[jj]);
0148 }
0149
0150 ab_tree = (TTree*) ab_file->Get(ab_tree_name);
0151 assert( ab_tree!=0 );
0152 ab_tree->SetMakeClass(1);
0153 ab_tree->SetBranchAddress("dccID", &ab_dccID, &b_ab_dccID );
0154 ab_tree->SetBranchAddress("towerID", &ab_towerID, &b_ab_towerID );
0155 ab_tree->SetBranchAddress("channelID", &ab_channelID, &b_ab_channelID );
0156 ab_tree->SetBranchAddress("ieta", &ab_ieta, &b_ab_ieta );
0157 ab_tree->SetBranchAddress("iphi", &ab_iphi, &b_ab_iphi );
0158 ab_tree->SetBranchAddress("flag", &ab_flag, &b_ab_flag );
0159 for( int ii=0; ii<iSize_ab; ii++ )
0160 {
0161 ab_tree->SetBranchAddress( ab_varName[ii], &ab_ab[ii], &b_ab_ab[ii] );
0162 }
0163
0164 pn_tree = (TTree*) pn_file->Get(pn_tree_name);
0165 assert( pn_tree!=0 );
0166 pn_tree->SetMakeClass(1);
0167 pn_tree->SetBranchAddress( "pnID", &pn_pnID, &b_pn_pnID );
0168 pn_tree->SetBranchAddress( "moduleID", &pn_moduleID, &b_pn_moduleID );
0169 pn_tree->SetBranchAddress( "PN", pn_PN, &b_pn_PN );
0170 pn_tree->SetBranchAddress( "PNoPN", pn_PNoPN, &b_pn_PNoPN );
0171 pn_tree->SetBranchAddress( "PNoPN0", pn_PNoPNA, &b_pn_PNoPNA );
0172 pn_tree->SetBranchAddress( "PNoPN1", pn_PNoPNB, &b_pn_PNoPNB );
0173
0174 mtq_tree = (TTree*) mtq_file->Get(mtq_tree_name);
0175 assert( mtq_tree!=0 );
0176 mtq_tree->SetMakeClass(1);
0177 mtq_tree->SetBranchAddress("event", &mtq_event, &b_mtq_event );
0178 mtq_tree->SetBranchAddress("laser_color", &mtq_laser_color, &b_mtq_laser_color );
0179 mtq_tree->SetBranchAddress("status", &mtq_status, &b_mtq_status );
0180 for( int ii=0; ii<iSize_mtq; ii++ )
0181 {
0182 mtq_tree->SetBranchAddress( mtq_varName[ii], &mtq_mtq[ii], &b_mtq_mtq[ii] );
0183 }
0184 }
0185
0186 void
0187 MELaserPrim::bookHistograms()
0188 {
0189 refresh();
0190
0191 TString i_name, d_name;
0192
0193 if( _detStr.Contains( "EB" ) )
0194 {
0195 ixmin=0;
0196 ixmax=85;
0197 nx =ixmax-ixmin;
0198 iymin=0;
0199 iymax=20;
0200 ny =iymax-iymin;
0201
0202 _pn[1] = pair<int,int>(0,5);
0203 _pn[2] = pair<int,int>(1,6);
0204 _pn[3] = _pn[2];
0205 _pn[4] = pair<int,int>(2,7);
0206 _pn[5] = _pn[4];
0207 _pn[6] = pair<int,int>(3,8);
0208 _pn[7] = _pn[6];
0209 _pn[8] = pair<int,int>(4,9);
0210 _pn[9] = _pn[8];
0211
0212 }
0213 else
0214 {
0215 cout << "EE numbering not implemented yet, sorry --- abort" << endl;
0216 abort();
0217 }
0218
0219
0220
0221
0222 bookHistoI( _primStr, "LOGIC_ID" );
0223 bookHistoI( _primStr, "FLAG" );
0224 bookHistoF( _primStr, "MEAN" );
0225 bookHistoF( _primStr, "RMS" );
0226 bookHistoF( _primStr, "PEAK" );
0227 bookHistoF( _primStr, "APD_OVER_PNA_MEAN" );
0228 bookHistoF( _primStr, "APD_OVER_PNA_RMS" );
0229 bookHistoF( _primStr, "APD_OVER_PNA_PEAK" );
0230 bookHistoF( _primStr, "APD_OVER_PNB_MEAN" );
0231 bookHistoF( _primStr, "APD_OVER_PNB_RMS" );
0232 bookHistoF( _primStr, "APD_OVER_PNB_PEAK" );
0233 bookHistoF( _primStr, "APD_OVER_PN_MEAN" );
0234 bookHistoF( _primStr, "APD_OVER_PN_RMS" );
0235 bookHistoF( _primStr, "APD_OVER_PN_PEAK" );
0236 bookHistoF( _primStr, "SHAPE_COR" );
0237 bookHistoF( _primStr, "ALPHA" );
0238 bookHistoF( _primStr, "BETA" );
0239
0240 TString t_name;
0241
0242
0243
0244
0245 t_name = lmfLaserName( iLmfLaserPnPrim, _color );
0246 addBranchI( t_name, "LOGIC_ID" );
0247 addBranchI( t_name, "FLAG" );
0248 addBranchF( t_name, "MEAN" );
0249 addBranchF( t_name, "RMS" );
0250 addBranchF( t_name, "PEAK" );
0251 addBranchF( t_name, "PNA_OVER_PNB_MEAN" );
0252 addBranchF( t_name, "PNA_OVER_PNB_RMS" );
0253 addBranchF( t_name, "PNA_OVER_PNB_PEAK" );
0254
0255
0256
0257
0258 t_name = lmfLaserName( iLmfLaserPulse, _color );
0259 addBranchI( t_name, "LOGIC_ID" );
0260 addBranchI( t_name, "FIT_METHOD" );
0261 addBranchF( t_name, "MTQ_AMPL" );
0262 addBranchF( t_name, "MTQ_TIME" );
0263 addBranchF( t_name, "MTQ_RISE" );
0264 addBranchF( t_name, "MTQ_FWHM" );
0265 addBranchF( t_name, "MTQ_FW20" );
0266 addBranchF( t_name, "MTQ_FW80" );
0267 addBranchF( t_name, "MTQ_SLIDING" );
0268
0269
0270
0271
0272 t_name = lmfLaserName( iLmfLaserConfig );
0273 addBranchI( t_name, "LOGIC_ID" );
0274 addBranchI( t_name, "WAVELENGTH" );
0275 addBranchI( t_name, "VFE_GAIN" );
0276 addBranchI( t_name, "PN_GAIN" );
0277 addBranchI( t_name, "LSR_POWER" );
0278 addBranchI( t_name, "LSR_ATTENUATOR" );
0279 addBranchI( t_name, "LSR_CURRENT" );
0280 addBranchI( t_name, "LSR_DELAY_1" );
0281 addBranchI( t_name, "LSR_DELAY_2" );
0282
0283
0284
0285
0286 t_name = "LMF_RUN_DAT";
0287 addBranchI( t_name, "LOGIC_ID" );
0288 addBranchI( t_name, "NEVENTS" );
0289 addBranchI( t_name, "QUALITY_FLAG" );
0290
0291
0292
0293
0294 t_name = "LMF_RUN_IOV";
0295 addBranchI( t_name, "TAG_ID" );
0296 addBranchI( t_name, "SUB_RUN_NUM" );
0297 addBranchI( t_name, "SUB_RUN_START" );
0298 addBranchI( t_name, "SUB_RUN_END" );
0299 addBranchI( t_name, "DB_TIMESTAMP" );
0300 addBranchC( t_name, "SUB_RUN_TYPE" );
0301
0302
0303
0304
0305 t_name = "RUN_LASERRUN_CONFIG_DAT";
0306 addBranchI( t_name, "LOGIC_ID" );
0307 addBranchC( t_name, "LASER_SEQUENCE_TYPE" );
0308 addBranchC( t_name, "LASER_SEQUENCE_COND" );
0309 }
0310
0311 void
0312 MELaserPrim::fillHistograms()
0313 {
0314 Long64_t nb = 0;
0315 Long64_t nentries = 0;
0316 Long64_t ientry = 0;
0317
0318 nentries = apdpn_tree->GetEntriesFast();
0319 for( Long64_t jentry=0; jentry<nentries; jentry++ )
0320 {
0321 ientry = apdpn_tree->LoadTree( jentry );
0322 assert( ientry>=0 );
0323 nb = apdpn_tree->GetEntry( jentry );
0324
0325 ientry = ab_tree->LoadTree( jentry );
0326 assert( ientry>=0 );
0327 nb = ab_tree->GetEntry( jentry );
0328
0329 assert( apdpn_ieta==ab_ieta && apdpn_iphi==ab_iphi );
0330
0331 int module_ = apdpn_moduleID+1;
0332 int side_ = 1;
0333 if( module_%2 ) side_=0;
0334
0335 int ix = apdpn_ieta;
0336 int iy = apdpn_iphi;
0337
0338 int id1 = _sm;
0339 int id2 = ix*20 + (20 - iy);
0340 int logic_id_ = 1011000000;
0341 logic_id_ += 10000*id1 + id2;
0342
0343 if( side_!=_side )
0344 {
0345 setInt( "LOGIC_ID", ix, iy, -logic_id_ );
0346 setInt( "FLAG", ix, iy, 0 );
0347 continue;
0348 }
0349
0350 int flag = apdpn_flag;
0351
0352 setInt( "LOGIC_ID", ix, iy, logic_id_ );
0353 setInt( "FLAG", ix, iy, flag );
0354 setVal( "MEAN", ix, iy, apdpn_apdpn[iAPD][iMean] );
0355 setVal( "RMS", ix, iy, apdpn_apdpn[iAPD][iRMS] );
0356 setVal( "PEAK", ix, iy, apdpn_apdpn[iAPD][iWbin] );
0357 setVal( "APD_OVER_PNA_MEAN", ix, iy, apdpn_apdpn[iAPDoPNA][iMean] );
0358 setVal( "APD_OVER_PNA_RMS", ix, iy, apdpn_apdpn[iAPDoPNA][iRMS] );
0359 setVal( "APD_OVER_PNA_PEAK", ix, iy, apdpn_apdpn[iAPDoPNA][iWbin] );
0360 setVal( "APD_OVER_PNB_MEAN", ix, iy, apdpn_apdpn[iAPDoPNB][iMean] );
0361 setVal( "APD_OVER_PNB_RMS", ix, iy, apdpn_apdpn[iAPDoPNB][iRMS] );
0362 setVal( "APD_OVER_PNB_PEAK", ix, iy, apdpn_apdpn[iAPDoPNB][iWbin] );
0363 setVal( "APD_OVER_PN_MEAN", ix, iy, apdpn_apdpn[iAPDoPN][iMean] );
0364 setVal( "APD_OVER_PN_RMS", ix, iy, apdpn_apdpn[iAPDoPN][iRMS] );
0365 setVal( "APD_OVER_PN_PEAK", ix, iy, apdpn_apdpn[iAPDoPN][iWbin] );
0366 setVal( "SHAPE_COR", ix, iy, apdpn_ShapeCor );
0367 setVal( "ALPHA", ix, iy, ab_ab[iAlpha] );
0368 setVal( "BETA", ix, iy, ab_ab[iBeta] );
0369
0370 }
0371
0372 TString t_name;
0373
0374
0375
0376
0377 t_name = lmfLaserName( iLmfLaserPnPrim, _color );
0378
0379 nentries = pn_tree->GetEntriesFast();
0380 assert( nentries%2==0 );
0381
0382 int module_(0), pn_[2];
0383 int id1_(_sm), id2_(0);
0384 int logic_id_(0);
0385
0386 Long64_t jentry=0;
0387 if( _side==1 ) jentry+=2;
0388 while( jentry<nentries )
0389 {
0390 for( int jj=0; jj<2; jj++ )
0391 {
0392
0393
0394
0395 int zentry = jentry+jj;
0396 assert( zentry<nentries );
0397
0398 ientry = pn_tree->LoadTree( zentry );
0399 assert( ientry>=0 );
0400 nb = pn_tree->GetEntry( zentry );
0401
0402 if( jj==1 ) assert( pn_moduleID+1==module_ );
0403 module_ = pn_moduleID+1;
0404 assert( pn_pnID==jj );
0405
0406 pn_[jj] = ( jj==0 ) ? _pn[module_].first : _pn[module_].second;
0407 id2_ = pn_[jj];
0408 logic_id_ = 1131000000 ;
0409
0410 logic_id_ += 10000*id1_ + id2_;
0411
0412 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
0413 f_t[t_name+separator+"MEAN"] = pn_PN[iMean];
0414 f_t[t_name+separator+"RMS"] = pn_PN[iRMS];
0415 f_t[t_name+separator+"PEAK"] = pn_PN[iMean];
0416 f_t[t_name+separator+"PNA_OVER_PNB_MEAN"] = (jj==0) ? pn_PNoPNB[iMean] : pn_PNoPNA[iMean];
0417 f_t[t_name+separator+"PNA_OVER_PNB_RMS" ] = (jj==0) ? pn_PNoPNB[iRMS] : pn_PNoPNA[iRMS];
0418 f_t[t_name+separator+"PNA_OVER_PNB_PEAK"] = (jj==0) ? pn_PNoPNB[iMean] : pn_PNoPNA[iMean];
0419
0420 t_t[t_name]->Fill();
0421
0422 }
0423
0424
0425 jentry += 4;
0426 }
0427
0428 logic_id_ = 1041000000;
0429 logic_id_ += 10000*id1_;
0430 logic_id_ += id1_;
0431
0432
0433
0434 t_name = lmfLaserName( iLmfLaserPulse, _color );
0435
0436 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
0437 i_t[t_name+separator+"FIT_METHOD"] = _side;
0438 f_t[t_name+separator+"MTQ_AMPL"] = 0.;
0439 f_t[t_name+separator+"MTQ_TIME"] = 0.;
0440 f_t[t_name+separator+"MTQ_RISE"] = 0.;
0441 f_t[t_name+separator+"MTQ_FWHM"] = 0.;
0442 f_t[t_name+separator+"MTQ_FW20"] = 0.;
0443 f_t[t_name+separator+"MTQ_FW80"] = 0.;
0444 f_t[t_name+separator+"MTQ_SLIDING"] = 0.;
0445
0446 nentries = mtq_tree->GetEntriesFast();
0447 int nevt = 0 ;
0448 int nevent[2] = {0,0} ;
0449 int side_ = 0 ;
0450 for( Long64_t jentry=0; jentry<nentries; jentry++ )
0451 {
0452 ientry = mtq_tree-> LoadTree( jentry );
0453 assert( ientry>=0 );
0454 nb = mtq_tree->GetEntry( jentry );
0455
0456 if( mtq_laser_color!=_color ) continue;
0457
0458 if( mtq_event==1 && nevent[0]>0 )
0459 {
0460 side_ = 1;
0461 }
0462 nevent[side_]++;
0463 if( side_!=_side ) continue;
0464
0465 bool ok = ( mtq_status==1 ) && ( mtq_mtq[iAmpl]>0 );
0466 if( !ok ) continue;
0467
0468 nevt++;
0469 f_t[t_name+separator+"MTQ_AMPL"] += mtq_mtq[iAmpl];
0470 f_t[t_name+separator+"MTQ_TIME"] += mtq_mtq[iPeak];
0471 f_t[t_name+separator+"MTQ_RISE"] += mtq_mtq[iTrise];
0472 f_t[t_name+separator+"MTQ_FWHM"] += mtq_mtq[iFwhm];
0473 f_t[t_name+separator+"MTQ_FW20"] += mtq_mtq[iFw20];
0474 f_t[t_name+separator+"MTQ_FW80"] += mtq_mtq[iFw80];
0475 f_t[t_name+separator+"MTQ_SLIDING"] += 0.;
0476
0477
0478 }
0479
0480
0481 if( nevt!=0 )
0482 {
0483 f_t[t_name+separator+"MTQ_AMPL"] /= nevt;
0484 f_t[t_name+separator+"MTQ_TIME"] /= nevt;
0485 f_t[t_name+separator+"MTQ_RISE"] /= nevt;
0486 f_t[t_name+separator+"MTQ_FWHM"] /= nevt;
0487 f_t[t_name+separator+"MTQ_FW20"] /= nevt;
0488 f_t[t_name+separator+"MTQ_FW80"] /= nevt;
0489 f_t[t_name+separator+"MTQ_SLIDING"] /= nevt;
0490 }
0491
0492 t_t[t_name]->Fill();
0493
0494
0495
0496
0497 t_name = lmfLaserName( iLmfLaserRun );
0498
0499 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
0500 i_t[t_name+separator+"NEVENTS"] = nevent[side_];
0501 i_t[t_name+separator+"QUALITY_FLAG"] = 1;
0502 t_t[t_name]->Fill();
0503
0504
0505
0506
0507 t_name = lmfLaserName( iLmfLaserConfig );
0508
0509 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
0510 i_t[t_name+separator+"WAVELENGTH"] = _color;
0511 i_t[t_name+separator+"VFE_GAIN"] = iVfeGain12;
0512 i_t[t_name+separator+"PN_GAIN"] = iPnGain16;
0513 i_t[t_name+separator+"LSR_POWER"] = 0;
0514 i_t[t_name+separator+"LSR_ATTENUATOR"] = 0;
0515 i_t[t_name+separator+"LSR_CURRENT"] = 0;
0516 i_t[t_name+separator+"LSR_DELAY_1"] = 0;
0517 i_t[t_name+separator+"LSR_DELAY_2"] = 0;
0518 t_t[t_name]->Fill();
0519
0520
0521
0522
0523 t_name = "LMF_RUN_IOV";
0524
0525 i_t[t_name+separator+"TAG_ID"] = 0;
0526 i_t[t_name+separator+"SUB_RUN_NUM"] = _run;
0527 i_t[t_name+separator+"SUB_RUN_START"] = _ts;
0528 i_t[t_name+separator+"SUB_RUN_END"] = _ts+6;
0529 i_t[t_name+separator+"DB_TIMESTAMP"] = _ts;
0530 c_t[t_name+separator+"SUB_RUN_TYPE"] = "LASER TEST BEAM H4";
0531 t_t[t_name]->Fill();
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544 }
0545
0546 void
0547 MELaserPrim::writeHistograms()
0548 {
0549 TString cur(_outpath);
0550 if( !cur.EndsWith("/") ) cur+="/";
0551
0552 TString _outfile(cur);
0553 _outfile += "LMF_";
0554 _outfile += _regionStr;
0555 switch( _color )
0556 {
0557 case iBlue: _outfile += "_BlueLaser"; break;
0558 case iGreen: _outfile += "_GreenLaser"; break;
0559 case iRed: _outfile += "_RedLaser"; break;
0560 case iIRed: _outfile += "_IRedLaser"; break;
0561 default: break;
0562 }
0563 _outfile += "_Run"; _outfile += _run;
0564 _outfile += "_TS"; _outfile += _ts;
0565 _outfile += ".root";
0566
0567 out_file = new TFile( _outfile, "RECREATE" );
0568
0569
0570
0571 map< TString, TH2* >::iterator it;
0572
0573 for( it=i_h.begin(); it!=i_h.end(); it++ )
0574 {
0575 it->second->Write();
0576 }
0577
0578 for( it=f_h.begin(); it!=f_h.end(); it++ )
0579 {
0580 it->second->Write();
0581 }
0582
0583 map< TString, TTree* >::iterator it_t;
0584 for( it_t=t_t.begin(); it_t!=t_t.end(); it_t++ )
0585 {
0586 it_t->second->Write();
0587 }
0588
0589
0590 out_file->Close();
0591 delete out_file;
0592 out_file=0;
0593 }
0594
0595 MELaserPrim::~MELaserPrim()
0596 {
0597 delete apdpn_tree;
0598 delete ab_tree;
0599 delete pn_tree;
0600 delete mtq_tree;
0601 if( apdpn_file!=0 )
0602 {
0603 apdpn_file->Close();
0604 delete apdpn_file;
0605 apdpn_file = 0;
0606 pn_file=0;
0607 }
0608 if( ab_file!=0 )
0609 {
0610 ab_file->Close();
0611 delete ab_file;
0612 ab_file = 0;
0613 }
0614 if( pn_file!=0 )
0615 {
0616 pn_file->Close();
0617 delete pn_file;
0618 pn_file = 0;
0619 }
0620 if( mtq_file!=0 )
0621 {
0622 mtq_file->Close();
0623 delete mtq_file;
0624 mtq_file = 0;
0625 }
0626 }
0627
0628 void
0629 MELaserPrim::print( ostream& o )
0630 {
0631 o << "DCC/SM/side/color/run/ts " << _dcc << "/" << _sm << "/" << _side << "/" << _color << "/" << _run << "/" << _ts << endl;
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644 }
0645
0646 TString
0647 MELaserPrim::lmfLaserName( int table, int color )
0648 {
0649 TString str("LMF_ERROR");
0650 if( table<0 || table>=iSizeLmfLaser ) return str;
0651 if( color<0 || color>=iSizeColor ) return str;
0652
0653 TString colstr;
0654 switch( color )
0655 {
0656 case iBlue: colstr = "_BLUE"; break;
0657 case iGreen: colstr = "_GREEN"; break;
0658 case iRed: colstr = "_RED"; break;
0659 case iIRed: colstr = "_IRED"; break;
0660 default: abort();
0661 }
0662 str = "LMF_LASER";
0663 switch( table )
0664 {
0665 case iLmfLaserRun: str = "LMF_RUN"; break;
0666 case iLmfLaserConfig: str += "_CONFIG"; break;
0667 case iLmfLaserPulse: str += colstr; str += "_PULSE"; break;
0668 case iLmfLaserPrim: str += colstr; str += "_PRIM"; break;
0669 case iLmfLaserPnPrim: str += colstr; str += "_PN_PRIM"; break;
0670 default: abort();
0671 }
0672 str += "_DAT";
0673 return str;
0674 }
0675
0676 void
0677 MELaserPrim::addBranchI( const char* t_name_, const char* v_name_ )
0678 {
0679 TString slashI("/I");
0680 TString t_name(t_name_);
0681 TString v_name(v_name_);
0682 if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
0683 t_t[t_name]->Branch(v_name, &i_t[t_name+separator+v_name],v_name+slashI);
0684 }
0685
0686 void
0687 MELaserPrim::addBranchF( const char* t_name_, const char* v_name_ )
0688 {
0689 TString slashF("/F");
0690 TString t_name(t_name_);
0691 TString v_name(v_name_);
0692 if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
0693 t_t[t_name]->Branch(v_name, &f_t[t_name+separator+v_name],v_name+slashF);
0694 }
0695
0696 void
0697 MELaserPrim::addBranchC( const char* t_name_, const char* v_name_ )
0698 {
0699 TString slashC("/C");
0700 TString t_name(t_name_);
0701 TString v_name(v_name_);
0702 if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
0703 t_t[t_name]->Branch(v_name, &c_t[t_name+separator+v_name],v_name+slashC);
0704 }
0705
0706 void
0707 MELaserPrim::bookHistoI( const char* h_name_, const char* v_name_ )
0708 {
0709 TString i_name = TString(h_name_)+TString(v_name_);
0710 TH2* h_ = new TH2I(i_name,i_name,nx,ixmin,ixmax,ny,iymin,iymax);
0711 setHistoStyle( h_ );
0712 i_h[i_name] = h_;
0713 }
0714
0715 void
0716 MELaserPrim::bookHistoF( const char* h_name_, const char* v_name_ )
0717 {
0718 TString d_name = TString(h_name_)+TString(v_name_);
0719 TH2* h_ = new TH2F(d_name,d_name,nx,ixmin,ixmax,ny,iymin,iymax);
0720 setHistoStyle( h_ );
0721 f_h[d_name] = h_;
0722 }
0723
0724
0725 bool
0726 MELaserPrim::setInt( const char* name, int ix, int iy, int ival )
0727 {
0728 int _ival = getInt( _primStr+name, ix, iy );
0729 assert( _ival!=-99 );
0730 if( _ival!=0 ) return false;
0731
0732 TH2I* h_ = (TH2I*) i_h[_primStr+name];
0733 assert( h_!=0 );
0734 h_->Fill( ix+0.5, iy+0.5, ival );
0735
0736 return true;
0737 }
0738
0739 bool
0740 MELaserPrim::setVal( const char* name, int ix, int iy, float val )
0741 {
0742 float _val = getVal( _primStr+name, ix, iy );
0743 assert( _val!=-99 );
0744 if( _val!=0 ) return false;
0745
0746 TH2F* h_ = (TH2F*) f_h[_primStr+name];
0747 assert( h_!=0 );
0748 h_->Fill( ix+0.5, iy+0.5, val );
0749
0750 return true;
0751 }
0752
0753 Int_t
0754 MELaserPrim::getInt( const char* name, int ix, int iy )
0755 {
0756 Int_t ival=-99;
0757 if( i_h.count(name)==1 )
0758 {
0759 TH2I* h_ = (TH2I*) i_h[name];
0760 assert( h_!=0 );
0761 int binx = h_->GetXaxis()->FindBin( ix+0.5 );
0762 int biny = h_->GetYaxis()->FindBin( iy+0.5 );
0763 ival = (Int_t) h_->GetCellContent( binx, biny );
0764 }
0765 return ival;
0766 }
0767
0768 Float_t
0769 MELaserPrim::getVal( const char* name, int ix, int iy )
0770 {
0771 Float_t val=-99.;
0772 if( f_h.count(name)==1 )
0773 {
0774 TH2F* h_ = (TH2F*) f_h[name];
0775 assert( h_!=0 );
0776 int binx = h_->GetXaxis()->FindBin( ix+0.5 );
0777 int biny = h_->GetYaxis()->FindBin( iy+0.5 );
0778 val = h_->GetCellContent( binx, biny );
0779 }
0780 return val;
0781 }
0782
0783 bool
0784 MELaserPrim::setInt( const char* tname, const char* vname, int ival )
0785 {
0786 TString key_(tname); key_ += separator; key_ += vname;
0787 assert( i_t.count(key_)==1 );
0788 i_t[key_] = ival;
0789 return true;
0790 }
0791
0792 bool
0793 MELaserPrim::setVal( const char* tname, const char* vname, float val )
0794 {
0795 TString key_(tname); key_ += separator; key_ += vname;
0796 assert( f_t.count(key_)==1 );
0797 f_t[key_] = val;
0798 return true;
0799 }
0800
0801 bool
0802 MELaserPrim::fill( const char* tname )
0803 {
0804 TString key_( tname );
0805 assert( t_t.count(key_)==1 );
0806 t_t[key_] -> Fill();
0807 return true;
0808 }
0809
0810 void
0811 MELaserPrim::setHistoStyle( TH1* h )
0812 {
0813 if( h==0 ) return;
0814
0815 float _scale = 1;
0816
0817 h->SetLineColor(4);
0818 h->SetLineWidth(1);
0819 h->SetFillColor(38);
0820 TAxis* axis[3];
0821 axis[0] = h->GetXaxis();
0822 axis[1] = h->GetYaxis();
0823 axis[2] = h->GetZaxis();
0824 for( int ii=0; ii<3; ii++ )
0825 {
0826 TAxis* a = axis[ii];
0827 if( !a ) continue;
0828 a->SetLabelFont(132);
0829 a->SetLabelOffset(_scale*0.005);
0830 a->SetLabelSize(_scale*0.04);
0831 a->SetTitleFont(132);
0832 a->SetTitleOffset(_scale*1);
0833 a->SetTitleSize(_scale*0.04);
0834 }
0835 h->SetStats( kTRUE );
0836 }
0837
0838 void
0839 MELaserPrim::refresh()
0840 {
0841 map< TString, TH2* >::iterator it;
0842
0843 for( it=i_h.begin(); it!=i_h.end(); it++ )
0844 {
0845 delete it->second;
0846 it->second = 0;
0847 }
0848 i_h.clear();
0849
0850 for( it=f_h.begin(); it!=f_h.end(); it++ )
0851 {
0852 delete it->second;
0853 it->second = 0;
0854 }
0855 f_h.clear();
0856
0857 map< TString, TTree* >::iterator it_t;
0858 for( it_t=t_t.begin(); it_t!=t_t.end(); it_t++ )
0859 {
0860 delete it_t->second;
0861 it->second = 0;
0862 }
0863 t_t.clear();
0864 }