CMS 3D CMS Logo

MELaserPrim.cc
Go to the documentation of this file.
1 #define MELaserPrim_cxx
2 #include <cassert>
5 #include <cassert>
6 #include <cstdlib>
7 
8 TString MELaserPrim::apdpn_arrayName[MELaserPrim::iSizeArray_apdpn] = {"APD", "APDoPN", "APDoPNA", "APDoPNB","APDoAPD","APDoAPDA", "APDoAPDB", "Time"};
9 TString MELaserPrim::apdpn_varName[MELaserPrim::iSize_apdpn] = { "Mean", "RMS", "M3", "Nevt", "Min", "Max"};
11 
12  { { " (ADC Counts)", " (ADC Counts)", " (ADC Counts)" ,"", " (ADC Counts)", " (ADC Counts)"},
13  {"", "", "", "", "", ""},
14  {"", "", "", "", "", ""},
15  {"", "", "", "", "", ""},
16  {"", "", "", "", "", ""},
17  {"", "", "", "", "", ""},
18  {" (25 ns)", " (25 ns)", " (25 ns)", "", " (25 ns)", " (25 ns)"} };
21 TString MELaserPrim::ab_varName[MELaserPrim::iSize_ab] = { "alpha", "beta", "width", "chi2" };
22 TString MELaserPrim::mtq_varName[MELaserPrim::iSize_mtq] = {"peak", "sigma", "fit", "ampl", "trise", "fwhm", "fw20", "fw80", "sliding" };
24  {"(nanoseconds)", "(nanoseconds)", "(nanoseconds)",
25  "(ADC counts)", "(nanoseconds)",
26  "(nanoseconds)", "(nanoseconds)", "(nanoseconds)", "(ADC counts)"};
27 
28 TString MELaserPrim::separator = "__";
29 
30 //ClassImp( MELaserPrim )
31 
33  const char* inpath, const char* outfile )
34 : init_ok(false), _isBarrel(true), _inpath(inpath), _outfile(outfile)
35 {
36  apdpn_file =nullptr;
37  ab_file =nullptr;
38  mtq_file =nullptr;
39  tpapd_file =nullptr;
40  apdpn_tree =nullptr;
41  ab_tree =nullptr;
42  pn_tree =nullptr;
43  mtq_tree =nullptr;
44  tpapd_tree =nullptr;
45  tppn_tree =nullptr;
46  ixmin =0;
47  ixmax =0;
48  iymin =0;
49  iymax =0;
50 
51  _dcc = header.dcc;
52  _side = header.side;
53  _run = header.run;
54  _lb = header.lb;
55  _events = header.events;
56  _ts = header.ts_beg;
57  _ts_beg = header.ts_beg;
58  _ts_end = header.ts_end;
59 
60  _type = settings.type;
61  _color = settings.wavelength;
62  _power = settings.power;
63  _filter = settings.filter;
64  _delay = settings.delay;
65  _mgpagain = settings.mgpagain;
66  _memgain = settings.memgain;
67 
68  if( _type==ME::iLaser )
69  {
73  }
74  else if( _type==ME::iTestPulse )
75  {
78  }
79 
80  _lmr = ME::lmr( _dcc, _side );
85  _regionStr += "_"; _regionStr += _side;
86 
87  init();
89  //fillHistograms();
90  //writeHistograms();
91 }
92 
93 TString
95 {
96  switch( iname )
97  {
98  case iECAL: return "ECAL";
99  case iECAL_LMR: return "ECAL_LMR";
100  case iEB_crystal_number: return "EB_crystal_number";
101  case iEB_LM_LMM: return "EB_LM_LMM";
102  case iEB_LM_PN: return "EB_LM_PN";
103  case iEE_crystal_number: return "EE_crystal_number";
104  case iEE_LM_LMM: return "EE_LM_LMM";
105  case iEE_LM_PN: return "EE_LM_PN";
106  default:
107  abort();
108  }
109  return "";
110 }
111 
112 int
113 MELaserPrim::logicId( int channelView, int id1, int id2 )
114 {
115  assert( channelView>=iECAL && channelView<iSize_cv );
116  return 1000000*channelView + 10000*id1 + id2;
117 }
118 
119 bool
120 MELaserPrim::getViewIds( int logic_id, int& channelView, int& id1, int& id2 )
121 {
122  bool out = true;
123  int channelView_ = logic_id/1000000;
124  if( channelView!=0 && channelView_!=channelView ) out=false;
125  channelView = channelView_;
126  id1 = (logic_id%1000000)/10000;
127  id2 = logic_id%10000;
128  return out;
129 }
130 
131 void
133 {
134  bool verbose_ = false;
135 
136  if( _inpath=="0" )
137  {
138  if( verbose_ ) std::cout << "no input file" << std::endl;
139  init_ok = true;
140  return; // GHM
141  }
142 
143  TString cur(_inpath);
144  if( !cur.EndsWith("/") ) cur+="/";
145 
146  if( _type==ME::iLaser )
147  {
148  TString _APDPN_fname =cur; _APDPN_fname += "APDPN_LASER.root";
149  TString _AB_fname =cur; _AB_fname += "AB.root";
150  TString _MTQ_fname =cur; _MTQ_fname += "MATACQ.root";
151 
152  bool apdpn_ok, ab_ok, pn_ok, mtq_ok;
153  apdpn_ok=false; ab_ok=false; pn_ok=false; mtq_ok=false;
154 
155  FILE *test;
156  test = fopen( _APDPN_fname,"r");
157  if (test) {
158  apdpn_ok = true;
159  pn_ok = true;
160  fclose( test );
161  }
162  test = fopen( _AB_fname,"r");
163  if (test)
164  {
165  ab_ok = true;
166  fclose( test );
167  }
168  test = fopen( _MTQ_fname,"r");
169  if (test)
170  {
171  mtq_ok = true;
172  fclose( test );
173  }
174 
175  if(apdpn_ok) apdpn_file = TFile::Open( _APDPN_fname );
176  if(ab_ok) ab_file = TFile::Open( _AB_fname );
177  if(mtq_ok) mtq_file = TFile::Open( _MTQ_fname );
178 
179  if( verbose_ )
180  {
181  std::cout << _APDPN_fname << " ok=" << apdpn_ok << std::endl;
182  std::cout << _AB_fname << " ok=" << ab_ok << std::endl;
183  std::cout << _MTQ_fname << " ok=" << mtq_ok << std::endl;
184  }
185  if (!apdpn_ok || !pn_ok ) return; // FIXME !
186 
187  TString apdpn_tree_name;
188  TString ab_tree_name;
189  TString pn_tree_name;
190  TString mtq_tree_name;
191 
192  apdpn_tree_name = "APDCol";
193  ab_tree_name = "ABCol";
194  pn_tree_name = "PNCol";
195  mtq_tree_name = "MatacqCol";
196 
197  apdpn_tree_name += _color;
198  ab_tree_name += _color;
199  pn_tree_name += _color;
200  mtq_tree_name += _color;
201 
202  if(mtq_ok) {
203  TTree *ckeckMtq = (TTree*) mtq_file->Get(mtq_tree_name);
204  if( ckeckMtq ==nullptr ) mtq_ok = false;
205  }
206 
207  if( _color != ME::iIRed && _color != ME::iBlue ){
208  std::cout << "MELaserPrim::init() -- Fatal Error -- Wrong Laser Color : " << _color << " ---- Abort " << std::endl;
209  return;
210  }
211 
212  apdpn_tree = (TTree*) apdpn_file->Get(apdpn_tree_name);
213  assert( apdpn_tree!=nullptr );
214  apdpn_tree->SetMakeClass(1);
215  apdpn_tree->SetBranchAddress("dccID", &apdpn_dccID, &b_apdpn_dccID);
216  apdpn_tree->SetBranchAddress("towerID", &apdpn_towerID, &b_apdpn_towerID);
217  apdpn_tree->SetBranchAddress("channelID", &apdpn_channelID, &b_apdpn_channelID);
218  apdpn_tree->SetBranchAddress("moduleID", &apdpn_moduleID, &b_apdpn_moduleID);
219  apdpn_tree->SetBranchAddress("side", &apdpn_side, &b_apdpn_side);
220  apdpn_tree->SetBranchAddress("ieta", &apdpn_ieta, &b_apdpn_ieta);
221  apdpn_tree->SetBranchAddress("iphi", &apdpn_iphi, &b_apdpn_iphi);
222  apdpn_tree->SetBranchAddress("flag", &apdpn_flag, &b_apdpn_flag);
223  if( apdpn_tree->GetBranchStatus("ShapeCor")) apdpn_tree->SetBranchAddress("ShapeCor", &apdpn_ShapeCor, &b_apdpn_ShapeCor);
224  else apdpn_ShapeCor = 0.0;
225  for( int jj=0; jj<iSizeArray_apdpn; jj++ )
226  {
227  TString name_ = apdpn_arrayName[jj];
228  apdpn_tree->SetBranchAddress(name_, apdpn_apdpn[jj], &b_apdpn_apdpn[jj]);
229  }
230 
231  if(ab_ok) {
232  ab_tree = (TTree*) ab_file->Get(ab_tree_name);
233  assert( ab_tree!=nullptr );
234  ab_tree->SetMakeClass(1);
235  ab_tree->SetBranchAddress("dccID", &ab_dccID, &b_ab_dccID );
236  ab_tree->SetBranchAddress("towerID", &ab_towerID, &b_ab_towerID );
237  ab_tree->SetBranchAddress("channelID", &ab_channelID, &b_ab_channelID );
238  ab_tree->SetBranchAddress("ieta", &ab_ieta, &b_ab_ieta );
239  ab_tree->SetBranchAddress("iphi", &ab_iphi, &b_ab_iphi );
240  ab_tree->SetBranchAddress("flag", &ab_flag, &b_ab_flag );
241  for( int ii=0; ii<iSize_ab; ii++ )
242  {
243  ab_tree->SetBranchAddress( ab_varName[ii], &ab_ab[ii], &b_ab_ab[ii] );
244  }
245  }
246 
247  pn_tree = (TTree*) apdpn_file->Get(pn_tree_name);
248  assert( pn_tree!=nullptr );
249  pn_tree->SetMakeClass(1);
250  pn_tree->SetBranchAddress( "side", &pn_side, &b_pn_side );
251  pn_tree->SetBranchAddress( "pnID", &pn_pnID, &b_pn_pnID );
252  pn_tree->SetBranchAddress( "moduleID", &pn_moduleID, &b_pn_moduleID );
253  pn_tree->SetBranchAddress( "PN", pn_PN, &b_pn_PN );
254  pn_tree->SetBranchAddress( "PNoPN", pn_PNoPN, &b_pn_PNoPN );
255  pn_tree->SetBranchAddress( "PNoPNA", pn_PNoPNA, &b_pn_PNoPNA );
256  pn_tree->SetBranchAddress( "PNoPNB", pn_PNoPNB, &b_pn_PNoPNB );
257 
258 
259  if( mtq_ok ) {
260  mtq_tree = (TTree*) mtq_file->Get(mtq_tree_name);
261  assert( mtq_tree!=nullptr );
262  mtq_tree->SetMakeClass(1);
263  mtq_tree->SetBranchAddress("side", &mtq_side, &b_mtq_side );
264 
265  for( int ii=0; ii<iSize_mtq; ii++ )
266  {
267  mtq_tree->SetBranchAddress( mtq_varName[ii], &mtq_mtq[ii], &b_mtq_mtq[ii] );
268  }
269  }
270  }
271  else if( _type==ME::iTestPulse )
272  {
273  TString _TPAPD_fname =cur; _TPAPD_fname += "APDPN_TESTPULSE.root";
274 
275  bool tpapd_ok;
276  tpapd_ok=false;
277 
278  FILE *test;
279  test = fopen( _TPAPD_fname,"r");
280  if (test) {
281  tpapd_ok = true;
282  fclose( test );
283  }
284 
285  if(tpapd_ok) tpapd_file = TFile::Open( _TPAPD_fname );
286 
287  if( verbose_ )
288  {
289  std::cout << _TPAPD_fname << " ok=" << tpapd_ok << std::endl;
290  }
291  if (!tpapd_ok ) return;
292 
293  TString tpapd_tree_name;
294  TString tppn_tree_name;
295 
296  tpapd_tree_name = "TPAPD";
297  tppn_tree_name = "TPPN";
298 
299  tpapd_tree = (TTree*) tpapd_file->Get(tpapd_tree_name);
300  assert( tpapd_tree!=nullptr );
301  tpapd_tree->SetMakeClass(1);
302  tpapd_tree->SetBranchAddress("ieta", &tpapd_ieta, &b_tpapd_ieta);
303  tpapd_tree->SetBranchAddress("iphi", &tpapd_iphi, &b_tpapd_iphi);
304  tpapd_tree->SetBranchAddress("dccID", &tpapd_dccID, &b_tpapd_dccID);
305  tpapd_tree->SetBranchAddress("side", &tpapd_side, &b_tpapd_side);
306  tpapd_tree->SetBranchAddress("towerID", &tpapd_towerID, &b_tpapd_towerID);
307  tpapd_tree->SetBranchAddress("channelID", &tpapd_channelID, &b_tpapd_channelID);
308  tpapd_tree->SetBranchAddress("moduleID", &tpapd_moduleID, &b_tpapd_moduleID);
309  tpapd_tree->SetBranchAddress("flag", &tpapd_flag, &b_tpapd_flag);
310  tpapd_tree->SetBranchAddress("gain", &tpapd_gain, &b_tpapd_gain);
311  tpapd_tree->SetBranchAddress("APD", tpapd_APD, &b_tpapd_APD );
312 
313  tppn_tree = (TTree*) tpapd_file->Get(tppn_tree_name);
314  assert( tppn_tree!=nullptr );
315  tppn_tree->SetMakeClass(1);
316  tppn_tree->SetBranchAddress( "side", &tppn_side, &b_tppn_side );
317  tppn_tree->SetBranchAddress( "pnID", &tppn_pnID, &b_tppn_pnID );
318  tppn_tree->SetBranchAddress( "moduleID", &tppn_moduleID, &b_tppn_moduleID );
319  tppn_tree->SetBranchAddress( "gain", &tppn_gain, &b_tppn_gain );
320  tppn_tree->SetBranchAddress( "PN", tppn_PN, &b_tppn_PN );
321  }
322  init_ok = true;
323 }
324 
325 void
327 {
328  if( !init_ok ) return;
329  refresh();
330 
331  TString i_name, d_name;
332 
333  if( _isBarrel )
334  {
335  ixmin=0;
336  ixmax=85;
337  nx =ixmax-ixmin;
338  iymin=0;
339  iymax=20;
340  ny =iymax-iymin;
341 
342 // for( int ilmod=1; ilmod<=9; ilmod++ )
343 // {
344 // _pn[ilmod] = MEEBGeom::pn( ilmod );
345 // }
346  }
347  else // fixme --- to be implemented
348  {
349  ixmin=1;
350  ixmax=101;
351  nx =ixmax-ixmin;
352  iymin=1;
353  iymax=101;
354  ny =iymax-iymin;
355 // for( int ilmod=1; ilmod<=21; ilmod++ ) // modules 20 and 21 are fake...
356 // {
357 // _pn[ilmod] = MEEEGeom::pn( ilmod );
358 // }
359  // abort();
360  }
361 
362  TString t_name;
363 
364  //
365  // Laser Run
366  //
367  t_name = "LMF_RUN_DAT";
368  addBranchI( t_name, "LOGIC_ID" );
369  addBranchI( t_name, "NEVENTS" );
370  addBranchI( t_name, "QUALITY_FLAG" );
371 
372  //
373  // Laser Run IOV
374  //
375  t_name = "LMF_RUN_IOV";
376  addBranchI( t_name, "TAG_ID" );
377  addBranchI( t_name, "SUB_RUN_NUM" );
378  addBranchI( t_name, "SUB_RUN_START_LOW" );
379  addBranchI( t_name, "SUB_RUN_START_HIGH" );
380  addBranchI( t_name, "SUB_RUN_END_LOW" );
381  addBranchI( t_name, "SUB_RUN_END_HIGH" );
382  addBranchI( t_name, "DB_TIMESTAMP_LOW" );
383  addBranchI( t_name, "DB_TIMESTAMP_HIGH" );
384  addBranchC( t_name, "SUB_RUN_TYPE" );
385 
386  if( _type==ME::iLaser )
387  {
388  //
389  // Laser ADC Primitives
390  //
391  bookHistoI( _primStr, "LOGIC_ID" );
392  bookHistoI( _primStr, "FLAG" );
393  bookHistoF( _primStr, "MEAN" );
394  bookHistoF( _primStr, "RMS" );
395  bookHistoF( _primStr, "M3" );
396  bookHistoF( _primStr, "APD_OVER_PNA_MEAN" );
397  bookHistoF( _primStr, "APD_OVER_PNA_RMS" );
398  bookHistoF( _primStr, "APD_OVER_PNA_M3" );
399  bookHistoF( _primStr, "APD_OVER_PNB_MEAN" );
400  bookHistoF( _primStr, "APD_OVER_PNB_RMS" );
401  bookHistoF( _primStr, "APD_OVER_PNB_M3" );
402  bookHistoF( _primStr, "APD_OVER_PN_MEAN" );
403  bookHistoF( _primStr, "APD_OVER_PN_RMS" );
404  bookHistoF( _primStr, "APD_OVER_PN_M3" );
405  bookHistoF( _primStr, "APD_OVER_APDA_MEAN" );
406  bookHistoF( _primStr, "APD_OVER_APDA_RMS" );
407  bookHistoF( _primStr, "APD_OVER_APDA_M3" );
408  bookHistoF( _primStr, "APD_OVER_APDB_MEAN" );
409  bookHistoF( _primStr, "APD_OVER_APDB_RMS" );
410  bookHistoF( _primStr, "APD_OVER_APDB_M3" );
411  bookHistoF( _primStr, "SHAPE_COR" );
412  bookHistoF( _primStr, "ALPHA" );
413  bookHistoF( _primStr, "BETA" );
414  // NEW GHM 08/06 --> SCHEMA MODIFIED?
415  bookHistoF( _primStr, "TIME_MEAN" );
416  bookHistoF( _primStr, "TIME_RMS" );
417  bookHistoF( _primStr, "TIME_M3" );
418  bookHistoF( _primStr, "TIME_NEVT" );
419 
420  //
421  // Laser PN Primitives
422  //
424  addBranchI( t_name, "LOGIC_ID" );
425  addBranchI( t_name, "FLAG" );
426  addBranchF( t_name, "MEAN" );
427  addBranchF( t_name, "RMS" );
428  addBranchF( t_name, "M3" );
429  addBranchF( t_name, "PNA_OVER_PNB_MEAN" );
430  addBranchF( t_name, "PNA_OVER_PNB_RMS" );
431  addBranchF( t_name, "PNA_OVER_PNB_M3" );
432 
433  //
434  // Laser Pulse
435  //
437  addBranchI( t_name, "LOGIC_ID" );
438  addBranchI( t_name, "FIT_METHOD" );
439  addBranchF( t_name, "MTQ_AMPL" );
440  addBranchF( t_name, "MTQ_TIME" );
441  addBranchF( t_name, "MTQ_RISE" );
442  addBranchF( t_name, "MTQ_FWHM" );
443  addBranchF( t_name, "MTQ_FW20" );
444  addBranchF( t_name, "MTQ_FW80" );
445  addBranchF( t_name, "MTQ_SLIDING" );
446 
447  //
448  // Laser Config
449  //
451  addBranchI( t_name, "LOGIC_ID" );
452  addBranchI( t_name, "WAVELENGTH" );
453  addBranchI( t_name, "VFE_GAIN" );
454  addBranchI( t_name, "PN_GAIN" );
455  addBranchI( t_name, "LSR_POWER" );
456  addBranchI( t_name, "LSR_ATTENUATOR" );
457  addBranchI( t_name, "LSR_CURRENT" );
458  addBranchI( t_name, "LSR_DELAY_1" );
459  addBranchI( t_name, "LSR_DELAY_2" );
460 
461  //
462  // Laser LaserRun config dat
463  //
464  t_name = "RUN_LASERRUN_CONFIG_DAT";
465  addBranchI( t_name, "LOGIC_ID" );
466  addBranchC( t_name, "LASER_SEQUENCE_TYPE" );
467  addBranchC( t_name, "LASER_SEQUENCE_COND" );
468 
469  }
470  else if( _type==ME::iTestPulse )
471  {
472  //
473  // Test Pulse ADC Primitives
474  //
475  bookHistoI( _tpPrimStr, "LOGIC_ID" );
476  bookHistoI( _tpPrimStr, "FLAG" );
477  bookHistoF( _tpPrimStr, "MEAN" );
478  bookHistoF( _tpPrimStr, "RMS" );
479  bookHistoF( _tpPrimStr, "M3" );
480  bookHistoF( _tpPrimStr, "NEVT" );
481 
482  //
483  // Test Pulse PN Primitives
484  //
486  addBranchI( t_name, "LOGIC_ID" );
487  addBranchI( t_name, "FLAG" );
488  addBranchI( t_name, "GAIN" );
489  addBranchF( t_name, "MEAN" );
490  addBranchF( t_name, "RMS" );
491  addBranchF( t_name, "M3" );
492 
493  //
494  // Test Pulse Config
495  //
497  addBranchI( t_name, "LOGIC_ID" );
498  addBranchI( t_name, "VFE_GAIN" );
499  addBranchI( t_name, "PN_GAIN" );
500  }
501 }
502 
503 void
505 {
506  TString t_name;
507 
508  if( !init_ok ) return;
509 
510  Long64_t nentries = 0;
511  Long64_t ientry = 0;
512 
513  int channelView_(0);
514  int id1_(0), id2_(0);
515  int logic_id_(0);
516 
517  if( _type==ME::iLaser )
518  {
519 
520  nentries = apdpn_tree->GetEntriesFast();
521  for( Long64_t jentry=0; jentry<nentries; jentry++ )
522  {
523  ientry = apdpn_tree->LoadTree( jentry );
524  assert( ientry>=0 );
525  apdpn_tree->GetEntry( jentry );
526 
527  if(ab_tree){
528  ientry = ab_tree->LoadTree( jentry );
529  assert( ientry>=0 );
530  ab_tree->GetEntry( jentry );
531  }
532 
533 
534  if( apdpn_iphi<0 ) continue;
535 
536  // fixme remove until coordinated are fine
537  //if(ab_tree) assert( apdpn_ieta==ab_ieta && apdpn_iphi==ab_iphi );
538 
539  int ix(0);
540  int iy(0);
541  if( _isBarrel )
542  {
543  // Barrel, global coordinates
544  id1_ = _sm;
545  if ( apdpn_side != _side ) continue;
546  int ieta=apdpn_ieta;
547  int iphi=apdpn_iphi;
548  MEEBGeom::XYCoord xy_ = MEEBGeom::localCoord( ieta, iphi );
549  ix = xy_.first;
550  iy = xy_.second;
551  id2_ = MEEBGeom::crystal_channel( ix, iy );
552  channelView_ = iEB_crystal_number;
553  }
554  else
555  {
556  // EndCaps, global coordinates
557  id1_ = apdpn_iphi;
558  id2_ = apdpn_ieta;
559  ix = id1_;
560  iy = id2_;
561  channelView_ = iEE_crystal_number;
562  }
563 
564  logic_id_ = logicId( channelView_, id1_, id2_ );
565 
566  int flag = apdpn_flag;
567 
568  setInt( "LOGIC_ID", ix, iy, logic_id_ );
569  setInt( "FLAG", ix, iy, flag );
570  setVal( "MEAN", ix, iy, apdpn_apdpn[iAPD][iMean] );
571  setVal( "RMS", ix, iy, apdpn_apdpn[iAPD][iRMS] );
572  setVal( "M3", ix, iy, apdpn_apdpn[iAPD][iM3] ); // fixme --- peak?
573  setVal( "APD_OVER_PNA_MEAN", ix, iy, apdpn_apdpn[iAPDoPNA][iMean] );
574  setVal( "APD_OVER_PNA_RMS", ix, iy, apdpn_apdpn[iAPDoPNA][iRMS] );
575  setVal( "APD_OVER_PNA_M3", ix, iy, apdpn_apdpn[iAPDoPNA][iM3] ); // fixme
576  setVal( "APD_OVER_PNB_MEAN", ix, iy, apdpn_apdpn[iAPDoPNB][iMean] );
577  setVal( "APD_OVER_PNB_RMS", ix, iy, apdpn_apdpn[iAPDoPNB][iRMS] );
578  setVal( "APD_OVER_PNB_M3", ix, iy, apdpn_apdpn[iAPDoPNB][iM3] ); // fixme
579  setVal( "APD_OVER_PN_MEAN", ix, iy, apdpn_apdpn[iAPDoPN][iMean] );
580  setVal( "APD_OVER_PN_RMS", ix, iy, apdpn_apdpn[iAPDoPN][iRMS] );
581  setVal( "APD_OVER_PN_M3", ix, iy, apdpn_apdpn[iAPDoPN][iM3] ); // fixme
582  // JM
583  setVal( "APD_OVER_APD_MEAN", ix, iy, apdpn_apdpn[iAPDoAPDA][iMean] );
584  setVal( "APD_OVER_APD_RMS", ix, iy, apdpn_apdpn[iAPDoAPDA][iRMS] );
585  setVal( "APD_OVER_APD_M3", ix, iy, apdpn_apdpn[iAPDoAPDA][iM3] ); // fixme
586  setVal( "APD_OVER_APDA_MEAN", ix, iy, apdpn_apdpn[iAPDoAPDA][iMean] );
587  setVal( "APD_OVER_APDA_RMS", ix, iy, apdpn_apdpn[iAPDoAPDA][iRMS] );
588  setVal( "APD_OVER_APDA_M3", ix, iy, apdpn_apdpn[iAPDoAPDA][iM3] ); // fixme
589  setVal( "APD_OVER_APDB_MEAN", ix, iy, apdpn_apdpn[iAPDoAPDB][iMean] );
590  setVal( "APD_OVER_APDB_RMS", ix, iy, apdpn_apdpn[iAPDoAPDB][iRMS] );
591  setVal( "APD_OVER_APDB_M3", ix, iy, apdpn_apdpn[iAPDoAPDB][iM3] ); // fixme
592  // JM
593  setVal( "SHAPE_COR", ix, iy, apdpn_ShapeCor );
594  if(ab_tree){
595  setVal( "ALPHA", ix, iy, ab_ab[iAlpha] );
596  setVal( "BETA", ix, iy, ab_ab[iBeta] );
597  }else{
598  setVal( "ALPHA", ix, iy, 0. );
599  setVal( "BETA", ix, iy, 0. );
600  }
601  // NEW GHM 08/06
602  setVal( "TIME_MEAN", ix, iy, apdpn_apdpn[iTime][iMean] );
603  setVal( "TIME_RMS", ix, iy, apdpn_apdpn[iTime][iRMS] );
604  setVal( "TIME_M3", ix, iy, apdpn_apdpn[iTime][iM3] );
605  setVal( "TIME_NEVT", ix, iy, apdpn_apdpn[iTime][iNevt] );
606 
607  }
608 
609 
610  //
611  // PN primitives
612  //
614 
615  nentries = pn_tree->GetEntriesFast();
616  assert( nentries%2==0 );
617  int module_(0);
618  id1_=_sm; id2_=0;
619 
620  Long64_t jentry=0;
621 
622  while( jentry<nentries )
623  {
624  for( int jj=0; jj<2; jj++ )
625  {
626  // jj=0 --> PNA
627  // jj=1 --> PNB
628 
629  int zentry = jentry+jj;
630  assert( zentry<nentries );
631 
632  ientry = pn_tree->LoadTree( zentry );
633  assert( ientry>=0 );
634  pn_tree->GetEntry( zentry );
635 
636  if( _side!=pn_side ) break;
637 
638  if( jj==1 ) assert( pn_moduleID==module_ );
639  module_ = pn_moduleID;
640  assert( pn_pnID==jj );
641 
642  // get the PN number
643  std::pair<int,int> memPn_ = ME::pn( _lmr, module_, (ME::PN)jj );
644  if( _isBarrel )
645  {
646  // assert( memPn_.first%600==_dcc%600 );
647  id1_ = _sm;
648  id2_ = memPn_.second;
649  }
650  else
651  {
652  int dee_ = MEEEGeom::dee( _lmr );
653  // int mem_ = memPn_.first%600;
654 // if( dee_==1 )
655 // {
656 // if( jj==ME::iPNA ) assert( mem_==50 );
657 // else assert( mem_==51 );
658 // }
659 // else if( dee_==2 )
660 // {
661 // if( jj==ME::iPNA ) assert( mem_==47 ); // warning !
662 // else assert( mem_==46 );
663 // // assert( mem_==46 || mem_==47 );
664 // }
665 // else if( dee_==3 )
666 // {
667 // if( jj==ME::iPNA ) assert( mem_==1 );
668 // else assert( mem_==2 );
669 // }
670 // else if( dee_==4 )
671 // {
672 // if( jj==ME::iPNA ) assert( mem_==5 );
673 // else assert( mem_==6 );
674 // }
675  id1_ = dee_;
676  id2_ = (jj+1)*100+memPn_.second;
677  }
678 
679  if( _isBarrel )
680  {
681  channelView_ = iEB_LM_PN;
682  }
683  else
684  {
685  channelView_ = iEE_LM_PN;
686  }
687  logic_id_ = logicId( channelView_, id1_, id2_ );
688 
689  i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
690  f_t[t_name+separator+"MEAN"] = pn_PN[iMean];
691  f_t[t_name+separator+"RMS"] = pn_PN[iRMS];
692  f_t[t_name+separator+"M3"] = pn_PN[iM3];
693  f_t[t_name+separator+"PNA_OVER_PNB_MEAN"] = (jj==0) ? pn_PNoPNB[iMean] : pn_PNoPNA[iMean];
694  f_t[t_name+separator+"PNA_OVER_PNB_RMS" ] = (jj==0) ? pn_PNoPNB[iRMS] : pn_PNoPNA[iRMS];
695  f_t[t_name+separator+"PNA_OVER_PNB_M3"] = (jj==0) ? pn_PNoPNB[iM3] : pn_PNoPNA[iM3];
696 
697  t_t[t_name]->Fill();
698 
699  }
700  // std::cout << "Module=" << module_ << "\tPNA=" << pn_[0] << "\tPNB=" << pn_[1] << std::endl;
701 
702 // if( _isBarrel )
703 // jentry += 4;
704 // else
705 // jentry += 2;
706  jentry += 2;
707  }
708 
709  logic_id_ = logicId( iECAL_LMR, _lmr );
710 
711  //
712  // MATACQ primitives
713  //
714 
715  if(mtq_tree){
716 
718 
719  nentries = mtq_tree->GetEntriesFast();
720  assert( nentries==2 );
721  for( Long64_t jentry=0; jentry<nentries; jentry++ )
722  {
723  ientry = mtq_tree->LoadTree( jentry );
724  assert( ientry>=0 );
725  mtq_tree->GetEntry( jentry );
726 
727  if ( mtq_side != _side ) continue;
728 
729  i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
730  i_t[t_name+separator+"FIT_METHOD"] = 0 ; // fixme --- what's this? ? ?
731  f_t[t_name+separator+"MTQ_AMPL"] = mtq_mtq[iAmpl];
732  f_t[t_name+separator+"MTQ_TIME"] = mtq_mtq[iPeak];
733  f_t[t_name+separator+"MTQ_RISE"] = mtq_mtq[iTrise];
734  f_t[t_name+separator+"MTQ_FWHM"] = mtq_mtq[iFwhm];
735  f_t[t_name+separator+"MTQ_FW20"] = mtq_mtq[iFw20];
736  f_t[t_name+separator+"MTQ_FW80"] = mtq_mtq[iFw80];
737  f_t[t_name+separator+"MTQ_SLIDING"] = mtq_mtq[iSlide]; // fixme --- sliding: max of average in sliding window
738 
739  t_t[t_name]->Fill();
740  }
741  }else{
742 
744 
745  i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
746  i_t[t_name+separator+"FIT_METHOD"] = 0 ; // fixme
747  f_t[t_name+separator+"MTQ_AMPL"] = 0.0;
748  f_t[t_name+separator+"MTQ_TIME"] = 0.0;
749  f_t[t_name+separator+"MTQ_RISE"] = 0.0;
750  f_t[t_name+separator+"MTQ_FWHM"] = 0.0;
751  f_t[t_name+separator+"MTQ_FW20"] = 0.0;
752  f_t[t_name+separator+"MTQ_FW80"] = 0.0;
753  f_t[t_name+separator+"MTQ_SLIDING"] = 0.0;
754 
755  t_t[t_name]->Fill();
756  }
757 
758  //
759  // Laser Run
760  //
761  t_name = lmfLaserName( ME::iLmfLaserRun, _type );
762  //std::cout << "Fill "<< t_name << std::endl;
763  i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
764  i_t[t_name+separator+"NEVENTS"] = _events;
765  i_t[t_name+separator+"QUALITY_FLAG"] = 1; // fixme
766  t_t[t_name]->Fill();
767 
768  //
769  // Laser Config
770  //
772  //std::cout << "Fill "<< t_name << std::endl;
773  i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
774  i_t[t_name+separator+"WAVELENGTH"] = _color;
775  i_t[t_name+separator+"VFE_GAIN"] = _mgpagain; // fixme
776  i_t[t_name+separator+"PN_GAIN"] = _memgain; // fixme
777  i_t[t_name+separator+"LSR_POWER"] = _power; // will be available from MATACQ data
778  i_t[t_name+separator+"LSR_ATTENUATOR"] = _filter; // idem
779  i_t[t_name+separator+"LSR_CURRENT"] = 0; // idem
780  i_t[t_name+separator+"LSR_DELAY_1"] = _delay; // idem
781  i_t[t_name+separator+"LSR_DELAY_2"] = 0; // idem
782  t_t[t_name]->Fill();
783 
784  }
785  else if( _type==ME::iTestPulse )
786  {
787 
788 // nentries = tpapd_tree->GetEntriesFast();
789 // for( Long64_t jentry=0; jentry<nentries; jentry++ )
790 // {
791 // ientry = tpapd_tree->LoadTree( jentry );
792 // assert( ientry>=0 );
793 // nb = tpapd_tree->GetEntry( jentry );
794 
795 // if( tpapd_iphi<0 ) continue;
796 
797 // const bool new_= true;
798 
799 // int ix;
800 // int iy;
801 // int id2;
802 // if( new_ )
803 // {
804 // // for Cruzet3 , global coordinates
805 // if ( tpapd_side != _side ) continue;
806 // int ieta=tpapd_ieta;
807 // int iphi=tpapd_iphi;
808 // MEEBGeom::XYCoord xy_ = MEEBGeom::localCoord( ieta, iphi );
809 // ix = xy_.first;
810 // iy = xy_.second;
811 // id2 = ix*20 + iy; // !!! TO BE CHECKED !!!
812 // }
813 // else
814 // {
815 // // for Cruzet2 , local coordinates
816 // ix = tpapd_ieta;
817 // iy = 19-tpapd_iphi;
818 // id2 = ix*20 + (20 - iy); // !!! TO BE CHECKED !!!
819 // }
820 // //
821 
822 // int id1 = _sm; // fixme --- this is for barrel
823 // int logic_id_ = 1011000000; // fixme
824 // logic_id_ += 10000*id1 + id2;
825 
826 // int flag = tpapd_flag;
827 
828 // setInt( "LOGIC_ID", ix, iy, logic_id_ );
829 // setInt( "FLAG", ix, iy, flag );
830 // setVal( "MEAN", ix, iy, tpapd_APD[iMean] );
831 // setVal( "RMS", ix, iy, tpapd_APD[iRMS] );
832 // setVal( "M3", ix, iy, tpapd_APD[iM3] );
833 // setVal( "NEVT", ix, iy, tpapd_APD[iNevt] );
834 // }
835 
836 // //
837 // // PN primitives
838 // //
839 // t_name = lmfLaserName( ME::iLmfTestPulsePnPrim, _type );
840 
841 // nentries = tppn_tree->GetEntriesFast();
842 // assert( nentries%2==0 );
843 // int module_, pn_[2];
844 // int id1_(_sm), id2_(0);
845 // int logic_id_(0);
846 
847 // Long64_t jentry=0;
848 // if( _side==1 ) jentry+=2; // fixme : true also for endcaps?
849 // while( jentry<nentries )
850 // {
851 // for( int jj=0; jj<2; jj++ )
852 // {
853 // // jj=0 --> PNA
854 // // jj=1 --> PNB
855 
856 // int zentry = jentry+jj;
857 // assert( zentry<nentries );
858 
859 // ientry = tppn_tree->LoadTree( zentry );
860 // assert( ientry>=0 );
861 // nb = tppn_tree->GetEntry( zentry );
862 
863 // if( jj==1 ) assert( tppn_moduleID==module_ );
864 // module_ = tppn_moduleID;
865 // assert( tppn_pnID==jj );
866 
867 // pn_[jj] = ( jj==0 ) ? _pn[module_].first : _pn[module_].second;
868 // id2_ = pn_[jj];
869 // logic_id_ = 1131000000 ;
870 // // logic_id_ = 0; // fixme
871 // logic_id_ += 10000*id1_ + id2_;
872 
873 // i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
874 // i_t[t_name+separator+"GAIN"] = tppn_gain;
875 // f_t[t_name+separator+"MEAN"] = tppn_PN[iMean];
876 // f_t[t_name+separator+"RMS"] = tppn_PN[iRMS];
877 // f_t[t_name+separator+"M3"] = tppn_PN[iM3]; // fixme --- peak?
878 
879 // t_t[t_name]->Fill();
880 
881 // }
882 
883 // // std::cout << "Module=" << module_ << "\tPNA=" << pn_[0] << "\tPNB=" << pn_[1] << std::endl;
884 
885 // jentry += 4;
886 // }
887 
888 // logic_id_ = 1041000000;
889 // logic_id_ += 10000*id1_;
890 // logic_id_ += id1_;
891 
892 // //
893 // // Test Pulse Run
894 // //
895 // t_name = lmfLaserName( ME::iLmfTestPulseRun, _type );
896 // //std::cout << "Fill "<< t_name << std::endl;
897 // i_t[t_name+separator+"LOGIC_ID"] = logic_id_; // fixme --- is there a channelview for this?
898 // i_t[t_name+separator+"NEVENTS"] = _events;
899 // i_t[t_name+separator+"QUALITY_FLAG"] = 1; // fixme
900 // t_t[t_name]->Fill();
901 
902 // //
903 // // Test Pulse Config
904 // //
905 // t_name = lmfLaserName( ME::iLmfTestPulseConfig, _type );
906 // //std::cout << "Fill "<< t_name << std::endl;
907 // i_t[t_name+separator+"LOGIC_ID"] = logic_id_; // fixme
908 // i_t[t_name+separator+"VFE_GAIN"] = _mgpagain; // fixme
909 // i_t[t_name+separator+"PN_GAIN"] = _memgain; // fixme
910 // t_t[t_name]->Fill();
911  }
912 
913  //
914  // Laser Run IOV
915  //
916  t_name = "LMF_RUN_IOV";
917  //std::cout << "Fill "<< t_name << std::endl;
918  i_t[t_name+separator+"TAG_ID"] = 0; // fixme
919  i_t[t_name+separator+"SUB_RUN_NUM"] = _run; // fixme
920  i_t[t_name+separator+"SUB_RUN_START_LOW" ] = ME::time_low( _ts_beg );
921  i_t[t_name+separator+"SUB_RUN_START_HIGH"] = ME::time_high( _ts_beg );
922  i_t[t_name+separator+"SUB_RUN_END_LOW" ] = ME::time_low( _ts_end );
923  i_t[t_name+separator+"SUB_RUN_END_HIGH" ] = ME::time_high( _ts_end );
924  i_t[t_name+separator+"DB_TIMESTAMP_LOW" ] = ME::time_low( _ts );
925  i_t[t_name+separator+"DB_TIMESTAMP_HIGH" ] = ME::time_high( _ts );
926  c_t[t_name+separator+"SUB_RUN_TYPE"] = "LASER TEST CRUZET"; //fixme
927  t_t[t_name]->Fill();
928 
929 }
930 
931 void
933 {
934  if( !init_ok ) return;
935 
936  out_file = new TFile( _outfile, "RECREATE" );
937  // out_file->cd();
938 
939  std::map< TString, TH2* >::iterator it;
940 
941  for( it=i_h.begin(); it!=i_h.end(); ++it )
942  {
943  it->second->Write();
944  delete it->second;
945  }
946 
947  for( it=f_h.begin(); it!=f_h.end(); ++it )
948  {
949  it->second->Write();
950  delete it->second;
951  }
952 
953  std::map< TString, TTree* >::iterator it_t;
954  for( it_t=t_t.begin(); it_t!=t_t.end(); ++it_t )
955  {
956  it_t->second->Write();
957  delete it_t->second;
958  }
959 
960  // std::cout << "Closing " << _outfile << std::endl;
961  out_file->Close();
962  delete out_file;
963  out_file=nullptr;
964 }
965 
967 {
968  delete apdpn_tree;
969  delete ab_tree;
970  delete pn_tree;
971  delete mtq_tree;
972  delete tpapd_tree;
973  delete tppn_tree;
974  if( apdpn_file!=nullptr )
975  {
976  // std::cout << "Closing apdpn_file " << std::endl;
977  apdpn_file->Close();
978  delete apdpn_file;
979  apdpn_file = nullptr;
980  }
981  if( ab_file!=nullptr )
982  {
983  // std::cout << "Closing ab_file " << std::endl;
984  ab_file->Close();
985  delete ab_file;
986  ab_file = nullptr;
987  }
988  if( mtq_file!=nullptr )
989  {
990  // std::cout << "Closing mtq_file " << std::endl;
991  mtq_file->Close();
992  delete mtq_file;
993  mtq_file = nullptr;
994  }
995  if( tpapd_file!=nullptr )
996  {
997  // std::cout << "Closing tpapd_file " << std::endl;
998  tpapd_file->Close();
999  delete tpapd_file;
1000  tpapd_file = nullptr;
1001  }
1002 }
1003 
1004 void
1005 MELaserPrim::print( std::ostream& o )
1006 {
1007  o << "DCC/SM/side/type/color/run/ts " << _dcc << "/" << _sm << "/" << _side << "/"
1008  << _type << "/" << _color << "/" << _run << "/" << _ts << std::endl;
1009 
1010 // for( int ix=ixmin; ix<ixmax; ix++ )
1011 // {
1012 // for( int iy=iymin; iy<iymax; iy++ )
1013 // {
1014 // int flag = getInt( _primStr+"FLAG", ix, iy );
1015 // if( flag==0 ) continue;
1016 // int logic_id = getInt( _primStr+"LOGIC_ID", ix, iy );
1017 // float apd = getVal( _primStr+"MEAN", ix, iy );
1018 // o << "Crystal ieta=" << ix << "\tiphi=" << iy << "\tlogic_id=" << logic_id << "\tAPD=" << apd << endl;
1019 // }
1020 // }
1021 }
1022 
1023 TString
1024 MELaserPrim::lmfLaserName( int table, int type, int color )
1025 {
1026  TString str("LMF_ERROR");
1027  if( table<0 || table>=ME::iSizeLmf ) return str;
1028  if( color<0 || color>=ME::iSizeC ) return str;
1029 
1030  if( type==ME::iLaser )
1031  {
1032  TString colstr;
1033  switch( color )
1034  {
1035  case ME::iBlue: colstr = "_BLUE"; break;
1036  case ME::iGreen: colstr = "_GREEN"; break;
1037  case ME::iRed: colstr = "_RED"; break;
1038  case ME::iIRed: colstr = "_IRED"; break;
1039  default: abort();
1040  }
1041  str = "LMF_LASER";
1042  switch( table )
1043  {
1044  case ME::iLmfLaserRun: str = "LMF_RUN"; break;
1045  case ME::iLmfLaserConfig: str += "_CONFIG"; break;
1046  case ME::iLmfLaserPulse: str += colstr; str += "_PULSE"; break;
1047  case ME::iLmfLaserPrim: str += colstr; str += "_PRIM"; break;
1048  case ME::iLmfLaserPnPrim: str += colstr; str += "_PN_PRIM"; break;
1049  default: abort();
1050  }
1051  }
1052  else if( type==ME::iTestPulse )
1053  {
1054  str = "LMF_TEST_PULSE";
1055  switch( table )
1056  {
1057  case ME::iLmfTestPulseRun: str = "LMF_RUN"; break;
1058  case ME::iLmfTestPulseConfig: str += "_CONFIG"; break;
1059  case ME::iLmfTestPulsePrim: str += "_PRIM"; break;
1060  case ME::iLmfTestPulsePnPrim: str += "_PN_PRIM"; break;
1061  default: abort();
1062  }
1063  }
1064  str += "_DAT";
1065  return str;
1066 }
1067 
1068 void
1069 MELaserPrim::addBranchI( const char* t_name_, const char* v_name_ )
1070 {
1071  TString slashI("/i"); // Warning: always unsigned
1072  TString t_name(t_name_);
1073  TString v_name(v_name_);
1074  if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
1075  t_t[t_name]->Branch(v_name, &i_t[t_name+separator+v_name],v_name+slashI);
1076 }
1077 
1078 void
1079 MELaserPrim::addBranchF( const char* t_name_, const char* v_name_ )
1080 {
1081  TString slashF("/F");
1082  TString t_name(t_name_);
1083  TString v_name(v_name_);
1084  if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
1085  t_t[t_name]->Branch(v_name, &f_t[t_name+separator+v_name],v_name+slashF);
1086 }
1087 
1088 void
1089 MELaserPrim::addBranchC( const char* t_name_, const char* v_name_ )
1090 {
1091  TString slashC("/C");
1092  TString t_name(t_name_);
1093  TString v_name(v_name_);
1094  if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
1095  t_t[t_name]->Branch(v_name, &c_t[t_name+separator+v_name],v_name+slashC);
1096 }
1097 
1098 void
1099 MELaserPrim::bookHistoI( const char* h_name_, const char* v_name_ )
1100 {
1101  TString i_name = TString(h_name_)+TString(v_name_);
1102  TH2* h_ = new TH2I(i_name,i_name,nx,ixmin,ixmax,ny,iymin,iymax);
1103  setHistoStyle( h_ );
1104  i_h[i_name] = h_;
1105 }
1106 
1107 void
1108 MELaserPrim::bookHistoF( const char* h_name_, const char* v_name_ )
1109 {
1110  TString d_name = TString(h_name_)+TString(v_name_);
1111  TH2* h_ = new TH2F(d_name,d_name,nx,ixmin,ixmax,ny,iymin,iymax);
1112  setHistoStyle( h_ );
1113  f_h[d_name] = h_;
1114 }
1115 
1116 
1117 bool
1118 MELaserPrim::setInt( const char* name, int ix, int iy, int ival )
1119 {
1120  TString name_;
1121  if( _type==ME::iLaser ) name_=_primStr+name;
1122  else if( _type==ME::iTestPulse ) name_=_tpPrimStr+name;
1123 
1124  int _ival = getInt( name_, ix, iy );
1125  assert( _ival!=-99 );
1126  if( _ival!=0 ) return false;
1127 
1128  TH2I* h_ = (TH2I*) i_h[name_];
1129  assert( h_!=nullptr );
1130  h_->Fill( ix+0.5, iy+0.5, ival );
1131 
1132  return true;
1133 }
1134 
1135 bool
1136 MELaserPrim::setVal( const char* name, int ix, int iy, float val )
1137 {
1138  TString name_;
1139  if( _type==ME::iLaser ) name_=_primStr+name;
1140  else if( _type==ME::iTestPulse ) name_=_tpPrimStr+name;
1141 
1142  float _val = getVal( name_, ix, iy );
1143  assert( _val!=-99 );
1144  if( _val!=0 ) return false;
1145 
1146  TH2F* h_ = (TH2F*) f_h[name_];
1147  assert( h_!=nullptr );
1148 
1149  h_->Fill( ix+0.5, iy+0.5, val );
1150 
1151  return true;
1152 }
1153 
1154 Int_t
1155 MELaserPrim::getInt( const char* name, int ix, int iy )
1156 {
1157  Int_t ival=-99;
1158  if( i_h.count(name)==1 )
1159  {
1160  TH2I* h_ = (TH2I*) i_h[name];
1161  assert( h_!=nullptr );
1162  int binx = h_->GetXaxis()->FindBin( ix+0.5 );
1163  int biny = h_->GetYaxis()->FindBin( iy+0.5 );
1164  ival = (Int_t) h_->GetCellContent( binx, biny );
1165  }
1166  return ival;
1167 }
1168 
1169 Float_t
1170 MELaserPrim::getVal( const char* name, int ix, int iy )
1171 {
1172  Float_t val=-99.;
1173  if( f_h.count(name)==1 )
1174  {
1175  TH2F* h_ = (TH2F*) f_h[name];
1176  assert( h_!=nullptr );
1177  int binx = h_->GetXaxis()->FindBin( ix+0.5 );
1178  int biny = h_->GetYaxis()->FindBin( iy+0.5 );
1179  val = h_->GetCellContent( binx, biny );
1180  }
1181  return val;
1182 }
1183 
1184 bool
1185 MELaserPrim::setInt( const char* tname, const char* vname, int ival )
1186 {
1187  TString key_(tname); key_ += separator; key_ += vname;
1188  assert( i_t.count(key_)==1 );
1189  i_t[key_] = ival;
1190  return true;
1191 }
1192 
1193 bool
1194 MELaserPrim::setVal( const char* tname, const char* vname, float val )
1195 {
1196  TString key_(tname); key_ += separator; key_ += vname;
1197 
1198  // ghm
1199  if( f_t.count(key_)!=1 )
1200  {
1201  std::cout << key_ << std::endl;
1202  }
1203  assert( f_t.count(key_)==1 );
1204  f_t[key_] = val;
1205  return true;
1206 }
1207 
1208 bool
1209 MELaserPrim::fill( const char* tname )
1210 {
1211  TString key_( tname );
1212  assert( t_t.count(key_)==1 );
1213  t_t[key_] -> Fill();
1214  return true;
1215 }
1216 
1217 void
1219 {
1220  if( h==nullptr ) return;
1221 
1222  float _scale = 1;
1223 
1224  h->SetLineColor(4);
1225  h->SetLineWidth(1);
1226  h->SetFillColor(38);
1227  TAxis* axis[3];
1228  axis[0] = h->GetXaxis();
1229  axis[1] = h->GetYaxis();
1230  axis[2] = h->GetZaxis();
1231  for( int ii=0; ii<3; ii++ )
1232  {
1233  TAxis* a = axis[ii];
1234  if( !a ) continue;
1235  a->SetLabelFont(132);
1236  a->SetLabelOffset(_scale*0.005);
1237  a->SetLabelSize(_scale*0.04);
1238  a->SetTitleFont(132);
1239  a->SetTitleOffset(_scale*1);
1240  a->SetTitleSize(_scale*0.04);
1241  }
1242  h->SetStats( kTRUE );
1243 }
1244 
1245 void
1247 {
1248  std::map< TString, TH2* >::iterator it;
1249 
1250  for( it=i_h.begin(); it!=i_h.end(); ++it )
1251  {
1252  delete it->second;
1253  it->second = nullptr;
1254  }
1255  i_h.clear();
1256 
1257  for( it=f_h.begin(); it!=f_h.end(); ++it )
1258  {
1259  delete it->second;
1260  it->second = nullptr;
1261  }
1262  f_h.clear();
1263 
1264  std::map< TString, TTree* >::iterator it_t;
1265  for( it_t=t_t.begin(); it_t!=t_t.end(); ++it_t )
1266  {
1267  delete it_t->second;
1268  it->second = nullptr;
1269  }
1270  t_t.clear();
1271 }
std::map< TString, float > f_t
Definition: MELaserPrim.h:151
Int_t apdpn_dccID
Definition: MELaserPrim.h:155
static void regionAndSector(int ilmr, int &ireg, int &isect, int &idcc, int &iside)
Definition: ME.cc:348
Double_t tpapd_APD[iSize_apdpn]
Definition: MELaserPrim.h:200
static const char module_[]
type
Definition: HCALResponse.h:21
static XYCoord localCoord(int icr)
Definition: MEEBGeom.cc:153
Int_t pn_pnID
Definition: MELaserPrim.h:178
TBranch * b_ab_channelID
Definition: MELaserPrim.h:225
int events
Definition: ME.h:80
bool _isBarrel
Definition: MELaserPrim.h:79
TBranch * b_tppn_moduleID
Definition: MELaserPrim.h:260
int dcc
Definition: ME.h:80
int mgpagain
Definition: ME.h:87
TBranch * b_apdpn_apdpn[iSizeArray_apdpn]
Definition: MELaserPrim.h:220
TString _inpath
Definition: MELaserPrim.h:131
int wavelength
Definition: ME.h:86
TBranch * b_tppn_PN
Definition: MELaserPrim.h:262
TString _outfile
Definition: MELaserPrim.h:134
static bool getViewIds(int logicId, int &channelView, int &id1, int &id2)
Definition: MELaserPrim.cc:120
static TString mtq_varUnit[iSize_mtq]
Definition: MELaserPrim.h:271
TBranch * b_tppn_pnID
Definition: MELaserPrim.h:259
TTree * apdpn_tree
Definition: MELaserPrim.h:123
TBranch * b_apdpn_channelID
Definition: MELaserPrim.h:212
Double_t pn_PN[iSize_apdpn]
Definition: MELaserPrim.h:180
TBranch * b_pn_pnID
Definition: MELaserPrim.h:233
TFile * mtq_file
Definition: MELaserPrim.h:118
void writeHistograms()
Definition: MELaserPrim.cc:932
TBranch * b_pn_PNoPNA
Definition: MELaserPrim.h:237
void fillHistograms()
Definition: MELaserPrim.cc:504
Double_t pn_PNoPNB[iSize_apdpn]
Definition: MELaserPrim.h:183
Int_t pn_moduleID
Definition: MELaserPrim.h:179
static int crystal_channel(EBLocalCoord ix, EBLocalCoord iy)
Definition: MEEBGeom.cc:332
TString _tpPrimStr
Definition: MELaserPrim.h:111
TTree * tppn_tree
Definition: MELaserPrim.h:128
static char const * tname
Definition: GTSchema.h:13
Int_t tppn_moduleID
Definition: MELaserPrim.h:205
Definition: ME.h:16
TimeStamp ts_beg
Definition: ME.h:81
Int_t tpapd_ieta
Definition: MELaserPrim.h:192
TBranch * b_ab_ab[iSize_ab]
Definition: MELaserPrim.h:229
Double_t pn_PNoPN[iSize_apdpn]
Definition: MELaserPrim.h:181
TBranch * b_ab_towerID
Definition: MELaserPrim.h:224
Double_t ab_ab[iSize_ab]
Definition: MELaserPrim.h:174
Int_t getInt(const char *, int ix, int iy)
TBranch * b_tpapd_dccID
Definition: MELaserPrim.h:248
TBranch * b_mtq_side
Definition: MELaserPrim.h:241
static TString apdpn_varName[iSize_apdpn]
Definition: MELaserPrim.h:265
bool setVal(const char *, int ix, int iy, float val)
Int_t ab_flag
Definition: MELaserPrim.h:173
static TString apdpn_arrayName[iSizeArray_apdpn]
Definition: MELaserPrim.h:264
int filter
Definition: ME.h:86
Int_t tppn_gain
Definition: MELaserPrim.h:206
Double_t mtq_mtq[iSize_mtq]
Definition: MELaserPrim.h:188
static std::pair< ME::DCCid, ME::PNid > pn(ME::LMRid ilmr, ME::LMMid ilmmod, ME::PN ipn)
Definition: ME.cc:648
TBranch * b_tpapd_gain
Definition: MELaserPrim.h:254
Int_t ab_towerID
Definition: MELaserPrim.h:169
TBranch * b_tpapd_APD
Definition: MELaserPrim.h:255
std::map< TString, TTree * > t_t
Definition: MELaserPrim.h:149
Int_t tpapd_dccID
Definition: MELaserPrim.h:193
Int_t ab_ieta
Definition: MELaserPrim.h:171
static Time time_low(TimeStamp t)
Definition: ME.cc:232
Int_t tppn_side
Definition: MELaserPrim.h:203
static TString channelViewName(int)
Definition: MELaserPrim.cc:94
TBranch * b_ab_ieta
Definition: MELaserPrim.h:226
TBranch * b_apdpn_ieta
Definition: MELaserPrim.h:216
Int_t tpapd_side
Definition: MELaserPrim.h:194
Int_t ab_channelID
Definition: MELaserPrim.h:170
Int_t apdpn_iphi
Definition: MELaserPrim.h:162
ME::TimeStamp _ts_end
Definition: MELaserPrim.h:96
Int_t tpapd_towerID
Definition: MELaserPrim.h:195
TBranch * b_pn_moduleID
Definition: MELaserPrim.h:234
TTree * ab_tree
Definition: MELaserPrim.h:124
Int_t tpapd_iphi
Definition: MELaserPrim.h:191
Definition: ME.h:70
bool init_ok
Definition: MELaserPrim.h:48
TTree * mtq_tree
Definition: MELaserPrim.h:126
Definition: ME.h:70
static TString apdpn_extraVarUnit[iSizeExtra_apdpn]
Definition: MELaserPrim.h:268
bool fill(const char *tname)
Definition: ME.h:69
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
MELaserPrim(ME::Header header, ME::Settings settings, const char *inpath, const char *outfile)
Definition: MELaserPrim.cc:32
TBranch * b_pn_PN
Definition: MELaserPrim.h:235
Int_t pn_side
Definition: MELaserPrim.h:177
static TString mtq_varName[iSize_mtq]
Definition: MELaserPrim.h:270
Float_t getVal(const char *, int ix, int iy)
void addBranchC(const char *t_name, const char *v_name)
void print(std::ostream &o)
TBranch * b_pn_side
Definition: MELaserPrim.h:232
TBranch * b_tpapd_flag
Definition: MELaserPrim.h:253
TimeStamp ts_end
Definition: ME.h:81
void bookHistograms()
Definition: MELaserPrim.cc:326
TBranch * b_tppn_gain
Definition: MELaserPrim.h:261
TFile * apdpn_file
Definition: MELaserPrim.h:115
Int_t mtq_side
Definition: MELaserPrim.h:186
TBranch * b_ab_dccID
Definition: MELaserPrim.h:223
TBranch * b_apdpn_ShapeCor
Definition: MELaserPrim.h:219
bool setInt(const char *, int ix, int iy, int ival)
Definition: ME.h:70
TBranch * b_pn_PNoPN
Definition: MELaserPrim.h:236
std::map< TString, TH2 * > i_h
Definition: MELaserPrim.h:145
Definition: ME.h:70
TString _primStr
Definition: MELaserPrim.h:108
Int_t tpapd_flag
Definition: MELaserPrim.h:198
static int logicId(int channelView, int id1, int id2=0)
Definition: MELaserPrim.cc:113
Int_t apdpn_moduleID
Definition: MELaserPrim.h:158
Definition: ME.h:16
TBranch * b_tpapd_towerID
Definition: MELaserPrim.h:250
std::pair< EBLocalCoord, EBLocalCoord > XYCoord
Definition: MEEBGeom.h:27
ii
Definition: cuy.py:588
Int_t apdpn_flag
Definition: MELaserPrim.h:163
int side
Definition: ME.h:80
static TString lmfLaserName(int table, int type, int color=ME::iBlue)
int lb
Definition: ME.h:80
void refresh()
std::map< TString, const char * > c_t
Definition: MELaserPrim.h:152
int run
Definition: ME.h:80
TBranch * b_tppn_side
Definition: MELaserPrim.h:258
Int_t ab_iphi
Definition: MELaserPrim.h:172
void addBranchI(const char *t_name, const char *v_name)
TBranch * b_pn_PNoPNB
Definition: MELaserPrim.h:238
static TString ab_varName[iSize_ab]
Definition: MELaserPrim.h:269
static TString apdpn_varUnit[iSizeArray_apdpn][iSize_apdpn]
Definition: MELaserPrim.h:266
TBranch * b_apdpn_flag
Definition: MELaserPrim.h:218
Int_t tpapd_gain
Definition: MELaserPrim.h:199
int power
Definition: ME.h:86
TBranch * b_ab_flag
Definition: MELaserPrim.h:228
TBranch * b_mtq_mtq[iSize_mtq]
Definition: MELaserPrim.h:243
TBranch * b_tpapd_side
Definition: MELaserPrim.h:249
Double_t apdpn_ShapeCor
Definition: MELaserPrim.h:164
Int_t tpapd_moduleID
Definition: MELaserPrim.h:197
Double_t pn_PNoPNA[iSize_apdpn]
Definition: MELaserPrim.h:182
Int_t apdpn_channelID
Definition: MELaserPrim.h:157
Int_t apdpn_ieta
Definition: MELaserPrim.h:161
Int_t ab_dccID
Definition: MELaserPrim.h:168
Definition: ME.h:78
int type
Definition: ME.h:86
TBranch * b_tpapd_iphi
Definition: MELaserPrim.h:246
static int lmr(int idcc, int iside)
Definition: ME.cc:261
Int_t tppn_pnID
Definition: MELaserPrim.h:204
TBranch * b_tpapd_channelID
Definition: MELaserPrim.h:251
TString _pnPrimStr
Definition: MELaserPrim.h:109
TTree * tpapd_tree
Definition: MELaserPrim.h:127
static TString apdpn_extraVarName[iSizeExtra_apdpn]
Definition: MELaserPrim.h:267
TString _pulseStr
Definition: MELaserPrim.h:110
double a
Definition: hdecay.h:121
Definition: ME.h:70
static Time time_high(TimeStamp t)
Definition: ME.cc:238
TBranch * b_tpapd_moduleID
Definition: MELaserPrim.h:252
static int dee(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:284
Int_t apdpn_towerID
Definition: MELaserPrim.h:156
Int_t tpapd_channelID
Definition: MELaserPrim.h:196
ME::TimeStamp _ts_beg
Definition: MELaserPrim.h:95
PN
Definition: ME.h:46
TBranch * b_tpapd_ieta
Definition: MELaserPrim.h:247
TBranch * b_apdpn_iphi
Definition: MELaserPrim.h:217
int delay
Definition: ME.h:86
virtual ~MELaserPrim()
Definition: MELaserPrim.cc:966
TFile * ab_file
Definition: MELaserPrim.h:116
TBranch * b_apdpn_towerID
Definition: MELaserPrim.h:211
void addBranchF(const char *t_name, const char *v_name)
TBranch * b_apdpn_side
Definition: MELaserPrim.h:215
ME::TimeStamp _ts
Definition: MELaserPrim.h:94
TFile * out_file
Definition: MELaserPrim.h:120
void setHistoStyle(TH1 *)
Double_t apdpn_apdpn[iSizeArray_apdpn][iSize_apdpn]
Definition: MELaserPrim.h:165
static TString smName(int ilmr)
Definition: ME.cc:415
void bookHistoI(const char *t_name, const char *v_name)
TBranch * b_ab_iphi
Definition: MELaserPrim.h:227
static TString separator
Definition: MELaserPrim.h:73
TString _sectorStr
Definition: MELaserPrim.h:106
TString _regionStr
Definition: MELaserPrim.h:107
Double_t tppn_PN[iSize_apdpn]
Definition: MELaserPrim.h:207
TString _tpPnPrimStr
Definition: MELaserPrim.h:112
int memgain
Definition: ME.h:87
TFile * tpapd_file
Definition: MELaserPrim.h:119
TBranch * b_apdpn_dccID
Definition: MELaserPrim.h:210
std::map< TString, int > i_t
Definition: MELaserPrim.h:150
TTree * pn_tree
Definition: MELaserPrim.h:125
std::map< TString, TH2 * > f_h
Definition: MELaserPrim.h:146
TBranch * b_apdpn_moduleID
Definition: MELaserPrim.h:213
Int_t apdpn_side
Definition: MELaserPrim.h:160
void bookHistoF(const char *t_name, const char *v_name)