CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Histograms.h
Go to the documentation of this file.
1 #ifndef Validation_RecoMuon_Histograms_H
2 #define Validation_RecoMuon_Histograms_H
3 
12 #include "TH1F.h"
13 #include "TH2F.h"
14 #include "TString.h"
15 #include "TFile.h"
16 
20 
22 #include <iostream>
23 #include <vector>
24 #include <math.h>
25 
27 public:
28 
29  HTrackVariables(std::string dirName_, std::string name,std::string whereIs =""):theName(name.c_str()),where(whereIs.c_str()){
31  dbe_->cd();
32  std::string dirName=dirName_;
33  //dirName+="/";
34  //dirName+=name.c_str();
35 
36  dbe_->setCurrentFolder(dirName.c_str());
37 
38  hEta = dbe_->book1D(theName+"_Eta_"+where,"#eta at "+where,120,-3.,3.);
39  hPhi = dbe_->book1D(theName+"_Phi_"+where,"#phi at "+where,100,-Geom::pi(),Geom::pi());
40  hP = dbe_->book1D(theName+"_P_"+where,"p_{t} at "+where,1000,0,2000);
41  hPt = dbe_->book1D(theName+"_Pt_"+where,"p_{t} at "+where,1000,0,2000);
42  hCharge = dbe_->book1D(theName+"_charge_"+where,"Charge at "+where,4,-2.,2.);
43 
44  hEtaVsGen = dbe_->book1D(theName+"_EtaVsGen_"+where,"#eta at "+where,120,-3.,3.);
45  hPhiVsGen = dbe_->book1D(theName+"_PhiVsGen_"+where,"#phi at "+where,100,-Geom::pi(),Geom::pi());
46  hPtVsGen = dbe_->book1D(theName+"_PtVsGen_"+where,"p_{t} at "+where,1000,0,2000);
47 
48  hDeltaR = dbe_->book1D(theName+"_DeltaR_"+where,"Delta R w.r.t. sim track for "+where,1000,0,20);
49 
50  theEntries = 0;
51  }
52 
53  /*
54  HTrackVariables(std::string name, TFile* file):theName(name.c_str()){
55 
56  hEta = dynamic_cast<TH1F*>( file->Get(theName+"_Eta_"+where));
57  hPhi = dynamic_cast<TH1F*>( file->Get(theName+"_Phi_"+where));
58  hP = dynamic_cast<TH1F*>( file->Get(theName+"_P_"+where));
59  hPt = dynamic_cast<TH1F*>( file->Get(theName+"_Pt_"+where));
60  hCharge = dynamic_cast<TH1F*>( file->Get(theName+"_charge_"+where));
61  }
62  */
63 
65 
66  MonitorElement *eta() {return hEta;}
67  MonitorElement *phi() {return hPhi;}
68  MonitorElement *p() {return hP;}
69  MonitorElement *pt() {return hPt;}
71  int entries() {return theEntries;}
72 
73  void Fill(double p, double pt, double eta, double phi, double charge){
74  hEta->Fill(eta);
75  hPhi->Fill(phi);
76  hP->Fill(p);
77  hPt->Fill(pt);
78  hCharge->Fill(charge);
79  ++theEntries;
80  }
81 
82  void Fill(double pt, double eta, double phi){
83  hEtaVsGen->Fill(eta);
84  hPhiVsGen->Fill(phi);
85  hPtVsGen->Fill(pt);
86  }
87 
88  void FillDeltaR(double deltaR){
89  hDeltaR->Fill(deltaR);
90  }
91 
93 
96  // efficiencyHistos.push_back(computeEfficiency(p(),sim->p()));
97  efficiencyHistos.push_back(computeEfficiency(hPtVsGen,sim->pt()));
98  // efficiencyHistos.push_back(computeEfficiency(charge(),sim->charge()));
99 
100  double efficiency = 100*entries()/sim->entries();
101  return efficiency;
102  }
103 
105 
106  TH1F* hReco = reco->getTH1F();
107  TH1F* hSim = sim->getTH1F();
108 
109  std::string name = hReco->GetName();
110  std::string title = hReco->GetTitle();
111 
112  MonitorElement * me = dbe_->book1D(
113  "Eff_"+name,
114  "Efficiecny as a function of "+title,
115  hSim->GetNbinsX(),
116  hSim->GetXaxis()->GetXmin(),
117  hSim->GetXaxis()->GetXmax()
118  );
119 
120  me->getTH1F()->Divide(hReco,hSim,1.,1.,"b");
121 
122  // Set the error accordingly to binomial statistics
123  int nBinsEta = me->getTH1F()->GetNbinsX();
124  for(int bin = 1; bin <= nBinsEta; bin++) {
125  float nSimHit = hSim->GetBinContent(bin);
126  float eff = me->getTH1F()->GetBinContent(bin);
127  float error = 0;
128  if(nSimHit != 0 && eff <= 1) {
129  error = sqrt(eff*(1-eff)/nSimHit);
130  }
131  me->getTH1F()->SetBinError(bin, error);
132  }
133 
134  return me;
135  }
136 
137 
138  private:
140 
141  std::string theName;
142  std::string where;
143 
145 
151 
155 
157 
158  std::vector<MonitorElement*> efficiencyHistos;
159 
160 
161 };
162 
163 
164 class HResolution {
165 public:
166 
167  HResolution(std::string dirName_,std::string name,std::string whereIs):theName(name.c_str()),where(whereIs.c_str()){
168 
170  dbe_->cd();
171  std::string dirName=dirName_;
172  //dirName+="/";
173  //dirName+=name.c_str();
174 
175  dbe_->setCurrentFolder(dirName.c_str());
176 
177  double eta = 15.; int neta = 800;
178  double phi = 12.; int nphi = 400;
179  double pt = 60.; int npt = 2000;
180 
181  hEta = dbe_->book1D(theName+"_Eta_"+where,"#eta "+theName,neta,-eta,eta); // 400
182  hPhi = dbe_->book1D(theName+"_Phi_"+where,"#phi "+theName,nphi,-phi,phi); // 100
183 
184  hP = dbe_->book1D(theName+"_P_"+where,"P "+theName,400,-4,4); // 200
185  hPt = dbe_->book1D(theName+"_Pt_"+where,"P_{t} "+theName,npt,-pt,pt); // 200
186 
187  hCharge = dbe_->book1D(theName+"_charge_"+where,"Charge "+theName,4,-2.,2.);
188 
189 
190  h2Eta = dbe_->book2D(theName+"_Eta_vs_Eta"+where,"#eta "+theName+" as a function of #eta",200,-2.5,2.5,neta,-eta,eta);
191  h2Phi = dbe_->book2D(theName+"_Phi_vs_Phi"+where,"#phi "+theName+" as a function of #phi",100,-Geom::pi(),Geom::pi(),nphi,-phi,phi);
192 
193  h2P = dbe_->book2D(theName+"_P_vs_P"+where,"P "+theName+" as a function of P",1000,0,2000,400,-4,4);
194  h2Pt = dbe_->book2D(theName+"_Pt_vs_Pt"+where,"P_{t} "+theName+" as a function of P_{t}",1000,0,2000,npt,-pt,pt);
195 
196  h2PtVsEta = dbe_->book2D(theName+"_Pt_vs_Eta"+where,"P_{t} "+theName+" as a function of #eta",200,-2.5,2.5,npt,-pt,pt);
197  h2PtVsPhi = dbe_->book2D(theName+"_Pt_vs_Phi"+where,"P_{t} "+theName+" as a function of #phi",100,-Geom::pi(),Geom::pi(),npt,-pt,pt);
198 
199  h2EtaVsPt = dbe_->book2D(theName+"_Eta_vs_Pt"+where,"#eta "+theName+" as a function of P_{t}",1000,0,2000,neta,-eta,eta);
200  h2EtaVsPhi = dbe_->book2D(theName+"_Eta_vs_Phi"+where,"#eta "+theName+" as a function of #phi",100,-Geom::pi(),Geom::pi(),neta,-eta,eta);
201 
202  h2PhiVsPt = dbe_->book2D(theName+"_Phi_vs_Pt"+where,"#phi "+theName+" as a function of P_{t}",1000,0,2000,nphi,-phi,phi);
203  h2PhiVsEta = dbe_->book2D(theName+"_Phi_vs_Eta"+where,"#phi "+theName+" as a function of #eta",200,-2.5,2.5,nphi,-phi,phi);
204  }
205 
206  HResolution(std::string name, TFile* file):theName(name.c_str()){
207  // dynamic_cast<TH1F*>( file->Get(theName+"") );
208  }
209 
211 
212 
213  void Fill(double p, double pt, double eta, double phi,
214  double rp, double rpt,double reta, double rphi, double rcharge){
215 
216  Fill(rp, rpt, reta, rphi, rcharge);
217 
218 
219  h2Eta->Fill(eta,reta);
220  h2Phi->Fill(phi,rphi);
221 
222  h2P->Fill(p,rp);
223  h2Pt->Fill(pt,rpt);
224 
225  h2PtVsEta->Fill(eta,rpt);
226  h2PtVsPhi->Fill(phi,rpt);
227 
228  h2EtaVsPt ->Fill(pt,reta);
229  h2EtaVsPhi->Fill(phi,reta);
230 
231  h2PhiVsPt ->Fill(pt,rphi);
232  h2PhiVsEta->Fill(eta,rphi);
233  }
234 
235 
236  void Fill(double p, double pt, double eta, double phi,
237  double rp, double rpt){
238 
239  hP->Fill(rp);
240  hPt->Fill(rpt);
241 
242  h2P->Fill(p,rp);
243  // h2PVsEta->Fill(eta,rp);
244  // h2PVsPhi->Fill(phi,rp);
245 
246  h2Pt->Fill(pt,rpt);
247  h2PtVsEta->Fill(eta,rpt);
248  h2PtVsPhi->Fill(phi,rpt);
249  }
250 
251  void Fill(double rp, double rpt,
252  double reta, double rphi, double rcharge){
253 
254  hEta->Fill(reta);
255  hPhi->Fill(rphi);
256 
257  hP->Fill(rp);
258  hPt->Fill(rpt);
259 
260  hCharge->Fill(rcharge);
261  }
262 
263 
264 
265 private:
267 
268  std::string theName;
269  std::string where;
270 
273 
276 
278 
281 
284 
287 
290 
293 
294 };
295 
296 
298  public:
299  HResolution1DRecHit(std::string name):theName(name.c_str()){
300 
301  // Position, sigma, residual, pull
302  hResX = dbe_->book1D (theName+"_X_Res", "X residual", 5000, -0.5,0.5);
303  hResY = dbe_->book1D (theName+"_Y_Res", "Y residual", 5000, -1.,1.);
304  hResZ = dbe_->book1D (theName+"_Z_Res", "Z residual", 5000, -1.5,1.5);
305 
306  hResXVsEta = dbe_->book2D(theName+"_XResVsEta", "X residual vs eta",
307  200, -2.5,2.5, 5000, -1.5,1.5);
308  hResYVsEta = dbe_->book2D(theName+"_YResVsEta", "Y residual vs eta",
309  200, -2.5,2.5, 5000, -1.,1.);
310  hResZVsEta = dbe_->book2D(theName+"_ZResVsEta", "Z residual vs eta",
311  200, -2.5,2.5, 5000, -1.5,1.5);
312 
313  hXResVsPhi = dbe_->book2D(theName+"_XResVsPhi", "X residual vs phi",
314  100,-Geom::pi(),Geom::pi(), 5000, -0.5,0.5);
315  hYResVsPhi = dbe_->book2D(theName+"_YResVsPhi", "Y residual vs phi",
316  100,-Geom::pi(),Geom::pi(), 5000, -1.,1.);
317  hZResVsPhi = dbe_->book2D(theName+"_ZResVsPhi", "Z residual vs phi",
318  100,-Geom::pi(),Geom::pi(), 5000, -1.5,1.5);
319 
320  hXResVsPos = dbe_->book2D(theName+"_XResVsPos", "X residual vs position",
321  10000, -750,750, 5000, -0.5,0.5);
322  hYResVsPos = dbe_->book2D(theName+"_YResVsPos", "Y residual vs position",
323  10000, -740,740, 5000, -1.,1.);
324  hZResVsPos = dbe_->book2D(theName+"_ZResVsPos", "Z residual vs position",
325  10000, -1100,1100, 5000, -1.5,1.5);
326 
327  hXPull = dbe_->book1D (theName+"_XPull", "X pull", 600, -2,2);
328  hYPull = dbe_->book1D (theName+"_YPull", "Y pull", 600, -2,2);
329  hZPull = dbe_->book1D (theName+"_ZPull", "Z pull", 600, -2,2);
330 
331  hXPullVsPos = dbe_->book2D (theName+"_XPullVsPos", "X pull vs position",10000, -750,750, 600, -2,2);
332  hYPullVsPos = dbe_->book2D (theName+"_YPullVsPos", "Y pull vs position",10000, -740,740, 600, -2,2);
333  hZPullVsPos = dbe_->book2D (theName+"_ZPullVsPos", "Z pull vs position",10000, -1100,1100, 600, -2,2);
334  }
335 
336  HResolution1DRecHit(TString name_, TFile* file){}
337 
339 
340  void Fill(double x, double y, double z,
341  double dx, double dy, double dz,
342  double errx, double erry, double errz,
343  double eta, double phi) {
344 
345  double rx = dx/x, ry = dy/y, rz = dz/z;
346 
347  hResX->Fill(rx);
348  hResY->Fill(ry);
349  hResZ->Fill(rz);
350 
351  hResXVsEta->Fill(eta,rx);
352  hResYVsEta->Fill(eta,ry);
353  hResZVsEta->Fill(eta,rz);
354 
355  hXResVsPhi->Fill(phi,rx);
356  hYResVsPhi->Fill(phi,ry);
357  hZResVsPhi->Fill(phi,rz);
358 
359  hXResVsPos->Fill(x,rx);
360  hYResVsPos->Fill(y,ry);
361  hZResVsPos->Fill(z,rz);
362 
363  if(errx < 1e-6)
364  std::cout << "NO proper error set for X: "<<errx<<std::endl;
365  else{
366  hXPull->Fill(dx/errx);
367  hXPullVsPos->Fill(x,dx/errx);
368  }
369 
370  if(erry < 1e-6)
371  std::cout << "NO proper error set for Y: "<<erry<<std::endl;
372  else{
373  hYPull->Fill(dy/erry);
374  hYPullVsPos->Fill(y,dy/erry);
375  }
376  if(errz < 1e-6)
377  std::cout << "NO proper error set for Z: "<<errz<<std::endl;
378  else{
379  hZPull->Fill(dz/errz);
380  hZPullVsPos->Fill(z,dz/errz);
381  }
382  }
383 
384 
385 
386  public:
387  std::string theName;
388 
392 
396 
400 
404 
408 
412 
413  private:
415 };
416 #endif
417 
MonitorElement * hResXVsEta
Definition: Histograms.h:393
DQMStore * dbe_
Definition: Histograms.h:266
MonitorElement * hZPull
Definition: Histograms.h:407
MonitorElement * h2PhiVsPt
Definition: Histograms.h:291
MonitorElement * h2Eta
Definition: Histograms.h:279
MonitorElement * h2EtaVsPhi
Definition: Histograms.h:289
void Fill(double p, double pt, double eta, double phi, double rp, double rpt, double reta, double rphi, double rcharge)
Definition: Histograms.h:213
MonitorElement * hCharge
Definition: Histograms.h:150
std::string where
Definition: Histograms.h:269
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
MonitorElement * hPt
Definition: Histograms.h:149
double computeEfficiency(HTrackVariables *sim)
Definition: Histograms.h:92
HResolution(std::string name, TFile *file)
Definition: Histograms.h:206
MonitorElement * hP
Definition: Histograms.h:274
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:406
HTrackVariables(std::string dirName_, std::string name, std::string whereIs="")
Definition: Histograms.h:29
MonitorElement * hPt
Definition: Histograms.h:275
MonitorElement * hPhi
Definition: Histograms.h:147
MonitorElement * hXPullVsPos
Definition: Histograms.h:409
MonitorElement * h2P
Definition: Histograms.h:282
MonitorElement * hCharge
Definition: Histograms.h:277
MonitorElement * p()
Definition: Histograms.h:68
MonitorElement * hPhi
Definition: Histograms.h:272
T eta() const
MonitorElement * h2PhiVsEta
Definition: Histograms.h:292
MonitorElement * eta()
Definition: Histograms.h:66
Definition: sim.h:19
void Fill(double pt, double eta, double phi)
Definition: Histograms.h:82
MonitorElement * hP
Definition: Histograms.h:148
double double double z
MonitorElement * hXPull
Definition: Histograms.h:405
std::string theName
Definition: Histograms.h:268
void Fill(long long x)
MonitorElement * hYPullVsPos
Definition: Histograms.h:410
MonitorElement * hYResVsPhi
Definition: Histograms.h:398
std::vector< MonitorElement * > efficiencyHistos
Definition: Histograms.h:158
MonitorElement * hPhiVsGen
Definition: Histograms.h:153
std::string theName
Definition: Histograms.h:387
MonitorElement * hResYVsEta
Definition: Histograms.h:394
MonitorElement * phi()
Definition: Histograms.h:67
MonitorElement * hResZVsEta
Definition: Histograms.h:395
T sqrt(T t)
Definition: SSEVec.h:46
MonitorElement * h2Phi
Definition: Histograms.h:280
void Fill(double rp, double rpt, double reta, double rphi, double rcharge)
Definition: Histograms.h:251
MonitorElement * h2Pt
Definition: Histograms.h:283
MonitorElement * hXResVsPos
Definition: Histograms.h:401
void Fill(double p, double pt, double eta, double phi, double rp, double rpt)
Definition: Histograms.h:236
MonitorElement * computeEfficiency(MonitorElement *reco, MonitorElement *sim)
Definition: Histograms.h:104
MonitorElement * hZPullVsPos
Definition: Histograms.h:411
MonitorElement * hPtVsGen
Definition: Histograms.h:154
MonitorElement * charge()
Definition: Histograms.h:70
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
MonitorElement * pt()
Definition: Histograms.h:69
HResolution1DRecHit(TString name_, TFile *file)
Definition: Histograms.h:336
MonitorElement * hYPull
Definition: Histograms.h:406
void Fill(double p, double pt, double eta, double phi, double charge)
Definition: Histograms.h:73
MonitorElement * hXResVsPhi
Definition: Histograms.h:397
MonitorElement * hZResVsPhi
Definition: Histograms.h:399
TH1F * getTH1F(void) const
MonitorElement * hEtaVsGen
Definition: Histograms.h:152
MonitorElement * hYResVsPos
Definition: Histograms.h:402
double pi()
Definition: Pi.h:31
std::string theName
Definition: Histograms.h:141
MonitorElement * h2EtaVsPt
Definition: Histograms.h:288
MonitorElement * h2PtVsPhi
Definition: Histograms.h:286
tuple cout
Definition: gather_cfg.py:121
void Fill(double x, double y, double z, double dx, double dy, double dz, double errx, double erry, double errz, double eta, double phi)
Definition: Histograms.h:340
HResolution(std::string dirName_, std::string name, std::string whereIs)
Definition: Histograms.h:167
MonitorElement * hResY
Definition: Histograms.h:390
x
Definition: VDTMath.h:216
MonitorElement * hZResVsPos
Definition: Histograms.h:403
HResolution1DRecHit(std::string name)
Definition: Histograms.h:299
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:845
virtual Int_t Fill(Double_t x, Double_t y)
Definition: Histograms.h:1741
MonitorElement * hEta
Definition: Histograms.h:271
MonitorElement * hResZ
Definition: Histograms.h:391
MonitorElement * h2PtVsEta
Definition: Histograms.h:285
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
void FillDeltaR(double deltaR)
Definition: Histograms.h:88
MonitorElement * hDeltaR
Definition: Histograms.h:156
DQMStore * dbe_
Definition: Histograms.h:139
MonitorElement * hResX
Definition: Histograms.h:389
MonitorElement * hEta
Definition: Histograms.h:146
std::string where
Definition: Histograms.h:142
Definition: DDAxes.h:10