CMS 3D CMS Logo

EcalMixingModuleValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalMixingModuleValidation.cc
3  *
4  * \author F. Cossutti
5  *
6 */
7 
18 
20  : HepMCToken_(consumes<edm::HepMCProduct>(edm::InputTag(ps.getParameter<std::string>("moduleLabelMC")))),
21  EBdigiCollectionToken_(consumes<EBDigiCollection>(ps.getParameter<edm::InputTag>("EBdigiCollection"))),
22  EEdigiCollectionToken_(consumes<EEDigiCollection>(ps.getParameter<edm::InputTag>("EEdigiCollection"))),
23  ESdigiCollectionToken_(consumes<ESDigiCollection>(ps.getParameter<edm::InputTag>("ESdigiCollection"))),
24  crossingFramePCaloHitEBToken_(consumes<CrossingFrame<PCaloHit> >(
25  edm::InputTag(std::string("mix"), ps.getParameter<std::string>("hitsProducer") + std::string("EcalHitsEB")))),
26  crossingFramePCaloHitEEToken_(consumes<CrossingFrame<PCaloHit> >(
27  edm::InputTag(std::string("mix"), ps.getParameter<std::string>("hitsProducer") + std::string("EcalHitsEE")))),
28  crossingFramePCaloHitESToken_(consumes<CrossingFrame<PCaloHit> >(edm::InputTag(
29  std::string("mix"), ps.getParameter<std::string>("hitsProducer") + std::string("EcalHitsES")))) {
30  // needed for MixingModule checks
31 
32  double simHitToPhotoelectronsBarrel = ps.getParameter<double>("simHitToPhotoelectronsBarrel");
33  double simHitToPhotoelectronsEndcap = ps.getParameter<double>("simHitToPhotoelectronsEndcap");
34  double photoelectronsToAnalogBarrel = ps.getParameter<double>("photoelectronsToAnalogBarrel");
35  double photoelectronsToAnalogEndcap = ps.getParameter<double>("photoelectronsToAnalogEndcap");
36  double samplingFactor = ps.getParameter<double>("samplingFactor");
37  double timePhase = ps.getParameter<double>("timePhase");
38  int readoutFrameSize = ps.getParameter<int>("readoutFrameSize");
39  int binOfMaximum = ps.getParameter<int>("binOfMaximum");
40  bool doPhotostatistics = ps.getParameter<bool>("doPhotostatistics");
41  bool syncPhase = ps.getParameter<bool>("syncPhase");
42 
43  doPhotostatistics = false;
44 
45  theParameterMap = new EcalSimParameterMap(simHitToPhotoelectronsBarrel,
46  simHitToPhotoelectronsEndcap,
47  photoelectronsToAnalogBarrel,
48  photoelectronsToAnalogEndcap,
49  samplingFactor,
50  timePhase,
51  readoutFrameSize,
52  binOfMaximum,
53  doPhotostatistics,
54  syncPhase);
55  //theEcalShape = new EcalShape(timePhase);
56 
57  //theEcalResponse = new CaloHitResponse(theParameterMap, theEcalShape);
58 
59  /*
60  int ESGain = ps.getParameter<int>("ESGain");
61  double ESNoiseSigma = ps.getParameter<double> ("ESNoiseSigma");
62  int ESBaseline = ps.getParameter<int>("ESBaseline");
63  double ESMIPADC = ps.getParameter<double>("ESMIPADC");
64  double ESMIPkeV = ps.getParameter<double>("ESMIPkeV");
65 */
66 
67  theESShape = new ESShape();
68  theEBShape = new EBShape(true);
69  theEEShape = new EEShape(true);
70 
74 
75  // double effwei = 1.;
76 
77  /*
78  if (ESGain == 0)
79  effwei = 1.45;
80  else if (ESGain == 1)
81  effwei = 0.9066;
82  else if (ESGain == 2)
83  effwei = 0.8815;
84 
85  esBaseline_ = (double)ESBaseline;
86  esADCtokeV_ = 1000000.*ESMIPADC/ESMIPkeV;
87  esThreshold_ = 3.*effwei*ESNoiseSigma/esADCtokeV_;
88 */
89  theMinBunch = -10;
90  theMaxBunch = 10;
91 
92  // verbosity switch
93  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
94 
95  gainConv_[1] = 1.;
96  gainConv_[2] = 2.;
97  gainConv_[3] = 12.;
98  gainConv_[0] = 12.;
99  barrelADCtoGeV_ = 0.035;
100  endcapADCtoGeV_ = 0.06;
101 
102  meEBDigiMixRatiogt100ADC_ = nullptr;
103  meEEDigiMixRatiogt100ADC_ = nullptr;
104 
105  meEBDigiMixRatioOriggt50pc_ = nullptr;
106  meEEDigiMixRatioOriggt40pc_ = nullptr;
107 
108  meEBbunchCrossing_ = nullptr;
109  meEEbunchCrossing_ = nullptr;
110  meESbunchCrossing_ = nullptr;
111 
112  for (int i = 0; i < nBunch; i++) {
113  meEBBunchShape_[i] = nullptr;
114  meEEBunchShape_[i] = nullptr;
115  meESBunchShape_[i] = nullptr;
116  }
117 
118  meEBShape_ = nullptr;
119  meEEShape_ = nullptr;
120  meESShape_ = nullptr;
121 
122  meEBShapeRatio_ = nullptr;
123  meEEShapeRatio_ = nullptr;
124  meESShapeRatio_ = nullptr;
125 }
126 
128 
133 }
134 
136  Char_t histo[200];
137 
138  ibooker.setCurrentFolder("EcalDigisV/EcalDigiTask");
139 
140  sprintf(histo, "EcalDigiTask Barrel maximum Digi over sim signal ratio gt 100 ADC");
141  meEBDigiMixRatiogt100ADC_ = ibooker.book1D(histo, histo, 200, 0., 100.);
142 
143  sprintf(histo, "EcalDigiTask Endcap maximum Digi over sim signal ratio gt 100 ADC");
144  meEEDigiMixRatiogt100ADC_ = ibooker.book1D(histo, histo, 200, 0., 100.);
145 
146  sprintf(histo, "EcalDigiTask Barrel maximum Digi over sim signal ratio signal gt 50pc gun");
147  meEBDigiMixRatioOriggt50pc_ = ibooker.book1D(histo, histo, 200, 0., 100.);
148 
149  sprintf(histo, "EcalDigiTask Endcap maximum Digi over sim signal ratio signal gt 40pc gun");
150  meEEDigiMixRatioOriggt40pc_ = ibooker.book1D(histo, histo, 200, 0., 100.);
151 
152  sprintf(histo, "EcalDigiTask Barrel bunch crossing");
153  meEBbunchCrossing_ = ibooker.book1D(histo, histo, 20, -10., 10.);
154 
155  sprintf(histo, "EcalDigiTask Endcap bunch crossing");
156  meEEbunchCrossing_ = ibooker.book1D(histo, histo, 20, -10., 10.);
157 
158  sprintf(histo, "EcalDigiTask Preshower bunch crossing");
159  meESbunchCrossing_ = ibooker.book1D(histo, histo, 20, -10., 10.);
160 
161  for (int i = 0; i < nBunch; i++) {
162  sprintf(histo, "EcalDigiTask Barrel shape bunch crossing %02d", i - 10);
163  meEBBunchShape_[i] = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 400.);
164 
165  sprintf(histo, "EcalDigiTask Endcap shape bunch crossing %02d", i - 10);
166  meEEBunchShape_[i] = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 400.);
167 
168  sprintf(histo, "EcalDigiTask Preshower shape bunch crossing %02d", i - 10);
169  meESBunchShape_[i] = ibooker.bookProfile(histo, histo, 3, 0, 3, 4000, 0., 400.);
170  }
171 
172  sprintf(histo, "EcalDigiTask Barrel shape digi");
173  meEBShape_ = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 2000.);
174 
175  sprintf(histo, "EcalDigiTask Endcap shape digi");
176  meEEShape_ = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 2000.);
177 
178  sprintf(histo, "EcalDigiTask Preshower shape digi");
179  meESShape_ = ibooker.bookProfile(histo, histo, 3, 0, 3, 4000, 0., 2000.);
180 
181  sprintf(histo, "EcalDigiTask Barrel shape digi ratio");
182  meEBShapeRatio_ = ibooker.book1D(histo, histo, 10, 0, 10.);
183 
184  sprintf(histo, "EcalDigiTask Endcap shape digi ratio");
185  meEEShapeRatio_ = ibooker.book1D(histo, histo, 10, 0, 10.);
186 
187  sprintf(histo, "EcalDigiTask Preshower shape digi ratio");
188  meESShapeRatio_ = ibooker.book1D(histo, histo, 3, 0, 3.);
189 }
190 
192  // add shapes for each bunch crossing and divide the digi by the result
193 
194  std::vector<MonitorElement*> theBunches;
195  for (int i = 0; i < nBunch; i++) {
196  theBunches.push_back(meEBBunchShape_[i]);
197  }
199 
200  theBunches.clear();
201 
202  for (int i = 0; i < nBunch; i++) {
203  theBunches.push_back(meEEBunchShape_[i]);
204  }
206 
207  theBunches.clear();
208 
209  for (int i = 0; i < nBunch; i++) {
210  theBunches.push_back(meESBunchShape_[i]);
211  }
213 }
214 
215 void EcalMixingModuleValidation::bunchSumTest(std::vector<MonitorElement*>& theBunches,
216  MonitorElement*& theTotal,
217  MonitorElement*& theRatio,
218  int nSample) {
219  std::vector<double> bunchSum;
220  bunchSum.reserve(nSample);
221  std::vector<double> bunchSumErro;
222  bunchSumErro.reserve(nSample);
223  std::vector<double> total;
224  total.reserve(nSample);
225  std::vector<double> totalErro;
226  totalErro.reserve(nSample);
227  std::vector<double> ratio;
228  ratio.reserve(nSample);
229  std::vector<double> ratioErro;
230  ratioErro.reserve(nSample);
231 
232  for (int iEl = 0; iEl < nSample; iEl++) {
233  bunchSum[iEl] = 0.;
234  bunchSumErro[iEl] = 0.;
235  total[iEl] = 0.;
236  totalErro[iEl] = 0.;
237  ratio[iEl] = 0.;
238  ratioErro[iEl] = 0.;
239  }
240 
241  for (int iSample = 0; iSample < nSample; iSample++) {
242  total[iSample] += theTotal->getBinContent(iSample + 1);
243  totalErro[iSample] += theTotal->getBinError(iSample + 1);
244 
245  for (int iBunch = theMinBunch; iBunch <= theMaxBunch; iBunch++) {
246  int iHisto = iBunch - theMinBunch;
247 
248  bunchSum[iSample] += theBunches[iHisto]->getBinContent(iSample + 1);
249  bunchSumErro[iSample] += pow(theBunches[iHisto]->getBinError(iSample + 1), 2);
250  }
251  bunchSumErro[iSample] = sqrt(bunchSumErro[iSample]);
252 
253  if (bunchSum[iSample] > 0.) {
254  ratio[iSample] = total[iSample] / bunchSum[iSample];
255  ratioErro[iSample] =
256  sqrt(pow(totalErro[iSample] / bunchSum[iSample], 2) +
257  pow((total[iSample] * bunchSumErro[iSample]) / (bunchSum[iSample] * bunchSum[iSample]), 2));
258  }
259 
260  std::cout << " Sample = " << iSample << " Total = " << total[iSample] << " +- " << totalErro[iSample] << "\n"
261  << " Sum = " << bunchSum[iSample] << " +- " << bunchSumErro[iSample] << "\n"
262  << " Ratio = " << ratio[iSample] << " +- " << ratioErro[iSample] << std::endl;
263 
264  theRatio->setBinContent(iSample + 1, (float)ratio[iSample]);
265  theRatio->setBinError(iSample + 1, (float)ratioErro[iSample]);
266  }
267 }
268 
270  //LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
271 
272  checkPedestals(c);
273 
274  std::vector<SimTrack> theSimTracks;
275  std::vector<SimVertex> theSimVertexes;
276 
278  edm::Handle<CrossingFrame<PCaloHit> > crossingFrame;
282 
283  bool skipMC = false;
284  e.getByToken(HepMCToken_, MCEvt);
285  if (!MCEvt.isValid()) {
286  skipMC = true;
287  }
288 
289  const EBDigiCollection* EBdigis = nullptr;
290  const EEDigiCollection* EEdigis = nullptr;
291  const ESDigiCollection* ESdigis = nullptr;
292 
293  bool isBarrel = true;
294  e.getByToken(EBdigiCollectionToken_, EcalDigiEB);
295  if (EcalDigiEB.isValid()) {
296  EBdigis = EcalDigiEB.product();
297  LogDebug("DigiInfo") << "total # EBdigis: " << EBdigis->size();
298  if (EBdigis->empty())
299  isBarrel = false;
300  } else {
301  isBarrel = false;
302  }
303 
304  bool isEndcap = true;
305  e.getByToken(EEdigiCollectionToken_, EcalDigiEE);
306  if (EcalDigiEE.isValid()) {
307  EEdigis = EcalDigiEE.product();
308  LogDebug("DigiInfo") << "total # EEdigis: " << EEdigis->size();
309  if (EEdigis->empty())
310  isEndcap = false;
311  } else {
312  isEndcap = false;
313  }
314 
315  bool isPreshower = true;
316  e.getByToken(ESdigiCollectionToken_, EcalDigiES);
317  if (EcalDigiES.isValid()) {
318  ESdigis = EcalDigiES.product();
319  LogDebug("DigiInfo") << "total # ESdigis: " << ESdigis->size();
320  if (ESdigis->empty())
321  isPreshower = false;
322  } else {
323  isPreshower = false;
324  }
325 
326  double theGunEnergy = 0.;
327  if (!skipMC) {
328  for (HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
329  p != MCEvt->GetEvent()->particles_end();
330  ++p) {
331  theGunEnergy = (*p)->momentum().e();
332  }
333  }
334  // in case no HepMC available, assume an arbitrary average energy for an interesting "gun"
335  else {
336  edm::LogWarning("DigiInfo") << "No HepMC available, using 30 GeV as giun energy";
337  theGunEnergy = 30.;
338  }
339 
340  // BARREL
341 
342  // loop over simHits
343 
344  if (isBarrel) {
345  e.getByToken(crossingFramePCaloHitEBToken_, crossingFrame);
346  const MixCollection<PCaloHit> barrelHits(crossingFrame.product());
347 
348  MapType ebSignalSimMap;
349 
350  double ebSimThreshold = 0.5 * theGunEnergy;
351 
352  for (auto const& iHit : barrelHits) {
353  EBDetId ebid = EBDetId(iHit.id());
354 
355  LogDebug("HitInfo") << " CaloHit " << iHit.getName() << "\n"
356  << " DetID = " << iHit.id() << " EBDetId = " << ebid.ieta() << " " << ebid.iphi() << "\n"
357  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
358  << " Track Id = " << iHit.geantTrackId() << "\n"
359  << " Energy = " << iHit.energy();
360 
361  uint32_t crystid = ebid.rawId();
362 
363  if (iHit.eventId().rawId() == 0)
364  ebSignalSimMap[crystid] += iHit.energy();
365 
366  if (meEBbunchCrossing_)
367  meEBbunchCrossing_->Fill(iHit.eventId().bunchCrossing());
368  }
369 
370  // loop over Digis
371 
372  const EBDigiCollection* barrelDigi = EcalDigiEB.product();
373 
374  std::vector<double> ebAnalogSignal;
375  std::vector<double> ebADCCounts;
376  std::vector<double> ebADCGains;
377  ebAnalogSignal.reserve(EBDataFrame::MAXSAMPLES);
378  ebADCCounts.reserve(EBDataFrame::MAXSAMPLES);
379  ebADCGains.reserve(EBDataFrame::MAXSAMPLES);
380 
381  for (unsigned int digis = 0; digis < EcalDigiEB->size(); ++digis) {
382  EBDataFrame ebdf = (*barrelDigi)[digis];
383  int nrSamples = ebdf.size();
384 
385  EBDetId ebid = ebdf.id();
386 
387  double Emax = 0.;
388  int Pmax = 0;
389 
390  for (int sample = 0; sample < nrSamples; ++sample) {
391  ebAnalogSignal[sample] = 0.;
392  ebADCCounts[sample] = 0.;
393  ebADCGains[sample] = -1.;
394  }
395 
396  for (int sample = 0; sample < nrSamples; ++sample) {
398 
399  ebADCCounts[sample] = (mySample.adc());
400  ebADCGains[sample] = (mySample.gainId());
401  ebAnalogSignal[sample] = (ebADCCounts[sample] * gainConv_[(int)ebADCGains[sample]] * barrelADCtoGeV_);
402  if (Emax < ebAnalogSignal[sample]) {
403  Emax = ebAnalogSignal[sample];
404  Pmax = sample;
405  }
406  LogDebug("DigiInfo") << "EB sample " << sample << " ADC counts = " << ebADCCounts[sample]
407  << " Gain Id = " << ebADCGains[sample] << " Analog eq = " << ebAnalogSignal[sample];
408  }
409  double pedestalPreSampleAnalog = 0.;
410  findPedestal(ebid, (int)ebADCGains[Pmax], pedestalPreSampleAnalog);
411  pedestalPreSampleAnalog *= gainConv_[(int)ebADCGains[Pmax]] * barrelADCtoGeV_;
412  double Erec = Emax - pedestalPreSampleAnalog;
413 
414  if (ebSignalSimMap[ebid.rawId()] != 0.) {
415  LogDebug("DigiInfo") << " Digi / Signal Hit = " << Erec << " / " << ebSignalSimMap[ebid.rawId()] << " gainConv "
416  << gainConv_[(int)ebADCGains[Pmax]];
417  if (Erec > 100. * barrelADCtoGeV_ && meEBDigiMixRatiogt100ADC_)
418  meEBDigiMixRatiogt100ADC_->Fill(Erec / ebSignalSimMap[ebid.rawId()]);
419  if (ebSignalSimMap[ebid.rawId()] > ebSimThreshold && meEBDigiMixRatioOriggt50pc_)
420  meEBDigiMixRatioOriggt50pc_->Fill(Erec / ebSignalSimMap[ebid.rawId()]);
421  if (ebSignalSimMap[ebid.rawId()] > ebSimThreshold && meEBShape_) {
422  for (int i = 0; i < 10; i++) {
423  pedestalPreSampleAnalog = 0.;
424  findPedestal(ebid, (int)ebADCGains[i], pedestalPreSampleAnalog);
425  pedestalPreSampleAnalog *= gainConv_[(int)ebADCGains[i]] * barrelADCtoGeV_;
426  meEBShape_->Fill(i, ebAnalogSignal[i] - pedestalPreSampleAnalog);
427  }
428  }
429  }
430  }
431 
432  EcalSubdetector thisDet = EcalBarrel;
433  computeSDBunchDigi(c, barrelHits, ebSignalSimMap, thisDet, ebSimThreshold, randomEngine(e.streamID()));
434  }
435 
436  // ENDCAP
437 
438  // loop over simHits
439 
440  if (isEndcap) {
441  e.getByToken(crossingFramePCaloHitEEToken_, crossingFrame);
442  const MixCollection<PCaloHit> endcapHits(crossingFrame.product());
443  MapType eeSignalSimMap;
444 
445  double eeSimThreshold = 0.4 * theGunEnergy;
446 
447  for (auto const& iHit : endcapHits) {
448  EEDetId eeid = EEDetId(iHit.id());
449 
450  LogDebug("HitInfo") << " CaloHit " << iHit.getName() << "\n"
451  << " DetID = " << iHit.id() << " EEDetId side = " << eeid.zside() << " = " << eeid.ix() << " "
452  << eeid.iy() << "\n"
453  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
454  << " Track Id = " << iHit.geantTrackId() << "\n"
455  << " Energy = " << iHit.energy();
456 
457  uint32_t crystid = eeid.rawId();
458 
459  if (iHit.eventId().rawId() == 0)
460  eeSignalSimMap[crystid] += iHit.energy();
461 
462  if (meEEbunchCrossing_)
463  meEEbunchCrossing_->Fill(iHit.eventId().bunchCrossing());
464  }
465 
466  // loop over Digis
467 
468  const EEDigiCollection* endcapDigi = EcalDigiEE.product();
469 
470  std::vector<double> eeAnalogSignal;
471  std::vector<double> eeADCCounts;
472  std::vector<double> eeADCGains;
473  eeAnalogSignal.reserve(EEDataFrame::MAXSAMPLES);
474  eeADCCounts.reserve(EEDataFrame::MAXSAMPLES);
475  eeADCGains.reserve(EEDataFrame::MAXSAMPLES);
476 
477  for (unsigned int digis = 0; digis < EcalDigiEE->size(); ++digis) {
478  EEDataFrame eedf = (*endcapDigi)[digis];
479  int nrSamples = eedf.size();
480 
481  EEDetId eeid = eedf.id();
482 
483  double Emax = 0.;
484  int Pmax = 0;
485 
486  for (int sample = 0; sample < nrSamples; ++sample) {
487  eeAnalogSignal[sample] = 0.;
488  eeADCCounts[sample] = 0.;
489  eeADCGains[sample] = -1.;
490  }
491 
492  for (int sample = 0; sample < nrSamples; ++sample) {
494 
495  eeADCCounts[sample] = (mySample.adc());
496  eeADCGains[sample] = (mySample.gainId());
497  eeAnalogSignal[sample] = (eeADCCounts[sample] * gainConv_[(int)eeADCGains[sample]] * endcapADCtoGeV_);
498  if (Emax < eeAnalogSignal[sample]) {
499  Emax = eeAnalogSignal[sample];
500  Pmax = sample;
501  }
502  LogDebug("DigiInfo") << "EE sample " << sample << " ADC counts = " << eeADCCounts[sample]
503  << " Gain Id = " << eeADCGains[sample] << " Analog eq = " << eeAnalogSignal[sample];
504  }
505  double pedestalPreSampleAnalog = 0.;
506  findPedestal(eeid, (int)eeADCGains[Pmax], pedestalPreSampleAnalog);
507  pedestalPreSampleAnalog *= gainConv_[(int)eeADCGains[Pmax]] * endcapADCtoGeV_;
508  double Erec = Emax - pedestalPreSampleAnalog;
509 
510  if (eeSignalSimMap[eeid.rawId()] != 0.) {
511  LogDebug("DigiInfo") << " Digi / Signal Hit = " << Erec << " / " << eeSignalSimMap[eeid.rawId()] << " gainConv "
512  << gainConv_[(int)eeADCGains[Pmax]];
513  if (Erec > 100. * endcapADCtoGeV_ && meEEDigiMixRatiogt100ADC_)
514  meEEDigiMixRatiogt100ADC_->Fill(Erec / eeSignalSimMap[eeid.rawId()]);
515  if (eeSignalSimMap[eeid.rawId()] > eeSimThreshold && meEEDigiMixRatioOriggt40pc_)
516  meEEDigiMixRatioOriggt40pc_->Fill(Erec / eeSignalSimMap[eeid.rawId()]);
517  if (eeSignalSimMap[eeid.rawId()] > eeSimThreshold && meEBShape_) {
518  for (int i = 0; i < 10; i++) {
519  pedestalPreSampleAnalog = 0.;
520  findPedestal(eeid, (int)eeADCGains[i], pedestalPreSampleAnalog);
521  pedestalPreSampleAnalog *= gainConv_[(int)eeADCGains[i]] * endcapADCtoGeV_;
522  meEEShape_->Fill(i, eeAnalogSignal[i] - pedestalPreSampleAnalog);
523  }
524  }
525  }
526  }
527 
528  EcalSubdetector thisDet = EcalEndcap;
529  computeSDBunchDigi(c, endcapHits, eeSignalSimMap, thisDet, eeSimThreshold, randomEngine(e.streamID()));
530  }
531 
532  if (isPreshower) {
533  e.getByToken(crossingFramePCaloHitESToken_, crossingFrame);
534  const MixCollection<PCaloHit> preshowerHits(crossingFrame.product());
535 
536  MapType esSignalSimMap;
537 
538  for (auto const& iHit : preshowerHits) {
539  ESDetId esid = ESDetId(iHit.id());
540 
541  LogDebug("HitInfo") << " CaloHit " << iHit.getName() << "\n"
542  << " DetID = " << iHit.id() << "ESDetId: z side " << esid.zside() << " plane "
543  << esid.plane() << esid.six() << ',' << esid.siy() << ':' << esid.strip() << "\n"
544  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
545  << " Track Id = " << iHit.geantTrackId() << "\n"
546  << " Energy = " << iHit.energy();
547 
548  uint32_t stripid = esid.rawId();
549 
550  if (iHit.eventId().rawId() == 0)
551  esSignalSimMap[stripid] += iHit.energy();
552 
553  if (meESbunchCrossing_)
554  meESbunchCrossing_->Fill(iHit.eventId().bunchCrossing());
555 
556  // loop over Digis
557 
558  const ESDigiCollection* preshowerDigi = EcalDigiES.product();
559 
560  std::vector<double> esADCCounts;
561  std::vector<double> esADCAnalogSignal;
562  esADCCounts.reserve(ESDataFrame::MAXSAMPLES);
563  esADCAnalogSignal.reserve(ESDataFrame::MAXSAMPLES);
564 
565  for (unsigned int digis = 0; digis < EcalDigiES->size(); ++digis) {
566  ESDataFrame esdf = (*preshowerDigi)[digis];
567  int nrSamples = esdf.size();
568 
569  ESDetId esid = esdf.id();
570 
571  for (int sample = 0; sample < nrSamples; ++sample) {
572  esADCCounts[sample] = 0.;
573  esADCAnalogSignal[sample] = 0.;
574  }
575 
576  for (int sample = 0; sample < nrSamples; ++sample) {
577  ESSample mySample = esdf[sample];
578 
579  esADCCounts[sample] = (mySample.adc());
580  esBaseline_ = m_ESpeds->find(esid)->getMean();
581  const double factor(esADCtokeV_ / (*(m_ESmips->getMap().find(esid))));
582  esThreshold_ = 3. * m_ESeffwei * ((*m_ESpeds->find(esid)).getRms()) / factor;
583  esADCAnalogSignal[sample] = (esADCCounts[sample] - esBaseline_) / factor;
584  }
585  LogDebug("DigiInfo") << "Preshower Digi for ESDetId: z side " << esid.zside() << " plane " << esid.plane()
586  << esid.six() << ',' << esid.siy() << ':' << esid.strip();
587  for (int i = 0; i < 3; i++) {
588  LogDebug("DigiInfo") << "sample " << i << " ADC = " << esADCCounts[i]
589  << " Analog eq = " << esADCAnalogSignal[i];
590  }
591 
592  if (esSignalSimMap[esid.rawId()] > esThreshold_ && meESShape_) {
593  for (int i = 0; i < 3; i++) {
594  meESShape_->Fill(i, esADCAnalogSignal[i]);
595  }
596  }
597  }
598  }
599 
600  EcalSubdetector thisDet = EcalPreshower;
601  computeSDBunchDigi(c, preshowerHits, esSignalSimMap, thisDet, esThreshold_, randomEngine(e.streamID()));
602  }
603 }
604 
606  // ADC -> GeV Scale
608  eventSetup.get<EcalADCToGeVConstantRcd>().get(pAgc);
609  const EcalADCToGeVConstant* agc = pAgc.product();
610 
611  EcalMGPAGainRatio* defaultRatios = new EcalMGPAGainRatio();
612 
613  gainConv_[1] = 1.;
614  gainConv_[2] = defaultRatios->gain12Over6();
615  gainConv_[3] = gainConv_[2] * (defaultRatios->gain6Over1());
616  gainConv_[0] = gainConv_[2] * (defaultRatios->gain6Over1());
617 
618  LogDebug("EcalDigi") << " Gains conversions: "
619  << "\n"
620  << " g1 = " << gainConv_[1] << "\n"
621  << " g2 = " << gainConv_[2] << "\n"
622  << " g3 = " << gainConv_[3];
623 
624  delete defaultRatios;
625 
626  const double barrelADCtoGeV_ = agc->getEBValue();
627  LogDebug("EcalDigi") << " Barrel GeV/ADC = " << barrelADCtoGeV_;
628  const double endcapADCtoGeV_ = agc->getEEValue();
629  LogDebug("EcalDigi") << " Endcap GeV/ADC = " << endcapADCtoGeV_;
630 
631  // ES condition objects
632  edm::ESHandle<ESGain> esgain_;
634  edm::ESHandle<ESPedestals> esPedestals_;
636 
637  eventSetup.get<ESGainRcd>().get(esgain_);
638  eventSetup.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
639  eventSetup.get<ESPedestalsRcd>().get(esPedestals_);
640  eventSetup.get<ESIntercalibConstantsRcd>().get(esMIPs_);
641 
642  const ESGain* esgain = esgain_.product();
643  m_ESpeds = esPedestals_.product();
644  m_ESmips = esMIPs_.product();
645  const ESMIPToGeVConstant* esMipToGeV = esMIPToGeV_.product();
646  m_ESgain = (int)esgain->getESGain();
647  const double valESMIPToGeV = (m_ESgain == 1) ? esMipToGeV->getESValueLow() : esMipToGeV->getESValueHigh();
648 
650 
651  esADCtokeV_ = 1000000. * valESMIPToGeV;
652 
653  m_ESeffwei = (0 == m_ESgain ? 1.45 : (1 == m_ESgain ? 0.9066 : (2 == m_ESgain ? 0.8815 : 1.0)));
654 }
655 
657  // Pedestals from event setup
658 
660  eventSetup.get<EcalPedestalsRcd>().get(dbPed);
661  thePedestals = dbPed.product();
662 }
663 
664 void EcalMixingModuleValidation::findPedestal(const DetId& detId, int gainId, double& ped) const {
666  // should I care if it doesn't get found?
667  if (mapItr == thePedestals->getMap().end()) {
668  edm::LogError("EcalMMValid") << "Could not find pedestal for " << detId.rawId() << " among the "
669  << thePedestals->getMap().size();
670  } else {
671  EcalPedestals::Item item = (*mapItr);
672 
673  switch (gainId) {
674  case 0:
675  ped = item.mean_x1;
676  break;
677  case 1:
678  ped = item.mean_x12;
679  break;
680  case 2:
681  ped = item.mean_x6;
682  break;
683  case 3:
684  ped = item.mean_x1;
685  break;
686  default:
687  edm::LogError("EcalMMValid") << "Bad Pedestal " << gainId;
688  break;
689  }
690  LogDebug("EcalMMValid") << "Pedestals for " << detId.rawId() << " gain range " << gainId << " : \n"
691  << "Mean = " << ped;
692  }
693 }
694 
697  MapType& SignalSimMap,
698  const EcalSubdetector& thisDet,
699  const double& theSimThreshold,
700  CLHEP::HepRandomEngine* engine) {
701  if (thisDet != EcalBarrel && thisDet != EcalEndcap && thisDet != EcalPreshower) {
702  edm::LogError("EcalMMValid") << "Invalid subdetector type";
703  return;
704  }
705  //bool isCrystal = true;
706  //if ( thisDet == EcalPreshower ) isCrystal = false;
707 
708  // load the geometry
709 
710  edm::ESHandle<CaloGeometry> hGeometry;
711  eventSetup.get<CaloGeometryRecord>().get(hGeometry);
712 
713  const CaloGeometry* pGeometry = &*hGeometry;
714 
715  // see if we need to update
716  if (pGeometry != theGeometry) {
717  theGeometry = pGeometry;
718  //theEcalResponse->setGeometry(theGeometry);
722  }
723 
724  // vector of DetId with energy above a fraction of the gun's energy
725 
726  const std::vector<DetId>& theSDId = theGeometry->getValidDetIds(DetId::Ecal, thisDet);
727 
728  std::vector<DetId> theOverThresholdId;
729  for (unsigned int i = 0; i < theSDId.size(); i++) {
730  int sdId = theSDId[i].rawId();
731  if (SignalSimMap[sdId] > theSimThreshold)
732  theOverThresholdId.push_back(theSDId[i]);
733  }
734 
736  if (thisDet == EcalPreshower)
737  limit = ESDataFrame::MAXSAMPLES;
738 
739  for (int iBunch = theMinBunch; iBunch <= theMaxBunch; iBunch++) {
740  //if ( isCrystal ) {
741  if (thisDet == EcalBarrel) {
742  theEBResponse->setBunchRange(iBunch, iBunch);
743  theEBResponse->clear();
744  theEBResponse->run(theHits, engine);
745  } else if (thisDet == EcalEndcap) {
746  theEEResponse->setBunchRange(iBunch, iBunch);
747  theEEResponse->clear();
748  theEEResponse->run(theHits, engine);
749  } else {
750  theESResponse->setBunchRange(iBunch, iBunch);
751  theESResponse->clear();
752  theESResponse->run(theHits, engine);
753  }
754 
755  int iHisto = iBunch - theMinBunch;
756 
757  for (std::vector<DetId>::const_iterator idItr = theOverThresholdId.begin(); idItr != theOverThresholdId.end();
758  ++idItr) {
759  CaloSamples* analogSignal;
760  //if ( isCrystal )
761  if (thisDet == EcalBarrel) {
762  analogSignal = theEBResponse->findSignal(*idItr);
763  } else if (thisDet == EcalEndcap) {
764  analogSignal = theEEResponse->findSignal(*idItr);
765  } else {
766  analogSignal = theESResponse->findSignal(*idItr);
767  }
768 
769  if (analogSignal) {
770  (*analogSignal) *= theParameterMap->simParameters(analogSignal->id()).photoelectronsToAnalog();
771 
772  for (int i = 0; i < limit; i++) {
773  if (thisDet == EcalBarrel) {
774  meEBBunchShape_[iHisto]->Fill(i, (float)(*analogSignal)[i]);
775  } else if (thisDet == EcalEndcap) {
776  meEEBunchShape_[iHisto]->Fill(i, (float)(*analogSignal)[i]);
777  } else if (thisDet == EcalPreshower) {
778  meESBunchShape_[iHisto]->Fill(i, (float)(*analogSignal)[i]);
779  }
780  }
781  }
782  }
783  }
784 }
785 
786 CLHEP::HepRandomEngine* EcalMixingModuleValidation::randomEngine(edm::StreamID const& streamID) {
787  unsigned int index = streamID.value();
788  if (index >= randomEngines_.size()) {
789  randomEngines_.resize(index + 1, nullptr);
790  }
791  CLHEP::HepRandomEngine* ptr = randomEngines_[index];
792  if (!ptr) {
794  ptr = &rng->getEngine(streamID);
795  randomEngines_[index] = ptr;
796  }
797  return ptr;
798 }
#define LogDebug(id)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getParameter(std::string const &) const
void setGeometry(const CaloGeometry *geometry)
geometry needed for time-of-flight
T getUntrackedParameter(std::string const &, T const &) const
void checkPedestals(const edm::EventSetup &c)
int strip() const
Definition: ESDetId.h:47
const ESIntercalibConstants * m_ESmips
int ix() const
Definition: EEDetId.h:77
key_type id() const
Definition: EBDataFrame.h:28
void findPedestal(const DetId &detId, int gainId, double &ped) const
static const int MAXSAMPLES
Definition: CaloSamples.h:86
std::map< uint32_t, float, std::less< uint32_t > > MapType
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
Definition: ESGain.h:7
void setGain(const int gain)
Definition: ESShape.h:23
const self & getMap() const
edm::EDGetTokenT< edm::HepMCProduct > HepMCToken_
const ESDetId & id() const
Definition: ESDataFrame.h:19
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
const self & getMap() const
float getESValueLow() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
virtual double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
void checkCalibrations(edm::EventSetup const &c)
MonitorElement * meEEBunchShape_[nBunch]
edm::EDGetTokenT< EBDigiCollection > EBdigiCollectionToken_
std::vector< CLHEP::HepRandomEngine * > randomEngines_
MonitorElement * meEBBunchShape_[nBunch]
int six() const
Definition: ESDetId.h:43
int size() const
Definition: ESDataFrame.h:21
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitEEToken_
int gainId() const
get the gainId (2 bits)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
virtual void run(const MixCollection< PCaloHit > &hits, CLHEP::HepRandomEngine *)
Complete cell digitization.
int size() const
Definition: EcalDataFrame.h:26
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
void Fill(long long x)
int siy() const
Definition: ESDetId.h:45
EcalPedestalsMap::const_iterator EcalPedestalsMapIterator
Definition: EcalPedestals.h:49
void bunchSumTest(std::vector< MonitorElement * > &theBunches, MonitorElement *&theTotal, MonitorElement *&theRatio, int nSample)
MonitorElement * meESBunchShape_[nBunch]
Creates electronics signals from hits.
~EcalMixingModuleValidation() override
Destructor.
T sqrt(T t)
Definition: SSEVec.h:19
static const int MAXSAMPLES
Definition: ESDataFrame.h:30
CLHEP::HepRandomEngine * randomEngine(edm::StreamID const &streamID)
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:333
const_iterator find(uint32_t rawId) const
int zside() const
Definition: EEDetId.h:71
const CaloSimParameters & simParameters(const DetId &id) const override
return the sim parameters relative to the right subdet
int iy() const
Definition: EEDetId.h:83
float gain6Over1() const
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
int zside() const
Definition: ESDetId.h:39
bool isValid() const
Definition: HandleBase.h:70
virtual double getBinContent(int binx) const
get content of bin (1-D)
bool isEndcap(GeomDetEnumerators::SubDetector m)
void computeSDBunchDigi(const edm::EventSetup &eventSetup, const MixCollection< PCaloHit > &theHits, MapType &ebSignalSimMap, const EcalSubdetector &thisDet, const double &theSimThreshold, CLHEP::HepRandomEngine *)
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitEBToken_
key_type id() const
Definition: EEDataFrame.h:24
Definition: EBShape.h:6
std::map< int, double, std::less< int > > gainConv_
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
void reserve(size_t isize)
Definition: DetId.h:17
const EcalSimParameterMap * theParameterMap
edm::EDGetTokenT< ESDigiCollection > ESdigiCollectionToken_
unsigned int value() const
Definition: StreamID.h:42
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
T const * product() const
Definition: Handle.h:69
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
float getESGain() const
Definition: ESGain.h:13
void dqmEndRun(const edm::Run &r, const edm::EventSetup &c) override
void analyze(edm::Event const &e, edm::EventSetup const &c) override
Analyze.
float gain12Over6() const
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitESToken_
void setBunchRange(int minBunch, int maxBunch)
tells it which pileup bunches to do
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:75
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
HLT enums.
void clear()
frees up memory
T get() const
Definition: EventSetup.h:73
StreamID streamID() const
Definition: Event.h:96
int plane() const
Definition: ESDetId.h:41
void setEventSetup(const edm::EventSetup &evtSetup)
const_iterator find(uint32_t rawId) const
const_iterator end() const
int adc() const
get the ADC sample (singed 16 bits)
Definition: ESSample.h:16
virtual void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
EcalMixingModuleValidation(const edm::ParameterSet &ps)
Constructor.
EcalSubdetector
float getESValueHigh() const
T const * product() const
Definition: ESHandle.h:86
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
edm::EDGetTokenT< EEDigiCollection > EEdigiCollectionToken_
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:45
Definition: EEShape.h:6
int adc() const
get the ADC sample (12 bits)