FairRoot/PandaRoot
ana_pid.C
Go to the documentation of this file.
1 #include "TH1F.h"
2 #include "TH2F.h"
3 #include "TString.h"
4 #include "TCanvas.h"
5 #include "TStopwatch.h"
6 
7 void config_histo(TH1F *h, TString tx, TString ty,double offy=1.65)
8 {
9  h->SetLineWidth(1);
10  h->SetLineColor(1);
11  h->SetFillColor(3);
12  //h->Sumw2();
13 
14  h->GetXaxis()->SetTitleOffset(1.3);
15  h->GetXaxis()->SetTitleColor(1);
16  h->GetXaxis()->SetLabelSize(0.05);
17  h->GetXaxis()->SetTitleSize(0.05);
18  h->GetXaxis()->SetNdivisions(505);
19 
20  h->GetYaxis()->SetTitleOffset(offy);
21  h->GetYaxis()->SetTitleFont(42);
22  h->GetYaxis()->SetLabelSize(0.05);
23  h->GetYaxis()->SetTitleSize(0.05);
24 
25  h->SetXTitle(tx);
26  h->SetYTitle(ty);
27 
28 }
29 
30 
31 int ana_pid(TString fname="dsdsj_10k.root",int num=0)
32 {
33  TStopwatch timer;
34  timer.Start();
35 
36  int i;
37 
38  gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
39  basiclibs();
40 
41 
42  gSystem->Load("libRho");
43  /*
44  TCanvas *c1=new TCanvas("c1","2-dim",1100 ,750);
45  c1->Divide(3,2);
46 
47  TCanvas *c2=new TCanvas("c2","1-dim",1100 ,750);
48  c2->Divide(3,2);
49 
50  TCanvas *c4=new TCanvas("c4","LH",750 ,750);
51  c4->Divide(5,5);
52 
53  TCanvas *c3=new TCanvas("c3","mom+tht",600,350);
54  c3->Divide(2,1);
55 */
56 
57  TFile* f = new TFile(fname.Data());
58  TTree *t=f->Get("pndsim") ;
59  //TClonesArray *fTr=new TClonesArray("TParticle");
60  //TClonesArray *fTrMc=new TClonesArray("TParticle");
61  TClonesArray *fCands=new TClonesArray("TCandidate");
62 
63  //t->SetBranchAddress("PndParticles",&fTr) ;
64  //t->SetBranchAddress("PndMcParticles",&fTrMc);
65  t->SetBranchStatus("*",0);
66  t->SetBranchStatus("PndChargedCandidates*",1);
67  t->SetBranchAddress("PndChargedCandidates",&fCands);
68 
69  //TParticle *tr1;
70  //TParticle *tr2;
71  TCandidate *tc;
72 
73 
74  TH1F *hmom= new TH1F("hmom","momentum charged tracks",100,0,6);
75  TH1F *htht= new TH1F("htht","theta charged tracks",100,0,180);
76 
77  TH2F *thtcbar = new TH2F("thtcbar","#theta_{c} DrcBarrel",200,0,8,200,0.,0.9);
78  thtcbar->SetMarkerSize(0.1);
79 
80  TH2F *thtcdsc = new TH2F("thtcdsc","#theta_{c} DrcDisc",200,0,8,200,0.0,0.9);
81  thtcdsc->SetMarkerSize(0.1);
82 
83  TH2F *thtcrch = new TH2F("thtcrch","#theta_{c} Rich",200,0.,8,200,0.,0.35);
84  thtcrch->SetMarkerSize(0.1);
85 
86  TH2F *m2tof = new TH2F("m2tof","m^{2} Tof",100,0,1.5,100,0.,1.2);
87  m2tof->SetMarkerSize(0.1);
88 
89  TH2F *dedxmvd = new TH2F("dedxmvd","dE/dx Mvd",100,0,1.5,100,0.,20);
90  dedxmvd->SetMarkerSize(0.1);
91 
92  TH2F *dedxstt = new TH2F("dedxstt","dE/dx Stt",100,0,1.5,100,0.,20);
93  dedxstt->SetMarkerSize(0.1);
94 
95  TH1F *thtcB[5], *thtcD[5], *thtcR[5];
96  TH1F *m2T[5], *dedxM[5],*dedxS[5];
97 
98  TH1F *LHe[5],*LHmu[5],*LHpi[5],*LHk[5],*LHp[5];
99 
100  int colors[5]={1,2,4,6,8};
101 
102  for (i=0;i<5;i++)
103  {
104  char tmp[50];
105  sprintf(tmp,"%d",i);
106  TString nums(tmp);
107  thtcB[i]=new TH1F(("h1"+nums).Data(),("h1"+nums).Data(),100,0,0.85);
108  thtcD[i]=new TH1F(("h2"+nums).Data(),("h2"+nums).Data(),100,0,0.85);
109  thtcR[i]=new TH1F(("h3"+nums).Data(),("h3"+nums).Data(),100,0,0.85);
110 
111  m2T[i]=new TH1F(("h4"+nums).Data(),("h4"+nums).Data(),100,0,1.4);
112  dedxM[i]=new TH1F(("h5"+nums).Data(),("h5"+nums).Data(),100,0,40);
113  dedxS[i]=new TH1F(("h6"+nums).Data(),("h6"+nums).Data(),100,0,40);
114 
115  LHe[i]=new TH1F(("LHe"+nums).Data(),("LH for being electron"+nums).Data(),50,0,1);
116  LHmu[i]=new TH1F(("LHmu"+nums).Data(),("LH for being muons"+nums).Data(),50,0,1);
117  LHpi[i]=new TH1F(("LHpi"+nums).Data(),("LH for being pions"+nums).Data(),50,0,1);
118  LHk[i]=new TH1F(("LHk"+nums).Data(),("LH for being kaons"+nums).Data(),50,0,1);
119  LHp[i]=new TH1F(("LHp"+nums).Data(),("LH for being protons"+nums).Data(),50,0,1);
120 
121  LHe[i]->SetFillColor(colors[0]);
122  LHmu[i]->SetFillColor(colors[1]);
123  LHpi[i]->SetFillColor(colors[2]);
124  LHk[i]->SetFillColor(colors[3]);
125  LHp[i]->SetFillColor(colors[4]);
126 
127  thtcB[i]->SetLineColor(colors[i]);
128  thtcR[i]->SetLineColor(colors[i]);
129  thtcD[i]->SetLineColor(colors[i]);
130  m2T[i]->SetLineColor(colors[i]);
131  dedxM[i]->SetLineColor(colors[i]);
132  dedxS[i]->SetLineColor(colors[i]);
133  }
134 
135  if (num==0) num= t->GetEntriesFast();
136  cout <<"\n####### Processing "<<num <<" events...\n"<<endl;
137 
138  TCandList allCands,neutralCands,chargedCands, plusCands,minusCands;
139 
140  TCandList kpCands,kmCands,piCands;
141 
142  TPidChargedSelector *chargedSel = new TPidChargedSelector;
143 
144  // TPidSimpleKaonSelector *kSel = new TPidSimpleKaonSelector();
145  // kSel->SetCriterion("loose");
146  // TPidSimplePionSelector *piSel = new TPidSimplePionSelector();
147  // piSel->SetCriterion("loose");
148 
149  int i2;
150 
151  int pidhypo[2213];
152  pidhypo[11]=0;
153  pidhypo[13]=1;
154  pidhypo[211]=2;
155  pidhypo[321]=3;
156  pidhypo[2212]=4;
157 
158  TFile *tf = new TFile(fname+"_ana.root","RECREATE");
159  TNtuple *ntp=new TNtuple("ntp","ntp","pid:px:py:pz:e:p:pt:tht:ctht:le:lmu:lpi:lk:lp:tcb:tcd:tcr:mt:dem:des:det:tcbr:tcdr:tcrr:mtr:demr:desr:detr");
160 
161 
162  for (Int_t j=0; j< num;j++)
163  {
164  t->GetEntry(j);
165  if (!(j%100)) cout <<"evt:"<<j<<endl;
166 
167  //allCands.Cleanup();
168  //chargedCands.Cleanup();
169 
170  for (Int_t i1=0; i1<fCands->GetEntriesFast(); i1++)
171  {
172  tc = (TCandidate *)fCands->At(i1);
173  // allCands.Add(*tc);
174 
175 
176  //chargedCands.Select(allCands, chargedSel);
177 
178  float valvect[28];
179 
180  double pmin=0.5;
181  double pmax=0.7;
182 
183  double thtmin=0./180.*3.1415;
184  double thtmax=180./180.*3.1415;
185 
186  //TCandListIterator iterch(chargedCands);
187  //while (tc=iterch.Next()){
188  double *pi=tc->GetPidInfo();
189  double p=tc->P();
190  double tht=tc->GetVect().Theta();
191 
192  double pt = p*sin(tht);
193  int pid=abs((int)pi[29]);
194  int hypo=pidhypo[pid];
195 
196  // TNtuple *ntp=new TNtuple("ntp","ntp","pid:p:px:py:pz:e:pt:tht:ctht:le:lmu:lpi:lk:lp:tcb:tcd:tcr:mt:dem:des:det:tcbr:tcdr:tcrr:mtr:demr:desr:detr");
197  valvect[0]=(float)hypo;
198  valvect[1]=(float)p;
199  valvect[2]=(float)tc->Px() ;
200  valvect[3]=(float)tc->Py() ;
201  valvect[4]=(float)tc->Pz() ;
202  valvect[5]=(float)tc->E() ;
203  valvect[6]=(float)tc->Pt() ;
204  valvect[7]=(float)tht ;
205  valvect[8]=(float)cos(tht) ;
206 
207  valvect[9]=(float)pi[0] ; // LH e
208  valvect[10]=(float)pi[1] ;// LH mu
209  valvect[11]=(float)pi[2] ;// LH pi
210  valvect[12]=(float)pi[3] ;// LH K
211  valvect[13]=(float)pi[4] ;// LH p
212 
213  valvect[14]=(float)pi[5] ;// tht_c barrel
214  valvect[15]=(float)pi[6] ;// tht_c disc
215  valvect[16]=(float)pi[7] ;// tht_c rich
216  valvect[17]=(float)pi[8] ;// m squared tof
217  valvect[18]=(float)pi[9] ;// dEdx mvd
218  valvect[19]=(float)pi[10] ;// dEdx stt
219  valvect[20]=(float)pi[11] ;// dEdx tpc
220 
221  valvect[21]=(float)pi[12] ;// tht_c barrel error
222  valvect[22]=(float)pi[13] ;// tht_c disc error
223  valvect[23]=(float)pi[14] ;// tht_c rich error
224  valvect[24]=(float)pi[15] ;// m squared tof error
225  valvect[25]=(float)pi[16] ;// dEdx mvd error
226  valvect[26]=(float)pi[17] ;// dEdx stt error
227  valvect[27]=(float)pi[18] ;// dEdx tpc error
228 
229  ntp->Fill(valvect);
230  }
231 
232 
233  }
234 
235 
236  ntp->Write();
237  tf->Close();
238 
239  timer.Stop();
240  Double_t rtime = timer.RealTime();
241  Double_t ctime = timer.CpuTime();
242  printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
243  return 0;
244 }
Double_t p
Definition: anasim.C:58
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
basiclibs()
int num[96]
Definition: ranlxd.cxx:381
Int_t i
Definition: run_full.C:25
TClonesArray * fCands
Definition: poormantracks.C:27
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
int pid()
#define pi
Definition: createSTT.C:60
int ana_pid(TString fname="dsdsj_10k.root", int num=0)
Definition: ana_pid.C:31
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
Double_t
void config_histo(TH1 *h, TString tx, TString ty)
TStopwatch timer
Definition: hit_dirc.C:51
TString tht(TString pts, TString exts="px py pz")
Definition: invexp.C:168
TFile * f
Definition: bump_analys.C:12
Double_t ctime
Definition: hit_dirc.C:114
TTree * t
Definition: bump_analys.C:13
Double_t rtime
Definition: hit_dirc.C:113