CMS 3D CMS Logo

SimHitsValidationHcal.cc
Go to the documentation of this file.
5 
6 #define DebugLog
7 
9 
10  g4Label_ = ps.getParameter<std::string>("ModuleLabel");
11  hcalHits_ = ps.getParameter<std::string>("HitCollection");
12  verbose_ = ps.getParameter<bool>("Verbose");
13  testNumber_= ps.getParameter<bool>("TestNumber");
14 
15  tok_hits_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_,hcalHits_));
16 
17  edm::LogInfo("HitsValidationHcal") << "Module Label: " << g4Label_
18  << " Hits: " << hcalHits_
19  << " TestNumbering " << testNumber_;
20 }
21 
23 
25 
27  es.get<HcalRecNumberingRecord>().get( pHRNDC );
28  hcons = &(*pHRNDC);
33 
34  //Get Phi segmentation from geometry, use the max phi number so that all iphi values are included.
35 
36  int NphiMax = hcons->getNPhi(0);
37 
38  NphiMax = (hcons->getNPhi(1) > NphiMax ? hcons->getNPhi(1) : NphiMax);
39  NphiMax = (hcons->getNPhi(2) > NphiMax ? hcons->getNPhi(2) : NphiMax);
40  NphiMax = (hcons->getNPhi(3) > NphiMax ? hcons->getNPhi(3) : NphiMax);
41 
42  //Center the iphi bins on the integers
43  float iphi_min = 0.5;
44  float iphi_max = NphiMax + 0.5;
45  int iphi_bins = (int) (iphi_max - iphi_min);
46 
47  int iEtaHBMax = hcons->getEtaRange(0).second;
48  int iEtaHEMax = hcons->getEtaRange(1).second;
49  int iEtaHFMax = hcons->getEtaRange(2).second;
50  int iEtaHOMax = hcons->getEtaRange(3).second;
51 
52  //Retain classic behavior, all plots have same ieta range.
53  //Comment out code to allow each subdetector to have its on range
54 
55  int iEtaMax = (iEtaHBMax > iEtaHEMax ? iEtaHBMax : iEtaHEMax);
56  iEtaMax = (iEtaMax > iEtaHFMax ? iEtaMax : iEtaHFMax);
57  iEtaMax = (iEtaMax > iEtaHOMax ? iEtaMax : iEtaHOMax);
58 
59  iEtaHBMax = iEtaMax;
60  iEtaHEMax = iEtaMax;
61  iEtaHFMax = iEtaMax;
62  iEtaHOMax = iEtaMax;
63 
64  //Give an empty bin around the subdet ieta range to make it clear that all ieta rings have been included
65  //float ieta_min_HB = -iEtaHBMax - 1.5;
66  //float ieta_max_HB = iEtaHBMax + 1.5;
67  //int ieta_bins_HB = (int) (ieta_max_HB - ieta_min_HB);
68 
69  //float ieta_min_HE = -iEtaHEMax - 1.5;
70  //float ieta_max_HE = iEtaHEMax + 1.5;
71  //int ieta_bins_HE = (int) (ieta_max_HE - ieta_min_HE);
72 
73  //float ieta_min_HF = -iEtaHFMax - 1.5;
74  //float ieta_max_HF = iEtaHFMax + 1.5;
75  //int ieta_bins_HF = (int) (ieta_max_HF - ieta_min_HF);
76 
77  //float ieta_min_HO = -iEtaHOMax - 1.5;
78  //float ieta_max_HO = iEtaHOMax + 1.5;
79  //int ieta_bins_HO = (int) (ieta_max_HO - ieta_min_HO);
80 
81 #ifdef DebugLog
82  edm::LogInfo("HitsValidationHcal") << " Maximum Depths HB:"<< maxDepthHB_
83  << " HE:" << maxDepthHE_ << " HO:"
84  << maxDepthHO_ << " HF:" << maxDepthHF_;
85 #endif
86  std::vector<std::pair<std::string,std::string> > divisions = getHistogramTypes();
87 
88  edm::LogInfo("HitsValidationHcal") << "Booking the Histograms";
89  ib.setCurrentFolder("HcalHitsV/SimHitsValidationHcal");
90 
91  //Histograms for Hits
92 
93  char name[100], title[200];
94  for (unsigned int i=0; i<types.size(); ++i) {
96  sprintf (name, "HcalHitEta%s", divisions[i].first.c_str());
97  sprintf (title, "Hit energy as a function of eta tower index in %s", divisions[i].second.c_str());
98  meHcalHitEta_.push_back(ib.book1D(name, title, limit.bins, limit.low, limit.high));
99 
100  sprintf (name, "HcalHitTimeAEta%s", divisions[i].first.c_str());
101  sprintf (title, "Hit time as a function of eta tower index in %s", divisions[i].second.c_str());
102  meHcalHitTimeEta_.push_back(ib.book1D(name, title, limit.bins, limit.low, limit.high));
103 
104  sprintf (name, "HcalHitE25%s", divisions[i].first.c_str());
105  sprintf (title, "Energy in time window 0 to 25 for a tower in %s", divisions[i].second.c_str());
106  meHcalEnergyl25_.push_back(ib.book2D(name, title, limit.bins, limit.low, limit.high, iphi_bins, iphi_min, iphi_max));
107 
108  sprintf (name, "HcalHitE50%s", divisions[i].first.c_str());
109  sprintf (title, "Energy in time window 0 to 50 for a tower in %s", divisions[i].second.c_str());
110  meHcalEnergyl50_.push_back(ib.book2D(name, title, limit.bins, limit.low, limit.high, iphi_bins, iphi_min, iphi_max));
111 
112  sprintf (name, "HcalHitE100%s", divisions[i].first.c_str());
113  sprintf (title, "Energy in time window 0 to 100 for a tower in %s", divisions[i].second.c_str());
114  meHcalEnergyl100_.push_back(ib.book2D(name, title, limit.bins, limit.low, limit.high, iphi_bins, iphi_min, iphi_max));
115 
116  sprintf (name, "HcalHitE250%s", divisions[i].first.c_str());
117  sprintf (title, "Energy in time window 0 to 250 for a tower in %s", divisions[i].second.c_str());
118  meHcalEnergyl250_.push_back(ib.book2D(name, title, limit.bins, limit.low, limit.high, iphi_bins, iphi_min, iphi_max));
119  }
120 
121  sprintf (name, "Energy_HB");
122  meEnergy_HB = ib.book1D(name, name, 100,0,1);
123  sprintf (name, "Energy_HE");
124  meEnergy_HE = ib.book1D(name, name, 100,0,1);
125  sprintf (name, "Energy_HO");
126  meEnergy_HO = ib.book1D(name, name, 100,0,1);
127  sprintf (name, "Energy_HF");
128  meEnergy_HF = ib.book1D(name, name, 100,0,50);
129 
130  sprintf (name, "Time_HB");
131  metime_HB = ib.book1D(name, name, 300,-150,150);
132  sprintf (name, "Time_HE");
133  metime_HE = ib.book1D(name, name, 300,-150,150);
134  sprintf (name, "Time_HO");
135  metime_HO = ib.book1D(name, name, 300,-150, 150);
136  sprintf (name, "Time_HF");
137  metime_HF = ib.book1D(name, name, 300,-150,150);
138 
139  sprintf (name, "Time_Enweighted_HB");
140  metime_enweighted_HB = ib.book1D(name, name, 300,-150,150);
141  sprintf (name, "Time_Enweighted_HE");
142  metime_enweighted_HE = ib.book1D(name, name, 300,-150,150);
143  sprintf (name, "Time_Enweighted_HO");
144  metime_enweighted_HO = ib.book1D(name, name, 300,-150, 150);
145  sprintf (name, "Time_Enweighted_HF");
146  metime_enweighted_HF = ib.book1D(name, name, 300,-150,150);
147 }
148 
150  const edm::EventSetup& ) {
151 
152 
153 #ifdef DebugLog
154  edm::LogInfo("HitsValidationHcal") << "Run = " << e.id().run() << " Event = "
155  << e.id().event();
156 #endif
157  std::vector<PCaloHit> caloHits;
159 
160  bool getHits = false;
161  e.getByToken(tok_hits_,hitsHcal);
162  if (hitsHcal.isValid()) getHits = true;
163 #ifdef DebugLog
164  edm::LogInfo("HitsValidationHcal") << "HitsValidationHcal.: Input flags Hits "
165  << getHits;
166 #endif
167  if (getHits) {
168  caloHits.insert(caloHits.end(),hitsHcal->begin(),hitsHcal->end());
169 #ifdef DebugLog
170  edm::LogInfo("HitsValidationHcal") << "testNumber_:" << testNumber_;
171 #endif
172  if (testNumber_) {
173  for (unsigned int i=0; i<caloHits.size(); ++i) {
174  unsigned int id_ = caloHits[i].id();
176  caloHits[i].setID(hid.rawId());
177 #ifdef DebugLog
178  edm::LogInfo("HitsValidationHcal") << "Hit[" << i << "] " << hid;
179 #endif
180  }
181  }
182 #ifdef DebugLog
183  edm::LogInfo("HitsValidationHcal") << "HitsValidationHcal: Hit buffer "
184  << caloHits.size();
185 #endif
186  analyzeHits (caloHits);
187  }
188 }
189 
190 void SimHitsValidationHcal::analyzeHits (std::vector<PCaloHit>& hits) {
191 
192  int nHit = hits.size();
193  double entotHB = 0, entotHE = 0, entotHF = 0, entotHO = 0;
194  double timetotHB = 0, timetotHE = 0, timetotHF = 0, timetotHO = 0;
195  int nHB=0, nHE=0, nHO=0, nHF=0;
196 
197  std::map<std::pair<HcalDetId,unsigned int>,energysum> map_try;
198  map_try.clear();
199  std::map<std::pair<HcalDetId,unsigned int>,energysum>::iterator itr;
200 
201  for (int i=0; i<nHit; i++) {
202  double energy = hits[i].energy();
203  double time = hits[i].time();
204  HcalDetId id = HcalDetId(hits[i].id());
205  int itime = (int)(time);
206  int subdet = id.subdet();
207  int depth = id.depth();
208  int eta = id.ieta();
209  unsigned int dep = hits[i].depth();
210 
211  std::pair<int,int> types = histId(subdet, eta, depth, dep);
212  if (subdet == static_cast<int>(HcalBarrel)) {
213  entotHB += energy;
214  timetotHB += time;
215  nHB++;
216  } else if (subdet == static_cast<int>(HcalEndcap)) {
217  entotHE += energy;
218  timetotHE += time;
219  nHE++;
220  } else if (subdet == static_cast<int>(HcalOuter)) {
221  entotHO += energy;
222  timetotHO += time;
223  nHO++;
224  } else if (subdet == static_cast<int>(HcalForward)) {
225  entotHF += energy;
226  timetotHF += time;
227  nHF++;
228  }
229 
230  std::pair<HcalDetId,unsigned int> id0(id,dep);
231  energysum ensum;
232  if (map_try.count(id0) != 0) ensum = map_try[id0];
233  if (itime<250) {
234  ensum.e250 += energy;
235  if (itime<100) {
236  ensum.e100 += energy;
237  if (itime<50) {
238  ensum.e50 += energy;
239  if (itime<25) ensum.e25 += energy;
240  }
241  }
242  }
243  map_try[id0] = ensum;
244 
245 #ifdef DebugLog
246  edm::LogInfo("HitsValidationHcal") << "Hit[" << i << "] ID " << std::dec
247  << " " << id << std::dec << " Det "
248  << id.det() << " Sub " << subdet
249  << " depth " << depth << " depthX "
250  << dep << " Eta " << eta << " Phi "
251  << id.iphi() << " E " << energy
252  << " time " << time << " type "
253  << types.first << " " << types.second;
254 #endif
255 
256  double etax = eta - 0.5;
257  if (eta < 0) etax += 1;
258  if (types.first >= 0) {
259  meHcalHitEta_[types.first]->Fill(etax,energy);
260  meHcalHitTimeEta_[types.first]->Fill(etax,time);
261  }
262  if (types.second >= 0) {
263  meHcalHitEta_[types.second]->Fill(etax,energy);
264  meHcalHitTimeEta_[types.second]->Fill(etax,time);
265  }
266  }
267 
268  meEnergy_HB->Fill(entotHB);
269  meEnergy_HE->Fill(entotHE);
270  meEnergy_HF->Fill(entotHF);
271  meEnergy_HO->Fill(entotHO);
272 
273  metime_HB->Fill(timetotHB);
274  metime_HE->Fill(timetotHE);
275  metime_HF->Fill(timetotHF);
276  metime_HO->Fill(timetotHO);
277 
278  metime_enweighted_HB->Fill(timetotHB,entotHB);
279  metime_enweighted_HE->Fill(timetotHE,entotHE);
280  metime_enweighted_HF->Fill(timetotHF,entotHF);
281  metime_enweighted_HO->Fill(timetotHO,entotHO);
282 
283 
284  for (itr = map_try.begin(); itr != map_try.end(); ++itr) {
285  HcalDetId id = (*itr).first.first;
286  energysum ensum = (*itr).second;
287  std::pair<int,int> types = histId((int)(id.subdet()), id.ieta(), id.depth(), (*itr).first.second);
288  int eta = id.ieta();
289  int phi = id.iphi();
290  double etax= eta-0.5;
291  double phix= phi-0.5;
292  if (types.first >= 0) {
293  meHcalEnergyl25_[types.first]->Fill(etax,phix,ensum.e25);
294  meHcalEnergyl50_[types.first]->Fill(etax,phix,ensum.e50);
295  meHcalEnergyl100_[types.first]->Fill(etax,phix,ensum.e100);
296  meHcalEnergyl250_[types.first]->Fill(etax,phix,ensum.e250);
297  }
298  if (types.second >= 0) {
299  meHcalEnergyl25_[types.second]->Fill(etax,phix,ensum.e25);
300  meHcalEnergyl50_[types.second]->Fill(etax,phix,ensum.e50);
301  meHcalEnergyl100_[types.second]->Fill(etax,phix,ensum.e100);
302  meHcalEnergyl250_[types.second]->Fill(etax,phix,ensum.e250);
303  }
304 
305 #ifdef DebugLog
306  edm::LogInfo("HitsValidationHcal") << " energy of tower =" << (*itr).first.first
307  << " in time 25ns is == " << (*itr).second.e25
308  << " in time 25-50ns == " << (*itr).second.e50
309  << " in time 50-100ns == " << (*itr).second.e100
310  << " in time 100-250 ns == " << (*itr).second.e250;
311 #endif
312  }
313 
314 }
315 
317 
318  int bins;
319  std::pair<int,int> range;
320  double low, high;
321 
322  if (type.subdet == HcalBarrel) {
323  range = hcons->getEtaRange(0);
324  low =-range.second;
325  high = range.second;
326  bins = (high-low);
327  } else if (type.subdet == HcalEndcap) {
328  range = hcons->getEtaRange(1);
329  bins = range.second- range.first;
330  if (type.z == 1) {
331  low = range.first;
332  high = range.second;
333  } else {
334  low =-range.second;
335  high =-range.first;
336  }
337  } else if (type.subdet == HcalOuter) {
338  range = hcons->getEtaRange(3);
339  low =-range.second;
340  high = range.second;
341  bins = high-low;
342  } else if (type.subdet == HcalForward) {
343  range = hcons->getEtaRange(2);
344  bins = range.second-range.first;
345  if (type.z == 1) {
346  low = range.first;
347  high = range.second;
348  } else {
349  low =-range.second;
350  high =-range.first;
351  }
352  } else {
353  bins = 82;
354  low =-41;
355  high = 41;
356  }
357 #ifdef DebugLog
358  edm::LogInfo("HitsValidationHcal") << "Subdetector:" << type.subdet << " z:"
359  << type.z << " range.first:" << range.first
360  << " and second:" << range.second;
361  edm::LogInfo("HitsValidationHcal") << "bins: " << bins << " low:" << low
362  << " high:" << high;
363 #endif
364  return SimHitsValidationHcal::etaRange(bins, low, high);
365 }
366 
367 std::pair<int,int> SimHitsValidationHcal::histId(int subdet, int eta, int depth, unsigned int dep) {
368 
369  int id1(-1), id2(-1);
370  for (unsigned int k=0; k<types.size(); ++k) {
371  if (subdet == HcalForward) {
372  if (subdet == (int)(types[k].subdet) && depth == types[k].depth1 &&
373  eta*types[k].z > 0 && dep == (unsigned int)(types[k].depth2)) {
374  id1 = k; break;
375  }
376  } else if (subdet == HcalEndcap) {
377  if (subdet == (int)(types[k].subdet) && depth == types[k].depth1 &&
378  eta*types[k].z > 0) {
379  id1 = k; break;
380  }
381  } else {
382  if (subdet == (int)(types[k].subdet) && depth == types[k].depth1) {
383  id1 = k; break;
384  }
385  }
386  }
387  if (subdet == HcalForward) depth += 2*dep;
388  for (unsigned int k=0; k<types.size(); ++k) {
389  if (types[k].subdet == HcalEmpty && types[k].depth1 == depth) {
390  id2 = k;
391  break;
392  }
393  }
394  return std::pair<int,int>(id1,id2);
395 }
396 
397 std::vector<std::pair<std::string,std::string> > SimHitsValidationHcal::getHistogramTypes() {
398 
400  maxDepth = std::max(maxDepth,maxDepthHF_);
401  maxDepth = std::max(maxDepth,maxDepthHO_);
402 
403  std::vector<std::pair<std::string,std::string> > divisions;
404  std::pair<std::string,std::string> names;
405  char name1[40], name2[40];
407  //first overall Hcal
408  for (int depth=0; depth<maxDepth; ++depth) {
409  snprintf (name1, 40, "HC%d", depth);
410  snprintf (name2, 40, "HCAL depth%d", depth+1);
411  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
413  divisions.push_back(names);
414  types.push_back(type);
415  }
416  //HB
417  for (int depth=0; depth<maxDepthHB_; ++depth) {
418  snprintf (name1, 40, "HB%d", depth);
419  snprintf (name2, 40, "HB depth%d", depth+1);
420  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
422  divisions.push_back(names);
423  types.push_back(type);
424  }
425  //HE
426  for (int depth=0; depth<maxDepthHE_; ++depth) {
427  snprintf (name1, 40, "HE%d+z", depth);
428  snprintf (name2, 40, "HE +z depth%d", depth+1);
429  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
431  divisions.push_back(names);
432  types.push_back(type);
433  snprintf (name1, 40, "HE%d-z", depth);
434  snprintf (name2, 40, "HE -z depth%d", depth+1);
435  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
437  divisions.push_back(names);
438  types.push_back(type);
439  }
440  //HO
441  {
442  int depth = maxDepthHO_;
443  snprintf (name1, 40, "HO%d", depth);
444  snprintf (name2, 40, "HO depth%d", depth);
445  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
446  type = SimHitsValidationHcal::idType(HcalOuter,0,depth,depth);
447  divisions.push_back(names);
448  types.push_back(type);
449  }
450  //HF (first absorber, then different types of abnormal hits)
451  std::string hfty1[4] = {"A","W","B","J"};
452  std::string hfty2[4] = {"Absorber", "Window", "Bundle", "Jungle"};
453  int dept0[4] = {0, 1, 2, 3};
454  for (int k=0; k<4; ++k) {
455  for (int depth=0; depth<maxDepthHF_; ++depth) {
456  snprintf (name1, 40, "HF%s%d+z", hfty1[k].c_str(), depth);
457  snprintf (name2, 40, "HF (%s) +z depth%d", hfty2[k].c_str(), depth+1);
458  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
460  divisions.push_back(names);
461  types.push_back(type);
462  snprintf (name1, 40, "HF%s%d-z", hfty1[k].c_str(), depth);
463  snprintf (name2, 40, "HF (%s) -z depth%d", hfty2[k].c_str(), depth+1);
464  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
465  type = SimHitsValidationHcal::idType(HcalForward,-1,depth+1,dept0[k]);
466  divisions.push_back(names);
467  types.push_back(type);
468  }
469  }
470 
471  return divisions;
472 }
473 
476  desc.add<std::string>("ModuleLabel","g4SimHits");
477  desc.add<std::string>("HitCollection","HcalHits");
478  desc.add<bool>("Verbose",false);
479  desc.add<bool>("TestNumber",false);
480 
481  descriptions.addDefault(desc);
482 }
483 
RunNumber_t run() const
Definition: EventID.h:39
SimHitsValidationHcal(const edm::ParameterSet &ps)
type
Definition: HCALResponse.h:21
MonitorElement * meEnergy_HF
std::vector< MonitorElement * > meHcalHitEta_
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
const HcalDDDRecConstants * hcons
static const HistoName names[]
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MonitorElement * metime_enweighted_HO
std::vector< MonitorElement * > meHcalEnergyl25_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
void analyze(const edm::Event &e, const edm::EventSetup &c) override
std::pair< int, int > getEtaRange(const int &i) const
void Fill(long long x)
MonitorElement * metime_enweighted_HB
U second(std::pair< T, U > const &p)
MonitorElement * meEnergy_HB
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< MonitorElement * > meHcalEnergyl250_
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
MonitorElement * metime_enweighted_HF
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
std::vector< MonitorElement * > meHcalEnergyl100_
std::vector< MonitorElement * > meHcalEnergyl50_
MonitorElement * metime_enweighted_HE
int k[5][pyjets_maxn]
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
int getMaxDepth(const int &type) const
MonitorElement * meEnergy_HE
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EventID id() const
Definition: EventBase.h:60
std::vector< MonitorElement * > meHcalHitTimeEta_
T get() const
Definition: EventSetup.h:63
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::pair< int, int > histId(int subdet, int eta, int depth, unsigned int dep)
DetId relabel(const uint32_t testId) const
MonitorElement * meEnergy_HO
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hits_
Definition: Run.h:44
int getNPhi(const int &type) const
ib
Definition: cuy.py:661
std::vector< std::pair< std::string, std::string > > getHistogramTypes()
void analyzeHits(std::vector< PCaloHit > &)