]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCComparison.C
Get properly the track information and the number of tracks
[u/mrichter/AliRoot.git] / TPC / AliTPCComparison.C
1 //#include "alles.h"
2 //#include "TParticle.h"
3 struct GoodTrack {
4   Int_t lab;
5   Int_t code;
6   Float_t px,py,pz;
7   Float_t x,y,z;
8 };
9 Int_t good_tracks(GoodTrack *gt, Int_t max);
10
11 Int_t AliTPCComparison() {
12   Int_t i;
13    gBenchmark->Start("AliTPCComparison");
14    cerr<<"Doing comparison...\n";
15
16    TFile *cf=TFile::Open("AliTPCclusters.root");
17    if (!cf->IsOpen()) {cerr<<"Can't open AliTPCclusters.root !\n"; return 1;}
18    AliTPCParam *digp= (AliTPCParam*)cf->Get("75x40_100x60");
19    if (!digp) { cerr<<"TPC parameters have not been found !\n"; return 2; }
20
21 // Load clusters
22    AliTPCClustersArray *ca=new AliTPCClustersArray;
23    ca->Setup(digp);
24    ca->SetClusterType("AliTPCcluster");
25    ca->ConnectTree("Segment Tree");
26    Int_t nentr=Int_t(ca->GetTree()->GetEntries());
27    for (i=0; i<nentr; i++) {
28      //AliSegmentID *s=;
29        ca->LoadEntry(i);
30    }
31
32 // Load tracks
33    TFile *tf=TFile::Open("AliTPCtracks.root");
34    if (!tf->IsOpen()) {cerr<<"Can't open AliTPCtracks.root !\n"; return 3;}
35    TObjArray tarray(2000);
36    TTree *tracktree=(TTree*)tf->Get("TreeT");
37    TBranch *tbranch=tracktree->GetBranch("tracks");
38    nentr=(Int_t)tracktree->GetEntries();
39    
40    for (i=0; i<nentr; i++) {
41        AliTPCtrack *iotrack=new AliTPCtrack;
42        tbranch->SetAddress(&iotrack);
43        tracktree->GetEvent(i);
44        iotrack->CookLabel(ca);
45        tarray.AddLast(iotrack);
46    }   
47    tf->Close();
48
49    delete ca;
50    cf->Close();
51
52 /////////////////////////////////////////////////////////////////////////
53    GoodTrack gt[15000];
54    Int_t ngood=0;
55    ifstream in("good_tracks");
56    if (in) {
57       cerr<<"Reading good tracks...\n";
58       while (in>>gt[ngood].lab>>gt[ngood].code>>gt[ngood].px>>gt[ngood].py>>gt[ngood].pz>>gt[ngood].x>>gt[ngood].y>>gt[ngood].z) {
59          ngood++;
60          cerr<<ngood<<'\r';
61          if (ngood==15000) {
62             cerr<<"Too many good tracks !\n";
63             break;
64          }
65       }
66       if (!in.eof()) cerr<<"Read error (good_tracks) !\n";
67    } else {
68       cerr<<"Marking good tracks (this will take a while)...\n";
69       ngood=good_tracks(gt,15000);
70       ofstream out("good_tracks");
71       if (out) {
72          for (Int_t ngd=0; ngd<ngood; ngd++)            
73             out<<gt[ngd].lab<<' '<<gt[ngd].code<<' '<<gt[ngd].px <<' '<<gt[ngd].py<<' '<<gt[ngd].pz<<' '<<gt[ngd].x  <<' '<<gt[ngd].y <<' '<<gt[ngd].z <<endl;
74       } else cerr<<"Can not open file (good_tracks) !\n";
75       out.close();
76    }
77    cerr<<"Number of good tracks : "<<ngood<<endl;
78
79    cerr<<"Doing comparison...\n";
80    TH1F *hp=new TH1F("hp","PHI resolution",50,-20.,20.); hp->SetFillColor(4);
81    TH1F *hl=new TH1F("hl","LAMBDA resolution",50,-20,20);hl->SetFillColor(4);
82    TH1F *hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.); 
83    hpt->SetFillColor(2); 
84    TH1F *hmpt=new TH1F("hmpt","Relative Pt resolution (pt>4GeV/c)",30,-60,60); 
85    hmpt->SetFillColor(6);
86
87    TH1F *hgood=new TH1F("hgood","Good tracks",20,0,7);    
88    TH1F *hfound=new TH1F("hfound","Found tracks",20,0,7);
89    TH1F *hfake=new TH1F("hfake","Fake tracks",20,0,7);
90    TH1F *hg=new TH1F("hg","",20,0,7); //efficiency for good tracks
91    hg->SetLineColor(4); hg->SetLineWidth(2);
92    TH1F *hf=new TH1F("hf","Efficiency for fake tracks",20,0,7);
93    hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
94
95    TH1F *he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,100.);
96    TH2F *hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,200.);
97
98    Int_t mingood = ngood;  //MI change
99    Int_t * track_notfound = new Int_t[ngood];
100    Int_t   itrack_notfound =0;
101    Int_t * track_fake  = new Int_t[ngood];
102    Int_t   itrack_fake = 0;
103    Int_t * track_multifound = new Int_t[ngood];
104    Int_t * track_multifound_n = new Int_t[ngood];
105    Int_t   itrack_multifound =0;
106
107    while (ngood--) {
108       Int_t lab=gt[ngood].lab,tlab=-1;
109       Float_t ptg=
110       TMath::Sqrt(gt[ngood].px*gt[ngood].px + gt[ngood].py*gt[ngood].py);
111
112       hgood->Fill(ptg);
113
114       AliTPCtrack *track=0;
115       for (i=0; i<nentr; i++) {
116           track=(AliTPCtrack*)tarray.UncheckedAt(i);
117           tlab=track->GetLabel();
118           if (lab==TMath::Abs(tlab)) break;
119       }
120       if (i==nentr) {
121         //      cerr<<"Track "<<lab<<" was not found !\n";
122         track_notfound[itrack_notfound++]=lab;
123         continue;
124       }
125       
126       //MI change  - addition
127       Int_t micount=0;
128       Int_t mi;
129       AliTPCtrack * mitrack;
130       for (mi=0; mi<nentr; mi++) {
131         mitrack=(AliTPCtrack*)tarray.UncheckedAt(mi);          
132         if (lab==TMath::Abs(mitrack->GetLabel())) micount++;
133       }
134       if (micount>1) {
135         //cout<<"Track no. "<<lab<<" found "<<micount<<"  times\n";
136         track_multifound[itrack_multifound]=lab;
137         track_multifound_n[itrack_multifound]=micount;
138         itrack_multifound++;
139       }
140       
141
142       //
143       Double_t xk=gt[ngood].x;//digp->GetPadRowRadii(0,0);
144       track->PropagateTo(xk);
145
146       if (lab==tlab) hfound->Fill(ptg);
147       else { 
148         track_fake[itrack_fake++]=lab;
149         hfake->Fill(ptg); 
150         //cerr<<lab<<" fake\n";
151       }
152
153       Double_t px,py,pz,pt=fabs(track->GetPt());track->GetPxPyPz(px,py,pz);
154
155       if (TMath::Abs(gt[ngood].code)==11 && ptg>4.) {
156          hmpt->Fill((1/pt - 1/ptg)/(1/ptg)*100.);
157       } else {
158          Float_t phig=TMath::ATan2(gt[ngood].py,gt[ngood].px);
159          Float_t phi =TMath::ATan2(py,px );
160          hp->Fill((phi - phig)*1000.);
161
162          Float_t lamg=TMath::ATan2(gt[ngood].pz,ptg);
163          Float_t lam =TMath::ATan2(pz ,pt );
164          hl->Fill((lam - lamg)*1000.);
165
166          hpt->Fill((1/pt - 1/ptg)/(1/ptg)*100.);
167       }
168
169       Float_t mom=track->GetP();
170       Float_t dedx=track->GetdEdx();
171       hep->Fill(mom,dedx,1.);
172       if (TMath::Abs(gt[ngood].code)==211)
173          if (mom>0.4 && mom<0.5) {
174             he->Fill(dedx,1.);
175          }
176
177    }
178
179    
180    Stat_t ng=hgood->GetEntries(); cerr<<"Good tracks "<<ng<<endl;
181    Stat_t nf=hfound->GetEntries();
182    if (ng!=0) 
183       cerr<<"\n\n\nIntegral efficiency is about "<<nf/ng*100.<<" %\n";
184    
185    //MI change  - addition
186    cout<<"Total number of found tracks ="<<nentr<<"\n";
187    cout<<"Total number of \"good\" tracks ="<<mingood<<"\n";
188
189
190    cout<<"\nList of Not found tracks :\n";
191    //   Int_t i;
192    for ( i = 0; i< itrack_notfound; i++){
193      cout<<track_notfound[i]<<"\t";
194      if ((i%5)==4) cout<<"\n";
195    }
196    cout<<"\nList of fake  tracks :\n";
197    for ( i = 0; i< itrack_fake; i++){
198      cout<<track_fake[i]<<"\t";
199      if ((i%5)==4) cout<<"\n";
200    }
201     cout<<"\nList of multiple found tracks :\n";
202    for ( i=0; i<itrack_multifound; i++) {
203        cout<<"id.   "<<track_multifound[i]<<"     found - "<<track_multifound_n[i]<<"times\n";
204    }
205    cout<<"\n\n\n";
206
207    
208    gStyle->SetOptStat(111110);
209    gStyle->SetOptFit(1);
210
211    TCanvas *c1=new TCanvas("c1","",0,0,700,850);
212
213    TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
214    p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10); 
215    hp->SetFillColor(4);  hp->SetXTitle("(mrad)"); hp->Fit("gaus"); c1->cd();
216
217    TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw(); 
218    p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
219    hl->SetXTitle("(mrad)"); hl->Fit("gaus"); c1->cd();
220
221    TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
222    p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10); 
223    hpt->SetXTitle("(%)"); hpt->Fit("gaus"); c1->cd();
224
225    TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
226    p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
227    hmpt->SetXTitle("(%)"); hmpt->Fit("gaus"); c1->cd();
228
229    TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd(); 
230    p5->SetFillColor(41); p5->SetFrameFillColor(10);
231    hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
232    hg->Divide(hfound,hgood,1,1.,"b");
233    hf->Divide(hfake,hgood,1,1.,"b");
234    hg->SetMaximum(1.4);
235    hg->SetYTitle("Tracking efficiency");
236    hg->SetXTitle("Pt (GeV/c)");
237    hg->Draw();
238
239    TLine *line1 = new TLine(0,1.0,7,1.0); line1->SetLineStyle(4);
240    line1->Draw("same");
241    TLine *line2 = new TLine(0,0.9,7,0.9); line2->SetLineStyle(4);
242    line2->Draw("same");
243
244    hf->SetFillColor(1);
245    hf->SetFillStyle(3013);
246    hf->SetLineColor(2);
247    hf->SetLineWidth(2);
248    hf->Draw("histsame");
249    TText *text = new TText(0.461176,0.248448,"Fake tracks");
250    text->SetTextSize(0.05);
251    text->Draw();
252    text = new TText(0.453919,1.11408,"Good tracks");
253    text->SetTextSize(0.05);
254    text->Draw();
255
256
257
258    TCanvas *c2=new TCanvas("c2","",320,32,530,590);
259
260    TPad *p6=new TPad("p6","",0.,0.,1.,.5); p6->Draw();
261    p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10); 
262    he->SetFillColor(2); he->SetFillStyle(3005);  
263    he->SetXTitle("Arbitrary Units"); 
264    he->Fit("gaus"); c2->cd();
265
266    TPad *p7=new TPad("p7","",0.,0.5,1.,1.); p7->Draw(); 
267    p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
268    hep->SetXTitle("p (Gev/c)"); hep->SetYTitle("dE/dX (Arb. Units)"); 
269    hep->Draw(); c1->cd();
270
271    gBenchmark->Stop("AliTPCComparison");
272    gBenchmark->Show("AliTPCComparison");
273
274
275    return 0;
276 }
277
278
279 Int_t good_tracks(GoodTrack *gt, Int_t max) {
280    Int_t nt=0;
281
282    TFile *file=TFile::Open("galice.root");
283    if (!file->IsOpen()) {cerr<<"Can't open galice.root !\n"; exit(4);}
284
285    if (!(gAlice=(AliRun*)file->Get("gAlice"))) {
286      cerr<<"gAlice have not been found on galice.root !\n";
287      exit(5);
288    }
289
290    gAlice->GetEvent(0);   
291
292    AliTPC *TPC=(AliTPC*)gAlice->GetDetector("TPC");
293    Int_t ver = TPC->IsVersion(); 
294    cerr<<"TPC version "<<ver<<" has been found !\n";
295
296    AliTPCParam *digp=(AliTPCParam*)file->Get("75x40_100x60");
297    if (!digp) { cerr<<"TPC parameters have not been found !\n"; exit(6); }
298    TPC->SetParam(digp);
299
300    Int_t nrow_up=digp->GetNRowUp();
301    Int_t nrows=digp->GetNRowLow()+nrow_up;
302    Int_t zero=digp->GetZeroSup();
303    Int_t gap=Int_t(0.125*nrows);
304    Int_t good_number=Int_t(0.4*nrows);
305
306    TObjArray *particles=gAlice->Particles(); //MI change 
307    
308    //
309    //   Int_t np=particles->GetEntriesFast();
310    Int_t np=gAlice->GetNtrack(); //FCA correction
311    Int_t *good=new Int_t[np];
312    for (Int_t ii=0; ii<np; ii++) good[ii]=0;
313
314
315    //MI change to be possible compile macro
316    //definition out of the swith statemnet
317     Int_t sectors_by_rows=0;
318     TTree *TD=0;
319     AliSimDigits da, *digits=&da;
320     Int_t *count=0;
321    switch (ver) {
322    case 1:
323      {
324       TFile *cf=TFile::Open("AliTPCclusters.root");
325       if (!cf->IsOpen()){cerr<<"Can't open AliTPCclusters.root !\n";exit(5);}
326       AliTPCClustersArray *ca=new AliTPCClustersArray;
327       ca->Setup(digp);
328       ca->SetClusterType("AliTPCcluster");
329       ca->ConnectTree("Segment Tree");
330       Int_t nrows=Int_t(ca->GetTree()->GetEntries());
331       for (Int_t n=0; n<nrows; n++) {
332           AliSegmentID *s=ca->LoadEntry(n);
333           Int_t sec,row;
334           digp->AdjustSectorRow(s->GetID(),sec,row);
335           AliTPCClustersRow &clrow = *ca->GetRow(sec,row);
336           Int_t ncl=clrow.GetArray()->GetEntriesFast();
337           while (ncl--) {
338               AliTPCcluster *c=(AliTPCcluster*)clrow[ncl];
339               Int_t lab=c->GetLabel(0);
340               if (lab<0) continue; //noise cluster
341               lab=TMath::Abs(lab);
342               if (sec>=digp->GetNInnerSector())
343               if (row==nrow_up-1    ) good[lab]|=0x1000;
344               if (sec>=digp->GetNInnerSector())
345               if (row==nrow_up-1-gap) good[lab]|=0x800;
346               good[lab]++;
347           }
348           ca->ClearRow(sec,row);
349       }
350       cf->Close();
351      }
352       break;
353    case 2:
354       TD=(TTree*)gDirectory->Get("TreeD_75x40_100x60");
355       TD->GetBranch("Segment")->SetAddress(&digits);
356       count = new Int_t[np];
357       Int_t i;
358       for (i=0; i<np; i++) count[i]=0;
359       sectors_by_rows=(Int_t)TD->GetEntries();
360       for (i=0; i<sectors_by_rows; i++) {
361           if (!TD->GetEvent(i)) continue;
362           Int_t sec,row;
363           digp->AdjustSectorRow(digits->GetID(),sec,row);
364           cerr<<sec<<' '<<row<<"                                     \r";
365           digits->First();
366           while (digits->Next()) {
367               Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn();
368               Short_t dig = digits->GetDigit(it,ip);
369               Int_t idx0=digits->GetTrackID(it,ip,0); 
370               Int_t idx1=digits->GetTrackID(it,ip,1);
371               Int_t idx2=digits->GetTrackID(it,ip,2);
372               if (idx0>=0 && dig>=zero) count[idx0]+=1;
373               if (idx1>=0 && dig>=zero) count[idx1]+=1;
374               if (idx2>=0 && dig>=zero) count[idx2]+=1;
375           }
376           for (Int_t j=0; j<np; j++) {
377               if (count[j]>1) {
378                  if (sec>=digp->GetNInnerSector())
379                    if (row==nrow_up-1    ) good[j]|=0x1000;
380                  if (sec>=digp->GetNInnerSector())
381                    if (row==nrow_up-1-gap) good[j]|=0x800;
382                  good[j]++;
383               }
384               count[j]=0;
385           }
386       }
387       delete[] count;
388       break;
389    default:
390       cerr<<"Invalid TPC version !\n";
391       file->Close();
392       exit(7);
393    }
394
395    TTree *TH=gAlice->TreeH();
396    //   TClonesArray *hits=TPC->Hits();
397    Int_t npart=(Int_t)TH->GetEntries();
398
399    while (npart--) {
400       AliTPChit *hit0=0;
401
402       TPC->ResetHits();
403       TH->GetEvent(npart);
404       AliTPChit * hit = (AliTPChit*) TPC->FirstHit(-1);
405       while (hit){
406         if (hit->fQ==0.) break;
407         hit =  (AliTPChit*) TPC->NextHit();
408       }
409       if (hit) {
410         hit0 = new AliTPChit(*hit); //Make copy of hit
411         hit = hit0;
412       }
413       else continue;
414       AliTPChit *hit1=(AliTPChit*)TPC->NextHit();       
415       if (hit1==0) continue;
416       /*      Int_t nhits=hits->GetEntriesFast();
417       if (nhits==0) continue;
418       AliTPChit *hit;
419       Int_t j;
420       for (j=0; j<nhits-1; j++) {
421          hit=(AliTPChit*)hits->UncheckedAt(j);
422          if (hit->fQ==0.) break;
423       }
424       if (j==nhits-1) continue;
425       AliTPChit *hit1=(AliTPChit*)hits->UncheckedAt(j+1);
426       */
427       if (hit1->fQ != 0.) continue;
428       Int_t i=hit->Track();
429       //      TParticle *p = (TParticle*)particles->UncheckedAt(i);
430       TParticle *p = (TParticle*)gAlice->Particle(i);
431
432       if (p->GetFirstMother()>=0) continue;  //secondary particle
433       if (good[i] < 0x1000+0x800+2+good_number) continue;
434       if (p->Pt()<0.100) continue;
435       if (TMath::Abs(p->Pz()/p->Pt())>0.999) continue;
436
437       gt[nt].lab=i;
438       gt[nt].code=p->GetPdgCode();
439 //**** px py pz - in global coordinate system, x y z - in local !
440       gt[nt].px=hit->X(); gt[nt].py=hit->Y(); gt[nt].pz=hit->Z();
441       Float_t cs,sn; digp->AdjustCosSin(hit1->fSector,cs,sn);
442       gt[nt].x = hit1->X()*cs + hit1->Y()*sn;
443       gt[nt].y =-hit1->X()*sn + hit1->Y()*cs;
444       gt[nt].z = hit1->Z();
445       nt++;     
446         if (hit0) delete hit0;
447       cerr<<i<<"                \r";
448       if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
449    }
450    delete[] good;
451
452    //delete gAlice; gAlice=0;
453
454    file->Close();
455    gBenchmark->Stop("AliTPCComparison");
456    gBenchmark->Show("AliTPCComparison");   
457    return nt;
458 }
459
460
461