CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  val_max = val_max + bl - bl1;
430  for (k = 0; k < _nsamples; k++) {
431  yrange[k] = yrange[k] + bl - bl1;
432  }
433  }
434 
435  for (unsigned int k = 0; k < _nsamples; k++) {
436  adc[k] = yrange[k];
437  }
438 
439  pn0 = allPNAmpl[MyPn0];
440  pn1 = allPNAmpl[MyPn1];
441 
442  if (samplemax >= _timingcutlow && samplemax <= _timingcuthigh && lightside == side)
443  ADCtrees->Fill();
444  }
445 
446  } else {
447  for (EEDigiCollection::const_iterator digiItr = EEDigi->begin(); digiItr != EEDigi->end();
448  ++digiItr) { // Loop on crystals
449 
450  EEDetId id_crystal(digiItr->id());
451  EEDataFrame df(*digiItr);
452 
453  phi = id_crystal.ix() - 1;
454  eta = id_crystal.iy() - 1;
455  side = 0; // FIXME
456 
457  // Recover the TT id and the electronic crystal numbering from EcalElectronicsMapping
458 
459  EcalElectronicsId elecid_crystal = TheMapping.getElectronicsId(id_crystal);
460 
461  int towerID = elecid_crystal.towerId();
462  int channelID = elecid_crystal.channelId() - 1;
463 
464  int module = MEEEGeom::lmmod(phi, eta);
465 
466  std::pair<int, int> pnpair = MEEEGeom::pn(module, _fedid);
467  unsigned int MyPn0 = pnpair.first;
468  unsigned int MyPn1 = pnpair.second;
469 
470  unsigned int channel = MEEEGeom::crystal(phi, eta);
471  assert(channel < nCrys);
472 
473  double adcmax = 0.0;
474 
475  if (towerID != int(_tower) || channelID != int(_channel) || dccID != int(_fedid - 600))
476  continue;
477  else
478  channelNumber = channel;
479 
480  for (unsigned int i = 0; i < (*digiItr).size(); ++i) { // Loop on adc samples
481 
482  EcalMGPASample samp_crystal(df.sample(i));
483  adc[i] = samp_crystal.adc();
484  adcG[i] = samp_crystal.gainId();
485 
486  if (i == 0)
487  adcGain = adcG[i];
488  if (i > 0)
489  adcGain = TMath::Max(adcG[i], adcGain);
490 
491  if (adc[i] > adcmax) {
492  adcmax = adc[i];
493  }
494  }
495 
496  for (dsum = 0., dsum1 = 0., k = 0; k < _presample; k++) {
497  dsum += adc[k];
498  if (k < _presample - 1)
499  dsum1 += adc[k];
500  }
501 
502  bl = dsum / ((double)_presample);
503  bl1 = dsum1 / ((double)_presample - 1);
504 
505  for (val_max = 0., k = 0; k < _nsamples; k++) {
506  yrange[k] = adc[k] - bl;
507  if (yrange[k] > val_max) {
508  val_max = yrange[k];
509  samplemax = k;
510  }
511  }
512 
513  if (samplemax == 4 || samplemax == 5) {
514  val_max = val_max + bl - bl1;
515  for (k = 0; k < _nsamples; k++) {
516  yrange[k] = yrange[k] + bl - bl1;
517  }
518  }
519 
520  for (unsigned int k = 0; k < _nsamples; k++) {
521  adc[k] = yrange[k];
522  }
523 
524  pn0 = allPNAmpl[MyPn0];
525  pn1 = allPNAmpl[MyPn1];
526 
527  if (samplemax >= _timingcutlow && samplemax <= _timingcuthigh && lightside == side)
528  ADCtrees->Fill();
529  }
530  }
531 
532 } // analyze
533 
534 //========================================================================
536  //========================================================================
537 
538  assert(colors.size() <= nColor);
539  unsigned int nCol = colors.size();
540 
541  ADCtrees->Write();
542 
543  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
544  << "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
545  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
546  << "\t+=+ Analyzing laser data: getting per event +=+";
547  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
548  << "\t+=+ APD Amplitudes and ADC samples +=+";
549  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
550  << "\t+=+ for fed:" << _fedid << ", tower:" << _tower << ", and channel:" << _channel;
551 
552  // Define temporary tree to save APD amplitudes
553 
554  APDFile = new TFile(resfile.c_str(), "RECREATE");
555 
556  int ieta, iphi, channelID, towerID, flag;
557  double alpha, beta;
558 
559  colors.push_back(color);
560 
561  for (unsigned int i = 0; i < nCol; i++) {
562  stringstream name1;
563  name1 << "headerCol" << colors[i];
564 
565  header[i] = new TTree(name1.str().c_str(), name1.str().c_str());
566 
567  header[i]->Branch("alpha", &alpha, "alpha/D");
568  header[i]->Branch("beta", &beta, "beta/D");
569  header[i]->Branch("iphi", &iphi, "iphi/I");
570  header[i]->Branch("ieta", &ieta, "ieta/I");
571  header[i]->Branch("dccID", &dccID, "dccID/I");
572  header[i]->Branch("towerID", &towerID, "towerID/I");
573  header[i]->Branch("channelID", &channelID, "channelID/I");
574 
575  header[i]->SetBranchAddress("alpha", &alpha);
576  header[i]->SetBranchAddress("beta", &beta);
577  header[i]->SetBranchAddress("iphi", &iphi);
578  header[i]->SetBranchAddress("ieta", &ieta);
579  header[i]->SetBranchAddress("dccID", &dccID);
580  header[i]->SetBranchAddress("towerID", &towerID);
581  header[i]->SetBranchAddress("channelID", &channelID);
582  }
583 
584  stringstream name2;
585  name2 << "APDTree";
586  APDtrees = new TTree(name2.str().c_str(), name2.str().c_str());
587 
588  //List of branches
589 
590  APDtrees->Branch("event", &event, "event/I");
591  APDtrees->Branch("color", &color, "color/I");
592  APDtrees->Branch("adc", &adc, "adc[10]/D");
593  APDtrees->Branch("peakMatacq", &peak, "peak/D");
594  APDtrees->Branch("ttrigMatacq", &ttrig, "ttrig/D");
595  APDtrees->Branch("apdAmpl", &apdAmpl, "apdAmpl/D");
596  APDtrees->Branch("apdTime", &apdTime, "apdTime/D");
597  APDtrees->Branch("flag", &flag, "flag/I");
598  APDtrees->Branch("pn0", &pn0, "pn0/D");
599  APDtrees->Branch("pn1", &pn1, "pn1/D");
600 
601  APDtrees->SetBranchAddress("event", &event);
602  APDtrees->SetBranchAddress("color", &color);
603  APDtrees->SetBranchAddress("adc", adc);
604  APDtrees->SetBranchAddress("peakMatacq", &peak);
605  APDtrees->SetBranchAddress("ttrigMatacq", &ttrig);
606  APDtrees->SetBranchAddress("apdAmpl", &apdAmpl);
607  APDtrees->SetBranchAddress("apdTime", &apdTime);
608  APDtrees->SetBranchAddress("flag", &flag);
609  APDtrees->SetBranchAddress("pn0", &pn0);
610  APDtrees->SetBranchAddress("pn1", &pn1);
611 
612  // Retrieve alpha and beta for APD amplitudes calculation
613 
614  TFile* alphaFile = new TFile(refalphabeta_.c_str());
615  TTree* alphaTree[2];
616 
617  Double_t alphaRun, betaRun;
618  int ietaRun, iphiRun, channelIDRun, towerIDRun, dccIDRun, flagRun;
619 
620  for (unsigned int i = 0; i < nCol; i++) {
621  stringstream name3;
622  name3 << "ABCol" << i;
623  alphaTree[i] = (TTree*)alphaFile->Get(name3.str().c_str());
624  alphaTree[i]->SetBranchStatus("*", false);
625  alphaTree[i]->SetBranchStatus("alpha", true);
626  alphaTree[i]->SetBranchStatus("beta", true);
627  alphaTree[i]->SetBranchStatus("iphi", true);
628  alphaTree[i]->SetBranchStatus("ieta", true);
629  alphaTree[i]->SetBranchStatus("dccID", true);
630  alphaTree[i]->SetBranchStatus("towerID", true);
631  alphaTree[i]->SetBranchStatus("channelID", true);
632  alphaTree[i]->SetBranchStatus("flag", true);
633 
634  alphaTree[i]->SetBranchAddress("alpha", &alphaRun);
635  alphaTree[i]->SetBranchAddress("beta", &betaRun);
636  alphaTree[i]->SetBranchAddress("iphi", &iphiRun);
637  alphaTree[i]->SetBranchAddress("ieta", &ietaRun);
638  alphaTree[i]->SetBranchAddress("dccID", &dccIDRun);
639  alphaTree[i]->SetBranchAddress("towerID", &towerIDRun);
640  alphaTree[i]->SetBranchAddress("channelID", &channelIDRun);
641  alphaTree[i]->SetBranchAddress("flag", &flagRun);
642  }
643 
645 
646  double chi2;
647 
648  for (unsigned int icol = 0; icol < nCol; icol++) {
649  IsThereDataADC[icol] = 1;
650  stringstream cut;
651  cut << "color==" << colors.at(icol);
652  if (ADCtrees->GetEntries(cut.str().c_str()) < 10)
653  IsThereDataADC[icol] = 0;
654  IsHeaderFilled[icol] = 0;
655  }
656 
657  // Define submodule and channel number inside the submodule (as Patrice)
658 
659  Long64_t nbytes = 0, nb = 0;
660  for (Long64_t jentry = 0; jentry < ADCtrees->GetEntriesFast(); jentry++) { // Loop on events
661  nb = ADCtrees->GetEntry(jentry);
662  nbytes += nb;
663 
664  int iCry = channelNumber;
665 
666  // get back color
667 
668  unsigned int iCol = 0;
669  for (unsigned int i = 0; i < nCol; i++) {
670  if (color == colors[i]) {
671  iCol = i;
672  i = colors.size();
673  }
674  }
675 
676  alphaTree[iCol]->GetEntry(iCry);
677 
678  flag = flagRun;
679  iphi = iphiRun;
680  ieta = ietaRun;
681  towerID = towerIDRun;
682  channelID = channelIDRun;
683  alpha = alphaRun;
684  beta = betaRun;
685 
686  if (IsHeaderFilled[iCol] == 0) {
687  header[iCol]->Fill();
688  IsHeaderFilled[iCol] = 1;
689  }
690  // Amplitude calculation
691 
692  apdAmpl = 0;
693  apdTime = 0;
694 
695  pslsfit->init(_nsamples, _firstsample, _lastsample, _niter, alphaRun, betaRun);
696  chi2 = pslsfit->doFit(&adc[0]);
697 
698  if (chi2 < 0. || chi2 == 102 || chi2 == 101) {
699  apdAmpl = 0;
700  apdTime = 0;
701 
702  } else {
703  apdAmpl = pslsfit->getAmpl();
704  apdTime = pslsfit->getTime();
705  }
706 
707  APDtrees->Fill();
708  }
709 
710  alphaFile->Close();
711 
712  ADCFile->Close();
713 
714  APDFile->Write();
715  APDFile->Close();
716 
717  // Remove unwanted files
718 
719  stringstream del;
720  del << "rm " << ADCfile;
721  system(del.str().c_str());
722 
723  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
724  << "\t+=+ .................................................. done +=+";
725  edm::LogVerbatim("EcalPerEvtLaserAnalyzer")
726  << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
727 }
728 
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
float alpha
Definition: AMPTWrapper.h:105
const edm::EventSetup & c
static int crystal(CrysCoord ix, CrysCoord iy)
Definition: MEEEGeom.cc:372
int xtalId() const
get the channel id
edm::EDGetTokenT< EBDigiCollection > ebDigiToken_
int stripId() const
get the tower id
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#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
std::vector< T >::const_iterator const_iterator
const unsigned int _timingcuthigh
void init(int, int, int)
Definition: TPNFit.cc:24
tuple runType
Definition: runPedHist.py:37
int towerId() const
get the tower id
const_iterator begin() const
The iterator returned can not safely be used across threads.
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
bool getData(T &iHolder) const
Definition: EventSetup.h:128
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
const unsigned int _firstsamplePN
const std::string digiPNCollection_
bool isValid() const
Definition: HandleBase.h:70
static int lmmod(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:90
virtual void init(int, int, int, int, double, double)
const_iterator end() const
T Max(T a, T b)
Definition: MathUtil.h:44
static int side(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:105
EcalPerEvtLaserAnalyzer(const edm::ParameterSet &iConfig)
T const * product() const
Definition: Handle.h:70
virtual double doFit(double *)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
const_iterator end() const
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
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
int channelId() const
so far for EndCap only :
const_iterator begin() const
tuple module
Definition: callgraph.py:69
const edm::EDGetTokenT< EcalPnDiodeDigiCollection > pnDiodeDigiToken_