00001 #define MELaserPrim_cxx
00002 #include <assert.h>
00003 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MELaserPrim.h"
00004 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEGeom.h"
00005 #include <cassert>
00006 #include <cstdlib>
00007
00008 TString MELaserPrim::apdpn_arrayName[MELaserPrim::iSizeArray_apdpn] = {"APD", "APDoPN", "APDoPNA", "APDoPNB","APDoAPD","APDoAPDA", "APDoAPDB", "Time"};
00009 TString MELaserPrim::apdpn_varName[MELaserPrim::iSize_apdpn] = { "Mean", "RMS", "M3", "Nevt", "Min", "Max"};
00010 TString MELaserPrim::apdpn_varUnit[MELaserPrim::iSizeArray_apdpn][MELaserPrim::iSize_apdpn] =
00011
00012 { { " (ADC Counts)", " (ADC Counts)", " (ADC Counts)" ,"", " (ADC Counts)", " (ADC Counts)"},
00013 {"", "", "", "", "", ""},
00014 {"", "", "", "", "", ""},
00015 {"", "", "", "", "", ""},
00016 {"", "", "", "", "", ""},
00017 {"", "", "", "", "", ""},
00018 {" (25 ns)", " (25 ns)", " (25 ns)", "", " (25 ns)", " (25 ns)"} };
00019 TString MELaserPrim::apdpn_extraVarName[MELaserPrim::iSizeExtra_apdpn] = { "ShapeCor" };
00020 TString MELaserPrim::apdpn_extraVarUnit[MELaserPrim::iSizeExtra_apdpn] = { "" };
00021 TString MELaserPrim::ab_varName[MELaserPrim::iSize_ab] = { "alpha", "beta", "width", "chi2" };
00022 TString MELaserPrim::mtq_varName[MELaserPrim::iSize_mtq] = {"peak", "sigma", "fit", "ampl", "trise", "fwhm", "fw20", "fw80", "sliding" };
00023 TString MELaserPrim::mtq_varUnit[MELaserPrim::iSize_mtq] =
00024 {"(nanoseconds)", "(nanoseconds)", "(nanoseconds)",
00025 "(ADC counts)", "(nanoseconds)",
00026 "(nanoseconds)", "(nanoseconds)", "(nanoseconds)", "(ADC counts)"};
00027
00028 TString MELaserPrim::separator = "__";
00029
00030
00031
00032 MELaserPrim::MELaserPrim( ME::Header header, ME::Settings settings,
00033 const char* inpath, const char* outfile )
00034 : init_ok(false), _isBarrel(true), _inpath(inpath), _outfile(outfile)
00035 {
00036 apdpn_file =0;
00037 ab_file =0;
00038 mtq_file =0;
00039 tpapd_file =0;
00040 apdpn_tree =0;
00041 ab_tree =0;
00042 pn_tree =0;
00043 mtq_tree =0;
00044 tpapd_tree =0;
00045 tppn_tree =0;
00046 ixmin =0;
00047 ixmax =0;
00048 iymin =0;
00049 iymax =0;
00050
00051 _dcc = header.dcc;
00052 _side = header.side;
00053 _run = header.run;
00054 _lb = header.lb;
00055 _events = header.events;
00056 _ts = header.ts_beg;
00057 _ts_beg = header.ts_beg;
00058 _ts_end = header.ts_end;
00059
00060 _type = settings.type;
00061 _color = settings.wavelength;
00062 _power = settings.power;
00063 _filter = settings.filter;
00064 _delay = settings.delay;
00065 _mgpagain = settings.mgpagain;
00066 _memgain = settings.memgain;
00067
00068 if( _type==ME::iLaser )
00069 {
00070 _primStr = lmfLaserName( ME::iLmfLaserPrim, _type, _color )+separator;
00071 _pnPrimStr = lmfLaserName( ME::iLmfLaserPnPrim, _type, _color )+separator;
00072 _pulseStr = lmfLaserName( ME::iLmfLaserPulse, _type, _color )+separator;
00073 }
00074 else if( _type==ME::iTestPulse )
00075 {
00076 _tpPrimStr = lmfLaserName( ME::iLmfTestPulsePrim, _type )+separator;
00077 _tpPnPrimStr = lmfLaserName( ME::iLmfTestPulsePnPrim, _type )+separator;
00078 }
00079
00080 _lmr = ME::lmr( _dcc, _side );
00081 ME::regionAndSector( _lmr, _reg, _sm, _dcc, _side );
00082 _isBarrel = (_reg==ME::iEBM || _reg==ME::iEBP);
00083 _sectorStr = ME::smName( _lmr );
00084 _regionStr = _sectorStr;
00085 _regionStr += "_"; _regionStr += _side;
00086
00087 init();
00088 bookHistograms();
00089
00090
00091 }
00092
00093 TString
00094 MELaserPrim::channelViewName( int iname )
00095 {
00096 switch( iname )
00097 {
00098 case iECAL: return "ECAL";
00099 case iECAL_LMR: return "ECAL_LMR";
00100 case iEB_crystal_number: return "EB_crystal_number";
00101 case iEB_LM_LMM: return "EB_LM_LMM";
00102 case iEB_LM_PN: return "EB_LM_PN";
00103 case iEE_crystal_number: return "EE_crystal_number";
00104 case iEE_LM_LMM: return "EE_LM_LMM";
00105 case iEE_LM_PN: return "EE_LM_PN";
00106 default:
00107 abort();
00108 }
00109 return "";
00110 }
00111
00112 int
00113 MELaserPrim::logicId( int channelView, int id1, int id2 )
00114 {
00115 assert( channelView>=iECAL && channelView<iSize_cv );
00116 return 1000000*channelView + 10000*id1 + id2;
00117 }
00118
00119 bool
00120 MELaserPrim::getViewIds( int logic_id, int& channelView, int& id1, int& id2 )
00121 {
00122 bool out = true;
00123 int channelView_ = logic_id/1000000;
00124 if( channelView!=0 && channelView_!=channelView ) out=false;
00125 channelView = channelView_;
00126 id1 = (logic_id%1000000)/10000;
00127 id2 = logic_id%10000;
00128 return out;
00129 }
00130
00131 void
00132 MELaserPrim::init()
00133 {
00134 bool verbose_ = false;
00135
00136 if( _inpath=="0" )
00137 {
00138 if( verbose_ ) std::cout << "no input file" << std::endl;
00139 init_ok = true;
00140 return;
00141 }
00142
00143 TString cur(_inpath);
00144 if( !cur.EndsWith("/") ) cur+="/";
00145
00146 if( _type==ME::iLaser )
00147 {
00148 TString _APDPN_fname =cur; _APDPN_fname += "APDPN_LASER.root";
00149 TString _AB_fname =cur; _AB_fname += "AB.root";
00150 TString _MTQ_fname =cur; _MTQ_fname += "MATACQ.root";
00151
00152 bool apdpn_ok, ab_ok, pn_ok, mtq_ok;
00153 apdpn_ok=false; ab_ok=false; pn_ok=false; mtq_ok=false;
00154
00155 FILE *test;
00156 test = fopen( _APDPN_fname,"r");
00157 if (test) {
00158 apdpn_ok = true;
00159 pn_ok = true;
00160 fclose( test );
00161 }
00162 test = fopen( _AB_fname,"r");
00163 if (test)
00164 {
00165 ab_ok = true;
00166 fclose( test );
00167 }
00168 test = fopen( _MTQ_fname,"r");
00169 if (test)
00170 {
00171 mtq_ok = true;
00172 fclose( test );
00173 }
00174
00175 if(apdpn_ok) apdpn_file = TFile::Open( _APDPN_fname );
00176 if(ab_ok) ab_file = TFile::Open( _AB_fname );
00177 if(mtq_ok) mtq_file = TFile::Open( _MTQ_fname );
00178
00179 if( verbose_ )
00180 {
00181 std::cout << _APDPN_fname << " ok=" << apdpn_ok << std::endl;
00182 std::cout << _AB_fname << " ok=" << ab_ok << std::endl;
00183 std::cout << _MTQ_fname << " ok=" << mtq_ok << std::endl;
00184 }
00185 if (!apdpn_ok || !pn_ok ) return;
00186
00187 TString apdpn_tree_name;
00188 TString ab_tree_name;
00189 TString pn_tree_name;
00190 TString mtq_tree_name;
00191
00192 apdpn_tree_name = "APDCol";
00193 ab_tree_name = "ABCol";
00194 pn_tree_name = "PNCol";
00195 mtq_tree_name = "MatacqCol";
00196
00197 apdpn_tree_name += _color;
00198 ab_tree_name += _color;
00199 pn_tree_name += _color;
00200 mtq_tree_name += _color;
00201
00202 if(mtq_ok) {
00203 TTree *ckeckMtq = (TTree*) mtq_file->Get(mtq_tree_name);
00204 if( ckeckMtq ==0 ) mtq_ok = false;
00205 }
00206
00207 if( _color != ME::iIRed && _color != ME::iBlue ){
00208 std::cout << "MELaserPrim::init() -- Fatal Error -- Wrong Laser Color : " << _color << " ---- Abort " << std::endl;
00209 return;
00210 }
00211
00212 apdpn_tree = (TTree*) apdpn_file->Get(apdpn_tree_name);
00213 assert( apdpn_tree!=0 );
00214 apdpn_tree->SetMakeClass(1);
00215 apdpn_tree->SetBranchAddress("dccID", &apdpn_dccID, &b_apdpn_dccID);
00216 apdpn_tree->SetBranchAddress("towerID", &apdpn_towerID, &b_apdpn_towerID);
00217 apdpn_tree->SetBranchAddress("channelID", &apdpn_channelID, &b_apdpn_channelID);
00218 apdpn_tree->SetBranchAddress("moduleID", &apdpn_moduleID, &b_apdpn_moduleID);
00219 apdpn_tree->SetBranchAddress("side", &apdpn_side, &b_apdpn_side);
00220 apdpn_tree->SetBranchAddress("ieta", &apdpn_ieta, &b_apdpn_ieta);
00221 apdpn_tree->SetBranchAddress("iphi", &apdpn_iphi, &b_apdpn_iphi);
00222 apdpn_tree->SetBranchAddress("flag", &apdpn_flag, &b_apdpn_flag);
00223 if( apdpn_tree->GetBranchStatus("ShapeCor")) apdpn_tree->SetBranchAddress("ShapeCor", &apdpn_ShapeCor, &b_apdpn_ShapeCor);
00224 else apdpn_ShapeCor = 0.0;
00225 for( int jj=0; jj<iSizeArray_apdpn; jj++ )
00226 {
00227 TString name_ = apdpn_arrayName[jj];
00228 apdpn_tree->SetBranchAddress(name_, apdpn_apdpn[jj], &b_apdpn_apdpn[jj]);
00229 }
00230
00231 if(ab_ok) {
00232 ab_tree = (TTree*) ab_file->Get(ab_tree_name);
00233 assert( ab_tree!=0 );
00234 ab_tree->SetMakeClass(1);
00235 ab_tree->SetBranchAddress("dccID", &ab_dccID, &b_ab_dccID );
00236 ab_tree->SetBranchAddress("towerID", &ab_towerID, &b_ab_towerID );
00237 ab_tree->SetBranchAddress("channelID", &ab_channelID, &b_ab_channelID );
00238 ab_tree->SetBranchAddress("ieta", &ab_ieta, &b_ab_ieta );
00239 ab_tree->SetBranchAddress("iphi", &ab_iphi, &b_ab_iphi );
00240 ab_tree->SetBranchAddress("flag", &ab_flag, &b_ab_flag );
00241 for( int ii=0; ii<iSize_ab; ii++ )
00242 {
00243 ab_tree->SetBranchAddress( ab_varName[ii], &ab_ab[ii], &b_ab_ab[ii] );
00244 }
00245 }
00246
00247 pn_tree = (TTree*) apdpn_file->Get(pn_tree_name);
00248 assert( pn_tree!=0 );
00249 pn_tree->SetMakeClass(1);
00250 pn_tree->SetBranchAddress( "side", &pn_side, &b_pn_side );
00251 pn_tree->SetBranchAddress( "pnID", &pn_pnID, &b_pn_pnID );
00252 pn_tree->SetBranchAddress( "moduleID", &pn_moduleID, &b_pn_moduleID );
00253 pn_tree->SetBranchAddress( "PN", pn_PN, &b_pn_PN );
00254 pn_tree->SetBranchAddress( "PNoPN", pn_PNoPN, &b_pn_PNoPN );
00255 pn_tree->SetBranchAddress( "PNoPNA", pn_PNoPNA, &b_pn_PNoPNA );
00256 pn_tree->SetBranchAddress( "PNoPNB", pn_PNoPNB, &b_pn_PNoPNB );
00257
00258
00259 if( mtq_ok ) {
00260 mtq_tree = (TTree*) mtq_file->Get(mtq_tree_name);
00261 assert( mtq_tree!=0 );
00262 mtq_tree->SetMakeClass(1);
00263 mtq_tree->SetBranchAddress("side", &mtq_side, &b_mtq_side );
00264
00265 for( int ii=0; ii<iSize_mtq; ii++ )
00266 {
00267 mtq_tree->SetBranchAddress( mtq_varName[ii], &mtq_mtq[ii], &b_mtq_mtq[ii] );
00268 }
00269 }
00270 }
00271 else if( _type==ME::iTestPulse )
00272 {
00273 TString _TPAPD_fname =cur; _TPAPD_fname += "APDPN_TESTPULSE.root";
00274
00275 bool tpapd_ok;
00276 tpapd_ok=false;
00277
00278 FILE *test;
00279 test = fopen( _TPAPD_fname,"r");
00280 if (test) {
00281 tpapd_ok = true;
00282 fclose( test );
00283 }
00284
00285 if(tpapd_ok) tpapd_file = TFile::Open( _TPAPD_fname );
00286
00287 if( verbose_ )
00288 {
00289 std::cout << _TPAPD_fname << " ok=" << tpapd_ok << std::endl;
00290 }
00291 if (!tpapd_ok ) return;
00292
00293 TString tpapd_tree_name;
00294 TString tppn_tree_name;
00295
00296 tpapd_tree_name = "TPAPD";
00297 tppn_tree_name = "TPPN";
00298
00299 tpapd_tree = (TTree*) tpapd_file->Get(tpapd_tree_name);
00300 assert( tpapd_tree!=0 );
00301 tpapd_tree->SetMakeClass(1);
00302 tpapd_tree->SetBranchAddress("ieta", &tpapd_ieta, &b_tpapd_ieta);
00303 tpapd_tree->SetBranchAddress("iphi", &tpapd_iphi, &b_tpapd_iphi);
00304 tpapd_tree->SetBranchAddress("dccID", &tpapd_dccID, &b_tpapd_dccID);
00305 tpapd_tree->SetBranchAddress("side", &tpapd_side, &b_tpapd_side);
00306 tpapd_tree->SetBranchAddress("towerID", &tpapd_towerID, &b_tpapd_towerID);
00307 tpapd_tree->SetBranchAddress("channelID", &tpapd_channelID, &b_tpapd_channelID);
00308 tpapd_tree->SetBranchAddress("moduleID", &tpapd_moduleID, &b_tpapd_moduleID);
00309 tpapd_tree->SetBranchAddress("flag", &tpapd_flag, &b_tpapd_flag);
00310 tpapd_tree->SetBranchAddress("gain", &tpapd_gain, &b_tpapd_gain);
00311 tpapd_tree->SetBranchAddress("APD", tpapd_APD, &b_tpapd_APD );
00312
00313 tppn_tree = (TTree*) tpapd_file->Get(tppn_tree_name);
00314 assert( tppn_tree!=0 );
00315 tppn_tree->SetMakeClass(1);
00316 tppn_tree->SetBranchAddress( "side", &tppn_side, &b_tppn_side );
00317 tppn_tree->SetBranchAddress( "pnID", &tppn_pnID, &b_tppn_pnID );
00318 tppn_tree->SetBranchAddress( "moduleID", &tppn_moduleID, &b_tppn_moduleID );
00319 tppn_tree->SetBranchAddress( "gain", &tppn_gain, &b_tppn_gain );
00320 tppn_tree->SetBranchAddress( "PN", tppn_PN, &b_tppn_PN );
00321 }
00322 init_ok = true;
00323 }
00324
00325 void
00326 MELaserPrim::bookHistograms()
00327 {
00328 if( !init_ok ) return;
00329 refresh();
00330
00331 TString i_name, d_name;
00332
00333 if( _isBarrel )
00334 {
00335 ixmin=0;
00336 ixmax=85;
00337 nx =ixmax-ixmin;
00338 iymin=0;
00339 iymax=20;
00340 ny =iymax-iymin;
00341
00342
00343
00344
00345
00346 }
00347 else
00348 {
00349 ixmin=1;
00350 ixmax=101;
00351 nx =ixmax-ixmin;
00352 iymin=1;
00353 iymax=101;
00354 ny =iymax-iymin;
00355
00356
00357
00358
00359
00360 }
00361
00362 TString t_name;
00363
00364
00365
00366
00367 t_name = "LMF_RUN_DAT";
00368 addBranchI( t_name, "LOGIC_ID" );
00369 addBranchI( t_name, "NEVENTS" );
00370 addBranchI( t_name, "QUALITY_FLAG" );
00371
00372
00373
00374
00375 t_name = "LMF_RUN_IOV";
00376 addBranchI( t_name, "TAG_ID" );
00377 addBranchI( t_name, "SUB_RUN_NUM" );
00378 addBranchI( t_name, "SUB_RUN_START_LOW" );
00379 addBranchI( t_name, "SUB_RUN_START_HIGH" );
00380 addBranchI( t_name, "SUB_RUN_END_LOW" );
00381 addBranchI( t_name, "SUB_RUN_END_HIGH" );
00382 addBranchI( t_name, "DB_TIMESTAMP_LOW" );
00383 addBranchI( t_name, "DB_TIMESTAMP_HIGH" );
00384 addBranchC( t_name, "SUB_RUN_TYPE" );
00385
00386 if( _type==ME::iLaser )
00387 {
00388
00389
00390
00391 bookHistoI( _primStr, "LOGIC_ID" );
00392 bookHistoI( _primStr, "FLAG" );
00393 bookHistoF( _primStr, "MEAN" );
00394 bookHistoF( _primStr, "RMS" );
00395 bookHistoF( _primStr, "M3" );
00396 bookHistoF( _primStr, "APD_OVER_PNA_MEAN" );
00397 bookHistoF( _primStr, "APD_OVER_PNA_RMS" );
00398 bookHistoF( _primStr, "APD_OVER_PNA_M3" );
00399 bookHistoF( _primStr, "APD_OVER_PNB_MEAN" );
00400 bookHistoF( _primStr, "APD_OVER_PNB_RMS" );
00401 bookHistoF( _primStr, "APD_OVER_PNB_M3" );
00402 bookHistoF( _primStr, "APD_OVER_PN_MEAN" );
00403 bookHistoF( _primStr, "APD_OVER_PN_RMS" );
00404 bookHistoF( _primStr, "APD_OVER_PN_M3" );
00405 bookHistoF( _primStr, "APD_OVER_APDA_MEAN" );
00406 bookHistoF( _primStr, "APD_OVER_APDA_RMS" );
00407 bookHistoF( _primStr, "APD_OVER_APDA_M3" );
00408 bookHistoF( _primStr, "APD_OVER_APDB_MEAN" );
00409 bookHistoF( _primStr, "APD_OVER_APDB_RMS" );
00410 bookHistoF( _primStr, "APD_OVER_APDB_M3" );
00411 bookHistoF( _primStr, "SHAPE_COR" );
00412 bookHistoF( _primStr, "ALPHA" );
00413 bookHistoF( _primStr, "BETA" );
00414
00415 bookHistoF( _primStr, "TIME_MEAN" );
00416 bookHistoF( _primStr, "TIME_RMS" );
00417 bookHistoF( _primStr, "TIME_M3" );
00418 bookHistoF( _primStr, "TIME_NEVT" );
00419
00420
00421
00422
00423 t_name = lmfLaserName( ME::iLmfLaserPnPrim, _type, _color );
00424 addBranchI( t_name, "LOGIC_ID" );
00425 addBranchI( t_name, "FLAG" );
00426 addBranchF( t_name, "MEAN" );
00427 addBranchF( t_name, "RMS" );
00428 addBranchF( t_name, "M3" );
00429 addBranchF( t_name, "PNA_OVER_PNB_MEAN" );
00430 addBranchF( t_name, "PNA_OVER_PNB_RMS" );
00431 addBranchF( t_name, "PNA_OVER_PNB_M3" );
00432
00433
00434
00435
00436 t_name = lmfLaserName( ME::iLmfLaserPulse, _type, _color );
00437 addBranchI( t_name, "LOGIC_ID" );
00438 addBranchI( t_name, "FIT_METHOD" );
00439 addBranchF( t_name, "MTQ_AMPL" );
00440 addBranchF( t_name, "MTQ_TIME" );
00441 addBranchF( t_name, "MTQ_RISE" );
00442 addBranchF( t_name, "MTQ_FWHM" );
00443 addBranchF( t_name, "MTQ_FW20" );
00444 addBranchF( t_name, "MTQ_FW80" );
00445 addBranchF( t_name, "MTQ_SLIDING" );
00446
00447
00448
00449
00450 t_name = lmfLaserName( ME::iLmfLaserConfig, _type );
00451 addBranchI( t_name, "LOGIC_ID" );
00452 addBranchI( t_name, "WAVELENGTH" );
00453 addBranchI( t_name, "VFE_GAIN" );
00454 addBranchI( t_name, "PN_GAIN" );
00455 addBranchI( t_name, "LSR_POWER" );
00456 addBranchI( t_name, "LSR_ATTENUATOR" );
00457 addBranchI( t_name, "LSR_CURRENT" );
00458 addBranchI( t_name, "LSR_DELAY_1" );
00459 addBranchI( t_name, "LSR_DELAY_2" );
00460
00461
00462
00463
00464 t_name = "RUN_LASERRUN_CONFIG_DAT";
00465 addBranchI( t_name, "LOGIC_ID" );
00466 addBranchC( t_name, "LASER_SEQUENCE_TYPE" );
00467 addBranchC( t_name, "LASER_SEQUENCE_COND" );
00468
00469 }
00470 else if( _type==ME::iTestPulse )
00471 {
00472
00473
00474
00475 bookHistoI( _tpPrimStr, "LOGIC_ID" );
00476 bookHistoI( _tpPrimStr, "FLAG" );
00477 bookHistoF( _tpPrimStr, "MEAN" );
00478 bookHistoF( _tpPrimStr, "RMS" );
00479 bookHistoF( _tpPrimStr, "M3" );
00480 bookHistoF( _tpPrimStr, "NEVT" );
00481
00482
00483
00484
00485 t_name = lmfLaserName( ME::iLmfTestPulsePnPrim, _type );
00486 addBranchI( t_name, "LOGIC_ID" );
00487 addBranchI( t_name, "FLAG" );
00488 addBranchI( t_name, "GAIN" );
00489 addBranchF( t_name, "MEAN" );
00490 addBranchF( t_name, "RMS" );
00491 addBranchF( t_name, "M3" );
00492
00493
00494
00495
00496 t_name = lmfLaserName( ME::iLmfTestPulseConfig, _type );
00497 addBranchI( t_name, "LOGIC_ID" );
00498 addBranchI( t_name, "VFE_GAIN" );
00499 addBranchI( t_name, "PN_GAIN" );
00500 }
00501 }
00502
00503 void
00504 MELaserPrim::fillHistograms()
00505 {
00506 TString t_name;
00507
00508 if( !init_ok ) return;
00509
00510 Long64_t nentries = 0;
00511 Long64_t ientry = 0;
00512
00513 int channelView_(0);
00514 int id1_(0), id2_(0);
00515 int logic_id_(0);
00516
00517 if( _type==ME::iLaser )
00518 {
00519
00520 nentries = apdpn_tree->GetEntriesFast();
00521 for( Long64_t jentry=0; jentry<nentries; jentry++ )
00522 {
00523 ientry = apdpn_tree->LoadTree( jentry );
00524 assert( ientry>=0 );
00525 apdpn_tree->GetEntry( jentry );
00526
00527 if(ab_tree){
00528 ientry = ab_tree->LoadTree( jentry );
00529 assert( ientry>=0 );
00530 ab_tree->GetEntry( jentry );
00531 }
00532
00533
00534 if( apdpn_iphi<0 ) continue;
00535
00536
00537
00538
00539 int ix(0);
00540 int iy(0);
00541 if( _isBarrel )
00542 {
00543
00544 id1_ = _sm;
00545 if ( apdpn_side != _side ) continue;
00546 int ieta=apdpn_ieta;
00547 int iphi=apdpn_iphi;
00548 MEEBGeom::XYCoord xy_ = MEEBGeom::localCoord( ieta, iphi );
00549 ix = xy_.first;
00550 iy = xy_.second;
00551 id2_ = MEEBGeom::crystal_channel( ix, iy );
00552 channelView_ = iEB_crystal_number;
00553 }
00554 else
00555 {
00556
00557 id1_ = apdpn_iphi;
00558 id2_ = apdpn_ieta;
00559 ix = id1_;
00560 iy = id2_;
00561 channelView_ = iEE_crystal_number;
00562 }
00563
00564 logic_id_ = logicId( channelView_, id1_, id2_ );
00565
00566 int flag = apdpn_flag;
00567
00568 setInt( "LOGIC_ID", ix, iy, logic_id_ );
00569 setInt( "FLAG", ix, iy, flag );
00570 setVal( "MEAN", ix, iy, apdpn_apdpn[iAPD][iMean] );
00571 setVal( "RMS", ix, iy, apdpn_apdpn[iAPD][iRMS] );
00572 setVal( "M3", ix, iy, apdpn_apdpn[iAPD][iM3] );
00573 setVal( "APD_OVER_PNA_MEAN", ix, iy, apdpn_apdpn[iAPDoPNA][iMean] );
00574 setVal( "APD_OVER_PNA_RMS", ix, iy, apdpn_apdpn[iAPDoPNA][iRMS] );
00575 setVal( "APD_OVER_PNA_M3", ix, iy, apdpn_apdpn[iAPDoPNA][iM3] );
00576 setVal( "APD_OVER_PNB_MEAN", ix, iy, apdpn_apdpn[iAPDoPNB][iMean] );
00577 setVal( "APD_OVER_PNB_RMS", ix, iy, apdpn_apdpn[iAPDoPNB][iRMS] );
00578 setVal( "APD_OVER_PNB_M3", ix, iy, apdpn_apdpn[iAPDoPNB][iM3] );
00579 setVal( "APD_OVER_PN_MEAN", ix, iy, apdpn_apdpn[iAPDoPN][iMean] );
00580 setVal( "APD_OVER_PN_RMS", ix, iy, apdpn_apdpn[iAPDoPN][iRMS] );
00581 setVal( "APD_OVER_PN_M3", ix, iy, apdpn_apdpn[iAPDoPN][iM3] );
00582
00583 setVal( "APD_OVER_APD_MEAN", ix, iy, apdpn_apdpn[iAPDoAPDA][iMean] );
00584 setVal( "APD_OVER_APD_RMS", ix, iy, apdpn_apdpn[iAPDoAPDA][iRMS] );
00585 setVal( "APD_OVER_APD_M3", ix, iy, apdpn_apdpn[iAPDoAPDA][iM3] );
00586 setVal( "APD_OVER_APDA_MEAN", ix, iy, apdpn_apdpn[iAPDoAPDA][iMean] );
00587 setVal( "APD_OVER_APDA_RMS", ix, iy, apdpn_apdpn[iAPDoAPDA][iRMS] );
00588 setVal( "APD_OVER_APDA_M3", ix, iy, apdpn_apdpn[iAPDoAPDA][iM3] );
00589 setVal( "APD_OVER_APDB_MEAN", ix, iy, apdpn_apdpn[iAPDoAPDB][iMean] );
00590 setVal( "APD_OVER_APDB_RMS", ix, iy, apdpn_apdpn[iAPDoAPDB][iRMS] );
00591 setVal( "APD_OVER_APDB_M3", ix, iy, apdpn_apdpn[iAPDoAPDB][iM3] );
00592
00593 setVal( "SHAPE_COR", ix, iy, apdpn_ShapeCor );
00594 if(ab_tree){
00595 setVal( "ALPHA", ix, iy, ab_ab[iAlpha] );
00596 setVal( "BETA", ix, iy, ab_ab[iBeta] );
00597 }else{
00598 setVal( "ALPHA", ix, iy, 0. );
00599 setVal( "BETA", ix, iy, 0. );
00600 }
00601
00602 setVal( "TIME_MEAN", ix, iy, apdpn_apdpn[iTime][iMean] );
00603 setVal( "TIME_RMS", ix, iy, apdpn_apdpn[iTime][iRMS] );
00604 setVal( "TIME_M3", ix, iy, apdpn_apdpn[iTime][iM3] );
00605 setVal( "TIME_NEVT", ix, iy, apdpn_apdpn[iTime][iNevt] );
00606
00607 }
00608
00609
00610
00611
00612
00613 t_name = lmfLaserName( ME::iLmfLaserPnPrim, _type, _color );
00614
00615 nentries = pn_tree->GetEntriesFast();
00616 assert( nentries%2==0 );
00617 int module_(0);
00618 id1_=_sm; id2_=0;
00619
00620 Long64_t jentry=0;
00621
00622 while( jentry<nentries )
00623 {
00624 for( int jj=0; jj<2; jj++ )
00625 {
00626
00627
00628
00629 int zentry = jentry+jj;
00630 assert( zentry<nentries );
00631
00632 ientry = pn_tree->LoadTree( zentry );
00633 assert( ientry>=0 );
00634 pn_tree->GetEntry( zentry );
00635
00636 if( _side!=pn_side ) break;
00637
00638 if( jj==1 ) assert( pn_moduleID==module_ );
00639 module_ = pn_moduleID;
00640 assert( pn_pnID==jj );
00641
00642
00643 std::pair<int,int> memPn_ = ME::pn( _lmr, module_, (ME::PN)jj );
00644 if( _isBarrel )
00645 {
00646
00647 id1_ = _sm;
00648 id2_ = memPn_.second;
00649 }
00650 else
00651 {
00652 int dee_ = MEEEGeom::dee( _lmr );
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675 id1_ = dee_;
00676 id2_ = (jj+1)*100+memPn_.second;
00677 }
00678
00679 if( _isBarrel )
00680 {
00681 channelView_ = iEB_LM_PN;
00682 }
00683 else
00684 {
00685 channelView_ = iEE_LM_PN;
00686 }
00687 logic_id_ = logicId( channelView_, id1_, id2_ );
00688
00689 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00690 f_t[t_name+separator+"MEAN"] = pn_PN[iMean];
00691 f_t[t_name+separator+"RMS"] = pn_PN[iRMS];
00692 f_t[t_name+separator+"M3"] = pn_PN[iM3];
00693 f_t[t_name+separator+"PNA_OVER_PNB_MEAN"] = (jj==0) ? pn_PNoPNB[iMean] : pn_PNoPNA[iMean];
00694 f_t[t_name+separator+"PNA_OVER_PNB_RMS" ] = (jj==0) ? pn_PNoPNB[iRMS] : pn_PNoPNA[iRMS];
00695 f_t[t_name+separator+"PNA_OVER_PNB_M3"] = (jj==0) ? pn_PNoPNB[iM3] : pn_PNoPNA[iM3];
00696
00697 t_t[t_name]->Fill();
00698
00699 }
00700
00701
00702
00703
00704
00705
00706 jentry += 2;
00707 }
00708
00709 logic_id_ = logicId( iECAL_LMR, _lmr );
00710
00711
00712
00713
00714
00715 if(mtq_tree){
00716
00717 t_name = lmfLaserName( ME::iLmfLaserPulse, _type, _color );
00718
00719 nentries = mtq_tree->GetEntriesFast();
00720 assert( nentries==2 );
00721 for( Long64_t jentry=0; jentry<nentries; jentry++ )
00722 {
00723 ientry = mtq_tree->LoadTree( jentry );
00724 assert( ientry>=0 );
00725 mtq_tree->GetEntry( jentry );
00726
00727 if ( mtq_side != _side ) continue;
00728
00729 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00730 i_t[t_name+separator+"FIT_METHOD"] = 0 ;
00731 f_t[t_name+separator+"MTQ_AMPL"] = mtq_mtq[iAmpl];
00732 f_t[t_name+separator+"MTQ_TIME"] = mtq_mtq[iPeak];
00733 f_t[t_name+separator+"MTQ_RISE"] = mtq_mtq[iTrise];
00734 f_t[t_name+separator+"MTQ_FWHM"] = mtq_mtq[iFwhm];
00735 f_t[t_name+separator+"MTQ_FW20"] = mtq_mtq[iFw20];
00736 f_t[t_name+separator+"MTQ_FW80"] = mtq_mtq[iFw80];
00737 f_t[t_name+separator+"MTQ_SLIDING"] = mtq_mtq[iSlide];
00738
00739 t_t[t_name]->Fill();
00740 }
00741 }else{
00742
00743 t_name = lmfLaserName( ME::iLmfLaserPulse, _type, _color );
00744
00745 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00746 i_t[t_name+separator+"FIT_METHOD"] = 0 ;
00747 f_t[t_name+separator+"MTQ_AMPL"] = 0.0;
00748 f_t[t_name+separator+"MTQ_TIME"] = 0.0;
00749 f_t[t_name+separator+"MTQ_RISE"] = 0.0;
00750 f_t[t_name+separator+"MTQ_FWHM"] = 0.0;
00751 f_t[t_name+separator+"MTQ_FW20"] = 0.0;
00752 f_t[t_name+separator+"MTQ_FW80"] = 0.0;
00753 f_t[t_name+separator+"MTQ_SLIDING"] = 0.0;
00754
00755 t_t[t_name]->Fill();
00756 }
00757
00758
00759
00760
00761 t_name = lmfLaserName( ME::iLmfLaserRun, _type );
00762
00763 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00764 i_t[t_name+separator+"NEVENTS"] = _events;
00765 i_t[t_name+separator+"QUALITY_FLAG"] = 1;
00766 t_t[t_name]->Fill();
00767
00768
00769
00770
00771 t_name = lmfLaserName( ME::iLmfLaserConfig, _type );
00772
00773 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00774 i_t[t_name+separator+"WAVELENGTH"] = _color;
00775 i_t[t_name+separator+"VFE_GAIN"] = _mgpagain;
00776 i_t[t_name+separator+"PN_GAIN"] = _memgain;
00777 i_t[t_name+separator+"LSR_POWER"] = _power;
00778 i_t[t_name+separator+"LSR_ATTENUATOR"] = _filter;
00779 i_t[t_name+separator+"LSR_CURRENT"] = 0;
00780 i_t[t_name+separator+"LSR_DELAY_1"] = _delay;
00781 i_t[t_name+separator+"LSR_DELAY_2"] = 0;
00782 t_t[t_name]->Fill();
00783
00784 }
00785 else if( _type==ME::iTestPulse )
00786 {
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911 }
00912
00913
00914
00915
00916 t_name = "LMF_RUN_IOV";
00917
00918 i_t[t_name+separator+"TAG_ID"] = 0;
00919 i_t[t_name+separator+"SUB_RUN_NUM"] = _run;
00920 i_t[t_name+separator+"SUB_RUN_START_LOW" ] = ME::time_low( _ts_beg );
00921 i_t[t_name+separator+"SUB_RUN_START_HIGH"] = ME::time_high( _ts_beg );
00922 i_t[t_name+separator+"SUB_RUN_END_LOW" ] = ME::time_low( _ts_end );
00923 i_t[t_name+separator+"SUB_RUN_END_HIGH" ] = ME::time_high( _ts_end );
00924 i_t[t_name+separator+"DB_TIMESTAMP_LOW" ] = ME::time_low( _ts );
00925 i_t[t_name+separator+"DB_TIMESTAMP_HIGH" ] = ME::time_high( _ts );
00926 c_t[t_name+separator+"SUB_RUN_TYPE"] = "LASER TEST CRUZET";
00927 t_t[t_name]->Fill();
00928
00929 }
00930
00931 void
00932 MELaserPrim::writeHistograms()
00933 {
00934 if( !init_ok ) return;
00935
00936 out_file = new TFile( _outfile, "RECREATE" );
00937
00938
00939 std::map< TString, TH2* >::iterator it;
00940
00941 for( it=i_h.begin(); it!=i_h.end(); it++ )
00942 {
00943 it->second->Write();
00944 delete it->second;
00945 }
00946
00947 for( it=f_h.begin(); it!=f_h.end(); it++ )
00948 {
00949 it->second->Write();
00950 delete it->second;
00951 }
00952
00953 std::map< TString, TTree* >::iterator it_t;
00954 for( it_t=t_t.begin(); it_t!=t_t.end(); it_t++ )
00955 {
00956 it_t->second->Write();
00957 delete it_t->second;
00958 }
00959
00960
00961 out_file->Close();
00962 delete out_file;
00963 out_file=0;
00964 }
00965
00966 MELaserPrim::~MELaserPrim()
00967 {
00968 delete apdpn_tree;
00969 delete ab_tree;
00970 delete pn_tree;
00971 delete mtq_tree;
00972 delete tpapd_tree;
00973 delete tppn_tree;
00974 if( apdpn_file!=0 )
00975 {
00976
00977 apdpn_file->Close();
00978 delete apdpn_file;
00979 apdpn_file = 0;
00980 }
00981 if( ab_file!=0 )
00982 {
00983
00984 ab_file->Close();
00985 delete ab_file;
00986 ab_file = 0;
00987 }
00988 if( mtq_file!=0 )
00989 {
00990
00991 mtq_file->Close();
00992 delete mtq_file;
00993 mtq_file = 0;
00994 }
00995 if( tpapd_file!=0 )
00996 {
00997
00998 tpapd_file->Close();
00999 delete tpapd_file;
01000 tpapd_file = 0;
01001 }
01002 }
01003
01004 void
01005 MELaserPrim::print( ostream& o )
01006 {
01007 o << "DCC/SM/side/type/color/run/ts " << _dcc << "/" << _sm << "/" << _side << "/"
01008 << _type << "/" << _color << "/" << _run << "/" << _ts << std::endl;
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021 }
01022
01023 TString
01024 MELaserPrim::lmfLaserName( int table, int type, int color )
01025 {
01026 TString str("LMF_ERROR");
01027 if( table<0 || table>=ME::iSizeLmf ) return str;
01028 if( color<0 || color>=ME::iSizeC ) return str;
01029
01030 if( type==ME::iLaser )
01031 {
01032 TString colstr;
01033 switch( color )
01034 {
01035 case ME::iBlue: colstr = "_BLUE"; break;
01036 case ME::iGreen: colstr = "_GREEN"; break;
01037 case ME::iRed: colstr = "_RED"; break;
01038 case ME::iIRed: colstr = "_IRED"; break;
01039 default: abort();
01040 }
01041 str = "LMF_LASER";
01042 switch( table )
01043 {
01044 case ME::iLmfLaserRun: str = "LMF_RUN"; break;
01045 case ME::iLmfLaserConfig: str += "_CONFIG"; break;
01046 case ME::iLmfLaserPulse: str += colstr; str += "_PULSE"; break;
01047 case ME::iLmfLaserPrim: str += colstr; str += "_PRIM"; break;
01048 case ME::iLmfLaserPnPrim: str += colstr; str += "_PN_PRIM"; break;
01049 default: abort();
01050 }
01051 }
01052 else if( type==ME::iTestPulse )
01053 {
01054 str = "LMF_TEST_PULSE";
01055 switch( table )
01056 {
01057 case ME::iLmfTestPulseRun: str = "LMF_RUN"; break;
01058 case ME::iLmfTestPulseConfig: str += "_CONFIG"; break;
01059 case ME::iLmfTestPulsePrim: str += "_PRIM"; break;
01060 case ME::iLmfTestPulsePnPrim: str += "_PN_PRIM"; break;
01061 default: abort();
01062 }
01063 }
01064 str += "_DAT";
01065 return str;
01066 }
01067
01068 void
01069 MELaserPrim::addBranchI( const char* t_name_, const char* v_name_ )
01070 {
01071 TString slashI("/i");
01072 TString t_name(t_name_);
01073 TString v_name(v_name_);
01074 if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
01075 t_t[t_name]->Branch(v_name, &i_t[t_name+separator+v_name],v_name+slashI);
01076 }
01077
01078 void
01079 MELaserPrim::addBranchF( const char* t_name_, const char* v_name_ )
01080 {
01081 TString slashF("/F");
01082 TString t_name(t_name_);
01083 TString v_name(v_name_);
01084 if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
01085 t_t[t_name]->Branch(v_name, &f_t[t_name+separator+v_name],v_name+slashF);
01086 }
01087
01088 void
01089 MELaserPrim::addBranchC( const char* t_name_, const char* v_name_ )
01090 {
01091 TString slashC("/C");
01092 TString t_name(t_name_);
01093 TString v_name(v_name_);
01094 if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
01095 t_t[t_name]->Branch(v_name, &c_t[t_name+separator+v_name],v_name+slashC);
01096 }
01097
01098 void
01099 MELaserPrim::bookHistoI( const char* h_name_, const char* v_name_ )
01100 {
01101 TString i_name = TString(h_name_)+TString(v_name_);
01102 TH2* h_ = new TH2I(i_name,i_name,nx,ixmin,ixmax,ny,iymin,iymax);
01103 setHistoStyle( h_ );
01104 i_h[i_name] = h_;
01105 }
01106
01107 void
01108 MELaserPrim::bookHistoF( const char* h_name_, const char* v_name_ )
01109 {
01110 TString d_name = TString(h_name_)+TString(v_name_);
01111 TH2* h_ = new TH2F(d_name,d_name,nx,ixmin,ixmax,ny,iymin,iymax);
01112 setHistoStyle( h_ );
01113 f_h[d_name] = h_;
01114 }
01115
01116
01117 bool
01118 MELaserPrim::setInt( const char* name, int ix, int iy, int ival )
01119 {
01120 TString name_;
01121 if( _type==ME::iLaser ) name_=_primStr+name;
01122 else if( _type==ME::iTestPulse ) name_=_tpPrimStr+name;
01123
01124 int _ival = getInt( name_, ix, iy );
01125 assert( _ival!=-99 );
01126 if( _ival!=0 ) return false;
01127
01128 TH2I* h_ = (TH2I*) i_h[name_];
01129 assert( h_!=0 );
01130 h_->Fill( ix+0.5, iy+0.5, ival );
01131
01132 return true;
01133 }
01134
01135 bool
01136 MELaserPrim::setVal( const char* name, int ix, int iy, float val )
01137 {
01138 TString name_;
01139 if( _type==ME::iLaser ) name_=_primStr+name;
01140 else if( _type==ME::iTestPulse ) name_=_tpPrimStr+name;
01141
01142 float _val = getVal( name_, ix, iy );
01143 assert( _val!=-99 );
01144 if( _val!=0 ) return false;
01145
01146 TH2F* h_ = (TH2F*) f_h[name_];
01147 assert( h_!=0 );
01148
01149 h_->Fill( ix+0.5, iy+0.5, val );
01150
01151 return true;
01152 }
01153
01154 Int_t
01155 MELaserPrim::getInt( const char* name, int ix, int iy )
01156 {
01157 Int_t ival=-99;
01158 if( i_h.count(name)==1 )
01159 {
01160 TH2I* h_ = (TH2I*) i_h[name];
01161 assert( h_!=0 );
01162 int binx = h_->GetXaxis()->FindBin( ix+0.5 );
01163 int biny = h_->GetYaxis()->FindBin( iy+0.5 );
01164 ival = (Int_t) h_->GetCellContent( binx, biny );
01165 }
01166 return ival;
01167 }
01168
01169 Float_t
01170 MELaserPrim::getVal( const char* name, int ix, int iy )
01171 {
01172 Float_t val=-99.;
01173 if( f_h.count(name)==1 )
01174 {
01175 TH2F* h_ = (TH2F*) f_h[name];
01176 assert( h_!=0 );
01177 int binx = h_->GetXaxis()->FindBin( ix+0.5 );
01178 int biny = h_->GetYaxis()->FindBin( iy+0.5 );
01179 val = h_->GetCellContent( binx, biny );
01180 }
01181 return val;
01182 }
01183
01184 bool
01185 MELaserPrim::setInt( const char* tname, const char* vname, int ival )
01186 {
01187 TString key_(tname); key_ += separator; key_ += vname;
01188 assert( i_t.count(key_)==1 );
01189 i_t[key_] = ival;
01190 return true;
01191 }
01192
01193 bool
01194 MELaserPrim::setVal( const char* tname, const char* vname, float val )
01195 {
01196 TString key_(tname); key_ += separator; key_ += vname;
01197
01198
01199 if( f_t.count(key_)!=1 )
01200 {
01201 std::cout << key_ << std::endl;
01202 }
01203 assert( f_t.count(key_)==1 );
01204 f_t[key_] = val;
01205 return true;
01206 }
01207
01208 bool
01209 MELaserPrim::fill( const char* tname )
01210 {
01211 TString key_( tname );
01212 assert( t_t.count(key_)==1 );
01213 t_t[key_] -> Fill();
01214 return true;
01215 }
01216
01217 void
01218 MELaserPrim::setHistoStyle( TH1* h )
01219 {
01220 if( h==0 ) return;
01221
01222 float _scale = 1;
01223
01224 h->SetLineColor(4);
01225 h->SetLineWidth(1);
01226 h->SetFillColor(38);
01227 TAxis* axis[3];
01228 axis[0] = h->GetXaxis();
01229 axis[1] = h->GetYaxis();
01230 axis[2] = h->GetZaxis();
01231 for( int ii=0; ii<3; ii++ )
01232 {
01233 TAxis* a = axis[ii];
01234 if( !a ) continue;
01235 a->SetLabelFont(132);
01236 a->SetLabelOffset(_scale*0.005);
01237 a->SetLabelSize(_scale*0.04);
01238 a->SetTitleFont(132);
01239 a->SetTitleOffset(_scale*1);
01240 a->SetTitleSize(_scale*0.04);
01241 }
01242 h->SetStats( kTRUE );
01243 }
01244
01245 void
01246 MELaserPrim::refresh()
01247 {
01248 std::map< TString, TH2* >::iterator it;
01249
01250 for( it=i_h.begin(); it!=i_h.end(); it++ )
01251 {
01252 delete it->second;
01253 it->second = 0;
01254 }
01255 i_h.clear();
01256
01257 for( it=f_h.begin(); it!=f_h.end(); it++ )
01258 {
01259 delete it->second;
01260 it->second = 0;
01261 }
01262 f_h.clear();
01263
01264 std::map< TString, TTree* >::iterator it_t;
01265 for( it_t=t_t.begin(); it_t!=t_t.end(); it_t++ )
01266 {
01267 delete it_t->second;
01268 it->second = 0;
01269 }
01270 t_t.clear();
01271 }