]>
Commit | Line | Data |
---|---|---|
0717295b | 1 | //******************************************************************** |
2 | // Example (very naive for the moment) of using the ESD classes | |
42345b19 | 3 | // It demonstrates the idea of the "combined PID". |
4 | // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch | |
0717295b | 5 | //******************************************************************** |
6 | ||
7 | #if !defined( __CINT__) || defined(__MAKECINT__) | |
8 | #include <Riostream.h> | |
9 | #include "TKey.h" | |
10 | #include "TFile.h" | |
11 | #include "TH1F.h" | |
12 | #include "TH2F.h" | |
13 | #include "TCanvas.h" | |
14 | #include "TStopwatch.h" | |
15 | #include "TParticle.h" | |
42345b19 | 16 | #include "TROOT.h" |
0717295b | 17 | |
18 | #include "AliRun.h" | |
19 | #include "AliStack.h" | |
20 | #include "AliRunLoader.h" | |
21 | #include "AliLoader.h" | |
22 | ||
23 | #include "AliESD.h" | |
24 | #endif | |
25 | ||
26 | extern AliRun *gAlice; | |
42345b19 | 27 | extern TROOT *gROOT; |
0717295b | 28 | |
42345b19 | 29 | Int_t AliESDcomparison(const Char_t *dir=".") { |
30 | TH2F *tpcHist=(TH2F*)gROOT->FindObject("tpcHist"); | |
31 | if (!tpcHist) | |
32 | tpcHist=new TH2F("tpcHist","TPC dE/dX vs momentum",100,0.,4.,100,0.,500.); | |
0717295b | 33 | tpcHist->SetXTitle("p (GeV/c)"); tpcHist->SetYTitle("dE/dx (Arb. Units)"); |
42345b19 | 34 | tpcHist->SetMarkerStyle(8); |
35 | tpcHist->SetMarkerSize(0.3); | |
0717295b | 36 | |
42345b19 | 37 | const Char_t *hname[]={ |
38 | "piG","piR","piF","piGood","piFake", | |
39 | "kaG","kaR","kaF","kaGood","kaFake", | |
40 | "prG","prR","prF","prGood","prFake" | |
41 | }; | |
42 | Int_t nh=sizeof(hname)/sizeof(const Char_t *); | |
43 | TH1F **hprt=new TH1F*[nh]; | |
44 | ||
45 | for (Int_t i=0; i<nh; i++) { | |
46 | hprt[i]=(TH1F*)gROOT->FindObject(hname[i]); | |
47 | if (hprt[i]==0) {hprt[i]=new TH1F(hname[i],"",20,0.,4.);hprt[i]->Sumw2();} | |
48 | } | |
49 | TH1F *piG=hprt[0]; | |
50 | TH1F *piR=hprt[1]; | |
51 | TH1F *piF=hprt[2]; | |
52 | TH1F *piGood=hprt[3]; | |
53 | piGood->SetTitle("Combined PID for pions"); | |
54 | piGood->SetLineColor(4); piGood->SetXTitle("p (GeV/c)"); | |
55 | TH1F *piFake=hprt[4]; | |
56 | piFake->SetLineColor(2); | |
57 | TH1F *kaG=hprt[5]; | |
58 | TH1F *kaR=hprt[6]; | |
59 | TH1F *kaF=hprt[7]; | |
60 | TH1F *kaGood=hprt[8]; | |
61 | kaGood->SetTitle("Combined PID for kaons"); | |
62 | kaGood->SetLineColor(4); kaGood->SetXTitle("p (GeV/c)"); | |
63 | TH1F *kaFake=hprt[9]; | |
64 | kaFake->SetLineColor(2); | |
65 | TH1F *prG=hprt[10]; | |
66 | TH1F *prR=hprt[11]; | |
67 | TH1F *prF=hprt[12]; | |
68 | TH1F *prGood=hprt[13]; | |
69 | prGood->SetTitle("Combined PID for protons"); | |
70 | prGood->SetLineColor(4); prGood->SetXTitle("p (GeV/c)"); | |
71 | TH1F *prFake=hprt[14]; | |
72 | prFake->SetLineColor(2); | |
73 | ||
74 | delete[] hprt; | |
75 | ||
76 | Char_t fname[100]; | |
0717295b | 77 | |
78 | if (gAlice) { | |
79 | delete gAlice->GetRunLoader(); | |
80 | delete gAlice; | |
81 | gAlice=0; | |
82 | } | |
42345b19 | 83 | sprintf(fname,"%s/galice.root",dir); |
84 | AliRunLoader *rl = AliRunLoader::Open(fname); | |
0717295b | 85 | if (rl == 0x0) { |
86 | cerr<<"Can not open session"<<endl; | |
87 | return 1; | |
88 | } | |
89 | if (rl->LoadgAlice()) { | |
90 | cerr<<"LoadgAlice returned error"<<endl; | |
91 | delete rl; | |
92 | return 1; | |
93 | } | |
94 | if (rl->LoadHeader()) { | |
95 | cerr<<"LoadHeader returned error"<<endl; | |
96 | delete rl; | |
97 | return 1; | |
98 | } | |
99 | rl->LoadKinematics(); | |
42345b19 | 100 | AliStack *stack = rl->Stack(); |
0717295b | 101 | |
42345b19 | 102 | sprintf(fname,"%s/AliESDs.root",dir); |
103 | TFile *ef=TFile::Open(fname); | |
0717295b | 104 | if (!ef->IsOpen()) {cerr<<"Can't AliESDs.root !\n"; return 1;} |
105 | ||
106 | TStopwatch timer; | |
107 | Int_t rc=0,n=0; | |
108 | TKey *key=0; | |
109 | TIter next(ef->GetListOfKeys()); | |
110 | ||
111 | //****** Tentative particle type "concentrations" | |
112 | Double_t c[5]={0.01, 0.01, 0.85, 0.10, 0.05}; | |
113 | ||
114 | //******* The loop over events | |
115 | while ((key=(TKey*)next())!=0) { | |
116 | rl->GetEvent(n); | |
7ed22428 | 117 | ef->cd(); |
0717295b | 118 | |
119 | cerr<<"Processing event number : "<<n++<<endl; | |
120 | ||
121 | AliESD *event=(AliESD*)key->ReadObj(); | |
122 | ||
123 | Int_t ntrk=event->GetNumberOfTracks(); | |
124 | cerr<<"Number of ESD tracks : "<<ntrk<<endl; | |
125 | //****** The loop over tracks | |
126 | ||
127 | Int_t pisel=0,kasel=0,prsel=0,nsel=0; | |
128 | ||
129 | while (ntrk--) { | |
130 | AliESDtrack *t=event->GetTrack(ntrk); | |
131 | ||
132 | Double_t p=t->GetP(); | |
133 | ||
134 | if (t->GetStatus()&AliESDtrack::kTPCin) { | |
135 | Double_t dedx=t->GetTPCsignal(); | |
136 | tpcHist->Fill(p,dedx,1); | |
137 | } | |
138 | ||
139 | UInt_t status=AliESDtrack::kESDpid; | |
140 | status|=AliESDtrack::kTPCpid; | |
141 | status|=AliESDtrack::kTOFpid; | |
142 | ||
143 | if ((t->GetStatus()&status) == status) { | |
144 | nsel++; | |
145 | ||
146 | Int_t lab=TMath::Abs(t->GetLabel()); | |
147 | TParticle *part=stack->Particle(lab); | |
148 | Int_t code=part->GetPdgCode(); | |
149 | ||
150 | Double_t r[10]; t->GetESDpid(r); | |
151 | ||
152 | Double_t rcc=0.; | |
153 | Int_t i; | |
154 | for (i=0; i<AliESDtrack::kSPECIES; i++) rcc+=(c[i]*r[i]); | |
155 | if (rcc==0.) continue; | |
156 | ||
157 | //Here we apply Bayes' formula | |
158 | Double_t w[10]; | |
159 | for (i=0; i<AliESDtrack::kSPECIES; i++) w[i]=c[i]*r[i]/rcc; | |
160 | ||
161 | if (w[4]>w[3] && w[4]>w[2] && w[4]>w[1] && w[4]>w[0]) {//proton | |
162 | prsel++; | |
163 | prG->Fill(p); | |
164 | if (TMath::Abs(code)==2212) prR->Fill(p); | |
165 | else prF->Fill(p); | |
166 | } | |
167 | ||
168 | if (w[3]>w[4] && w[3]>w[2] && w[3]>w[1] && w[3]>w[0]) {//kaon | |
169 | kasel++; | |
170 | kaG->Fill(p); | |
171 | if (TMath::Abs(code)==321) kaR->Fill(p); | |
172 | else kaF->Fill(p); | |
173 | } | |
174 | ||
175 | if (w[2]>w[3] && w[2]>w[4] && w[2]>w[1] && w[2]>w[0]) {//pion | |
176 | pisel++; | |
177 | piG->Fill(p); | |
178 | if (TMath::Abs(code)==211) piR->Fill(p); | |
179 | else piF->Fill(p); | |
180 | } | |
181 | ||
182 | } | |
183 | ||
184 | } | |
185 | delete event; | |
186 | cerr<<"Number of selected ESD tracks : "<<nsel<<endl; | |
187 | cerr<<"Number of selected pion ESD tracks : "<<pisel<<endl; | |
188 | cerr<<"Number of selected kaon ESD tracks : "<<kasel<<endl; | |
189 | cerr<<"Number of selected proton ESD tracks : "<<prsel<<endl; | |
190 | } | |
191 | ||
192 | timer.Stop(); timer.Print(); | |
193 | ||
42345b19 | 194 | TCanvas *c1=(TCanvas*)gROOT->FindObject("c1"); |
195 | if (c1) delete c1; | |
196 | c1=new TCanvas("c1","",0,0,600,1200); | |
0717295b | 197 | c1->Divide(1,4); |
198 | ||
199 | c1->cd(1); | |
200 | tpcHist->Draw(); | |
201 | ||
202 | c1->cd(2); | |
42345b19 | 203 | //piG->Sumw2(); piF->Sumw2(); piR->Sumw2(); |
0717295b | 204 | piGood->Divide(piR,piG,1,1,"b"); |
205 | piFake->Divide(piF,piG,1,1,"b"); | |
206 | piGood->Draw("hist"); | |
207 | piFake->Draw("same"); | |
208 | ||
209 | c1->cd(3); | |
42345b19 | 210 | //kaG->Sumw2(); kaF->Sumw2(); kaR->Sumw2(); |
0717295b | 211 | kaGood->Divide(kaR,kaG,1,1,"b"); |
212 | kaFake->Divide(kaF,kaG,1,1,"b"); | |
213 | kaGood->Draw("hist"); | |
214 | kaFake->Draw("same"); | |
215 | ||
216 | c1->cd(4); | |
42345b19 | 217 | //prG->Sumw2(); prF->Sumw2(); prR->Sumw2(); |
0717295b | 218 | prGood->Divide(prR,prG,1,1,"b"); |
219 | prFake->Divide(prF,prG,1,1,"b"); | |
220 | prGood->Draw("hist"); | |
221 | prFake->Draw("same"); | |
222 | ||
223 | ef->Close(); | |
224 | ||
225 | delete rl; | |
226 | ||
227 | return rc; | |
228 | } |