CMS 3D CMS Logo

EcalEndcapSimHitsValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalEndcapSimHitsValidation.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  EEHitsCollection(ps.getParameter<std::string>("EEHitsCollection")),
20  ValidationCollection(ps.getParameter<std::string>("ValidationCollection")) {
21  EEHitsToken =
22  consumes<edm::PCaloHitContainer>(edm::InputTag(std::string(g4InfoLabel), std::string(EEHitsCollection)));
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  if (dbe_) {
32  if (verbose_) {
33  dbe_->setVerbose(1);
34  } else {
35  dbe_->setVerbose(0);
36  }
37  }
38 
39  if (dbe_) {
40  if (verbose_)
41  dbe_->showDirStructure();
42  }
43 
44  meEEzpHits_ = nullptr;
45  meEEzmHits_ = nullptr;
46  meEEzpCrystals_ = nullptr;
47  meEEzmCrystals_ = nullptr;
48  meEEzpOccupancy_ = nullptr;
49  meEEzmOccupancy_ = nullptr;
50  meEELongitudinalShower_ = nullptr;
51  meEEHitEnergy_ = nullptr;
52  meEEhitLog10Energy_ = nullptr;
53  meEEhitLog10EnergyNorm_ = nullptr;
54  meEEhitLog10Energy25Norm_ = nullptr;
55  meEEHitEnergy2_ = nullptr;
56  meEEcrystalEnergy_ = nullptr;
57  meEEcrystalEnergy2_ = nullptr;
58 
59  meEEe1_ = nullptr;
60  meEEe4_ = nullptr;
61  meEEe9_ = nullptr;
62  meEEe16_ = nullptr;
63  meEEe25_ = nullptr;
64 
65  meEEe1oe4_ = nullptr;
66  meEEe1oe9_ = nullptr;
67  meEEe4oe9_ = nullptr;
68  meEEe9oe16_ = nullptr;
69  meEEe1oe25_ = nullptr;
70  meEEe9oe25_ = nullptr;
71  meEEe16oe25_ = nullptr;
72 
73  myEntries = 0;
74  for (int myStep = 0; myStep < 26; myStep++) {
75  eRLength[myStep] = 0.0;
76  }
77 
78  Char_t histo[200];
79 
80  if (dbe_) {
81  dbe_->setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
82 
83  sprintf(histo, "EE+ hits multiplicity");
84  meEEzpHits_ = dbe_->book1D(histo, histo, 50, 0., 5000.);
85 
86  sprintf(histo, "EE- hits multiplicity");
87  meEEzmHits_ = dbe_->book1D(histo, histo, 50, 0., 5000.);
88 
89  sprintf(histo, "EE+ crystals multiplicity");
90  meEEzpCrystals_ = dbe_->book1D(histo, histo, 200, 0., 2000.);
91 
92  sprintf(histo, "EE- crystals multiplicity");
93  meEEzmCrystals_ = dbe_->book1D(histo, histo, 200, 0., 2000.);
94 
95  sprintf(histo, "EE+ occupancy");
96  meEEzpOccupancy_ = dbe_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
97 
98  sprintf(histo, "EE- occupancy");
99  meEEzmOccupancy_ = dbe_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
100 
101  sprintf(histo, "EE longitudinal shower profile");
102  meEELongitudinalShower_ = dbe_->bookProfile(histo, histo, 26, 0, 26, 100, 0, 20000);
103 
104  sprintf(histo, "EE hits energy spectrum");
105  meEEHitEnergy_ = dbe_->book1D(histo, histo, 4000, 0., 400.);
106 
107  sprintf(histo, "EE hits log10energy spectrum");
108  meEEhitLog10Energy_ = dbe_->book1D(histo, histo, 140, -10., 4.);
109 
110  sprintf(histo, "EE hits log10energy spectrum vs normalized energy");
111  meEEhitLog10EnergyNorm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
112 
113  sprintf(histo, "EE hits log10energy spectrum vs normalized energy25");
114  meEEhitLog10Energy25Norm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
115 
116  sprintf(histo, "EE hits energy spectrum 2");
117  meEEHitEnergy2_ = dbe_->book1D(histo, histo, 1000, 0., 0.001);
118 
119  sprintf(histo, "EE crystal energy spectrum");
120  meEEcrystalEnergy_ = dbe_->book1D(histo, histo, 5000, 0., 50.);
121 
122  sprintf(histo, "EE crystal energy spectrum 2");
123  meEEcrystalEnergy2_ = dbe_->book1D(histo, histo, 1000, 0., 0.001);
124 
125  sprintf(histo, "EE E1");
126  meEEe1_ = dbe_->book1D(histo, histo, 400, 0., 400.);
127 
128  sprintf(histo, "EE E4");
129  meEEe4_ = dbe_->book1D(histo, histo, 400, 0., 400.);
130 
131  sprintf(histo, "EE E9");
132  meEEe9_ = dbe_->book1D(histo, histo, 400, 0., 400.);
133 
134  sprintf(histo, "EE E16");
135  meEEe16_ = dbe_->book1D(histo, histo, 400, 0., 400.);
136 
137  sprintf(histo, "EE E25");
138  meEEe25_ = dbe_->book1D(histo, histo, 400, 0., 400.);
139 
140  sprintf(histo, "EE E1oE4");
141  meEEe1oe4_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
142 
143  sprintf(histo, "EE E1oE9");
144  meEEe1oe9_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
145 
146  sprintf(histo, "EE E4oE9");
147  meEEe4oe9_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
148 
149  sprintf(histo, "EE E9oE16");
150  meEEe9oe16_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
151 
152  sprintf(histo, "EE E1oE25");
153  meEEe1oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
154 
155  sprintf(histo, "EE E9oE25");
156  meEEe9oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
157 
158  sprintf(histo, "EE E16oE25");
159  meEEe16oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
160  }
161 }
162 
164 
166 
168  // for ( int myStep = 0; myStep<26; myStep++){
169  // if (meEELongitudinalShower_) meEELongitudinalShower_->Fill(float(myStep),
170  // eRLength[myStep]/myEntries);
171  //}
172 }
173 
175  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
176 
178  e.getByToken(EEHitsToken, EcalHitsEE);
179 
180  // Do nothing if no EndCap data available
181  if (!EcalHitsEE.isValid())
182  return;
183 
184  edm::Handle<PEcalValidInfo> MyPEcalValidInfo;
185  e.getByToken(ValidationCollectionToken, MyPEcalValidInfo);
186 
187  std::vector<PCaloHit> theEECaloHits;
188  theEECaloHits.insert(theEECaloHits.end(), EcalHitsEE->begin(), EcalHitsEE->end());
189 
190  myEntries++;
191 
192  std::map<unsigned int, std::vector<PCaloHit *>, std::less<unsigned int>> CaloHitMap;
193 
194  double EEetzp_ = 0.;
195  double EEetzm_ = 0.;
196 
197  double ee1 = 0.0;
198  double ee4 = 0.0;
199  double ee9 = 0.0;
200  double ee16 = 0.0;
201  double ee25 = 0.0;
202  std::vector<double> econtr(140, 0.);
203  std::vector<double> econtr25(140, 0.);
204 
205  MapType eemap;
206  MapType eemapzp;
207  MapType eemapzm;
208  uint32_t nEEzpHits = 0;
209  uint32_t nEEzmHits = 0;
210 
211  for (std::vector<PCaloHit>::iterator isim = theEECaloHits.begin(); isim != theEECaloHits.end(); ++isim) {
212  if (isim->time() > 500.) {
213  continue;
214  }
215 
216  CaloHitMap[isim->id()].push_back(&(*isim));
217 
218  EEDetId eeid(isim->id());
219 
220  LogDebug("HitInfo") << " CaloHit " << isim->getName() << "\n"
221  << " DetID = " << isim->id() << " EEDetId = " << eeid.ix() << " " << eeid.iy() << "\n"
222  << " Time = " << isim->time() << "\n"
223  << " Track Id = " << isim->geantTrackId() << "\n"
224  << " Energy = " << isim->energy();
225 
226  uint32_t crystid = eeid.rawId();
227 
228  if (eeid.zside() > 0) {
229  nEEzpHits++;
230  EEetzp_ += isim->energy();
231  eemapzp[crystid] += isim->energy();
232  if (meEEzpOccupancy_)
233  meEEzpOccupancy_->Fill(eeid.ix(), eeid.iy());
234  } else if (eeid.zside() < 0) {
235  nEEzmHits++;
236  EEetzm_ += isim->energy();
237  eemapzm[crystid] += isim->energy();
238  if (meEEzmOccupancy_)
239  meEEzmOccupancy_->Fill(eeid.ix(), eeid.iy());
240  }
241 
242  if (meEEHitEnergy_)
243  meEEHitEnergy_->Fill(isim->energy());
244  if (isim->energy() > 0) {
246  meEEhitLog10Energy_->Fill(log10(isim->energy()));
247  int log10i = int((log10(isim->energy()) + 10.) * 10.);
248  if (log10i >= 0 && log10i < 140)
249  econtr[log10i] += isim->energy();
250  }
251  if (meEEHitEnergy2_)
252  meEEHitEnergy2_->Fill(isim->energy());
253  eemap[crystid] += isim->energy();
254  }
255 
256  if (meEEzpCrystals_)
257  meEEzpCrystals_->Fill(eemapzp.size());
258  if (meEEzmCrystals_)
259  meEEzmCrystals_->Fill(eemapzm.size());
260 
261  if (meEEcrystalEnergy_) {
262  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = eemap.begin(); it != eemap.end(); ++it)
263  meEEcrystalEnergy_->Fill((*it).second);
264  }
265  if (meEEcrystalEnergy2_) {
266  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = eemap.begin(); it != eemap.end(); ++it)
267  meEEcrystalEnergy2_->Fill((*it).second);
268  }
269 
270  if (meEEzpHits_)
271  meEEzpHits_->Fill(nEEzpHits);
272  if (meEEzmHits_)
273  meEEzmHits_->Fill(nEEzmHits);
274 
275  int nEEHits = nEEzmHits + nEEzpHits;
276  if (nEEHits > 0) {
277  uint32_t eecenterid = getUnitWithMaxEnergy(eemap);
278  EEDetId myEEid(eecenterid);
279  int bx = myEEid.ix();
280  int by = myEEid.iy();
281  int bz = myEEid.zside();
282  ee1 = energyInMatrixEE(1, 1, bx, by, bz, eemap);
283  if (meEEe1_)
284  meEEe1_->Fill(ee1);
285  ee9 = energyInMatrixEE(3, 3, bx, by, bz, eemap);
286  if (meEEe9_)
287  meEEe9_->Fill(ee9);
288  ee25 = energyInMatrixEE(5, 5, bx, by, bz, eemap);
289  if (meEEe25_)
290  meEEe25_->Fill(ee25);
291 
292  std::vector<uint32_t> ids25;
293  ids25 = getIdsAroundMax(5, 5, bx, by, bz, eemap);
294 
295  for (unsigned i = 0; i < 25; i++) {
296  for (unsigned int j = 0; j < CaloHitMap[ids25[i]].size(); j++) {
297  if (CaloHitMap[ids25[i]][j]->energy() > 0) {
298  int log10i = int((log10(CaloHitMap[ids25[i]][j]->energy()) + 10.) * 10.);
299  if (log10i >= 0 && log10i < 140)
300  econtr25[log10i] += CaloHitMap[ids25[i]][j]->energy();
301  }
302  }
303  }
304 
305  MapType neweemap;
306  if (fillEEMatrix(3, 3, bx, by, bz, neweemap, eemap)) {
307  ee4 = eCluster2x2(neweemap);
308  if (meEEe4_)
309  meEEe4_->Fill(ee4);
310  }
311  if (fillEEMatrix(5, 5, bx, by, bz, neweemap, eemap)) {
312  ee16 = eCluster4x4(ee9, neweemap);
313  if (meEEe16_)
314  meEEe16_->Fill(ee16);
315  }
316 
317  if (meEEe1oe4_ && ee4 > 0.1)
318  meEEe1oe4_->Fill(ee1 / ee4);
319  if (meEEe1oe9_ && ee9 > 0.1)
320  meEEe1oe9_->Fill(ee1 / ee9);
321  if (meEEe4oe9_ && ee9 > 0.1)
322  meEEe4oe9_->Fill(ee4 / ee9);
323  if (meEEe9oe16_ && ee16 > 0.1)
324  meEEe9oe16_->Fill(ee9 / ee16);
325  if (meEEe16oe25_ && ee25 > 0.1)
326  meEEe16oe25_->Fill(ee16 / ee25);
327  if (meEEe1oe25_ && ee25 > 0.1)
328  meEEe1oe25_->Fill(ee1 / ee25);
329  if (meEEe9oe25_ && ee25 > 0.1)
330  meEEe9oe25_->Fill(ee9 / ee25);
331 
332  if (meEEhitLog10EnergyNorm_ && (EEetzp_ + EEetzm_) != 0) {
333  for (int i = 0; i < 140; i++) {
334  meEEhitLog10EnergyNorm_->Fill(-10. + (float(i) + 0.5) / 10., econtr[i] / (EEetzp_ + EEetzm_));
335  }
336  }
337 
338  if (meEEhitLog10Energy25Norm_ && ee25 != 0) {
339  for (int i = 0; i < 140; i++) {
340  meEEhitLog10Energy25Norm_->Fill(-10. + (float(i) + 0.5) / 10., econtr25[i] / ee25);
341  }
342  }
343  }
344 
345  if (MyPEcalValidInfo.isValid()) {
346  if (MyPEcalValidInfo->ee1x1() > 0.) {
347  std::vector<float> EX0 = MyPEcalValidInfo->eX0();
350  for (int myStep = 0; myStep < 26; myStep++) {
351  eRLength[myStep] += EX0[myStep];
353  meEELongitudinalShower_->Fill(float(myStep), eRLength[myStep] / myEntries);
354  }
355  }
356  }
357 }
358 
360  int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap) {
361  int ncristals = 0;
362  float totalEnergy = 0.;
363 
364  int goBackInX = nCellInX / 2;
365  int goBackInY = nCellInY / 2;
366  int startX = centralX - goBackInX;
367  int startY = centralY - goBackInY;
368 
369  for (int ix = startX; ix < startX + nCellInX; ix++) {
370  for (int iy = startY; iy < startY + nCellInY; iy++) {
371  uint32_t index;
372 
373  if (EEDetId::validDetId(ix, iy, centralZ)) {
374  index = EEDetId(ix, iy, centralZ).rawId();
375  } else {
376  continue;
377  }
378 
379  totalEnergy += themap[index];
380  ncristals += 1;
381  }
382  }
383 
384  LogDebug("GeomInfo") << nCellInX << " x " << nCellInY << " EE matrix energy = " << totalEnergy << " for " << ncristals
385  << " crystals";
386  return totalEnergy;
387 }
388 
390  int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap) {
391  int ncristals = 0;
392  std::vector<uint32_t> ids(nCellInX * nCellInY);
393 
394  int goBackInX = nCellInX / 2;
395  int goBackInY = nCellInY / 2;
396  int startX = centralX - goBackInX;
397  int startY = centralY - goBackInY;
398 
399  for (int ix = startX; ix < startX + nCellInX; ix++) {
400  for (int iy = startY; iy < startY + nCellInY; iy++) {
401  uint32_t index;
402 
403  if (EEDetId::validDetId(ix, iy, centralZ)) {
404  index = EEDetId(ix, iy, centralZ).rawId();
405  } else {
406  continue;
407  }
408 
409  ids[ncristals] = index;
410  ncristals += 1;
411  }
412  }
413 
414  return ids;
415 }
416 
418  int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &fillmap, MapType &themap) {
419  int goBackInX = nCellInX / 2;
420  int goBackInY = nCellInY / 2;
421 
422  int startX = CentralX - goBackInX;
423  int startY = CentralY - goBackInY;
424 
425  int i = 0;
426  for (int ix = startX; ix < startX + nCellInX; ix++) {
427  for (int iy = startY; iy < startY + nCellInY; iy++) {
428  uint32_t index;
429 
430  if (EEDetId::validDetId(ix, iy, CentralZ)) {
431  index = EEDetId(ix, iy, CentralZ).rawId();
432  } else {
433  continue;
434  }
435  fillmap[i++] = themap[index];
436  }
437  }
438  uint32_t centerid = getUnitWithMaxEnergy(themap);
439 
440  if (fillmap[i / 2] == themap[centerid])
441  return true;
442  else
443  return false;
444 }
445 
447  float E22 = 0.;
448  float e012 = themap[0] + themap[1] + themap[2];
449  float e036 = themap[0] + themap[3] + themap[6];
450  float e678 = themap[6] + themap[7] + themap[8];
451  float e258 = themap[2] + themap[5] + themap[8];
452 
453  if ((e012 > e678 || e012 == e678) && (e036 > e258 || e036 == e258))
454  return E22 = themap[0] + themap[1] + themap[3] + themap[4];
455  else if ((e012 > e678 || e012 == e678) && (e036 < e258 || e036 == e258))
456  return E22 = themap[1] + themap[2] + themap[4] + themap[5];
457  else if ((e012 < e678 || e012 == e678) && (e036 > e258 || e036 == e258))
458  return E22 = themap[3] + themap[4] + themap[6] + themap[7];
459  else if ((e012 < e678 || e012 == e678) && (e036 < e258 || e036 == e258))
460  return E22 = themap[4] + themap[5] + themap[7] + themap[8];
461  else {
462  return E22;
463  }
464 }
465 
467  float E44 = 0.;
468  float e0_4 = themap[0] + themap[1] + themap[2] + themap[3] + themap[4];
469  float e0_20 = themap[0] + themap[5] + themap[10] + themap[15] + themap[20];
470  float e4_24 = themap[4] + themap[9] + themap[14] + themap[19] + themap[24];
471  float e0_24 = themap[20] + themap[21] + themap[22] + themap[23] + themap[24];
472 
473  if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
474  return E44 = e33 + themap[0] + themap[1] + themap[2] + themap[3] + themap[5] + themap[10] + themap[15];
475  else if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
476  return E44 = e33 + themap[1] + themap[2] + themap[3] + themap[4] + themap[9] + themap[14] + themap[19];
477  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
478  return E44 = e33 + themap[5] + themap[10] + themap[15] + themap[20] + themap[21] + themap[22] + themap[23];
479  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
480  return E44 = e33 + themap[21] + themap[22] + themap[23] + themap[24] + themap[9] + themap[14] + themap[19];
481  else {
482  return E44;
483  }
484 }
485 
487  // look for max
488  uint32_t unitWithMaxEnergy = 0;
489  float maxEnergy = 0.;
490 
491  MapType::iterator iter;
492  for (iter = themap.begin(); iter != themap.end(); iter++) {
493  if (maxEnergy < (*iter).second) {
494  maxEnergy = (*iter).second;
495  unitWithMaxEnergy = (*iter).first;
496  }
497  }
498 
499  LogDebug("GeomInfo") << " max energy of " << maxEnergy << " GeV in Unit id " << unitWithMaxEnergy;
500  return unitWithMaxEnergy;
501 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int ix() const
Definition: EEDetId.h:77
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
~EcalEndcapSimHitsValidation() override
Destructor.
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
edm::EDGetTokenT< PEcalValidInfo > ValidationCollectionToken
virtual float energyInMatrixEE(int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap)
void Fill(long long x)
std::map< uint32_t, float, std::less< uint32_t > > MapType
float eCluster4x4(float e33, MapType &themap)
int zside() const
Definition: EEDetId.h:71
int iy() const
Definition: EEDetId.h:83
void Reset()
reset ME (ie. contents, errors, etc)
bool isValid() const
Definition: HandleBase.h:74
bool fillEEMatrix(int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &fillmap, MapType &themap)
Namespace of DDCMS conversion namespace.
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
edm::EDGetTokenT< edm::PCaloHitContainer > EEHitsToken
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
uint32_t getUnitWithMaxEnergy(MapType &themap)
FloatVector eX0() const
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
float ee1x1() const
std::vector< uint32_t > getIdsAroundMax(int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap)
EcalEndcapSimHitsValidation(const edm::ParameterSet &ps)
Constructor.