FairRoot/PandaRoot
production/tdrct/eta_c/track_check.C
Go to the documentation of this file.
1 
2 enum DetectorId {
5 
6 int track_check(Int_t nEntries = 0)
7 {
8  gROOT->LoadMacro("$VMCWORKDIR/gconfig/rootlogon.C");
9  rootlogon();
10  TString inPidFile = "evt_pid_stt.root";
11  TString inSimFile = "evt_points_stt.root";
12 
13  TFile *inFile = TFile::Open(inSimFile,"READ");
14 
15  TTree *tree=(TTree *) inFile->Get("pndsim") ;
16  tree->AddFriend("pndsim",inPidFile);
17 
18  TClonesArray* cand_array=new TClonesArray("PndPidCandidate");
19  tree->SetBranchAddress("PidChargedCand", &cand_array);
20 
21  TClonesArray* mc_array=new TClonesArray("PndMCTrack");
22  tree->SetBranchAddress("MCTrack", &mc_array);
23 
24  TFile *out = TFile::Open("out_test.root","RECREATE");
25  TNtuple *nt = new TNtuple("nt","nt","evt:id:mc_p:mc_theta:mc_phi:mc_pid:mc_stt:mc_tpc:mc_mvd:mc_gem:p:theta:phi:mult:stt:tpc:mvd");
26  TNtuple *ntEvt = new TNtuple("ntEvt","ntEvt","evt:acc_stt:acc_tpc:eff:effct:cand:mc_phi1:mc_phi2:reco_phi1:reco_phi2:mc_all:reco_all");
27  Float_t mass_k = 0.493677;
28 
29  if (nEntries==0) nEntries = tree->GetEntriesFast();
30  for (Int_t j=0; j< nEntries; j++){
31  tree->GetEntry(j);
32  //if (cand_array->GetEntriesFast()==0) continue;
33  if ((j%100)==0) cout << "processing event " << j << "\n";
34 
35  Float_t mc_mom = 0, mc_theta = 0, mc_phi = 0;
36  Float_t rec_mom = -1, rec_theta = -1, rec_phi = 0;
37  Int_t stt_mccount = 0, tpc_mccount = 0, reco_stt = 0, reco_tpc = 0,reco_mvd = 0, reco_gem = 0, reco_count = 0, reco_ctcount = 0;
38  TLorentzVector mc_k[4], reco_k[4], mc_phi1, reco_phi1, mc_phi2, reco_phi2, mc_all, reco_all;
39  for (Int_t mc = 0; mc < mc_array->GetEntriesFast(); mc++)
40  {
41  PndMCTrack *mctrack = (PndMCTrack*)mc_array->At(mc);
42  if (mctrack->GetMotherID()!=-1) continue;
43  if (mctrack->GetNPoints(kSTT)) stt_mccount++;
44  if (mctrack->GetNPoints(kTPC)) tpc_mccount++;
45  mc_k[mc] = mctrack->Get4Momentum();
46  mc_mom = mctrack->GetMomentum().Mag();
47  mc_theta = mctrack->GetMomentum().Theta()*TMath::RadToDeg();
48  mc_phi = mctrack->GetMomentum().Phi()*TMath::RadToDeg();
49  Int_t mc_pid = mctrack->GetPdgCode();
50  Int_t cand_mult = 0;
51  for (Int_t pp=0; pp<cand_array->GetEntriesFast(); pp++)
52  {
53  PndPidCandidate *pidCand = (PndPidCandidate*)cand_array->At(pp);
54  if (pidCand->GetMcIndex()!=mc) continue;
55  if ( (cand_mult==0) || ((cand_mult>0) && (fabs(rec_mom-mc_mom)> fabs(pidCand->GetMomentum().Mag()-mc_mom))) )
56  {
57  rec_mom = pidCand->GetMomentum().Mag();
58  rec_theta = pidCand->GetMomentum().Theta();
59  rec_phi = pidCand->GetMomentum().Phi();
60  reco_k[mc].SetXYZM(pidCand->GetMomentum().X(),pidCand->GetMomentum().Y(),pidCand->GetMomentum().Z(),mass_k);
61  reco_stt = pidCand->GetSttHits();
62  reco_tpc = pidCand->GetTpcHits();
63  reco_mvd = pidCand->GetMvdHits();
64  }
65  cand_mult++;
66 
67  } // end of candidate loop
68 
69  if (cand_mult>0) reco_count++;
70  if ((cand_mult>0) && ((reco_stt>0) || (reco_tpc>0))) reco_ctcount++;
71  Float_t ntuple_nt[] = {
72  j,mc, mc_mom,mc_theta,mc_phi, mc_pid,
73  mctrack->GetNPoints(kSTT), mctrack->GetNPoints(kTPC), mctrack->GetNPoints(kMVD), mctrack->GetNPoints(kGEM),
74  rec_mom, rec_theta*TMath::RadToDeg(), rec_phi*TMath::RadToDeg(), cand_mult, reco_stt, reco_tpc, reco_mvd
75  };
76  nt->Fill(ntuple_nt);
77 
78  } // end of MC loop
79  mc_phi1 = mc_k[0] + mc_k[1];
80  mc_phi2 = mc_k[2] + mc_k[3];
81  reco_phi1 = reco_k[0] + reco_k[1];
82  reco_phi2 = reco_k[2] + reco_k[3];
83  mc_all = mc_phi1 + mc_phi2;
84  reco_all = reco_phi1 + reco_phi2;
85 
86  Float_t ntuple_evt[] = {
87  j, stt_mccount, tpc_mccount, reco_count, reco_ctcount,cand_array->GetEntriesFast(),
88  mc_phi1.M(), mc_phi2.M(), reco_phi1.M(), reco_phi2.M(), mc_all.M(), reco_all.M()
89  };
90  ntEvt->Fill(ntuple_evt);
91 
92 
93  } // end of event loop
94 
95  nt->Draw("mc_theta>>hMcTheta(50,0,100)");
96  nt->Draw("mc_theta>>hMcSttTheta(50,0,100)","mc_stt>0");
97  nt->Draw("mc_theta>>hMcSttMvdTheta(50,0,100)","(mc_stt>0)||(mc_mvd>0)");
98  nt->Draw("mc_theta>>hMcTpcTheta(50,0,100)","mc_tpc>0");
99  nt->Draw("mc_theta>>hMcTpcMvdTheta(50,0,100)","(mc_tpc>0)||(mc_tpc>0)");
100  nt->Draw("mc_theta>>hMcMvdTheta(50,0,100)","mc_mvd>0");
101  nt->Draw("mc_theta>>hMcGemTheta(50,0,100)","mc_gem>0");
102  nt->Draw("mc_theta>>hRecoTheta(50,0,100)","mult>0");
103  nt->Draw("mc_theta>>hRecoCtTheta(50,0,100)","mult>0&&(stt>0||tpc>0)");
104  nt->Draw("mc_theta>>hRecoEffTheta(50,0,100)","mult>0");
105  nt->Draw("mc_theta>>hRecoEffCtTheta(50,0,100)","mult>0&&(stt>0||tpc>0)");
106  hRecoEffTheta->Divide(hMcTheta);
107  hRecoEffCtTheta->Divide(hMcTheta);
108  nt->Draw("mc_theta>>hMcAccSttTheta(50,0,100)","mc_stt>0");
109  hMcAccSttTheta->Divide(hMcTheta);
110  nt->Draw("mc_theta>>hMcAccTpcTheta(50,0,100)","mc_tpc>0");
111  hMcAccTpcTheta->Divide(hMcTheta);
112 
113 
114  nt->Draw("mc_phi>>hMcPhi(50,-200,200)");
115  nt->Draw("mc_phi>>hMcSttPhi(50,-200,200)","mc_stt>0");
116  nt->Draw("mc_phi>>hMcSttMvdPhi(50,-200,200)","(mc_stt>0)||(mc_mvd>0)");
117  nt->Draw("mc_phi>>hMcTpcPhi(50,-200,200)","mc_tpc>0");
118  nt->Draw("mc_phi>>hMcTpcMvdPhi(50,-200,200)","(mc_tpc>0)||(mc_mvd>0)");
119  nt->Draw("mc_phi>>hMcMvdPhi(50,-200,200)","mc_mvd>0");
120  nt->Draw("mc_phi>>hMcGemPhi(50,-200,200)","mc_gem>0");
121  nt->Draw("mc_phi>>hRecoPhi(50,-200,200)","mult>0");
122  nt->Draw("mc_phi>>hRecoCtPhi(50,-200,200)","mult>0&&(stt>0||tpc>0)");
123  nt->Draw("mc_phi>>hRecoEffPhi(50,-200,200)","mult>0");
124  nt->Draw("mc_phi>>hRecoEffCtPhi(50,-200,200)","mult>0&&(stt>0||tpc>0)");
125  hRecoEffPhi->Divide(hMcPhi);
126  hRecoEffCtPhi->Divide(hMcPhi);
127  nt->Draw("mc_phi>>hMcAccSttPhi(50,-200,200)","mc_stt>0");
128  hMcAccSttPhi->Divide(hMcPhi);
129  nt->Draw("mc_phi>>hMcAccTpcPhi(50,-200,200)","mc_tpc>0");
130  hMcAccTpcPhi->Divide(hMcPhi);
131 
132  nt->Draw("mc_p>>hMcP(100,0,5)");
133  nt->Draw("mc_p>>hMcSttP(100,0,5)","mc_stt>0");
134  nt->Draw("mc_p>>hMcSttMvdP(100,0,5)","(mc_stt>0)||(mc_mvd>0)");
135  nt->Draw("mc_p>>hMcTpcP(100,0,5)","mc_tpc>0");
136  nt->Draw("mc_p>>hMcTpcMvdP(100,0,5)","(mc_tpc>0)||(mc_mvd>0)");
137  nt->Draw("mc_p>>hMcMvdP(100,0,5)","mc_mvd>0");
138  nt->Draw("mc_p>>hMcGemP(100,0,5)","mc_gem>0");
139  nt->Draw("mc_p>>hRecoP(100,0,5)","mult>0");
140  nt->Draw("mc_p>>hRecoCtP(100,0,5)","mult>0&&(stt>0||tpc>0)");
141  nt->Draw("mc_p>>hRecoEffP(100,0,5)","mult>0");
142  nt->Draw("mc_p>>hRecoEffCtP(100,0,5)","mult>0&&(stt>0||tpc>0)");
143  hRecoEffP->Divide(hMcP);
144  hRecoEffCtP->Divide(hMcP);
145  nt->Draw("mc_p>>hMcAccSttP(100,0,5)","mc_stt>0");
146  hMcAccSttP->Divide(hMcP);
147  nt->Draw("mc_p>>hMcAccTpcP(100,0,5)","mc_tpc>0");
148  hMcAccTpcP->Divide(hMcP);
149 
150  nt->Draw("(mc_p-p):mc_p>>hresp_p(100,0,5,100,-0.5,0.5)","mult>0");
151  nt->Draw("(mc_p-p):mc_theta>>hresp_theta(100,0,100,100,-0.5,0.5)","mult>0","colz");
152  nt->Draw("(mc_theta-theta):mc_theta>>hrestheta_theta(100,0,100,100,-2,2)","mult>0");
153  nt->Draw("(mc_theta-theta):mc_p>>hrestheta_p(100,0,5,100,-2,2)","mult>0");
154  nt->Draw("(mc_phi-phi):mc_phi>>hresphi_phi(100,-200,200,100,-2,2)","mult>0");
155 
156  ntEvt->Draw("reco_phi1>>hphi(100,0.95,1.1)","eff==4");
157  ntEvt->Draw("reco_phi2>>hphi2(100,0.95,1.1)","eff==4");
158  hphi->Add(hphi2);
159  ntEvt->Draw("reco_all>>hAll(100,2.5,3.5)","eff==4");
160  out->cd();
161 
162  nt->Write();
163  ntEvt->Write();
164 
165  hMcTheta->Write(); hMcSttTheta->Write(); hMcSttMvdTheta->Write(); hMcMvdTheta->Write(); hMcGemTheta->Write(); hRecoTheta->Write();
166  hMcTpcTheta->Write(); hMcTpcMvdTheta->Write(); hRecoEffTheta->Write(); hMcAccSttTheta->Write(); hMcAccTpcTheta->Write();
167  hMcPhi->Write(); hMcSttPhi->Write(); hMcSttMvdPhi->Write(); hMcMvdPhi->Write(); hMcGemPhi->Write(); hRecoPhi->Write();
168  hMcTpcPhi->Write(); hMcTpcMvdPhi->Write(); hRecoEffPhi->Write(); hMcAccSttPhi->Write(); hMcAccTpcPhi->Write();
169  hMcP->Write(); hMcSttP->Write(); hMcSttMvdP->Write(); hMcMvdP->Write(); hMcGemP->Write(); hRecoP->Write();
170  hMcTpcP->Write(); hMcTpcMvdP->Write(); hRecoEffP->Write();hMcAccSttP->Write(); hMcAccTpcP->Write();
171  hRecoCtTheta->Write();
172  hRecoCtPhi->Write();
173  hRecoCtP->Write();
174  hRecoEffCtTheta->Write();
175  hRecoEffCtPhi->Write();
176  hRecoEffCtP->Write();
177 
178 
179 
180  hresp_p->Write();
181  hresp_theta->Write();
182  hrestheta_theta->Write();
183  hrestheta_p->Write();
184  hresphi_phi->Write();
185  hphi->Write();
186  hAll->Write();
187 
188  out->Save();
189 
190  return 0;
191 }
PndMCTrack * mctrack
int track_check(Int_t nEntries=0)
TTree * tree
Definition: plot_dirc.C:12
Int_t GetNPoints(DetectorId detId) const
Definition: PndMCTrack.cxx:120
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
TClonesArray * mc_array
Definition: anaLmdCluster.C:25
TLorentzVector Get4Momentum() const
Definition: PndMCTrack.cxx:102
Int_t GetMcIndex() const
TString inFile
Definition: hit_dirc.C:8
int reco_mvd()
Definition: reco_mvd.C:1
TString inSimFile
Int_t GetSttHits() const
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
TFile * out
Definition: reco_muo.C:20
Int_t GetMvdHits() const
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
TVector3 GetMomentum() const