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 nb = 0;
00511 Long64_t nentries = 0;
00512 Long64_t ientry = 0;
00513
00514 int channelView_(0);
00515 int id1_(0), id2_(0);
00516 int logic_id_(0);
00517
00518 if( _type==ME::iLaser )
00519 {
00520
00521 nentries = apdpn_tree->GetEntriesFast();
00522 for( Long64_t jentry=0; jentry<nentries; jentry++ )
00523 {
00524 ientry = apdpn_tree->LoadTree( jentry );
00525 assert( ientry>=0 );
00526 nb = apdpn_tree->GetEntry( jentry );
00527
00528 if(ab_tree){
00529 ientry = ab_tree->LoadTree( jentry );
00530 assert( ientry>=0 );
00531 nb = ab_tree->GetEntry( jentry );
00532 }
00533
00534
00535 if( apdpn_iphi<0 ) continue;
00536
00537
00538
00539
00540 int ix(0);
00541 int iy(0);
00542 if( _isBarrel )
00543 {
00544
00545 id1_ = _sm;
00546 if ( apdpn_side != _side ) continue;
00547 int ieta=apdpn_ieta;
00548 int iphi=apdpn_iphi;
00549 MEEBGeom::XYCoord xy_ = MEEBGeom::localCoord( ieta, iphi );
00550 ix = xy_.first;
00551 iy = xy_.second;
00552 id2_ = MEEBGeom::crystal_channel( ix, iy );
00553 channelView_ = iEB_crystal_number;
00554 }
00555 else
00556 {
00557
00558 id1_ = apdpn_iphi;
00559 id2_ = apdpn_ieta;
00560 ix = id1_;
00561 iy = id2_;
00562 channelView_ = iEE_crystal_number;
00563 }
00564
00565 logic_id_ = logicId( channelView_, id1_, id2_ );
00566
00567 int flag = apdpn_flag;
00568
00569 setInt( "LOGIC_ID", ix, iy, logic_id_ );
00570 setInt( "FLAG", ix, iy, flag );
00571 setVal( "MEAN", ix, iy, apdpn_apdpn[iAPD][iMean] );
00572 setVal( "RMS", ix, iy, apdpn_apdpn[iAPD][iRMS] );
00573 setVal( "M3", ix, iy, apdpn_apdpn[iAPD][iM3] );
00574 setVal( "APD_OVER_PNA_MEAN", ix, iy, apdpn_apdpn[iAPDoPNA][iMean] );
00575 setVal( "APD_OVER_PNA_RMS", ix, iy, apdpn_apdpn[iAPDoPNA][iRMS] );
00576 setVal( "APD_OVER_PNA_M3", ix, iy, apdpn_apdpn[iAPDoPNA][iM3] );
00577 setVal( "APD_OVER_PNB_MEAN", ix, iy, apdpn_apdpn[iAPDoPNB][iMean] );
00578 setVal( "APD_OVER_PNB_RMS", ix, iy, apdpn_apdpn[iAPDoPNB][iRMS] );
00579 setVal( "APD_OVER_PNB_M3", ix, iy, apdpn_apdpn[iAPDoPNB][iM3] );
00580 setVal( "APD_OVER_PN_MEAN", ix, iy, apdpn_apdpn[iAPDoPN][iMean] );
00581 setVal( "APD_OVER_PN_RMS", ix, iy, apdpn_apdpn[iAPDoPN][iRMS] );
00582 setVal( "APD_OVER_PN_M3", ix, iy, apdpn_apdpn[iAPDoPN][iM3] );
00583
00584 setVal( "APD_OVER_APD_MEAN", ix, iy, apdpn_apdpn[iAPDoAPDA][iMean] );
00585 setVal( "APD_OVER_APD_RMS", ix, iy, apdpn_apdpn[iAPDoAPDA][iRMS] );
00586 setVal( "APD_OVER_APD_M3", ix, iy, apdpn_apdpn[iAPDoAPDA][iM3] );
00587 setVal( "APD_OVER_APDA_MEAN", ix, iy, apdpn_apdpn[iAPDoAPDA][iMean] );
00588 setVal( "APD_OVER_APDA_RMS", ix, iy, apdpn_apdpn[iAPDoAPDA][iRMS] );
00589 setVal( "APD_OVER_APDA_M3", ix, iy, apdpn_apdpn[iAPDoAPDA][iM3] );
00590 setVal( "APD_OVER_APDB_MEAN", ix, iy, apdpn_apdpn[iAPDoAPDB][iMean] );
00591 setVal( "APD_OVER_APDB_RMS", ix, iy, apdpn_apdpn[iAPDoAPDB][iRMS] );
00592 setVal( "APD_OVER_APDB_M3", ix, iy, apdpn_apdpn[iAPDoAPDB][iM3] );
00593
00594 setVal( "SHAPE_COR", ix, iy, apdpn_ShapeCor );
00595 if(ab_tree){
00596 setVal( "ALPHA", ix, iy, ab_ab[iAlpha] );
00597 setVal( "BETA", ix, iy, ab_ab[iBeta] );
00598 }else{
00599 setVal( "ALPHA", ix, iy, 0. );
00600 setVal( "BETA", ix, iy, 0. );
00601 }
00602
00603 setVal( "TIME_MEAN", ix, iy, apdpn_apdpn[iTime][iMean] );
00604 setVal( "TIME_RMS", ix, iy, apdpn_apdpn[iTime][iRMS] );
00605 setVal( "TIME_M3", ix, iy, apdpn_apdpn[iTime][iM3] );
00606 setVal( "TIME_NEVT", ix, iy, apdpn_apdpn[iTime][iNevt] );
00607
00608 }
00609
00610
00611
00612
00613
00614 t_name = lmfLaserName( ME::iLmfLaserPnPrim, _type, _color );
00615
00616 nentries = pn_tree->GetEntriesFast();
00617 assert( nentries%2==0 );
00618 int module_(0);
00619 id1_=_sm; id2_=0;
00620
00621 Long64_t jentry=0;
00622
00623 while( jentry<nentries )
00624 {
00625 for( int jj=0; jj<2; jj++ )
00626 {
00627
00628
00629
00630 int zentry = jentry+jj;
00631 assert( zentry<nentries );
00632
00633 ientry = pn_tree->LoadTree( zentry );
00634 assert( ientry>=0 );
00635 nb = pn_tree->GetEntry( zentry );
00636
00637 if( _side!=pn_side ) break;
00638
00639 if( jj==1 ) assert( pn_moduleID==module_ );
00640 module_ = pn_moduleID;
00641 assert( pn_pnID==jj );
00642
00643
00644 std::pair<int,int> memPn_ = ME::pn( _lmr, module_, (ME::PN)jj );
00645 if( _isBarrel )
00646 {
00647
00648 id1_ = _sm;
00649 id2_ = memPn_.second;
00650 }
00651 else
00652 {
00653 int dee_ = MEEEGeom::dee( _lmr );
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676 id1_ = dee_;
00677 id2_ = (jj+1)*100+memPn_.second;
00678 }
00679
00680 if( _isBarrel )
00681 {
00682 channelView_ = iEB_LM_PN;
00683 }
00684 else
00685 {
00686 channelView_ = iEE_LM_PN;
00687 }
00688 logic_id_ = logicId( channelView_, id1_, id2_ );
00689
00690 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00691 f_t[t_name+separator+"MEAN"] = pn_PN[iMean];
00692 f_t[t_name+separator+"RMS"] = pn_PN[iRMS];
00693 f_t[t_name+separator+"M3"] = pn_PN[iM3];
00694 f_t[t_name+separator+"PNA_OVER_PNB_MEAN"] = (jj==0) ? pn_PNoPNB[iMean] : pn_PNoPNA[iMean];
00695 f_t[t_name+separator+"PNA_OVER_PNB_RMS" ] = (jj==0) ? pn_PNoPNB[iRMS] : pn_PNoPNA[iRMS];
00696 f_t[t_name+separator+"PNA_OVER_PNB_M3"] = (jj==0) ? pn_PNoPNB[iM3] : pn_PNoPNA[iM3];
00697
00698 t_t[t_name]->Fill();
00699
00700 }
00701
00702
00703
00704
00705
00706
00707 jentry += 2;
00708 }
00709
00710 logic_id_ = logicId( iECAL_LMR, _lmr );
00711
00712
00713
00714
00715
00716 if(mtq_tree){
00717
00718 t_name = lmfLaserName( ME::iLmfLaserPulse, _type, _color );
00719
00720 nentries = mtq_tree->GetEntriesFast();
00721 assert( nentries==2 );
00722 for( Long64_t jentry=0; jentry<nentries; jentry++ )
00723 {
00724 ientry = mtq_tree->LoadTree( jentry );
00725 assert( ientry>=0 );
00726 nb = mtq_tree->GetEntry( jentry );
00727
00728 if ( mtq_side != _side ) continue;
00729
00730 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00731 i_t[t_name+separator+"FIT_METHOD"] = 0 ;
00732 f_t[t_name+separator+"MTQ_AMPL"] = mtq_mtq[iAmpl];
00733 f_t[t_name+separator+"MTQ_TIME"] = mtq_mtq[iPeak];
00734 f_t[t_name+separator+"MTQ_RISE"] = mtq_mtq[iTrise];
00735 f_t[t_name+separator+"MTQ_FWHM"] = mtq_mtq[iFwhm];
00736 f_t[t_name+separator+"MTQ_FW20"] = mtq_mtq[iFw20];
00737 f_t[t_name+separator+"MTQ_FW80"] = mtq_mtq[iFw80];
00738 f_t[t_name+separator+"MTQ_SLIDING"] = mtq_mtq[iSlide];
00739
00740 t_t[t_name]->Fill();
00741 }
00742 }else{
00743
00744 t_name = lmfLaserName( ME::iLmfLaserPulse, _type, _color );
00745
00746 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00747 i_t[t_name+separator+"FIT_METHOD"] = 0 ;
00748 f_t[t_name+separator+"MTQ_AMPL"] = 0.0;
00749 f_t[t_name+separator+"MTQ_TIME"] = 0.0;
00750 f_t[t_name+separator+"MTQ_RISE"] = 0.0;
00751 f_t[t_name+separator+"MTQ_FWHM"] = 0.0;
00752 f_t[t_name+separator+"MTQ_FW20"] = 0.0;
00753 f_t[t_name+separator+"MTQ_FW80"] = 0.0;
00754 f_t[t_name+separator+"MTQ_SLIDING"] = 0.0;
00755
00756 t_t[t_name]->Fill();
00757 }
00758
00759
00760
00761
00762 t_name = lmfLaserName( ME::iLmfLaserRun, _type );
00763
00764 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00765 i_t[t_name+separator+"NEVENTS"] = _events;
00766 i_t[t_name+separator+"QUALITY_FLAG"] = 1;
00767 t_t[t_name]->Fill();
00768
00769
00770
00771
00772 t_name = lmfLaserName( ME::iLmfLaserConfig, _type );
00773
00774 i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00775 i_t[t_name+separator+"WAVELENGTH"] = _color;
00776 i_t[t_name+separator+"VFE_GAIN"] = _mgpagain;
00777 i_t[t_name+separator+"PN_GAIN"] = _memgain;
00778 i_t[t_name+separator+"LSR_POWER"] = _power;
00779 i_t[t_name+separator+"LSR_ATTENUATOR"] = _filter;
00780 i_t[t_name+separator+"LSR_CURRENT"] = 0;
00781 i_t[t_name+separator+"LSR_DELAY_1"] = _delay;
00782 i_t[t_name+separator+"LSR_DELAY_2"] = 0;
00783 t_t[t_name]->Fill();
00784
00785 }
00786 else if( _type==ME::iTestPulse )
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
00917 t_name = "LMF_RUN_IOV";
00918
00919 i_t[t_name+separator+"TAG_ID"] = 0;
00920 i_t[t_name+separator+"SUB_RUN_NUM"] = _run;
00921 i_t[t_name+separator+"SUB_RUN_START_LOW" ] = ME::time_low( _ts_beg );
00922 i_t[t_name+separator+"SUB_RUN_START_HIGH"] = ME::time_high( _ts_beg );
00923 i_t[t_name+separator+"SUB_RUN_END_LOW" ] = ME::time_low( _ts_end );
00924 i_t[t_name+separator+"SUB_RUN_END_HIGH" ] = ME::time_high( _ts_end );
00925 i_t[t_name+separator+"DB_TIMESTAMP_LOW" ] = ME::time_low( _ts );
00926 i_t[t_name+separator+"DB_TIMESTAMP_HIGH" ] = ME::time_high( _ts );
00927 c_t[t_name+separator+"SUB_RUN_TYPE"] = "LASER TEST CRUZET";
00928 t_t[t_name]->Fill();
00929
00930 }
00931
00932 void
00933 MELaserPrim::writeHistograms()
00934 {
00935 if( !init_ok ) return;
00936
00937 out_file = new TFile( _outfile, "RECREATE" );
00938
00939
00940 std::map< TString, TH2* >::iterator it;
00941
00942 for( it=i_h.begin(); it!=i_h.end(); it++ )
00943 {
00944 it->second->Write();
00945 delete it->second;
00946 }
00947
00948 for( it=f_h.begin(); it!=f_h.end(); it++ )
00949 {
00950 it->second->Write();
00951 delete it->second;
00952 }
00953
00954 std::map< TString, TTree* >::iterator it_t;
00955 for( it_t=t_t.begin(); it_t!=t_t.end(); it_t++ )
00956 {
00957 it_t->second->Write();
00958 delete it_t->second;
00959 }
00960
00961
00962 out_file->Close();
00963 delete out_file;
00964 out_file=0;
00965 }
00966
00967 MELaserPrim::~MELaserPrim()
00968 {
00969 delete apdpn_tree;
00970 delete ab_tree;
00971 delete pn_tree;
00972 delete mtq_tree;
00973 delete tpapd_tree;
00974 delete tppn_tree;
00975 if( apdpn_file!=0 )
00976 {
00977
00978 apdpn_file->Close();
00979 delete apdpn_file;
00980 apdpn_file = 0;
00981 }
00982 if( ab_file!=0 )
00983 {
00984
00985 ab_file->Close();
00986 delete ab_file;
00987 ab_file = 0;
00988 }
00989 if( mtq_file!=0 )
00990 {
00991
00992 mtq_file->Close();
00993 delete mtq_file;
00994 mtq_file = 0;
00995 }
00996 if( tpapd_file!=0 )
00997 {
00998
00999 tpapd_file->Close();
01000 delete tpapd_file;
01001 tpapd_file = 0;
01002 }
01003 }
01004
01005 void
01006 MELaserPrim::print( ostream& o )
01007 {
01008 o << "DCC/SM/side/type/color/run/ts " << _dcc << "/" << _sm << "/" << _side << "/"
01009 << _type << "/" << _color << "/" << _run << "/" << _ts << std::endl;
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022 }
01023
01024 TString
01025 MELaserPrim::lmfLaserName( int table, int type, int color )
01026 {
01027 TString str("LMF_ERROR");
01028 if( table<0 || table>=ME::iSizeLmf ) return str;
01029 if( color<0 || color>=ME::iSizeC ) return str;
01030
01031 if( type==ME::iLaser )
01032 {
01033 TString colstr;
01034 switch( color )
01035 {
01036 case ME::iBlue: colstr = "_BLUE"; break;
01037 case ME::iGreen: colstr = "_GREEN"; break;
01038 case ME::iRed: colstr = "_RED"; break;
01039 case ME::iIRed: colstr = "_IRED"; break;
01040 default: abort();
01041 }
01042 str = "LMF_LASER";
01043 switch( table )
01044 {
01045 case ME::iLmfLaserRun: str = "LMF_RUN"; break;
01046 case ME::iLmfLaserConfig: str += "_CONFIG"; break;
01047 case ME::iLmfLaserPulse: str += colstr; str += "_PULSE"; break;
01048 case ME::iLmfLaserPrim: str += colstr; str += "_PRIM"; break;
01049 case ME::iLmfLaserPnPrim: str += colstr; str += "_PN_PRIM"; break;
01050 default: abort();
01051 }
01052 }
01053 else if( type==ME::iTestPulse )
01054 {
01055 str = "LMF_TEST_PULSE";
01056 switch( table )
01057 {
01058 case ME::iLmfTestPulseRun: str = "LMF_RUN"; break;
01059 case ME::iLmfTestPulseConfig: str += "_CONFIG"; break;
01060 case ME::iLmfTestPulsePrim: str += "_PRIM"; break;
01061 case ME::iLmfTestPulsePnPrim: str += "_PN_PRIM"; break;
01062 default: abort();
01063 }
01064 }
01065 str += "_DAT";
01066 return str;
01067 }
01068
01069 void
01070 MELaserPrim::addBranchI( const char* t_name_, const char* v_name_ )
01071 {
01072 TString slashI("/i");
01073 TString t_name(t_name_);
01074 TString v_name(v_name_);
01075 if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
01076 t_t[t_name]->Branch(v_name, &i_t[t_name+separator+v_name],v_name+slashI);
01077 }
01078
01079 void
01080 MELaserPrim::addBranchF( const char* t_name_, const char* v_name_ )
01081 {
01082 TString slashF("/F");
01083 TString t_name(t_name_);
01084 TString v_name(v_name_);
01085 if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
01086 t_t[t_name]->Branch(v_name, &f_t[t_name+separator+v_name],v_name+slashF);
01087 }
01088
01089 void
01090 MELaserPrim::addBranchC( const char* t_name_, const char* v_name_ )
01091 {
01092 TString slashC("/C");
01093 TString t_name(t_name_);
01094 TString v_name(v_name_);
01095 if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
01096 t_t[t_name]->Branch(v_name, &c_t[t_name+separator+v_name],v_name+slashC);
01097 }
01098
01099 void
01100 MELaserPrim::bookHistoI( const char* h_name_, const char* v_name_ )
01101 {
01102 TString i_name = TString(h_name_)+TString(v_name_);
01103 TH2* h_ = new TH2I(i_name,i_name,nx,ixmin,ixmax,ny,iymin,iymax);
01104 setHistoStyle( h_ );
01105 i_h[i_name] = h_;
01106 }
01107
01108 void
01109 MELaserPrim::bookHistoF( const char* h_name_, const char* v_name_ )
01110 {
01111 TString d_name = TString(h_name_)+TString(v_name_);
01112 TH2* h_ = new TH2F(d_name,d_name,nx,ixmin,ixmax,ny,iymin,iymax);
01113 setHistoStyle( h_ );
01114 f_h[d_name] = h_;
01115 }
01116
01117
01118 bool
01119 MELaserPrim::setInt( const char* name, int ix, int iy, int ival )
01120 {
01121 TString name_;
01122 if( _type==ME::iLaser ) name_=_primStr+name;
01123 else if( _type==ME::iTestPulse ) name_=_tpPrimStr+name;
01124
01125 int _ival = getInt( name_, ix, iy );
01126 assert( _ival!=-99 );
01127 if( _ival!=0 ) return false;
01128
01129 TH2I* h_ = (TH2I*) i_h[name_];
01130 assert( h_!=0 );
01131 h_->Fill( ix+0.5, iy+0.5, ival );
01132
01133 return true;
01134 }
01135
01136 bool
01137 MELaserPrim::setVal( const char* name, int ix, int iy, float val )
01138 {
01139 TString name_;
01140 if( _type==ME::iLaser ) name_=_primStr+name;
01141 else if( _type==ME::iTestPulse ) name_=_tpPrimStr+name;
01142
01143 float _val = getVal( name_, ix, iy );
01144 assert( _val!=-99 );
01145 if( _val!=0 ) return false;
01146
01147 TH2F* h_ = (TH2F*) f_h[name_];
01148 assert( h_!=0 );
01149
01150 h_->Fill( ix+0.5, iy+0.5, val );
01151
01152 return true;
01153 }
01154
01155 Int_t
01156 MELaserPrim::getInt( const char* name, int ix, int iy )
01157 {
01158 Int_t ival=-99;
01159 if( i_h.count(name)==1 )
01160 {
01161 TH2I* h_ = (TH2I*) i_h[name];
01162 assert( h_!=0 );
01163 int binx = h_->GetXaxis()->FindBin( ix+0.5 );
01164 int biny = h_->GetYaxis()->FindBin( iy+0.5 );
01165 ival = (Int_t) h_->GetCellContent( binx, biny );
01166 }
01167 return ival;
01168 }
01169
01170 Float_t
01171 MELaserPrim::getVal( const char* name, int ix, int iy )
01172 {
01173 Float_t val=-99.;
01174 if( f_h.count(name)==1 )
01175 {
01176 TH2F* h_ = (TH2F*) f_h[name];
01177 assert( h_!=0 );
01178 int binx = h_->GetXaxis()->FindBin( ix+0.5 );
01179 int biny = h_->GetYaxis()->FindBin( iy+0.5 );
01180 val = h_->GetCellContent( binx, biny );
01181 }
01182 return val;
01183 }
01184
01185 bool
01186 MELaserPrim::setInt( const char* tname, const char* vname, int ival )
01187 {
01188 TString key_(tname); key_ += separator; key_ += vname;
01189 assert( i_t.count(key_)==1 );
01190 i_t[key_] = ival;
01191 return true;
01192 }
01193
01194 bool
01195 MELaserPrim::setVal( const char* tname, const char* vname, float val )
01196 {
01197 TString key_(tname); key_ += separator; key_ += vname;
01198
01199
01200 if( f_t.count(key_)!=1 )
01201 {
01202 std::cout << key_ << std::endl;
01203 }
01204 assert( f_t.count(key_)==1 );
01205 f_t[key_] = val;
01206 return true;
01207 }
01208
01209 bool
01210 MELaserPrim::fill( const char* tname )
01211 {
01212 TString key_( tname );
01213 assert( t_t.count(key_)==1 );
01214 t_t[key_] -> Fill();
01215 return true;
01216 }
01217
01218 void
01219 MELaserPrim::setHistoStyle( TH1* h )
01220 {
01221 if( h==0 ) return;
01222
01223 float _scale = 1;
01224
01225 h->SetLineColor(4);
01226 h->SetLineWidth(1);
01227 h->SetFillColor(38);
01228 TAxis* axis[3];
01229 axis[0] = h->GetXaxis();
01230 axis[1] = h->GetYaxis();
01231 axis[2] = h->GetZaxis();
01232 for( int ii=0; ii<3; ii++ )
01233 {
01234 TAxis* a = axis[ii];
01235 if( !a ) continue;
01236 a->SetLabelFont(132);
01237 a->SetLabelOffset(_scale*0.005);
01238 a->SetLabelSize(_scale*0.04);
01239 a->SetTitleFont(132);
01240 a->SetTitleOffset(_scale*1);
01241 a->SetTitleSize(_scale*0.04);
01242 }
01243 h->SetStats( kTRUE );
01244 }
01245
01246 void
01247 MELaserPrim::refresh()
01248 {
01249 std::map< TString, TH2* >::iterator it;
01250
01251 for( it=i_h.begin(); it!=i_h.end(); it++ )
01252 {
01253 delete it->second;
01254 it->second = 0;
01255 }
01256 i_h.clear();
01257
01258 for( it=f_h.begin(); it!=f_h.end(); it++ )
01259 {
01260 delete it->second;
01261 it->second = 0;
01262 }
01263 f_h.clear();
01264
01265 std::map< TString, TTree* >::iterator it_t;
01266 for( it_t=t_t.begin(); it_t!=t_t.end(); it_t++ )
01267 {
01268 delete it_t->second;
01269 it->second = 0;
01270 }
01271 t_t.clear();
01272 }