11 #include<boost/make_shared.hpp>
13 #define SMART(expr) boost::shared_ptr<expr>
14 #define NEW(expr) boost::make_shared<expr>
16 #include <phfield/PHFieldUtility.h>
20 #include <TMatrixDSym.h>
34 #include <GenFit/AbsTrackRep.h>
35 #include <GenFit/RKTrackRep.h>
36 #include <GenFit/StateOnPlane.h>
39 #include <phgenfit/Fitter.h>
40 #include <phgenfit/Track.h>
41 #include <phgenfit/Measurement.h>
42 #include <phgenfit/PlanarMeasurement.h>
44 #define LogDEBUG std::cout<<"DEBUG: "<<__LINE__<<"\n"
53 int main(
int argc,
char**argv) {
55 TFile *fPHG4Hits = TFile::Open(
"AnaSvtxTracksForGenFit.root",
"read");
57 std::cout <<
"No TFile Openned: " << __LINE__ <<
"\n";
60 TTree *
T = (TTree*) fPHG4Hits->Get(
"tracks");
62 std::cout <<
"No TTree Found: " << __LINE__ <<
"\n";
70 double resolution_detector_xy = 0.005/3.;
73 TH2D *hpT_residual_vs_pT =
new TH2D(
"hpT_residual_vs_pT",
"#Delta pT/pT; pT[GeV/c]; #Delta pT/pT", 40, 0.5, 40.5, 1000, -1, 1);
75 TH2D *hDCAr_vs_pT =
new TH2D(
"hDCAr_vs_pT",
"DCAr vs. p; p [GeV/c]; DCAr [cm]", 40, 0.5, 40.5, 1000, -0.1, 0.1);
84 Float_t Cluster_size_dphi[
NLAYERS];
85 Float_t Cluster_size_dz[
NLAYERS];
95 Float_t AlanDion_dca2d;
98 T->SetBranchAddress(
"nhits", &nhits);
99 T->SetBranchAddress(
"gpx", &True_px);
100 T->SetBranchAddress(
"gpy", &True_py);
101 T->SetBranchAddress(
"gpz", &True_pz);
102 T->SetBranchAddress(
"gvx", &True_vx);
103 T->SetBranchAddress(
"gvy", &True_vy);
104 T->SetBranchAddress(
"gvz", &True_vz);
105 T->SetBranchAddress(
"px", &AlanDion_px);
106 T->SetBranchAddress(
"py", &AlanDion_py);
107 T->SetBranchAddress(
"pz", &AlanDion_pz);
108 T->SetBranchAddress(
"dca2d", &AlanDion_dca2d);
109 T->SetBranchAddress(
"x", Cluster_x);
110 T->SetBranchAddress(
"y", Cluster_y);
111 T->SetBranchAddress(
"z", Cluster_z);
112 T->SetBranchAddress(
"size_dphi", Cluster_size_dphi);
113 T->SetBranchAddress(
"size_dz", Cluster_size_dz);
115 double nentries = 10;
117 for (
unsigned int ientry = 0; ientry < nentries; ++ientry) {
119 if(ientry%1000==0) std::cout<<
"Processing: "<<100.*ientry/nentries <<
"%"<<
"\n";
129 TVector3 init_pos(0, 0, 0);
130 TVector3 True_mom(True_px, True_py, True_pz);
133 const bool smearPosMom =
true;
134 const double posSmear = 10 * resolution_detector_xy;
135 const double momSmear = 3. / 180. * TMath::Pi();
136 const double momMagSmear = 0.1;
138 TVector3 seed_pos(init_pos);
139 TVector3 seed_mom(True_mom);
141 seed_pos.SetX(gRandom->Gaus(seed_pos.X(), posSmear));
142 seed_pos.SetY(gRandom->Gaus(seed_pos.Y(), posSmear));
143 seed_pos.SetZ(gRandom->Gaus(seed_pos.Z(), posSmear));
145 seed_mom.SetPhi(gRandom->Gaus(True_mom.Phi(), momSmear));
146 seed_mom.SetTheta(gRandom->Gaus(True_mom.Theta(), momSmear));
148 gRandom->Gaus(True_mom.Mag(),
149 momMagSmear * True_mom.Mag()));
153 TMatrixDSym seed_cov(6);
155 for (
int idim = 0; idim < 3; ++idim)
156 seed_cov(idim, idim) = resolution_detector_xy
157 * resolution_detector_xy;
158 for (
int idim = 3; idim < 6; ++idim)
159 seed_cov(idim, idim) = pow(
160 resolution_detector_xy /
NLAYERS / sqrt(3), 2);
173 std::vector<PHGenFit::Measurement*> measurements;
174 for (
int imeas = 0; imeas <
NLAYERS; imeas++) {
175 TVector3
pos(Cluster_x[imeas],Cluster_y[imeas],Cluster_z[imeas]);
176 TVector3
n(Cluster_x[imeas],Cluster_y[imeas],0);
178 TVector3
u = v.Cross(n);
182 Cluster_size_dphi[imeas],Cluster_size_dz[imeas]);
183 measurements.push_back(meas);
194 TVector3(0, 0, 0), TVector3(0, 0, 1));
203 TVector3 GenFit_mom = state_at_beam_line->
getMom();
205 TVector3 AlanDion_mom(AlanDion_px,AlanDion_py,AlanDion_pz);
207 hpT_residual_vs_pT->Fill(True_mom.Pt(),(GenFit_mom.Pt() - True_mom.Pt())/True_mom.Pt());
209 hDCAr_vs_pT->Fill(True_mom.Mag(),state_at_beam_line->
getState()[3]);
211 delete state_at_beam_line;
213 measurements.clear();
217 gStyle->SetOptStat(000000000);
219 TF1 *tf_pT_resolution =
new TF1(
"tf_pT_resolution",
"sqrt([0]*[0] + x*x*[1]*[1])", 0, 40);
220 tf_pT_resolution->SetParameters(0,0);
221 TCanvas *c3 =
new TCanvas(
"c3",
"c3");
224 hpT_residual_vs_pT->FitSlicesY();
225 TH1D *hpT_resolution_vs_pT = (TH1D*)gDirectory->Get(
"hpT_residual_vs_pT_2");
226 hpT_resolution_vs_pT->SetTitle(
"PHGenFit: #sigma_{p_{T}}/p_{T}; p_{T}[GeV/c]; #sigma_{p_{T}}/p_{T}");
227 hpT_resolution_vs_pT->SetMarkerStyle(20);
228 hpT_resolution_vs_pT->Draw(
"e");
229 hpT_resolution_vs_pT->Fit(tf_pT_resolution);
231 hDCAr_vs_pT->FitSlicesY();
232 TH1D *hDCAr_resolution_vs_pT = (TH1D*) gDirectory->Get(
"hDCAr_vs_pT_2");
233 hDCAr_resolution_vs_pT->SetTitle(
234 "PHGenFit: #sigma_{DCAr} [cm]; p [GeV/c]; #sigma_{DCAr}");
235 hDCAr_resolution_vs_pT->SetMarkerStyle(20);
236 hDCAr_resolution_vs_pT->Draw(
"e");
238 c3->Print(
"pT_DCA_resolution.root");
249 std::cout<<
"SUCCESS! \n";