test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimHitsValidationHcal.cc
Go to the documentation of this file.
5 
6 //#define DebugLog
7 
9 
10  g4Label_ = ps.getUntrackedParameter<std::string>("moduleLabel","g4SimHits");
11  hcalHits_ = ps.getUntrackedParameter<std::string>("HitCollection","HcalHits");
12  verbose_ = ps.getUntrackedParameter<bool>("Verbose", false);
13  testNumber_= ps.getUntrackedParameter<bool>("TestNumber", false);
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 #ifdef DebugLog
34  edm::LogInfo("HitsValidationHcal") << " Maximum Depths HB:"<< maxDepthHB_
35  << " HE:" << maxDepthHE_ << " HO:"
36  << maxDepthHO_ << " HF:" << maxDepthHF_;
37 #endif
38  std::vector<std::pair<std::string,std::string> > divisions = getHistogramTypes();
39 
40  edm::LogInfo("HitsValidationHcal") << "Booking the Histograms";
41  ib.setCurrentFolder("HcalHitsV/SimHitsValidationHcal");
42 
43  //Histograms for Hits
44 
45  char name[100], title[200];
46  for (unsigned int i=0; i<types.size(); ++i) {
48  sprintf (name, "HcalHitEta%s", divisions[i].first.c_str());
49  sprintf (title, "Hit energy as a function of eta tower index in %s", divisions[i].second.c_str());
50  meHcalHitEta_.push_back(ib.book1D(name, title, limit.bins, limit.low, limit.high));
51 
52  sprintf (name, "HcalHitTimeAEta%s", divisions[i].first.c_str());
53  sprintf (title, "Hit time as a function of eta tower index in %s", divisions[i].second.c_str());
54  meHcalHitTimeEta_.push_back(ib.book1D(name, title, limit.bins, limit.low, limit.high));
55 
56  sprintf (name, "HcalHitE25%s", divisions[i].first.c_str());
57  sprintf (title, "Energy in time window 0 to 25 for a tower in %s", divisions[i].second.c_str());
58  meHcalEnergyl25_.push_back(ib.book2D(name, title, limit.bins, limit.low, limit.high, 72, 0., 72.));
59 
60  sprintf (name, "HcalHitE50%s", divisions[i].first.c_str());
61  sprintf (title, "Energy in time window 0 to 50 for a tower in %s", divisions[i].second.c_str());
62  meHcalEnergyl50_.push_back(ib.book2D(name, title, limit.bins, limit.low, limit.high, 72, 0., 72.));
63 
64  sprintf (name, "HcalHitE100%s", divisions[i].first.c_str());
65  sprintf (title, "Energy in time window 0 to 100 for a tower in %s", divisions[i].second.c_str());
66  meHcalEnergyl100_.push_back(ib.book2D(name, title, limit.bins, limit.low, limit.high, 72, 0., 72.));
67 
68  sprintf (name, "HcalHitE250%s", divisions[i].first.c_str());
69  sprintf (title, "Energy in time window 0 to 250 for a tower in %s", divisions[i].second.c_str());
70  meHcalEnergyl250_.push_back(ib.book2D(name, title, limit.bins, limit.low, limit.high, 72, 0., 72.));
71  }
72 
73  sprintf (name, "Energy_HB");
74  meEnergy_HB = ib.book1D(name, name, 100,0,1);
75  sprintf (name, "Energy_HE");
76  meEnergy_HE = ib.book1D(name, name, 100,0,1);
77  sprintf (name, "Energy_HO");
78  meEnergy_HO = ib.book1D(name, name, 100,0,1);
79  sprintf (name, "Energy_HF");
80  meEnergy_HF = ib.book1D(name, name, 100,0,50);
81 
82  sprintf (name, "Time_HB");
83  metime_HB = ib.book1D(name, name, 300,-150,150);
84  sprintf (name, "Time_HE");
85  metime_HE = ib.book1D(name, name, 300,-150,150);
86  sprintf (name, "Time_HO");
87  metime_HO = ib.book1D(name, name, 300,-150, 150);
88  sprintf (name, "Time_HF");
89  metime_HF = ib.book1D(name, name, 300,-150,150);
90 
91  sprintf (name, "Time_Enweighted_HB");
92  metime_enweighted_HB = ib.book1D(name, name, 300,-150,150);
93  sprintf (name, "Time_Enweighted_HE");
94  metime_enweighted_HE = ib.book1D(name, name, 300,-150,150);
95  sprintf (name, "Time_Enweighted_HO");
96  metime_enweighted_HO = ib.book1D(name, name, 300,-150, 150);
97  sprintf (name, "Time_Enweighted_HF");
98  metime_enweighted_HF = ib.book1D(name, name, 300,-150,150);
99 }
100 
102  const edm::EventSetup& ) {
103 
104 
105 #ifdef DebugLog
106  edm::LogInfo("HitsValidationHcal") << "Run = " << e.id().run() << " Event = "
107  << e.id().event();
108 #endif
109  std::vector<PCaloHit> caloHits;
111 
112  bool getHits = false;
113  e.getByToken(tok_hits_,hitsHcal);
114  if (hitsHcal.isValid()) getHits = true;
115 #ifdef DebugLog
116  edm::LogInfo("HitsValidationHcal") << "HitsValidationHcal.: Input flags Hits "
117  << getHits;
118 #endif
119  if (getHits) {
120  caloHits.insert(caloHits.end(),hitsHcal->begin(),hitsHcal->end());
121 #ifdef DebugLog
122  edm::LogInfo("HitsValidationHcal") << "testNumber_:" << testNumber_;
123 #endif
124  if (testNumber_) {
125  for (unsigned int i=0; i<caloHits.size(); ++i) {
126  unsigned int id_ = caloHits[i].id();
127  int subdet, z, depth0, eta0, phi0, lay;
128  HcalTestNumbering::unpackHcalIndex(id_, subdet, z, depth0, eta0, phi0, lay);
129  int sign = (z==0) ? (-1):(1);
130 #ifdef DebugLog
131  edm::LogInfo("HitsValidationHcal") << "Hit[" << i
132  << "] subdet|z|depth|eta|phi|lay "
133  << subdet << "|" << z << "|"
134  << depth0 << "|" << eta0 << "|"
135  << phi0 << "|" << lay;
136 #endif
137  HcalDDDRecConstants::HcalID id = hcons->getHCID(subdet, eta0, phi0, lay, depth0);
138 
139  HcalDetId hid;
140  if (subdet==int(HcalBarrel)) {
141  hid = HcalDetId(HcalBarrel,sign*id.eta,id.phi,id.depth);
142  } else if (subdet==int(HcalEndcap)) {
143  hid = HcalDetId(HcalEndcap,sign*id.eta,id.phi,id.depth);
144  } else if (subdet==int(HcalOuter)) {
145  hid = HcalDetId(HcalOuter,sign*id.eta,id.phi,id.depth);
146  } else if (subdet==int(HcalForward)) {
147  hid = HcalDetId(HcalForward,sign*id.eta,id.phi,id.depth);
148  }
149  caloHits[i].setID(hid.rawId());
150 #ifdef DebugLog
151  edm::LogInfo("HitsValidationHcal") << "Hit[" << i << "] " << hid;
152 #endif
153  }
154  }
155 #ifdef DebugLog
156  edm::LogInfo("HitsValidationHcal") << "HitsValidationHcal: Hit buffer "
157  << caloHits.size();
158 #endif
159  analyzeHits (caloHits);
160  }
161 }
162 
163 void SimHitsValidationHcal::analyzeHits (std::vector<PCaloHit>& hits) {
164 
165  int nHit = hits.size();
166  double entotHB = 0, entotHE = 0, entotHF = 0, entotHO = 0;
167  double timetotHB = 0, timetotHE = 0, timetotHF = 0, timetotHO = 0;
168  int nHB=0, nHE=0, nHO=0, nHF=0;
169 
170  std::map<std::pair<HcalDetId,unsigned int>,energysum> map_try;
171  map_try.clear();
172  std::map<std::pair<HcalDetId,unsigned int>,energysum>::iterator itr;
173 
174  for (int i=0; i<nHit; i++) {
175  double energy = hits[i].energy();
176  double time = hits[i].time();
177  HcalDetId id = HcalDetId(hits[i].id());
178  int itime = (int)(time);
179  int subdet = id.subdet();
180  int depth = id.depth();
181  int eta = id.ieta();
182  unsigned int dep = hits[i].depth();
183 
184  std::pair<int,int> types = histId(subdet, eta, depth, dep);
185  if (subdet == static_cast<int>(HcalBarrel)) {
186  entotHB += energy;
187  timetotHB += time;
188  nHB++;
189  } else if (subdet == static_cast<int>(HcalEndcap)) {
190  entotHE += energy;
191  timetotHE += time;
192  nHE++;
193  } else if (subdet == static_cast<int>(HcalOuter)) {
194  entotHO += energy;
195  timetotHO += time;
196  nHO++;
197  } else if (subdet == static_cast<int>(HcalForward)) {
198  entotHF += energy;
199  timetotHF += time;
200  nHF++;
201  }
202 
203  std::pair<HcalDetId,unsigned int> id0(id,dep);
204  energysum ensum;
205  if (map_try.count(id0) != 0) ensum = map_try[id0];
206  if (itime<250) {
207  ensum.e250 += energy;
208  if (itime<100) {
209  ensum.e100 += energy;
210  if (itime<50) {
211  ensum.e50 += energy;
212  if (itime<25) ensum.e25 += energy;
213  }
214  }
215  }
216  map_try[id0] = ensum;
217 
218 #ifdef DebugLog
219  edm::LogInfo("HitsValidationHcal") << "Hit[" << i << "] ID " << std::dec
220  << " " << id << std::dec << " Det "
221  << id.det() << " Sub " << subdet
222  << " depth " << depth << " depthX "
223  << dep << " Eta " << eta << " Phi "
224  << id.iphi() << " E " << energy
225  << " time " << time << " type "
226  << types.first << " " << types.second;
227 #endif
228 
229  double etax = eta - 0.5;
230  if (eta < 0) etax += 1;
231  if (types.first >= 0) {
232  meHcalHitEta_[types.first]->Fill(etax,energy);
233  meHcalHitTimeEta_[types.first]->Fill(etax,time);
234  }
235  if (types.second >= 0) {
236  meHcalHitEta_[types.second]->Fill(etax,energy);
237  meHcalHitTimeEta_[types.second]->Fill(etax,time);
238  }
239  }
240 
241  meEnergy_HB->Fill(entotHB);
242  meEnergy_HE->Fill(entotHE);
243  meEnergy_HF->Fill(entotHF);
244  meEnergy_HO->Fill(entotHO);
245 
246  metime_HB->Fill(timetotHB);
247  metime_HE->Fill(timetotHE);
248  metime_HF->Fill(timetotHF);
249  metime_HO->Fill(timetotHO);
250 
251  metime_enweighted_HB->Fill(timetotHB,entotHB);
252  metime_enweighted_HE->Fill(timetotHE,entotHE);
253  metime_enweighted_HF->Fill(timetotHF,entotHF);
254  metime_enweighted_HO->Fill(timetotHO,entotHO);
255 
256 
257  for (itr = map_try.begin(); itr != map_try.end(); ++itr) {
258  HcalDetId id = (*itr).first.first;
259  energysum ensum = (*itr).second;
260  std::pair<int,int> types = histId((int)(id.subdet()), id.ieta(), id.depth(), (*itr).first.second);
261  int eta = id.ieta();
262  int phi = id.iphi();
263  double etax= eta-0.5;
264  double phix= phi-0.5;
265  if (types.first >= 0) {
266  meHcalEnergyl25_[types.first]->Fill(etax,phix,ensum.e25);
267  meHcalEnergyl50_[types.first]->Fill(etax,phix,ensum.e50);
268  meHcalEnergyl100_[types.first]->Fill(etax,phix,ensum.e100);
269  meHcalEnergyl250_[types.first]->Fill(etax,phix,ensum.e250);
270  }
271  if (types.second >= 0) {
272  meHcalEnergyl25_[types.second]->Fill(etax,phix,ensum.e25);
273  meHcalEnergyl50_[types.second]->Fill(etax,phix,ensum.e50);
274  meHcalEnergyl100_[types.second]->Fill(etax,phix,ensum.e100);
275  meHcalEnergyl250_[types.second]->Fill(etax,phix,ensum.e250);
276  }
277 
278 #ifdef DebugLog
279  edm::LogInfo("HitsValidationHcal") << " energy of tower =" << (*itr).first.first
280  << " in time 25ns is == " << (*itr).second.e25
281  << " in time 25-50ns == " << (*itr).second.e50
282  << " in time 50-100ns == " << (*itr).second.e100
283  << " in time 100-250 ns == " << (*itr).second.e250;
284 #endif
285  }
286 
287 }
288 
290 
291  int bins;
292  std::pair<int,int> range;
293  double low, high;
294 
295  if (type.subdet == HcalBarrel) {
296  range = hcons->getEtaRange(0);
297  low =-range.second;
298  high = range.second;
299  bins = (high-low);
300  } else if (type.subdet == HcalEndcap) {
301  range = hcons->getEtaRange(1);
302  bins = range.second- range.first;
303  if (type.z == 1) {
304  low = range.first;
305  high = range.second;
306  } else {
307  low =-range.second;
308  high =-range.first;
309  }
310  } else if (type.subdet == HcalOuter) {
311  range = hcons->getEtaRange(3);
312  low =-range.second;
313  high = range.second;
314  bins = high-low;
315  } else if (type.subdet == HcalForward) {
316  range = hcons->getEtaRange(2);
317  bins = range.second-range.first;
318  if (type.z == 1) {
319  low = range.first;
320  high = range.second;
321  } else {
322  low =-range.second;
323  high =-range.first;
324  }
325  } else {
326  bins = 82;
327  low =-41;
328  high = 41;
329  }
330 #ifdef DebugLog
331  edm::LogInfo("HitsValidationHcal") << "Subdetector:" << type.subdet << " z:"
332  << type.z << " range.first:" << range.first
333  << " and second:" << range.second;
334  edm::LogInfo("HitsValidationHcal") << "bins: " << bins << " low:" << low
335  << " high:" << high;
336 #endif
337  return SimHitsValidationHcal::etaRange(bins, low, high);
338 }
339 
340 std::pair<int,int> SimHitsValidationHcal::histId(int subdet, int eta, int depth, unsigned int dep) {
341 
342  int id1(-1), id2(-1);
343  for (unsigned int k=0; k<types.size(); ++k) {
344  if (subdet == HcalForward) {
345  if (subdet == (int)(types[k].subdet) && depth == types[k].depth1 &&
346  eta*types[k].z > 0 && dep == (unsigned int)(types[k].depth2)) {
347  id1 = k; break;
348  }
349  } else if (subdet == HcalEndcap) {
350  if (subdet == (int)(types[k].subdet) && depth == types[k].depth1 &&
351  eta*types[k].z > 0) {
352  id1 = k; break;
353  }
354  } else {
355  if (subdet == (int)(types[k].subdet) && depth == types[k].depth1) {
356  id1 = k; break;
357  }
358  }
359  }
360  if (subdet == HcalForward) depth += 2*dep;
361  for (unsigned int k=0; k<types.size(); ++k) {
362  if (types[k].subdet == HcalEmpty && types[k].depth1 == depth) {
363  id2 = k;
364  break;
365  }
366  }
367  return std::pair<int,int>(id1,id2);
368 }
369 
370 std::vector<std::pair<std::string,std::string> > SimHitsValidationHcal::getHistogramTypes() {
371 
373  maxDepth = std::max(maxDepth,maxDepthHF_);
374  maxDepth = std::max(maxDepth,maxDepthHO_);
375 
376  std::vector<std::pair<std::string,std::string> > divisions;
377  std::pair<std::string,std::string> names;
378  char name1[40], name2[40];
380  //first overall Hcal
381  for (int depth=0; depth<maxDepth; ++depth) {
382  snprintf (name1, 40, "HC%d", depth);
383  snprintf (name2, 40, "HCAL depth%d", depth+1);
384  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
386  divisions.push_back(names);
387  types.push_back(type);
388  }
389  //HB
390  for (int depth=0; depth<maxDepthHB_; ++depth) {
391  snprintf (name1, 40, "HB%d", depth);
392  snprintf (name2, 40, "HB depth%d", depth+1);
393  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
395  divisions.push_back(names);
396  types.push_back(type);
397  }
398  //HE
399  for (int depth=0; depth<maxDepthHE_; ++depth) {
400  snprintf (name1, 40, "HE%d+z", depth);
401  snprintf (name2, 40, "HE +z depth%d", depth+1);
402  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
404  divisions.push_back(names);
405  types.push_back(type);
406  snprintf (name1, 40, "HE%d-z", depth);
407  snprintf (name2, 40, "HE -z depth%d", depth+1);
408  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
410  divisions.push_back(names);
411  types.push_back(type);
412  }
413  //HO
414  {
415  int depth = maxDepthHO_;
416  snprintf (name1, 40, "HO%d", depth);
417  snprintf (name2, 40, "HO depth%d", depth);
418  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
419  type = SimHitsValidationHcal::idType(HcalOuter,0,depth,depth);
420  divisions.push_back(names);
421  types.push_back(type);
422  }
423  //HF (first absorber, then different types of abnormal hits)
424  std::string hfty1[4] = {"A","W","B","J"};
425  std::string hfty2[4] = {"Absorber", "Window", "Bundle", "Jungle"};
426  int dept0[4] = {0, 1, 2, 3};
427  for (int k=0; k<4; ++k) {
428  for (int depth=0; depth<maxDepthHF_; ++depth) {
429  snprintf (name1, 40, "HF%s%d+z", hfty1[k].c_str(), depth);
430  snprintf (name2, 40, "HF (%s) +z depth%d", hfty2[k].c_str(), depth+1);
431  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
433  divisions.push_back(names);
434  types.push_back(type);
435  snprintf (name1, 40, "HF%s%d-z", hfty1[k].c_str(), depth);
436  snprintf (name2, 40, "HF (%s) -z depth%d", hfty2[k].c_str(), depth+1);
437  names = std::pair<std::string,std::string>(std::string(name1),std::string(name2));
438  type = SimHitsValidationHcal::idType(HcalForward,-1,depth+1,dept0[k]);
439  divisions.push_back(names);
440  types.push_back(type);
441  }
442  }
443 
444  return divisions;
445 }
446 
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_
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
const HcalDDDRecConstants * hcons
int ib
Definition: cuy.py:660
static const HistoName names[]
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)
MonitorElement * metime_enweighted_HO
double sign(double x)
std::vector< MonitorElement * > meHcalEnergyl25_
void analyze(const edm::Event &e, const edm::EventSetup &c)
void Fill(long long x)
MonitorElement * metime_enweighted_HB
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
int getMaxDepth(const int type) const
MonitorElement * meEnergy_HB
HcalID getHCID(int subdet, int ieta, int iphi, int lay, int idepth) const
std::vector< MonitorElement * > meHcalEnergyl250_
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
std::vector< idType > types
MonitorElement * metime_enweighted_HF
bool isValid() const
Definition: HandleBase.h:75
std::vector< MonitorElement * > meHcalEnergyl100_
std::vector< MonitorElement * > meHcalEnergyl50_
MonitorElement * metime_enweighted_HE
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:56
MonitorElement * meEnergy_HE
std::pair< int, int > getEtaRange(const int i) const
edm::EventID id() const
Definition: EventBase.h:59
std::vector< MonitorElement * > meHcalHitTimeEta_
std::pair< int, int > histId(int subdet, int eta, int depth, unsigned int dep)
MonitorElement * meEnergy_HO
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hits_
Definition: Run.h:43
std::vector< std::pair< std::string, std::string > > getHistogramTypes()
void analyzeHits(std::vector< PCaloHit > &)