CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalLaserAnalyzer.cc
Go to the documentation of this file.
1 /*
2  * \class EcalLaserAnalyzer
3  *
4  * primary author: Julie Malcles - CEA/Saclay
5  * author: Gautier Hamel De Monchenault - CEA/Saclay
6  */
7 
8 #include <TAxis.h>
9 #include <TH1.h>
10 #include <TProfile.h>
11 #include <TTree.h>
12 #include <TChain.h>
13 #include <TFile.h>
14 #include <TMath.h>
15 
17 
18 #include <sstream>
19 #include <fstream>
20 #include <iomanip>
21 
23 
25 
31 
44 
45 //========================================================================
47  //========================================================================
48  : iEvent(0),
49  eventHeaderCollection_(iConfig.getParameter<std::string>("eventHeaderCollection")),
50  eventHeaderProducer_(iConfig.getParameter<std::string>("eventHeaderProducer")),
51  digiCollection_(iConfig.getParameter<std::string>("digiCollection")),
52  digiProducer_(iConfig.getParameter<std::string>("digiProducer")),
53  digiPNCollection_(iConfig.getParameter<std::string>("digiPNCollection")),
54  rawDataToken_(consumes<EcalRawDataCollection>(edm::InputTag(eventHeaderProducer_, eventHeaderCollection_))),
55  pnDiodeDigiToken_(consumes<EcalPnDiodeDigiCollection>(edm::InputTag(digiProducer_))),
56  mappingToken_(esConsumes()),
57  // Framework parameters with default values
58  _nsamples(iConfig.getUntrackedParameter<unsigned int>("nSamples", 10)),
59  _presample(iConfig.getUntrackedParameter<unsigned int>("nPresamples", 2)),
60  _firstsample(iConfig.getUntrackedParameter<unsigned int>("firstSample", 1)),
61  _lastsample(iConfig.getUntrackedParameter<unsigned int>("lastSample", 2)),
62  _nsamplesPN(iConfig.getUntrackedParameter<unsigned int>("nSamplesPN", 50)),
63  _presamplePN(iConfig.getUntrackedParameter<unsigned int>("nPresamplesPN", 6)),
64  _firstsamplePN(iConfig.getUntrackedParameter<unsigned int>("firstSamplePN", 7)),
65  _lastsamplePN(iConfig.getUntrackedParameter<unsigned int>("lastSamplePN", 8)),
66  _timingcutlow(iConfig.getUntrackedParameter<unsigned int>("timingCutLow", 2)),
67  _timingcuthigh(iConfig.getUntrackedParameter<unsigned int>("timingCutHigh", 9)),
68  _timingquallow(iConfig.getUntrackedParameter<unsigned int>("timingQualLow", 3)),
69  _timingqualhigh(iConfig.getUntrackedParameter<unsigned int>("timingQualHigh", 8)),
70  _ratiomincutlow(iConfig.getUntrackedParameter<double>("ratioMinCutLow", 0.4)),
71  _ratiomincuthigh(iConfig.getUntrackedParameter<double>("ratioMinCutHigh", 0.95)),
72  _ratiomaxcutlow(iConfig.getUntrackedParameter<double>("ratioMaxCutLow", 0.8)),
73  _presamplecut(iConfig.getUntrackedParameter<double>("presampleCut", 5.0)),
74  _niter(iConfig.getUntrackedParameter<unsigned int>("nIter", 3)),
75  _fitab(iConfig.getUntrackedParameter<bool>("fitAB", false)),
76  _alpha(iConfig.getUntrackedParameter<double>("alpha", 1.5076494)),
77  _beta(iConfig.getUntrackedParameter<double>("beta", 1.5136036)),
78  _nevtmax(iConfig.getUntrackedParameter<unsigned int>("nEvtMax", 200)),
79  _noise(iConfig.getUntrackedParameter<double>("noise", 2.0)),
80  _chi2cut(iConfig.getUntrackedParameter<double>("chi2cut", 10.0)),
81  _ecalPart(iConfig.getUntrackedParameter<std::string>("ecalPart", "EB")),
82  _docorpn(iConfig.getUntrackedParameter<bool>("doCorPN", false)),
83  _fedid(iConfig.getUntrackedParameter<int>("fedID", -999)),
84  _saveallevents(iConfig.getUntrackedParameter<bool>("saveAllEvents", false)),
85  _qualpercent(iConfig.getUntrackedParameter<double>("qualPercent", 0.2)),
86  _debug(iConfig.getUntrackedParameter<int>("debug", 0)),
87  resdir_(iConfig.getUntrackedParameter<std::string>("resDir")),
88  pncorfile_(iConfig.getUntrackedParameter<std::string>("pnCorFile")),
89  nCrys(NCRYSEB),
90  nPNPerMod(NPNPERMOD),
91  nMod(NMODEE),
92  nSides(NSIDES),
93  runType(-1),
94  runNum(0),
95  fedID(-1),
96  dccID(-1),
97  side(2),
98  lightside(2),
99  iZ(1),
100  phi(-1),
101  eta(-1),
102  event(0),
103  color(-1),
104  pn0(0),
105  pn1(0),
106  apdAmpl(0),
107  apdAmplA(0),
108  apdAmplB(0),
109  apdTime(0),
110  pnAmpl(0),
111  pnID(-1),
112  moduleID(-1),
113  channelIteratorEE(0)
114 
115 //========================================================================
116 
117 {
118  if (_ecalPart == "EB") {
119  ebDigiToken_ = consumes<EBDigiCollection>(edm::InputTag(digiProducer_, digiCollection_));
120  } else if (_ecalPart == "EE") {
121  eeDigiToken_ = consumes<EEDigiCollection>(edm::InputTag(digiProducer_, digiCollection_));
122  }
123 
124  // Geometrical constants initialization
125 
126  if (_ecalPart == "EB") {
127  nCrys = NCRYSEB;
128  } else {
129  nCrys = NCRYSEE;
130  }
131  iZ = 1;
132  if (_fedid <= 609)
133  iZ = -1;
135  nMod = modules.size();
136  nRefChan = NREFCHAN;
137 
138  for (unsigned int j = 0; j < nCrys; j++) {
139  iEta[j] = -1;
140  iPhi[j] = -1;
141  iModule[j] = 10;
142  iTowerID[j] = -1;
143  iChannelID[j] = -1;
144  idccID[j] = -1;
145  iside[j] = -1;
146  wasTimingOK[j] = true;
147  wasGainOK[j] = true;
148  }
149 
150  for (unsigned int j = 0; j < nMod; j++) {
151  int ii = modules[j];
152  firstChanMod[ii - 1] = 0;
153  isFirstChanModFilled[ii - 1] = 0;
154  }
155 
156  // Quality check flags
157 
158  isGainOK = true;
159  isTimingOK = true;
160 
161  // PN linearity corrector
162 
164 
165  // Objects dealing with pulses
166 
168  _presample,
169  _firstsample,
170  _lastsample,
179 
180  // Object dealing with MEM numbering
181 
182  Mem = new TMem(_fedid);
183 
184  // Objects needed for npresample calculation
185 
186  Delta01 = new TMom();
187  Delta12 = new TMom();
188 }
189 
190 //========================================================================
192  //========================================================================
193 
194  // do anything here that needs to be done at destruction time
195  // (e.g. close files, deallocate resources etc.)
196 }
197 
198 //========================================================================
200  //========================================================================
201 
202  // Create temporary files and trees to save adc samples
203  //======================================================
204 
205  ADCfile = resdir_;
206  ADCfile += "/APDSamplesLaser.root";
207 
208  APDfile = resdir_;
209  APDfile += "/APDPNLaserAllEvents.root";
210 
211  ADCFile = new TFile(ADCfile.c_str(), "RECREATE");
212 
213  for (unsigned int i = 0; i < nCrys; i++) {
214  std::stringstream name;
215  name << "ADCTree" << i + 1;
216  ADCtrees[i] = new TTree(name.str().c_str(), name.str().c_str());
217 
218  ADCtrees[i]->Branch("ieta", &eta, "eta/I");
219  ADCtrees[i]->Branch("iphi", &phi, "phi/I");
220  ADCtrees[i]->Branch("side", &side, "side/I");
221  ADCtrees[i]->Branch("dccID", &dccID, "dccID/I");
222  ADCtrees[i]->Branch("towerID", &towerID, "towerID/I");
223  ADCtrees[i]->Branch("channelID", &channelID, "channelID/I");
224  ADCtrees[i]->Branch("event", &event, "event/I");
225  ADCtrees[i]->Branch("color", &color, "color/I");
226  ADCtrees[i]->Branch("adc", &adc, "adc[10]/D");
227  ADCtrees[i]->Branch("pn0", &pn0, "pn0/D");
228  ADCtrees[i]->Branch("pn1", &pn1, "pn1/D");
229 
230  ADCtrees[i]->SetBranchAddress("ieta", &eta);
231  ADCtrees[i]->SetBranchAddress("iphi", &phi);
232  ADCtrees[i]->SetBranchAddress("side", &side);
233  ADCtrees[i]->SetBranchAddress("dccID", &dccID);
234  ADCtrees[i]->SetBranchAddress("towerID", &towerID);
235  ADCtrees[i]->SetBranchAddress("channelID", &channelID);
236  ADCtrees[i]->SetBranchAddress("event", &event);
237  ADCtrees[i]->SetBranchAddress("color", &color);
238  ADCtrees[i]->SetBranchAddress("adc", adc);
239  ADCtrees[i]->SetBranchAddress("pn0", &pn0);
240  ADCtrees[i]->SetBranchAddress("pn1", &pn1);
241 
242  nevtAB[i] = 0;
243  }
244 
245  // Define output results filenames and shape analyzer object (alpha,beta)
246  //=====================================================================
247 
248  // 1) AlphaBeta files
249 
250  doesABTreeExist = true;
251 
252  std::stringstream nameabinitfile;
253  nameabinitfile << resdir_ << "/ABInit.root";
254  alphainitfile = nameabinitfile.str();
255 
256  std::stringstream nameabfile;
257  nameabfile << resdir_ << "/AB.root";
258  alphafile = nameabfile.str();
259 
260  FILE* test;
261  if (_fitab)
262  test = fopen(alphainitfile.c_str(), "r");
263  else
264  test = fopen(alphafile.c_str(), "r");
265  if (test == nullptr) {
266  doesABTreeExist = false;
267  _fitab = true;
268  };
269  delete test;
270 
271  TFile* fAB = nullptr;
272  TTree* ABInit = nullptr;
273  if (doesABTreeExist) {
274  fAB = new TFile(nameabinitfile.str().c_str());
275  }
276  if (doesABTreeExist && fAB) {
277  ABInit = (TTree*)fAB->Get("ABCol0");
278  }
279 
280  // 2) Shape analyzer
281 
282  if (doesABTreeExist && fAB && ABInit && ABInit->GetEntries() != 0) {
283  shapana = new TShapeAnalysis(ABInit, _alpha, _beta, 5.5, 1.0);
284  doesABTreeExist = true;
285  } else {
286  shapana = new TShapeAnalysis(_alpha, _beta, 5.5, 1.0);
287  doesABTreeExist = false;
288  _fitab = true;
289  }
291 
292  if (doesABTreeExist && fAB)
293  fAB->Close();
294 
295  // 2) APD file
296 
297  std::stringstream nameapdfile;
298  nameapdfile << resdir_ << "/APDPN_LASER.root";
299  resfile = nameapdfile.str();
300 
301  // Laser events counter
302 
303  laserEvents = 0;
304 }
305 
306 //========================================================================
308  //========================================================================
309 
310  ++iEvent;
311 
312  // retrieving DCC header
314  const EcalRawDataCollection* DCCHeader = nullptr;
315  e.getByToken(rawDataToken_, pDCCHeader);
316  if (!pDCCHeader.isValid()) {
317  edm::LogError("nodata") << "Error! can't get the product retrieving DCC header" << eventHeaderCollection_.c_str()
318  << " " << eventHeaderProducer_.c_str();
319  } else {
320  DCCHeader = pDCCHeader.product();
321  }
322 
323  //retrieving crystal data from Event
325  const EBDigiCollection* EBDigi = nullptr;
327  const EEDigiCollection* EEDigi = nullptr;
328  if (_ecalPart == "EB") {
329  e.getByToken(ebDigiToken_, pEBDigi);
330  if (!pEBDigi.isValid()) {
331  edm::LogError("nodata") << "Error! can't get the product retrieving EB crystal data " << digiCollection_.c_str();
332  } else {
333  EBDigi = pEBDigi.product();
334  }
335  } else if (_ecalPart == "EE") {
336  e.getByToken(eeDigiToken_, pEEDigi);
337  if (!pEEDigi.isValid()) {
338  edm::LogError("nodata") << "Error! can't get the product retrieving EE crystal data " << digiCollection_.c_str();
339  } else {
340  EEDigi = pEEDigi.product();
341  }
342  } else {
343  edm::LogError("cfg_error") << " Wrong ecalPart in cfg file ";
344  return;
345  }
346 
347  // retrieving crystal PN diodes from Event
349  const EcalPnDiodeDigiCollection* PNDigi = nullptr;
350  e.getByToken(pnDiodeDigiToken_, pPNDigi);
351  if (!pPNDigi.isValid()) {
352  edm::LogError("nodata") << "Error! can't get the product " << digiPNCollection_.c_str();
353  } else {
354  PNDigi = pPNDigi.product();
355  }
356 
357  // retrieving electronics mapping
358  const auto& TheMapping = c.getData(mappingToken_);
359 
360  // ============================
361  // Decode DCCHeader Information
362  // ============================
363 
364  for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
365  ++headerItr) {
366  // Get run type and run number
367 
368  int fed = headerItr->fedId();
369  if (fed != _fedid && _fedid != -999)
370  continue;
371 
372  runType = headerItr->getRunType();
373  runNum = headerItr->getRunNumber();
374  event = headerItr->getLV1();
375 
376  dccID = headerItr->getDccInTCCCommand();
377  fedID = headerItr->fedId();
378  lightside = headerItr->getRtHalf();
379 
380  // Check fed corresponds to the DCC in TCC
381 
382  if (600 + dccID != fedID)
383  continue;
384 
385  // Cut on runType
386 
389  return;
390 
391  // Retrieve laser color and event number
392 
393  EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
394  color = settings.wavelength;
395  if (color < 0)
396  return;
397 
398  std::vector<int>::iterator iter = find(colors.begin(), colors.end(), color);
399  if (iter == colors.end()) {
400  colors.push_back(color);
401  edm::LogVerbatim("EcalLaserAnalyzer") << " new color found " << color << " " << colors.size();
402  }
403  }
404 
405  // Cut on fedID
406 
407  if (fedID != _fedid && _fedid != -999)
408  return;
409 
410  // Count laser events
411 
412  laserEvents++;
413 
414  // ======================
415  // Decode PN Information
416  // ======================
417 
418  TPNFit* pnfit = new TPNFit();
420 
421  double chi2pn = 0;
422  unsigned int samplemax = 0;
423  int pnGain = 0;
424 
425  std::map<int, std::vector<double> > allPNAmpl;
426  std::map<int, std::vector<double> > allPNGain;
427 
428  // Loop on PNs digis
429 
430  for (EcalPnDiodeDigiCollection::const_iterator pnItr = PNDigi->begin(); pnItr != PNDigi->end(); ++pnItr) {
431  EcalPnDiodeDetId pnDetId = EcalPnDiodeDetId((*pnItr).id());
432 
433  if (_debug == 1)
434  edm::LogVerbatim("EcalLaserAnalyzer")
435  << "-- debug -- Inside PNDigi - pnID=" << pnDetId.iPnId() << ", dccID=" << pnDetId.iDCCId();
436 
437  // Skip MEM DCC without relevant data
438 
439  bool isMemRelevant = Mem->isMemRelevant(pnDetId.iDCCId());
440  if (!isMemRelevant)
441  continue;
442 
443  // Loop on PN samples
444 
445  for (int samId = 0; samId < (*pnItr).size(); samId++) {
446  pn[samId] = (*pnItr).sample(samId).adc();
447  pnG[samId] = (*pnItr).sample(samId).gainId();
448  if (samId == 0)
449  pnGain = pnG[samId];
450  if (samId > 0)
451  pnGain = int(TMath::Max(pnG[samId], pnGain));
452  }
453 
454  if (pnGain != 1)
455  edm::LogVerbatim("EcalLaserAnalyzer") << "PN gain different from 1";
456 
457  // Calculate amplitude from pulse
458 
459  PNPulse->setPulse(pn);
461  samplemax = PNPulse->getMaxSample();
462  chi2pn = pnfit->doFit(samplemax, &pnNoPed[0]);
463  if (chi2pn == 101 || chi2pn == 102 || chi2pn == 103)
464  pnAmpl = 0.;
465  else
466  pnAmpl = pnfit->getAmpl();
467 
468  // Apply linearity correction
469 
470  double corr = 1.0;
471  if (_docorpn)
472  corr = pnCorrector->getPNCorrectionFactor(pnAmpl, pnGain);
473  pnAmpl *= corr;
474 
475  // Fill PN ampl vector
476 
477  allPNAmpl[pnDetId.iDCCId()].push_back(pnAmpl);
478 
479  if (_debug == 1)
480  edm::LogVerbatim("EcalLaserAnalyzer") << "-- debug -- Inside PNDigi - PNampl=" << pnAmpl << ", PNgain=" << pnGain;
481  }
482 
483  // ===========================
484  // Decode EBDigis Information
485  // ===========================
486 
487  int adcGain = 0;
488 
489  if (EBDigi) {
490  // Loop on crystals
491  //===================
492 
493  for (EBDigiCollection::const_iterator digiItr = EBDigi->begin(); digiItr != EBDigi->end(); ++digiItr) {
494  // Retrieve geometry
495  //===================
496 
497  EBDetId id_crystal(digiItr->id());
498  EBDataFrame df(*digiItr);
499  EcalElectronicsId elecid_crystal = TheMapping.getElectronicsId(id_crystal);
500 
501  int etaG = id_crystal.ieta(); // global
502  int phiG = id_crystal.iphi(); // global
503 
504  std::pair<int, int> LocalCoord = MEEBGeom::localCoord(etaG, phiG);
505 
506  int etaL = LocalCoord.first; // local
507  int phiL = LocalCoord.second; // local
508 
509  int strip = elecid_crystal.stripId();
510  int xtal = elecid_crystal.xtalId();
511 
512  int module = MEEBGeom::lmmod(etaG, phiG);
513  int tower = elecid_crystal.towerId();
514 
515  int apdRefTT = MEEBGeom::apdRefTower(module);
516 
517  std::pair<int, int> pnpair = MEEBGeom::pn(module);
518  unsigned int MyPn0 = pnpair.first;
519  unsigned int MyPn1 = pnpair.second;
520 
521  int lmr = MEEBGeom::lmr(etaG, phiG);
522  unsigned int channel = MEEBGeom::electronic_channel(etaL, phiL);
523  assert(channel < nCrys);
524 
525  setGeomEB(etaG, phiG, module, tower, strip, xtal, apdRefTT, channel, lmr);
526 
527  if (_debug == 1)
528  edm::LogVerbatim("EcalLaserAnalyzer")
529  << "-- debug -- Inside EBDigi - towerID:" << towerID << " channelID:" << channelID << " module:" << module
530  << " modules:" << modules.size();
531 
532  // APD Pulse
533  //===========
534 
535  // Loop on adc samples
536 
537  for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
538  EcalMGPASample samp_crystal(df.sample(i));
539  adc[i] = samp_crystal.adc();
540  adcG[i] = samp_crystal.gainId();
541  adc[i] *= adcG[i];
542  if (i == 0)
543  adcGain = adcG[i];
544  if (i > 0)
545  adcGain = TMath::Max(adcG[i], adcGain);
546  }
547 
549 
550  // Quality checks
551  //================
552 
553  if (adcGain != 1)
554  nEvtBadGain[channel]++;
555  if (!APDPulse->isTimingQualOK())
556  nEvtBadTiming[channel]++;
557  nEvtTot[channel]++;
558 
559  // Associate PN ampl
560  //===================
561 
562  int mem0 = Mem->Mem(lmr, 0);
563  int mem1 = Mem->Mem(lmr, 1);
564 
565  if (allPNAmpl[mem0].size() > MyPn0)
566  pn0 = allPNAmpl[mem0][MyPn0];
567  else
568  pn0 = 0;
569  if (allPNAmpl[mem1].size() > MyPn1)
570  pn1 = allPNAmpl[mem1][MyPn1];
571  else
572  pn1 = 0;
573 
574  // Fill if Pulse is fine
575  //=======================
576 
577  if (APDPulse->isPulseOK() && lightside == side) {
578  ADCtrees[channel]->Fill();
579 
582 
583  if (nevtAB[channel] < _nevtmax && _fitab) {
584  if (doesABTreeExist)
585  shapana->putAllVals(channel, adc, eta, phi);
586  else
588  nevtAB[channel]++;
589  }
590  }
591  }
592 
593  } else if (EEDigi) {
594  // Loop on crystals
595  //===================
596 
597  for (EEDigiCollection::const_iterator digiItr = EEDigi->begin(); digiItr != EEDigi->end(); ++digiItr) {
598  // Retrieve geometry
599  //===================
600 
601  EEDetId id_crystal(digiItr->id());
602  EEDataFrame df(*digiItr);
603  EcalElectronicsId elecid_crystal = TheMapping.getElectronicsId(id_crystal);
604 
605  int etaG = id_crystal.iy();
606  int phiG = id_crystal.ix();
607 
608  int iX = (phiG - 1) / 5 + 1;
609  int iY = (etaG - 1) / 5 + 1;
610 
611  int tower = elecid_crystal.towerId();
612  int ch = elecid_crystal.channelId() - 1;
613 
614  int module = MEEEGeom::lmmod(iX, iY);
615  if (module >= 18 && side == 1)
616  module += 2;
617  int lmr = MEEEGeom::lmr(iX, iY, iZ);
618  int dee = MEEEGeom::dee(lmr);
619  int apdRefTT = MEEEGeom::apdRefTower(lmr, module);
620 
621  std::pair<int, int> pnpair = MEEEGeom::pn(dee, module);
622  unsigned int MyPn0 = pnpair.first;
623  unsigned int MyPn1 = pnpair.second;
624 
625  int hashedIndex = 100000 * eta + phi;
626  if (channelMapEE.count(hashedIndex) == 0) {
629  }
630  unsigned int channel = channelMapEE[hashedIndex];
631  assert(channel < nCrys);
632 
633  setGeomEE(etaG, phiG, iX, iY, iZ, module, tower, ch, apdRefTT, channel, lmr);
634 
635  if (_debug == 1)
636  edm::LogVerbatim("EcalLaserAnalyzer")
637  << "-- debug -- Inside EEDigi - towerID:" << towerID << " channelID:" << channelID << " module:" << module
638  << " modules:" << modules.size();
639 
640  // APD Pulse
641  //===========
642 
643  if ((*digiItr).size() > 10)
644  edm::LogVerbatim("EcalLaserAnalyzer") << "SAMPLES SIZE > 10!" << (*digiItr).size();
645 
646  // Loop on adc samples
647 
648  for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
649  EcalMGPASample samp_crystal(df.sample(i));
650  adc[i] = samp_crystal.adc();
651  adcG[i] = samp_crystal.gainId();
652  adc[i] *= adcG[i];
653 
654  if (i == 0)
655  adcGain = adcG[i];
656  if (i > 0)
657  adcGain = TMath::Max(adcG[i], adcGain);
658  }
659 
661 
662  // Quality checks
663  //================
664 
665  if (adcGain != 1)
666  nEvtBadGain[channel]++;
667  if (!APDPulse->isTimingQualOK())
668  nEvtBadTiming[channel]++;
669  nEvtTot[channel]++;
670 
671  // Associate PN ampl
672  //===================
673 
674  int mem0 = Mem->Mem(lmr, 0);
675  int mem1 = Mem->Mem(lmr, 1);
676 
677  if (allPNAmpl[mem0].size() > MyPn0)
678  pn0 = allPNAmpl[mem0][MyPn0];
679  else
680  pn0 = 0;
681  if (allPNAmpl[mem1].size() > MyPn1)
682  pn1 = allPNAmpl[mem1][MyPn1];
683  else
684  pn1 = 0;
685 
686  // Fill if Pulse is fine
687  //=======================
688 
689  if (APDPulse->isPulseOK() && lightside == side) {
690  ADCtrees[channel]->Fill();
691 
694 
695  if (nevtAB[channel] < _nevtmax && _fitab) {
696  if (doesABTreeExist)
697  shapana->putAllVals(channel, adc, eta, phi);
698  else
699  shapana->putAllVals(channel, adc, eta, phi, dccID, side, towerID, channelID);
700  nevtAB[channel]++;
701  }
702  }
703  }
704  }
705 }
706 // analyze
707 
708 //========================================================================
710  //========================================================================
711 
712  // Adjust channel numbers for EE
713  //===============================
714 
715  if (_ecalPart == "EE") {
716  nCrys = channelMapEE.size();
718  }
719 
720  // Set presamples number
721  //======================
722 
723  double delta01 = Delta01->getMean();
724  double delta12 = Delta12->getMean();
725  if (delta12 > _presamplecut) {
726  _presample = 2;
727  if (delta01 > _presamplecut)
728  _presample = 1;
729  }
730 
733 
734  // Get alpha and beta
735  //======================
736 
737  if (_fitab) {
738  edm::LogVerbatim("EcalLaserAnalyzer") << "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
739  edm::LogVerbatim("EcalLaserAnalyzer") << "\t+=+ Analyzing data: getting (alpha, beta) +=+";
740  TFile* fAB = nullptr;
741  TTree* ABInit = nullptr;
742  if (doesABTreeExist) {
743  fAB = new TFile(alphainitfile.c_str());
744  }
745  if (doesABTreeExist && fAB) {
746  ABInit = (TTree*)fAB->Get("ABCol0");
747  }
748  shapana->computeShape(alphafile, ABInit);
749  edm::LogVerbatim("EcalLaserAnalyzer") << "\t+=+ .................................... done +=+";
750  edm::LogVerbatim("EcalLaserAnalyzer") << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
751  }
752 
753  // Don't do anything if there is no events
754  //=========================================
755 
756  if (laserEvents == 0) {
757  ADCFile->Close();
758  std::stringstream del;
759  del << "rm " << ADCfile;
760  system(del.str().c_str());
761  edm::LogVerbatim("EcalLaserAnalyzer") << " No Laser Events ";
762  return;
763  }
764 
765  // Set quality flags for gains and timing
766  //=========================================
767 
768  double BadGainEvtPercentage = 0.0;
769  double BadTimingEvtPercentage = 0.0;
770 
771  int nChanBadGain = 0;
772  int nChanBadTiming = 0;
773 
774  for (unsigned int i = 0; i < nCrys; i++) {
775  if (nEvtTot[i] != 0) {
776  BadGainEvtPercentage = double(nEvtBadGain[i]) / double(nEvtTot[i]);
777  BadTimingEvtPercentage = double(nEvtBadTiming[i]) / double(nEvtTot[i]);
778  }
779  if (BadGainEvtPercentage > _qualpercent) {
780  wasGainOK[i] = false;
781  nChanBadGain++;
782  }
783  if (BadTimingEvtPercentage > _qualpercent) {
784  wasTimingOK[i] = false;
785  nChanBadTiming++;
786  }
787  }
788 
789  double BadGainChanPercentage = double(nChanBadGain) / double(nCrys);
790  double BadTimingChanPercentage = double(nChanBadTiming) / double(nCrys);
791 
792  if (BadGainChanPercentage > _qualpercent)
793  isGainOK = false;
794  if (BadTimingChanPercentage > _qualpercent)
795  isTimingOK = false;
796 
797  // Analyze adc samples to get amplitudes
798  //=======================================
799 
800  edm::LogVerbatim("EcalLaserAnalyzer") << "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
801  edm::LogVerbatim("EcalLaserAnalyzer") << "\t+=+ Analyzing laser data: getting APD, PN, APD/PN, PN/PN +=+";
802 
803  if (!isGainOK)
804  edm::LogVerbatim("EcalLaserAnalyzer") << "\t+=+ ............................ WARNING! APD GAIN WAS NOT 1 +=+";
805  if (!isTimingOK)
806  edm::LogVerbatim("EcalLaserAnalyzer") << "\t+=+ ............................ WARNING! TIMING WAS BAD +=+";
807 
808  APDFile = new TFile(APDfile.c_str(), "RECREATE");
809 
810  int ieta, iphi, channelID, towerID, flag;
811 
812  for (unsigned int i = 0; i < nCrys; i++) {
813  std::stringstream name;
814  name << "APDTree" << i + 1;
815 
816  APDtrees[i] = new TTree(name.str().c_str(), name.str().c_str());
817 
818  //List of branches
819 
820  APDtrees[i]->Branch("event", &event, "event/I");
821  APDtrees[i]->Branch("color", &color, "color/I");
822  APDtrees[i]->Branch("iphi", &iphi, "iphi/I");
823  APDtrees[i]->Branch("ieta", &ieta, "ieta/I");
824  APDtrees[i]->Branch("side", &side, "side/I");
825  APDtrees[i]->Branch("dccID", &dccID, "dccID/I");
826  APDtrees[i]->Branch("towerID", &towerID, "towerID/I");
827  APDtrees[i]->Branch("channelID", &channelID, "channelID/I");
828  APDtrees[i]->Branch("apdAmpl", &apdAmpl, "apdAmpl/D");
829  APDtrees[i]->Branch("apdTime", &apdTime, "apdTime/D");
830  if (_saveallevents)
831  APDtrees[i]->Branch("adc", &adc, "adc[10]/D");
832  APDtrees[i]->Branch("flag", &flag, "flag/I");
833  APDtrees[i]->Branch("flagAB", &flagAB, "flagAB/I");
834  APDtrees[i]->Branch("pn0", &pn0, "pn0/D");
835  APDtrees[i]->Branch("pn1", &pn1, "pn1/D");
836 
837  APDtrees[i]->SetBranchAddress("event", &event);
838  APDtrees[i]->SetBranchAddress("color", &color);
839  APDtrees[i]->SetBranchAddress("iphi", &iphi);
840  APDtrees[i]->SetBranchAddress("ieta", &ieta);
841  APDtrees[i]->SetBranchAddress("side", &side);
842  APDtrees[i]->SetBranchAddress("dccID", &dccID);
843  APDtrees[i]->SetBranchAddress("towerID", &towerID);
844  APDtrees[i]->SetBranchAddress("channelID", &channelID);
845  APDtrees[i]->SetBranchAddress("apdAmpl", &apdAmpl);
846  APDtrees[i]->SetBranchAddress("apdTime", &apdTime);
847  if (_saveallevents)
848  APDtrees[i]->SetBranchAddress("adc", adc);
849  APDtrees[i]->SetBranchAddress("flag", &flag);
850  APDtrees[i]->SetBranchAddress("flagAB", &flagAB);
851  APDtrees[i]->SetBranchAddress("pn0", &pn0);
852  APDtrees[i]->SetBranchAddress("pn1", &pn1);
853  }
854 
855  for (unsigned int iref = 0; iref < nRefChan; iref++) {
856  for (unsigned int imod = 0; imod < nMod; imod++) {
857  int jmod = modules[imod];
858 
859  std::stringstream nameref;
860  nameref << "refAPDTree" << imod << "_" << iref;
861 
862  RefAPDtrees[iref][jmod] = new TTree(nameref.str().c_str(), nameref.str().c_str());
863 
864  RefAPDtrees[iref][jmod]->Branch("eventref", &eventref, "eventref/I");
865  RefAPDtrees[iref][jmod]->Branch("colorref", &colorref, "colorref/I");
866  if (iref == 0)
867  RefAPDtrees[iref][jmod]->Branch("apdAmplA", &apdAmplA, "apdAmplA/D");
868  if (iref == 1)
869  RefAPDtrees[iref][jmod]->Branch("apdAmplB", &apdAmplB, "apdAmplB/D");
870 
871  RefAPDtrees[iref][jmod]->SetBranchAddress("eventref", &eventref);
872  RefAPDtrees[iref][jmod]->SetBranchAddress("colorref", &colorref);
873  if (iref == 0)
874  RefAPDtrees[iref][jmod]->SetBranchAddress("apdAmplA", &apdAmplA);
875  if (iref == 1)
876  RefAPDtrees[iref][jmod]->SetBranchAddress("apdAmplB", &apdAmplB);
877  }
878  }
879 
880  assert(colors.size() <= nColor);
881  unsigned int nCol = colors.size();
882 
883  // Declare PN stuff
884  //===================
885 
886  for (unsigned int iM = 0; iM < nMod; iM++) {
887  unsigned int iMod = modules[iM] - 1;
888 
889  for (unsigned int ich = 0; ich < nPNPerMod; ich++) {
890  for (unsigned int icol = 0; icol < nCol; icol++) {
891  PNFirstAnal[iMod][ich][icol] = new TPN(ich);
892  PNAnal[iMod][ich][icol] = new TPN(ich);
893  }
894  }
895  }
896 
897  // Declare function for APD ampl fit
898  //===================================
899 
901  double chi2;
902 
903  for (unsigned int iCry = 0; iCry < nCrys; iCry++) {
904  for (unsigned int icol = 0; icol < nCol; icol++) {
905  // Declare APD stuff
906  //===================
907 
908  APDFirstAnal[iCry][icol] = new TAPD();
909  IsThereDataADC[iCry][icol] = 1;
910  std::stringstream cut;
911  cut << "color==" << colors[icol];
912  if (ADCtrees[iCry]->GetEntries(cut.str().c_str()) < 10)
913  IsThereDataADC[iCry][icol] = 0;
914  }
915 
916  unsigned int iMod = iModule[iCry] - 1;
917  double alpha, beta;
918 
919  // Loop on events
920  //================
921 
922  Long64_t nbytes = 0, nb = 0;
923  for (Long64_t jentry = 0; jentry < ADCtrees[iCry]->GetEntriesFast(); jentry++) {
924  nb = ADCtrees[iCry]->GetEntry(jentry);
925  nbytes += nb;
926 
927  // Get back color
928 
929  unsigned int iCol = 0;
930  for (unsigned int i = 0; i < nCol; i++) {
931  if (color == colors[i]) {
932  iCol = i;
933  i = colors.size();
934  }
935  }
936 
937  // Retreive alpha and beta
938 
939  std::vector<double> abvals = shapana->getVals(iCry);
940  alpha = abvals[0];
941  beta = abvals[1];
942  flagAB = int(abvals[4]);
943  iphi = iPhi[iCry];
944  ieta = iEta[iCry];
945  towerID = iTowerID[iCry];
946  channelID = iChannelID[iCry];
947 
948  // Amplitude calculation
949 
952 
953  apdAmpl = 0;
954  apdAmplA = 0;
955  apdAmplB = 0;
956  apdTime = 0;
957 
958  if (APDPulse->isPulseOK()) {
959  pslsfit->init(_nsamples, _firstsample, _lastsample, _niter, alpha, beta);
960  chi2 = pslsfit->doFit(&adcNoPed[0]);
961 
962  if (chi2 < 0. || chi2 == 102 || chi2 == 101) {
963  apdAmpl = 0;
964  apdTime = 0;
965  flag = 0;
966  } else {
967  apdAmpl = pslsfit->getAmpl();
968  apdTime = pslsfit->getTime();
969  flag = 1;
970  }
971  } else {
972  apdAmpl = 0;
973  apdTime = 0;
974  flag = 0;
975  }
976 
977  if (_debug == 1)
978  edm::LogVerbatim("EcalLaserAnalyzer") << "-- debug test -- apdAmpl=" << apdAmpl << ", apdTime=" << apdTime;
979  double pnmean;
980  if (pn0 < 10 && pn1 > 10) {
981  pnmean = pn1;
982  } else if (pn1 < 10 && pn0 > 10) {
983  pnmean = pn0;
984  } else
985  pnmean = 0.5 * (pn0 + pn1);
986 
987  if (_debug == 1)
988  edm::LogVerbatim("EcalLaserAnalyzer") << "-- debug test -- pn0=" << pn0 << ", pn1=" << pn1;
989 
990  // Fill PN stuff
991  //===============
992 
993  if (firstChanMod[iMod] == iCry && IsThereDataADC[iCry][iCol] == 1) {
994  for (unsigned int ichan = 0; ichan < nPNPerMod; ichan++) {
995  PNFirstAnal[iMod][ichan][iCol]->addEntry(pnmean, pn0, pn1);
996  }
997  }
998 
999  // Fill APD stuff
1000  //================
1001 
1002  if (APDPulse->isPulseOK()) {
1003  APDFirstAnal[iCry][iCol]->addEntry(apdAmpl, pnmean, pn0, pn1, apdTime);
1004  APDtrees[iCry]->Fill();
1005 
1006  // Fill reference trees
1007  //=====================
1008 
1009  if (apdRefMap[0][iMod + 1] == iCry || apdRefMap[1][iMod + 1] == iCry) {
1010  apdAmplA = 0.0;
1011  apdAmplB = 0.0;
1012  eventref = event;
1013  colorref = color;
1014 
1015  for (unsigned int ir = 0; ir < nRefChan; ir++) {
1016  if (apdRefMap[ir][iMod + 1] == iCry) {
1017  if (ir == 0)
1018  apdAmplA = apdAmpl;
1019  else if (ir == 1)
1020  apdAmplB = apdAmpl;
1021  RefAPDtrees[ir][iMod + 1]->Fill();
1022  }
1023  }
1024  }
1025  }
1026  }
1027  }
1028 
1029  delete pslsfit;
1030 
1031  ADCFile->Close();
1032 
1033  // Remove temporary file
1034  //=======================
1035  std::stringstream del;
1036  del << "rm " << ADCfile;
1037  system(del.str().c_str());
1038 
1039  // Create output trees
1040  //=====================
1041 
1042  resFile = new TFile(resfile.c_str(), "RECREATE");
1043 
1044  for (unsigned int iColor = 0; iColor < nCol; iColor++) {
1045  std::stringstream nametree;
1046  nametree << "APDCol" << colors[iColor];
1047  std::stringstream nametree2;
1048  nametree2 << "PNCol" << colors[iColor];
1049 
1050  restrees[iColor] = new TTree(nametree.str().c_str(), nametree.str().c_str());
1051  respntrees[iColor] = new TTree(nametree2.str().c_str(), nametree2.str().c_str());
1052 
1053  restrees[iColor]->Branch("iphi", &iphi, "iphi/I");
1054  restrees[iColor]->Branch("ieta", &ieta, "ieta/I");
1055  restrees[iColor]->Branch("side", &side, "side/I");
1056  restrees[iColor]->Branch("dccID", &dccID, "dccID/I");
1057  restrees[iColor]->Branch("moduleID", &moduleID, "moduleID/I");
1058  restrees[iColor]->Branch("towerID", &towerID, "towerID/I");
1059  restrees[iColor]->Branch("channelID", &channelID, "channelID/I");
1060  restrees[iColor]->Branch("APD", &APD, "APD[6]/D");
1061  restrees[iColor]->Branch("Time", &Time, "Time[6]/D");
1062  restrees[iColor]->Branch("APDoPN", &APDoPN, "APDoPN[6]/D");
1063  restrees[iColor]->Branch("APDoPNA", &APDoPNA, "APDoPNA[6]/D");
1064  restrees[iColor]->Branch("APDoPNB", &APDoPNB, "APDoPNB[6]/D");
1065  restrees[iColor]->Branch("APDoAPDA", &APDoAPDA, "APDoAPDA[6]/D");
1066  restrees[iColor]->Branch("APDoAPDB", &APDoAPDB, "APDoAPDB[6]/D");
1067  restrees[iColor]->Branch("flag", &flag, "flag/I");
1068 
1069  respntrees[iColor]->Branch("side", &side, "side/I");
1070  respntrees[iColor]->Branch("moduleID", &moduleID, "moduleID/I");
1071  respntrees[iColor]->Branch("pnID", &pnID, "pnID/I");
1072  respntrees[iColor]->Branch("PN", &PN, "PN[6]/D");
1073  respntrees[iColor]->Branch("PNoPN", &PNoPN, "PNoPN[6]/D");
1074  respntrees[iColor]->Branch("PNoPNA", &PNoPNA, "PNoPNA[6]/D");
1075  respntrees[iColor]->Branch("PNoPNB", &PNoPNB, "PNoPNB[6]/D");
1076 
1077  restrees[iColor]->SetBranchAddress("iphi", &iphi);
1078  restrees[iColor]->SetBranchAddress("ieta", &ieta);
1079  restrees[iColor]->SetBranchAddress("side", &side);
1080  restrees[iColor]->SetBranchAddress("dccID", &dccID);
1081  restrees[iColor]->SetBranchAddress("moduleID", &moduleID);
1082  restrees[iColor]->SetBranchAddress("towerID", &towerID);
1083  restrees[iColor]->SetBranchAddress("channelID", &channelID);
1084  restrees[iColor]->SetBranchAddress("APD", APD);
1085  restrees[iColor]->SetBranchAddress("Time", Time);
1086  restrees[iColor]->SetBranchAddress("APDoPN", APDoPN);
1087  restrees[iColor]->SetBranchAddress("APDoPNA", APDoPNA);
1088  restrees[iColor]->SetBranchAddress("APDoPNB", APDoPNB);
1089  restrees[iColor]->SetBranchAddress("APDoAPDA", APDoAPDA);
1090  restrees[iColor]->SetBranchAddress("APDoAPDB", APDoAPDB);
1091  restrees[iColor]->SetBranchAddress("flag", &flag);
1092 
1093  respntrees[iColor]->SetBranchAddress("side", &side);
1094  respntrees[iColor]->SetBranchAddress("moduleID", &moduleID);
1095  respntrees[iColor]->SetBranchAddress("pnID", &pnID);
1096  respntrees[iColor]->SetBranchAddress("PN", PN);
1097  respntrees[iColor]->SetBranchAddress("PNoPN", PNoPN);
1098  respntrees[iColor]->SetBranchAddress("PNoPNA", PNoPNA);
1099  respntrees[iColor]->SetBranchAddress("PNoPNB", PNoPNB);
1100  }
1101 
1102  // Set Cuts for PN stuff
1103  //=======================
1104 
1105  for (unsigned int iM = 0; iM < nMod; iM++) {
1106  unsigned int iMod = modules[iM] - 1;
1107 
1108  for (unsigned int ich = 0; ich < nPNPerMod; ich++) {
1109  for (unsigned int icol = 0; icol < nCol; icol++) {
1110  PNAnal[iMod][ich][icol]->setPNCut(PNFirstAnal[iMod][ich][icol]->getPN().at(0),
1111  PNFirstAnal[iMod][ich][icol]->getPN().at(1));
1112  }
1113  }
1114  }
1115 
1116  // Build ref trees indexes
1117  //========================
1118  for (unsigned int imod = 0; imod < nMod; imod++) {
1119  int jmod = modules[imod];
1120  if (RefAPDtrees[0][jmod]->GetEntries() != 0 && RefAPDtrees[1][jmod]->GetEntries() != 0) {
1121  RefAPDtrees[0][jmod]->BuildIndex("eventref");
1122  RefAPDtrees[1][jmod]->BuildIndex("eventref");
1123  }
1124  }
1125 
1126  // Final loop on crystals
1127  //=======================
1128 
1129  for (unsigned int iCry = 0; iCry < nCrys; iCry++) {
1130  unsigned int iMod = iModule[iCry] - 1;
1131 
1132  // Set cuts on APD stuff
1133  //=======================
1134 
1135  for (unsigned int iCol = 0; iCol < nCol; iCol++) {
1136  std::vector<double> lowcut;
1137  std::vector<double> highcut;
1138  double cutMin;
1139  double cutMax;
1140 
1141  cutMin = APDFirstAnal[iCry][iCol]->getAPD().at(0) - 2.0 * APDFirstAnal[iCry][iCol]->getAPD().at(1);
1142  if (cutMin < 0)
1143  cutMin = 0;
1144  cutMax = APDFirstAnal[iCry][iCol]->getAPD().at(0) + 2.0 * APDFirstAnal[iCry][iCol]->getAPD().at(1);
1145 
1146  lowcut.push_back(cutMin);
1147  highcut.push_back(cutMax);
1148 
1149  cutMin = APDFirstAnal[iCry][iCol]->getTime().at(0) - 2.0 * APDFirstAnal[iCry][iCol]->getTime().at(1);
1150  cutMax = APDFirstAnal[iCry][iCol]->getTime().at(0) + 2.0 * APDFirstAnal[iCry][iCol]->getTime().at(1);
1151  lowcut.push_back(cutMin);
1152  highcut.push_back(cutMax);
1153 
1154  APDAnal[iCry][iCol] = new TAPD();
1155  APDAnal[iCry][iCol]->setAPDCut(APDFirstAnal[iCry][iCol]->getAPD().at(0),
1156  APDFirstAnal[iCry][iCol]->getAPD().at(1));
1157  APDAnal[iCry][iCol]->setAPDoPNCut(APDFirstAnal[iCry][iCol]->getAPDoPN().at(0),
1158  APDFirstAnal[iCry][iCol]->getAPDoPN().at(1));
1159  APDAnal[iCry][iCol]->setAPDoPN0Cut(APDFirstAnal[iCry][iCol]->getAPDoPN0().at(0),
1160  APDFirstAnal[iCry][iCol]->getAPDoPN0().at(1));
1161  APDAnal[iCry][iCol]->setAPDoPN1Cut(APDFirstAnal[iCry][iCol]->getAPDoPN1().at(0),
1162  APDFirstAnal[iCry][iCol]->getAPDoPN1().at(1));
1163  APDAnal[iCry][iCol]->setTimeCut(APDFirstAnal[iCry][iCol]->getTime().at(0),
1164  APDFirstAnal[iCry][iCol]->getTime().at(1));
1165  APDAnal[iCry][iCol]->set2DAPDoAPD0Cut(lowcut, highcut);
1166  APDAnal[iCry][iCol]->set2DAPDoAPD1Cut(lowcut, highcut);
1167  }
1168 
1169  // Final loop on events
1170  //=======================
1171 
1172  Long64_t nbytes = 0, nb = 0;
1173  for (Long64_t jentry = 0; jentry < APDtrees[iCry]->GetEntriesFast(); jentry++) {
1174  nb = APDtrees[iCry]->GetEntry(jentry);
1175  nbytes += nb;
1176 
1177  double pnmean;
1178  if (pn0 < 10 && pn1 > 10) {
1179  pnmean = pn1;
1180  } else if (pn1 < 10 && pn0 > 10) {
1181  pnmean = pn0;
1182  } else
1183  pnmean = 0.5 * (pn0 + pn1);
1184 
1185  // Get back color
1186  //================
1187 
1188  unsigned int iCol = 0;
1189  for (unsigned int i = 0; i < nCol; i++) {
1190  if (color == colors[i]) {
1191  iCol = i;
1192  i = colors.size();
1193  }
1194  }
1195 
1196  // Fill PN stuff
1197  //===============
1198 
1199  if (firstChanMod[iMod] == iCry && IsThereDataADC[iCry][iCol] == 1) {
1200  for (unsigned int ichan = 0; ichan < nPNPerMod; ichan++) {
1201  PNAnal[iMod][ichan][iCol]->addEntry(pnmean, pn0, pn1);
1202  }
1203  }
1204 
1205  // Get ref amplitudes
1206  //===================
1207 
1208  if (_debug == 1)
1209  edm::LogVerbatim("EcalLaserAnalyzer") << "-- debug test -- Last Loop event:" << event << " apdAmpl:" << apdAmpl;
1210  apdAmplA = 0.0;
1211  apdAmplB = 0.0;
1212 
1213  for (unsigned int iRef = 0; iRef < nRefChan; iRef++) {
1214  RefAPDtrees[iRef][iMod + 1]->GetEntryWithIndex(event);
1215  }
1216 
1217  if (_debug == 1)
1218  edm::LogVerbatim("EcalLaserAnalyzer")
1219  << "-- debug test -- Last Loop apdAmplA:" << apdAmplA << " apdAmplB:" << apdAmplB << ", event:" << event
1220  << ", eventref:" << eventref;
1221 
1222  // Fill APD stuff
1223  //===============
1224 
1225  APDAnal[iCry][iCol]->addEntry(apdAmpl, pnmean, pn0, pn1, apdTime, apdAmplA, apdAmplB);
1226  }
1227 
1228  moduleID = iMod + 1;
1229 
1230  if (moduleID >= 20)
1231  moduleID -= 2; // Trick to fix endcap specificity
1232 
1233  // Get final results for APD
1234  //===========================
1235 
1236  for (unsigned int iColor = 0; iColor < nCol; iColor++) {
1237  std::vector<double> apdvec = APDAnal[iCry][iColor]->getAPD();
1238  std::vector<double> apdpnvec = APDAnal[iCry][iColor]->getAPDoPN();
1239  std::vector<double> apdpn0vec = APDAnal[iCry][iColor]->getAPDoPN0();
1240  std::vector<double> apdpn1vec = APDAnal[iCry][iColor]->getAPDoPN1();
1241  std::vector<double> timevec = APDAnal[iCry][iColor]->getTime();
1242  std::vector<double> apdapd0vec = APDAnal[iCry][iColor]->getAPDoAPD0();
1243  std::vector<double> apdapd1vec = APDAnal[iCry][iColor]->getAPDoAPD1();
1244 
1245  for (unsigned int i = 0; i < apdvec.size(); i++) {
1246  APD[i] = apdvec.at(i);
1247  APDoPN[i] = apdpnvec.at(i);
1248  APDoPNA[i] = apdpn0vec.at(i);
1249  APDoPNB[i] = apdpn1vec.at(i);
1250  APDoAPDA[i] = apdapd0vec.at(i);
1251  APDoAPDB[i] = apdapd1vec.at(i);
1252  Time[i] = timevec.at(i);
1253  }
1254 
1255  // Fill APD results trees
1256  //========================
1257 
1258  iphi = iPhi[iCry];
1259  ieta = iEta[iCry];
1260  dccID = idccID[iCry];
1261  side = iside[iCry];
1262  towerID = iTowerID[iCry];
1263  channelID = iChannelID[iCry];
1264 
1265  if (!wasGainOK[iCry] || !wasTimingOK[iCry] || IsThereDataADC[iCry][iColor] == 0) {
1266  flag = 0;
1267  } else
1268  flag = 1;
1269 
1270  restrees[iColor]->Fill();
1271  }
1272  }
1273 
1274  // Get final results for PN
1275  //==========================
1276 
1277  for (unsigned int iM = 0; iM < nMod; iM++) {
1278  unsigned int iMod = modules[iM] - 1;
1279 
1280  side = iside[firstChanMod[iMod]];
1281 
1282  for (unsigned int ch = 0; ch < nPNPerMod; ch++) {
1283  pnID = ch;
1284  moduleID = iMod + 1;
1285 
1286  if (moduleID >= 20)
1287  moduleID -= 2; // Trick to fix endcap specificity
1288 
1289  for (unsigned int iColor = 0; iColor < nCol; iColor++) {
1290  std::vector<double> pnvec = PNAnal[iMod][ch][iColor]->getPN();
1291  std::vector<double> pnopnvec = PNAnal[iMod][ch][iColor]->getPNoPN();
1292  std::vector<double> pnopn0vec = PNAnal[iMod][ch][iColor]->getPNoPN0();
1293  std::vector<double> pnopn1vec = PNAnal[iMod][ch][iColor]->getPNoPN1();
1294 
1295  for (unsigned int i = 0; i < pnvec.size(); i++) {
1296  PN[i] = pnvec.at(i);
1297  PNoPN[i] = pnopnvec.at(i);
1298  PNoPNA[i] = pnopn0vec.at(i);
1299  PNoPNB[i] = pnopn1vec.at(i);
1300  }
1301 
1302  // Fill PN results trees
1303  //========================
1304 
1305  respntrees[iColor]->Fill();
1306  }
1307  }
1308  }
1309 
1310  // Remove temporary files
1311  //========================
1312  if (!_saveallevents) {
1313  APDFile->Close();
1314  std::stringstream del2;
1315  del2 << "rm " << APDfile;
1316  system(del2.str().c_str());
1317 
1318  } else {
1319  APDFile->cd();
1320  APDtrees[0]->Write();
1321 
1322  APDFile->Close();
1323  resFile->cd();
1324  }
1325 
1326  // Save results
1327  //===============
1328 
1329  for (unsigned int i = 0; i < nCol; i++) {
1330  restrees[i]->Write();
1331  respntrees[i]->Write();
1332  }
1333 
1334  resFile->Close();
1335 
1336  edm::LogVerbatim("EcalLaserAnalyzer") << "\t+=+ .................................................. done +=+";
1337  edm::LogVerbatim("EcalLaserAnalyzer") << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
1338 }
1339 
1341  int etaG, int phiG, int module, int tower, int strip, int xtal, int apdRefTT, int channel, int lmr) {
1342  side = MEEBGeom::side(etaG, phiG);
1343 
1344  assert(module >= *min_element(modules.begin(), modules.end()) &&
1345  module <= *max_element(modules.begin(), modules.end()));
1346 
1347  eta = etaG;
1348  phi = phiG;
1349  channelID = 5 * (strip - 1) + xtal - 1;
1350  towerID = tower;
1351 
1352  std::vector<int> apdRefChan = ME::apdRefChannels(module, lmr);
1353  for (unsigned int iref = 0; iref < nRefChan; iref++) {
1354  if (channelID == apdRefChan[iref] && towerID == apdRefTT && apdRefMap[iref].count(module) == 0) {
1355  apdRefMap[iref][module] = channel;
1356  }
1357  }
1358 
1359  if (isFirstChanModFilled[module - 1] == 0) {
1360  firstChanMod[module - 1] = channel;
1361  isFirstChanModFilled[module - 1] = 1;
1362  }
1363 
1364  iEta[channel] = eta;
1365  iPhi[channel] = phi;
1366  iModule[channel] = module;
1367  iTowerID[channel] = towerID;
1368  iChannelID[channel] = channelID;
1369  idccID[channel] = dccID;
1370  iside[channel] = side;
1371 }
1372 
1374  int etaG, int phiG, int iX, int iY, int iZ, int module, int tower, int ch, int apdRefTT, int channel, int lmr) {
1375  side = MEEEGeom::side(iX, iY, iZ);
1376 
1377  assert(module >= *min_element(modules.begin(), modules.end()) &&
1378  module <= *max_element(modules.begin(), modules.end()));
1379 
1380  eta = etaG;
1381  phi = phiG;
1382  channelID = ch;
1383  towerID = tower;
1384 
1385  std::vector<int> apdRefChan = ME::apdRefChannels(module, lmr);
1386  for (unsigned int iref = 0; iref < nRefChan; iref++) {
1387  if (channelID == apdRefChan[iref] && towerID == apdRefTT && apdRefMap[iref].count(module) == 0) {
1388  apdRefMap[iref][module] = channel;
1389  }
1390  }
1391 
1392  if (isFirstChanModFilled[module - 1] == 0) {
1393  firstChanMod[module - 1] = channel;
1394  isFirstChanModFilled[module - 1] = 1;
1395  }
1396 
1397  iEta[channel] = eta;
1398  iPhi[channel] = phi;
1399  iModule[channel] = module;
1400  iTowerID[channel] = towerID;
1401  iChannelID[channel] = channelID;
1402  idccID[channel] = dccID;
1403  iside[channel] = side;
1404 }
1405 
void addEntry(double val)
Definition: TMom.cc:88
Log< level::Info, true > LogVerbatim
static XYCoord localCoord(int icr)
Definition: MEEBGeom.cc:142
static int lmmod(SuperCrysCoord iX, SuperCrysCoord iY)
Definition: MEEEGeom.cc:112
TAPD * APDAnal[1700][nColor]
float alpha
Definition: AMPTWrapper.h:105
const edm::EventSetup & c
Definition: TPN.h:8
void setAPDCut(double, double)
Definition: TAPD.cc:141
TPN * PNFirstAnal[22][2][nColor]
const std::string digiProducer_
#define NMODEE
int xtalId() const
get the channel id
std::vector< double > getPN()
Definition: TPN.cc:90
#define NSIDES
void endJob() override
std::vector< int > modules
EcalLaserAnalyzer(const edm::ParameterSet &iConfig)
Definition: TAPD.h:8
static int apdRefTower(int ilmr, int ilmmod)
Definition: MEEEGeom.cc:1208
void addEntry(double, double, double)
Definition: TPN.cc:33
std::map< int, unsigned int > apdRefMap[2]
const double _ratiomincuthigh
int stripId() const
get the tower id
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
double getDelta(int, int)
Definition: TAPDPulse.cc:116
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< double > getPNoPN1()
Definition: TPN.cc:102
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
~EcalLaserAnalyzer() override
#define NCRYSEE
bool setPulse(double *)
Definition: TAPDPulse.cc:86
static int side(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:1155
void setPNCut(double, double)
Definition: TPN.cc:70
const unsigned int _nsamplesPN
void addEntry(double, double, double, double, double, double, double)
Definition: TAPD.cc:42
double getPNCorrectionFactor(double val0, int gain)
Definition: TPNCor.cc:64
std::vector< T >::const_iterator const_iterator
const edm::EDGetTokenT< EcalRawDataCollection > rawDataToken_
const std::string eventHeaderCollection_
void init(int, int, int)
Definition: TPNFit.cc:24
tuple runType
Definition: runPedHist.py:37
void computeShape(std::string namefile, TTree *)
int towerId() const
get the tower id
double * getAdcWithoutPedestal()
Definition: TPNPulse.cc:89
const_iterator begin() const
The iterator returned can not safely be used across threads.
void putAllVals(int, double *, int, int)
static int lmr(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:110
Log< level::Error, false > LogError
Definition: TMom.h:7
TPN * PNAnal[22][2][nColor]
int ii
Definition: cuy.py:589
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
void beginJob() override
bool setPulse(double *)
Definition: TPNPulse.cc:45
std::vector< double > getAPDoPN0()
Definition: TAPD.cc:224
void setTimeCut(double, double)
Definition: TAPD.cc:145
const double _presamplecut
edm::EDGetTokenT< EBDigiCollection > ebDigiToken_
TTree * RefAPDtrees[2][22]
static std::pair< int, int > pn(int ilmmod)
Definition: MEEBGeom.cc:447
void set2DAPDoAPD1Cut(const std::vector< double > &, const std::vector< double > &)
Definition: TAPD.cc:181
const unsigned int _nevtmax
const double _ratiomaxcutlow
void setAPDoPN0Cut(double, double)
Definition: TAPD.cc:143
std::vector< double > getPNoPN0()
Definition: TPN.cc:98
std::vector< double > getAPDoPN1()
Definition: TAPD.cc:228
const unsigned int _niter
bool getData(T &iHolder) const
Definition: EventSetup.h:128
const std::string eventHeaderProducer_
int iPnId() const
get the PnId
Definition: TMem.h:7
std::vector< int > colors
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 Mem(int, int)
Definition: TMem.cc:41
int iEvent
Definition: GenABIO.cc:224
std::vector< double > getAPDoAPD0()
Definition: TAPD.cc:236
void set2DAPDoAPD0Cut(const std::vector< double > &, const std::vector< double > &)
Definition: TAPD.cc:173
TAPD * APDFirstAnal[1700][nColor]
static int electronic_channel(EBLocalCoord ix, EBLocalCoord iy)
Definition: MEEBGeom.cc:326
unsigned int firstChanMod[22]
const unsigned int _timingqualhigh
#define NCRYSEB
double getAmpl()
Definition: TPNFit.h:32
const std::string digiPNCollection_
const unsigned int _nsamples
unsigned int isFirstChanModFilled[22]
double * getAdcWithoutPedestal()
Definition: TAPDPulse.cc:237
static int apdRefTower(int ilmmod)
Definition: MEEBGeom.cc:490
#define NREFCHAN
const unsigned int _lastsamplePN
unsigned int _presample
bool isValid() const
Definition: HandleBase.h:70
const unsigned int _lastsample
int iDCCId() const
get the DCCId
static int lmmod(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:90
std::vector< double > getAPDoAPD1()
Definition: TAPD.cc:241
virtual void init(int, int, int, int, double, double)
std::vector< double > getAPD()
Definition: TAPD.cc:216
const edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > mappingToken_
std::map< unsigned int, unsigned int > channelMapEE
unsigned int iModule[1700]
const_iterator end() const
const std::string resdir_
T Max(T a, T b)
Definition: MathUtil.h:44
std::string alphainitfile
static int side(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:105
TShapeAnalysis * shapana
const unsigned int _timingcutlow
bool isTimingQualOK()
Definition: TAPDPulse.cc:145
TTree * restrees[nColor]
T const * product() const
Definition: Handle.h:70
void setGeomEB(int etaG, int phiG, int module, int tower, int strip, int xtal, int apdRefTT, int channel, int lmr)
TTree * APDtrees[1700]
virtual double doFit(double *)
unsigned int nPNPerMod
#define NPNPERMOD
void analyze(const edm::Event &e, const edm::EventSetup &c) override
void setGeomEE(int etaG, int phiG, int iX, int iY, int iZ, int module, int tower, int ch, int apdRefTT, int channel, int lmr)
edm::EDGetTokenT< EEDigiCollection > eeDigiToken_
int IsThereDataADC[1700][nColor]
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
std::vector< double > getVals(int)
void set_const(int, int, int, int, int, double, double)
const_iterator end() const
void setPresamples(int)
Definition: TAPDPulse.cc:251
bool isPulseOK()
Definition: TAPDPulse.cc:162
const unsigned int _timingcuthigh
const unsigned int _presamplePN
void set_presample(int)
std::vector< double > getPNoPN()
Definition: TPN.cc:94
const edm::EDGetTokenT< EcalPnDiodeDigiCollection > pnDiodeDigiToken_
const unsigned int _firstsample
const unsigned int _firstsamplePN
const double _qualpercent
Definition: TPNFit.h:6
static int dee(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:292
bool isMemRelevant(int)
Definition: TMem.cc:30
unsigned int nevtAB[1700]
TTree * ADCtrees[1700]
int getMaxSample()
Definition: TPNPulse.cc:70
double doFit(int, double *)
Definition: TPNFit.cc:39
std::vector< double > getAPDoPN()
Definition: TAPD.cc:220
const std::string digiCollection_
Definition: TPNCor.h:7
const std::string pncorfile_
const double _ratiomincutlow
const unsigned int _timingquallow
TTree * respntrees[nColor]
std::vector< double > getTime()
Definition: TAPD.cc:232
static std::vector< int > apdRefChannels(ME::LMMid ilmmod, ME::LMRid ilmr)
Definition: ME.cc:545
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
static int lmr(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:254
tuple size
Write out results.
const std::string _ecalPart
int channelId() const
so far for EndCap only :
const_iterator begin() const
void setAPDoPNCut(double, double)
Definition: TAPD.cc:142
tuple module
Definition: callgraph.py:69
void setAPDoPN1Cut(double, double)
Definition: TAPD.cc:144