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 {
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 {
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 {
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 {
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 
size
Write out results.
void addEntry(double val)
Definition: TMom.cc:88
static XYCoord localCoord(int icr)
Definition: MEEBGeom.cc:142
T getParameter(std::string const &) const
std::map< int, int > channelMapEE
T getUntrackedParameter(std::string const &, T const &) const
static int lmmod(SuperCrysCoord iX, SuperCrysCoord iY)
Definition: MEEEGeom.cc:112
static std::vector< ME::DCCid > memFromDcc(ME::DCCid idcc)
Definition: ME.cc:561
#define NTTEB
int xtalId() const
get the channel id
unsigned int iModule[1700]
void analyze(const edm::Event &e, const edm::EventSetup &c) override
int stripId() const
get the tower id
#define NGAINPN
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
#define NTTEE
#define NCRYSEE
static int side(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:1155
std::vector< T >::const_iterator const_iterator
void init(int, int, int)
Definition: TPNFit.cc:24
int towerId() const
get the tower id
const_iterator begin() const
#define NGAINAPD
Definition: TMom.h:7
EcalTestPulseAnalyzer(const edm::ParameterSet &iConfig)
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
#define nTT
Definition: TMEGeom.h:6
int getNevt()
Definition: TMom.cc:144
int hashedIndex(int ieta, int iphi)
Definition: EcalPyUtils.cc:38
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
static std::pair< int, int > pn(int dee, int ilmod)
Definition: MEEEGeom.cc:574
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static int electronic_channel(EBLocalCoord ix, EBLocalCoord iy)
Definition: MEEBGeom.cc:326
#define NCRYSEB
double getAmpl()
Definition: TPNFit.h:31
#define NMODEB
void init_errmat(double)
Definition: TSFit.cc:87
int iDCCId() const
get the DCCId
static int lmmod(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:90
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
const_iterator end() const
T Max(T a, T b)
Definition: MathUtil.h:44
static int side(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:105
double getRMS()
Definition: TMom.cc:146
T const * product() const
Definition: Handle.h:69
double getMin()
Definition: TMom.cc:169
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
const_iterator end() const
T get() const
Definition: EventSetup.h:73
double getMax()
Definition: TMom.cc:170
Definition: TPNFit.h:8
double doFit(int, double *)
Definition: TPNFit.cc:39
EcalLogicID towerID(EcalElectronicsId const &)
void set_params(int, int, int, int, int, double, double, int, int)
Definition: TSFit.cc:39
Definition: TSFit.h:15
unsigned int isFirstChanModFilled[9]
T const * product() const
Definition: ESHandle.h:86
Definition: vlib.h:198
static std::vector< ME::LMMid > lmmodFromDcc(ME::DCCid idcc)
Definition: ME.cc:574
double getMean()
Definition: TMom.cc:121
int channelId() const
so far for EndCap only :
const_iterator begin() const
Definition: event.py:1