CMS 3D CMS Logo

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)
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
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  for (Long64_t jentry = 0; jentry < ADCtrees[iCry]->GetEntriesFast(); jentry++) {
923  ADCtrees[iCry]->GetEntry(jentry);
924 
925  // Get back color
926 
927  unsigned int iCol = 0;
928  for (unsigned int i = 0; i < nCol; i++) {
929  if (color == colors[i]) {
930  iCol = i;
931  i = colors.size();
932  }
933  }
934 
935  // Retreive alpha and beta
936 
937  std::vector<double> abvals = shapana->getVals(iCry);
938  alpha = abvals[0];
939  beta = abvals[1];
940  flagAB = int(abvals[4]);
941  iphi = iPhi[iCry];
942  ieta = iEta[iCry];
943  towerID = iTowerID[iCry];
944  channelID = iChannelID[iCry];
945 
946  // Amplitude calculation
947 
950 
951  apdAmpl = 0;
952  apdAmplA = 0;
953  apdAmplB = 0;
954  apdTime = 0;
955 
956  if (APDPulse->isPulseOK()) {
958  chi2 = pslsfit->doFit(&adcNoPed[0]);
959 
960  if (chi2 < 0. || chi2 == 102 || chi2 == 101) {
961  apdAmpl = 0;
962  apdTime = 0;
963  flag = 0;
964  } else {
965  apdAmpl = pslsfit->getAmpl();
966  apdTime = pslsfit->getTime();
967  flag = 1;
968  }
969  } else {
970  apdAmpl = 0;
971  apdTime = 0;
972  flag = 0;
973  }
974 
975  if (_debug == 1)
976  edm::LogVerbatim("EcalLaserAnalyzer") << "-- debug test -- apdAmpl=" << apdAmpl << ", apdTime=" << apdTime;
977  double pnmean;
978  if (pn0 < 10 && pn1 > 10) {
979  pnmean = pn1;
980  } else if (pn1 < 10 && pn0 > 10) {
981  pnmean = pn0;
982  } else
983  pnmean = 0.5 * (pn0 + pn1);
984 
985  if (_debug == 1)
986  edm::LogVerbatim("EcalLaserAnalyzer") << "-- debug test -- pn0=" << pn0 << ", pn1=" << pn1;
987 
988  // Fill PN stuff
989  //===============
990 
991  if (firstChanMod[iMod] == iCry && IsThereDataADC[iCry][iCol] == 1) {
992  for (unsigned int ichan = 0; ichan < nPNPerMod; ichan++) {
993  PNFirstAnal[iMod][ichan][iCol]->addEntry(pnmean, pn0, pn1);
994  }
995  }
996 
997  // Fill APD stuff
998  //================
999 
1000  if (APDPulse->isPulseOK()) {
1001  APDFirstAnal[iCry][iCol]->addEntry(apdAmpl, pnmean, pn0, pn1, apdTime);
1002  APDtrees[iCry]->Fill();
1003 
1004  // Fill reference trees
1005  //=====================
1006 
1007  if (apdRefMap[0][iMod + 1] == iCry || apdRefMap[1][iMod + 1] == iCry) {
1008  apdAmplA = 0.0;
1009  apdAmplB = 0.0;
1010  eventref = event;
1011  colorref = color;
1012 
1013  for (unsigned int ir = 0; ir < nRefChan; ir++) {
1014  if (apdRefMap[ir][iMod + 1] == iCry) {
1015  if (ir == 0)
1016  apdAmplA = apdAmpl;
1017  else if (ir == 1)
1018  apdAmplB = apdAmpl;
1019  RefAPDtrees[ir][iMod + 1]->Fill();
1020  }
1021  }
1022  }
1023  }
1024  }
1025  }
1026 
1027  delete pslsfit;
1028 
1029  ADCFile->Close();
1030 
1031  // Remove temporary file
1032  //=======================
1033  std::stringstream del;
1034  del << "rm " << ADCfile;
1035  system(del.str().c_str());
1036 
1037  // Create output trees
1038  //=====================
1039 
1040  resFile = new TFile(resfile.c_str(), "RECREATE");
1041 
1042  for (unsigned int iColor = 0; iColor < nCol; iColor++) {
1043  std::stringstream nametree;
1044  nametree << "APDCol" << colors[iColor];
1045  std::stringstream nametree2;
1046  nametree2 << "PNCol" << colors[iColor];
1047 
1048  restrees[iColor] = new TTree(nametree.str().c_str(), nametree.str().c_str());
1049  respntrees[iColor] = new TTree(nametree2.str().c_str(), nametree2.str().c_str());
1050 
1051  restrees[iColor]->Branch("iphi", &iphi, "iphi/I");
1052  restrees[iColor]->Branch("ieta", &ieta, "ieta/I");
1053  restrees[iColor]->Branch("side", &side, "side/I");
1054  restrees[iColor]->Branch("dccID", &dccID, "dccID/I");
1055  restrees[iColor]->Branch("moduleID", &moduleID, "moduleID/I");
1056  restrees[iColor]->Branch("towerID", &towerID, "towerID/I");
1057  restrees[iColor]->Branch("channelID", &channelID, "channelID/I");
1058  restrees[iColor]->Branch("APD", &APD, "APD[6]/D");
1059  restrees[iColor]->Branch("Time", &Time, "Time[6]/D");
1060  restrees[iColor]->Branch("APDoPN", &APDoPN, "APDoPN[6]/D");
1061  restrees[iColor]->Branch("APDoPNA", &APDoPNA, "APDoPNA[6]/D");
1062  restrees[iColor]->Branch("APDoPNB", &APDoPNB, "APDoPNB[6]/D");
1063  restrees[iColor]->Branch("APDoAPDA", &APDoAPDA, "APDoAPDA[6]/D");
1064  restrees[iColor]->Branch("APDoAPDB", &APDoAPDB, "APDoAPDB[6]/D");
1065  restrees[iColor]->Branch("flag", &flag, "flag/I");
1066 
1067  respntrees[iColor]->Branch("side", &side, "side/I");
1068  respntrees[iColor]->Branch("moduleID", &moduleID, "moduleID/I");
1069  respntrees[iColor]->Branch("pnID", &pnID, "pnID/I");
1070  respntrees[iColor]->Branch("PN", &PN, "PN[6]/D");
1071  respntrees[iColor]->Branch("PNoPN", &PNoPN, "PNoPN[6]/D");
1072  respntrees[iColor]->Branch("PNoPNA", &PNoPNA, "PNoPNA[6]/D");
1073  respntrees[iColor]->Branch("PNoPNB", &PNoPNB, "PNoPNB[6]/D");
1074 
1075  restrees[iColor]->SetBranchAddress("iphi", &iphi);
1076  restrees[iColor]->SetBranchAddress("ieta", &ieta);
1077  restrees[iColor]->SetBranchAddress("side", &side);
1078  restrees[iColor]->SetBranchAddress("dccID", &dccID);
1079  restrees[iColor]->SetBranchAddress("moduleID", &moduleID);
1080  restrees[iColor]->SetBranchAddress("towerID", &towerID);
1081  restrees[iColor]->SetBranchAddress("channelID", &channelID);
1082  restrees[iColor]->SetBranchAddress("APD", APD);
1083  restrees[iColor]->SetBranchAddress("Time", Time);
1084  restrees[iColor]->SetBranchAddress("APDoPN", APDoPN);
1085  restrees[iColor]->SetBranchAddress("APDoPNA", APDoPNA);
1086  restrees[iColor]->SetBranchAddress("APDoPNB", APDoPNB);
1087  restrees[iColor]->SetBranchAddress("APDoAPDA", APDoAPDA);
1088  restrees[iColor]->SetBranchAddress("APDoAPDB", APDoAPDB);
1089  restrees[iColor]->SetBranchAddress("flag", &flag);
1090 
1091  respntrees[iColor]->SetBranchAddress("side", &side);
1092  respntrees[iColor]->SetBranchAddress("moduleID", &moduleID);
1093  respntrees[iColor]->SetBranchAddress("pnID", &pnID);
1094  respntrees[iColor]->SetBranchAddress("PN", PN);
1095  respntrees[iColor]->SetBranchAddress("PNoPN", PNoPN);
1096  respntrees[iColor]->SetBranchAddress("PNoPNA", PNoPNA);
1097  respntrees[iColor]->SetBranchAddress("PNoPNB", PNoPNB);
1098  }
1099 
1100  // Set Cuts for PN stuff
1101  //=======================
1102 
1103  for (unsigned int iM = 0; iM < nMod; iM++) {
1104  unsigned int iMod = modules[iM] - 1;
1105 
1106  for (unsigned int ich = 0; ich < nPNPerMod; ich++) {
1107  for (unsigned int icol = 0; icol < nCol; icol++) {
1108  PNAnal[iMod][ich][icol]->setPNCut(PNFirstAnal[iMod][ich][icol]->getPN().at(0),
1109  PNFirstAnal[iMod][ich][icol]->getPN().at(1));
1110  }
1111  }
1112  }
1113 
1114  // Build ref trees indexes
1115  //========================
1116  for (unsigned int imod = 0; imod < nMod; imod++) {
1117  int jmod = modules[imod];
1118  if (RefAPDtrees[0][jmod]->GetEntries() != 0 && RefAPDtrees[1][jmod]->GetEntries() != 0) {
1119  RefAPDtrees[0][jmod]->BuildIndex("eventref");
1120  RefAPDtrees[1][jmod]->BuildIndex("eventref");
1121  }
1122  }
1123 
1124  // Final loop on crystals
1125  //=======================
1126 
1127  for (unsigned int iCry = 0; iCry < nCrys; iCry++) {
1128  unsigned int iMod = iModule[iCry] - 1;
1129 
1130  // Set cuts on APD stuff
1131  //=======================
1132 
1133  for (unsigned int iCol = 0; iCol < nCol; iCol++) {
1134  std::vector<double> lowcut;
1135  std::vector<double> highcut;
1136  double cutMin;
1137  double cutMax;
1138 
1139  cutMin = APDFirstAnal[iCry][iCol]->getAPD().at(0) - 2.0 * APDFirstAnal[iCry][iCol]->getAPD().at(1);
1140  if (cutMin < 0)
1141  cutMin = 0;
1142  cutMax = APDFirstAnal[iCry][iCol]->getAPD().at(0) + 2.0 * APDFirstAnal[iCry][iCol]->getAPD().at(1);
1143 
1144  lowcut.push_back(cutMin);
1145  highcut.push_back(cutMax);
1146 
1147  cutMin = APDFirstAnal[iCry][iCol]->getTime().at(0) - 2.0 * APDFirstAnal[iCry][iCol]->getTime().at(1);
1148  cutMax = APDFirstAnal[iCry][iCol]->getTime().at(0) + 2.0 * APDFirstAnal[iCry][iCol]->getTime().at(1);
1149  lowcut.push_back(cutMin);
1150  highcut.push_back(cutMax);
1151 
1152  APDAnal[iCry][iCol] = new TAPD();
1153  APDAnal[iCry][iCol]->setAPDCut(APDFirstAnal[iCry][iCol]->getAPD().at(0),
1154  APDFirstAnal[iCry][iCol]->getAPD().at(1));
1155  APDAnal[iCry][iCol]->setAPDoPNCut(APDFirstAnal[iCry][iCol]->getAPDoPN().at(0),
1156  APDFirstAnal[iCry][iCol]->getAPDoPN().at(1));
1157  APDAnal[iCry][iCol]->setAPDoPN0Cut(APDFirstAnal[iCry][iCol]->getAPDoPN0().at(0),
1158  APDFirstAnal[iCry][iCol]->getAPDoPN0().at(1));
1159  APDAnal[iCry][iCol]->setAPDoPN1Cut(APDFirstAnal[iCry][iCol]->getAPDoPN1().at(0),
1160  APDFirstAnal[iCry][iCol]->getAPDoPN1().at(1));
1161  APDAnal[iCry][iCol]->setTimeCut(APDFirstAnal[iCry][iCol]->getTime().at(0),
1162  APDFirstAnal[iCry][iCol]->getTime().at(1));
1163  APDAnal[iCry][iCol]->set2DAPDoAPD0Cut(lowcut, highcut);
1164  APDAnal[iCry][iCol]->set2DAPDoAPD1Cut(lowcut, highcut);
1165  }
1166 
1167  // Final loop on events
1168  //=======================
1169 
1170  for (Long64_t jentry = 0; jentry < APDtrees[iCry]->GetEntriesFast(); jentry++) {
1171  APDtrees[iCry]->GetEntry(jentry);
1172 
1173  double pnmean;
1174  if (pn0 < 10 && pn1 > 10) {
1175  pnmean = pn1;
1176  } else if (pn1 < 10 && pn0 > 10) {
1177  pnmean = pn0;
1178  } else
1179  pnmean = 0.5 * (pn0 + pn1);
1180 
1181  // Get back color
1182  //================
1183 
1184  unsigned int iCol = 0;
1185  for (unsigned int i = 0; i < nCol; i++) {
1186  if (color == colors[i]) {
1187  iCol = i;
1188  i = colors.size();
1189  }
1190  }
1191 
1192  // Fill PN stuff
1193  //===============
1194 
1195  if (firstChanMod[iMod] == iCry && IsThereDataADC[iCry][iCol] == 1) {
1196  for (unsigned int ichan = 0; ichan < nPNPerMod; ichan++) {
1197  PNAnal[iMod][ichan][iCol]->addEntry(pnmean, pn0, pn1);
1198  }
1199  }
1200 
1201  // Get ref amplitudes
1202  //===================
1203 
1204  if (_debug == 1)
1205  edm::LogVerbatim("EcalLaserAnalyzer") << "-- debug test -- Last Loop event:" << event << " apdAmpl:" << apdAmpl;
1206  apdAmplA = 0.0;
1207  apdAmplB = 0.0;
1208 
1209  for (unsigned int iRef = 0; iRef < nRefChan; iRef++) {
1210  RefAPDtrees[iRef][iMod + 1]->GetEntryWithIndex(event);
1211  }
1212 
1213  if (_debug == 1)
1214  edm::LogVerbatim("EcalLaserAnalyzer")
1215  << "-- debug test -- Last Loop apdAmplA:" << apdAmplA << " apdAmplB:" << apdAmplB << ", event:" << event
1216  << ", eventref:" << eventref;
1217 
1218  // Fill APD stuff
1219  //===============
1220 
1221  APDAnal[iCry][iCol]->addEntry(apdAmpl, pnmean, pn0, pn1, apdTime, apdAmplA, apdAmplB);
1222  }
1223 
1224  moduleID = iMod + 1;
1225 
1226  if (moduleID >= 20)
1227  moduleID -= 2; // Trick to fix endcap specificity
1228 
1229  // Get final results for APD
1230  //===========================
1231 
1232  for (unsigned int iColor = 0; iColor < nCol; iColor++) {
1233  std::vector<double> apdvec = APDAnal[iCry][iColor]->getAPD();
1234  std::vector<double> apdpnvec = APDAnal[iCry][iColor]->getAPDoPN();
1235  std::vector<double> apdpn0vec = APDAnal[iCry][iColor]->getAPDoPN0();
1236  std::vector<double> apdpn1vec = APDAnal[iCry][iColor]->getAPDoPN1();
1237  std::vector<double> timevec = APDAnal[iCry][iColor]->getTime();
1238  std::vector<double> apdapd0vec = APDAnal[iCry][iColor]->getAPDoAPD0();
1239  std::vector<double> apdapd1vec = APDAnal[iCry][iColor]->getAPDoAPD1();
1240 
1241  for (unsigned int i = 0; i < apdvec.size(); i++) {
1242  APD[i] = apdvec.at(i);
1243  APDoPN[i] = apdpnvec.at(i);
1244  APDoPNA[i] = apdpn0vec.at(i);
1245  APDoPNB[i] = apdpn1vec.at(i);
1246  APDoAPDA[i] = apdapd0vec.at(i);
1247  APDoAPDB[i] = apdapd1vec.at(i);
1248  Time[i] = timevec.at(i);
1249  }
1250 
1251  // Fill APD results trees
1252  //========================
1253 
1254  iphi = iPhi[iCry];
1255  ieta = iEta[iCry];
1256  dccID = idccID[iCry];
1257  side = iside[iCry];
1258  towerID = iTowerID[iCry];
1259  channelID = iChannelID[iCry];
1260 
1261  if (!wasGainOK[iCry] || !wasTimingOK[iCry] || IsThereDataADC[iCry][iColor] == 0) {
1262  flag = 0;
1263  } else
1264  flag = 1;
1265 
1266  restrees[iColor]->Fill();
1267  }
1268  }
1269 
1270  // Get final results for PN
1271  //==========================
1272 
1273  for (unsigned int iM = 0; iM < nMod; iM++) {
1274  unsigned int iMod = modules[iM] - 1;
1275 
1276  side = iside[firstChanMod[iMod]];
1277 
1278  for (unsigned int ch = 0; ch < nPNPerMod; ch++) {
1279  pnID = ch;
1280  moduleID = iMod + 1;
1281 
1282  if (moduleID >= 20)
1283  moduleID -= 2; // Trick to fix endcap specificity
1284 
1285  for (unsigned int iColor = 0; iColor < nCol; iColor++) {
1286  std::vector<double> pnvec = PNAnal[iMod][ch][iColor]->getPN();
1287  std::vector<double> pnopnvec = PNAnal[iMod][ch][iColor]->getPNoPN();
1288  std::vector<double> pnopn0vec = PNAnal[iMod][ch][iColor]->getPNoPN0();
1289  std::vector<double> pnopn1vec = PNAnal[iMod][ch][iColor]->getPNoPN1();
1290 
1291  for (unsigned int i = 0; i < pnvec.size(); i++) {
1292  PN[i] = pnvec.at(i);
1293  PNoPN[i] = pnopnvec.at(i);
1294  PNoPNA[i] = pnopn0vec.at(i);
1295  PNoPNB[i] = pnopn1vec.at(i);
1296  }
1297 
1298  // Fill PN results trees
1299  //========================
1300 
1301  respntrees[iColor]->Fill();
1302  }
1303  }
1304  }
1305 
1306  // Remove temporary files
1307  //========================
1308  if (!_saveallevents) {
1309  APDFile->Close();
1310  std::stringstream del2;
1311  del2 << "rm " << APDfile;
1312  system(del2.str().c_str());
1313 
1314  } else {
1315  APDFile->cd();
1316  APDtrees[0]->Write();
1317 
1318  APDFile->Close();
1319  resFile->cd();
1320  }
1321 
1322  // Save results
1323  //===============
1324 
1325  for (unsigned int i = 0; i < nCol; i++) {
1326  restrees[i]->Write();
1327  respntrees[i]->Write();
1328  }
1329 
1330  resFile->Close();
1331 
1332  edm::LogVerbatim("EcalLaserAnalyzer") << "\t+=+ .................................................. done +=+";
1333  edm::LogVerbatim("EcalLaserAnalyzer") << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
1334 }
1335 
1337  int etaG, int phiG, int module, int tower, int strip, int xtal, int apdRefTT, int channel, int lmr) {
1338  side = MEEBGeom::side(etaG, phiG);
1339 
1340  assert(module >= *min_element(modules.begin(), modules.end()) &&
1341  module <= *max_element(modules.begin(), modules.end()));
1342 
1343  eta = etaG;
1344  phi = phiG;
1345  channelID = 5 * (strip - 1) + xtal - 1;
1346  towerID = tower;
1347 
1348  std::vector<int> apdRefChan = ME::apdRefChannels(module, lmr);
1349  for (unsigned int iref = 0; iref < nRefChan; iref++) {
1350  if (channelID == apdRefChan[iref] && towerID == apdRefTT && apdRefMap[iref].count(module) == 0) {
1351  apdRefMap[iref][module] = channel;
1352  }
1353  }
1354 
1355  if (isFirstChanModFilled[module - 1] == 0) {
1356  firstChanMod[module - 1] = channel;
1357  isFirstChanModFilled[module - 1] = 1;
1358  }
1359 
1360  iEta[channel] = eta;
1361  iPhi[channel] = phi;
1362  iModule[channel] = module;
1363  iTowerID[channel] = towerID;
1364  iChannelID[channel] = channelID;
1365  idccID[channel] = dccID;
1366  iside[channel] = side;
1367 }
1368 
1370  int etaG, int phiG, int iX, int iY, int iZ, int module, int tower, int ch, int apdRefTT, int channel, int lmr) {
1371  side = MEEEGeom::side(iX, iY, iZ);
1372 
1373  assert(module >= *min_element(modules.begin(), modules.end()) &&
1374  module <= *max_element(modules.begin(), modules.end()));
1375 
1376  eta = etaG;
1377  phi = phiG;
1378  channelID = ch;
1379  towerID = tower;
1380 
1381  std::vector<int> apdRefChan = ME::apdRefChannels(module, lmr);
1382  for (unsigned int iref = 0; iref < nRefChan; iref++) {
1383  if (channelID == apdRefChan[iref] && towerID == apdRefTT && apdRefMap[iref].count(module) == 0) {
1384  apdRefMap[iref][module] = channel;
1385  }
1386  }
1387 
1388  if (isFirstChanModFilled[module - 1] == 0) {
1389  firstChanMod[module - 1] = channel;
1390  isFirstChanModFilled[module - 1] = 1;
1391  }
1392 
1393  iEta[channel] = eta;
1394  iPhi[channel] = phi;
1395  iModule[channel] = module;
1396  iTowerID[channel] = towerID;
1397  iChannelID[channel] = channelID;
1398  idccID[channel] = dccID;
1399  iside[channel] = side;
1400 }
1401 
size
Write out results.
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]
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Definition: TPN.h:8
void setAPDCut(double, double)
Definition: TAPD.cc:141
TPN * PNFirstAnal[22][2][nColor]
const std::string digiProducer_
#define NMODEE
std::vector< double > getPN()
Definition: TPN.cc:90
#define NSIDES
void endJob() override
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
double getDelta(int, int)
Definition: TAPDPulse.cc:116
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
T const * product() const
Definition: Handle.h:70
void addEntry(double, double, double, double, double, double, double)
Definition: TAPD.cc:42
double getPNCorrectionFactor(double val0, int gain)
Definition: TPNCor.cc:62
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
void computeShape(std::string namefile, TTree *)
double * getAdcWithoutPedestal()
Definition: TPNPulse.cc:89
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]
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
const std::string eventHeaderProducer_
Definition: TMem.h:7
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]
dictionary corr
const unsigned int _timingqualhigh
#define NCRYSEB
double getAmpl()
Definition: TPNFit.h:32
const std::string digiPNCollection_
const unsigned int _nsamples
unsigned int isFirstChanModFilled[22]
int towerId() const
get the tower id
double * getAdcWithoutPedestal()
Definition: TAPDPulse.cc:237
static int apdRefTower(int ilmmod)
Definition: MEEBGeom.cc:490
int channelId() const
so far for EndCap only :
#define NREFCHAN
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
const unsigned int _lastsamplePN
unsigned int _presample
const unsigned int _lastsample
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_
ii
Definition: cuy.py:589
std::map< unsigned int, unsigned int > channelMapEE
unsigned int iModule[1700]
const_iterator end() const
const std::string resdir_
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]
void setGeomEB(int etaG, int phiG, int module, int tower, int strip, int xtal, int apdRefTT, int channel, int lmr)
TTree * APDtrees[1700]
int stripId() const
get the tower id
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 iPnId() const
get the PnId
int IsThereDataADC[1700][nColor]
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
bool isValid() const
Definition: HandleBase.h:70
std::vector< double > getVals(int)
void set_const(int, int, int, int, int, double, double)
int xtalId() const
get the channel id
void setPresamples(int)
Definition: TAPDPulse.cc:251
HLT enums.
bool isPulseOK()
Definition: TAPDPulse.cc:162
const unsigned int _timingcuthigh
Definition: colors.py:1
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_
int iDCCId() const
get the DCCId
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
double getMean()
Definition: TMom.cc:121
static int lmr(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:254
const std::string _ecalPart
void setAPDoPNCut(double, double)
Definition: TAPD.cc:142
Definition: event.py:1
void setAPDoPN1Cut(double, double)
Definition: TAPD.cc:144