]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSComparisonV2.C
Revert one change (Sun,Alpha)
[u/mrichter/AliRoot.git] / ITS / AliITSComparisonV2.C
1 /****************************************************************************
2  *           Very important, delicate and rather obscure macro.             *
3  *                                                                          *
4  *               Creates list of "trackable" tracks,                        *
5  *             calculates efficiency, resolutions etc.                      *
6  *  The ESD tracks must be in an appropriate state (kITSin or kITSrefit)    *
7  *                                                                          *
8  *           Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch                 *
9  ****************************************************************************/
10
11 #if !defined(__CINT__) || defined(__MAKECINT__)
12   #include <Riostream.h>
13   #include <fstream.h>
14
15   #include "AliRun.h"
16   #include "AliHeader.h"
17   #include "AliStack.h"
18   #include "AliRunLoader.h"
19   #include "AliLoader.h"
20   #include "AliITSLoader.h"
21   #include "AliITS.h"
22   #include "AliITSgeom.h"
23   #include "AliITStrackerV2.h"
24   #include "AliITStrackV2.h"
25   #include "AliITSclusterV2.h"
26   #include "AliMagF.h"
27   #include "AliESD.h"
28
29   #include "TFile.h"
30   #include "TKey.h"
31   #include "TTree.h"
32   #include "TH1.h"
33   #include "TH2.h"
34   #include "TObjArray.h"
35   #include "TStyle.h"
36   #include "TCanvas.h"
37   #include "TLine.h"
38   #include "TText.h"
39   #include "TParticle.h"
40 #endif
41
42 struct GoodTrackITS {
43   Int_t lab;
44   Int_t code;
45   Float_t px,py,pz;
46   Float_t x,y,z;
47 };
48
49 Int_t good_tracks_its(GoodTrackITS *gt, const Int_t max, 
50 const char* evfoldname = AliConfig::fgkDefaultEventFolderName);
51
52 extern AliRun *gAlice;
53
54 Int_t AliITSComparisonV2() {
55    cerr<<"Doing comparison...\n";
56    if (gAlice) {
57       delete gAlice->GetRunLoader();
58       delete gAlice; 
59       gAlice=0;
60    }
61    
62    AliRunLoader *rl = AliRunLoader::Open("galice.root");
63    if (!rl) {
64        cerr<<"AliITSComparisonV2.C :Can't start sesion !\n";
65        return 1;
66    }
67    rl->LoadgAlice();
68    if (rl->GetAliRun())
69    AliKalmanTrack::SetConvConst(
70      1000/0.299792458/rl->GetAliRun()->Field()->SolenoidField()
71    );
72    else {
73       cerr<<"AliITSComparisonV2.C :Can't get AliRun !\n";
74       return 1;
75    }
76    //rl->UnloadgAlice();
77    
78
79    /* Generate a list of "good" tracks */
80    const Int_t MAX=15000;
81    GoodTrackITS gt[MAX];
82    Int_t ngood=0;
83    ifstream in("good_tracks_its");
84    if (in) {
85       cerr<<"Reading good tracks...\n";
86       while (in>>gt[ngood].lab>>gt[ngood].code>>
87                  gt[ngood].px>>gt[ngood].py>>gt[ngood].pz>>
88                  gt[ngood].x >>gt[ngood].y >>gt[ngood].z) {
89          ngood++;
90          cerr<<ngood<<'\r';
91          if (ngood==MAX) {
92             cerr<<"Too many good tracks !\n";
93             break;
94          }
95       }
96       if (!in.eof()) cerr<<"Read error (good_tracks_its) !\n";
97    } else {
98       cerr<<"Marking good tracks (this will take a while)...\n";
99       ngood=good_tracks_its(gt,MAX,AliConfig::fgkDefaultEventFolderName);
100       ofstream out("good_tracks_its");
101       if (out) {
102         for (Int_t ngd=0; ngd<ngood; ngd++)
103           out<<gt[ngd].lab<<' '<<gt[ngd].code<<' '
104              <<gt[ngd].px<<' '<<gt[ngd].py<<' '<<gt[ngd].pz<<' '
105              <<gt[ngd].x <<' '<<gt[ngd].y <<' '<<gt[ngd].z <<endl;
106       } else cerr<<"Can not open file (good_tracks_its) !\n";
107       out.close();
108    }
109
110    TObjArray tarray(2000);
111    { /*Load tracks*/
112    TFile *ef=TFile::Open("AliESDits.root");
113    if ((!ef)||(!ef->IsOpen())) {
114       ::Fatal("AliITSComparisonV2.C","Can't open AliESDits.root !");
115    }
116    TKey *key=0;
117    TIter next(ef->GetListOfKeys());
118    if ((key=(TKey*)next())!=0) {
119      AliESD *event=(AliESD*)key->ReadObj();
120      Int_t ntrk=event->GetNumberOfTracks();
121      for (Int_t i=0; i<ntrk; i++) {
122         AliESDtrack *t=event->GetTrack(i);
123         UInt_t status=t->GetStatus();
124         UInt_t flags=AliESDtrack::kTPCin|AliESDtrack::kITSin;
125
126         if ((status&AliESDtrack::kITSrefit)==0)
127           if ((status&flags)!=flags) continue;
128
129         AliITStrackV2 *iotrack=0;
130         iotrack=new AliITStrackV2(*t);
131         //if (t->GetConstrainedChi2()>=20) continue;   //  constrained 
132         //else iotrack=new AliITStrackV2(*t,kTRUE);    //     track
133         if ((status&flags)==flags) {
134            iotrack->PropagateTo(3.,0.0028,65.19);
135            iotrack->PropagateToVertex();
136         }
137         tarray.AddLast(iotrack);
138      }
139      delete event;
140    }
141    ef->Close();
142    }
143    Int_t nentr=tarray.GetEntriesFast();
144
145    TH1F *hp=new TH1F("hp","PHI resolution",50,-20.,20.); hp->SetFillColor(4);
146    TH1F *hl=new TH1F("hl","LAMBDA resolution",50,-20,20);hl->SetFillColor(4);
147    TH1F *hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.); 
148    hpt->SetFillColor(2); 
149    TH1F *hmpt=new TH1F("hmpt","Transverse impact parameter",30,-300,300); 
150    hmpt->SetFillColor(6);
151    TH1F *hz=new TH1F("hz","Longitudinal impact parameter",30,-300,300); 
152
153    AliITStrackV2 *trk=(AliITStrackV2*)tarray.UncheckedAt(0);
154    Double_t pmin=0.1*(100/0.299792458/0.2/trk->GetConvConst());
155    Double_t pmax=6.0+pmin;
156
157    TH1F *hgood=new TH1F("hgood","Good tracks",30,pmin,pmax);    
158    TH1F *hfound=new TH1F("hfound","Found tracks",30,pmin,pmax);
159    TH1F *hfake=new TH1F("hfake","Fake tracks",30,pmin,pmax);
160    TH1F *hg=new TH1F("hg","",30,pmin,pmax); //efficiency for good tracks
161    hg->SetLineColor(4); hg->SetLineWidth(2);
162    TH1F *hf=new TH1F("hf","Efficiency for fake tracks",30,pmin,pmax);
163    hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
164
165    //TH1F *hptw=new TH1F("hptw","Weghted pt",30,pmax,pmin);
166
167    TH1F *he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,100.);
168    TH2F *hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,200.);
169    hep->SetMarkerStyle(8);
170    hep->SetMarkerSize(0.4);
171
172
173    Int_t notf[MAX], nnotf=0;
174    Int_t fake[MAX], nfake=0;
175    Int_t mult[MAX], numb[MAX], nmult=0;
176
177    Int_t ng;
178    for (ng=0; ng<ngood; ng++) {
179       Int_t lab=gt[ng].lab, tlab=-1;
180       Double_t pxg=gt[ng].px, pyg=gt[ng].py, pzg=gt[ng].pz;
181       Double_t ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
182
183
184       if (ptg>pmin) hgood->Fill(ptg);
185
186       AliITStrackV2 *track=0;
187       Int_t cnt=0;
188       Int_t j;
189       for (j=0; j<nentr; j++) {
190           AliITStrackV2 *trk=(AliITStrackV2*)tarray.UncheckedAt(j);
191           Int_t lbl=trk->GetLabel();
192           if (lab==TMath::Abs(lbl)) {
193             if (cnt==0) {track=trk; tlab=lbl;}
194             cnt++;
195           }
196       }
197       if (cnt==0) {
198         notf[nnotf++]=lab;
199         continue;
200       } else if (cnt>1){
201         mult[nmult]=lab;
202         numb[nmult]=cnt; nmult++;        
203       }
204
205       if (ptg>pmin) {
206         if (lab==tlab) hfound->Fill(ptg);
207         else {
208           fake[nfake++]=lab;
209           hfake->Fill(ptg); 
210         }
211       }
212
213       Double_t xv,par[5]; track->GetExternalParameters(xv,par);
214       Float_t phi=TMath::ASin(par[2]) + track->GetAlpha();
215       if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
216       if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
217       Float_t lam=TMath::ATan(par[3]); 
218       Float_t pt_1=TMath::Abs(par[4]);
219
220       Double_t phig=TMath::ATan2(pyg,pxg);
221       hp->Fill((phi - phig)*1000.);
222
223       Double_t lamg=TMath::ATan2(pzg,ptg);
224       hl->Fill((lam - lamg)*1000.);
225
226       Double_t d=10000*track->GetD();
227       hmpt->Fill(d);
228
229       //hptw->Fill(ptg,TMath::Abs(d));
230
231       Double_t z=10000*track->GetZ();
232       hz->Fill(z);
233
234       hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
235
236       Float_t mom=1./(pt_1*TMath::Cos(lam));
237       Float_t dedx=track->GetdEdx();
238       hep->Fill(mom,dedx,1.);
239       if (TMath::Abs(gt[ng].code)==211)
240          if (mom>0.4 && mom<0.5) he->Fill(dedx,1.);
241    }
242
243
244    cout<<"\nList of Not found tracks :\n";
245    for (ng=0; ng<nnotf; ng++){
246      cout<<notf[ng]<<"\t";
247      if ((ng%9)==8) cout<<"\n";
248    }
249    cout<<"\n\nList of fake  tracks :\n";
250    for (ng=0; ng<nfake; ng++){
251      cout<<fake[ng]<<"\t";
252      if ((ng%9)==8) cout<<"\n";
253    }
254    cout<<"\n\nList of multiple found tracks :\n";
255    for (ng=0; ng<nmult; ng++) {
256        cout<<"id.   "<<mult[ng]
257            <<"     found - "<<numb[ng]<<"times\n";
258    }
259    cout<<endl;
260
261    cerr<<"Number of good tracks : "<<ngood<<endl;
262    cerr<<"Number of found tracks : "<<nentr<<endl;
263
264    ng=(Int_t)hgood->GetEntries(); //cerr<<"Good tracks "<<ng<<endl;
265    if (ng!=0)  
266    cerr<<"Integral efficiency is about "<<hfound->GetEntries()/ng*100.<<" %\n";
267    cerr<<endl;
268
269    gStyle->SetOptStat(111110);
270    gStyle->SetOptFit(1);
271
272    TCanvas *c1=new TCanvas("c1","",0,0,700,850);
273
274    TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
275    p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10); 
276    hp->SetFillColor(4);  hp->SetXTitle("(mrad)"); hp->Fit("gaus"); c1->cd();
277
278    TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw(); 
279    p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
280    hl->SetXTitle("(mrad)"); hl->Fit("gaus"); c1->cd();
281
282    TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
283    p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10); 
284    hpt->SetXTitle("(%)"); hpt->Fit("gaus"); c1->cd();
285
286    TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
287    p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
288    hmpt->SetXTitle("(micron)"); hmpt->Fit("gaus"); hz->Draw("same"); c1->cd();
289    //hfound->Sumw2();
290    //hptw->Sumw2(); 
291    //hg->SetMaximum(333);
292    //hg->SetYTitle("Impact Parameter Resolution (micron)");
293    //hg->SetXTitle("Pt (GeV/c)");
294    //hg->GetXaxis()->SetRange(0,10);
295    //hg->Divide(hptw,hfound,1,1.);
296    //hg->DrawCopy(); c1->cd();
297    
298
299    TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd(); 
300    p5->SetFillColor(41); p5->SetFrameFillColor(10);
301    hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
302    hg->Divide(hfound,hgood,1,1.,"b");
303    hf->Divide(hfake,hgood,1,1.,"b");
304    hg->SetMaximum(1.4);
305    hg->SetYTitle("Tracking efficiency");
306    hg->SetXTitle("Pt (GeV/c)");
307    hg->Draw();
308
309    TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
310    line1->Draw("same");
311    TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
312    line2->Draw("same");
313
314    hf->SetFillColor(1);
315    hf->SetFillStyle(3013);
316    hf->SetLineColor(2);
317    hf->SetLineWidth(2);
318    hf->Draw("histsame");
319    TText *text = new TText(0.461176,0.248448,"Fake tracks");
320    text->SetTextSize(0.05);
321    text->Draw();
322    text = new TText(0.453919,1.11408,"Good tracks");
323    text->SetTextSize(0.05);
324    text->Draw();
325
326    TCanvas *c2=new TCanvas("c2","",320,32,530,590);
327    TPad *p6=new TPad("p6","",0.,0.,1.,.5); p6->Draw();
328    p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10); 
329    he->SetFillColor(2); he->SetFillStyle(3005);  
330    he->SetXTitle("Arbitrary Units"); 
331    he->Fit("gaus"); c2->cd();
332
333    TPad *p7=new TPad("p7","",0.,0.5,1.,1.); p7->Draw(); 
334    p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
335    hep->SetXTitle("p (Gev/c)"); hep->SetYTitle("dE/dX (Arb. Units)"); 
336    hep->Draw(); c1->cd();
337    
338    return 0;
339 }
340
341 Int_t good_tracks_its(GoodTrackITS *gt, const Int_t max, const char* evfoldname) {
342    AliRunLoader* rl = AliRunLoader::GetRunLoader(evfoldname);
343    if (rl == 0x0) {
344       ::Fatal("AliITSComparisonV2.C::good_tracks_its",
345               "Can not find Run Loader in Folder Named %s",
346               evfoldname);
347    }
348
349    AliITSLoader* itsl = (AliITSLoader*)rl->GetLoader("ITSLoader");
350    if (itsl == 0x0) {
351        cerr<<"AliITSComparisonV2.C : Can not find ITSLoader\n";
352        delete rl;
353        return 3;
354    }
355    
356    rl->LoadgAlice();
357    rl->LoadHeader();
358    Int_t np = rl->GetHeader()->GetNtrack();
359
360    Int_t *good=new Int_t[np];
361    Int_t k;
362    for (k=0; k<np; k++) good[k]=0;
363
364    AliITS *ITS=(AliITS*)rl->GetAliRun()->GetDetector("ITS");
365    if (!ITS) {
366       cerr<<"can't get ITS !\n"; exit(8);
367    }
368    AliITSgeom *geom=ITS->GetITSgeom();
369    if (!geom) {
370       cerr<<"can't get ITS geometry !\n"; exit(9);
371    }
372
373    itsl->LoadRecPoints();
374    TTree *cTree=itsl->TreeR();
375    if (!cTree) {
376       cerr<<"Can't get cTree !\n"; exit(7);
377    }
378    TBranch *branch=cTree->GetBranch("Clusters");
379    if (!branch) {
380       cerr<<"Can't get clusters branch !\n"; exit(8);
381    }
382    TClonesArray *clusters=new TClonesArray("AliITSclusterV2",10000);
383    branch->SetAddress(&clusters);
384
385    Int_t entr=(Int_t)cTree->GetEntries();
386    for (k=0; k<entr; k++) {
387      cTree->GetEvent(k);
388      Int_t ncl=clusters->GetEntriesFast(); if (ncl==0) continue;
389      Int_t lay,lad,det;  geom->GetModuleId(k,lay,lad,det);
390      if (lay<1 || lay>6) {
391         cerr<<"wrong layer !\n"; exit(10);
392      }
393      while (ncl--) {
394         AliITSclusterV2 *pnt=(AliITSclusterV2*)clusters->UncheckedAt(ncl);
395         Int_t l0=pnt->GetLabel(0);
396           if (l0>=np) {cerr<<"Wrong label: "<<l0<<endl; continue;}
397         Int_t l1=pnt->GetLabel(1);
398           if (l1>=np) {cerr<<"Wrong label: "<<l1<<endl; continue;}
399         Int_t l2=pnt->GetLabel(2);
400           if (l2>=np) {cerr<<"Wrong label: "<<l2<<endl; continue;}
401         Int_t mask=1<<(lay-1);
402         if (l0>=0) good[l0]|=mask; 
403         if (l1>=0) good[l1]|=mask; 
404         if (l2>=0) good[l2]|=mask;
405      }
406    }
407    clusters->Delete(); delete clusters;
408    itsl->UnloadRawClusters();
409    
410    ifstream in("good_tracks_tpc");
411    if (!in) {
412      cerr<<"can't get good_tracks_tpc !\n"; exit(11);
413    }
414    
415    rl->LoadKinematics();
416    AliStack* stack = rl->Stack();
417    Int_t nt=0;
418    Double_t px,py,pz,x,y,z;
419    Int_t code,lab;
420    while (in>>lab>>code>>px>>py>>pz>>x>>y>>z) {
421       if (good[lab] != 0x3F) continue;
422       TParticle *p = (TParticle*)stack->Particle(lab);
423       if (p == 0x0) {
424          cerr<<"Can not get particle "<<lab<<endl;
425          nt++;
426          if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
427          continue;
428       }
429       gt[nt].lab=lab;
430       gt[nt].code=p->GetPdgCode();
431 //**** px py pz - in global coordinate system
432       gt[nt].px=p->Px(); gt[nt].py=p->Py(); gt[nt].pz=p->Pz();
433       gt[nt].x=gt[nt].y=gt[nt].z=0.;
434       nt++;
435       if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
436    }
437
438    delete[] good;
439
440    rl->UnloadKinematics();
441    rl->UnloadHeader();
442    rl->UnloadgAlice();
443
444    return nt;
445 }
446
447