CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  samplemax = k;
450  }
451  }
452 
453  apdGain = adcgain;
454 
455  if (allPNAmpl[dccMEM[0]].size() > MyPn0)
456  pnAmpl0 = allPNAmpl[dccMEM[0]][MyPn0];
457  else
458  pnAmpl0 = 0;
459  if (allPNAmpl[dccMEM[0]].size() > MyPn1)
460  pnAmpl1 = allPNAmpl[dccMEM[0]][MyPn1];
461  else
462  pnAmpl1 = 0;
463 
464  if (allPNGain[dccMEM[0]].size() > MyPn0)
465  pnGain = allPNGain[dccMEM[0]][MyPn0];
466  else
467  pnGain = 0;
468 
469  // Perform the fit on apd samples
470  //================================
471 
472  chi2 = pstpfit->fit_third_degree_polynomial(&yrange[0], ret_data);
473 
474  //Retrieve APD amplitude from fit
475  //================================
476 
477  if (val_max > 100000. || chi2 < 0. || chi2 == 102) {
478  apdAmpl = 0;
479  apdTime = 0;
480 
481  } else {
482  apdAmpl = ret_data[0];
483  apdTime = ret_data[1];
484  }
485 
486  trees[channel]->Fill();
487  }
488 
489  } else {
490  for (EEDigiCollection::const_iterator digiItr = EEDigi->begin(); digiItr != EEDigi->end();
491  ++digiItr) { // Loop on EE crystals
492 
493  EEDetId id_crystal(digiItr->id());
494  EEDataFrame df(*digiItr);
495 
496  phi = id_crystal.ix();
497  eta = id_crystal.iy();
498 
499  int iX = (phi - 1) / 5 + 1;
500  int iY = (eta - 1) / 5 + 1;
501 
502  side = MEEEGeom::side(iX, iY, iZ);
503 
504  // Recover the TT id and the electronic crystal numbering from EcalElectronicsMapping
505 
506  EcalElectronicsId elecid_crystal = TheMapping.getElectronicsId(id_crystal);
507 
508  towerID = elecid_crystal.towerId();
509  channelID = elecid_crystal.channelId() - 1;
510 
511  int module = MEEEGeom::lmmod(iX, iY);
512  if (module >= 18 && side == 1)
513  module += 2; // Trick to fix endcap specificity
514  int iMod = module - 1;
515 
516  assert(module >= *min_element(modules.begin(), modules.end()) &&
517  module <= *max_element(modules.begin(), modules.end()));
518 
519  std::pair<int, int> pnpair = MEEEGeom::pn(module, _fedid);
520 
521  unsigned int MyPn0 = pnpair.first;
522  unsigned int MyPn1 = pnpair.second;
523 
524  int hashedIndex = 100000 * eta + phi;
525 
526  if (channelMapEE.count(hashedIndex) == 0) {
529  }
530 
531  unsigned int channel = channelMapEE[hashedIndex];
532 
533  if (isFirstChanModFilled[iMod] == 0) {
534  firstChanMod[iMod] = channel;
535  isFirstChanModFilled[iMod] = 1;
536  }
537 
538  iEta[channel] = eta;
539  iPhi[channel] = phi;
540  iModule[channel] = module;
541  iTowerID[channel] = towerID;
542  iChannelID[channel] = channelID;
543  idccID[channel] = dccID;
544  iside[channel] = side;
545 
546  assert(channel < nCrys);
547 
548  // Get adc samples
549  //====================
550 
551  for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
552  EcalMGPASample samp_crystal(df.sample(i));
553  adc[i] = samp_crystal.adc();
554  adcG[i] = samp_crystal.gainId();
555 
556  if (i == 0)
557  adcgain = adcG[i];
558  if (i > 0)
559  adcgain = TMath::Max(adcG[i], adcgain);
560  }
561 
562  // Remove pedestal
563  //====================
564  for (dsum = 0., dsum1 = 0., k = 0; k < _presample; k++) {
565  dsum += adc[k];
566  if (k < _presample - 1)
567  dsum1 += adc[k];
568  }
569 
570  bl = dsum / ((double)_presample);
571 
572  for (val_max = 0., k = 0; k < _nsamples; k++) {
573  yrange[k] = adc[k] - bl;
574  if (yrange[k] > val_max) {
575  val_max = yrange[k];
576  samplemax = k;
577  }
578  }
579  apdGain = adcgain;
580 
581  int dccMEMIndex = 0;
582  if (side == 1)
583  dccMEMIndex += 2; // Trick to fix endcap specificity
584 
585  if (allPNAmpl[dccMEM[dccMEMIndex]].size() > MyPn0)
586  pnAmpl0 = allPNAmpl[dccMEM[dccMEMIndex]][MyPn0];
587  else
588  pnAmpl0 = 0;
589  if (allPNAmpl[dccMEM[dccMEMIndex + 1]].size() > MyPn1)
590  pnAmpl1 = allPNAmpl[dccMEM[dccMEMIndex + 1]][MyPn1];
591  else
592  pnAmpl1 = 0;
593 
594  if (allPNGain[dccMEM[dccMEMIndex]].size() > MyPn0)
595  pnGain = allPNGain[dccMEM[dccMEMIndex]][MyPn0];
596  else
597  pnGain = 0;
598 
599  // Perform the fit on apd samples
600  //=================================
601 
602  chi2 = pstpfit->fit_third_degree_polynomial(&yrange[0], ret_data);
603 
604  //Retrieve APD amplitude from fit
605  //=================================
606 
607  if (val_max > 100000. || chi2 < 0. || chi2 == 102) {
608  apdAmpl = 0;
609  apdTime = 0;
610 
611  } else {
612  apdAmpl = ret_data[0];
613  apdTime = ret_data[1];
614  }
615 
616  trees[channel]->Fill();
617  }
618  }
619 
620 } // end of analyze
621 
622 //========================================================================
624  //========================================================================
625 
626  // Don't do anything if there is no events
627  if (TPEvents == 0) {
628  outFile->Close();
629 
630  // Remove temporary file
631 
632  std::stringstream del;
633  del << "rm " << rootfile;
634  system(del.str().c_str());
635 
636  edm::LogVerbatim("EcalTestPulseAnalyzer") << " No TP Events ";
637  return;
638  }
639 
640  edm::LogVerbatim("EcalTestPulseAnalyzer") << "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
641  edm::LogVerbatim("EcalTestPulseAnalyzer") << "\t+=+ Analyzing test pulse data: getting APD, PN +=+";
642 
643  // Create output ntuples:
644 
645  //edm::LogVerbatim("EcalTestPulseAnalyzer")<< "TP Test Name File "<< resfile.c_str();
646 
647  resFile = new TFile(resfile.c_str(), "RECREATE");
648 
649  restrees = new TTree("TPAPD", "TPAPD");
650  respntrees = new TTree("TPPN", "TPPN");
651 
652  restrees->Branch("iphi", &iphi, "iphi/I");
653  restrees->Branch("ieta", &ieta, "ieta/I");
654  restrees->Branch("dccID", &dccID, "dccID/I");
655  restrees->Branch("side", &side, "side/I");
656  restrees->Branch("towerID", &towerID, "towerID/I");
657  restrees->Branch("channelID", &channelID, "channelID/I");
658  restrees->Branch("moduleID", &moduleID, "moduleID/I");
659  restrees->Branch("flag", &flag, "flag/I");
660  restrees->Branch("gain", &gain, "gain/I");
661  restrees->Branch("APD", &APD, "APD[6]/D");
662 
663  respntrees->Branch("pnID", &pnID, "pnID/I");
664  respntrees->Branch("moduleID", &moduleID, "moduleID/I");
665  respntrees->Branch("gain", &gain, "gain/I");
666  respntrees->Branch("PN", &PN, "PN[6]/D");
667 
668  restrees->SetBranchAddress("iphi", &iphi);
669  restrees->SetBranchAddress("ieta", &ieta);
670  restrees->SetBranchAddress("dccID", &dccID);
671  restrees->SetBranchAddress("side", &side);
672  restrees->SetBranchAddress("towerID", &towerID);
673  restrees->SetBranchAddress("channelID", &channelID);
674  restrees->SetBranchAddress("moduleID", &moduleID);
675  restrees->SetBranchAddress("flag", &flag);
676  restrees->SetBranchAddress("gain", &gain);
677  restrees->SetBranchAddress("APD", APD);
678 
679  respntrees->SetBranchAddress("pnID", &pnID);
680  respntrees->SetBranchAddress("moduleID", &moduleID);
681  respntrees->SetBranchAddress("gain", &gain);
682  respntrees->SetBranchAddress("PN", PN);
683 
684  TMom* APDAnal[1700][10];
685  TMom* PNAnal[9][2][10];
686 
687  for (unsigned int iMod = 0; iMod < nMod; iMod++) {
688  for (unsigned int ich = 0; ich < 2; ich++) {
689  for (unsigned int ig = 0; ig < nGainPN; ig++) {
690  PNAnal[iMod][ich][ig] = new TMom();
691  }
692  }
693  }
694 
695  for (unsigned int iCry = 0; iCry < nCrys; iCry++) { // Loop on data trees (ie on cristals)
696 
697  for (unsigned int iG = 0; iG < nGainAPD; iG++) {
698  APDAnal[iCry][iG] = new TMom();
699  }
700 
701  // Define submodule and channel number inside the submodule (as Patrice)
702 
703  unsigned int iMod = iModule[iCry] - 1;
704 
705  moduleID = iMod + 1;
706  if (moduleID >= 20)
707  moduleID -= 2; // Trick to fix endcap specificity
708 
709  Long64_t nbytes = 0, nb = 0;
710  for (Long64_t jentry = 0; jentry < trees[iCry]->GetEntriesFast(); jentry++) {
711  nb = trees[iCry]->GetEntry(jentry);
712  nbytes += nb;
713 
714  // PN Means and RMS
715 
716  if (firstChanMod[iMod] == iCry) {
717  PNAnal[iMod][0][pnGain]->addEntry(pnAmpl0);
718  PNAnal[iMod][1][pnGain]->addEntry(pnAmpl1);
719  }
720 
721  // APD means and RMS
722 
723  APDAnal[iCry][apdGain]->addEntry(apdAmpl);
724  }
725 
726  if (trees[iCry]->GetEntries() < 10) {
727  flag = -1;
728  for (int j = 0; j < 6; j++) {
729  APD[j] = 0.0;
730  }
731  } else
732  flag = 1;
733 
734  iphi = iPhi[iCry];
735  ieta = iEta[iCry];
736  dccID = idccID[iCry];
737  side = iside[iCry];
738  towerID = iTowerID[iCry];
739  channelID = iChannelID[iCry];
740 
741  for (unsigned int ig = 0; ig < nGainAPD; ig++) {
742  APD[0] = APDAnal[iCry][ig]->getMean();
743  APD[1] = APDAnal[iCry][ig]->getRMS();
744  APD[2] = APDAnal[iCry][ig]->getM3();
745  APD[3] = APDAnal[iCry][ig]->getNevt();
746  APD[4] = APDAnal[iCry][ig]->getMin();
747  APD[5] = APDAnal[iCry][ig]->getMax();
748  gain = ig;
749 
750  // Fill APD tree
751 
752  restrees->Fill();
753  }
754  }
755 
756  // Get final results for PN and PN/PN
757 
758  for (unsigned int ig = 0; ig < nGainPN; ig++) {
759  for (unsigned int iMod = 0; iMod < nMod; iMod++) {
760  for (int ch = 0; ch < 2; ch++) {
761  pnID = ch;
762  moduleID = iMod;
763  if (moduleID >= 20)
764  moduleID -= 2; // Trick to fix endcap specificity
765 
766  PN[0] = PNAnal[iMod][ch][ig]->getMean();
767  PN[1] = PNAnal[iMod][ch][ig]->getRMS();
768  PN[2] = PNAnal[iMod][ch][ig]->getM3();
769  PN[3] = PNAnal[iMod][ch][ig]->getNevt();
770  PN[4] = PNAnal[iMod][ch][ig]->getMin();
771  PN[5] = PNAnal[iMod][ch][ig]->getMax();
772  gain = ig;
773 
774  // Fill PN tree
775  respntrees->Fill();
776  }
777  }
778  }
779 
780  outFile->Close();
781 
782  // Remove temporary file
783 
784  std::stringstream del;
785  del << "rm " << rootfile;
786  system(del.str().c_str());
787 
788  // Save final results
789 
790  restrees->Write();
791  respntrees->Write();
792  resFile->Close();
793 
794  edm::LogVerbatim("EcalTestPulseAnalyzer") << "\t+=+ ...................................... done +=+";
795  edm::LogVerbatim("EcalTestPulseAnalyzer") << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
796 }
797 
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
static std::vector< ME::DCCid > memFromDcc(ME::DCCid idcc)
Definition: ME.cc:561
const edm::EventSetup & c
int xtalId() const
get the channel id
unsigned int iModule[1700]
const unsigned int _presamplePN
const unsigned int _samplemax
void analyze(const edm::Event &e, const edm::EventSetup &c) override
std::vector< int > modules
int stripId() const
get the tower id
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define NGAINPN
const std::string digiProducer_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
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
tuple runType
Definition: runPedHist.py:37
int towerId() const
get the tower id
const_iterator begin() const
The iterator returned can not safely be used across threads.
#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
bool getData(T &iHolder) const
Definition: EventSetup.h:128
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
const std::string eventHeaderCollection_
const std::string _ecalPart
void init_errmat(double)
Definition: TSFit.cc:87
bool isValid() const
Definition: HandleBase.h:70
int iDCCId() const
get the DCCId
static int lmmod(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:90
const_iterator end() const
T Max(T a, T b)
Definition: MathUtil.h:44
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
T const * product() const
Definition: Handle.h:70
double getMin()
Definition: TMom.cc:169
const std::string digiCollection_
const unsigned int _nsamples
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
const_iterator end() const
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
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
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
double getMean()
Definition: TMom.cc:121
tuple size
Write out results.
int channelId() const
so far for EndCap only :
const unsigned int _presample
const_iterator begin() const
tuple module
Definition: callgraph.py:69