Introduction of a new TOF constant (i.e. TDC bin width)
[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
2871e58d 25#include <Rtypes.h>
596a855f 26#include "AliTOFtracker.h"
74ea065c 27#include "AliTOFtrack.h"
28#include "TClonesArray.h"
d076c8d5 29#include "AliLog.h"
74ea065c 30#include "AliTOFdigit.h"
31#include "AliTOFGeometry.h"
74ea065c 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) {
d076c8d5 93 AliError("Could Not load FRAME! Assume Frame with Holes");
74ea065c 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
d076c8d5 138 AliInfo(Form("Number of matched tracks: %d",fnmatch));
139 AliInfo(Form("Number of good matched tracks: %d",fngoodmatch));
140 AliInfo(Form("Number of bad matched tracks: %d",fnbadmatch));
74ea065c 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
7bf28302 160 if (fSeeds) {
161 fSeeds->Delete();
162 delete fSeeds;
163 fSeeds = 0x0;
164 }
165 if (fTracks) {
166 fTracks->Delete();
167 delete fTracks;
168 fTracks = 0x0;
169 }
74ea065c 170 return 0;
171
172}
173//_________________________________________________________________________
174void AliTOFtracker::CollectESD() {
175 //prepare the set of ESD tracks to be matched to clusters in TOF
176
177 fTracks= new TClonesArray("AliTOFtrack");
178 TClonesArray &aTOFTrack = *fTracks;
179 for (Int_t i=0; i<fNseeds; i++) {
180
181 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
182 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
183
184 // TRD good tracks, already propagated at 371 cm
185
56da420e 186 AliTOFtrack *track = new AliTOFtrack(*t); // New
187 Double_t x = track->GetX(); //New
188
189 if (((t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
190 ( x >= AliTOFGeometry::RinTOF()) ){
74ea065c 191 track->SetSeedIndex(i);
192 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
193 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
194 fNseedsTOF++;
195 delete track;
196 }
197
198 // Propagate the rest of TPCbp
199
200 else {
74ea065c 201 if(track->PropagateToInnerTOF(fHoles)){ // temporary solution
202 // if(track->PropagateToInnerTOF(fGeom->GetHoles())){
203 track->SetSeedIndex(i);
204 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
205 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
206 fNseedsTOF++;
207 }
208 delete track;
209 }
210 }
211
212 // Sort according uncertainties on track position
213 fTracks->Sort();
214
215}
216//_________________________________________________________________________
217void AliTOFtracker::MatchTracks( Bool_t mLastStep){
218
219 //Match ESD tracks to clusters in TOF
220
74ea065c 221 Int_t nSteps=(Int_t)(fTOFHeigth/0.1);
7bf28302 222
223 //PH Arrays (moved outside of the loop)
224 Float_t * trackPos[4];
225 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
226 Int_t * clind[6];
227 for (Int_t ii=0;ii<6;ii++) clind[ii] = new Int_t[fN];
74ea065c 228
229 for (Int_t i=0; i<fNseedsTOF; i++) {
230
231 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(i);
232 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
7bf28302 233 if(t->GetTOFsignal()>0. ) continue;
74ea065c 234 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
74ea065c 235
236 // Some init
237
238 Int_t index[10000];
239 Float_t dist[10000];
240 Float_t cxpos[10000];
241 Float_t crecL[10000];
74ea065c 242
243 // Determine a window around the track
244
245 Double_t x,par[5];
246 trackTOFin->GetExternalParameters(x,par);
247 Double_t cov[15];
248 trackTOFin->GetExternalCovariance(cov);
249 Float_t scalefact=3.;
250 Double_t dphi=
251 scalefact*
252 ((5*TMath::Sqrt(cov[0]) + 0.5*fDy + 2.5*TMath::Abs(par[2]))/fR);
253 Double_t dz=
254 scalefact*
255 (5*TMath::Sqrt(cov[2]) + 0.5*fDz + 2.5*TMath::Abs(par[3]));
256
257 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
258 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
259 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
260 Double_t z=par[1];
261
74ea065c 262 Int_t nc=0;
263
264 // find the clusters in the window of the track
265
266 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
267 AliTOFcluster *c=fClusters[k];
268 if (c->GetZ() > z+dz) break;
269 if (c->IsUsed()) continue;
270
271 Double_t dph=TMath::Abs(c->GetPhi()-phi);
272 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
9b49e4c9 273 if (TMath::Abs(dph)>dphi) continue;
74ea065c 274
275 clind[0][nc] = c->GetDetInd(0);
276 clind[1][nc] = c->GetDetInd(1);
277 clind[2][nc] = c->GetDetInd(2);
278 clind[3][nc] = c->GetDetInd(3);
279 clind[4][nc] = c->GetDetInd(4);
280 clind[5][nc] = k;
281 nc++;
282 }
283
284 //start fine propagation
285
286 Int_t nStepsDone = 0;
287 for( Int_t istep=0; istep<nSteps; istep++){
288
289 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
290 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
291
292 Bool_t skip=kFALSE;
293 Double_t ysect=trackTOFin->GetYat(xs,skip);
294 if(skip)break;
295 if (ysect > ymax) {
296 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
297 break;
298 }
299 } else if (ysect <-ymax) {
300 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
301 break;
302 }
303 }
304
305 if(!trackTOFin->PropagateTo(xs)) {
306 break;
307 }
308
309 nStepsDone++;
310
311 // store the running point (Globalrf) - fine propagation
312
313 Double_t x,y,z;
314 trackTOFin->GetGlobalXYZ(x,y,z);
315 trackPos[0][istep]= (Float_t) x;
316 trackPos[1][istep]= (Float_t) y;
317 trackPos[2][istep]= (Float_t) z;
318 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
319 }
320
321
322 Int_t nfound = 0;
323 for (Int_t istep=0; istep<nStepsDone; istep++) {
324
325 Bool_t isInside =kFALSE;
326 Float_t ctrackPos[3];
327
328 ctrackPos[0]= trackPos[0][istep];
329 ctrackPos[1]= trackPos[1][istep];
330 ctrackPos[2]= trackPos[2][istep];
331
332 //now see whether the track matches any of the TOF clusters
333
334 for (Int_t i=0; i<nc; i++){
335 Int_t cind[5];
336 cind[0]= clind[0][i];
337 cind[1]= clind[1][i];
338 cind[2]= clind[2][i];
339 cind[3]= clind[3][i];
340 cind[4]= clind[4][i];
341 Bool_t accept = kFALSE;
342 if( mLastStep)accept = (fGeom->DistanceToPad(cind,ctrackPos)<fdCut);
343 if(!mLastStep)accept = (fGeom->IsInsideThePad(cind,ctrackPos));
344 if(accept){
345 if(!mLastStep)isInside=kTRUE;
346 dist[nfound]=fGeom->DistanceToPad(cind,ctrackPos);
347 crecL[nfound]=trackPos[3][istep];
348 index[nfound]=clind[5][i]; // store cluster id
349 cxpos[nfound]=AliTOFGeometry::RinTOF()+istep*0.1; //store prop.radius
350 nfound++;
351 if(isInside)break;
352 }//end if accept
353 } //end for on the clusters
9b49e4c9 354
355
74ea065c 356 if(isInside)break;
357 } //end for on the steps
358
9b49e4c9 359
360
74ea065c 361 if (nfound == 0 ) {
362 fnunmatch++;
7bf28302 363 delete trackTOFin;
74ea065c 364 continue;
365 }
366
367 fnmatch++;
368
369 // now choose the cluster to be matched with the track.
370
371 Int_t idclus=0;
372 Float_t recL = 0.;
373 Float_t xpos=0.;
374 Float_t mindist=1000.;
375 for (Int_t iclus= 0; iclus<nfound;iclus++){
376 if (dist[iclus]< mindist){
377 mindist = dist[iclus];
378 xpos = cxpos[iclus];
379 idclus =index[iclus];
380 recL=crecL[iclus]+fDx*0.5;
381 }
382 }
383
384 AliTOFcluster *c=fClusters[idclus];
385 c->Use();
386
387 // Track length correction for matching Step 2
388
389 if(mLastStep){
390 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
391 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
392 +trackPos[1][70]*trackPos[1][70]
393 +trackPos[2][70]*trackPos[2][70]);
394 Float_t dlt=rc-rt;
395 recL=trackPos[3][70]+dlt;
396 }
397
398 if (
399 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
400 ||
401 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
402 ||
403 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
404 ) {
405 fngoodmatch++;
406 }
407 else{
408 fnbadmatch++;
409 }
410
411 delete trackTOFin;
412
43f77f2d 413 //Double_t tof=50*c->GetTDC()+32; // in ps
414 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+32; // in ps
74ea065c 415 t->SetTOFsignal(tof);
416 t->SetTOFcluster(c->GetIndex());
417 Double_t time[10]; t->GetIntegratedTimes(time);
418 Double_t mom=t->GetP();
304864ab 419 for(Int_t j=0;j<=AliPID::kSPECIES;j++){
420 Double_t mass=AliPID::ParticleMass(j);
74ea065c 421 time[j]+=(recL-trackPos[3][0])/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
422 }
423
424 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
425 trackTOFout->PropagateTo(xpos);
426 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
427 t->SetIntegratedLength(recL);
428 t->SetIntegratedTimes(time);
429
430 delete trackTOFout;
431 }
7bf28302 432 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
433 for (Int_t ii=0;ii<6;ii++) delete [] clind[ii];
74ea065c 434}
435//_________________________________________________________________________
436Int_t AliTOFtracker::LoadClusters(TTree *dTree) {
437 //--------------------------------------------------------------------
438 //This function loads the TOF clusters
439 //--------------------------------------------------------------------
440
441 TBranch *branch=dTree->GetBranch("TOF");
442 if (!branch) {
d076c8d5 443 AliError("can't get the branch with the TOF digits !");
74ea065c 444 return 1;
445 }
446
447 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
448 branch->SetAddress(&digits);
449
450 dTree->GetEvent(0);
451 Int_t nd=digits->GetEntriesFast();
d076c8d5 452 AliInfo(Form("number of digits: %d",nd));
74ea065c 453
454 for (Int_t i=0; i<nd; i++) {
455 AliTOFdigit *d=(AliTOFdigit*)digits->UncheckedAt(i);
456 Int_t dig[5]; Float_t g[3];
457 dig[0]=d->GetSector();
458 dig[1]=d->GetPlate();
459 dig[2]=d->GetStrip();
460 dig[3]=d->GetPadz();
461 dig[4]=d->GetPadx();
462
463 fGeom->GetPos(dig,g);
464
465 Double_t h[5];
466 h[0]=TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
467 h[1]=TMath::ATan2(g[1],g[0]); h[2]=g[2];
468 h[3]=d->GetTdc(); h[4]=d->GetAdc();
469
470 AliTOFcluster *cl=new AliTOFcluster(h,d->GetTracks(),dig,i);
471 InsertCluster(cl);
472 }
473
474 return 0;
475}
476//_________________________________________________________________________
477void AliTOFtracker::UnloadClusters() {
478 //--------------------------------------------------------------------
479 //This function unloads TOF clusters
480 //--------------------------------------------------------------------
481 for (Int_t i=0; i<fN; i++) delete fClusters[i];
482 fN=0;
483}
484
485//_________________________________________________________________________
486Int_t AliTOFtracker::InsertCluster(AliTOFcluster *c) {
487 //--------------------------------------------------------------------
488 //This function adds a cluster to the array of clusters sorted in Z
489 //--------------------------------------------------------------------
490 if (fN==kMaxCluster) {
d076c8d5 491 AliError("Too many clusters !");
74ea065c 492 return 1;
493 }
494
495 if (fN==0) {fClusters[fN++]=c; return 0;}
496 Int_t i=FindClusterIndex(c->GetZ());
497 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTOFcluster*));
498 fClusters[i]=c; fN++;
499
500 return 0;
501}
502
503//_________________________________________________________________________
504Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
505 //--------------------------------------------------------------------
506 // This function returns the index of the nearest cluster
507 //--------------------------------------------------------------------
508 if (fN==0) return 0;
509 if (z <= fClusters[0]->GetZ()) return 0;
510 if (z > fClusters[fN-1]->GetZ()) return fN;
511 Int_t b=0, e=fN-1, m=(b+e)/2;
512 for (; b<e; m=(b+e)/2) {
513 if (z > fClusters[m]->GetZ()) b=m+1;
514 else e=m;
515 }
516 return m;
517}
518