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.
3 
5 
6  g4Label = ps.getUntrackedParameter<std::string>("moduleLabel","g4SimHits");
7  hcalHits = ps.getUntrackedParameter<std::string>("HitCollection","HcalHits");
8  verbose_ = ps.getUntrackedParameter<bool>("Verbose", false);
9 
10  tok_hits_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label,hcalHits));
11 
12  edm::LogInfo("HitsValidationHcal") << "Module Label: " << g4Label << " Hits: "
13  << hcalHits;
14 
16  if (dbe_) {
17  if (verbose_) {
18  dbe_->setVerbose(1);
19  sleep (3);
21  } else {
22  dbe_->setVerbose(0);
23  }
24  }
25 }
26 
28 
30 
31  if (dbe_) {
32  edm::LogInfo("HitsValidationHcal") << "Histograms booked";
33  dbe_->setCurrentFolder("HcalHitsV/SimHitsValidationHcal");
34 
35  //Histograms for Hits
36 
37  std::string divisions[nType]={"HB0","HB1","HE0+z","HE1+z","HE2+z","HE0-z","HE1-z",
38  "HE2-z","HO0","HFL0+z","HFS0+z","HFL1+z","HFS1+z",
39  "HFL2+z","HFS2+z","HFL3+z","HFS3+z","HFL0-z","HFS0-z",
40  "HFL1-z","HFS1-z","HFL2-z","HFS2-z","HFL3-z","HFS3-z"};
41 
42  std::string divisions1[nType]={"HB depth1","HB depth2 ","HE+z depth1","HE+z depth2","HE+z depth3","HE-z depth1","HE-z depth2",
43  "HE-z depth3","HO depth1","HFL+z depth1","HFS+z depth1","HFL+z depth2","HFS+z depth2",
44  "HFL+z depth3","HFS+z depth3","HFL+z depth4","HFS+z depth4","HFL-z depth1","HFS-z depth1",
45  "HFL-z depth2","HFS-z depth2","HFL-z depth3","HFS-z depth3 ","HFL-z depth4","HFS-z depth4"};
46 
47  double etaLow[nType]={-16,-16,16,16,16,-30,-30,-30,-15,29,29,29,29,29,29,29,29,
48  -41,-41,-41,-41,-41,-41,-41,-41};
49  double etaHigh[nType]={16,16,30,30,30,-16,-16,-16,15,41,41,41,41,41,41,41,41,
50  -29,-29,-29,-29,-29,-29,-29,-29};
51  int etaBins[nType]={32,32,14,14,14,14,14,14,30,12,12,12,12,12,12,12,12,
52  12,12,12,12,12,12,12,12};
53  char name[40], title[100];
54 
55  for (int i=0; i<nType; ++i) {
56  sprintf (name, "HcalHitEta%s", divisions[i].c_str());
57  sprintf (title, "Hit energy as a function of eta tower index in %s", divisions1[i].c_str());
58  meHcalHitEta_[i] = dbe_->book1D(name, title, etaBins[i], etaLow[i], etaHigh[i]);
59 
60  sprintf (name, "HcalHitTimeAEta%s", divisions[i].c_str());
61  sprintf (title, "Hit time as a function of eta tower index in %s", divisions1[i].c_str());
62  meHcalHitTimeEta_[i] = dbe_->book1D(name, title, etaBins[i], etaLow[i], etaHigh[i]);
63 
64  sprintf (name, "HcalHitE25%s", divisions[i].c_str());
65  sprintf (title, "Energy in time window 0 to 25 for a tower in %s", divisions1[i].c_str());
66  meHcalEnergyl25_[i] = dbe_->book2D(name, title, etaBins[i], etaLow[i], etaHigh[i], 72, 0., 72.);
67 
68  sprintf (name, "HcalHitE50%s", divisions[i].c_str());
69  sprintf (title, "Energy in time window 0 to 50 for a tower in %s", divisions1[i].c_str());
70  meHcalEnergyl50_[i] = dbe_->book2D(name, title, etaBins[i], etaLow[i], etaHigh[i], 72, 0., 72.);
71 
72  sprintf (name, "HalHitE100%s", divisions[i].c_str());
73  sprintf (title, "Energy in time window 0 to 100 for a tower in %s", divisions1[i].c_str());
74  meHcalEnergyl100_[i] = dbe_->book2D(name, title, etaBins[i], etaLow[i], etaHigh[i], 72, 0., 72.);
75 
76  sprintf (name, "HcalHitE250%s", divisions[i].c_str());
77  sprintf (title, "Energy in time window 0 to 250 for a tower in %s", divisions1[i].c_str());
78  meHcalEnergyl250_[i] = dbe_->book2D(name, title, etaBins[i], etaLow[i], etaHigh[i], 72, 0., 72.);
79  }
80 
81  sprintf (name, "Energy_HB");
82  meEnergy_HB = dbe_->book1D(name, name, 100,0,1);
83  sprintf (name, "Energy_HE");
84  meEnergy_HE = dbe_->book1D(name, name, 100,0,1);
85  sprintf (name, "Energy_HO");
86  meEnergy_HO = dbe_->book1D(name, name, 100,0,1);
87  sprintf (name, "Energy_HF");
88  meEnergy_HF = dbe_->book1D(name, name, 100,0,50);
89 
90  sprintf (name, "Time_HB");
91  metime_HB = dbe_->book1D(name, name, 300,-150,150);
92  sprintf (name, "Time_HE");
93  metime_HE = dbe_->book1D(name, name, 300,-150,150);
94  sprintf (name, "Time_HO");
95  metime_HO = dbe_->book1D(name, name, 300,-150, 150);
96  sprintf (name, "Time_HF");
97  metime_HF = dbe_->book1D(name, name, 300,-150,150);
98 
99  sprintf (name, "Time_Enweighted_HB");
100  metime_enweighted_HB = dbe_->book1D(name, name, 300,-150,150);
101  sprintf (name, "Time_Enweighted_HE");
102  metime_enweighted_HE = dbe_->book1D(name, name, 300,-150,150);
103  sprintf (name, "Time_Enweighted_HO");
104  metime_enweighted_HO = dbe_->book1D(name, name, 300,-150, 150);
105  sprintf (name, "Time_Enweighted_HF");
106  metime_enweighted_HF = dbe_->book1D(name, name, 300,-150,150);
107  }
108 }
109 
111 
113 
114 
115  LogDebug("SimHitsValidationHcal") << "Run = " << e.id().run() << " Event = "
116  << e.id().event();
117 
118  std::vector<PCaloHit> caloHits;
120 
121  bool getHits = false;
122  e.getByToken(tok_hits_,hitsHcal);
123  if (hitsHcal.isValid()) getHits = true;
124 
125  LogDebug("SimHitsValidationHcal") << "SimHitsValidationHcal.: Input flags Hits " << getHits;
126 
127  if (getHits) {
128  caloHits.insert(caloHits.end(),hitsHcal->begin(),hitsHcal->end());
129  LogDebug("SimHitsValidationHcal") << "SimHitsValidationHcal: Hit buffer "
130  << caloHits.size();
131  analyzeHits (caloHits);
132  }
133 }
134 
135 void SimHitsValidationHcal::analyzeHits (std::vector<PCaloHit>& hits) {
136 
137  int nHit = hits.size();
138  double entotHB = 0, entotHE = 0, entotHF = 0, entotHO = 0;
139  double timetotHB = 0, timetotHE = 0, timetotHF = 0, timetotHO = 0;
140  int nHB=0, nHE=0, nHO=0, nHF=0;
141 
142  std::map<std::pair<HcalDetId,int>,energysum> map_try;
143  map_try.clear();
144 
145  std::map<std::pair<HcalDetId,int>,energysum>::iterator itr;
146 
147  for (int i=0; i<nHit; i++) {
148  double energy = hits[i].energy();
149  double time = hits[i].time();
150  unsigned int id_ = hits[i].id();
151  HcalDetId id = HcalDetId(id_);
152  int itime = (int)(time);
153  int det = id.det();
154  int subdet = id.subdet();
155  int depth = id.depth();
156  int eta = id.ieta();
157  int phi = id.iphi();
158  unsigned int dep = hits[i].depth();
159 
160  int type =-1;
161  if (subdet == static_cast<int>(HcalBarrel)) {
162  entotHB += energy;
163  timetotHB += time;
164  nHB++;
165  type = depth-1;
166  } else if (subdet == static_cast<int>(HcalEndcap)) {
167  entotHE += energy;
168  timetotHE += time;
169  nHE++;
170  type = depth+1;
171  if (eta < 0) type += 3;
172  } else if (subdet == static_cast<int>(HcalOuter)) {
173  entotHO += energy;
174  timetotHO += time;
175  nHO++;
176  type = 8;
177  } else if (subdet == static_cast<int>(HcalForward)) {
178  entotHF += energy;
179  timetotHF += time;
180  nHF++;
181  type = depth+8+2*dep;
182  if (eta < 0) type += 8;
183  }
184 
185  std::pair<HcalDetId,int> id0(id,type);
186  // LogDebug("HitsValidationHcal") << "Id and type " << id << ":" << type;
187  energysum ensum;
188  if (map_try.count(id0) != 0) ensum = map_try[id0];
189  if (itime<250) {
190  ensum.e250 += energy;
191  if (itime<100) {
192  ensum.e100 += energy;
193  if (itime<50) {
194  ensum.e50 += energy;
195  if (itime<25) ensum.e25 += energy;
196  }
197  }
198  }
199  map_try[id0] = ensum;
200 
201  LogDebug("SimHitsValidationHcal") << "Hit[" << i << "] ID " << std::hex << id_
202  << std::dec << " " << id << std::dec<< " Det " << det << " Sub "
203  << subdet << " depth " << depth << " depthX "
204  << dep << " Eta " << eta << " Phi " << phi
205  << " E " << energy << " time " << time
206  << " type " << type;
207 
208  // LogDebug("HitsValidationHcal") << "Hit[" << i << "] ID " << std::hex << id_ << "ID="<<std::dec << id << " Det " << det << " Sub " << subdet << " depth " << depth << " depthX " << dep << " Eta " << eta << " Phi " << phi << " E " << energy << " time " << time <<" itime " << itime << " type " << type;
209 
210  double etax = eta - 0.5;
211  if (eta < 0) etax += 1;
212  if (dbe_ && type >= 0) {
213  meHcalHitEta_[type]->Fill(etax,energy);
214  meHcalHitTimeEta_[type]->Fill(etax,time);
215  }
216  }
217 
218  if (dbe_) {
219  meEnergy_HB->Fill(entotHB);
220  meEnergy_HE->Fill(entotHE);
221  meEnergy_HF->Fill(entotHF);
222  meEnergy_HO->Fill(entotHO);
223 
224  metime_HB->Fill(timetotHB);
225  metime_HE->Fill(timetotHE);
226  metime_HF->Fill(timetotHF);
227  metime_HO->Fill(timetotHO);
228 
229  metime_enweighted_HB->Fill(timetotHB,entotHB);
230  metime_enweighted_HE->Fill(timetotHE,entotHE);
231  metime_enweighted_HF->Fill(timetotHF,entotHF);
232  metime_enweighted_HO->Fill(timetotHO,entotHO);
233  }
234 
235  for ( itr = map_try.begin() ; itr != map_try.end(); ++itr) {
236  if (dbe_ && (*itr).first.second >= 0) {
237  HcalDetId id= (*itr).first.first;
238  energysum ensum= (*itr).second;
239  int eta = id.ieta();
240  int phi = id.iphi();
241  double etax= eta-0.5;
242  double phix= phi-0.5;
243  meHcalEnergyl25_[(*itr).first.second]->Fill(etax,phix,ensum.e25);
244  meHcalEnergyl50_[(*itr).first.second]->Fill(etax,phix,ensum.e50);
245  meHcalEnergyl100_[(*itr).first.second]->Fill(etax,phix,ensum.e100);
246  meHcalEnergyl250_[(*itr).first.second]->Fill(etax,phix,ensum.e250);
247 
248  //LogDebug("HitsValidationHcal") <<" energy of tower ="<<(*itr).first<<"in time 25ns is== "<<(*itr).second.e25<<"in time 25-50ns=="<<(*itr).second.e50<<"in time 50-100ns=="<<(*itr).second.e100<<"in time 100-250 ns=="<<(*itr).second.e250;
249  }
250  }
251 
252 }
253 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
SimHitsValidationHcal(const edm::ParameterSet &ps)
type
Definition: HCALResponse.h:21
MonitorElement * meEnergy_HF
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElement * meHcalHitEta_[nType]
MonitorElement * meHcalEnergyl50_[nType]
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:942
MonitorElement * metime_enweighted_HB
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void analyze(const edm::Event &e, const edm::EventSetup &c)
T eta() const
MonitorElement * meHcalHitTimeEta_[nType]
void Fill(long long x)
MonitorElement * meEnergy_HB
MonitorElement * meHcalEnergyl250_[nType]
MonitorElement * metime_enweighted_HF
MonitorElement * meHcalEnergyl25_[nType]
void setVerbose(unsigned level)
Definition: DQMStore.cc:619
bool isValid() const
Definition: HandleBase.h:76
MonitorElement * meEnergy_HE
edm::EventID id() const
Definition: EventBase.h:56
MonitorElement * meHcalEnergyl100_[nType]
void showDirStructure(void) const
Definition: DQMStore.cc:3282
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1070
MonitorElement * metime_enweighted_HE
MonitorElement * metime_enweighted_HO
MonitorElement * meEnergy_HO
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:655
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hits_
Definition: DDAxes.h:10
void analyzeHits(std::vector< PCaloHit > &)