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