CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalSimHitsValidation.cc
Go to the documentation of this file.
3 
4 
6  // DQM ROOT output
7  outputFile_ = conf.getUntrackedParameter<std::string>("outputFile", "myfile.root");
8 
9  if ( outputFile_.size() != 0 ) { edm::LogInfo("OutputInfo") << " Hcal SimHit Task histograms will be saved to '" << outputFile_.c_str() << "'";
10  } else {
11  edm::LogInfo("OutputInfo") << " Hcal SimHit Task histograms will NOT be saved";
12  }
13 
14  nevtot = 0;
15 
16  dbe_ = 0;
17  // get hold of back-end interface
19 
20  Char_t histo[200];
21 
22  if ( dbe_ ) {
23  dbe_->setCurrentFolder("HcalSimHitsV/HcalSimHitTask");
24 
25  // General counters
26  sprintf (histo, "N_HB" );
27  Nhb = dbe_->book1D(histo, histo, 2600,0.,2600.);
28  sprintf (histo, "N_HE" );
29  Nhe = dbe_->book1D(histo, histo, 2600,0.,2600.);
30  sprintf (histo, "N_HO" );
31  Nho = dbe_->book1D(histo, histo, 2200,0.,2200.);
32  sprintf (histo, "N_HF" );
33  Nhf = dbe_->book1D(histo, histo, 1800,0., 1800.);
34 
35  //Mean energy vs iEta TProfiles
36  sprintf (histo, "emean_vs_ieta_HB1" );
37  emean_vs_ieta_HB1 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s");
38  sprintf (histo, "emean_vs_ieta_HB2" );
39  emean_vs_ieta_HB2 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s");
40  sprintf (histo, "emean_vs_ieta_HE1" );
41  emean_vs_ieta_HE1 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10. ,2000., "s" );
42  sprintf (histo, "emean_vs_ieta_HE2" );
43  emean_vs_ieta_HE2 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s");
44  sprintf (histo, "emean_vs_ieta_HE3" );
45  emean_vs_ieta_HE3 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s" );
46  sprintf (histo, "emean_vs_ieta_HO" );
47  emean_vs_ieta_HO = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s" );
48  sprintf (histo, "emean_vs_ieta_HF1" );
49  emean_vs_ieta_HF1 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s" );
50  sprintf (histo, "emean_vs_ieta_HF2" );
51  emean_vs_ieta_HF2 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s" );
52 
53  //Occupancy vs. iEta TH1Fs
54  sprintf (histo, "occupancy_vs_ieta_HB1" );
55  occupancy_vs_ieta_HB1 = dbe_->book1D(histo, histo, 82, -41., 41.);
56  sprintf (histo, "occupancy_vs_ieta_HB2" );
57  occupancy_vs_ieta_HB2 = dbe_->book1D(histo, histo, 82, -41., 41.);
58  sprintf (histo, "occupancy_vs_ieta_HE1" );
59  occupancy_vs_ieta_HE1 = dbe_->book1D(histo, histo, 82, -41., 41.);
60  sprintf (histo, "occupancy_vs_ieta_HE2" );
61  occupancy_vs_ieta_HE2 = dbe_->book1D(histo, histo, 82, -41., 41.);
62  sprintf (histo, "occupancy_vs_ieta_HE3" );
63  occupancy_vs_ieta_HE3 = dbe_->book1D(histo, histo, 82, -41., 41.);
64  sprintf (histo, "occupancy_vs_ieta_HO" );
65  occupancy_vs_ieta_HO = dbe_->book1D(histo, histo, 82, -41., 41.);
66  sprintf (histo, "occupancy_vs_ieta_HF1" );
67  occupancy_vs_ieta_HF1 = dbe_->book1D(histo, histo, 82, -41., 41.);
68  sprintf (histo, "occupancy_vs_ieta_HF2" );
69  occupancy_vs_ieta_HF2 = dbe_->book1D(histo, histo, 82, -41., 41.);
70 
71  //Energy spectra
72  sprintf (histo, "HcalSimHitTask_energy_of_simhits_HB" ) ;
73  meSimHitsEnergyHB = dbe_->book1D(histo, histo, 510 , -0.1 , 5.);
74 
75  sprintf (histo, "HcalSimHitTask_energy_of_simhits_HE" ) ;
76  meSimHitsEnergyHE = dbe_->book1D(histo, histo, 510, -0.02, 2.);
77 
78  sprintf (histo, "HcalSimHitTask_energy_of_simhits_HO" ) ;
79  meSimHitsEnergyHO = dbe_->book1D(histo, histo, 510 , -0.1 , 5.);
80 
81  sprintf (histo, "HcalSimHitTask_energy_of_simhits_HF" ) ;
82  meSimHitsEnergyHF = dbe_->book1D(histo, histo, 1010 , -5. , 500.);
83 
84  //Energy in Cone
85  sprintf (histo, "HcalSimHitTask_En_simhits_cone_profile_vs_ieta_all_depths");
86  meEnConeEtaProfile = dbe_->bookProfile(histo, histo, 82, -41., 41., 210, -10., 200.);
87 
88  sprintf (histo, "HcalSimHitTask_En_simhits_cone_profile_vs_ieta_all_depths_E");
89  meEnConeEtaProfile_E = dbe_->bookProfile(histo, histo, 82, -41., 41., 210, -10., 200.);
90 
91  sprintf (histo, "HcalSimHitTask_En_simhits_cone_profile_vs_ieta_all_depths_EH");
92  meEnConeEtaProfile_EH = dbe_->bookProfile(histo, histo, 82, -41., 41., 210, -10., 200.);
93 
94  } //end-of if(_dbe)
95 
96 }
97 
98 
100 
102  //before check that histos are there....
103 
104  // check if ME still there (and not killed by MEtoEDM for memory saving)
105  if( dbe_ )
106  {
107  // check existence of first histo in the list
108  if (! dbe_->get("HcalSimHitsV/HcalSimHitTask/N_HB")) return;
109  }
110  else
111  return;
112 
113  //======================================
114 
115  for (int i = 1; i <= occupancy_vs_ieta_HB1->getNbinsX(); i++){
116 
117  int ieta = i - 42; // -41 -1, 0 40
118  if(ieta >=0 ) ieta +=1; // -41 -1, 1 41 - to make it detector-like
119 
120  float phi_factor;
121 
122  if (fabs(ieta) <= 20) phi_factor = 72.;
123  else if (fabs(ieta) < 40) phi_factor = 36.;
124  else phi_factor = 18.;
125 
126  float cnorm;
127 
128  //Occupancy vs. iEta TH1Fs
129  cnorm = occupancy_vs_ieta_HB1->getBinContent(i) / (phi_factor * nevtot);
131  cnorm = occupancy_vs_ieta_HB2->getBinContent(i) / (phi_factor * nevtot);
133 
134  cnorm = occupancy_vs_ieta_HE1->getBinContent(i) / (phi_factor * nevtot);
136  cnorm = occupancy_vs_ieta_HE2->getBinContent(i) / (phi_factor * nevtot);
138  cnorm = occupancy_vs_ieta_HE3->getBinContent(i) / (phi_factor * nevtot);
140 
141  cnorm = occupancy_vs_ieta_HO->getBinContent(i) / (phi_factor * nevtot);
143 
144  cnorm = occupancy_vs_ieta_HF1->getBinContent(i) / (phi_factor * nevtot);
146  cnorm = occupancy_vs_ieta_HF2->getBinContent(i) / (phi_factor * nevtot);
148  }
149 
150 
151  if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
152 }
153 
154 
156 
158 
159  using namespace edm;
160  using namespace std;
161 
162  //===========================================================================
163  // Getting SimHits
164  //===========================================================================
165 
166  double phi_MC = -999.; // phi of initial particle from HepMC
167  double eta_MC = -999.; // eta of initial particle from HepMC
168 
170  // ev.getByLabel("VtxSmeared",evtMC);
171  ev.getByLabel("generator",evtMC); // generator in late 310_preX
172  if (!evtMC.isValid()) {
173  std::cout << "no HepMCProduct found" << std::endl;
174  }
175 
176  // MC particle with highest pt is taken as a direction reference
177  double maxPt = -99999.;
178  int npart = 0;
179 
180  const HepMC::GenEvent * myGenEvent = evtMC->GetEvent();
181  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
182  p != myGenEvent->particles_end(); ++p ) {
183  double phip = (*p)->momentum().phi();
184  double etap = (*p)->momentum().eta();
185  double pt = (*p)->momentum().perp();
186  if(pt > maxPt) {npart++; maxPt = pt; phi_MC = phip; eta_MC = etap; }
187  }
188 
189  double partR = 0.3;
190 
191 
192  //Hcal SimHits
193 
194  //Approximate calibration constants
195  const float calib_HB = 120.;
196  const float calib_HE = 190.;
197  const float calib_HF1 = 1.0/0.383;
198  const float calib_HF2 = 1.0/0.368;
199 
201  ev.getByLabel("g4SimHits","HcalHits",hcalHits);
202  const PCaloHitContainer * SimHitResult = hcalHits.product () ;
203 
204  float eta_diff;
205  float etaMax = 9999;
206  int ietaMax = 0;
207 
208  double HcalCone = 0;
209 
210  c.get<CaloGeometryRecord>().get (geometry);
211 
212  for (std::vector<PCaloHit>::const_iterator SimHits = SimHitResult->begin () ; SimHits != SimHitResult->end(); ++SimHits) {
213  HcalDetId cell(SimHits->id());
214  const CaloCellGeometry* cellGeometry = geometry->getSubdetectorGeometry (cell)->getGeometry (cell);
215  double etaS = cellGeometry->getPosition().eta () ;
216  double phiS = cellGeometry->getPosition().phi () ;
217  double en = SimHits->energy();
218 
219  int sub = cell.subdet();
220  int depth = cell.depth();
221  double ieta = cell.ieta();
222 
223  //Energy in Cone
224  double r = dR(eta_MC, phi_MC, etaS, phiS);
225 
226  if (r < partR){
227  eta_diff = fabs(eta_MC - etaS);
228  if(eta_diff < etaMax) {
229  etaMax = eta_diff;
230  ietaMax = cell.ieta();
231  }
232  //Approximation of calibration
233  if (sub == 1) HcalCone += en*calib_HB;
234  else if (sub == 2) HcalCone += en*calib_HE;
235  else if (sub == 4 && depth == 1) HcalCone += en*calib_HF1;
236  else if (sub == 4 && depth == 2) HcalCone += en*calib_HF2;
237  }
238 
239  //Account for lack of ieta = 0
240  if (ieta > 0) ieta--;
241 
242  //HB
243  if (sub == 1){
244  meSimHitsEnergyHB->Fill(en);
245  if (depth == 1){
246  emean_vs_ieta_HB1->Fill(double(ieta), en);
247  occupancy_vs_ieta_HB1->Fill(double(ieta));
248  }
249  if (depth == 2){
250  emean_vs_ieta_HB2->Fill(double(ieta), en);
251  occupancy_vs_ieta_HB2->Fill(double(ieta));
252  }
253  }
254  //HE
255  if (sub == 2){
256  meSimHitsEnergyHE->Fill(en);
257  if (depth == 1){
258  emean_vs_ieta_HE1->Fill(double(ieta), en);
259  occupancy_vs_ieta_HE1->Fill(double(ieta));
260  }
261  if (depth == 2){
262  emean_vs_ieta_HE2->Fill(double(ieta), en);
263  occupancy_vs_ieta_HE2->Fill(double(ieta));
264  }
265  if (depth == 3){
266  emean_vs_ieta_HE3->Fill(double(ieta), en);
267  occupancy_vs_ieta_HE3->Fill(double(ieta));
268  }
269  }
270  //HO
271  if (sub == 3){
272  meSimHitsEnergyHO->Fill(en);
273  emean_vs_ieta_HO->Fill(double(ieta), en);
274  occupancy_vs_ieta_HO->Fill(double(ieta));
275  }
276  //HF
277  if (sub == 4){
278  meSimHitsEnergyHF->Fill(en);
279  if (depth == 1){
280  emean_vs_ieta_HF1->Fill(double(ieta), en);
281  occupancy_vs_ieta_HF1->Fill(double(ieta));
282  }
283  if (depth == 2){
284  emean_vs_ieta_HF2->Fill(double(ieta), en);
285  occupancy_vs_ieta_HF2->Fill(double(ieta));
286  }
287  }
288  }
289 
290  //Ecal EB SimHits
292  ev.getByLabel("g4SimHits","EcalHitsEB",ecalEBHits);
293  const PCaloHitContainer * SimHitResultEB = ecalEBHits.product () ;
294 
295  double EcalCone = 0;
296 
297  for (std::vector<PCaloHit>::const_iterator SimHits = SimHitResultEB->begin () ; SimHits != SimHitResultEB->end(); ++SimHits) {
298 
299  EBDetId EBid = EBDetId(SimHits->id());
300 
301  const CaloCellGeometry* cellGeometry = geometry->getSubdetectorGeometry (EBid)->getGeometry (EBid) ;
302  double etaS = cellGeometry->getPosition().eta () ;
303  double phiS = cellGeometry->getPosition().phi () ;
304  double en = SimHits->energy();
305 
306  double r = dR(eta_MC, phi_MC, etaS, phiS);
307 
308  if (r < partR) EcalCone += en;
309  }
310 
311  //Ecal EE SimHits
313  ev.getByLabel("g4SimHits","EcalHitsEE",ecalEEHits);
314  const PCaloHitContainer * SimHitResultEE = ecalEEHits.product () ;
315 
316  for (std::vector<PCaloHit>::const_iterator SimHits = SimHitResultEE->begin () ; SimHits != SimHitResultEE->end(); ++SimHits) {
317 
318  EEDetId EEid = EEDetId(SimHits->id());
319 
320  const CaloCellGeometry* cellGeometry = geometry->getSubdetectorGeometry (EEid)->getGeometry (EEid) ;
321  double etaS = cellGeometry->getPosition().eta () ;
322  double phiS = cellGeometry->getPosition().phi () ;
323  double en = SimHits->energy();
324 
325  double r = dR(eta_MC, phi_MC, etaS, phiS);
326 
327  if (r < partR) EcalCone += en;
328  }
329 
330  if (ietaMax != 0){ //If ietaMax == 0, there were no good HCAL SimHits
331  if (ietaMax > 0) ietaMax--; //Account for lack of ieta = 0
332 
333  meEnConeEtaProfile ->Fill(double(ietaMax), HcalCone);
334  meEnConeEtaProfile_E ->Fill(double(ietaMax), EcalCone);
335  meEnConeEtaProfile_EH ->Fill(double(ietaMax), HcalCone+EcalCone);
336  }
337 
338  nevtot++;
339 }
340 
341 
342 double HcalSimHitsValidation::dR(double eta1, double phi1, double eta2, double phi2) {
343  double PI = 3.1415926535898;
344  double deltaphi= phi1 - phi2;
345  if( phi2 > phi1 ) { deltaphi= phi2 - phi1;}
346  if(deltaphi > PI) { deltaphi = 2.*PI - deltaphi;}
347  double deltaeta = eta2 - eta1;
348  double tmp = sqrt(deltaeta* deltaeta + deltaphi*deltaphi);
349  return tmp;
350 }
351 
352 double HcalSimHitsValidation::phi12(double phi1, double en1, double phi2, double en2) {
353  // weighted mean value of phi1 and phi2
354 
355  double tmp;
356  double PI = 3.1415926535898;
357  double a1 = phi1; double a2 = phi2;
358 
359  if( a1 > 0.5*PI && a2 < 0.) a2 += 2*PI;
360  if( a2 > 0.5*PI && a1 < 0.) a1 += 2*PI;
361  tmp = (a1 * en1 + a2 * en2)/(en1 + en2);
362  if(tmp > PI) tmp -= 2.*PI;
363 
364  return tmp;
365 
366 }
367 
368 double HcalSimHitsValidation::dPhiWsign(double phi1, double phi2) {
369  // clockwise phi2 w.r.t phi1 means "+" phi distance
370  // anti-clockwise phi2 w.r.t phi1 means "-" phi distance
371 
372  double PI = 3.1415926535898;
373  double a1 = phi1; double a2 = phi2;
374  double tmp = a2 - a1;
375  if( a1*a2 < 0.) {
376  if(a1 > 0.5 * PI) tmp += 2.*PI;
377  if(a2 > 0.5 * PI) tmp -= 2.*PI;
378  }
379  return tmp;
380 
381 }
382 
383 
384 
386 
MonitorElement * meEnConeEtaProfile
T getUntrackedParameter(std::string const &, T const &) const
MonitorElement * meSimHitsEnergyHE
int i
Definition: DBlmapReader.cc:9
void setBinContent(int binx, double content)
set content of bin (1-D)
std::vector< PCaloHit > PCaloHitContainer
double dR(double eta1, double phi1, double eta2, double phi2)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
#define PI
double phi12(double phi1, double en1, double phi2, double en2)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2113
MonitorElement * meSimHitsEnergyHO
double npart
Definition: HydjetWrapper.h:45
MonitorElement * emean_vs_ieta_HE1
void Fill(long long x)
MonitorElement * meEnConeEtaProfile_E
MonitorElement * occupancy_vs_ieta_HB2
MonitorElement * occupancy_vs_ieta_HE2
MonitorElement * meSimHitsEnergyHF
MonitorElement * emean_vs_ieta_HO
T sqrt(T t)
Definition: SSEVec.h:46
MonitorElement * occupancy_vs_ieta_HE3
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1031
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1468
double dPhiWsign(double phi1, double phi2)
MonitorElement * emean_vs_ieta_HE2
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
tuple conf
Definition: dbtoconf.py:185
HcalSimHitsValidation(edm::ParameterSet const &conf)
MonitorElement * emean_vs_ieta_HE3
MonitorElement * emean_vs_ieta_HF1
MonitorElement * occupancy_vs_ieta_HB1
MonitorElement * emean_vs_ieta_HF2
const T & get() const
Definition: EventSetup.h:55
MonitorElement * meEnConeEtaProfile_EH
MonitorElement * emean_vs_ieta_HB1
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double getBinContent(int binx) const
get content of bin (1-D)
MonitorElement * occupancy_vs_ieta_HF2
MonitorElement * occupancy_vs_ieta_HO
int getNbinsX(void) const
get # of bins in X-axis
edm::ESHandle< CaloGeometry > geometry
tuple cout
Definition: gather_cfg.py:121
MonitorElement * meSimHitsEnergyHB
virtual void analyze(edm::Event const &ev, edm::EventSetup const &c)
MonitorElement * emean_vs_ieta_HB2
MonitorElement * occupancy_vs_ieta_HF1
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
MonitorElement * occupancy_vs_ieta_HE1