CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  myEntries = 0;
29  for (int myStep = 0; myStep < 26; myStep++) {
30  eRLength[myStep] = 0.0;
31  }
32 }
33 
35  ib.setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
36  ib.setScope(MonitorElementData::Scope::RUN);
37 
38  std::string histo = "EE+ hits multiplicity";
39  meEEzpHits_ = ib.book1D(histo, histo, 50, 0., 5000.);
40 
41  histo = "EE- hits multiplicity";
42  meEEzmHits_ = ib.book1D(histo, histo, 50, 0., 5000.);
43 
44  histo = "EE+ crystals multiplicity";
45  meEEzpCrystals_ = ib.book1D(histo, histo, 200, 0., 2000.);
46 
47  histo = "EE- crystals multiplicity";
48  meEEzmCrystals_ = ib.book1D(histo, histo, 200, 0., 2000.);
49 
50  histo = "EE+ occupancy";
51  meEEzpOccupancy_ = ib.book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
52 
53  histo = "EE- occupancy";
54  meEEzmOccupancy_ = ib.book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
55 
56  histo = "EE longitudinal shower profile";
57  meEELongitudinalShower_ = ib.bookProfile(histo, histo, 26, 0, 26, 100, 0, 20000);
58 
59  histo = "EE hits energy spectrum";
60  meEEHitEnergy_ = ib.book1D(histo, histo, 4000, 0., 400.);
61 
62  histo = "EE hits log10energy spectrum";
63  meEEhitLog10Energy_ = ib.book1D(histo, histo, 140, -10., 4.);
64 
65  histo = "EE hits log10energy spectrum vs normalized energy";
66  meEEhitLog10EnergyNorm_ = ib.bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
67 
68  histo = "EE hits log10energy spectrum vs normalized energy25";
69  meEEhitLog10Energy25Norm_ = ib.bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
70 
71  histo = "EE hits energy spectrum 2";
72  meEEHitEnergy2_ = ib.book1D(histo, histo, 1000, 0., 0.001);
73 
74  histo = "EE crystal energy spectrum";
75  meEEcrystalEnergy_ = ib.book1D(histo, histo, 5000, 0., 50.);
76 
77  histo = "EE crystal energy spectrum 2";
78  meEEcrystalEnergy2_ = ib.book1D(histo, histo, 1000, 0., 0.001);
79 
80  histo = "EE E1";
81  meEEe1_ = ib.book1D(histo, histo, 400, 0., 400.);
82 
83  histo = "EE E4";
84  meEEe4_ = ib.book1D(histo, histo, 400, 0., 400.);
85 
86  histo = "EE E9";
87  meEEe9_ = ib.book1D(histo, histo, 400, 0., 400.);
88 
89  histo = "EE E16";
90  meEEe16_ = ib.book1D(histo, histo, 400, 0., 400.);
91 
92  histo = "EE E25";
93  meEEe25_ = ib.book1D(histo, histo, 400, 0., 400.);
94 
95  histo = "EE E1oE4";
96  meEEe1oe4_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
97 
98  histo = "EE E1oE9";
99  meEEe1oe9_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
100 
101  histo = "EE E4oE9";
102  meEEe4oe9_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
103 
104  histo = "EE E9oE16";
105  meEEe9oe16_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
106 
107  histo = "EE E1oE25";
108  meEEe1oe25_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
109 
110  histo = "EE E9oE25";
111  meEEe9oe25_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
112 
113  histo = "EE E16oE25";
114  meEEe16oe25_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
115 }
116 
118  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
119 
121  e.getByToken(EEHitsToken, EcalHitsEE);
122 
123  // Do nothing if no EndCap data available
124  if (!EcalHitsEE.isValid())
125  return;
126 
127  edm::Handle<PEcalValidInfo> MyPEcalValidInfo;
128  e.getByToken(ValidationCollectionToken, MyPEcalValidInfo);
129 
130  std::vector<PCaloHit> theEECaloHits;
131  theEECaloHits.insert(theEECaloHits.end(), EcalHitsEE->begin(), EcalHitsEE->end());
132 
133  myEntries++;
134 
135  std::map<unsigned int, std::vector<PCaloHit *>, std::less<unsigned int>> CaloHitMap;
136 
137  double EEetzp_ = 0.;
138  double EEetzm_ = 0.;
139 
140  double ee1 = 0.0;
141  double ee4 = 0.0;
142  double ee9 = 0.0;
143  double ee16 = 0.0;
144  double ee25 = 0.0;
145  std::vector<double> econtr(140, 0.);
146  std::vector<double> econtr25(140, 0.);
147 
148  MapType eemap;
149  MapType eemapzp;
150  MapType eemapzm;
151  uint32_t nEEzpHits = 0;
152  uint32_t nEEzmHits = 0;
153 
154  for (std::vector<PCaloHit>::iterator isim = theEECaloHits.begin(); isim != theEECaloHits.end(); ++isim) {
155  if (isim->time() > 500.) {
156  continue;
157  }
158 
159  CaloHitMap[isim->id()].push_back(&(*isim));
160 
161  EEDetId eeid(isim->id());
162 
163  LogDebug("HitInfo") << " CaloHit " << isim->getName() << "\n"
164  << " DetID = " << isim->id() << " EEDetId = " << eeid.ix() << " " << eeid.iy() << "\n"
165  << " Time = " << isim->time() << "\n"
166  << " Track Id = " << isim->geantTrackId() << "\n"
167  << " Energy = " << isim->energy();
168 
169  uint32_t crystid = eeid.rawId();
170 
171  if (eeid.zside() > 0) {
172  nEEzpHits++;
173  EEetzp_ += isim->energy();
174  eemapzp[crystid] += isim->energy();
175  meEEzpOccupancy_->Fill(eeid.ix(), eeid.iy());
176  } else if (eeid.zside() < 0) {
177  nEEzmHits++;
178  EEetzm_ += isim->energy();
179  eemapzm[crystid] += isim->energy();
180  meEEzmOccupancy_->Fill(eeid.ix(), eeid.iy());
181  }
182 
183  meEEHitEnergy_->Fill(isim->energy());
184  if (isim->energy() > 0) {
185  meEEhitLog10Energy_->Fill(log10(isim->energy()));
186  int log10i = int((log10(isim->energy()) + 10.) * 10.);
187  if (log10i >= 0 && log10i < 140)
188  econtr[log10i] += isim->energy();
189  }
190  meEEHitEnergy2_->Fill(isim->energy());
191  eemap[crystid] += isim->energy();
192  }
193 
194  meEEzpCrystals_->Fill(eemapzp.size());
195  meEEzmCrystals_->Fill(eemapzm.size());
196 
197  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = eemap.begin(); it != eemap.end(); ++it)
198  meEEcrystalEnergy_->Fill((*it).second);
199  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = eemap.begin(); it != eemap.end(); ++it)
200  meEEcrystalEnergy2_->Fill((*it).second);
201 
202  meEEzpHits_->Fill(nEEzpHits);
203  meEEzmHits_->Fill(nEEzmHits);
204 
205  int nEEHits = nEEzmHits + nEEzpHits;
206  if (nEEHits > 0) {
207  uint32_t eecenterid = getUnitWithMaxEnergy(eemap);
208  EEDetId myEEid(eecenterid);
209  int bx = myEEid.ix();
210  int by = myEEid.iy();
211  int bz = myEEid.zside();
212  ee1 = energyInMatrixEE(1, 1, bx, by, bz, eemap);
213  meEEe1_->Fill(ee1);
214  ee9 = energyInMatrixEE(3, 3, bx, by, bz, eemap);
215  meEEe9_->Fill(ee9);
216  ee25 = energyInMatrixEE(5, 5, bx, by, bz, eemap);
217  meEEe25_->Fill(ee25);
218 
219  std::vector<uint32_t> ids25;
220  ids25 = getIdsAroundMax(5, 5, bx, by, bz, eemap);
221 
222  for (unsigned i = 0; i < 25; i++) {
223  for (unsigned int j = 0; j < CaloHitMap[ids25[i]].size(); j++) {
224  if (CaloHitMap[ids25[i]][j]->energy() > 0) {
225  int log10i = int((log10(CaloHitMap[ids25[i]][j]->energy()) + 10.) * 10.);
226  if (log10i >= 0 && log10i < 140)
227  econtr25[log10i] += CaloHitMap[ids25[i]][j]->energy();
228  }
229  }
230  }
231 
232  MapType neweemap;
233  if (fillEEMatrix(3, 3, bx, by, bz, neweemap, eemap)) {
234  ee4 = eCluster2x2(neweemap);
235  meEEe4_->Fill(ee4);
236  }
237  if (fillEEMatrix(5, 5, bx, by, bz, neweemap, eemap)) {
238  ee16 = eCluster4x4(ee9, neweemap);
239  meEEe16_->Fill(ee16);
240  }
241 
242  if (ee4 > 0.1)
243  meEEe1oe4_->Fill(ee1 / ee4);
244  if (ee9 > 0.1)
245  meEEe1oe9_->Fill(ee1 / ee9);
246  if (ee9 > 0.1)
247  meEEe4oe9_->Fill(ee4 / ee9);
248  if (ee16 > 0.1)
249  meEEe9oe16_->Fill(ee9 / ee16);
250  if (ee25 > 0.1)
251  meEEe16oe25_->Fill(ee16 / ee25);
252  if (ee25 > 0.1)
253  meEEe1oe25_->Fill(ee1 / ee25);
254  if (ee25 > 0.1)
255  meEEe9oe25_->Fill(ee9 / ee25);
256 
257  if ((EEetzp_ + EEetzm_) != 0) {
258  for (int i = 0; i < 140; i++) {
259  meEEhitLog10EnergyNorm_->Fill(-10. + (float(i) + 0.5) / 10., econtr[i] / (EEetzp_ + EEetzm_));
260  }
261  }
262 
263  if (ee25 != 0) {
264  for (int i = 0; i < 140; i++) {
265  meEEhitLog10Energy25Norm_->Fill(-10. + (float(i) + 0.5) / 10., econtr25[i] / ee25);
266  }
267  }
268  }
269 
270  if (MyPEcalValidInfo.isValid()) {
271  if (MyPEcalValidInfo->ee1x1() > 0.) {
272  std::vector<float> EX0 = MyPEcalValidInfo->eX0();
274  for (int myStep = 0; myStep < 26; myStep++) {
275  eRLength[myStep] += EX0[myStep];
276  meEELongitudinalShower_->Fill(float(myStep), eRLength[myStep] / myEntries);
277  }
278  }
279  }
280 }
281 
283  int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap) {
284  int ncristals = 0;
285  float totalEnergy = 0.;
286 
287  int goBackInX = nCellInX / 2;
288  int goBackInY = nCellInY / 2;
289  int startX = centralX - goBackInX;
290  int startY = centralY - goBackInY;
291 
292  for (int ix = startX; ix < startX + nCellInX; ix++) {
293  for (int iy = startY; iy < startY + nCellInY; iy++) {
294  uint32_t index;
295 
296  if (EEDetId::validDetId(ix, iy, centralZ)) {
297  index = EEDetId(ix, iy, centralZ).rawId();
298  } else {
299  continue;
300  }
301 
302  totalEnergy += themap[index];
303  ncristals += 1;
304  }
305  }
306 
307  LogDebug("GeomInfo") << nCellInX << " x " << nCellInY << " EE matrix energy = " << totalEnergy << " for " << ncristals
308  << " crystals";
309  return totalEnergy;
310 }
311 
313  int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap) {
314  int ncristals = 0;
315  std::vector<uint32_t> ids(nCellInX * nCellInY);
316 
317  int goBackInX = nCellInX / 2;
318  int goBackInY = nCellInY / 2;
319  int startX = centralX - goBackInX;
320  int startY = centralY - goBackInY;
321 
322  for (int ix = startX; ix < startX + nCellInX; ix++) {
323  for (int iy = startY; iy < startY + nCellInY; iy++) {
324  uint32_t index;
325 
326  if (EEDetId::validDetId(ix, iy, centralZ)) {
327  index = EEDetId(ix, iy, centralZ).rawId();
328  } else {
329  continue;
330  }
331 
332  ids[ncristals] = index;
333  ncristals += 1;
334  }
335  }
336 
337  return ids;
338 }
339 
341  int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &fillmap, MapType &themap) {
342  int goBackInX = nCellInX / 2;
343  int goBackInY = nCellInY / 2;
344 
345  int startX = CentralX - goBackInX;
346  int startY = CentralY - goBackInY;
347 
348  int i = 0;
349  for (int ix = startX; ix < startX + nCellInX; ix++) {
350  for (int iy = startY; iy < startY + nCellInY; iy++) {
351  uint32_t index;
352 
353  if (EEDetId::validDetId(ix, iy, CentralZ)) {
354  index = EEDetId(ix, iy, CentralZ).rawId();
355  } else {
356  continue;
357  }
358  fillmap[i++] = themap[index];
359  }
360  }
361  uint32_t centerid = getUnitWithMaxEnergy(themap);
362 
363  if (fillmap[i / 2] == themap[centerid])
364  return true;
365  else
366  return false;
367 }
368 
370  float E22 = 0.;
371  float e012 = themap[0] + themap[1] + themap[2];
372  float e036 = themap[0] + themap[3] + themap[6];
373  float e678 = themap[6] + themap[7] + themap[8];
374  float e258 = themap[2] + themap[5] + themap[8];
375 
376  if ((e012 > e678 || e012 == e678) && (e036 > e258 || e036 == e258))
377  E22 = themap[0] + themap[1] + themap[3] + themap[4];
378  else if ((e012 > e678 || e012 == e678) && (e036 < e258 || e036 == e258))
379  E22 = themap[1] + themap[2] + themap[4] + themap[5];
380  else if ((e012 < e678 || e012 == e678) && (e036 > e258 || e036 == e258))
381  E22 = themap[3] + themap[4] + themap[6] + themap[7];
382  else if ((e012 < e678 || e012 == e678) && (e036 < e258 || e036 == e258))
383  E22 = themap[4] + themap[5] + themap[7] + themap[8];
384 
385  return E22;
386 }
387 
389  float E44 = 0.;
390  float e0_4 = themap[0] + themap[1] + themap[2] + themap[3] + themap[4];
391  float e0_20 = themap[0] + themap[5] + themap[10] + themap[15] + themap[20];
392  float e4_24 = themap[4] + themap[9] + themap[14] + themap[19] + themap[24];
393  float e0_24 = themap[20] + themap[21] + themap[22] + themap[23] + themap[24];
394 
395  if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
396  E44 = e33 + themap[0] + themap[1] + themap[2] + themap[3] + themap[5] + themap[10] + themap[15];
397  else if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
398  E44 = e33 + themap[1] + themap[2] + themap[3] + themap[4] + themap[9] + themap[14] + themap[19];
399  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
400  E44 = e33 + themap[5] + themap[10] + themap[15] + themap[20] + themap[21] + themap[22] + themap[23];
401  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
402  E44 = e33 + themap[21] + themap[22] + themap[23] + themap[24] + themap[9] + themap[14] + themap[19];
403 
404  return E44;
405 }
406 
408  // look for max
409  uint32_t unitWithMaxEnergy = 0;
410  float maxEnergy = 0.;
411 
412  MapType::iterator iter;
413  for (iter = themap.begin(); iter != themap.end(); iter++) {
414  if (maxEnergy < (*iter).second) {
415  maxEnergy = (*iter).second;
416  unitWithMaxEnergy = (*iter).first;
417  }
418  }
419 
420  LogDebug("GeomInfo") << " max energy of " << maxEnergy << " GeV in Unit id " << unitWithMaxEnergy;
421  return unitWithMaxEnergy;
422 }
RunNumber_t run() const
Definition: EventID.h:38
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
const edm::EventSetup & c
void bookHistograms(DQMStore::IBooker &ib, edm::Run const &, edm::EventSetup const &c) override
int ix() const
Definition: EEDetId.h:77
int ib
Definition: cuy.py:661
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
virtual MonitorElementData::Scope setScope(MonitorElementData::Scope newscope)
Definition: DQMStore.cc:46
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
edm::EDGetTokenT< PEcalValidInfo > ValidationCollectionToken
virtual float energyInMatrixEE(int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap)
std::map< uint32_t, float, std::less< uint32_t > > MapType
void Fill(long long x)
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
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
float eCluster4x4(float e33, MapType &themap)
int zside() const
Definition: EEDetId.h:71
int iy() const
Definition: EEDetId.h:83
bool isValid() const
Definition: HandleBase.h:70
bool fillEEMatrix(int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &fillmap, MapType &themap)
Log< level::Info, false > LogInfo
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
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
edm::EDGetTokenT< edm::PCaloHitContainer > EEHitsToken
edm::EventID id() const
Definition: EventBase.h:59
uint32_t getUnitWithMaxEnergy(MapType &themap)
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
std::vector< uint32_t > getIdsAroundMax(int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap)
Definition: Run.h:45
#define LogDebug(id)
EcalEndcapSimHitsValidation(const edm::ParameterSet &ps)
Constructor.