Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DTrackingResolutionGEANT.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTrackingResolutionGEANT.cc
4 // Created: Mon Feb 25 15:06:17 EST 2008
5 // Creator: davidl (on Darwin fwing-dhcp13.jlab.org 8.11.1 i386)
6 //
7 
8 #include <TApplication.h>
9 #include <TROOT.h>
10 
11 #include <iostream>
12 #include <cstdlib>
13 using namespace std;
14 
16 
17 #define _DBG_ cout<<__FILE__<<":"<<__LINE__<<" "
18 
19 
20 //---------------------------------
21 // DTrackingResolutionGEANT (Constructor)
22 //---------------------------------
24 {
25 
26  // Make sure a TApplication exists, otherwise, the following will fail
27  if(!gApplication){
28  int argc=0;
29  new TApplication("myapp", &argc, NULL);
30  }
31 
32  // Open ROOT file
33  file = new TFile("hd_res_charged.root");
34  if(!file->IsOpen()){
35  cout<<endl;
36  cout<<"Couldn't open resolution file \"hd_res_charged.root\"!"<<endl;
37  cout<<"Make sure it exists in the current directory and is readable,"<<endl;
38  cout<<endl;
39  exit(0);
40  }
41  cout<<"Opened \""<<file->GetName()<<"\""<<endl;
42 
43  // Read pt resolution histogram
44  file->GetObject("dpt_over_pt_vs_p_vs_theta_2", pt_res_hist);
45  if(!pt_res_hist){
46  cout<<endl;
47  cout<<"Couldn't find resolution histogram \"dpt_over_pt_vs_p_vs_theta_2\""<<endl;
48  cout<<"in ROOT file!"<<endl;
49  cout<<endl;
50  exit(0);
51  }
52 
53  // Read theta resolution histogram
54  file->GetObject("dtheta_vs_p_vs_theta_2", theta_res_hist);
55  if(!theta_res_hist){
56  cout<<endl;
57  cout<<"Couldn't find resolution histogram \"dtheta_vs_p_vs_theta_2\""<<endl;
58  cout<<"in ROOT file!"<<endl;
59  cout<<endl;
60  exit(0);
61  }
62 
63  // Read phi resolution histogram
64  phi_res_hist = (TH2D*)gROOT->FindObject("dphi_vs_p_vs_theta_2");
65  if(!phi_res_hist){
66  cout<<endl;
67  cout<<"Couldn't find resolution histogram \"dphi_vs_p_vs_theta_2\""<<endl;
68  cout<<"in ROOT file!"<<endl;
69  cout<<endl;
70  exit(0);
71  }
72 
73  // Read in efficiency histogram
74  efficiency_hist = (TH2D*)gROOT->FindObject("eff_vs_p_vs_theta");
75  if(!efficiency_hist){
76  cout<<endl;
77  cout<<"Couldn't find efficiency histogram \"eff_vs_p_vs_theta\""<<endl;
78  cout<<"in ROOT file!"<<endl;
79  cout<<endl;
80  exit(0);
81  }
82 }
83 
84 //---------------------------------
85 // ~DTrackingResolutionGEANT (Destructor)
86 //---------------------------------
88 {
89  delete file;
90 }
91 
92 //----------------
93 // GetResolution
94 //----------------
95 void DTrackingResolutionGEANT::GetResolution(int geanttype, const TVector3 &mom, double &pt_res, double &theta_res, double &phi_res)
96 {
97  /// Return the momentum and angular resolutions for a charged
98  /// particle based on results from GEANT-based Monte Carlo studies.
99 
100  // Find bins for this momentum.
101  // Note that we assume the 3 histograms have the same format.
102  // Namely, number of bins and range so we only need to calculate
103  // the theta and p bins once.
104  double p = mom.Mag();
105  double theta = mom.Theta()*57.3;
106  int pbin = pt_res_hist->GetYaxis()->FindBin(p);
107  int thetabin = pt_res_hist->GetXaxis()->FindBin(theta);
108 
109 //_DBG_<<"pbin="<<pbin<<" thetabin="<<thetabin<<endl;
110  if(pbin<1 || pbin>pt_res_hist->GetNbinsY()){pt_res=theta_res=phi_res=0.0; return;}
111  if(thetabin<1 || thetabin>pt_res_hist->GetNbinsX()){pt_res=theta_res=phi_res=0.0; return;}
112 
113  // Here we should do an interpolation from the surrounding bins.
114  // We have fairly small bins though so I can afford to be
115  // lazy :)
116  pt_res = pt_res_hist->GetBinContent(thetabin, pbin)/100.0;
117  theta_res = theta_res_hist->GetBinContent(thetabin, pbin);
118  phi_res = phi_res_hist->GetBinContent(thetabin, pbin);
119 }
120 
121 //----------------
122 // GetEfficiency
123 //----------------
124 double DTrackingResolutionGEANT::GetEfficiency(int geanttype, const TVector3 &mom)
125 {
126  /// Return the reconstruction efficiency for a charged
127  /// particle based on results from GEANT-based Monte Carlo studies.
128 
129  // Find bins for this momentum.
130  double p = mom.Mag();
131  double theta = mom.Theta()*57.3;
132  int pbin = efficiency_hist->GetYaxis()->FindBin(p);
133  int thetabin = efficiency_hist->GetXaxis()->FindBin(theta);
134 
135  if(pbin<1 || pbin>efficiency_hist->GetNbinsY())return 0.0;
136  if(thetabin<1 || thetabin>efficiency_hist->GetNbinsX())return 0.0;
137 
138  // Here we should do an interpolation from the surrounding bins.
139  // We have fairly small bins though so I can afford to be
140  // lazy :)
141  return efficiency_hist->GetBinContent(thetabin, pbin);
142 }
143 
144 
145 
double GetEfficiency(int geanttype, const TVector3 &mom)
void GetResolution(int geanttype, const TVector3 &mom, double &pt_res, double &theta_res, double &phi_res)