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