CMS 3D CMS Logo

EcalRecHitsValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalRecHitsValidation.cc
3  *
4  * \author C. Rovelli
5  *
6  */
7 
17 #include <string>
18 
19 using namespace cms;
20 using namespace edm;
21 using namespace std;
22 
24  : pAgc(esConsumes()), pEcsToken(esConsumes()), pttMapToken(esConsumes()) {
25  // ----------------------
26  HepMCLabel = ps.getParameter<std::string>("moduleLabelMC");
27  hitsProducer_ = ps.getParameter<std::string>("hitsProducer");
28  EBrechitCollection_ = ps.getParameter<edm::InputTag>("EBrechitCollection");
29  EErechitCollection_ = ps.getParameter<edm::InputTag>("EErechitCollection");
30  ESrechitCollection_ = ps.getParameter<edm::InputTag>("ESrechitCollection");
31  EBuncalibrechitCollection_ = ps.getParameter<edm::InputTag>("EBuncalibrechitCollection");
32  EEuncalibrechitCollection_ = ps.getParameter<edm::InputTag>("EEuncalibrechitCollection");
33  // switch to allow disabling endcaps for phase 2
34  enableEndcaps_ = ps.getUntrackedParameter<bool>("enableEndcaps", true);
35 
36  // fix for consumes
37  HepMCLabel_Token_ = consumes<HepMCProduct>(ps.getParameter<std::string>("moduleLabelMC"));
38  EBrechitCollection_Token_ = consumes<EBRecHitCollection>(ps.getParameter<edm::InputTag>("EBrechitCollection"));
40  consumes<EBUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("EBuncalibrechitCollection"));
41 
42  EBHits_Token_ = consumes<CrossingFrame<PCaloHit>>(
43  edm::InputTag(std::string("mix"), ps.getParameter<std::string>("hitsProducer") + std::string("EcalHitsEB")));
44  if (enableEndcaps_) {
45  EErechitCollection_Token_ = consumes<EERecHitCollection>(ps.getParameter<edm::InputTag>("EErechitCollection"));
46  ESrechitCollection_Token_ = consumes<ESRecHitCollection>(ps.getParameter<edm::InputTag>("ESrechitCollection"));
48  consumes<EEUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("EEuncalibrechitCollection"));
49  EEHits_Token_ = consumes<CrossingFrame<PCaloHit>>(
50  edm::InputTag(std::string("mix"), ps.getParameter<std::string>("hitsProducer") + std::string("EcalHitsEE")));
51  ESHits_Token_ = consumes<CrossingFrame<PCaloHit>>(
52  edm::InputTag(std::string("mix"), ps.getParameter<std::string>("hitsProducer") + std::string("EcalHitsES")));
53  }
54 
55  // ----------------------
56  // DQM ROOT output
57  outputFile_ = ps.getUntrackedParameter<string>("outputFile", "");
58 
59  if (!outputFile_.empty()) {
60  LogInfo("OutputInfo") << " Ecal RecHits Task histograms will be saved to '" << outputFile_.c_str() << "'";
61  } else {
62  LogInfo("OutputInfo") << " Ecal RecHits Task histograms will NOT be saved";
63  }
64 
65  // ----------------------
66  // verbosity switch
67  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
68 
69  // ----------------------
70  meGunEnergy_ = nullptr;
71  meGunEta_ = nullptr;
72  meGunPhi_ = nullptr;
73  meEBRecHitSimHitRatio_ = nullptr;
74  meEERecHitSimHitRatio_ = nullptr;
75  meESRecHitSimHitRatio_ = nullptr;
78  meEBRecHitSimHitRatio12_ = nullptr;
79  meEERecHitSimHitRatio12_ = nullptr;
80  meEBRecHitSimHitRatio13_ = nullptr;
81  meEERecHitSimHitRatio13_ = nullptr;
84  meEBUnRecHitSimHitRatio_ = nullptr;
85  meEEUnRecHitSimHitRatio_ = nullptr;
88  meEBe5x5_ = nullptr;
89  meEBe5x5OverSimHits_ = nullptr;
90  meEBe5x5OverGun_ = nullptr;
91  meEEe5x5_ = nullptr;
92  meEEe5x5OverSimHits_ = nullptr;
93  meEEe5x5OverGun_ = nullptr;
94 
95  meEBRecHitLog10Energy_ = nullptr;
96  meEERecHitLog10Energy_ = nullptr;
97  meESRecHitLog10Energy_ = nullptr;
100  meESRecHitLog10EnergyContr_ = nullptr;
103 
110 
111  meEBRecHitFlags_ = nullptr;
113  meEBRecHitSimHitFlag6_ = nullptr;
114  meEBRecHitSimHitFlag7_ = nullptr;
116 
117  meEERecHitFlags_ = nullptr;
119  meEERecHitSimHitFlag6_ = nullptr;
120  meEERecHitSimHitFlag7_ = nullptr;
121 }
122 
124 
127 
128  ibooker.setCurrentFolder("EcalRecHitsV/EcalRecHitsTask");
129 
130  histo = "EcalRecHitsTask Gun Momentum";
131  meGunEnergy_ = ibooker.book1D(histo.c_str(), histo.c_str(), 100, 0., 1000.);
132 
133  histo = "EcalRecHitsTask Gun Eta";
134  meGunEta_ = ibooker.book1D(histo.c_str(), histo.c_str(), 700, -3.5, 3.5);
135 
136  histo = "EcalRecHitsTask Gun Phi";
137  meGunPhi_ = ibooker.book1D(histo.c_str(), histo.c_str(), 360, 0., 360.);
138 
139  histo = "EcalRecHitsTask Barrel RecSimHit Ratio";
140  meEBRecHitSimHitRatio_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
141 
142  histo = "EcalRecHitsTask Barrel RecSimHit Ratio gt 3p5 GeV";
143  meEBRecHitSimHitRatioGt35_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
144 
145  histo = "EcalRecHitsTask Barrel Unc RecSimHit Ratio";
146  meEBUnRecHitSimHitRatio_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
147 
148  histo = "EcalRecHitsTask Barrel RecSimHit Ratio Channel Status=10 11";
149  meEBRecHitSimHitRatio1011_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
150 
151  histo = "EcalRecHitsTask Barrel RecSimHit Ratio Channel Status=12";
152  meEBRecHitSimHitRatio12_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
153 
154  histo = "EcalRecHitsTask Barrel RecSimHit Ratio Channel Status=13";
155  meEBRecHitSimHitRatio13_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
156 
157  histo = "EcalRecHitsTask Barrel Unc RecSimHit Ratio gt 3p5 GeV";
158  meEBUnRecHitSimHitRatioGt35_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
159 
160  histo = "EcalRecHitsTask Barrel Rec E5x5";
161  meEBe5x5_ = ibooker.book1D(histo.c_str(), histo.c_str(), 4000, 0., 400.);
162 
163  histo = "EcalRecHitsTask Barrel Rec E5x5 over Sim E5x5";
164  meEBe5x5OverSimHits_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
165 
166  histo = "EcalRecHitsTask Barrel Rec E5x5 over gun energy";
167  meEBe5x5OverGun_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
168 
170  ibooker.book1D("EcalRecHitsTask Barrel Log10 Energy", "EcalRecHitsTask Barrel Log10 Energy", 90, -5., 4.);
171  meEBRecHitLog10EnergyContr_ = ibooker.bookProfile("EcalRecHits Barrel Log10En vs Hit Contribution",
172  "EcalRecHits Barrel Log10En vs Hit Contribution",
173  90,
174  -5.,
175  4.,
176  100,
177  0.,
178  1.);
179  meEBRecHitLog10Energy5x5Contr_ = ibooker.bookProfile("EcalRecHits Barrel Log10En5x5 vs Hit Contribution",
180  "EcalRecHits Barrel Log10En5x5 vs Hit Contribution",
181  90,
182  -5.,
183  4.,
184  100,
185  0.,
186  1.);
187 
188  histo = "EB Occupancy Flag=5 6";
189  meEBRecHitsOccupancyFlag5_6_ = ibooker.book2D(histo, histo, 170, -85., 85., 360, 0., 360.);
190  histo = "EB Occupancy Flag=8 9";
191  meEBRecHitsOccupancyFlag8_9_ = ibooker.book2D(histo, histo, 170, -85., 85., 360, 0., 360.);
192 
193  histo = "EcalRecHitsTask Barrel Reco Flags";
194  meEBRecHitFlags_ = ibooker.book1D(histo.c_str(), histo.c_str(), 10, 0., 10.);
195  histo = "EcalRecHitsTask Barrel RecSimHit Ratio vs SimHit Flag=5 6";
196  meEBRecHitSimHitvsSimHitFlag5_6_ = ibooker.book2D(histo.c_str(), histo.c_str(), 80, 0., 2., 4000, 0., 400.);
197  histo = "EcalRecHitsTask Barrel RecSimHit Ratio Flag=6";
198  meEBRecHitSimHitFlag6_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
199  histo = "EcalRecHitsTask Barrel RecSimHit Ratio Flag=7";
200  meEBRecHitSimHitFlag7_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
201  histo = "EcalRecHitsTask Barrel 5x5 RecSimHit Ratio vs SimHit Flag=8";
202  meEB5x5RecHitSimHitvsSimHitFlag8_ = ibooker.book2D(histo.c_str(), histo.c_str(), 80, 0., 2., 4000, 0., 400.);
203 
204  if (enableEndcaps_) {
205  histo = "EcalRecHitsTask Preshower RecSimHit Ratio";
206  meESRecHitSimHitRatio_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
207 
208  histo = "EcalRecHitsTask Endcap RecSimHit Ratio";
209  meEERecHitSimHitRatio_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
210 
211  histo = "EcalRecHitsTask Endcap RecSimHit Ratio gt 3p5 GeV";
212  meEERecHitSimHitRatioGt35_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
213 
214  histo = "EcalRecHitsTask Endcap Unc RecSimHit Ratio";
215  meEEUnRecHitSimHitRatio_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
216 
217  histo = "EcalRecHitsTask Endcap RecSimHit Ratio Channel Status=10 11";
218  meEERecHitSimHitRatio1011_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
219 
220  histo = "EcalRecHitsTask Endcap RecSimHit Ratio Channel Status=12";
221  meEERecHitSimHitRatio12_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
222 
223  histo = "EcalRecHitsTask Endcap RecSimHit Ratio Channel Status=13";
224  meEERecHitSimHitRatio13_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
225 
226  histo = "EcalRecHitsTask Endcap Unc RecSimHit Ratio gt 3p5 GeV";
227  meEEUnRecHitSimHitRatioGt35_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
228 
229  histo = "EcalRecHitsTask Endcap Rec E5x5";
230  meEEe5x5_ = ibooker.book1D(histo.c_str(), histo.c_str(), 4000, 0., 400.);
231 
232  histo = "EcalRecHitsTask Endcap Rec E5x5 over Sim E5x5";
233  meEEe5x5OverSimHits_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
234 
235  histo = "EcalRecHitsTask Endcap Rec E5x5 over gun energy";
236  meEEe5x5OverGun_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
237 
239  ibooker.book1D("EcalRecHitsTask Endcap Log10 Energy", "EcalRecHitsTask Endcap Log10 Energy", 90, -5., 4.);
241  ibooker.book1D("EcalRecHitsTask Preshower Log10 Energy", "EcalRecHitsTask Preshower Log10 Energy", 90, -5., 4.);
242 
243  meEERecHitLog10EnergyContr_ = ibooker.bookProfile("EcalRecHits Endcap Log10En vs Hit Contribution",
244  "EcalRecHits Endcap Log10En vs Hit Contribution",
245  90,
246  -5.,
247  4.,
248  100,
249  0.,
250  1.);
251  meESRecHitLog10EnergyContr_ = ibooker.bookProfile("EcalRecHits Preshower Log10En vs Hit Contribution",
252  "EcalRecHits Preshower Log10En vs Hit Contribution",
253  90,
254  -5.,
255  4.,
256  100,
257  0.,
258  1.);
259 
260  meEERecHitLog10Energy5x5Contr_ = ibooker.bookProfile("EcalRecHits Endcap Log10En5x5 vs Hit Contribution",
261  "EcalRecHits Endcap Log10En5x5 vs Hit Contribution",
262  90,
263  -5.,
264  4.,
265  100,
266  0.,
267  1.);
268 
269  histo = "EE+ Occupancy Flag=5 6";
270  meEERecHitsOccupancyPlusFlag5_6_ = ibooker.book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
271  histo = "EE- Occupancy Flag=5 6";
272  meEERecHitsOccupancyMinusFlag5_6_ = ibooker.book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
273  histo = "EE+ Occupancy Flag=8 9";
274  meEERecHitsOccupancyPlusFlag8_9_ = ibooker.book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
275  histo = "EE- Occupancy Flag=8 9";
276  meEERecHitsOccupancyMinusFlag8_9_ = ibooker.book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
277 
278  histo = "EcalRecHitsTask Endcap Reco Flags";
279  meEERecHitFlags_ = ibooker.book1D(histo.c_str(), histo.c_str(), 10, 0., 10.);
280 
281  histo = "EcalRecHitsTask Endcap RecSimHit Ratio vs SimHit Flag=5 6";
282  meEERecHitSimHitvsSimHitFlag5_6_ = ibooker.book2D(histo.c_str(), histo.c_str(), 80, 0., 2., 4000, 0., 400.);
283 
284  histo = "EcalRecHitsTask Endcap RecSimHit Ratio Flag=6";
285  meEERecHitSimHitFlag6_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
286 
287  histo = "EcalRecHitsTask Endcap RecSimHit Ratio Flag=7";
288  meEERecHitSimHitFlag7_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
289  }
290 }
291 
293  // Temporary stuff
294 
295  LogInfo("EcalRecHitsTask, EventInfo: ") << " Run = " << e.id().run() << " Event = " << e.id().event();
296 
297  // ADC -> GeV Scale
298  const EcalADCToGeVConstant *agc = &c.getData(pAgc);
299  const double barrelADCtoGeV_ = agc->getEBValue();
300  const double endcapADCtoGeV_ = agc->getEEValue();
301 
302  Handle<HepMCProduct> MCEvt;
303  bool skipMC = false;
304  e.getByToken(HepMCLabel_Token_, MCEvt);
305  if (!MCEvt.isValid()) {
306  skipMC = true;
307  }
308 
310 
311  bool skipBarrel = false;
313  Handle<EBUncalibratedRecHitCollection> EcalUncalibRecHitEB;
314  e.getByToken(EBuncalibrechitCollection_Token_, EcalUncalibRecHitEB);
315  if (EcalUncalibRecHitEB.isValid()) {
316  EBUncalibRecHit = EcalUncalibRecHitEB.product();
317  } else {
318  skipBarrel = true;
319  }
320 
321  bool skipEndcap = false;
323  Handle<EEUncalibratedRecHitCollection> EcalUncalibRecHitEE;
324  if (enableEndcaps_) {
325  e.getByToken(EEuncalibrechitCollection_Token_, EcalUncalibRecHitEE);
326  if (EcalUncalibRecHitEE.isValid()) {
327  EEUncalibRecHit = EcalUncalibRecHitEE.product();
328  } else {
329  skipEndcap = true;
330  }
331  } else
332  skipEndcap = true;
333 
334  const EBRecHitCollection *EBRecHit = nullptr;
335  Handle<EBRecHitCollection> EcalRecHitEB;
336  e.getByToken(EBrechitCollection_Token_, EcalRecHitEB);
337  if (EcalRecHitEB.isValid()) {
338  EBRecHit = EcalRecHitEB.product();
339  } else {
340  skipBarrel = true;
341  }
342 
343  const EERecHitCollection *EERecHit = nullptr;
344  Handle<EERecHitCollection> EcalRecHitEE;
345  if (enableEndcaps_) {
346  e.getByToken(EErechitCollection_Token_, EcalRecHitEE);
347  if (EcalRecHitEE.isValid()) {
348  EERecHit = EcalRecHitEE.product();
349  } else {
350  skipEndcap = true;
351  }
352  }
353 
354  bool skipPreshower = false;
355  const ESRecHitCollection *ESRecHit = nullptr;
356  Handle<ESRecHitCollection> EcalRecHitES;
357  if (enableEndcaps_) {
358  e.getByToken(ESrechitCollection_Token_, EcalRecHitES);
359  if (EcalRecHitES.isValid()) {
360  ESRecHit = EcalRecHitES.product();
361  } else {
362  skipPreshower = true;
363  }
364  } else
365  skipPreshower = true;
366 
367  // ----------------------
368  // gun
369  double eGun = 0.;
370  if (!skipMC) {
371  for (HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
372  p != MCEvt->GetEvent()->particles_end();
373  ++p) {
374  double htheta = (*p)->momentum().theta();
375  double heta = -99999.;
376  if (tan(htheta * 0.5) > 0) {
377  heta = -log(tan(htheta * 0.5));
378  }
379  double hphi = (*p)->momentum().phi();
380  hphi = (hphi >= 0) ? hphi : hphi + 2 * M_PI;
381  hphi = hphi / M_PI * 180.;
382 
383  LogDebug("EventInfo") << "EcalRecHitsTask: Particle gun type form MC = " << abs((*p)->pdg_id()) << "\n"
384  << "Energy = " << (*p)->momentum().e() << "\n"
385  << "Eta = " << heta << "\n"
386  << "Phi = " << hphi;
387 
388  if ((*p)->momentum().e() > eGun)
389  eGun = (*p)->momentum().e();
390 
391  if (meGunEnergy_)
392  meGunEnergy_->Fill((*p)->momentum().e());
393  if (meGunEta_)
394  meGunEta_->Fill(heta);
395  if (meGunPhi_)
396  meGunPhi_->Fill(hphi);
397  }
398  }
399 
400  // -------------------------------------------------------------------
401  // BARREL
402 
403  if (!skipBarrel) {
404  // 1) loop over simHits
405  e.getByToken(EBHits_Token_, crossingFrame);
406  const MixCollection<PCaloHit> barrelHits(crossingFrame.product());
407 
408  MapType ebSimMap;
409  MapType ebRecMap;
410  const int ebcSize = 90;
411  double ebcontr[ebcSize];
412  double ebcontr25[ebcSize];
413  for (int i = 0; i < ebcSize; i++) {
414  ebcontr[i] = 0.0;
415  ebcontr25[i] = 0.0;
416  }
417  double ebtotal = 0.;
418 
419  for (auto const &iHit : barrelHits) {
420  EBDetId ebid = EBDetId(iHit.id());
421 
422  LogDebug("SimHitInfo, barrel") << "CaloHit " << iHit.getName() << " DetID = " << iHit.id() << "\n"
423  << "Energy = " << iHit.energy() << " Time = " << iHit.time() << "\n"
424  << "EBDetId = " << ebid.ieta() << " " << ebid.iphi();
425 
426  uint32_t crystid = ebid.rawId();
427  ebSimMap[crystid] += iHit.energy();
428  }
429 
430  // 2) loop over RecHits
432  uncalibRecHit != EBUncalibRecHit->end();
433  ++uncalibRecHit) {
434  EBDetId EBid = EBDetId(uncalibRecHit->id());
435 
436  // Find corresponding recHit
437  EcalRecHitCollection::const_iterator myRecHit = EBRecHit->find(EBid);
438  if (myRecHit == EBRecHit->end())
439  continue;
440  ebRecMap[EBid.rawId()] += myRecHit->energy();
441 
442  // Fill log10(Energy) stuff...
443  ebtotal += myRecHit->energy();
444  if (myRecHit->energy() > 0) {
446  meEBRecHitLog10Energy_->Fill(log10(myRecHit->energy()));
447  int log10i = int((log10(myRecHit->energy()) + 5.) * 10.);
448  if (log10i >= 0 and log10i < ebcSize)
449  ebcontr[log10i] += myRecHit->energy();
450  }
451 
452  // comparison Rec/Sim hit
453  if (ebSimMap[EBid.rawId()] != 0.) {
454  double uncEnergy = uncalibRecHit->amplitude() * barrelADCtoGeV_;
456  meEBUnRecHitSimHitRatio_->Fill(uncEnergy / ebSimMap[EBid.rawId()]);
457  }
458  if (meEBUnRecHitSimHitRatioGt35_ && (myRecHit->energy() > 3.5)) {
459  meEBUnRecHitSimHitRatioGt35_->Fill(uncEnergy / ebSimMap[EBid.rawId()]);
460  }
461  }
462 
463  if (myRecHit != EBRecHit->end()) {
464  if (ebSimMap[EBid.rawId()] != 0.) {
466  meEBRecHitSimHitRatio_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
467  }
468  if (meEBRecHitSimHitRatioGt35_ && (myRecHit->energy() > 3.5)) {
469  meEBRecHitSimHitRatioGt35_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
470  }
471  uint16_t sc = 0;
472 
473  c.getData(pEcsToken);
474  auto pEcs = c.getHandle(pEcsToken);
475  const EcalChannelStatus *ecs = nullptr;
476  if (pEcs.isValid())
477  ecs = &c.getData(pEcsToken);
478  ;
479  if (ecs != nullptr) {
480  EcalChannelStatusMap::const_iterator csmi = ecs->find(EBid.rawId());
482  if (csmi != ecs->end())
483  csc = *csmi;
484  sc = csc.getStatusCode();
485  }
486 
487  if (meEBRecHitSimHitRatio1011_ != nullptr && (sc == 10 || sc == 11)) {
488  meEBRecHitSimHitRatio1011_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
489  }
490  if (meEBRecHitSimHitRatio12_ != nullptr && sc == 12) {
491  meEBRecHitSimHitRatio12_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
492  }
493 
494  auto pttMap = c.getHandle(pttMapToken);
495  const EcalTrigTowerConstituentsMap *ttMap = nullptr;
496  if (pttMap.isValid())
497  ttMap = &c.getData(pttMapToken);
498  double ttSimEnergy = 0;
499  if (ttMap != nullptr) {
500  EcalTrigTowerDetId ttDetId = EBid.tower();
501  std::vector<DetId> vid = ttMap->constituentsOf(ttDetId);
502  for (std::vector<DetId>::const_iterator dit = vid.begin(); dit != vid.end(); dit++) {
503  EBDetId ttEBid = EBDetId(*dit);
504  ttSimEnergy += ebSimMap[ttEBid.rawId()];
505  }
506  if (!vid.empty())
507  ttSimEnergy = ttSimEnergy / vid.size();
508  }
509  if (meEBRecHitSimHitRatio13_ != nullptr && sc == 13 && ttSimEnergy != 0)
510  meEBRecHitSimHitRatio13_->Fill(myRecHit->energy() / ttSimEnergy);
511 
512  int flag = myRecHit->recoFlag();
513  if (meEBRecHitFlags_ != nullptr)
517  meEBRecHitSimHitvsSimHitFlag5_6_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()], ebSimMap[EBid.rawId()]);
519  meEBRecHitSimHitFlag6_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
521  meEBRecHitSimHitFlag6_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
523  meEB5x5RecHitSimHitvsSimHitFlag8_->Fill(myRecHit->energy() / ttSimEnergy, ttSimEnergy);
524 
527  meEBRecHitsOccupancyFlag5_6_->Fill(EBid.ieta(), EBid.iphi());
529  meEBRecHitsOccupancyFlag8_9_->Fill(EBid.ieta(), EBid.iphi());
530  }
531  } else
532  continue;
533  } // loop over the UncalibratedRecHitCollection
534 
535  // RecHits matrix
536  uint32_t ebcenterid = getUnitWithMaxEnergy(ebRecMap);
537  EBDetId myEBid(ebcenterid);
538  int bx = myEBid.ietaAbs();
539  int by = myEBid.iphi();
540  int bz = myEBid.zside();
541  findBarrelMatrix(5, 5, bx, by, bz, ebRecMap);
542  double e5x5rec = 0.;
543  double e5x5sim = 0.;
544  for (unsigned int i = 0; i < crystalMatrix.size(); i++) {
545  e5x5rec += ebRecMap[crystalMatrix[i]];
546  e5x5sim += ebSimMap[crystalMatrix[i]];
547  if (ebRecMap[crystalMatrix[i]] > 0) {
548  int log10i25 = int((log10(ebRecMap[crystalMatrix[i]]) + 5.) * 10.);
549  if (log10i25 >= 0 && log10i25 < ebcSize)
550  ebcontr25[log10i25] += ebRecMap[crystalMatrix[i]];
551  }
552  }
553 
554  if (meEBe5x5_)
555  meEBe5x5_->Fill(e5x5rec);
556  if (e5x5sim > 0. && meEBe5x5OverSimHits_)
557  meEBe5x5OverSimHits_->Fill(e5x5rec / e5x5sim);
558  if (eGun > 0. && meEBe5x5OverGun_)
559  meEBe5x5OverGun_->Fill(e5x5rec / eGun);
560 
561  if (meEBRecHitLog10EnergyContr_ && ebtotal != 0) {
562  for (int i = 0; i < ebcSize; i++) {
563  meEBRecHitLog10EnergyContr_->Fill(-5. + (float(i) + 0.5) / 10., ebcontr[i] / ebtotal);
564  }
565  }
566 
567  if (meEBRecHitLog10Energy5x5Contr_ && e5x5rec != 0) {
568  for (int i = 0; i < ebcSize; i++) {
569  meEBRecHitLog10Energy5x5Contr_->Fill(-5. + (float(i) + 0.5) / 10., ebcontr25[i] / e5x5rec);
570  }
571  }
572  }
573 
574  // -------------------------------------------------------------------
575  // ENDCAP
576 
577  if (!skipEndcap) {
578  // 1) loop over simHits
579  e.getByToken(EEHits_Token_, crossingFrame);
580  const MixCollection<PCaloHit> endcapHits(crossingFrame.product());
581 
582  MapType eeSimMap;
583  MapType eeRecMap;
584  const int eecSize = 90;
585  double eecontr[eecSize];
586  double eecontr25[eecSize];
587  for (int i = 0; i < eecSize; i++) {
588  eecontr[i] = 0.0;
589  eecontr25[i] = 0.0;
590  }
591  double eetotal = 0.;
592 
593  for (auto const &iHit : endcapHits) {
594  EEDetId eeid(iHit.id());
595 
596  LogDebug("Endcap, HitInfo") << " CaloHit " << iHit.getName() << " DetID = " << iHit.id() << "\n"
597  << "Energy = " << iHit.energy() << " Time = " << iHit.time() << "\n"
598  << "EEDetId side " << eeid.zside() << " = " << eeid.ix() << " " << eeid.iy();
599 
600  uint32_t crystid = eeid.rawId();
601  eeSimMap[crystid] += iHit.energy();
602  }
603 
604  // 2) loop over RecHits
606  uncalibRecHit != EEUncalibRecHit->end();
607  ++uncalibRecHit) {
608  EEDetId EEid = EEDetId(uncalibRecHit->id());
609 
610  // Find corresponding recHit
611  EcalRecHitCollection::const_iterator myRecHit = EERecHit->find(EEid);
612  if (myRecHit == EERecHit->end())
613  continue;
614  eeRecMap[EEid.rawId()] += myRecHit->energy();
615 
616  // Fill log10(Energy) stuff...
617  eetotal += myRecHit->energy();
618  if (myRecHit->energy() > 0) {
620  meEERecHitLog10Energy_->Fill(log10(myRecHit->energy()));
621  int log10i = int((log10(myRecHit->energy()) + 5.) * 10.);
622  if (log10i >= 0 and log10i < eecSize)
623  eecontr[log10i] += myRecHit->energy();
624  }
625 
626  // comparison Rec/Sim hit
627  if (eeSimMap[EEid.rawId()] != 0.) {
628  double uncEnergy = uncalibRecHit->amplitude() * endcapADCtoGeV_;
630  meEEUnRecHitSimHitRatio_->Fill(uncEnergy / eeSimMap[EEid.rawId()]);
631  }
632  if (meEEUnRecHitSimHitRatioGt35_ && (myRecHit->energy() > 3.5)) {
633  meEEUnRecHitSimHitRatioGt35_->Fill(uncEnergy / eeSimMap[EEid.rawId()]);
634  }
635  }
636 
637  if (myRecHit != EERecHit->end()) {
638  if (eeSimMap[EEid.rawId()] != 0.) {
640  meEERecHitSimHitRatio_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
641  }
642  if (meEERecHitSimHitRatioGt35_ && (myRecHit->energy() > 3.5)) {
643  meEERecHitSimHitRatioGt35_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
644  }
645 
646  auto pEcs = c.getHandle(pEcsToken);
647  const EcalChannelStatus *ecs = nullptr;
648  if (pEcs.isValid())
649  ecs = &c.getData(pEcsToken);
650  if (ecs != nullptr) {
651  EcalChannelStatusMap::const_iterator csmi = ecs->find(EEid.rawId());
653  if (csmi != ecs->end())
654  csc = *csmi;
655  uint16_t sc = csc.getStatusCode();
656  if (meEERecHitSimHitRatio1011_ != nullptr && (sc == 10 || sc == 11)) {
657  meEERecHitSimHitRatio1011_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
658  }
659  if (meEERecHitSimHitRatio12_ != nullptr && sc == 12) {
660  meEERecHitSimHitRatio12_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
661  }
662  if (meEERecHitSimHitRatio13_ != nullptr && sc == 13) {
663  meEERecHitSimHitRatio13_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
664  }
665  }
666 
667  int flag = myRecHit->recoFlag();
668  if (meEERecHitFlags_ != nullptr)
672  meEERecHitSimHitvsSimHitFlag5_6_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()], eeSimMap[EEid.rawId()]);
674  meEERecHitSimHitFlag6_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
676  meEERecHitSimHitFlag6_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
677 
678  if (EEid.zside() > 0) {
681  meEERecHitsOccupancyPlusFlag5_6_->Fill(EEid.ix(), EEid.iy());
684  meEERecHitsOccupancyPlusFlag8_9_->Fill(EEid.ix(), EEid.iy());
685  }
686  if (EEid.zside() < 0) {
689  meEERecHitsOccupancyMinusFlag5_6_->Fill(EEid.ix(), EEid.iy());
692  meEERecHitsOccupancyMinusFlag8_9_->Fill(EEid.ix(), EEid.iy());
693  }
694  }
695  } else
696  continue;
697  } // loop over the UncalibratedechitCollection
698 
699  // RecHits matrix
700  uint32_t eecenterid = getUnitWithMaxEnergy(eeRecMap);
701  EEDetId myEEid(eecenterid);
702  int bx = myEEid.ix();
703  int by = myEEid.iy();
704  int bz = myEEid.zside();
705  findEndcapMatrix(5, 5, bx, by, bz, eeRecMap);
706  double e5x5rec = 0.;
707  double e5x5sim = 0.;
708  for (unsigned int i = 0; i < crystalMatrix.size(); i++) {
709  e5x5rec += eeRecMap[crystalMatrix[i]];
710  e5x5sim += eeSimMap[crystalMatrix[i]];
711  if (eeRecMap[crystalMatrix[i]] > 0) {
712  int log10i25 = int((log10(eeRecMap[crystalMatrix[i]]) + 5.) * 10.);
713  if (log10i25 >= 0 && log10i25 < eecSize)
714  eecontr25[log10i25] += eeRecMap[crystalMatrix[i]];
715  }
716  }
717 
718  if (meEEe5x5_)
719  meEEe5x5_->Fill(e5x5rec);
720  if (e5x5sim > 0. && meEEe5x5OverSimHits_)
721  meEEe5x5OverSimHits_->Fill(e5x5rec / e5x5sim);
722  if (eGun > 0. && meEEe5x5OverGun_)
723  meEEe5x5OverGun_->Fill(e5x5rec / eGun);
724 
725  if (meEERecHitLog10EnergyContr_ && eetotal != 0) {
726  for (int i = 0; i < eecSize; i++) {
727  meEERecHitLog10EnergyContr_->Fill(-5. + (float(i) + 0.5) / 10., eecontr[i] / eetotal);
728  }
729  }
730 
731  if (meEERecHitLog10Energy5x5Contr_ && e5x5rec != 0) {
732  for (int i = 0; i < eecSize; i++) {
733  meEERecHitLog10Energy5x5Contr_->Fill(-5. + (float(i) + 0.5) / 10., eecontr25[i] / e5x5rec);
734  }
735  }
736  }
737 
738  // -------------------------------------------------------------------
739  // PRESHOWER
740 
741  if (!skipPreshower) {
742  // 1) loop over simHits
743  e.getByToken(ESHits_Token_, crossingFrame);
744  const MixCollection<PCaloHit> preshowerHits(crossingFrame.product());
745 
746  MapType esSimMap;
747  const int escSize = 90;
748  double escontr[escSize];
749  for (int i = 0; i < escSize; i++) {
750  escontr[i] = 0.0;
751  }
752  double estotal = 0.;
753 
754  for (auto const &iHit : preshowerHits) {
755  ESDetId esid(iHit.id());
756  LogDebug("Preshower, HitInfo") << " CaloHit " << iHit.getName() << " DetID = " << iHit.id() << "\n"
757  << "Energy = " << iHit.energy() << " Time = " << iHit.time() << "\n"
758  << "ESDetId strip " << esid.strip() << " = " << esid.six() << " " << esid.siy();
759 
760  uint32_t crystid = esid.rawId();
761  esSimMap[crystid] += iHit.energy();
762  }
763 
764  // 2) loop over RecHits
765  for (EcalRecHitCollection::const_iterator recHit = ESRecHit->begin(); recHit != ESRecHit->end(); ++recHit) {
766  ESDetId ESid = ESDetId(recHit->id());
767  if (esSimMap[ESid.rawId()] != 0.) {
768  // Fill log10(Energy) stuff...
769  estotal += recHit->energy();
770  if (recHit->energy() > 0) {
772  meESRecHitLog10Energy_->Fill(log10(recHit->energy()));
773  int log10i = int((log10(recHit->energy()) + 5.) * 10.);
774  if (log10i >= 0 and log10i < escSize)
775  escontr[log10i] += recHit->energy();
776  }
777 
779  meESRecHitSimHitRatio_->Fill(recHit->energy() / esSimMap[ESid.rawId()]);
780  }
781  } else
782  continue;
783  } // loop over the RechitCollection
784 
785  if (meESRecHitLog10EnergyContr_ && estotal != 0) {
786  for (int i = 0; i < escSize; i++) {
787  meESRecHitLog10EnergyContr_->Fill(-5. + (float(i) + 0.5) / 10., escontr[i] / estotal);
788  }
789  }
790  }
791 }
792 
794  // look for max
795  uint32_t unitWithMaxEnergy = 0;
796  float maxEnergy = 0.;
797 
798  MapType::iterator iter;
799  for (iter = themap.begin(); iter != themap.end(); iter++) {
800  if (maxEnergy < (*iter).second) {
801  maxEnergy = (*iter).second;
802  unitWithMaxEnergy = (*iter).first;
803  }
804  }
805 
806  return unitWithMaxEnergy;
807 }
808 
810  int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &themap) {
811  int goBackInEta = nCellInEta / 2;
812  int goBackInPhi = nCellInPhi / 2;
813  int matrixSize = nCellInEta * nCellInPhi;
814  crystalMatrix.clear();
815  crystalMatrix.resize(matrixSize);
816 
817  int startEta = CentralZ * CentralEta - goBackInEta;
818  int startPhi = CentralPhi - goBackInPhi;
819 
820  int i = 0;
821  for (int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
822  for (int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
823  uint32_t index;
824  if (abs(ieta) > 85 || abs(ieta) < 1) {
825  continue;
826  }
827  if (iphi < 1) {
828  index = EBDetId(ieta, iphi + 360).rawId();
829  } else if (iphi > 360) {
830  index = EBDetId(ieta, iphi - 360).rawId();
831  } else {
832  index = EBDetId(ieta, iphi).rawId();
833  }
834  crystalMatrix[i++] = index;
835  }
836  }
837 }
838 
840  int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &themap) {
841  int goBackInX = nCellInX / 2;
842  int goBackInY = nCellInY / 2;
843  crystalMatrix.clear();
844 
845  int startX = CentralX - goBackInX;
846  int startY = CentralY - goBackInY;
847 
848  for (int ix = startX; ix < startX + nCellInX; ix++) {
849  for (int iy = startY; iy < startY + nCellInY; iy++) {
850  uint32_t index;
851 
852  if (EEDetId::validDetId(ix, iy, CentralZ)) {
853  index = EEDetId(ix, iy, CentralZ).rawId();
854  } else {
855  continue;
856  }
857  crystalMatrix.push_back(index);
858  }
859  }
860 }
MonitorElement * meEERecHitsOccupancyPlusFlag5_6_
MonitorElement * meEBRecHitSimHitRatio13_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
MonitorElement * meEBRecHitLog10Energy5x5Contr_
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:47
MonitorElement * meEBRecHitSimHitRatio1011_
MonitorElement * meEBRecHitSimHitFlag7_
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
MonitorElement * meEBRecHitSimHitRatio12_
std::vector< DetId > constituentsOf(const EcalTrigTowerDetId &id) const
Get the constituent detids for this tower id.
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
EcalRecHitsValidation(const edm::ParameterSet &ps)
Constructor.
edm::EDGetTokenT< CrossingFrame< PCaloHit > > ESHits_Token_
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
MonitorElement * meEERecHitSimHitRatio12_
T const * product() const
Definition: Handle.h:70
int ix() const
Definition: EEDetId.h:77
std::vector< T >::const_iterator const_iterator
MonitorElement * meEERecHitsOccupancyMinusFlag5_6_
edm::EDGetTokenT< ESRecHitCollection > ESrechitCollection_Token_
MonitorElement * meEERecHitSimHitRatio13_
MonitorElement * meEBe5x5OverSimHits_
uint32_t getUnitWithMaxEnergy(MapType &themap)
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > pttMapToken
MonitorElement * meEBRecHitSimHitFlag6_
edm::EDGetTokenT< CrossingFrame< PCaloHit > > EBHits_Token_
MonitorElement * meEB5x5RecHitSimHitvsSimHitFlag8_
edm::EDGetTokenT< EERecHitCollection > EErechitCollection_Token_
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
edm::InputTag EBuncalibrechitCollection_
std::map< uint32_t, float, std::less< uint32_t > > MapType
~EcalRecHitsValidation() override
Destructor.
MonitorElement * meEBUnRecHitSimHitRatio_
MonitorElement * meEBRecHitLog10EnergyContr_
void findEndcapMatrix(int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &themap)
MonitorElement * meEBRecHitsOccupancyFlag8_9_
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
MonitorElement * meEERecHitLog10EnergyContr_
MonitorElement * meGunEnergy_
MonitorElement * meEERecHitsOccupancyMinusFlag8_9_
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * meEERecHitFlags_
const_iterator begin() const
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
MonitorElement * meEERecHitSimHitFlag6_
MonitorElement * meEEUnRecHitSimHitRatioGt35_
MonitorElement * meEEUnRecHitSimHitRatio_
Definition: L1Track.h:19
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
const_iterator find(uint32_t rawId) const
MonitorElement * meEERecHitSimHitRatioGt35_
edm::InputTag EEuncalibrechitCollection_
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
#define M_PI
MonitorElement * meEERecHitSimHitFlag7_
Namespace of DDCMS conversion namespace.
const_iterator end() const
MonitorElement * meEBRecHitSimHitRatioGt35_
edm::EDGetTokenT< EEUncalibratedRecHitCollection > EEuncalibrechitCollection_Token_
Log< level::Info, false > LogInfo
edm::EDGetTokenT< EBRecHitCollection > EBrechitCollection_Token_
MonitorElement * meESRecHitLog10Energy_
int zside() const
Definition: EEDetId.h:71
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
MonitorElement * meEBRecHitSimHitvsSimHitFlag5_6_
edm::ESGetToken< EcalChannelStatus, EcalChannelStatusRcd > pEcsToken
std::vector< Item >::const_iterator const_iterator
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
MonitorElement * meEERecHitSimHitvsSimHitFlag5_6_
MonitorElement * meEBRecHitFlags_
MonitorElement * meEERecHitLog10Energy_
bool isValid() const
Definition: HandleBase.h:70
MonitorElement * meEBRecHitLog10Energy_
edm::EDGetTokenT< EBUncalibratedRecHitCollection > EBuncalibrechitCollection_Token_
HLT enums.
edm::ESGetToken< EcalADCToGeVConstant, EcalADCToGeVConstantRcd > pAgc
MonitorElement * meEBUnRecHitSimHitRatioGt35_
void findBarrelMatrix(int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &themap)
std::vector< uint32_t > crystalMatrix
MonitorElement * meEERecHitLog10Energy5x5Contr_
MonitorElement * meESRecHitLog10EnergyContr_
edm::EDGetTokenT< CrossingFrame< PCaloHit > > EEHits_Token_
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
const_iterator end() const
MonitorElement * meEERecHitsOccupancyPlusFlag8_9_
MonitorElement * meESRecHitSimHitRatio_
MonitorElement * meEBRecHitSimHitRatio_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MonitorElement * meEBRecHitsOccupancyFlag5_6_
MonitorElement * meEEe5x5OverGun_
MonitorElement * meEERecHitSimHitRatio1011_
MonitorElement * meEEe5x5OverSimHits_
edm::EDGetTokenT< edm::HepMCProduct > HepMCLabel_Token_
MonitorElement * meEBe5x5OverGun_
Definition: Run.h:45
int iy() const
Definition: EEDetId.h:83
#define LogDebug(id)
MonitorElement * meEERecHitSimHitRatio_