CMS 3D CMS Logo

EcalBarrelSimHitsValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalBarrelSimHitsValidation.cc
3  *
4  * \author C.Rovelli
5  *
6  */
7 
12 
13 using namespace cms;
14 using namespace edm;
15 using namespace std;
16 
18  : g4InfoLabel(ps.getParameter<std::string>("moduleLabelG4")),
19  EBHitsCollection(ps.getParameter<std::string>("EBHitsCollection")),
20  ValidationCollection(ps.getParameter<std::string>("ValidationCollection")) {
21  EBHitsToken =
22  consumes<edm::PCaloHitContainer>(edm::InputTag(std::string(g4InfoLabel), std::string(EBHitsCollection)));
25  // verbosity switch
26  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
27 
28  // get hold of back-end interface
29  dbe_ = nullptr;
30  dbe_ = edm::Service<DQMStore>().operator->();
31 
32  if (dbe_) {
33  if (verbose_)
34  dbe_->showDirStructure();
35  }
36 
37  menEBHits_ = nullptr;
38  menEBCrystals_ = nullptr;
39  meEBOccupancy_ = nullptr;
40  meEBLongitudinalShower_ = nullptr;
41  meEBhitEnergy_ = nullptr;
42  meEBhitLog10Energy_ = nullptr;
43  meEBhitLog10EnergyNorm_ = nullptr;
44  meEBhitLog10Energy25Norm_ = nullptr;
45  meEBhitEnergy2_ = nullptr;
46  meEBcrystalEnergy_ = nullptr;
47  meEBcrystalEnergy2_ = nullptr;
48 
49  meEBe1_ = nullptr;
50  meEBe4_ = nullptr;
51  meEBe9_ = nullptr;
52  meEBe16_ = nullptr;
53  meEBe25_ = nullptr;
54 
55  meEBe1oe4_ = nullptr;
56  meEBe1oe9_ = nullptr;
57  meEBe4oe9_ = nullptr;
58  meEBe9oe16_ = nullptr;
59  meEBe1oe25_ = nullptr;
60  meEBe9oe25_ = nullptr;
61  meEBe16oe25_ = nullptr;
62 
63  myEntries = 0;
64  for (int myStep = 0; myStep < 26; myStep++) {
65  eRLength[myStep] = 0.0;
66  }
67 
68  Char_t histo[200];
69 
70  if (dbe_) {
71  dbe_->setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
72 
73  sprintf(histo, "EB hits multiplicity");
74  menEBHits_ = dbe_->book1D(histo, histo, 50, 0., 5000.);
75 
76  sprintf(histo, "EB crystals multiplicity");
77  menEBCrystals_ = dbe_->book1D(histo, histo, 200, 0., 2000.);
78 
79  sprintf(histo, "EB occupancy");
80  meEBOccupancy_ = dbe_->book2D(histo, histo, 360, 0., 360., 170, -85., 85.);
81 
82  sprintf(histo, "EB longitudinal shower profile");
83  meEBLongitudinalShower_ = dbe_->bookProfile(histo, histo, 26, 0., 26., 100, 0., 20000.);
84 
85  sprintf(histo, "EB hits energy spectrum");
86  meEBhitEnergy_ = dbe_->book1D(histo, histo, 4000, 0., 400.);
87 
88  sprintf(histo, "EB hits log10energy spectrum");
89  meEBhitLog10Energy_ = dbe_->book1D(histo, histo, 140, -10., 4.);
90 
91  sprintf(histo, "EB hits log10energy spectrum vs normalized energy");
92  meEBhitLog10EnergyNorm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
93 
94  sprintf(histo, "EB hits log10energy spectrum vs normalized energy25");
95  meEBhitLog10Energy25Norm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
96 
97  sprintf(histo, "EB hits energy spectrum 2");
98  meEBhitEnergy2_ = dbe_->book1D(histo, histo, 1000, 0., 0.001);
99 
100  sprintf(histo, "EB crystal energy spectrum");
101  meEBcrystalEnergy_ = dbe_->book1D(histo, histo, 5000, 0., 50.);
102 
103  sprintf(histo, "EB crystal energy spectrum 2");
104  meEBcrystalEnergy2_ = dbe_->book1D(histo, histo, 1000, 0., 0.001);
105 
106  sprintf(histo, "EB E1");
107  meEBe1_ = dbe_->book1D(histo, histo, 400, 0., 400.);
108 
109  sprintf(histo, "EB E4");
110  meEBe4_ = dbe_->book1D(histo, histo, 400, 0., 400.);
111 
112  sprintf(histo, "EB E9");
113  meEBe9_ = dbe_->book1D(histo, histo, 400, 0., 400.);
114 
115  sprintf(histo, "EB E16");
116  meEBe16_ = dbe_->book1D(histo, histo, 400, 0., 400.);
117 
118  sprintf(histo, "EB E25");
119  meEBe25_ = dbe_->book1D(histo, histo, 400, 0., 400.);
120 
121  sprintf(histo, "EB E1oE4");
122  meEBe1oe4_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
123 
124  sprintf(histo, "EB E1oE9");
125  meEBe1oe9_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
126 
127  sprintf(histo, "EB E4oE9");
128  meEBe4oe9_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
129 
130  sprintf(histo, "EB E9oE16");
131  meEBe9oe16_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
132 
133  sprintf(histo, "EB E1oE25");
134  meEBe1oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
135 
136  sprintf(histo, "EB E9oE25");
137  meEBe9oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
138 
139  sprintf(histo, "EB E16oE25");
140  meEBe16oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
141  }
142 }
143 
145 
147 
149  // for (int myStep=0; myStep<26; myStep++){
150  // if (meEBLongitudinalShower_) meEBLongitudinalShower_->Fill(float(myStep),
151  // eRLength[myStep]/myEntries);
152  //}
153 }
154 
156  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
157 
159  e.getByToken(EBHitsToken, EcalHitsEB);
160 
161  // Do nothing if no Barrel data available
162  if (!EcalHitsEB.isValid())
163  return;
164 
165  edm::Handle<PEcalValidInfo> MyPEcalValidInfo;
166  e.getByToken(ValidationCollectionToken, MyPEcalValidInfo);
167 
168  std::vector<PCaloHit> theEBCaloHits;
169  theEBCaloHits.insert(theEBCaloHits.end(), EcalHitsEB->begin(), EcalHitsEB->end());
170 
171  myEntries++;
172 
173  double EBEnergy_ = 0.;
174  std::map<unsigned int, std::vector<PCaloHit *>, std::less<unsigned int>> CaloHitMap;
175 
176  double eb1 = 0.0;
177  double eb4 = 0.0;
178  double eb9 = 0.0;
179  double eb16 = 0.0;
180  double eb25 = 0.0;
181  std::vector<double> econtr(140, 0.);
182  std::vector<double> econtr25(140, 0.);
183 
184  MapType ebmap;
185  uint32_t nEBHits = 0;
186 
187  for (std::vector<PCaloHit>::iterator isim = theEBCaloHits.begin(); isim != theEBCaloHits.end(); ++isim) {
188  if (isim->time() > 500.) {
189  continue;
190  }
191 
192  CaloHitMap[isim->id()].push_back(&(*isim));
193 
194  EBDetId ebid(isim->id());
195 
196  LogDebug("HitInfo") << " CaloHit " << isim->getName() << "\n"
197  << " DetID = " << isim->id() << " EBDetId = " << ebid.ieta() << " " << ebid.iphi() << "\n"
198  << " Time = " << isim->time() << "\n"
199  << " Track Id = " << isim->geantTrackId() << "\n"
200  << " Energy = " << isim->energy();
201 
202  if (meEBOccupancy_)
203  meEBOccupancy_->Fill(ebid.iphi(), ebid.ieta());
204 
205  uint32_t crystid = ebid.rawId();
206  ebmap[crystid] += isim->energy();
207 
208  EBEnergy_ += isim->energy();
209  nEBHits++;
210  meEBhitEnergy_->Fill(isim->energy());
211  if (isim->energy() > 0) {
212  meEBhitLog10Energy_->Fill(log10(isim->energy()));
213  int log10i = int((log10(isim->energy()) + 10.) * 10.);
214  if (log10i >= 0 && log10i < 140)
215  econtr[log10i] += isim->energy();
216  }
217  meEBhitEnergy2_->Fill(isim->energy());
218  }
219 
220  if (menEBCrystals_)
221  menEBCrystals_->Fill(ebmap.size());
222  if (meEBcrystalEnergy_) {
223  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = ebmap.begin(); it != ebmap.end(); ++it)
224  meEBcrystalEnergy_->Fill((*it).second);
225  }
226  if (meEBcrystalEnergy2_) {
227  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = ebmap.begin(); it != ebmap.end(); ++it)
228  meEBcrystalEnergy2_->Fill((*it).second);
229  }
230 
231  if (menEBHits_)
232  menEBHits_->Fill(nEBHits);
233 
234  if (nEBHits > 0) {
235  uint32_t ebcenterid = getUnitWithMaxEnergy(ebmap);
236  EBDetId myEBid(ebcenterid);
237  int bx = myEBid.ietaAbs();
238  int by = myEBid.iphi();
239  int bz = myEBid.zside();
240  eb1 = energyInMatrixEB(1, 1, bx, by, bz, ebmap);
241  if (meEBe1_)
242  meEBe1_->Fill(eb1);
243  eb9 = energyInMatrixEB(3, 3, bx, by, bz, ebmap);
244  if (meEBe9_)
245  meEBe9_->Fill(eb9);
246  eb25 = energyInMatrixEB(5, 5, bx, by, bz, ebmap);
247  if (meEBe25_)
248  meEBe25_->Fill(eb25);
249 
250  std::vector<uint32_t> ids25;
251  ids25 = getIdsAroundMax(5, 5, bx, by, bz, ebmap);
252 
253  for (unsigned i = 0; i < 25; i++) {
254  for (unsigned int j = 0; j < CaloHitMap[ids25[i]].size(); j++) {
255  if (CaloHitMap[ids25[i]][j]->energy() > 0) {
256  int log10i = int((log10(CaloHitMap[ids25[i]][j]->energy()) + 10.) * 10.);
257  if (log10i >= 0 && log10i < 140)
258  econtr25[log10i] += CaloHitMap[ids25[i]][j]->energy();
259  }
260  }
261  }
262 
263  MapType newebmap;
264  if (fillEBMatrix(3, 3, bx, by, bz, newebmap, ebmap)) {
265  eb4 = eCluster2x2(newebmap);
266  if (meEBe4_)
267  meEBe4_->Fill(eb4);
268  }
269  if (fillEBMatrix(5, 5, bx, by, bz, newebmap, ebmap)) {
270  eb16 = eCluster4x4(eb9, newebmap);
271  if (meEBe16_)
272  meEBe16_->Fill(eb16);
273  }
274 
275  if (meEBe1oe4_ && eb4 > 0.1)
276  meEBe1oe4_->Fill(eb1 / eb4);
277  if (meEBe1oe9_ && eb9 > 0.1)
278  meEBe1oe9_->Fill(eb1 / eb9);
279  if (meEBe4oe9_ && eb9 > 0.1)
280  meEBe4oe9_->Fill(eb4 / eb9);
281  if (meEBe9oe16_ && eb16 > 0.1)
282  meEBe9oe16_->Fill(eb9 / eb16);
283  if (meEBe1oe25_ && eb25 > 0.1)
284  meEBe1oe25_->Fill(eb1 / eb25);
285  if (meEBe9oe25_ && eb25 > 0.1)
286  meEBe9oe25_->Fill(eb9 / eb25);
287  if (meEBe16oe25_ && eb25 > 0.1)
288  meEBe16oe25_->Fill(eb16 / eb25);
289 
290  if (meEBhitLog10EnergyNorm_ && EBEnergy_ != 0) {
291  for (int i = 0; i < 140; i++) {
292  meEBhitLog10EnergyNorm_->Fill(-10. + (float(i) + 0.5) / 10., econtr[i] / EBEnergy_);
293  }
294  }
295 
296  if (meEBhitLog10Energy25Norm_ && eb25 != 0) {
297  for (int i = 0; i < 140; i++) {
298  meEBhitLog10Energy25Norm_->Fill(-10. + (float(i) + 0.5) / 10., econtr25[i] / eb25);
299  }
300  }
301  }
302 
303  if (MyPEcalValidInfo.isValid()) {
304  if (MyPEcalValidInfo->eb1x1() > 0.) {
305  std::vector<float> BX0 = MyPEcalValidInfo->bX0();
308  for (int myStep = 0; myStep < 26; myStep++) {
309  eRLength[myStep] += BX0[myStep];
311  meEBLongitudinalShower_->Fill(float(myStep), eRLength[myStep] / myEntries);
312  }
313  }
314  }
315 }
316 
318  int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap) {
319  int ncristals = 0;
320  float totalEnergy = 0.;
321 
322  int goBackInEta = nCellInEta / 2;
323  int goBackInPhi = nCellInPhi / 2;
324  int startEta = centralZ * centralEta - goBackInEta;
325  int startPhi = centralPhi - goBackInPhi;
326 
327  for (int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
328  for (int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
329  uint32_t index;
330  if (abs(ieta) > 85 || abs(ieta) < 1) {
331  continue;
332  }
333  if (iphi < 1) {
334  index = EBDetId(ieta, iphi + 360).rawId();
335  } else if (iphi > 360) {
336  index = EBDetId(ieta, iphi - 360).rawId();
337  } else {
338  index = EBDetId(ieta, iphi).rawId();
339  }
340 
341  totalEnergy += themap[index];
342  ncristals += 1;
343  }
344  }
345 
346  LogDebug("GeomInfo") << nCellInEta << " x " << nCellInPhi << " EB matrix energy = " << totalEnergy << " for "
347  << ncristals << " crystals";
348  return totalEnergy;
349 }
350 
352  int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap) {
353  int ncristals = 0;
354  std::vector<uint32_t> ids(nCellInEta * nCellInPhi);
355 
356  int goBackInEta = nCellInEta / 2;
357  int goBackInPhi = nCellInPhi / 2;
358  int startEta = centralZ * centralEta - goBackInEta;
359  int startPhi = centralPhi - goBackInPhi;
360 
361  for (int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
362  for (int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
363  uint32_t index;
364  if (abs(ieta) > 85 || abs(ieta) < 1) {
365  continue;
366  }
367  if (iphi < 1) {
368  index = EBDetId(ieta, iphi + 360).rawId();
369  } else if (iphi > 360) {
370  index = EBDetId(ieta, iphi - 360).rawId();
371  } else {
372  index = EBDetId(ieta, iphi).rawId();
373  }
374  ids[ncristals] = index;
375  ncristals += 1;
376  }
377  }
378 
379  return ids;
380 }
381 
383  int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &fillmap, MapType &themap) {
384  int goBackInEta = nCellInEta / 2;
385  int goBackInPhi = nCellInPhi / 2;
386 
387  int startEta = CentralZ * CentralEta - goBackInEta;
388  int startPhi = CentralPhi - goBackInPhi;
389 
390  int i = 0;
391  for (int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
392  for (int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
393  uint32_t index;
394  if (abs(ieta) > 85 || abs(ieta) < 1) {
395  continue;
396  }
397  if (iphi < 1) {
398  index = EBDetId(ieta, iphi + 360).rawId();
399  } else if (iphi > 360) {
400  index = EBDetId(ieta, iphi - 360).rawId();
401  } else {
402  index = EBDetId(ieta, iphi).rawId();
403  }
404  fillmap[i++] = themap[index];
405  }
406  }
407 
408  uint32_t ebcenterid = getUnitWithMaxEnergy(themap);
409 
410  if (fillmap[i / 2] == themap[ebcenterid])
411  return true;
412  else
413  return false;
414 }
415 
417  float E22 = 0.;
418  float e012 = themap[0] + themap[1] + themap[2];
419  float e036 = themap[0] + themap[3] + themap[6];
420  float e678 = themap[6] + themap[7] + themap[8];
421  float e258 = themap[2] + themap[5] + themap[8];
422 
423  if ((e012 > e678 || e012 == e678) && (e036 > e258 || e036 == e258))
424  return E22 = themap[0] + themap[1] + themap[3] + themap[4];
425  else if ((e012 > e678 || e012 == e678) && (e036 < e258 || e036 == e258))
426  return E22 = themap[1] + themap[2] + themap[4] + themap[5];
427  else if ((e012 < e678 || e012 == e678) && (e036 > e258 || e036 == e258))
428  return E22 = themap[3] + themap[4] + themap[6] + themap[7];
429  else if ((e012 < e678 || e012 == e678) && (e036 < e258 || e036 == e258))
430  return E22 = themap[4] + themap[5] + themap[7] + themap[8];
431  else {
432  return E22;
433  }
434 }
435 
437  float E44 = 0.;
438  float e0_4 = themap[0] + themap[1] + themap[2] + themap[3] + themap[4];
439  float e0_20 = themap[0] + themap[5] + themap[10] + themap[15] + themap[20];
440  float e4_24 = themap[4] + themap[9] + themap[14] + themap[19] + themap[24];
441  float e0_24 = themap[20] + themap[21] + themap[22] + themap[23] + themap[24];
442 
443  if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
444  return E44 = e33 + themap[0] + themap[1] + themap[2] + themap[3] + themap[5] + themap[10] + themap[15];
445  else if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
446  return E44 = e33 + themap[1] + themap[2] + themap[3] + themap[4] + themap[9] + themap[14] + themap[19];
447  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
448  return E44 = e33 + themap[5] + themap[10] + themap[15] + themap[20] + themap[21] + themap[22] + themap[23];
449  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
450  return E44 = e33 + themap[21] + themap[22] + themap[23] + themap[24] + themap[9] + themap[14] + themap[19];
451  else {
452  return E44;
453  }
454 }
455 
457  // look for max
458  uint32_t unitWithMaxEnergy = 0;
459  float maxEnergy = 0.;
460 
461  MapType::iterator iter;
462  for (iter = themap.begin(); iter != themap.end(); iter++) {
463  if (maxEnergy < (*iter).second) {
464  maxEnergy = (*iter).second;
465  unitWithMaxEnergy = (*iter).first;
466  }
467  }
468 
469  LogDebug("GeomInfo") << " max energy of " << maxEnergy << " GeV in Unit id " << unitWithMaxEnergy;
470  return unitWithMaxEnergy;
471 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:38
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
std::vector< uint32_t > getIdsAroundMax(int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
float eb1x1() const
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
void Fill(long long x)
virtual void Reset()
reset ME (ie. contents, errors, etc)
float eCluster4x4(float e33, MapType &themap)
~EcalBarrelSimHitsValidation() override
Destructor.
std::map< uint32_t, float, std::less< uint32_t > > MapType
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< edm::PCaloHitContainer > EBHitsToken
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< PEcalValidInfo > ValidationCollectionToken
uint32_t getUnitWithMaxEnergy(MapType &themap)
Namespace of DDCMS conversion namespace.
virtual float energyInMatrixEB(int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap)
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
bool fillEBMatrix(int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &fillmap, MapType &themap)
FloatVector bX0() const
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:47
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
EcalBarrelSimHitsValidation(const edm::ParameterSet &ps)
Constructor.