FairRoot/PandaRoot
anaLmdCluster.C
Go to the documentation of this file.
1 /*
2  * anaLmdCluster.C
3  * Created on: Oct 6, 2009
4  * Author: huagen
5  */
6 //the macro anaLmdCluster is to plot the reco_hits and track theta
7 {
8 
9  // load library by run Macro
10  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
11 
12  // Timer
13  TStopwatch timer;
14  timer.Start();
15 
16 // define some variables
17  int nEvents = 1e7;
18  bool verbose = false;
19  double pi = TMath::Pi();
20 
21 //To open the data file, MC point and Recon Hit
22  TFile *mcf = new TFile("/private/huagen/simdata/Lmd_MC_BD_DPM_elastic_6.2_1.9mrad_5M_1.root");
23 // TFile *mcf = new TFile("/private/huagen/simdata/Lmd_Test.root");
24  TTree *tree1 = (TTree*)mcf->Get("pndsim");
25  TClonesArray *mc_array = new TClonesArray("PndSdsMCPoint");
26  tree1->SetBranchAddress("LMDPoint",&mc_array);
27 
28  TClonesArray *mc_track = new TClonesArray("PndMCTrack");
29  tree1->SetBranchAddress("MCTrack",&mc_track);
30 
31  TFile *rcf = new TFile("/private/huagen/simdata/Lmd_Reco_BD_DPM_elastic_6.2_1.9mrad_5M_1.root");
32 // TFile *rcf = new TFile("/private/huagen/simdata/Lmd_Test_Reco.root");
33  TTree *tree2 = (TTree*)rcf->Get("pndsim");
34  TClonesArray *hit_array = new TClonesArray("PndSdsHit");
35  tree2->SetBranchAddress("LMDHitsStrip",&hit_array);
36 
37 //To define the histograms
38  TH1F *mcTheta = new TH1F("MCHit theta","Theta fitted by MCHits",300, 0.001, 0.01);
39  TH1F *rcTheta = new TH1F("Reco theta","Theta determined by RecoHits",300, 0.001, 0.01);
40  //Define the plots for hit on first plane
41  TH1F *refTheta = new TH1F("MCTrue theta","The track theta set in Generator",300, 0.001, 0.01);
42 
43  TH1F *dTheta = new TH1F("FirstMCHit-MCTrue","delta theta between FirstMCHit and MCTrue",300,-0.003,0.003);
44  TH1F *dTheta0 = new TH1F("RecoHit-MCTrue","delta theta between RecoHit and MCTrue theta",300, -0.003,0.003);//theta resolution
45 // TH1F *dTheta1 = new TH1F("FirstRecoHit-MCTrue","",300, -0.003,0.003);
46  TH1F *dTheta2 = new TH1F("MCHit-MCTrue","",300, -0.003,0.003);
47  TH1F *dTheta3 = new TH1F("RecoHit-MCHit","delta theta between RecoHit and MCHit",300, -0.003,0.003); //digi&reco effect
48 
49  TF1 *trackFit = new TF1("trackFit","pol1",-40,40);
50 
51 // Define some gobal variables
52  TVector3 vecmc, vecrc;
53  double mcX=0, mcY=0, mcZ=0, rcX=0, rcY=0, rcZ=0;
55  double mc_x[4],mc_y[4],mc_z[4],r_mc[4];
56  double rc_x[4],rc_y[4],rc_z[4],r_rc[4];
57  double r_mc_err[4],r_rc_err[4],z_mc_err[4],z_rc_err[4];
58 
59 //Loop the event and get theta
60  for(int i =0; i<nEvents&&i<tree1->GetEntriesFast();i++)
61  {
62  tree2->GetEntry(i);
63  tree1->GetEntry(i);
64  cout<<"the Event No is "<<i<<endl;
65 
66  if(hit_array->GetEntriesFast()==4)
67  {
68  for (int j=0; j<hit_array->GetEntriesFast();j++)
69  {// cout<<"the point no "<<j<<" of Event "<<i<<endl;
70  if(hit_array->GetEntriesFast()!=mc_array->GetEntriesFast()) continue;
71  PndSdsHit *hit = (PndSdsHit*)hit_array->At(j);
72  PndSdsMCPoint *point = (PndSdsMCPoint*)mc_array->At(j);
73 
74  mcX = (point->GetPosition().X()+point->GetPositionOut().X())/2;
75  mcY = (point->GetPosition().Y()+point->GetPositionOut().Y())/2;
76  mcZ = (point->GetPosition().Z()+point->GetPositionOut().Z())/2;
77 
78 // mcX = point->GetPosition().X();//+point->GetPositionOut().X())/2;
79 // mcY = point->GetPosition().Y();//+point->GetPositionOut().Y())/2;
80 // mcZ = point->GetPosition().Z();//+point->GetPositionOut().Z())/2;
81  cout<<"the mcX, mcY, mcZ are "<<mcX<<","<<mcY<<","<<mcZ<<endl;
82  vecmc.SetXYZ(mcX,mcY,mcZ);
83  vecrc = hit->GetPosition();
84  cout<<"the rcX, rcY, rcZ are "<<vecrc.x()<<","<<vecrc.Y()<<","<<vecrc.Z()<<endl;
85  Int_t iTrack = point->GetTrackID();
86  // cout<<"The iTrack (point->GetTrackID() is :"<<iTrack<<endl;
87  //if (iTrack>=0)
88  // {
89  PndMCTrack *track = (PndMCTrack*)mc_track->At(iTrack);
90  // }
91  if(track->GetMotherID()== -1) trackthe = track->GetMomentum().Theta();
92  cout<<"the track theta is "<<trackthe<<endl;
93  // }
94  mc_x[j]=vecmc.X();
95  mc_y[j]=vecmc.Y();
96  mc_z[j]=vecmc.Z()-1110;
97  r_mc[j]=TMath::Sqrt(mc_x[j]*mc_x[j]+mc_y[j]*mc_y[j]);
98  std::cout<<"the r_mc[j] is "<<r_mc[j]<<std::endl;
99  std::cout<<"the mc_z[j] is "<<mc_z[j]<<std::endl;
100  r_mc_err[j]=0;
101  z_mc_err[j]=0;
102 
103  rc_x[j]=vecrc.X();
104  rc_y[j]=vecrc.Y();
105  rc_z[j]=vecrc.Z()-1110;
106  r_rc[j]=TMath::Sqrt(rc_x[j]*rc_x[j]+rc_y[j]*rc_y[j]);
107  std::cout<<"the r_rc[j] is "<<r_rc[j]<<std::endl;
108  std::cout<<"the rc_z[j] is "<<rc_z[j]<<std::endl;
109  r_rc_err[j]=0;
110  z_rc_err[j]=0;
111  double tempmc = TMath::Sqrt(mc_x[0]*mc_x[0]+mc_y[0]*mc_y[0]);
112  mcfirstthe = TMath::ATan(tempmc/(mc_z[0]+1110));
113  cout<<"the first hit theta is "<<mcfirstthe<<endl;
114 
115  }//loop all events containing for 4 hits
116 
117  TGraphErrors *mctrack = new TGraphErrors(4,mc_z,r_mc,z_mc_err,r_mc_err);
118  mctrack->Fit("trackFit","ONF");
119  mctheta=TMath::ATan(trackFit->GetParameter(1));
120  cout<<"the mc fit theta is "<<mctheta<<endl;
121 
122  TGraphErrors *rctrack = new TGraphErrors(4,rc_z,r_rc,z_rc_err,r_rc_err);
123  rctrack->Fit("trackFit","ONF");
124  rctheta=TMath::ATan(trackFit->GetParameter(1));
125  cout<<"the rc fit theta is "<<rctheta<<endl;
126 
127  dthe0 = rctheta-trackthe;
128  dthe2 = mctheta-trackthe;
129  dthe3 = rctheta-mctheta;
130  dtheta = mcfirstthe-trackthe;
131 
132  //fill the histograms
133  rcTheta->Fill(rctheta);
134  mcTheta->Fill(mctheta);
135  refTheta->Fill(trackthe);
136 
137  dTheta0->Fill(dthe0);
138  dTheta2->Fill(dthe2);
139  dTheta3->Fill(dthe3);
140  dTheta->Fill(dtheta);
141  //fill the plots
142  }
143 }
144 
145  //draw the plots
147  TF1 *total = new TF1("total","gaus",-0.06,0.06);
148  total->SetLineColor(kRed);
149  total->SetLineWidth(1);
150 
151  TCanvas *can1 = new TCanvas("Theta","MC,RC,Track theta",0,0,800, 800);
152  can1->Divide(2,2);
153  TPad* mypad = 0;
154 
155  can1->cd(1); mcTheta->DrawCopy(); //mcTheta->Fit("gaus");
156  can1->cd(2); rcTheta->DrawCopy(); //rcTheta->Fit("gaus");
157  can1->cd(3); refTheta->DrawCopy();
158 
159  gStyle->SetOptFit();
160  TCanvas *can2 = new TCanvas("Delta theat","MC,RC,Track",0,0,800, 800);
161  can2->Divide(2,2);
162 
163  can2->cd(1); dTheta0->DrawCopy(); dTheta0->Fit("total","R");
164 // can2->cd(3); dTheta1->DrawCopy(); // dTheta1->Fit("total","R");
165  can2->cd(2); dTheta2->DrawCopy(); dTheta2->Fit("total","R");
166  can2->cd(3); dTheta3->DrawCopy(); dTheta3->Fit("total","R");
167  can2->cd(4); dTheta ->DrawCopy(); dTheta->Fit("total","R");
168 
169  timer.Stop();
170  Double_t rtime = timer.RealTime();
171  Double_t ctime = timer.CpuTime();
172  cout<<endl<<endl;
173  cout<<"the macro finished successfully"<<endl;
174  cout<<"the real time is "<<rtime<<" and CPU time is "<<ctime<<endl;
175  cout<<endl;
176 
177 }
PndMCTrack * mctrack
double mc_x[4]
Definition: anaLmdCluster.C:55
TH1F * dTheta2
Definition: anaLmdCluster.C:46
double r_mc_err[4]
Definition: anaLmdCluster.C:57
double rc_z[4]
Definition: anaLmdCluster.C:56
TH1F * dTheta3
Definition: anaLmdCluster.C:47
Int_t i
Definition: run_full.C:25
TVector3 GetPosition() const
Definition: PndSdsHit.h:93
TH1F * rcTheta
Definition: anaLmdCluster.C:39
PndRiemannTrack track
Definition: RiemannTest.C:33
TStopwatch timer
Definition: anaLmdCluster.C:7
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
int nEvents
Definition: anaLmdCluster.C:17
double mcY
Definition: anaLmdCluster.C:53
TH1F * dTheta0
Definition: anaLmdCluster.C:44
double dthe1
Definition: anaLmdCluster.C:54
double z_mc_err[4]
Definition: anaLmdCluster.C:57
Double_t par[3]
TFile * mcf
Definition: anaLmdCluster.C:22
TTree * tree1
Definition: anaLmdCluster.C:24
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
TClonesArray * mc_array
Definition: anaLmdCluster.C:25
TVector3 GetPositionOut() const
Definition: PndSdsMCPoint.h:91
TH1F * refTheta
Definition: anaLmdCluster.C:41
double mcX
Definition: anaLmdCluster.C:53
TH1F * dTheta
Definition: anaLmdCluster.C:43
double rc_x[4]
Definition: anaLmdCluster.C:56
Double_t ctime
double mc_z[4]
Definition: anaLmdCluster.C:55
double trackthe
Definition: anaLmdCluster.C:54
double r_rc_err[4]
Definition: anaLmdCluster.C:57
Double_t rtime
TF1 * trackFit
Definition: anaLmdCluster.C:49
double z_rc_err[4]
Definition: anaLmdCluster.C:57
double rcZ
Definition: anaLmdCluster.C:53
double rctheta
Definition: anaLmdCluster.C:54
Double_t
double mc_y[4]
Definition: anaLmdCluster.C:55
TClonesArray * point
Definition: anaLmdDigi.C:29
double dtheta
Definition: anaLmdCluster.C:54
double dthe3
Definition: anaLmdCluster.C:54
TFile * rcf
Definition: anaLmdCluster.C:31
double dthe0
Definition: anaLmdCluster.C:54
double rcX
Definition: anaLmdCluster.C:53
TH1F * mcTheta
Definition: anaLmdCluster.C:38
TPad * mypad
TF1 * total
TVector3 vecmc
Definition: anaLmdCluster.C:52
double dthe2
Definition: anaLmdCluster.C:54
TClonesArray * hit_array
Definition: anaLmdCluster.C:34
TVector3 GetPosition() const
Definition: PndSdsMCPoint.h:90
TCanvas * can2
double mctheta
Definition: anaLmdCluster.C:54
double r_mc[4]
Definition: anaLmdCluster.C:55
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
double mcZ
Definition: anaLmdCluster.C:53
TClonesArray * mc_track
Definition: anaLmdCluster.C:28
double pi
Definition: anaLmdCluster.C:19
double rc_y[4]
Definition: anaLmdCluster.C:56
TTree * tree2
Definition: anaLmdCluster.C:33
double rcfirstthe
Definition: anaLmdCluster.C:54
TCanvas * can1
double mcfirstthe
Definition: anaLmdCluster.C:54
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
double rcY
Definition: anaLmdCluster.C:53
Double_t Pi
double r_rc[4]
Definition: anaLmdCluster.C:56
bool verbose
Definition: anaLmdCluster.C:18
TVector3 vecrc
Definition: anaLmdCluster.C:52