CMS 3D CMS Logo

EcalTestPulseAnalyzer.cc
Go to the documentation of this file.
1 /*
2  *
3  * \class EcalTestPulseAnalyzer
4  *
5  * primary author: Julie Malcles - CEA/Saclay
6  * author: Gautier Hamel De Monchenault - CEA/Saclay
7  */
8 #include <TFile.h>
9 #include <TTree.h>
10 
11 using namespace std;
12 #include "EcalTestPulseAnalyzer.h"
13 
14 #include <sstream>
15 #include <iostream>
16 #include <iomanip>
17 
20 
26 
30 
34 
38 
41 
42 using namespace std;
43 
44 //========================================================================
46  //========================================================================
47  : iEvent(0),
48 
49  // framework parameters with default values
50 
51  _nsamples(iConfig.getUntrackedParameter<unsigned int>("nSamples", 10)),
52  _presample(iConfig.getUntrackedParameter<unsigned int>("nPresamples", 3)),
53  _firstsample(iConfig.getUntrackedParameter<unsigned int>("firstSample", 1)),
54  _lastsample(iConfig.getUntrackedParameter<unsigned int>("lastSample", 2)),
55  _samplemin(iConfig.getUntrackedParameter<unsigned int>("sampleMin", 3)),
56  _samplemax(iConfig.getUntrackedParameter<unsigned int>("sampleMax", 9)),
57  _nsamplesPN(iConfig.getUntrackedParameter<unsigned int>("nSamplesPN", 50)),
58  _presamplePN(iConfig.getUntrackedParameter<unsigned int>("nPresamplesPN", 6)),
59  _firstsamplePN(iConfig.getUntrackedParameter<unsigned int>("firstSamplePN", 7)),
60  _lastsamplePN(iConfig.getUntrackedParameter<unsigned int>("lastSamplePN", 8)),
61  _niter(iConfig.getUntrackedParameter<unsigned int>("nIter", 3)),
62  _chi2max(iConfig.getUntrackedParameter<double>("chi2Max", 10.0)),
63  _timeofmax(iConfig.getUntrackedParameter<double>("timeOfMax", 4.5)),
64  _ecalPart(iConfig.getUntrackedParameter<std::string>("ecalPart", "EB")),
65  _fedid(iConfig.getUntrackedParameter<int>("fedID", -999)),
66  nCrys(NCRYSEB),
67  nTT(NTTEB),
68  nMod(NMODEB),
69  nGainPN(NGAINPN),
70  nGainAPD(NGAINAPD),
71  towerID(-1),
72  channelID(-1),
73  runType(-1),
74  runNum(0),
75  fedID(-1),
76  dccID(-1),
77  side(-1),
78  iZ(1),
79  phi(-1),
80  eta(-1),
81  event(0),
82  apdAmpl(0),
83  apdTime(0),
84  pnAmpl(0),
85  pnID(-1),
86  moduleID(-1),
87  channelIteratorEE(0)
88 
89 //========================================================================
90 
91 {
92  //now do what ever initialization is needed
93 
94  resdir_ = iConfig.getUntrackedParameter<std::string>("resDir");
95 
96  digiCollection_ = iConfig.getParameter<std::string>("digiCollection");
97  digiPNCollection_ = iConfig.getParameter<std::string>("digiPNCollection");
98  digiProducer_ = iConfig.getParameter<std::string>("digiProducer");
99 
100  eventHeaderCollection_ = iConfig.getParameter<std::string>("eventHeaderCollection");
101  eventHeaderProducer_ = iConfig.getParameter<std::string>("eventHeaderProducer");
102 
103  // Define geometrical constants
104 
105  if (_ecalPart == "EB") {
106  nCrys = NCRYSEB;
107  nTT = NTTEB;
108  } else {
109  nCrys = NCRYSEE;
110  nTT = NTTEE;
111  }
112 
113  iZ = 1;
114  if (_fedid <= 609)
115  iZ = -1;
116 
119  nMod = modules.size();
120 }
121 
122 //========================================================================
124  //========================================================================
125 
126  // do anything here that needs to be done at desctruction time
127  // (e.g. close files, deallocate resources etc.)
128 }
129 
130 //========================================================================
132  //========================================================================
133 
134  // Define temporary file
135 
136  rootfile = resdir_;
137  rootfile += "/TmpTreeTestPulseAnalyzer.root";
138 
139  outFile = new TFile(rootfile.c_str(), "RECREATE");
140 
141  for (unsigned int i = 0; i < nCrys; i++) {
142  std::stringstream name;
143  name << "Tree" << i;
144 
145  trees[i] = new TTree(name.str().c_str(), name.str().c_str());
146 
147  //List of branches
148 
149  trees[i]->Branch("iphi", &phi, "phi/I");
150  trees[i]->Branch("ieta", &eta, "eta/I");
151  trees[i]->Branch("side", &side, "side/I");
152  trees[i]->Branch("dccID", &dccID, "dccID/I");
153  trees[i]->Branch("towerID", &towerID, "towerID/I");
154  trees[i]->Branch("channelID", &channelID, "channelID/I");
155  trees[i]->Branch("event", &event, "event/I");
156  trees[i]->Branch("apdGain", &apdGain, "apdGain/I");
157  trees[i]->Branch("pnGain", &pnGain, "pnGain/I");
158  trees[i]->Branch("apdAmpl", &apdAmpl, "apdAmpl/D");
159  trees[i]->Branch("pnAmpl0", &pnAmpl0, "pnAmpl0/D");
160  trees[i]->Branch("pnAmpl1", &pnAmpl1, "pnAmpl1/D");
161 
162  trees[i]->SetBranchAddress("ieta", &eta);
163  trees[i]->SetBranchAddress("iphi", &phi);
164  trees[i]->SetBranchAddress("side", &side);
165  trees[i]->SetBranchAddress("dccID", &dccID);
166  trees[i]->SetBranchAddress("towerID", &towerID);
167  trees[i]->SetBranchAddress("channelID", &channelID);
168  trees[i]->SetBranchAddress("event", &event);
169  trees[i]->SetBranchAddress("apdGain", &apdGain);
170  trees[i]->SetBranchAddress("pnGain", &pnGain);
171  trees[i]->SetBranchAddress("apdAmpl", &apdAmpl);
172  trees[i]->SetBranchAddress("pnAmpl0", &pnAmpl0);
173  trees[i]->SetBranchAddress("pnAmpl1", &pnAmpl1);
174  }
175 
176  // Initializations
177 
178  for (unsigned int j = 0; j < nCrys; j++) {
179  iEta[j] = -1;
180  iPhi[j] = -1;
181  iModule[j] = 10;
182  iTowerID[j] = -1;
183  iChannelID[j] = -1;
184  idccID[j] = -1;
185  iside[j] = -1;
186  }
187 
188  for (unsigned int j = 0; j < nMod; j++) {
189  firstChanMod[j] = 0;
190  isFirstChanModFilled[j] = 0;
191  }
192 
193  // Define output results file name
194 
195  std::stringstream namefile;
196  namefile << resdir_ << "/APDPN_TESTPULSE.root";
197  resfile = namefile.str();
198 
199  // TP events counter
200  TPEvents = 0;
201 }
202 
203 //========================================================================
205  //========================================================================
206 
207  ++iEvent;
208 
209  // Retrieve DCC header
211  const EcalRawDataCollection* DCCHeader = nullptr;
212  try {
213  e.getByLabel(eventHeaderProducer_, eventHeaderCollection_, pDCCHeader);
214  DCCHeader = pDCCHeader.product();
215  } catch (std::exception& ex) {
216  std::cerr << "Error! can't get the product retrieving DCC header" << eventHeaderCollection_.c_str() << std::endl;
217  }
218 
219  // retrieving crystal EB data from Event
221  const EBDigiCollection* EBDigi = nullptr;
222 
223  // retrieving crystal EE data from Event
225  const EEDigiCollection* EEDigi = nullptr;
226 
227  if (_ecalPart == "EB") {
228  try {
229  e.getByLabel(digiProducer_, digiCollection_, pEBDigi);
230  EBDigi = pEBDigi.product();
231  } catch (std::exception& ex) {
232  std::cerr << "Error! can't get the product retrieving EB crystal data " << digiCollection_.c_str() << std::endl;
233  }
234  } else {
235  try {
236  e.getByLabel(digiProducer_, digiCollection_, pEEDigi);
237  EEDigi = pEEDigi.product();
238  } catch (std::exception& ex) {
239  std::cerr << "Error! can't get the product retrieving EE crystal data " << digiCollection_.c_str() << std::endl;
240  }
241  }
242 
243  // Retrieve crystal PN diodes from Event
245  const EcalPnDiodeDigiCollection* PNDigi = nullptr;
246  try {
247  e.getByLabel(digiProducer_, digiPNCollection_, pPNDigi);
248  PNDigi = pPNDigi.product();
249  } catch (std::exception& ex) {
250  std::cerr << "Error! can't get the product " << digiCollection_.c_str() << std::endl;
251  }
252 
253  // retrieving electronics mapping
255  const EcalElectronicsMapping* TheMapping = nullptr;
256  try {
257  c.get<EcalMappingRcd>().get(ecalmapping);
258  TheMapping = ecalmapping.product();
259  } catch (std::exception& ex) {
260  std::cerr << "Error! can't get the product EcalMappingRcd" << std::endl;
261  }
262 
263  // ====================================
264  // Decode Basic DCCHeader Information
265  // ====================================
266 
267  for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
268  ++headerItr) {
269  int fed = headerItr->fedId();
270 
271  if (fed != _fedid && _fedid != -999)
272  continue;
273 
274  runType = headerItr->getRunType();
275  runNum = headerItr->getRunNumber();
276  event = headerItr->getLV1();
277 
278  dccID = headerItr->getDccInTCCCommand();
279  fedID = headerItr->fedId();
280 
281  if (600 + dccID != fedID)
282  continue;
283 
284  // Cut on runType
285 
288  return;
289  }
290 
291  // Cut on fedID
292 
293  if (fedID != _fedid && _fedid != -999)
294  return;
295 
296  // Count TP events
297  TPEvents++;
298 
299  // ======================
300  // Decode PN Information
301  // ======================
302 
303  TPNFit* pnfit = new TPNFit();
305 
306  double chi2pn = 0;
307  double ypnrange[50];
308  double dsum = 0.;
309  double dsum1 = 0.;
310  double bl = 0.;
311  double val_max = 0.;
312  int samplemax = 0;
313  unsigned int k;
314  int pnG[50];
315  int pngain = 0;
316 
317  std::map<int, std::vector<double> > allPNAmpl;
318  std::map<int, std::vector<int> > allPNGain;
319 
320  for (EcalPnDiodeDigiCollection::const_iterator pnItr = PNDigi->begin(); pnItr != PNDigi->end();
321  ++pnItr) { // Loop on PNs
322 
323  EcalPnDiodeDetId pnDetId = EcalPnDiodeDetId((*pnItr).id());
324 
325  bool isMemRelevant = false;
326  for (unsigned int imem = 0; imem < dccMEM.size(); imem++) {
327  if (pnDetId.iDCCId() == dccMEM[imem]) {
328  isMemRelevant = true;
329  }
330  }
331 
332  // skip mem dcc without relevant data
333  if (!isMemRelevant)
334  continue;
335 
336  for (int samId = 0; samId < (*pnItr).size(); samId++) { // Loop on PN samples
337  pn[samId] = (*pnItr).sample(samId).adc();
338  pnG[samId] = (*pnItr).sample(samId).gainId();
339 
340  if (pnG[samId] != 1)
341  std::cout << "PN gain different from 1 for sample " << samId << std::endl;
342  if (samId == 0)
343  pngain = pnG[samId];
344  if (samId > 0)
345  pngain = TMath::Max(pnG[samId], pngain);
346  }
347 
348  for (dsum = 0., k = 0; k < _presamplePN; k++) {
349  dsum += pn[k];
350  }
351  bl = dsum / ((double)_presamplePN);
352 
353  for (val_max = 0., k = 0; k < _nsamplesPN; k++) {
354  ypnrange[k] = pn[k] - bl;
355 
356  if (ypnrange[k] > val_max) {
357  val_max = ypnrange[k];
358  samplemax = k;
359  }
360  }
361 
362  chi2pn = pnfit->doFit(samplemax, &ypnrange[0]);
363 
364  if (chi2pn == 101 || chi2pn == 102 || chi2pn == 103)
365  pnAmpl = 0.;
366  else
367  pnAmpl = pnfit->getAmpl();
368 
369  allPNAmpl[pnDetId.iDCCId()].push_back(pnAmpl);
370  allPNGain[pnDetId.iDCCId()].push_back(pngain);
371  }
372 
373  // ===========================
374  // Decode EBDigis Information
375  // ===========================
376 
377  TSFit* pstpfit = new TSFit(_nsamples, 650);
378  pstpfit->set_params(
380  pstpfit->init_errmat(10.);
381 
382  double chi2 = 0;
383  double yrange[10];
384  int adcgain = 0;
385  int adcG[10];
386 
387  if (EBDigi) {
388  for (EBDigiCollection::const_iterator digiItr = EBDigi->begin(); digiItr != EBDigi->end();
389  ++digiItr) { // Loop on EB crystals
390 
391  EBDetId id_crystal(digiItr->id());
392  EBDataFrame df(*digiItr);
393 
394  int etaG = id_crystal.ieta(); // global
395  int phiG = id_crystal.iphi(); // global
396 
397  int etaL; // local
398  int phiL; // local
399  std::pair<int, int> LocalCoord = MEEBGeom::localCoord(etaG, phiG);
400 
401  etaL = LocalCoord.first;
402  phiL = LocalCoord.second;
403 
404  eta = etaG;
405  phi = phiG;
406 
407  side = MEEBGeom::side(etaG, phiG);
408 
409  EcalElectronicsId elecid_crystal = TheMapping->getElectronicsId(id_crystal);
410 
411  towerID = elecid_crystal.towerId();
412  int strip = elecid_crystal.stripId();
413  int xtal = elecid_crystal.xtalId();
414  channelID = 5 * (strip - 1) + xtal - 1; // FIXME
415 
416  int module = MEEBGeom::lmmod(etaG, phiG);
417  int iMod = module - 1;
418 
419  assert(module >= *min_element(modules.begin(), modules.end()) &&
420  module <= *max_element(modules.begin(), modules.end()));
421 
422  std::pair<int, int> pnpair = MEEBGeom::pn(module);
423  unsigned int MyPn0 = pnpair.first;
424  unsigned int MyPn1 = pnpair.second;
425 
426  unsigned int channel = MEEBGeom::electronic_channel(etaL, phiL);
427 
428  if (isFirstChanModFilled[iMod] == 0) {
429  firstChanMod[iMod] = channel;
430  isFirstChanModFilled[iMod] = 1;
431  }
432 
433  iEta[channel] = eta;
434  iPhi[channel] = phi;
435  iModule[channel] = module;
436  iTowerID[channel] = towerID;
437  iChannelID[channel] = channelID;
438  idccID[channel] = dccID;
439  iside[channel] = side;
440 
441  // get adc samples
442  //====================
443 
444  for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
445  EcalMGPASample samp_crystal(df.sample(i));
446  adc[i] = samp_crystal.adc();
447  adcG[i] = samp_crystal.gainId();
448 
449  if (i == 0)
450  adcgain = adcG[i];
451  if (i > 0)
452  adcgain = TMath::Max(adcG[i], adcgain);
453  }
454  // Remove pedestal
455  //====================
456  for (dsum = 0., dsum1 = 0., k = 0; k < _presample; k++) {
457  dsum += adc[k];
458  if (k < _presample - 1)
459  dsum1 += adc[k];
460  }
461 
462  bl = dsum / ((double)_presample);
463 
464  for (val_max = 0., k = 0; k < _nsamples; k++) {
465  yrange[k] = adc[k] - bl;
466  if (yrange[k] > val_max) {
467  val_max = yrange[k];
468  samplemax = k;
469  }
470  }
471 
472  apdGain = adcgain;
473 
474  if (allPNAmpl[dccMEM[0]].size() > MyPn0)
475  pnAmpl0 = allPNAmpl[dccMEM[0]][MyPn0];
476  else
477  pnAmpl0 = 0;
478  if (allPNAmpl[dccMEM[0]].size() > MyPn1)
479  pnAmpl1 = allPNAmpl[dccMEM[0]][MyPn1];
480  else
481  pnAmpl1 = 0;
482 
483  if (allPNGain[dccMEM[0]].size() > MyPn0)
484  pnGain = allPNGain[dccMEM[0]][MyPn0];
485  else
486  pnGain = 0;
487 
488  // Perform the fit on apd samples
489  //================================
490 
491  chi2 = pstpfit->fit_third_degree_polynomial(&yrange[0], ret_data);
492 
493  //Retrieve APD amplitude from fit
494  //================================
495 
496  if (val_max > 100000. || chi2 < 0. || chi2 == 102) {
497  apdAmpl = 0;
498  apdTime = 0;
499 
500  } else {
501  apdAmpl = ret_data[0];
502  apdTime = ret_data[1];
503  }
504 
505  trees[channel]->Fill();
506  }
507 
508  } else {
509  for (EEDigiCollection::const_iterator digiItr = EEDigi->begin(); digiItr != EEDigi->end();
510  ++digiItr) { // Loop on EE crystals
511 
512  EEDetId id_crystal(digiItr->id());
513  EEDataFrame df(*digiItr);
514 
515  phi = id_crystal.ix();
516  eta = id_crystal.iy();
517 
518  int iX = (phi - 1) / 5 + 1;
519  int iY = (eta - 1) / 5 + 1;
520 
521  side = MEEEGeom::side(iX, iY, iZ);
522 
523  // Recover the TT id and the electronic crystal numbering from EcalElectronicsMapping
524 
525  EcalElectronicsId elecid_crystal = TheMapping->getElectronicsId(id_crystal);
526 
527  towerID = elecid_crystal.towerId();
528  channelID = elecid_crystal.channelId() - 1;
529 
530  int module = MEEEGeom::lmmod(iX, iY);
531  if (module >= 18 && side == 1)
532  module += 2; // Trick to fix endcap specificity
533  int iMod = module - 1;
534 
535  assert(module >= *min_element(modules.begin(), modules.end()) &&
536  module <= *max_element(modules.begin(), modules.end()));
537 
538  std::pair<int, int> pnpair = MEEEGeom::pn(module, _fedid);
539 
540  unsigned int MyPn0 = pnpair.first;
541  unsigned int MyPn1 = pnpair.second;
542 
543  int hashedIndex = 100000 * eta + phi;
544 
545  if (channelMapEE.count(hashedIndex) == 0) {
548  }
549 
550  unsigned int channel = channelMapEE[hashedIndex];
551 
552  if (isFirstChanModFilled[iMod] == 0) {
553  firstChanMod[iMod] = channel;
554  isFirstChanModFilled[iMod] = 1;
555  }
556 
557  iEta[channel] = eta;
558  iPhi[channel] = phi;
559  iModule[channel] = module;
560  iTowerID[channel] = towerID;
561  iChannelID[channel] = channelID;
562  idccID[channel] = dccID;
563  iside[channel] = side;
564 
565  assert(channel < nCrys);
566 
567  // Get adc samples
568  //====================
569 
570  for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
571  EcalMGPASample samp_crystal(df.sample(i));
572  adc[i] = samp_crystal.adc();
573  adcG[i] = samp_crystal.gainId();
574 
575  if (i == 0)
576  adcgain = adcG[i];
577  if (i > 0)
578  adcgain = TMath::Max(adcG[i], adcgain);
579  }
580 
581  // Remove pedestal
582  //====================
583  for (dsum = 0., dsum1 = 0., k = 0; k < _presample; k++) {
584  dsum += adc[k];
585  if (k < _presample - 1)
586  dsum1 += adc[k];
587  }
588 
589  bl = dsum / ((double)_presample);
590 
591  for (val_max = 0., k = 0; k < _nsamples; k++) {
592  yrange[k] = adc[k] - bl;
593  if (yrange[k] > val_max) {
594  val_max = yrange[k];
595  samplemax = k;
596  }
597  }
598  apdGain = adcgain;
599 
600  int dccMEMIndex = 0;
601  if (side == 1)
602  dccMEMIndex += 2; // Trick to fix endcap specificity
603 
604  if (allPNAmpl[dccMEM[dccMEMIndex]].size() > MyPn0)
605  pnAmpl0 = allPNAmpl[dccMEM[dccMEMIndex]][MyPn0];
606  else
607  pnAmpl0 = 0;
608  if (allPNAmpl[dccMEM[dccMEMIndex + 1]].size() > MyPn1)
609  pnAmpl1 = allPNAmpl[dccMEM[dccMEMIndex + 1]][MyPn1];
610  else
611  pnAmpl1 = 0;
612 
613  if (allPNGain[dccMEM[dccMEMIndex]].size() > MyPn0)
614  pnGain = allPNGain[dccMEM[dccMEMIndex]][MyPn0];
615  else
616  pnGain = 0;
617 
618  // Perform the fit on apd samples
619  //=================================
620 
621  chi2 = pstpfit->fit_third_degree_polynomial(&yrange[0], ret_data);
622 
623  //Retrieve APD amplitude from fit
624  //=================================
625 
626  if (val_max > 100000. || chi2 < 0. || chi2 == 102) {
627  apdAmpl = 0;
628  apdTime = 0;
629 
630  } else {
631  apdAmpl = ret_data[0];
632  apdTime = ret_data[1];
633  }
634 
635  trees[channel]->Fill();
636  }
637  }
638 
639 } // end of analyze
640 
641 //========================================================================
643  //========================================================================
644 
645  // Don't do anything if there is no events
646  if (TPEvents == 0) {
647  outFile->Close();
648 
649  // Remove temporary file
650 
651  std::stringstream del;
652  del << "rm " << rootfile;
653  system(del.str().c_str());
654 
655  std::cout << " No TP Events " << std::endl;
656  return;
657  }
658 
659  std::cout << "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" << std::endl;
660  std::cout << "\t+=+ Analyzing test pulse data: getting APD, PN +=+" << std::endl;
661 
662  // Create output ntuples:
663 
664  //std::cout<< "TP Test Name File "<< resfile.c_str() << std::endl;
665 
666  resFile = new TFile(resfile.c_str(), "RECREATE");
667 
668  restrees = new TTree("TPAPD", "TPAPD");
669  respntrees = new TTree("TPPN", "TPPN");
670 
671  restrees->Branch("iphi", &iphi, "iphi/I");
672  restrees->Branch("ieta", &ieta, "ieta/I");
673  restrees->Branch("dccID", &dccID, "dccID/I");
674  restrees->Branch("side", &side, "side/I");
675  restrees->Branch("towerID", &towerID, "towerID/I");
676  restrees->Branch("channelID", &channelID, "channelID/I");
677  restrees->Branch("moduleID", &moduleID, "moduleID/I");
678  restrees->Branch("flag", &flag, "flag/I");
679  restrees->Branch("gain", &gain, "gain/I");
680  restrees->Branch("APD", &APD, "APD[6]/D");
681 
682  respntrees->Branch("pnID", &pnID, "pnID/I");
683  respntrees->Branch("moduleID", &moduleID, "moduleID/I");
684  respntrees->Branch("gain", &gain, "gain/I");
685  respntrees->Branch("PN", &PN, "PN[6]/D");
686 
687  restrees->SetBranchAddress("iphi", &iphi);
688  restrees->SetBranchAddress("ieta", &ieta);
689  restrees->SetBranchAddress("dccID", &dccID);
690  restrees->SetBranchAddress("side", &side);
691  restrees->SetBranchAddress("towerID", &towerID);
692  restrees->SetBranchAddress("channelID", &channelID);
693  restrees->SetBranchAddress("moduleID", &moduleID);
694  restrees->SetBranchAddress("flag", &flag);
695  restrees->SetBranchAddress("gain", &gain);
696  restrees->SetBranchAddress("APD", APD);
697 
698  respntrees->SetBranchAddress("pnID", &pnID);
699  respntrees->SetBranchAddress("moduleID", &moduleID);
700  respntrees->SetBranchAddress("gain", &gain);
701  respntrees->SetBranchAddress("PN", PN);
702 
703  TMom* APDAnal[1700][10];
704  TMom* PNAnal[9][2][10];
705 
706  for (unsigned int iMod = 0; iMod < nMod; iMod++) {
707  for (unsigned int ich = 0; ich < 2; ich++) {
708  for (unsigned int ig = 0; ig < nGainPN; ig++) {
709  PNAnal[iMod][ich][ig] = new TMom();
710  }
711  }
712  }
713 
714  for (unsigned int iCry = 0; iCry < nCrys; iCry++) { // Loop on data trees (ie on cristals)
715 
716  for (unsigned int iG = 0; iG < nGainAPD; iG++) {
717  APDAnal[iCry][iG] = new TMom();
718  }
719 
720  // Define submodule and channel number inside the submodule (as Patrice)
721 
722  unsigned int iMod = iModule[iCry] - 1;
723 
724  moduleID = iMod + 1;
725  if (moduleID >= 20)
726  moduleID -= 2; // Trick to fix endcap specificity
727 
728  Long64_t nbytes = 0, nb = 0;
729  for (Long64_t jentry = 0; jentry < trees[iCry]->GetEntriesFast(); jentry++) {
730  nb = trees[iCry]->GetEntry(jentry);
731  nbytes += nb;
732 
733  // PN Means and RMS
734 
735  if (firstChanMod[iMod] == iCry) {
736  PNAnal[iMod][0][pnGain]->addEntry(pnAmpl0);
737  PNAnal[iMod][1][pnGain]->addEntry(pnAmpl1);
738  }
739 
740  // APD means and RMS
741 
742  APDAnal[iCry][apdGain]->addEntry(apdAmpl);
743  }
744 
745  if (trees[iCry]->GetEntries() < 10) {
746  flag = -1;
747  for (int j = 0; j < 6; j++) {
748  APD[j] = 0.0;
749  }
750  } else
751  flag = 1;
752 
753  iphi = iPhi[iCry];
754  ieta = iEta[iCry];
755  dccID = idccID[iCry];
756  side = iside[iCry];
757  towerID = iTowerID[iCry];
758  channelID = iChannelID[iCry];
759 
760  for (unsigned int ig = 0; ig < nGainAPD; ig++) {
761  APD[0] = APDAnal[iCry][ig]->getMean();
762  APD[1] = APDAnal[iCry][ig]->getRMS();
763  APD[2] = APDAnal[iCry][ig]->getM3();
764  APD[3] = APDAnal[iCry][ig]->getNevt();
765  APD[4] = APDAnal[iCry][ig]->getMin();
766  APD[5] = APDAnal[iCry][ig]->getMax();
767  gain = ig;
768 
769  // Fill APD tree
770 
771  restrees->Fill();
772  }
773  }
774 
775  // Get final results for PN and PN/PN
776 
777  for (unsigned int ig = 0; ig < nGainPN; ig++) {
778  for (unsigned int iMod = 0; iMod < nMod; iMod++) {
779  for (int ch = 0; ch < 2; ch++) {
780  pnID = ch;
781  moduleID = iMod;
782  if (moduleID >= 20)
783  moduleID -= 2; // Trick to fix endcap specificity
784 
785  PN[0] = PNAnal[iMod][ch][ig]->getMean();
786  PN[1] = PNAnal[iMod][ch][ig]->getRMS();
787  PN[2] = PNAnal[iMod][ch][ig]->getM3();
788  PN[3] = PNAnal[iMod][ch][ig]->getNevt();
789  PN[4] = PNAnal[iMod][ch][ig]->getMin();
790  PN[5] = PNAnal[iMod][ch][ig]->getMax();
791  gain = ig;
792 
793  // Fill PN tree
794  respntrees->Fill();
795  }
796  }
797  }
798 
799  outFile->Close();
800 
801  // Remove temporary file
802 
803  std::stringstream del;
804  del << "rm " << rootfile;
805  system(del.str().c_str());
806 
807  // Save final results
808 
809  restrees->Write();
810  respntrees->Write();
811  resFile->Close();
812 
813  std::cout << "\t+=+ ...................................... done +=+" << std::endl;
814  std::cout << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" << std::endl;
815 }
816 
DeadROC_duringRun.runNum
runNum
Definition: DeadROC_duringRun.py:21
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
NMODEB
#define NMODEB
Definition: EcalLaserAnalyzer.h:37
EcalElectronicsMapping
Definition: EcalElectronicsMapping.h:28
EcalTestPulseAnalyzer::resdir_
std::string resdir_
Definition: EcalTestPulseAnalyzer.h:65
NCRYSEE
#define NCRYSEE
Definition: EcalABAnalyzer.h:33
TMom::addEntry
void addEntry(double val)
Definition: TMom.cc:88
EcalTestPulseAnalyzer::iZ
int iZ
Definition: EcalTestPulseAnalyzer.h:101
EcalTestPulseAnalyzer::EcalTestPulseAnalyzer
EcalTestPulseAnalyzer(const edm::ParameterSet &iConfig)
Definition: EcalTestPulseAnalyzer.cc:45
EcalTestPulseAnalyzer::pnAmpl
double pnAmpl
Definition: EcalTestPulseAnalyzer.h:126
EcalTestPulseAnalyzer::_fedid
int _fedid
Definition: EcalTestPulseAnalyzer.h:63
EcalElectronicsId.h
EcalTestPulseAnalyzer::pnAmpl1
double pnAmpl1
Definition: EcalTestPulseAnalyzer.h:125
mps_fire.i
i
Definition: mps_fire.py:428
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
EcalTestPulseAnalyzer::rootfile
std::string rootfile
Definition: EcalTestPulseAnalyzer.h:74
EcalTestPulseAnalyzer::nCrys
unsigned int nCrys
Definition: EcalTestPulseAnalyzer.h:80
MessageLogger.h
EcalTestPulseAnalyzer::_firstsample
unsigned int _firstsample
Definition: EcalTestPulseAnalyzer.h:51
NTTEE
#define NTTEE
Definition: EcalPerEvtLaserAnalyzer.h:30
edm::Handle::product
T const * product() const
Definition: Handle.h:70
TPNFit
Definition: TPNFit.h:8
ESHandle.h
edm::DataFrameContainer::const_iterator
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: DataFrameContainer.h:61
EcalTestPulseAnalyzer::eta
int eta
Definition: EcalTestPulseAnalyzer.h:114
EcalTestPulseAnalyzer::TPEvents
int TPEvents
Definition: EcalTestPulseAnalyzer.h:87
MEEBGeom::electronic_channel
static int electronic_channel(EBLocalCoord ix, EBLocalCoord iy)
Definition: MEEBGeom.cc:326
EcalTestPulseAnalyzer::digiCollection_
std::string digiCollection_
Definition: EcalTestPulseAnalyzer.h:66
EcalTestPulseAnalyzer::phi
int phi
Definition: EcalTestPulseAnalyzer.h:114
modules
Definition: ZHLTMatchFilter.cc:17
EcalTestPulseAnalyzer::iEvent
int iEvent
Definition: EcalTestPulseAnalyzer.h:45
EBDetId
Definition: EBDetId.h:17
NGAINPN
#define NGAINPN
Definition: EcalTestPulseAnalyzer.h:32
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
EBDataFrame
Definition: EBDataFrame.h:11
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalDetIdCollections.h
EcalTestPulseAnalyzer::gain
int gain
Definition: EcalTestPulseAnalyzer.h:139
EcalTestPulseAnalyzer::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: EcalTestPulseAnalyzer.cc:204
EcalTestPulseAnalyzer::nGainPN
unsigned int nGainPN
Definition: EcalTestPulseAnalyzer.h:83
TSFit
Definition: TSFit.h:15
EcalTestPulseAnalyzer::digiProducer_
std::string digiProducer_
Definition: EcalTestPulseAnalyzer.h:68
EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM
Definition: EcalDCCHeaderBlock.h:29
CollectionTags_cfi.EBDigi
EBDigi
Definition: CollectionTags_cfi.py:27
cms::cuda::assert
assert(be >=bs)
edm::SortedCollection
Definition: SortedCollection.h:49
EcalTestPulseAnalyzer::_niter
unsigned int _niter
Definition: EcalTestPulseAnalyzer.h:59
EcalTestPulseAnalyzer::towerID
int towerID
Definition: EcalTestPulseAnalyzer.h:91
NTTEB
#define NTTEB
Definition: EcalPerEvtLaserAnalyzer.h:25
EcalTestPulseAnalyzer::_samplemin
unsigned int _samplemin
Definition: EcalTestPulseAnalyzer.h:53
EcalTestPulseAnalyzer::pnGain
int pnGain
Definition: EcalTestPulseAnalyzer.h:120
EcalTestPulseAnalyzer::iside
int iside[1700]
Definition: EcalTestPulseAnalyzer.h:146
NCRYSEB
#define NCRYSEB
Definition: EcalABAnalyzer.h:30
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
EcalPnDiodeDetId
Definition: EcalPnDiodeDetId.h:22
EcalTestPulseAnalyzer::resFile
TFile * resFile
Definition: EcalTestPulseAnalyzer.h:106
EcalTestPulseAnalyzer::_lastsamplePN
unsigned int _lastsamplePN
Definition: EcalTestPulseAnalyzer.h:58
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
MEEBGeom::pn
static std::pair< int, int > pn(int ilmmod)
Definition: MEEBGeom.cc:447
edm::Handle
Definition: AssociativeIterator.h:50
ME::lmmodFromDcc
static std::vector< ME::LMMid > lmmodFromDcc(ME::DCCid idcc)
Definition: ME.cc:574
EcalTestPulseAnalyzer::apdGain
int apdGain
Definition: EcalTestPulseAnalyzer.h:119
EcalTestPulseAnalyzer::iChannelID
int iChannelID[1700]
Definition: EcalTestPulseAnalyzer.h:146
EcalTestPulseAnalyzer::restrees
TTree * restrees
Definition: EcalTestPulseAnalyzer.h:130
EcalElectronicsId::towerId
int towerId() const
get the tower id
Definition: EcalElectronicsId.h:33
EcalTestPulseAnalyzer::iphi
int iphi
Definition: EcalTestPulseAnalyzer.h:139
EcalTestPulseAnalyzer::pnID
int pnID
Definition: EcalTestPulseAnalyzer.h:140
EcalDCCHeaderBlock::TESTPULSE_GAP
Definition: EcalDCCHeaderBlock.h:43
EcalTestPulseAnalyzer::_nsamples
unsigned int _nsamples
Definition: EcalTestPulseAnalyzer.h:49
EcalTestPulseAnalyzer::nGainAPD
unsigned int nGainAPD
Definition: EcalTestPulseAnalyzer.h:84
NGAINAPD
#define NGAINAPD
Definition: EcalTestPulseAnalyzer.h:33
EcalTestPulseAnalyzer::nMod
unsigned int nMod
Definition: EcalTestPulseAnalyzer.h:82
MEEBGeom::side
static int side(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:105
EcalRawDataCollections.h
EcalTestPulseAnalyzer::fedID
int fedID
Definition: EcalTestPulseAnalyzer.h:98
MakerMacros.h
EcalTestPulseAnalyzer::eventHeaderCollection_
std::string eventHeaderCollection_
Definition: EcalTestPulseAnalyzer.h:69
EcalTestPulseAnalyzer::iModule
unsigned int iModule[1700]
Definition: EcalTestPulseAnalyzer.h:145
CollectionTags_cfi.EEDigi
EEDigi
Definition: CollectionTags_cfi.py:28
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TSFit::fit_third_degree_polynomial
double fit_third_degree_polynomial(double *, double *)
Definition: TSFit.cc:255
EcalElectronicsId::channelId
int channelId() const
so far for EndCap only :
Definition: EcalElectronicsId.cc:71
edm::SortedCollection::begin
const_iterator begin() const
Definition: SortedCollection.h:262
PVValHelper::eta
Definition: PVValidationHelpers.h:69
nTT
#define nTT
Definition: TMEGeom.h:6
EcalMappingRcd.h
EcalDigiCollections.h
EcalTestPulseAnalyzer::beginJob
void beginJob() override
Definition: EcalTestPulseAnalyzer.cc:131
edm::ESHandle< EcalElectronicsMapping >
EcalElectronicsMapping::getElectronicsId
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
Definition: EcalElectronicsMapping.cc:324
EcalTestPulseAnalyzer::apdTime
double apdTime
Definition: EcalTestPulseAnalyzer.h:123
EcalTestPulseAnalyzer::adc
double adc[10]
Definition: EcalTestPulseAnalyzer.h:116
EcalTestPulseAnalyzer::ret_data
double ret_data[20]
Definition: EcalTestPulseAnalyzer.h:89
EcalTestPulseAnalyzer::outFile
TFile * outFile
Definition: EcalTestPulseAnalyzer.h:105
dqmdumpme.k
k
Definition: dqmdumpme.py:60
EcalTestPulseAnalyzer::_chi2max
double _chi2max
Definition: EcalTestPulseAnalyzer.h:60
EcalTestPulseAnalyzer::trees
TTree * trees[1700]
Definition: EcalTestPulseAnalyzer.h:110
MEGeom.h
EcalDCCHeaderBlock::TESTPULSE_MGPA
Definition: EcalDCCHeaderBlock.h:30
EcalElectronicsId
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
Definition: EcalElectronicsId.h:18
MEEEGeom::pn
static std::pair< int, int > pn(int dee, int ilmod)
Definition: MEEEGeom.cc:574
EEDetId
Definition: EEDetId.h:14
EcalTestPulseAnalyzer::dccMEM
std::vector< int > dccMEM
Definition: EcalTestPulseAnalyzer.h:134
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalTestPulseAnalyzer::ieta
int ieta
Definition: EcalTestPulseAnalyzer.h:139
EcalTestPulseAnalyzer::_lastsample
unsigned int _lastsample
Definition: EcalTestPulseAnalyzer.h:52
EcalTestPulseAnalyzer::endJob
void endJob() override
Definition: EcalTestPulseAnalyzer.cc:642
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
EcalTestPulseAnalyzer::_ecalPart
std::string _ecalPart
Definition: EcalTestPulseAnalyzer.h:62
TPNFit.h
EcalPnDiodeDetId::iDCCId
int iDCCId() const
get the DCCId
Definition: EcalPnDiodeDetId.h:44
edm::ParameterSet
Definition: ParameterSet.h:47
TMom
Definition: TMom.h:7
EcalTestPulseAnalyzer::_samplemax
unsigned int _samplemax
Definition: EcalTestPulseAnalyzer.h:54
Event.h
TSFit::init_errmat
void init_errmat(double)
Definition: TSFit.cc:87
EcalTestPulseAnalyzer::flag
int flag
Definition: EcalTestPulseAnalyzer.h:139
TPNFit::getAmpl
double getAmpl()
Definition: TPNFit.h:31
EcalTestPulseAnalyzer::idccID
int idccID[1700]
Definition: EcalTestPulseAnalyzer.h:146
EcalTestPulseAnalyzer::APD
double APD[6]
Definition: EcalTestPulseAnalyzer.h:142
EcalTestPulseAnalyzer::runNum
int runNum
Definition: EcalTestPulseAnalyzer.h:97
EBDigiCollection
Definition: EcalDigiCollections.h:56
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
EcalTestPulseAnalyzer::resfile
std::string resfile
Definition: EcalTestPulseAnalyzer.h:75
EEDigiCollection
Definition: EcalDigiCollections.h:69
EcalTestPulseAnalyzer::pnG
int pnG
Definition: EcalTestPulseAnalyzer.h:121
EcalTestPulseAnalyzer::_firstsamplePN
unsigned int _firstsamplePN
Definition: EcalTestPulseAnalyzer.h:57
EcalElectronicsMapping.h
EcalTestPulseAnalyzer
Definition: EcalTestPulseAnalyzer.h:35
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
TMom::getM3
double getM3()
Definition: TMom.cc:156
EcalTestPulseAnalyzer::_timeofmax
double _timeofmax
Definition: EcalTestPulseAnalyzer.h:61
ME.h
TMom::getNevt
int getNevt()
Definition: TMom.cc:144
EcalTestPulseAnalyzer::iEta
int iEta[1700]
Definition: EcalTestPulseAnalyzer.h:144
Max
T Max(T a, T b)
Definition: MathUtil.h:44
EcalTestPulseAnalyzer::pn
double pn[50]
Definition: EcalTestPulseAnalyzer.h:117
edm::EventSetup
Definition: EventSetup.h:57
EcalTestPulseAnalyzer::digiPNCollection_
std::string digiPNCollection_
Definition: EcalTestPulseAnalyzer.h:67
EcalTestPulseAnalyzer::_presample
unsigned int _presample
Definition: EcalTestPulseAnalyzer.h:50
TPNFit::init
void init(int, int, int)
Definition: TPNFit.cc:24
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
EcalTestPulseAnalyzer::moduleID
int moduleID
Definition: EcalTestPulseAnalyzer.h:140
get
#define get
EcalTestPulseAnalyzer::channelID
int channelID
Definition: EcalTestPulseAnalyzer.h:92
TMom::getMean
double getMean()
Definition: TMom.cc:121
EcalMGPASample
Definition: EcalMGPASample.h:22
PedestalClient_cfi.pngain
pngain
Definition: PedestalClient_cfi.py:52
EcalTestPulseAnalyzer::eventHeaderProducer_
std::string eventHeaderProducer_
Definition: EcalTestPulseAnalyzer.h:70
EcalTestPulseAnalyzer.h
EcalTestPulseAnalyzer::nTT
unsigned int nTT
Definition: EcalTestPulseAnalyzer.h:81
EcalTestPulseAnalyzer::apdAmpl
double apdAmpl
Definition: EcalTestPulseAnalyzer.h:122
MEEEGeom::lmmod
static int lmmod(SuperCrysCoord iX, SuperCrysCoord iY)
Definition: MEEEGeom.cc:112
EcalTestPulseAnalyzer::isFirstChanModFilled
unsigned int isFirstChanModFilled[9]
Definition: EcalTestPulseAnalyzer.h:149
TPNFit::doFit
double doFit(int, double *)
Definition: TPNFit.cc:39
std
Definition: JetResolutionObject.h:76
EcalTestPulseAnalyzer::firstChanMod
unsigned int firstChanMod[9]
Definition: EcalTestPulseAnalyzer.h:148
EcalTestPulseAnalyzer::dccID
int dccID
Definition: EcalTestPulseAnalyzer.h:99
EcalMappingRcd
Definition: EcalMappingRcd.h:15
hgcalPerformanceValidation.df
df
Definition: hgcalPerformanceValidation.py:640
EcalTestPulseAnalyzer::iTowerID
int iTowerID[1700]
Definition: EcalTestPulseAnalyzer.h:146
TMom::getMax
double getMax()
Definition: TMom.cc:170
MEEBGeom::lmmod
static int lmmod(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:90
TMom.h
EcalTestPulseAnalyzer::channelIteratorEE
int channelIteratorEE
Definition: EcalTestPulseAnalyzer.h:141
ecaldqm::towerID
EcalLogicID towerID(EcalElectronicsId const &)
Definition: LogicIDTranslation.cc:37
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
EcalTestPulseAnalyzer::iPhi
int iPhi[1700]
Definition: EcalTestPulseAnalyzer.h:144
MEEBGeom::localCoord
static XYCoord localCoord(int icr)
Definition: MEEBGeom.cc:142
Exception.h
EcalTestPulseAnalyzer::pnAmpl0
double pnAmpl0
Definition: EcalTestPulseAnalyzer.h:124
EcalTestPulseAnalyzer::respntrees
TTree * respntrees
Definition: EcalTestPulseAnalyzer.h:131
EcalTestPulseAnalyzer::_nsamplesPN
unsigned int _nsamplesPN
Definition: EcalTestPulseAnalyzer.h:55
EcalTestPulseAnalyzer::runType
int runType
Definition: EcalTestPulseAnalyzer.h:96
MEEEGeom::side
static int side(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:1155
EcalElectronicsId::stripId
int stripId() const
get the tower id
Definition: EcalElectronicsId.h:35
TSFit.h
EcalTestPulseAnalyzer::_presamplePN
unsigned int _presamplePN
Definition: EcalTestPulseAnalyzer.h:56
ParameterSet.h
EcalTestPulseAnalyzer::~EcalTestPulseAnalyzer
~EcalTestPulseAnalyzer() override
Definition: EcalTestPulseAnalyzer.cc:123
EcalCondDBWriter_cfi.runType
runType
Definition: EcalCondDBWriter_cfi.py:64
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
event
Definition: event.py:1
EEDataFrame
Definition: EEDataFrame.h:12
edm::Event
Definition: Event.h:73
TMom::getRMS
double getRMS()
Definition: TMom.cc:146
TSFit::set_params
void set_params(int, int, int, int, int, double, double, int, int)
Definition: TSFit.cc:39
ME::memFromDcc
static std::vector< ME::DCCid > memFromDcc(ME::DCCid idcc)
Definition: ME.cc:561
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
EcalElectronicsId::xtalId
int xtalId() const
get the channel id
Definition: EcalElectronicsId.h:37
ecalpyutils::hashedIndex
int hashedIndex(int ieta, int iphi)
Definition: EcalPyUtils.cc:38
EcalTestPulseAnalyzer::channelMapEE
std::map< int, int > channelMapEE
Definition: EcalTestPulseAnalyzer.h:133
EcalTestPulseAnalyzer::side
int side
Definition: EcalTestPulseAnalyzer.h:100
EcalTestPulseAnalyzer::PN
double PN[6]
Definition: EcalTestPulseAnalyzer.h:142
TMom::getMin
double getMin()
Definition: TMom.cc:169
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37