1 /****************************************************************************
2 * This macro estimates efficiency of matching with the TOF. *
3 * TOF "Good" tracks are those originating from the primary vertex, *
4 * being "good" in the ITS and having at least one digit in the TOF. *
5 * (To get the list of "good" tracks one should first run *
6 * AliTPCComparison.C and AliITSComparisonV2.C macros) *
7 * Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch *
8 ****************************************************************************/
10 #if !defined(__CINT__) || defined(__MAKECINT__)
11 #include <Riostream.h>
15 #include "AliHeader.h"
17 #include "AliRunLoader.h"
18 #include "AliLoader.h"
21 #include "AliTOFdigit.h"
27 #include "TClonesArray.h"
32 #include "TParticle.h"
42 extern AliRun *gAlice;
44 Int_t AliTOFComparison() {
45 Int_t good_tracks_tof(GoodTrackTOF *gt, const Int_t max);
47 cerr<<"Doing comparison...\n";
50 delete gAlice->GetRunLoader();
51 delete gAlice;//if everything was OK here it is already NULL
55 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
58 AliRunLoader *rl = AliRunLoader::Open("galice.root");
60 cerr<<"Can not open session"<<endl;
63 AliLoader* tofl = rl->GetLoader("TOFLoader");
65 cerr<<"Can not get the TOF loader"<<endl;
68 tofl->LoadDigits("read");
72 TTree *tofTree=tofl->TreeD();
74 cerr<<"Can't get the TOF cluster tree !\n";
77 TBranch *branch=tofTree->GetBranch("TOF");
79 cerr<<"Can't get the branch with the TOF digits !\n";
82 branch->SetAddress(&digits);
89 Int_t nd=digits->GetEntriesFast();
90 cerr<<"Number of digits: "<<nd<<endl;
92 const Int_t MAX=15000;
95 ifstream in("good_tracks_tof");
97 cerr<<"Reading good tracks...\n";
98 while (in>>gt[ngood].lab>>gt[ngood].code>>
99 gt[ngood].px>>gt[ngood].py>>gt[ngood].pz>>
100 gt[ngood].x >>gt[ngood].y >>gt[ngood].z) {
104 cerr<<"Too many good tracks !\n";
108 if (!in.eof()) cerr<<"Read error (good_tracks_its) !\n";
110 cerr<<"Marking good tracks (this will take a while)...\n";
111 ngood=good_tracks_tof(gt,MAX);
112 ofstream out("good_tracks_tof");
114 for (Int_t ngd=0; ngd<ngood; ngd++)
115 out<<gt[ngd].lab<<' '<<gt[ngd].code<<' '
116 <<gt[ngd].px<<' '<<gt[ngd].py<<' '<<gt[ngd].pz<<' '
117 <<gt[ngd].x <<' '<<gt[ngd].y <<' '<<gt[ngd].z <<endl;
118 } else cerr<<"Can not open file (good_tracks_tof) !\n";
125 TH1F *hgood=new TH1F("hgood","Good tracks",30,pmin,pmax);
126 TH1F *hfound=new TH1F("hfound","Matched tracks",30,pmin,pmax);
127 TH1F *hfake=new TH1F("hfake","Mismatched tracks",30,pmin,pmax);
128 TH1F *hgp=new TH1F("hgp","",30,pmin,pmax); //efficiency for good tracks
129 hgp->SetLineColor(4); hgp->SetLineWidth(2);
130 TH1F *hfp=new TH1F("hfp","Probability of mismatching",30,pmin,pmax);
131 hfp->SetFillColor(1); hfp->SetFillStyle(3013); hfp->SetLineWidth(2);
133 TH1F *hgoo=new TH1F("hgoo","Good tracks",30,-1,1);
134 TH1F *hfoun=new TH1F("hfoun","Matched tracks",30,-1,1);
135 TH1F *hfak=new TH1F("hfak","Mismatched tracks",30,-1,1);
136 TH1F *hgl=new TH1F("hgl","",30,-1,1); //efficiency for good tracks
137 hgl->SetLineColor(4); hgl->SetLineWidth(2);
138 TH1F *hfl=new TH1F("hfl","Probability of mismatching",30,-1,1);
139 hfl->SetFillColor(1); hfl->SetFillStyle(3013); hfl->SetLineWidth(2);
141 TFile *ef=TFile::Open("AliESDs.root");
142 if (!ef->IsOpen()) {cerr<<"Can't AliESDs.root !\n"; return 1;}
144 TIter next(ef->GetListOfKeys());
147 while ((key=(TKey*)next())!=0) {
148 cerr<<"Processing event number : "<<nev++<<endl;
150 AliESD *event=(AliESD*)key->ReadObj();
151 Int_t ntrk=event->GetNumberOfTracks();
152 cerr<<"Number of ESD tracks : "<<ntrk<<endl;
156 for (Int_t i=0; i<ngood; i++) {
158 Double_t pxg=gt[i].px, pyg=gt[i].py, pzg=gt[i].pz;
159 Double_t ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
161 if (ptg<0.1) continue;
163 Double_t tgl=pzg/ptg; //tan(lambda)
165 if (ptg>pmin) { hgood->Fill(ptg); hgoo->Fill(tgl); }
169 for (j=0; j<ntrk; j++) {
170 AliESDtrack *tt=event->GetTrack(j);
171 if (lab!=TMath::Abs(tt->GetLabel())) continue;
173 //if ((tt->GetStatus()&AliESDtrack::kTOFpid) == 0) continue;
174 if (tt->GetTOFsignal() < 0) continue;
175 UInt_t idx=tt->GetTOFcluster();
176 if ((Int_t)idx>=nd) {
177 cerr<<"Wrong digit index ! "<<idx<<endl;
180 AliTOFdigit *dig=(AliTOFdigit*)digits->UncheckedAt(idx);
181 Int_t *label=dig->GetTracks();
186 if (ptg>pmin) { hfake->Fill(ptg); hfak->Fill(tgl); }
189 if (ptg>pmin) { hfound->Fill(ptg); hfoun->Fill(tgl); }
194 cerr<<"Not matched: "<<lab<<" ";
196 cerr<<(t->GetStatus()&AliESDtrack::kITSout)<<' '
197 <<(t->GetStatus()&AliESDtrack::kTPCout)<<' '
198 <<(t->GetStatus()&AliESDtrack::kTRDout)<<' '
199 <<(t->GetStatus()&AliESDtrack::kTIME);
200 } else cerr<<"No ESD track !";
205 cerr<<"Number of good tracks: "<<ngood<<endl;
206 cerr<<"Number of matched tracks: "<<matched<<endl;
207 cerr<<"Number of mismatched tracks: "<<mismatched<<endl;
208 if (ngood!=0) cerr<<"Efficiency: "<<Float_t(matched)/ngood<<endl;
210 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
211 hgp->Divide(hfound,hgood,1,1.,"b");
212 hfp->Divide(hfake,hgood,1,1.,"b");
213 hgp->SetMaximum(1.4);
214 hgp->SetYTitle("Matching efficiency");
215 hgp->SetXTitle("Pt (GeV/c)");
217 hfoun->Sumw2(); hgoo->Sumw2(); hfak->Sumw2();
218 hgl->Divide(hfoun,hgoo,1,1.,"b");
219 hfl->Divide(hfak,hgoo,1,1.,"b");
220 hgl->SetMaximum(1.4);
221 hgl->SetYTitle("Matching efficiency");
222 hgl->SetXTitle("Tan(lambda)");
224 TCanvas *c1=new TCanvas("c1","",0,0,600,900);
230 hfp->Draw("histsame");
231 TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
233 TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
239 hfl->Draw("histsame");
240 TLine *line3 = new TLine(-1,1.0,1,1.0); line3->SetLineStyle(4);
242 TLine *line4 = new TLine(-1,0.9,1,0.9); line4->SetLineStyle(4);
251 Int_t good_tracks_tof(GoodTrackTOF *gt, const Int_t max) {
252 ifstream in("good_tracks_its");
254 cerr<<"Can't get good_tracks_its !\n"; exit(11);
257 AliRunLoader *rl = AliRunLoader::Open("galice.root","COMPARISON");
259 cerr<<"Can't start session !\n";
268 Int_t np = rl->GetHeader()->GetNtrack();
270 Int_t *good=new Int_t[np];
272 for (k=0; k<np; k++) good[k]=0;
274 AliLoader* tofl = rl->GetLoader("TOFLoader");
276 cerr<<"Can not get the TOF loader"<<endl;
279 tofl->LoadDigits("read");
281 TTree *dTree=tofl->TreeD();
283 cerr<<"Can't get the TOF cluster tree !\n";
287 TBranch *branch=dTree->GetBranch("TOF");
289 cerr<<"Can't get the branch with the TOF digits !\n";
292 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
293 branch->SetAddress(&digits);
296 Int_t nd=digits->GetEntriesFast();
297 cerr<<"Number of digits: "<<nd<<endl;
299 for (Int_t i=0; i<nd; i++) {
300 AliTOFdigit *d=(AliTOFdigit*)digits->UncheckedAt(i);
301 Int_t l0=d->GetTrack(0);
302 if (l0>=np) {cerr<<"Wrong label: "<<l0<<endl; continue;}
303 Int_t l1=d->GetTrack(1);
304 if (l1>=np) {cerr<<"Wrong label: "<<l1<<endl; continue;}
305 Int_t l2=d->GetTrack(2);
306 if (l2>=np) {cerr<<"Wrong label: "<<l2<<endl; continue;}
307 if (l0>=0) good[l0]++;
308 if (l1>=0) good[l1]++;
309 if (l2>=0) good[l2]++;
313 rl->LoadKinematics();
314 AliStack* stack = rl->Stack();
316 Double_t px,py,pz,x,y,z;
318 while (in>>lab>>code>>px>>py>>pz>>x>>y>>z) {
319 if (good[lab] == 0) continue;
320 TParticle *p = (TParticle*)stack->Particle(lab);
322 cerr<<"Can not get particle "<<lab<<endl;
325 if (TMath::Abs(p->Vx())>0.1) continue;
326 if (TMath::Abs(p->Vy())>0.1) continue;
327 if (TMath::Abs(p->Vz())>0.1) continue;
330 gt[nt].code=p->GetPdgCode();
331 //**** px py pz - in global coordinate system
332 gt[nt].px=p->Px(); gt[nt].py=p->Py(); gt[nt].pz=p->Pz();
333 gt[nt].x=p->Vx(); gt[nt].y=p->Vy(); gt[nt].z=p->Vz();
335 if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
340 rl->UnloadKinematics();