CMS 3D CMS Logo

EcalMatacqAnalyzer.cc
Go to the documentation of this file.
1 /*
2  * \class EcalMatacqAnalyzer
3  *
4  * primary author: Gautier Hamel De Monchenault - CEA/Saclay
5  * author: Julie Malcles - CEA/Saclay
6  */
7 
8 #include <TFile.h>
9 #include <TTree.h>
10 #include <TProfile.h>
11 #include <TChain.h>
12 #include <vector>
13 
15 
16 #include <sstream>
17 #include <iostream>
18 #include <iomanip>
19 
22 
24 
28 
32 
33 //========================================================================
35  //========================================================================
36  :
37 
38  iEvent(0),
39 
40  // framework parameters with default values
41 
42  _presample(iConfig.getUntrackedParameter<double>("nPresamples", 6.7)),
43  _nsamplesaftmax(iConfig.getUntrackedParameter<unsigned int>("nSamplesAftMax", 80)),
44  _noiseCut(iConfig.getUntrackedParameter<unsigned int>("noiseCut", 7)),
45  _parabnbefmax(iConfig.getUntrackedParameter<unsigned int>("paraBeforeMax", 8)),
46  _parabnaftmax(iConfig.getUntrackedParameter<unsigned int>("paraAfterMax", 7)),
47  _thres(iConfig.getUntrackedParameter<unsigned int>("threshold", 10)),
48  _lowlev(iConfig.getUntrackedParameter<unsigned int>("lowLevel", 20)),
49  _highlev(iConfig.getUntrackedParameter<unsigned int>("highLevel", 80)),
50  _nevlasers(iConfig.getUntrackedParameter<unsigned int>("nEventLaser", 600)),
51  _timebefmax(iConfig.getUntrackedParameter<unsigned int>("timeBefMax", 100)),
52  _timeaftmax(iConfig.getUntrackedParameter<unsigned int>("timeAftMax", 250)),
53  _cutwindow(iConfig.getUntrackedParameter<double>("cutWindow", 0.1)),
54  _nsamplesshape(iConfig.getUntrackedParameter<unsigned int>("nSamplesShape", 250)),
55  _presampleshape(iConfig.getUntrackedParameter<unsigned int>("nPresamplesShape", 50)),
56  _slide(iConfig.getUntrackedParameter<unsigned int>("nSlide", 100)),
57  _fedid(iConfig.getUntrackedParameter<int>("fedID", -999)),
58  _debug(iConfig.getUntrackedParameter<int>("debug", 0)),
59  resdir_(iConfig.getUntrackedParameter<std::string>("resDir")),
60  digiCollection_(iConfig.getParameter<std::string>("digiCollection")),
61  digiProducer_(iConfig.getParameter<std::string>("digiProducer")),
62  eventHeaderCollection_(iConfig.getParameter<std::string>("eventHeaderCollection")),
63  eventHeaderProducer_(iConfig.getParameter<std::string>("eventHeaderProducer")),
64  pmatToken_(consumes<EcalMatacqDigiCollection>(edm::InputTag(digiProducer_, digiCollection_))),
65  dccToken_(consumes<EcalRawDataCollection>(edm::InputTag(eventHeaderProducer_, eventHeaderCollection_))),
66  nSides(NSIDES),
67  lightside(0),
68  runType(-1),
69  runNum(0),
70  event(0),
71  color(-1),
72  maxsamp(0),
73  nsamples(0),
74  tt(0)
75 
76 //========================================================================
77 {
78  //now do what ever initialization is needed
79 }
80 
81 //========================================================================
83  //========================================================================
84 
85  // Define temporary file name
86 
87  sampfile = resdir_;
88  sampfile += "/TmpTreeMatacqAnalyzer.root";
89 
90  sampFile = new TFile(sampfile.c_str(), "RECREATE");
91 
92  // declaration of the tree to fill
93 
94  tree = new TTree("MatacqTree", "MatacqTree");
95 
96  //List of branches
97 
98  tree->Branch("event", &event, "event/I");
99  tree->Branch("color", &color, "color/I");
100  tree->Branch("matacq", &matacq, "matacq[2560]/D");
101  tree->Branch("nsamples", &nsamples, "nsamples/I");
102  tree->Branch("maxsamp", &maxsamp, "maxsamp/I");
103  tree->Branch("tt", &tt, "tt/D");
104  tree->Branch("lightside", &lightside, "lightside/I");
105 
106  tree->SetBranchAddress("event", &event);
107  tree->SetBranchAddress("color", &color);
108  tree->SetBranchAddress("matacq", matacq);
109  tree->SetBranchAddress("nsamples", &nsamples);
110  tree->SetBranchAddress("maxsamp", &maxsamp);
111  tree->SetBranchAddress("tt", &tt);
112  tree->SetBranchAddress("lightside", &lightside);
113 
114  // Define output results files' names
115 
116  std::stringstream namefile;
117  namefile << resdir_ << "/MATACQ.root";
118  outfile = namefile.str();
119 
120  // Laser events counter
121  laserEvents = 0;
122  isThereMatacq = false;
123 }
124 
125 //========================================================================
127  //========================================================================
128 
129  ++iEvent;
130 
131  if (_debug == 1)
132  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- Entering Analyze -- event= " << iEvent;
133 
134  // retrieving MATACQ :
135  const edm::Handle<EcalMatacqDigiCollection>& pmatacqDigi = e.getHandle(pmatToken_);
136  const EcalMatacqDigiCollection* matacqDigi = (pmatacqDigi.isValid()) ? pmatacqDigi.product() : nullptr;
137  if (pmatacqDigi.isValid()) {
138  if (_debug == 1)
139  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- Matacq Digis Found -- ";
140  } else {
141  edm::LogError("EcalMatacqAnalyzzer") << "Error! can't get the product EcalMatacqDigi producer:"
142  << digiProducer_.c_str() << " collection:" << digiCollection_.c_str();
143  return;
144  }
145 
146  // retrieving DCC header
147 
148  const edm::Handle<EcalRawDataCollection>& pDCCHeader = e.getHandle(dccToken_);
149  const EcalRawDataCollection* DCCHeader = (pDCCHeader.isValid()) ? pDCCHeader.product() : nullptr;
150  if (!pDCCHeader.isValid()) {
151  edm::LogError("EcalMatacqAnalyzzer") << "Error! can't get the product EcalRawData producer:"
152  << eventHeaderProducer_.c_str()
153  << " collection:" << eventHeaderCollection_.c_str();
154  return;
155  }
156 
157  // ====================================
158  // Decode Basic DCCHeader Information
159  // ====================================
160 
161  if (_debug == 1)
162  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- Before header -- ";
163 
164  for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
165  ++headerItr) {
166  EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
167  color = (int)settings.wavelength;
168  if (color < 0)
169  return;
170 
171  // Get run type and run number
172 
173  int fed = headerItr->fedId();
174 
175  if (fed != _fedid && _fedid != -999)
176  continue;
177 
178  runType = headerItr->getRunType();
179  runNum = headerItr->getRunNumber();
180  event = headerItr->getLV1();
181 
182  if (_debug == 1)
183  edm::LogVerbatim("EcalMatacqAnalyzzer")
184  << "-- debug test -- runtype:" << runType << " event:" << event << " runNum:" << runNum;
185 
186  dccID = headerItr->getDccInTCCCommand();
187  fedID = headerItr->fedId();
188  lightside = headerItr->getRtHalf();
189 
190  //assert (lightside<2 && lightside>=0);
191 
192  if (lightside != 1 && lightside != 0) {
193  edm::LogVerbatim("EcalMatacqAnalyzzer") << "Unexpected lightside: " << lightside << " for event " << iEvent;
194  return;
195  }
196  if (_debug == 1) {
197  edm::LogVerbatim("EcalMatacqAnalyzzer")
198  << "-- debug test -- Inside header before fed cut -- color=" << color << ", dcc=" << dccID
199  << ", fed=" << fedID << ", lightside=" << lightside << ", runType=" << runType;
200  }
201 
202  // take event only if the fed corresponds to the DCC in TCC
203  if (600 + dccID != fedID)
204  continue;
205 
206  if (_debug == 1) {
207  edm::LogVerbatim("EcalMatacqAnalyzzer")
208  << "-- debug test -- Inside header after fed cut -- color=" << color << ", dcc=" << dccID << ", fed=" << fedID
209  << ", lightside=" << lightside << ", runType=" << runType;
210  }
211 
212  // Cut on runType
213 
216  return;
217 
218  std::vector<int>::iterator iter = find(colors.begin(), colors.end(), color);
219  if (iter == colors.end()) {
220  colors.push_back(color);
221  edm::LogVerbatim("EcalMatacqAnalyzzer") << " new color found " << color << " " << colors.size();
222  }
223  }
224 
225  if (_debug == 1)
226  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- Before digis -- Event:" << iEvent;
227 
228  // Count laser events
229  laserEvents++;
230 
231  // ===========================
232  // Decode Matacq Information
233  // ===========================
234 
235  int iCh = 0;
236  double max = 0;
237 
238  for (EcalMatacqDigiCollection::const_iterator it = matacqDigi->begin(); it != matacqDigi->end();
239  ++it) { // Loop on matacq channel
240 
241  //
242  const EcalMatacqDigi& digis = *it;
243 
244  //if(digis.size()==0 || iCh>=N_channels) continue;
245  if (_debug == 1) {
246  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- Inside digis -- digi size=" << digis.size();
247  }
248 
249  if (digis.size() == 0)
250  continue;
251  else
252  isThereMatacq = true;
253 
254  max = 0;
255  maxsamp = 0;
256  nsamples = digis.size();
257  tt = digis.tTrig();
258 
259  for (int i = 0; i < digis.size(); ++i) { // Loop on matacq samples
260  matacq[i] = -digis.adcCount(i);
261  if (matacq[i] > max) {
262  max = matacq[i];
263  maxsamp = i;
264  }
265  }
266  if (_debug == 1) {
267  edm::LogVerbatim("EcalMatacqAnalyzzer")
268  << "-- debug test -- Inside digis -- nsamples=" << nsamples << ", max=" << max;
269  }
270 
271  iCh++;
272  }
273 
274  if (_debug == 1)
275  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- After digis -- Event: " << iEvent;
276  tree->Fill();
277 
278 } // analyze
279 
280 //========================================================================
282  // Don't do anything if there is no events
283  if (!isThereMatacq) {
284  edm::LogVerbatim("EcalMatacqAnalyzzer") << "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
285  edm::LogVerbatim("EcalMatacqAnalyzzer") << "\t+=+ WARNING! NO MATACQ +=+";
286  edm::LogVerbatim("EcalMatacqAnalyzzer") << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
287 
288  // Remove temporary file
289  FILE* test;
290  test = fopen(sampfile.c_str(), "r");
291  if (test) {
292  std::stringstream del2;
293  del2 << "rm " << sampfile;
294  system(del2.str().c_str());
295  }
296  return;
297  }
298 
299  assert(colors.size() <= nColor);
300  unsigned int nCol = colors.size();
301 
302  for (unsigned int iCol = 0; iCol < nCol; iCol++) {
303  for (unsigned int iSide = 0; iSide < nSide; iSide++) {
304  MTQ[iCol][iSide] = new TMTQ();
305  }
306  }
307 
308  outFile = new TFile(outfile.c_str(), "RECREATE");
309 
310  TProfile* shapeMat = new TProfile("shapeLaser", "shapeLaser", _nsamplesshape, -0.5, double(_nsamplesshape) - 0.5);
311  TProfile* shapeMatTmp = new TProfile(
312  "shapeLaserTmp", "shapeLaserTmp", _timeaftmax + _timebefmax, -0.5, double(_timeaftmax + _timebefmax) - 0.5);
313 
314  edm::LogVerbatim("EcalMatacqAnalyzzer") << "\n\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
315  edm::LogVerbatim("EcalMatacqAnalyzzer") << "\t+=+ Analyzing MATACQ data +=+";
316 
317  //
318  // create output ntuple
319  //
320 
321  mtqShape = new TTree("MatacqShape", "MatacqShape");
322 
323  // list of branches
324  // keep Patrice's notations
325 
326  mtqShape->Branch("event", &event, "event/I");
327  mtqShape->Branch("color", &color, "color/I");
328  mtqShape->Branch("status", &status, "status/I");
329  mtqShape->Branch("peak", &peak, "peak/D");
330  mtqShape->Branch("sigma", &sigma, "sigma/D");
331  mtqShape->Branch("fit", &fit, "fit/D");
332  mtqShape->Branch("ampl", &ampl, "ampl/D");
333  mtqShape->Branch("trise", &trise, "trise/D");
334  mtqShape->Branch("fwhm", &fwhm, "fwhm/D");
335  mtqShape->Branch("fw20", &fw20, "fw20/D");
336  mtqShape->Branch("fw80", &fw80, "fw80/D");
337  mtqShape->Branch("ped", &ped, "ped/D");
338  mtqShape->Branch("pedsig", &pedsig, "pedsig/D");
339  mtqShape->Branch("ttrig", &ttrig, "ttrig/D");
340  mtqShape->Branch("sliding", &sliding, "sliding/D");
341 
342  mtqShape->SetBranchAddress("event", &event);
343  mtqShape->SetBranchAddress("color", &color);
344  mtqShape->SetBranchAddress("status", &status);
345  mtqShape->SetBranchAddress("peak", &peak);
346  mtqShape->SetBranchAddress("sigma", &sigma);
347  mtqShape->SetBranchAddress("fit", &fit);
348  mtqShape->SetBranchAddress("ampl", &ampl);
349  mtqShape->SetBranchAddress("fwhm", &fwhm);
350  mtqShape->SetBranchAddress("fw20", &fw20);
351  mtqShape->SetBranchAddress("fw80", &fw80);
352  mtqShape->SetBranchAddress("trise", &trise);
353  mtqShape->SetBranchAddress("ped", &ped);
354  mtqShape->SetBranchAddress("pedsig", &pedsig);
355  mtqShape->SetBranchAddress("ttrig", &ttrig);
356  mtqShape->SetBranchAddress("sliding", &sliding);
357 
358  unsigned int endsample;
359  unsigned int presample;
360 
361  // loop over the entries of the tree
362  TChain* fChain = (TChain*)tree;
363  Long64_t nentries = fChain->GetEntriesFast();
364  Long64_t nbytes = 0, nb = 0;
365 
366  for (Long64_t jentry = 0; jentry < nentries; jentry++) {
367  // load the event
368  Long64_t ientry = fChain->LoadTree(jentry);
369  if (ientry < 0)
370  break;
371  nb = fChain->GetEntry(jentry);
372  nbytes += nb;
373 
374  status = 0;
375  peak = -1;
376  sigma = 0;
377  fit = -1;
378  ampl = -1;
379  trise = -1;
380  ttrig = tt;
381  fwhm = 0;
382  fw20 = 0;
383  fw80 = 0;
384  ped = 0;
385  pedsig = 0;
386  sliding = 0;
387 
388  if (_debug == 1)
389  edm::LogVerbatim("EcalMatacqAnalyzzer")
390  << "-- debug test -- inside loop 1 -- jentry:" << jentry << " over nentries=" << nentries;
391 
392  // create the object for Matacq data analysis
393 
394  endsample = maxsamp + _nsamplesaftmax;
395  presample = int(_presample * nsamples / 100.);
396  TMatacq* mtq = new TMatacq(nsamples,
397  presample,
398  endsample,
399  _noiseCut,
402  _thres,
403  _lowlev,
404  _highlev,
405  _nevlasers,
406  _slide);
407 
408  if (_debug == 1)
409  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- inside loop 2 -- ";
410 
411  // analyse the Matacq data
412  if (mtq->rawPulseAnalysis(nsamples, &matacq[0]) == 0) {
413  status = 1;
414  ped = mtq->getBaseLine();
415  pedsig = mtq->getsigBaseLine();
416 
417  if (_debug == 1)
418  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- inside loop 3 -- ped:" << ped;
419  if (mtq->findPeak() == 0) {
420  peak = mtq->getTimpeak();
421  sigma = mtq->getsigTimpeak();
422  }
423  if (_debug == 1)
424  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- inside loop 4 -- peak:" << peak;
425  if (mtq->doFit() == 0) {
426  fit = mtq->getTimax();
427  ampl = mtq->getAmpl();
428  fwhm = mtq->getFwhm();
429  fw20 = mtq->getWidth20();
430  fw80 = mtq->getWidth80();
431  sliding = mtq->getSlide();
432  }
433  if (_debug == 1)
434  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- inside loop 4 -- ampl:" << ampl;
435  if (mtq->compute_trise() == 0) {
436  trise = mtq->getTrise();
437  }
438  if (_debug == 1)
439  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- inside loop 5 -- trise:" << trise;
440  }
441 
442  if (_debug == 1)
443  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- inside loop 6 -- status:" << status;
444 
445  if (status == 1 && mtq->findPeak() == 0) {
446  int firstS = int(peak - double(_timebefmax));
447  int lastS = int(peak + double(_timeaftmax));
448 
449  // Fill histo if there are enough samples
450  if (_debug == 1)
451  edm::LogVerbatim("EcalMatacqAnalyzzer")
452  << "-- debug test -- inside loop 7 -- firstS:" << firstS << ", nsamples:" << nsamples;
453 
454  if (firstS >= 0 && lastS <= nsamples) {
455  for (int i = firstS; i < lastS; i++) {
456  shapeMatTmp->Fill(double(i) - firstS, matacq[i]);
457  }
458 
459  } else { // else extrapolate
460 
461  int firstSBis;
462 
463  if (firstS < 0) { // fill first bins with 0
464 
465  double thisped;
466  thisped = (matacq[0] + matacq[1] + matacq[2] + matacq[4] + matacq[5]) / 5.0;
467 
468  for (int i = firstS; i < 0; i++) {
469  shapeMatTmp->Fill(double(i) - firstS, thisped);
470  }
471  firstSBis = 0;
472 
473  } else {
474  firstSBis = firstS;
475  }
476 
477  if (lastS > nsamples) {
478  for (int i = firstSBis; i < int(nsamples); i++) {
479  shapeMatTmp->Fill(double(i) - firstS, matacq[i]);
480  }
481 
482  //extrapolate with expo tail
483 
484  double expb = 0.998;
485  double matacqval = expb * matacq[nsamples - 1];
486 
487  for (int i = nsamples; i < lastS; i++) {
488  shapeMatTmp->Fill(double(i) - firstS, matacqval);
489  matacqval *= expb;
490  }
491 
492  } else {
493  for (int i = firstSBis; i < lastS; i++) {
494  shapeMatTmp->Fill(double(i) - firstS, matacq[i]);
495  }
496  }
497  }
498  }
499  if (_debug == 1)
500  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- inside loop 8";
501 
502  // get back color
503 
504  int iCol = nCol;
505  for (unsigned int i = 0; i < nCol; i++) {
506  if (color == colors[i]) {
507  iCol = i;
508  i = nCol;
509  }
510  }
511  if (_debug == 1)
512  edm::LogVerbatim("EcalMatacqAnalyzzer")
513  << "-- debug test -- inside loop 8bis color:" << color << " iCol:" << iCol << " nCol:" << nCol;
514 
515  // fill TMTQ
516 
517  if (status == 1 && mtq->findPeak() == 0 && mtq->doFit() == 0 && mtq->compute_trise() == 0)
518  MTQ[iCol][lightside]->addEntry(peak, sigma, fit, ampl, trise, fwhm, fw20, fw80, ped, pedsig, sliding);
519 
520  // fill the output tree
521 
522  if (_debug == 1)
523  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- inside loop 9";
524  mtqShape->Fill();
525 
526  // clean up
527  delete mtq;
528  }
529 
530  if (_debug == 1)
531  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- after loop ";
532  sampFile->Close();
533 
534  double Peak[6], Sigma[6], Fit[6], Ampl[6], Trise[6], Fwhm[6], Fw20[6], Fw80[6], Ped[6], Pedsig[6], Sliding[6];
535  int Side;
536 
537  for (unsigned int iColor = 0; iColor < nCol; iColor++) {
538  std::stringstream nametree;
539  nametree << "MatacqCol" << colors[iColor];
540  meanTree[iColor] = new TTree(nametree.str().c_str(), nametree.str().c_str());
541  meanTree[iColor]->Branch("side", &Side, "Side/I");
542  meanTree[iColor]->Branch("peak", &Peak, "Peak[6]/D");
543  meanTree[iColor]->Branch("sigma", &Sigma, "Sigma[6]/D");
544  meanTree[iColor]->Branch("fit", &Fit, "Fit[6]/D");
545  meanTree[iColor]->Branch("ampl", &Ampl, "Ampl[6]/D");
546  meanTree[iColor]->Branch("trise", &Trise, "Trise[6]/D");
547  meanTree[iColor]->Branch("fwhm", &Fwhm, "Fwhm[6]/D");
548  meanTree[iColor]->Branch("fw20", &Fw20, "Fw20[6]/D");
549  meanTree[iColor]->Branch("fw80", &Fw80, "Fw80[6]/D");
550  meanTree[iColor]->Branch("ped", &Ped, "Ped[6]/D");
551  meanTree[iColor]->Branch("pedsig", &Pedsig, "Pedsig[6]/D");
552  meanTree[iColor]->Branch("sliding", &Sliding, "Sliding[6]/D");
553 
554  meanTree[iColor]->SetBranchAddress("side", &Side);
555  meanTree[iColor]->SetBranchAddress("peak", Peak);
556  meanTree[iColor]->SetBranchAddress("sigma", Sigma);
557  meanTree[iColor]->SetBranchAddress("fit", Fit);
558  meanTree[iColor]->SetBranchAddress("ampl", Ampl);
559  meanTree[iColor]->SetBranchAddress("fwhm", Fwhm);
560  meanTree[iColor]->SetBranchAddress("fw20", Fw20);
561  meanTree[iColor]->SetBranchAddress("fw80", Fw80);
562  meanTree[iColor]->SetBranchAddress("trise", Trise);
563  meanTree[iColor]->SetBranchAddress("ped", Ped);
564  meanTree[iColor]->SetBranchAddress("pedsig", Pedsig);
565  meanTree[iColor]->SetBranchAddress("sliding", Sliding);
566  }
567 
568  for (unsigned int iCol = 0; iCol < nCol; iCol++) {
569  for (unsigned int iSide = 0; iSide < nSides; iSide++) {
570  Side = iSide;
571  std::vector<double> val[TMTQ::nOutVar];
572 
573  for (int iVar = 0; iVar < TMTQ::nOutVar; iVar++) {
574  val[iVar] = MTQ[iCol][iSide]->get(iVar);
575 
576  for (unsigned int i = 0; i < val[iVar].size(); i++) {
577  switch (iVar) {
578  case TMTQ::iPeak:
579  Peak[i] = val[iVar].at(i);
580  break;
581  case TMTQ::iSigma:
582  Sigma[i] = val[iVar].at(i);
583  break;
584  case TMTQ::iFit:
585  Fit[i] = val[iVar].at(i);
586  break;
587  case TMTQ::iAmpl:
588  Ampl[i] = val[iVar].at(i);
589  break;
590  case TMTQ::iFwhm:
591  Fwhm[i] = val[iVar].at(i);
592  break;
593  case TMTQ::iFw20:
594  Fw20[i] = val[iVar].at(i);
595  break;
596  case TMTQ::iFw80:
597  Fw80[i] = val[iVar].at(i);
598  break;
599  case TMTQ::iTrise:
600  Trise[i] = val[iVar].at(i);
601  break;
602  case TMTQ::iPed:
603  Ped[i] = val[iVar].at(i);
604  break;
605  case TMTQ::iPedsig:
606  Pedsig[i] = val[iVar].at(i);
607  break;
608  case TMTQ::iSlide:
609  Sliding[i] = val[iVar].at(i);
610  break;
611  }
612  }
613  }
614  meanTree[iCol]->Fill();
615  if (_debug == 1)
616  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- inside final loop ";
617  }
618  }
619 
620  // Calculate maximum with pol 2
621 
622  int im = shapeMatTmp->GetMaximumBin();
623  double q1 = shapeMatTmp->GetBinContent(im - 1);
624  double q2 = shapeMatTmp->GetBinContent(im);
625  double q3 = shapeMatTmp->GetBinContent(im + 1);
626 
627  double a2 = (q3 + q1) / 2.0 - q2;
628  double a1 = q2 - q1 + a2 * (1 - 2 * im);
629  double a0 = q2 - a1 * im - a2 * im * im;
630 
631  double am = a0 - a1 * a1 / (4 * a2);
632 
633  // Compute pedestal
634 
635  double bl = 0;
636  for (unsigned int i = 1; i < _presampleshape + 1; i++) {
637  bl += shapeMatTmp->GetBinContent(i);
638  }
639  bl /= _presampleshape;
640 
641  // Compute and save laser shape
642 
643  if (_debug == 1)
644  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- computing shape ";
645 
646  int firstBin = 0;
647  double height = 0.0;
648 
649  for (unsigned int i = _timebefmax; i > _presampleshape; i--) {
650  height = shapeMatTmp->GetBinContent(i) - bl;
651 
652  if (height < (am - bl) * _cutwindow) {
653  firstBin = i;
654  i = _presampleshape;
655  }
656  }
657 
658  unsigned int lastBin = firstBin + _nsamplesshape;
659 
660  for (unsigned int i = firstBin; i < lastBin; i++) {
661  shapeMat->Fill(i - firstBin, shapeMatTmp->GetBinContent(i) - bl);
662  }
663 
664  mtqShape->Write();
665  for (unsigned int iColor = 0; iColor < nCol; iColor++) {
666  meanTree[iColor]->Write();
667  }
668  if (_debug == 1)
669  edm::LogVerbatim("EcalMatacqAnalyzzer") << "-- debug test -- writing ";
670  shapeMat->Write();
671 
672  // close the output file
673  outFile->Close();
674 
675  // Remove temporary file
676  FILE* test;
677  test = fopen(sampfile.c_str(), "r");
678  if (test) {
679  std::stringstream del2;
680  del2 << "rm " << sampfile;
681  system(del2.str().c_str());
682  }
683 
684  edm::LogVerbatim("EcalMatacqAnalyzzer") << "\t+=+ .................... done +=+";
685  edm::LogVerbatim("EcalMatacqAnalyzzer") << "\t+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+";
686 }
687 
double getWidth80()
Definition: TMatacq.h:74
Log< level::Info, true > LogVerbatim
Definition: TMTQ.h:8
const unsigned int _timeaftmax
const unsigned int _thres
#define NSIDES
EcalMatacqAnalyzer(const edm::ParameterSet &iConfig)
const unsigned int _slide
void beginJob() override
const unsigned int _lowlev
const std::string digiCollection_
T const * product() const
Definition: Handle.h:70
const unsigned int _presampleshape
std::vector< T >::const_iterator const_iterator
int compute_trise()
Definition: TMatacq.cc:347
double getTimax()
Definition: TMatacq.h:69
TMTQ * MTQ[nColor][nSide]
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)
double getBaseLine()
Definition: TMatacq.h:62
const std::string resdir_
double getsigBaseLine()
Definition: TMatacq.h:63
float adcCount(const int &i) const
const std::string eventHeaderCollection_
double getFwhm()
Definition: TMatacq.h:72
TTree * meanTree[nColor]
double getsigTimpeak()
Definition: TMatacq.h:66
int iEvent
Definition: GenABIO.cc:224
Definition: TTTypes.h:54
void analyze(const edm::Event &e, const edm::EventSetup &c) override
const unsigned int _nevlasers
double getSlide()
Definition: TMatacq.h:75
Definition: Fit.h:32
std::vector< double > get(int)
Definition: TMTQ.cc:69
int doFit()
Definition: TMatacq.cc:213
double getAmpl()
Definition: TMatacq.h:68
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
int rawPulseAnalysis(Int_t, Double_t *)
Definition: TMatacq.cc:57
float tTrig() const
const unsigned int _timebefmax
const_iterator end() const
const std::string eventHeaderProducer_
double getWidth20()
Definition: TMatacq.h:73
int findPeak()
Definition: TMatacq.cc:136
const unsigned int _parabnbefmax
const edm::EDGetTokenT< EcalMatacqDigiCollection > pmatToken_
static constexpr float a0
const std::string digiProducer_
double getTrise()
Definition: TMatacq.h:71
const unsigned int _nsamplesaftmax
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
Definition: colors.py:1
int size() const
Definition: TMatacq.h:6
const unsigned int _nsamplesshape
Definition: tree.py:1
const unsigned int _noiseCut
const edm::EDGetTokenT< EcalRawDataCollection > dccToken_
void endJob() override
const unsigned int _highlev
const unsigned int _parabnaftmax
Definition: event.py:1
double getTimpeak()
Definition: TMatacq.h:65