CMS 3D CMS Logo

EcalPerEvtLaserAnalyzer.cc
Go to the documentation of this file.
1 /*
2  * \class EcalPerEvtLaserAnalyzer
3  *
4  * primary author: Julie Malcles - CEA/Saclay
5  * author: Gautier Hamel De Monchenault - CEA/Saclay
6  */
7 
8 #include "TFile.h"
9 #include "TTree.h"
10 
12 
13 #include <sstream>
14 #include <iomanip>
15 #include <ctime>
16 
18 
21 
26 
29 
32 
33 using namespace std;
34 
35 //========================================================================
37  //========================================================================
38  : iEvent(0),
39  eventHeaderCollection_(iConfig.getParameter<std::string>("eventHeaderCollection")),
40  eventHeaderProducer_(iConfig.getParameter<std::string>("eventHeaderProducer")),
41  digiCollection_(iConfig.getParameter<std::string>("digiCollection")),
42  digiProducer_(iConfig.getParameter<std::string>("digiProducer")),
43  digiPNCollection_(iConfig.getParameter<std::string>("digiPNCollection")),
44  rawDataToken_(consumes<EcalRawDataCollection>(edm::InputTag(eventHeaderProducer_, eventHeaderCollection_))),
45  pnDiodeDigiToken_(consumes<EcalPnDiodeDigiCollection>(edm::InputTag(digiProducer_, digiPNCollection_))),
46  mappingToken_(esConsumes()),
47  // framework parameters with default values
48  _nsamples(iConfig.getUntrackedParameter<unsigned int>("nSamples", 10)),
49  _presample(iConfig.getUntrackedParameter<unsigned int>("nPresamples", 3)),
50  _firstsample(iConfig.getUntrackedParameter<unsigned int>("firstSample", 1)),
51  _lastsample(iConfig.getUntrackedParameter<unsigned int>("lastSample", 2)),
52  _nsamplesPN(iConfig.getUntrackedParameter<unsigned int>("nSamplesPN", 50)),
53  _presamplePN(iConfig.getUntrackedParameter<unsigned int>("nPresamplesPN", 6)),
54  _firstsamplePN(iConfig.getUntrackedParameter<unsigned int>("firstSamplePN", 7)),
55  _lastsamplePN(iConfig.getUntrackedParameter<unsigned int>("lastSamplePN", 8)),
56  _timingcutlow(iConfig.getUntrackedParameter<unsigned int>("timingCutLow", 3)),
57  _timingcuthigh(iConfig.getUntrackedParameter<unsigned int>("timingCutHigh", 7)),
58  _niter(iConfig.getUntrackedParameter<unsigned int>("nIter", 3)),
59  _fedid(iConfig.getUntrackedParameter<unsigned int>("fedID", 0)),
60  _tower(iConfig.getUntrackedParameter<unsigned int>("tower", 1)),
61  _channel(iConfig.getUntrackedParameter<unsigned int>("channel", 1)),
62  _ecalPart(iConfig.getUntrackedParameter<std::string>("ecalPart", "EB")),
63  resdir_(iConfig.getUntrackedParameter<std::string>("resDir")),
64  refalphabeta_(iConfig.getUntrackedParameter<std::string>("refAlphaBeta")),
65  nCrys(NCRYSEB),
66  IsFileCreated(0),
67  runType(-1),
68  runNum(0),
69  dccID(-1),
70  lightside(2),
71  doesRefFileExist(0),
72  ttMat(-1),
73  peakMat(-1),
74  peak(-1),
75  evtMat(-1),
76  colMat(-1)
77 //========================================================================
78 
79 {
80  if (_ecalPart == "EB") {
81  ebDigiToken_ = consumes<EBDigiCollection>(edm::InputTag(digiProducer_, digiCollection_));
82  } else if (_ecalPart == "EE") {
83  eeDigiToken_ = consumes<EEDigiCollection>(edm::InputTag(digiProducer_, digiCollection_));
84  }
85 
86  // Define geometrical constants
87  //
88  if (_ecalPart == "EB") {
89  nCrys = NCRYSEB;
90  } else {
91  nCrys = NCRYSEE;
92  }
93 }
94 
95 //========================================================================
97  //========================================================================
98 
99  // do anything here that needs to be done at desctruction time
100  // (e.g. close files, deallocate resources etc.)
101 }
102 
103 //========================================================================
105  //========================================================================
106 
107  // Define temporary files' names
108 
109  stringstream namefile1;
110  namefile1 << resdir_ << "/ADCSamples.root";
111 
112  ADCfile = namefile1.str();
113 
114  // Create temporary file and trees to save adc samples
115 
116  ADCFile = new TFile(ADCfile.c_str(), "RECREATE");
117 
118  stringstream name;
119  name << "ADCTree";
120 
121  ADCtrees = new TTree(name.str().c_str(), name.str().c_str());
122 
123  ADCtrees->Branch("iphi", &phi, "phi/I");
124  ADCtrees->Branch("ieta", &eta, "eta/I");
125  ADCtrees->Branch("dccID", &dccID, "dccID/I");
126  ADCtrees->Branch("event", &event, "event/I");
127  ADCtrees->Branch("color", &color, "color/I");
128  ADCtrees->Branch("adc", &adc, "adc[10]/D");
129  ADCtrees->Branch("ttrigMatacq", &ttrig, "ttrig/D");
130  ADCtrees->Branch("peakMatacq", &peak, "peak/D");
131  ADCtrees->Branch("pn0", &pn0, "pn0/D");
132  ADCtrees->Branch("pn1", &pn1, "pn1/D");
133 
134  ADCtrees->SetBranchAddress("ieta", &eta);
135  ADCtrees->SetBranchAddress("iphi", &phi);
136  ADCtrees->SetBranchAddress("dccID", &dccID);
137  ADCtrees->SetBranchAddress("event", &event);
138  ADCtrees->SetBranchAddress("color", &color);
139  ADCtrees->SetBranchAddress("adc", adc);
140  ADCtrees->SetBranchAddress("ttrigMatacq", &ttrig);
141  ADCtrees->SetBranchAddress("peakMatacq", &peak);
142  ADCtrees->SetBranchAddress("pn0", &pn0);
143  ADCtrees->SetBranchAddress("pn1", &pn1);
144 
145  IsFileCreated = 0;
146 }
147 
148 //========================================================================
150  //========================================================================
151 
152  ++iEvent;
153 
154  // retrieving DCC header
156  const EcalRawDataCollection* DCCHeader = nullptr;
157  e.getByToken(rawDataToken_, pDCCHeader);
158  if (!pDCCHeader.isValid()) {
159  edm::LogError("nodata") << "Error! can't get the product retrieving DCC header" << eventHeaderCollection_.c_str();
160  } else {
161  DCCHeader = pDCCHeader.product();
162  }
163 
164  // retrieving crystal data from Event
166  const EBDigiCollection* EBDigi = nullptr;
168  const EEDigiCollection* EEDigi = nullptr;
169  if (_ecalPart == "EB") {
170  e.getByToken(ebDigiToken_, pEBDigi);
171  if (!pEBDigi.isValid()) {
172  edm::LogError("nodata") << "Error! can't get the product retrieving EB crystal data " << digiCollection_.c_str();
173  } else {
174  EBDigi = pEBDigi.product();
175  }
176  } else {
177  e.getByToken(eeDigiToken_, pEEDigi);
178  if (!pEEDigi.isValid()) {
179  edm::LogError("nodata") << "Error! can't get the product retrieving EE crystal data " << digiCollection_.c_str();
180  } else {
181  EEDigi = pEEDigi.product();
182  }
183  }
184 
185  // retrieving crystal PN diodes from Event
187  const EcalPnDiodeDigiCollection* PNDigi = nullptr;
188  e.getByToken(pnDiodeDigiToken_, pPNDigi);
189  if (!pPNDigi.isValid()) {
190  edm::LogError("nodata") << "Error! can't get the product " << digiPNCollection_.c_str();
191  } else {
192  PNDigi = pPNDigi.product();
193  }
194 
195  // retrieving electronics mapping
196  const auto& TheMapping = c.getData(mappingToken_);
197 
198  // ====================================
199  // Decode Basic DCCHeader Information
200  // ====================================
201 
202  for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
203  ++headerItr) {
204  // Get run type and run number
205 
206  int fed = headerItr->fedId();
207 
208  if (fed != _fedid && _fedid != -999)
209  continue;
210 
211  runType = headerItr->getRunType();
212  runNum = headerItr->getRunNumber();
213  event = headerItr->getLV1();
214  dccID = headerItr->getDccInTCCCommand();
215  fedID = headerItr->fedId();
216 
217  // take event only if the fed corresponds to the DCC in TCC
218  if (600 + dccID != fedID)
219  continue;
220 
221  // Cut on runType
223  return;
224 
225  // Define output results files' names
226 
227  if (IsFileCreated == 0) {
228  stringstream namefile2;
229  namefile2 << resdir_ << "/APDAmpl_Run" << runNum << "_" << _fedid << "_" << _tower << "_" << _channel << ".root";
230  resfile = namefile2.str();
231 
232  // Get Matacq ttrig
233 
234  stringstream namefile;
235  namefile << resdir_ << "/Matacq-Run" << runNum << ".root";
236 
237  doesRefFileExist = 0;
238 
239  FILE* test;
240  test = fopen(namefile.str().c_str(), "r");
241  if (test)
242  doesRefFileExist = 1;
243 
244  if (doesRefFileExist == 1) {
245  matacqFile = new TFile((namefile.str().c_str()));
246  matacqTree = (TTree*)matacqFile->Get("MatacqShape");
247 
248  matacqTree->SetBranchAddress("event", &evtMat);
249  matacqTree->SetBranchAddress("color", &colMat);
250  matacqTree->SetBranchAddress("peak", &peakMat);
251  matacqTree->SetBranchAddress("ttrig", &ttMat);
252  }
253 
254  IsFileCreated = 1;
255  }
256 
257  // Retrieve laser color and event number
258 
259  EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
260  int color = settings.wavelength;
261 
262  vector<int>::iterator iter = find(colors.begin(), colors.end(), color);
263  if (iter == colors.end()) {
264  colors.push_back(color);
265  edm::LogVerbatim("EcalPerEvtLaserAnalyzer") << " new color found " << color << " " << colors.size();
266  }
267  }
268 
269  // cut on fedID
270 
271  if (fedID != _fedid && _fedid != -999)
272  return;
273 
274  // ======================
275  // Decode PN Information
276  // ======================
277 
278  TPNFit* pnfit = new TPNFit();
280 
281  double chi2pn = 0;
282  double ypnrange[50];
283  double dsum = 0.;
284  double dsum1 = 0.;
285  double bl = 0.;
286  double bl1 = 0.;
287  double val_max = 0.;
288  unsigned int samplemax = 0;
289  unsigned int k;
290 
291  std::vector<double> allPNAmpl;
292 
293  for (EcalPnDiodeDigiCollection::const_iterator pnItr = PNDigi->begin(); pnItr != PNDigi->end();
294  ++pnItr) { // Loop on PNs
295 
296  for (int samId = 0; samId < (*pnItr).size(); samId++) { // Loop on PN samples
297  pn[samId] = (*pnItr).sample(samId).adc();
298  }
299 
300  for (dsum = 0., k = 0; k < _presamplePN; k++) {
301  dsum += pn[k];
302  }
303  bl = dsum / ((double)_presamplePN);
304 
305  for (val_max = 0., k = 0; k < _nsamplesPN; k++) {
306  ypnrange[k] = pn[k] - bl;
307 
308  if (ypnrange[k] > val_max) {
309  val_max = ypnrange[k];
310  samplemax = k;
311  }
312  }
313 
314  chi2pn = pnfit->doFit(samplemax, &ypnrange[0]);
315 
316  if (chi2pn == 101 || chi2pn == 102 || chi2pn == 103)
317  pnAmpl = 0.;
318  else
319  pnAmpl = pnfit->getAmpl();
320 
321  allPNAmpl.push_back(pnAmpl);
322  }
323 
324  // ===========
325  // Get Matacq
326  // ===========
327 
328  ttrig = -1.;
329  peak = -1.;
330 
331  if (doesRefFileExist == 1) {
332  // FIXME
333  if (color == 0)
334  matacqTree->GetEntry(event - 1);
335  else if (color == 3)
336  matacqTree->GetEntry(matacqTree->GetEntries("color==0") + event - 1);
337  ttrig = ttMat;
338  peak = peakMat;
339  }
340 
341  // ===========================
342  // Decode EBDigis Information
343  // ===========================
344 
345  double yrange[10];
346  int adcGain = 0;
347  int side = 0;
348 
349  if (EBDigi) {
350  for (EBDigiCollection::const_iterator digiItr = EBDigi->begin(); digiItr != EBDigi->end();
351  ++digiItr) { // Loop on crystals
352 
353  EBDetId id_crystal(digiItr->id());
354  EBDataFrame df(*digiItr);
355 
356  int etaG = id_crystal.ieta(); // global
357  int phiG = id_crystal.iphi(); // global
358 
359  int etaL; // local
360  int phiL; // local
361  std::pair<int, int> LocalCoord = MEEBGeom::localCoord(etaG, phiG);
362 
363  etaL = LocalCoord.first;
364  phiL = LocalCoord.second;
365 
366  eta = etaG;
367  phi = phiG;
368 
369  side = MEEBGeom::side(etaG, phiG);
370 
371  EcalElectronicsId elecid_crystal = TheMapping.getElectronicsId(id_crystal);
372 
373  int towerID = elecid_crystal.towerId();
374  // int channelID=elecid_crystal.channelId()-1; // FIXME so far for endcap only
375  int strip = elecid_crystal.stripId();
376  int xtal = elecid_crystal.xtalId();
377  int channelID = 5 * (strip - 1) + xtal - 1; // FIXME
378 
379  int module = MEEBGeom::lmmod(etaG, phiG);
380 
381  std::pair<int, int> pnpair = MEEBGeom::pn(module);
382  unsigned int MyPn0 = pnpair.first;
383  unsigned int MyPn1 = pnpair.second;
384 
385  unsigned int channel = MEEBGeom::electronic_channel(etaL, phiL);
386  assert(channel < nCrys);
387 
388  double adcmax = 0.0;
389 
390  if (towerID != int(_tower) || channelID != int(_channel) || dccID != int(_fedid - 600))
391  continue;
392  else
393  channelNumber = channel;
394 
395  for (unsigned int i = 0; i < (*digiItr).size(); ++i) { // Loop on adc samples
396 
397  EcalMGPASample samp_crystal(df.sample(i));
398  adc[i] = samp_crystal.adc();
399  adcG[i] = samp_crystal.gainId();
400 
401  if (i == 0)
402  adcGain = adcG[i];
403  if (i > 0)
404  adcGain = TMath::Max(adcG[i], adcGain);
405 
406  if (adc[i] > adcmax) {
407  adcmax = adc[i];
408  }
409  }
410 
411  for (dsum = 0., dsum1 = 0., k = 0; k < _presample; k++) {
412  dsum += adc[k];
413  if (k < _presample - 1)
414  dsum1 += adc[k];
415  }
416 
417  bl = dsum / ((double)_presample);
418  bl1 = dsum1 / ((double)_presample - 1);
419 
420  for (val_max = 0., k = 0; k < _nsamples; k++) {
421  yrange[k] = adc[k] - bl;
422  if (yrange[k] > val_max) {
423  val_max = yrange[k];
424  samplemax = k;
425  }
426  }
427 
428  if (samplemax == 4 || samplemax == 5) {
429  for (k = 0; k < _nsamples; k++) {
430  yrange[k] = yrange[k] + bl - bl1;
431  }
432  }
433 
434  for (unsigned int k = 0; k < _nsamples; k++) {
435  adc[k] = yrange[k];
436  }
437 
438  pn0 = allPNAmpl[MyPn0];
439  pn1 = allPNAmpl[MyPn1];
440 
441  if (samplemax >= _timingcutlow && samplemax <= _timingcuthigh && lightside == side)
442  ADCtrees->Fill();
443  }
444 
445  } else {
446  for (EEDigiCollection::const_iterator digiItr = EEDigi->begin(); digiItr != EEDigi->end();
447  ++digiItr) { // Loop on crystals
448 
449  EEDetId id_crystal(digiItr->id());
450  EEDataFrame df(*digiItr);
451 
452  phi = id_crystal.ix() - 1;
453  eta = id_crystal.iy() - 1;
454  side = 0; // FIXME
455 
456  // Recover the TT id and the electronic crystal numbering from EcalElectronicsMapping
457 
458  EcalElectronicsId elecid_crystal = TheMapping.getElectronicsId(id_crystal);
459 
460  int towerID = elecid_crystal.towerId();
461  int channelID = elecid_crystal.channelId() - 1;
462 
463  int module = MEEEGeom::lmmod(phi, eta);
464 
465  std::pair<int, int> pnpair = MEEEGeom::pn(module, _fedid);
466  unsigned int MyPn0 = pnpair.first;
467  unsigned int MyPn1 = pnpair.second;
468 
469  unsigned int channel = MEEEGeom::crystal(phi, eta);
470  assert(channel < nCrys);
471 
472  double adcmax = 0.0;
473 
474  if (towerID != int(_tower) || channelID != int(_channel) || dccID != int(_fedid - 600))
475  continue;
476  else
477  channelNumber = channel;
478 
479  for (unsigned int i = 0; i < (*digiItr).size(); ++i) { // Loop on adc samples
480 
481  EcalMGPASample samp_crystal(df.sample(i));
482  adc[i] = samp_crystal.adc();
483  adcG[i] = samp_crystal.gainId();
484 
485  if (i == 0)
486  adcGain = adcG[i];
487  if (i > 0)
488  adcGain = TMath::Max(adcG[i], adcGain);
489 
490  if (adc[i] > adcmax) {
491  adcmax = adc[i];
492  }
493  }
494 
495  for (dsum = 0., dsum1 = 0., k = 0; k < _presample; k++) {
496  dsum += adc[k];
497  if (k < _presample - 1)
498  dsum1 += adc[k];
499  }
500 
501  bl = dsum / ((double)_presample);
502  bl1 = dsum1 / ((double)_presample - 1);
503 
504  for (val_max = 0., k = 0; k < _nsamples; k++) {
505  yrange[k] = adc[k] - bl;
506  if (yrange[k] > val_max) {
507  val_max = yrange[k];
508  samplemax = k;
509  }
510  }
511 
512  if (samplemax == 4 || samplemax == 5) {
513  for (k = 0; k < _nsamples; k++) {
514  yrange[k] = yrange[k] + bl - bl1;
515  }
516  }
517 
518  for (unsigned int k = 0; k < _nsamples; k++) {
519  adc[k] = yrange[k];
520  }
521 
522  pn0 = allPNAmpl[MyPn0];
523  pn1 = allPNAmpl[MyPn1];
524 
525  if (samplemax >= _timingcutlow && samplemax <= _timingcuthigh && lightside == side)
526  ADCtrees->Fill();
527  }
528  }
529 
530 } // analyze
531 
532 //========================================================================
534  //========================================================================
535 
536  assert(colors.size() <= nColor);
537  unsigned int nCol = colors.size();
538 
539  ADCtrees->Write();
540 
541  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
542  << "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
543  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
544  << "\t+=+ Analyzing laser data: getting per event +=+";
545  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
546  << "\t+=+ APD Amplitudes and ADC samples +=+";
547  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
548  << "\t+=+ for fed:" << _fedid << ", tower:" << _tower << ", and channel:" << _channel;
549 
550  // Define temporary tree to save APD amplitudes
551 
552  APDFile = new TFile(resfile.c_str(), "RECREATE");
553 
554  int ieta, iphi, channelID, towerID, flag;
555  double alpha, beta;
556 
557  colors.push_back(color);
558 
559  for (unsigned int i = 0; i < nCol; i++) {
560  stringstream name1;
561  name1 << "headerCol" << colors[i];
562 
563  header[i] = new TTree(name1.str().c_str(), name1.str().c_str());
564 
565  header[i]->Branch("alpha", &alpha, "alpha/D");
566  header[i]->Branch("beta", &beta, "beta/D");
567  header[i]->Branch("iphi", &iphi, "iphi/I");
568  header[i]->Branch("ieta", &ieta, "ieta/I");
569  header[i]->Branch("dccID", &dccID, "dccID/I");
570  header[i]->Branch("towerID", &towerID, "towerID/I");
571  header[i]->Branch("channelID", &channelID, "channelID/I");
572 
573  header[i]->SetBranchAddress("alpha", &alpha);
574  header[i]->SetBranchAddress("beta", &beta);
575  header[i]->SetBranchAddress("iphi", &iphi);
576  header[i]->SetBranchAddress("ieta", &ieta);
577  header[i]->SetBranchAddress("dccID", &dccID);
578  header[i]->SetBranchAddress("towerID", &towerID);
579  header[i]->SetBranchAddress("channelID", &channelID);
580  }
581 
582  stringstream name2;
583  name2 << "APDTree";
584  APDtrees = new TTree(name2.str().c_str(), name2.str().c_str());
585 
586  //List of branches
587 
588  APDtrees->Branch("event", &event, "event/I");
589  APDtrees->Branch("color", &color, "color/I");
590  APDtrees->Branch("adc", &adc, "adc[10]/D");
591  APDtrees->Branch("peakMatacq", &peak, "peak/D");
592  APDtrees->Branch("ttrigMatacq", &ttrig, "ttrig/D");
593  APDtrees->Branch("apdAmpl", &apdAmpl, "apdAmpl/D");
594  APDtrees->Branch("apdTime", &apdTime, "apdTime/D");
595  APDtrees->Branch("flag", &flag, "flag/I");
596  APDtrees->Branch("pn0", &pn0, "pn0/D");
597  APDtrees->Branch("pn1", &pn1, "pn1/D");
598 
599  APDtrees->SetBranchAddress("event", &event);
600  APDtrees->SetBranchAddress("color", &color);
601  APDtrees->SetBranchAddress("adc", adc);
602  APDtrees->SetBranchAddress("peakMatacq", &peak);
603  APDtrees->SetBranchAddress("ttrigMatacq", &ttrig);
604  APDtrees->SetBranchAddress("apdAmpl", &apdAmpl);
605  APDtrees->SetBranchAddress("apdTime", &apdTime);
606  APDtrees->SetBranchAddress("flag", &flag);
607  APDtrees->SetBranchAddress("pn0", &pn0);
608  APDtrees->SetBranchAddress("pn1", &pn1);
609 
610  // Retrieve alpha and beta for APD amplitudes calculation
611 
612  TFile* alphaFile = new TFile(refalphabeta_.c_str());
613  TTree* alphaTree[2];
614 
615  Double_t alphaRun, betaRun;
616  int ietaRun, iphiRun, channelIDRun, towerIDRun, dccIDRun, flagRun;
617 
618  for (unsigned int i = 0; i < nCol; i++) {
619  stringstream name3;
620  name3 << "ABCol" << i;
621  alphaTree[i] = (TTree*)alphaFile->Get(name3.str().c_str());
622  alphaTree[i]->SetBranchStatus("*", false);
623  alphaTree[i]->SetBranchStatus("alpha", true);
624  alphaTree[i]->SetBranchStatus("beta", true);
625  alphaTree[i]->SetBranchStatus("iphi", true);
626  alphaTree[i]->SetBranchStatus("ieta", true);
627  alphaTree[i]->SetBranchStatus("dccID", true);
628  alphaTree[i]->SetBranchStatus("towerID", true);
629  alphaTree[i]->SetBranchStatus("channelID", true);
630  alphaTree[i]->SetBranchStatus("flag", true);
631 
632  alphaTree[i]->SetBranchAddress("alpha", &alphaRun);
633  alphaTree[i]->SetBranchAddress("beta", &betaRun);
634  alphaTree[i]->SetBranchAddress("iphi", &iphiRun);
635  alphaTree[i]->SetBranchAddress("ieta", &ietaRun);
636  alphaTree[i]->SetBranchAddress("dccID", &dccIDRun);
637  alphaTree[i]->SetBranchAddress("towerID", &towerIDRun);
638  alphaTree[i]->SetBranchAddress("channelID", &channelIDRun);
639  alphaTree[i]->SetBranchAddress("flag", &flagRun);
640  }
641 
643 
644  double chi2;
645 
646  for (unsigned int icol = 0; icol < nCol; icol++) {
647  IsThereDataADC[icol] = 1;
648  stringstream cut;
649  cut << "color==" << colors.at(icol);
650  if (ADCtrees->GetEntries(cut.str().c_str()) < 10)
651  IsThereDataADC[icol] = 0;
652  IsHeaderFilled[icol] = 0;
653  }
654 
655  // Define submodule and channel number inside the submodule (as Patrice)
656 
657  Long64_t nbytes = 0, nb = 0;
658  for (Long64_t jentry = 0; jentry < ADCtrees->GetEntriesFast(); jentry++) { // Loop on events
659  nb = ADCtrees->GetEntry(jentry);
660  nbytes += nb;
661 
662  int iCry = channelNumber;
663 
664  // get back color
665 
666  unsigned int iCol = 0;
667  for (unsigned int i = 0; i < nCol; i++) {
668  if (color == colors[i]) {
669  iCol = i;
670  i = colors.size();
671  }
672  }
673 
674  alphaTree[iCol]->GetEntry(iCry);
675 
676  flag = flagRun;
677  iphi = iphiRun;
678  ieta = ietaRun;
679  towerID = towerIDRun;
680  channelID = channelIDRun;
681  alpha = alphaRun;
682  beta = betaRun;
683 
684  if (IsHeaderFilled[iCol] == 0) {
685  header[iCol]->Fill();
686  IsHeaderFilled[iCol] = 1;
687  }
688  // Amplitude calculation
689 
690  apdAmpl = 0;
691  apdTime = 0;
692 
693  pslsfit->init(_nsamples, _firstsample, _lastsample, _niter, alphaRun, betaRun);
694  chi2 = pslsfit->doFit(&adc[0]);
695 
696  if (chi2 < 0. || chi2 == 102 || chi2 == 101) {
697  apdAmpl = 0;
698  apdTime = 0;
699 
700  } else {
701  apdAmpl = pslsfit->getAmpl();
702  apdTime = pslsfit->getTime();
703  }
704 
705  APDtrees->Fill();
706  }
707 
708  alphaFile->Close();
709 
710  ADCFile->Close();
711 
712  APDFile->Write();
713  APDFile->Close();
714 
715  // Remove unwanted files
716 
717  stringstream del;
718  del << "rm " << ADCfile;
719  system(del.str().c_str());
720 
721  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
722  << "\t+=+ .................................................. done +=+";
723  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
724  << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
725 }
726 
const std::string eventHeaderCollection_
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
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
float alpha
Definition: AMPTWrapper.h:105
static int crystal(CrysCoord ix, CrysCoord iy)
Definition: MEEEGeom.cc:372
edm::EDGetTokenT< EBDigiCollection > ebDigiToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
#define NCRYSEE
T const * product() const
Definition: Handle.h:70
std::vector< T >::const_iterator const_iterator
const unsigned int _timingcuthigh
void init(int, int, int)
Definition: TPNFit.cc:24
Log< level::Error, false > LogError
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 analyze(const edm::Event &e, const edm::EventSetup &c) override
static std::pair< int, int > pn(int ilmmod)
Definition: MEEBGeom.cc:447
static std::pair< int, int > pn(int dee, int ilmod)
Definition: MEEEGeom.cc:574
int iEvent
Definition: GenABIO.cc:224
static int electronic_channel(EBLocalCoord ix, EBLocalCoord iy)
Definition: MEEBGeom.cc:326
#define NCRYSEB
double getAmpl()
Definition: TPNFit.h:32
const unsigned int _timingcutlow
int towerId() const
get the tower id
const unsigned int _firstsamplePN
int channelId() const
so far for EndCap only :
const std::string digiPNCollection_
const_iterator begin() const
static int lmmod(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:90
virtual void init(int, int, int, int, double, double)
const_iterator end() const
static int side(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:105
EcalPerEvtLaserAnalyzer(const edm::ParameterSet &iConfig)
int stripId() const
get the tower id
virtual double doFit(double *)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
bool isValid() const
Definition: HandleBase.h:70
int xtalId() const
get the channel id
HLT enums.
Definition: colors.py:1
edm::EDGetTokenT< EEDigiCollection > eeDigiToken_
const edm::EDGetTokenT< EcalRawDataCollection > rawDataToken_
Definition: TPNFit.h:6
double doFit(int, double *)
Definition: TPNFit.cc:39
EcalLogicID towerID(EcalElectronicsId const &)
const edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > mappingToken_
const unsigned int _lastsamplePN
Definition: event.py:1
const edm::EDGetTokenT< EcalPnDiodeDigiCollection > pnDiodeDigiToken_