]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCTestTracking.C
removed obsolete AliTPCDigitsDisplay.C
[u/mrichter/AliRoot.git] / TPC / AliTPCTestTracking.C
CommitLineData
cc80f89e 1struct GoodTrack {
2 Int_t lab;
3 Int_t code;
4 Float_t px,py,pz;
5 Float_t x,y,z;
6};
7Int_t good_tracks(GoodTrack *gt, Int_t max);
8
8c555625 9void AliTPCTestTracking() {
cc80f89e 10 const char *pname="75x40_100x60";
8c555625 11
12// Dynamically link some shared libs
cc80f89e 13
8c555625 14 if (gClassTable->GetID("AliRun") < 0) {
15 gROOT->LoadMacro("loadlibs.C");
16 loadlibs();
17 } else {
18 delete gAlice;
19 gAlice=0;
20 }
21
22// Connect the Root Galice file containing Geometry, Kine and Hits
23 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("galice.root");
24 if (!file) file = new TFile("galice.root");
cc80f89e 25 //if (!file) file = TFile::Open("rfio:galice.root");
8c555625 26
27// Get AliRun object from file or create it if not on file
28 if (!gAlice) {
29 gAlice = (AliRun*)file->Get("gAlice");
30 if (gAlice) printf("AliRun object found on file\n");
31 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
32 }
33
34 gAlice->GetEvent(0);
35
8c555625 36 AliTPC *TPC = (AliTPC*)gAlice->GetDetector("TPC");
cc80f89e 37 Int_t ver=TPC->IsVersion();
8c555625 38 cerr<<"TPC version "<<ver<<" has been found !\n";
39
cc80f89e 40 AliTPCParam *digp= (AliTPCParam*)file->Get(pname);
41 if (digp!=0) TPC->SetParam(digp);
8c555625 42 else cerr<<"Warning: default TPC parameters will be used !\n";
43
cc80f89e 44 Int_t nrow_up=TPC->GetParam()->GetNRowUp();
45 Int_t nrows=TPC->GetParam()->GetNRowLow()+nrow_up;
3c0f9266 46
8c555625 47 switch (ver) {
48 case 1:
49 cerr<<"Making clusters...\n";
50 TPC->Hits2Clusters();
8c555625 51 break;
52 case 2:
53 cerr<<"Looking for clusters...\n";
54 TPC->Digits2Clusters();
8c555625 55 break;
56 default:
57 cerr<<"Invalid TPC version !\n";
58 return;
59 }
60
cc80f89e 61 TClonesArray *clusters=TPC->Clusters();
62 Int_t n=clusters->GetEntriesFast();
63 cerr<<"Number of clusters "<<n<<" \n";
64
8c555625 65 cerr<<"Looking for tracks...\n";
cc80f89e 66 TStopwatch timer;
8c555625 67 TPC->Clusters2Tracks();
cc80f89e 68 timer.Stop(); timer.Print();
69 Int_t nt=0;
8c555625 70 TClonesArray *tracks=TPC->Tracks();
71 if (tracks) nt=tracks->GetEntriesFast();
72 cerr<<"Number of found tracks "<<nt<<endl;
73
74/////////////////////////////////////////////////////////////////////////
cc80f89e 75 GoodTrack gt[7000];
76 Int_t ngood=0;
77 ifstream in("good_tracks");
78 if (in) {
79 cerr<<"Reading good tracks...\n";
80 while (in>>gt[ngood].lab>>gt[ngood].code
81 >>gt[ngood].px >>gt[ngood].py>>gt[ngood].pz
82 >>gt[ngood].x >>gt[ngood].y >>gt[ngood].z) {
83 ngood++;
84 cerr<<ngood<<'\r';
85 if (ngood==7000) {
86 cerr<<"Too many good tracks !\n";
87 break;
88 }
89 }
90 if (!in.eof()) cerr<<"Read error (good_tracks) !\n";
91 } else {
92 cerr<<"Marking good tracks (this will take a while)...\n";
93 ngood=good_tracks(gt,7000);
94 ofstream out("good_tracks");
95 if (out) {
96 for (Int_t ngd=0; ngd<ngood; ngd++)
97 out<<gt[ngd].lab<<' '<<gt[ngd].code<<' '
98 <<gt[ngd].px <<' '<<gt[ngd].py<<' '<<gt[ngd].pz<<' '
99 <<gt[ngd].x <<' '<<gt[ngd].y <<' '<<gt[ngd].z <<endl;
100 } else cerr<<"Can not open file (good_tracks) !\n";
101 out.close();
102 }
103 cerr<<"Number of good tracks : "<<ngood<<endl;
104
8c555625 105 cerr<<"Doing comparison...\n";
cc80f89e 106 TH1F *hp=new TH1F("hp","PHI resolution",50,-20.,20.); hp->SetFillColor(4);
107 TH1F *hl=new TH1F("hl","LAMBDA resolution",50,-20,20);hl->SetFillColor(4);
8c555625 108 TH1F *hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
109 hpt->SetFillColor(2);
cc80f89e 110 TH1F *hmpt=new TH1F("hmpt","Relative Pt resolution (pt>4GeV/c)",30,-60,60);
111 hmpt->SetFillColor(6);
8c555625 112
cc80f89e 113 TH1F *hgood=new TH1F("hgood","Good tracks",20,0,7);
114 TH1F *hfound=new TH1F("hfound","Found tracks",20,0,7);
115 TH1F *hfake=new TH1F("hfake","Fake tracks",20,0,7);
116 TH1F *hg=new TH1F("hg","",20,0,7); //efficiency for good tracks
8c555625 117 hg->SetLineColor(4); hg->SetLineWidth(2);
cc80f89e 118 TH1F *hf=new TH1F("hf","Efficiency for fake tracks",20,0,7);
8c555625 119 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
120
cc80f89e 121 TH1F *he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,100.);
122 TH2F *hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,200.);
8c555625 123
cc80f89e 124 while (ngood--) {
125 Int_t lab=gt[ngood].lab,tlab;
126 Float_t ptg=
127 TMath::Sqrt(gt[ngood].px*gt[ngood].px + gt[ngood].py*gt[ngood].py);
8c555625 128
129 hgood->Fill(ptg);
cc80f89e 130
131 AliTPCtrack *track;
132 Int_t i;
133 for (i=0; i<nt; i++) {
134 track=(AliTPCtrack*)tracks->UncheckedAt(i);
135 tlab=track->GetLabel(nrows);
136 if (lab==TMath::Abs(tlab)) break;
8c555625 137 }
cc80f89e 138 if (i==nt) {
139 cerr<<"Track "<<lab<<" was not found !\n";
140 continue;
141 }
142 Double_t xk=gt[ngood].x;//digp->GetPadRowRadii(0,0);
143 track->PropagateTo(xk);
3c0f9266 144
cc80f89e 145 if (lab==tlab) hfound->Fill(ptg);
146 else { hfake->Fill(ptg); cerr<<lab<<" fake\n";}
147
148 Double_t px,py,pz,pt=fabs(track->GetPt());track->GetPxPyPz(px,py,pz);
149
150 if (TMath::Abs(gt[ngood].code)==11 && ptg>4.) {
151 hmpt->Fill((1/pt - 1/ptg)/(1/ptg)*100.);
152 } else {
153 Float_t phig=TMath::ATan2(gt[ngood].py,gt[ngood].px);
154 Float_t phi =TMath::ATan2(py,px );
155 hp->Fill((phi - phig)*1000.);
3c0f9266 156
cc80f89e 157 Float_t lamg=TMath::ATan2(gt[ngood].pz,ptg);
158 Float_t lam =TMath::ATan2(pz ,pt );
159 hl->Fill((lam - lamg)*1000.);
160
161 hpt->Fill((1/pt - 1/ptg)/(1/ptg)*100.);
162 }
163 Float_t mom=track->GetP();
164 Float_t dedx=track->GetdEdX(0.05,0.70);
165 hep->Fill(mom,dedx,1.);
166 if (TMath::Abs(gt[ngood].code)==211)
167 if (mom>0.4 && mom<0.5) {
168 he->Fill(dedx,1.);
169 }
170 }
171
172 Stat_t ng=hgood->GetEntries(); cerr<<"Good tracks "<<ng<<endl;
173 Stat_t nf=hfound->GetEntries();
174 if (ng!=0)
175 cerr<<"Integral efficiency is about "<<nf/ng*100.<<" %\n";
8c555625 176
177 gStyle->SetOptStat(111110);
178 gStyle->SetOptFit(1);
179
180 TCanvas *c1=new TCanvas("c1","",0,0,700,850);
181
182 TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
183 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
184 hp->SetFillColor(4); hp->SetXTitle("(mrad)"); hp->Fit("gaus"); c1->cd();
185
186 TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw();
187 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
188 hl->SetXTitle("(mrad)"); hl->Fit("gaus"); c1->cd();
189
190 TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
191 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
192 hpt->SetXTitle("(%)"); hpt->Fit("gaus"); c1->cd();
193
194 TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
195 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
cc80f89e 196 hmpt->SetXTitle("(%)"); hmpt->Fit("gaus"); c1->cd();
8c555625 197
198 TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd();
3c0f9266 199 p5->SetFillColor(41); p5->SetFrameFillColor(10);
8c555625 200 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
201 hg->Divide(hfound,hgood,1,1.,"b");
202 hf->Divide(hfake,hgood,1,1.,"b");
203 hg->SetMaximum(1.4);
204 hg->SetYTitle("Tracking efficiency");
205 hg->SetXTitle("Pt (GeV/c)");
206 hg->Draw();
207
cc80f89e 208 TLine *line1 = new TLine(0,1.0,7,1.0); line1->SetLineStyle(4);
8c555625 209 line1->Draw("same");
cc80f89e 210 TLine *line2 = new TLine(0,0.9,7,0.9); line2->SetLineStyle(4);
8c555625 211 line2->Draw("same");
212
213 hf->SetFillColor(1);
214 hf->SetFillStyle(3013);
215 hf->SetLineColor(2);
216 hf->SetLineWidth(2);
217 hf->Draw("histsame");
218 TText *text = new TText(0.461176,0.248448,"Fake tracks");
219 text->SetTextSize(0.05);
220 text->Draw();
221 text = new TText(0.453919,1.11408,"Good tracks");
222 text->SetTextSize(0.05);
223 text->Draw();
3c0f9266 224
225
226
227 TCanvas *c2=new TCanvas("c2","",320,32,530,590);
228
229 TPad *p6=new TPad("p6","",0.,0.,1.,.5); p6->Draw();
230 p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10);
231 he->SetFillColor(2); he->SetFillStyle(3005);
232 he->SetXTitle("Arbitrary Units");
233 he->Fit("gaus"); c2->cd();
234
235 TPad *p7=new TPad("p7","",0.,0.5,1.,1.); p7->Draw();
236 p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
237 hep->SetXTitle("p (Gev/c)"); hep->SetYTitle("dE/dX (Arb. Units)");
238 hep->Draw(); c1->cd();
239
cc80f89e 240}
3c0f9266 241
cc80f89e 242
243Int_t good_tracks(GoodTrack *gt, Int_t max) {
244 const char *tname="TreeD_75x40_100x60";
245
246 Int_t nt=0;
247
248 AliTPC *TPC = (AliTPC*)gAlice->GetDetector("TPC");
249 Int_t ver=TPC->IsVersion();
250 AliTPCParam *digp= (AliTPCParam*)TPC->GetParam();
251
252 Int_t nrow_up=TPC->GetParam()->GetNRowUp();
253 Int_t nrows=TPC->GetParam()->GetNRowLow()+nrow_up;
254 Int_t zero=TPC->GetParam()->GetZeroSup();
255 Int_t gap=Int_t(0.125*nrows);
256 Int_t good_number=Int_t(0.4*nrows);
257
258 //gAlice->GetEvent(0);
259 TClonesArray *particles=gAlice->Particles();
260 Int_t np=particles->GetEntriesFast();
261 Int_t *good=new Int_t[np];
262 for (Int_t ii=0; ii<np; ii++) good[ii]=0;
263
264 switch (ver) {
265 case 1:
266 TClonesArray *clusters=TPC->Clusters();
267 Int_t n=0;
268 if (clusters) n=clusters->GetEntriesFast();
269 for (Int_t i=0; i<n; i++) {
270 AliTPCcluster *c=(AliTPCcluster*)clusters->UncheckedAt(i);
271 Int_t lab=c->fTracks[0];
272 if (lab<0) continue; //noise cluster
273 lab=TMath::Abs(lab);
274 Int_t sec=c->fSector, row=c->fPadRow;
275 if (sec>=digp->GetNInnerSector())
276 if (row==nrow_up-1 ) good[lab]|=0x1000;
277 if (sec>=digp->GetNInnerSector())
278 if (row==nrow_up-1-gap) good[lab]|=0x800;
279 good[lab]++;
280 }
281 break;
282 case 2:
283 TTree *TD=(TTree*)gDirectory->Get(tname);
284 AliSimDigits da, *digits=&da;
285 TD->GetBranch("Segment")->SetAddress(&digits);
286 Int_t *count = new Int_t[np];
287 Int_t i;
288 for (i=0; i<np; i++) count[i]=0;
289 Int_t sectors_by_rows=(Int_t)TD->GetEntries();
290 for (i=0; i<sectors_by_rows; i++) {
291 if (!TD->GetEvent(i)) continue;
292 Int_t sec,row;
293 digp->AdjustSectorRow(digits->GetID(),sec,row);
294 cerr<<sec<<' '<<row<<" \r";
295 digits->First();
296 while (digits->Next()) {
297 Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn();
298 Short_t dig = digits->GetDigit(it,ip);
299 Int_t idx0=digits->GetTrackID(it,ip,0);
300 Int_t idx1=digits->GetTrackID(it,ip,1);
301 Int_t idx2=digits->GetTrackID(it,ip,2);
302 if (idx0>=0 && dig>=zero) count[idx0]+=1;
303 if (idx1>=0 && dig>=zero) count[idx1]+=1;
304 if (idx2>=0 && dig>=zero) count[idx2]+=1;
305 }
306 for (Int_t j=0; j<np; j++) {
307 if (count[j]>1) {
308 if (sec>=digp->GetNInnerSector())
309 if (row==nrow_up-1 ) good[j]|=0x1000;
310 if (sec>=digp->GetNInnerSector())
311 if (row==nrow_up-1-gap) good[j]|=0x800;
312 good[j]++;
313 }
314 count[j]=0;
315 }
316 }
317 delete[] count;
318 break;
319 default:
320 cerr<<"Invalid TPC version !\n";
321 return;
322 }
323
324 TTree *TH=gAlice->TreeH();
325 TClonesArray *hits=TPC->Hits();
326 Int_t npart=TH->GetEntries();
327
328 while (npart--) {
329 TPC->ResetHits();
330 TH->GetEvent(npart);
331 Int_t nhits=hits->GetEntriesFast();
332 if (nhits==0) continue;
333 AliTPChit *hit;
334 Int_t j;
335 for (j=0; j<nhits-1; j++) {
336 hit=(AliTPChit*)hits->UncheckedAt(j);
337 if (hit->fQ==0.) break;
338 }
339 if (j==nhits-1) continue;
340 AliTPChit *hit1=(AliTPChit*)hits->UncheckedAt(j+1);
341 if (hit1->fQ != 0.) continue;
342 Int_t i=hit->fTrack;
343 TParticle *p = (TParticle*)particles->UncheckedAt(i);
344 if (p->GetFirstMother()>=0) continue; //secondary particle
345 if (good[i] < 0x1000+0x800+2+good_number) continue;
346 if (p->Pt()<0.100) continue;
347 if (TMath::Abs(p->Pz()/p->Pt())>0.999) continue;
348
349 gt[nt].lab=i;
350 gt[nt].code=p->GetPdgCode();
351//**** px py pz - in global coordinate system, x y z - in local !
352 gt[nt].px=hit->fX; gt[nt].py=hit->fY; gt[nt].pz=hit->fZ;
353 Float_t cs,sn; digp->AdjustCosSin(hit1->fSector,cs,sn);
354 gt[nt].x = hit1->fX*cs + hit1->fY*sn;
355 gt[nt].y =-hit1->fX*sn + hit1->fY*cs;
356 gt[nt].z = hit1->fZ;
357 nt++;
358
359 cerr<<i<<" \r";
360 if (nt==max) {cerr<<"Too many good tracks !\n"; break;}
361 }
362 delete[] good;
363 return nt;
8c555625 364}
365