]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFtracker.cxx
Removing obsolete dependences
[u/mrichter/AliRoot.git] / TOF / AliTOFtracker.cxx
CommitLineData
596a855f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
74ea065c 15// AliTOFtracker Class
16// Task: Perform association of the ESD tracks to TOF Clusters
17// and Update ESD track with associated TOF Cluster parameters
18//
19// -- Authors : S. Arcelli, C. Zampolli (Bologna University and INFN)
20// -- Contacts: Annalisa.De.Caro@cern.ch
21// -- : Chiara.Zampolli@bo.infn.it
22// -- : Silvia.Arcelli@bo.infn.it
23//--------------------------------------------------------------------
596a855f 24
25#include "AliTOFtracker.h"
74ea065c 26#include "AliTOFtrack.h"
27#include "TClonesArray.h"
28#include "TError.h"
29#include "AliTOFdigit.h"
30#include "AliTOFGeometry.h"
31#include "AliTOF.h"
32#include "AliRun.h"
33#include "AliModule.h"
596a855f 34
35ClassImp(AliTOFtracker)
36
74ea065c 37//_____________________________________________________________________________
38AliTOFtracker::AliTOFtracker(AliTOFGeometry * geom, Double_t parPID[2]) {
39 //AliTOFtracker main Ctor
40
41 fHoles=true;
42 fNseeds=0;
43 fNseedsTOF=0;
44 fngoodmatch=0;
45 fnbadmatch=0;
46 fnunmatch=0;
47 fnmatch=0;
48 fGeom = geom;
49 fTOFpid = new AliTOFpidESD(parPID);
50 fR=378.;
51 fTOFHeigth=15.3;
52 fdCut=3.;
53 fDy=AliTOFGeometry::XPad();
54 fDz=AliTOFGeometry::ZPad();
55 fDx=1.5;
56 fSeeds=0x0;
57 fTracks=0x0;
58 fN=0;
59 Init(); // temporary solution to know about Holes/no Holes
60}
61//_____________________________________________________________________________
62AliTOFtracker::AliTOFtracker(const AliTOFtracker &t):AliTracker() {
63 //AliTOFtracker copy Ctor
64
65 fHoles=t.fHoles;
66 fNseeds=t.fNseeds;
67 fNseedsTOF=t.fNseedsTOF;
68 fngoodmatch=t.fngoodmatch;
69 fnbadmatch=t.fnbadmatch;
70 fnunmatch=t.fnunmatch;
71 fnmatch=t.fnmatch;
72 fGeom = t.fGeom;
73 fTOFpid = t.fTOFpid;
74 fR=t.fR;
75 fTOFHeigth=t.fTOFHeigth;
76 fdCut=t.fdCut;
77 fDy=t.fDy;
78 fDz=t.fDz;
79 fDx=1.5;
80 fSeeds=t.fSeeds;
81 fTracks=t.fTracks;
82 fN=t.fN;
83}
84//_____________________________________________________________________________
85void AliTOFtracker::Init() {
86
87// temporary solution to know about Holes/no Holes, will be implemented as
88// an AliTOFGeometry getter
89
90 AliModule* frame=gAlice->GetModule("FRAME");
91
92 if(!frame) {
93 Error("Init","Could Not load FRAME! Assume Frame with Holes \n");
94 fHoles=true;
95 } else{
96 if(frame->IsVersion()==1) {fHoles=false;}
97 else {fHoles=true;}
98 }
99}
100//_____________________________________________________________________________
101Int_t AliTOFtracker::PropagateBack(AliESD* event) {
102 //
103 // Gets seeds from ESD event and Match with TOF Clusters
104 //
105
106
107 //Initialise some counters
108
109 fNseeds=0;
110 fNseedsTOF=0;
111 fngoodmatch=0;
112 fnbadmatch=0;
113 fnunmatch=0;
114 fnmatch=0;
115
116 Int_t ntrk=event->GetNumberOfTracks();
117 fNseeds = ntrk;
118 fSeeds= new TClonesArray("AliESDtrack");
119 TClonesArray &aESDTrack = *fSeeds;
120
121
122 //Load ESD tracks into a local Array of ESD Seeds
123
124 for (Int_t i=0; i<fNseeds; i++) {
125 AliESDtrack *t=event->GetTrack(i);
126 new(aESDTrack[i]) AliESDtrack(*t);
127 }
128
129 //Prepare ESD tracks candidates for TOF Matching
130 CollectESD();
131
132 //First Step with Strict Matching Criterion
133 MatchTracks(kFALSE);
134
135 //Second Step with Looser Matching Criterion
136 MatchTracks(kTRUE);
137
138 Info("PropagateBack","Number of matched tracks: %d",fnmatch);
139 Info("PropagateBack","Number of good matched tracks: %d",fngoodmatch);
140 Info("PropagateBack","Number of bad matched tracks: %d",fnbadmatch);
141
142 //Update the matched ESD tracks
143
144 for (Int_t i=0; i<ntrk; i++) {
145 AliESDtrack *t=event->GetTrack(i);
146 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
147 if(seed->GetTOFsignal()>0){
148 t->SetTOFsignal(seed->GetTOFsignal());
149 t->SetTOFcluster(seed->GetTOFcluster());
150 AliTOFtrack *track = new AliTOFtrack(*seed);
151 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
152 delete track;
153 }
154 }
155
156
157 //Make TOF PID
158 fTOFpid->MakePID(event);
159
160 delete fSeeds;
161 delete fTracks;
162 return 0;
163
164}
165//_________________________________________________________________________
166void AliTOFtracker::CollectESD() {
167 //prepare the set of ESD tracks to be matched to clusters in TOF
168
169 fTracks= new TClonesArray("AliTOFtrack");
170 TClonesArray &aTOFTrack = *fTracks;
171 for (Int_t i=0; i<fNseeds; i++) {
172
173 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
174 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
175
176 // TRD good tracks, already propagated at 371 cm
177
178 if (
179 ((t->GetStatus()&AliESDtrack::kTRDout)!=0) &&
180 ((t->GetStatus()&AliESDtrack::kTRDStop)==0)){
181 AliTOFtrack *track = new AliTOFtrack(*t);
182 track->SetSeedIndex(i);
183 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
184 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
185 fNseedsTOF++;
186 delete track;
187 }
188
189 // Propagate the rest of TPCbp
190
191 else {
192 AliTOFtrack *track = new AliTOFtrack(*t);
193 if(track->PropagateToInnerTOF(fHoles)){ // temporary solution
194 // if(track->PropagateToInnerTOF(fGeom->GetHoles())){
195 track->SetSeedIndex(i);
196 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
197 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
198 fNseedsTOF++;
199 }
200 delete track;
201 }
202 }
203
204 // Sort according uncertainties on track position
205 fTracks->Sort();
206
207}
208//_________________________________________________________________________
209void AliTOFtracker::MatchTracks( Bool_t mLastStep){
210
211 //Match ESD tracks to clusters in TOF
212
213 static const Double_t kMasses[]={
214 0.000511, 0.105658, 0.139570, 0.493677, 0.938272, 1.875613
215 };
216
217 Int_t nSteps=(Int_t)(fTOFHeigth/0.1);
218
219 for (Int_t i=0; i<fNseedsTOF; i++) {
220
221 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(i);
222 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
223 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
224 if(t->GetTOFsignal()>0. )continue;
225
226 // Some init
227
228 Int_t index[10000];
229 Float_t dist[10000];
230 Float_t cxpos[10000];
231 Float_t crecL[10000];
9b49e4c9 232 Float_t * trackPos[4];
233 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
234 // Float_t trackPos[4][nSteps];
74ea065c 235
236 // Determine a window around the track
237
238 Double_t x,par[5];
239 trackTOFin->GetExternalParameters(x,par);
240 Double_t cov[15];
241 trackTOFin->GetExternalCovariance(cov);
242 Float_t scalefact=3.;
243 Double_t dphi=
244 scalefact*
245 ((5*TMath::Sqrt(cov[0]) + 0.5*fDy + 2.5*TMath::Abs(par[2]))/fR);
246 Double_t dz=
247 scalefact*
248 (5*TMath::Sqrt(cov[2]) + 0.5*fDz + 2.5*TMath::Abs(par[3]));
249
250 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
251 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
252 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
253 Double_t z=par[1];
254
9b49e4c9 255 Int_t * clind[6];
256 for (Int_t ii=0;ii<6;ii++) clind[ii] = new Int_t[fN];
257 // Int_t clind[6][fN];
74ea065c 258 Int_t nc=0;
259
260 // find the clusters in the window of the track
261
262 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
263 AliTOFcluster *c=fClusters[k];
264 if (c->GetZ() > z+dz) break;
265 if (c->IsUsed()) continue;
266
267 Double_t dph=TMath::Abs(c->GetPhi()-phi);
268 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
9b49e4c9 269 if (TMath::Abs(dph)>dphi) continue;
74ea065c 270
271 clind[0][nc] = c->GetDetInd(0);
272 clind[1][nc] = c->GetDetInd(1);
273 clind[2][nc] = c->GetDetInd(2);
274 clind[3][nc] = c->GetDetInd(3);
275 clind[4][nc] = c->GetDetInd(4);
276 clind[5][nc] = k;
277 nc++;
278 }
279
280 //start fine propagation
281
282 Int_t nStepsDone = 0;
283 for( Int_t istep=0; istep<nSteps; istep++){
284
285 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
286 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
287
288 Bool_t skip=kFALSE;
289 Double_t ysect=trackTOFin->GetYat(xs,skip);
290 if(skip)break;
291 if (ysect > ymax) {
292 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
293 break;
294 }
295 } else if (ysect <-ymax) {
296 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
297 break;
298 }
299 }
300
301 if(!trackTOFin->PropagateTo(xs)) {
302 break;
303 }
304
305 nStepsDone++;
306
307 // store the running point (Globalrf) - fine propagation
308
309 Double_t x,y,z;
310 trackTOFin->GetGlobalXYZ(x,y,z);
311 trackPos[0][istep]= (Float_t) x;
312 trackPos[1][istep]= (Float_t) y;
313 trackPos[2][istep]= (Float_t) z;
314 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
315 }
316
317
318 Int_t nfound = 0;
319 for (Int_t istep=0; istep<nStepsDone; istep++) {
320
321 Bool_t isInside =kFALSE;
322 Float_t ctrackPos[3];
323
324 ctrackPos[0]= trackPos[0][istep];
325 ctrackPos[1]= trackPos[1][istep];
326 ctrackPos[2]= trackPos[2][istep];
327
328 //now see whether the track matches any of the TOF clusters
329
330 for (Int_t i=0; i<nc; i++){
331 Int_t cind[5];
332 cind[0]= clind[0][i];
333 cind[1]= clind[1][i];
334 cind[2]= clind[2][i];
335 cind[3]= clind[3][i];
336 cind[4]= clind[4][i];
337 Bool_t accept = kFALSE;
338 if( mLastStep)accept = (fGeom->DistanceToPad(cind,ctrackPos)<fdCut);
339 if(!mLastStep)accept = (fGeom->IsInsideThePad(cind,ctrackPos));
340 if(accept){
341 if(!mLastStep)isInside=kTRUE;
342 dist[nfound]=fGeom->DistanceToPad(cind,ctrackPos);
343 crecL[nfound]=trackPos[3][istep];
344 index[nfound]=clind[5][i]; // store cluster id
345 cxpos[nfound]=AliTOFGeometry::RinTOF()+istep*0.1; //store prop.radius
346 nfound++;
347 if(isInside)break;
348 }//end if accept
349 } //end for on the clusters
9b49e4c9 350
351
74ea065c 352 if(isInside)break;
353 } //end for on the steps
354
9b49e4c9 355 for (Int_t ii=0;ii<6;ii++) delete [] clind[ii];
356
357
74ea065c 358 if (nfound == 0 ) {
359 fnunmatch++;
360 continue;
361 }
362
363 fnmatch++;
364
365 // now choose the cluster to be matched with the track.
366
367 Int_t idclus=0;
368 Float_t recL = 0.;
369 Float_t xpos=0.;
370 Float_t mindist=1000.;
371 for (Int_t iclus= 0; iclus<nfound;iclus++){
372 if (dist[iclus]< mindist){
373 mindist = dist[iclus];
374 xpos = cxpos[iclus];
375 idclus =index[iclus];
376 recL=crecL[iclus]+fDx*0.5;
377 }
378 }
379
380 AliTOFcluster *c=fClusters[idclus];
381 c->Use();
382
383 // Track length correction for matching Step 2
384
385 if(mLastStep){
386 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
387 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
388 +trackPos[1][70]*trackPos[1][70]
389 +trackPos[2][70]*trackPos[2][70]);
390 Float_t dlt=rc-rt;
391 recL=trackPos[3][70]+dlt;
392 }
393
394 if (
395 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
396 ||
397 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
398 ||
399 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
400 ) {
401 fngoodmatch++;
402 }
403 else{
404 fnbadmatch++;
405 }
406
407 delete trackTOFin;
408
409 Double_t tof=50*c->GetTDC()+32; // in ps
410 t->SetTOFsignal(tof);
411 t->SetTOFcluster(c->GetIndex());
412 Double_t time[10]; t->GetIntegratedTimes(time);
413 Double_t mom=t->GetP();
414 for(Int_t j=0;j<=5;j++){
415 Double_t mass=kMasses[j];
416 time[j]+=(recL-trackPos[3][0])/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
417 }
418
419 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
420 trackTOFout->PropagateTo(xpos);
421 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
422 t->SetIntegratedLength(recL);
423 t->SetIntegratedTimes(time);
424
425 delete trackTOFout;
9b49e4c9 426 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
74ea065c 427 }
428}
429//_________________________________________________________________________
430Int_t AliTOFtracker::LoadClusters(TTree *dTree) {
431 //--------------------------------------------------------------------
432 //This function loads the TOF clusters
433 //--------------------------------------------------------------------
434
435 TBranch *branch=dTree->GetBranch("TOF");
436 if (!branch) {
437 Error("LoadClusters"," can't get the branch with the TOF digits !\n");
438 return 1;
439 }
440
441 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
442 branch->SetAddress(&digits);
443
444 dTree->GetEvent(0);
445 Int_t nd=digits->GetEntriesFast();
446 Info("LoadClusters","number of digits: %d",nd);
447
448 for (Int_t i=0; i<nd; i++) {
449 AliTOFdigit *d=(AliTOFdigit*)digits->UncheckedAt(i);
450 Int_t dig[5]; Float_t g[3];
451 dig[0]=d->GetSector();
452 dig[1]=d->GetPlate();
453 dig[2]=d->GetStrip();
454 dig[3]=d->GetPadz();
455 dig[4]=d->GetPadx();
456
457 fGeom->GetPos(dig,g);
458
459 Double_t h[5];
460 h[0]=TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
461 h[1]=TMath::ATan2(g[1],g[0]); h[2]=g[2];
462 h[3]=d->GetTdc(); h[4]=d->GetAdc();
463
464 AliTOFcluster *cl=new AliTOFcluster(h,d->GetTracks(),dig,i);
465 InsertCluster(cl);
466 }
467
468 return 0;
469}
470//_________________________________________________________________________
471void AliTOFtracker::UnloadClusters() {
472 //--------------------------------------------------------------------
473 //This function unloads TOF clusters
474 //--------------------------------------------------------------------
475 for (Int_t i=0; i<fN; i++) delete fClusters[i];
476 fN=0;
477}
478
479//_________________________________________________________________________
480Int_t AliTOFtracker::InsertCluster(AliTOFcluster *c) {
481 //--------------------------------------------------------------------
482 //This function adds a cluster to the array of clusters sorted in Z
483 //--------------------------------------------------------------------
484 if (fN==kMaxCluster) {
485 Error("InsertCluster","Too many clusters !\n");
486 return 1;
487 }
488
489 if (fN==0) {fClusters[fN++]=c; return 0;}
490 Int_t i=FindClusterIndex(c->GetZ());
491 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTOFcluster*));
492 fClusters[i]=c; fN++;
493
494 return 0;
495}
496
497//_________________________________________________________________________
498Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
499 //--------------------------------------------------------------------
500 // This function returns the index of the nearest cluster
501 //--------------------------------------------------------------------
502 if (fN==0) return 0;
503 if (z <= fClusters[0]->GetZ()) return 0;
504 if (z > fClusters[fN-1]->GetZ()) return fN;
505 Int_t b=0, e=fN-1, m=(b+e)/2;
506 for (; b<e; m=(b+e)/2) {
507 if (z > fClusters[m]->GetZ()) b=m+1;
508 else e=m;
509 }
510 return m;
511}
512