1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
15 // AliTOFtracker Class
16 // Task: Perform association of the ESD tracks to TOF Clusters
17 // and Update ESD track with associated TOF Cluster parameters
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 //--------------------------------------------------------------------
26 #include "AliTOFtracker.h"
27 #include "AliTOFtrack.h"
28 #include "TClonesArray.h"
30 #include "AliTOFdigit.h"
31 #include "AliTOFGeometry.h"
33 #include "AliModule.h"
35 ClassImp(AliTOFtracker)
37 //_____________________________________________________________________________
38 AliTOFtracker::AliTOFtracker(AliTOFGeometry * geom, Double_t parPID[2]) {
39 //AliTOFtracker main Ctor
49 fTOFpid = new AliTOFpidESD(parPID);
53 fDy=AliTOFGeometry::XPad();
54 fDz=AliTOFGeometry::ZPad();
59 Init(); // temporary solution to know about Holes/no Holes
61 //_____________________________________________________________________________
62 AliTOFtracker::AliTOFtracker(const AliTOFtracker &t):AliTracker() {
63 //AliTOFtracker copy Ctor
67 fNseedsTOF=t.fNseedsTOF;
68 fngoodmatch=t.fngoodmatch;
69 fnbadmatch=t.fnbadmatch;
70 fnunmatch=t.fnunmatch;
75 fTOFHeigth=t.fTOFHeigth;
84 //_____________________________________________________________________________
85 void AliTOFtracker::Init() {
87 // temporary solution to know about Holes/no Holes, will be implemented as
88 // an AliTOFGeometry getter
90 AliModule* frame=gAlice->GetModule("FRAME");
93 AliError("Could Not load FRAME! Assume Frame with Holes");
96 if(frame->IsVersion()==1) {fHoles=false;}
100 //_____________________________________________________________________________
101 Int_t AliTOFtracker::PropagateBack(AliESD* event) {
103 // Gets seeds from ESD event and Match with TOF Clusters
107 //Initialise some counters
116 Int_t ntrk=event->GetNumberOfTracks();
118 fSeeds= new TClonesArray("AliESDtrack");
119 TClonesArray &aESDTrack = *fSeeds;
122 //Load ESD tracks into a local Array of ESD Seeds
124 for (Int_t i=0; i<fNseeds; i++) {
125 AliESDtrack *t=event->GetTrack(i);
126 new(aESDTrack[i]) AliESDtrack(*t);
129 //Prepare ESD tracks candidates for TOF Matching
132 //First Step with Strict Matching Criterion
135 //Second Step with Looser Matching Criterion
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));
142 //Update the matched ESD tracks
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);
158 fTOFpid->MakePID(event);
173 //_________________________________________________________________________
174 void AliTOFtracker::CollectESD() {
175 //prepare the set of ESD tracks to be matched to clusters in TOF
177 fTracks= new TClonesArray("AliTOFtrack");
178 TClonesArray &aTOFTrack = *fTracks;
179 for (Int_t i=0; i<fNseeds; i++) {
181 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
182 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
184 // TRD good tracks, already propagated at 371 cm
186 AliTOFtrack *track = new AliTOFtrack(*t); // New
187 Double_t x = track->GetX(); //New
189 if (((t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
190 ( x >= AliTOFGeometry::RinTOF()) ){
191 track->SetSeedIndex(i);
192 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
193 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
198 // Propagate the rest of TPCbp
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);
212 // Sort according uncertainties on track position
216 //_________________________________________________________________________
217 void AliTOFtracker::MatchTracks( Bool_t mLastStep){
219 //Match ESD tracks to clusters in TOF
221 Int_t nSteps=(Int_t)(fTOFHeigth/0.1);
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];
227 for (Int_t ii=0;ii<6;ii++) clind[ii] = new Int_t[fN];
229 for (Int_t i=0; i<fNseedsTOF; i++) {
231 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(i);
232 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
233 if(t->GetTOFsignal()>0. ) continue;
234 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
240 Float_t cxpos[10000];
241 Float_t crecL[10000];
243 // Determine a window around the track
246 trackTOFin->GetExternalParameters(x,par);
248 trackTOFin->GetExternalCovariance(cov);
249 Float_t scalefact=3.;
252 ((5*TMath::Sqrt(cov[0]) + 0.5*fDy + 2.5*TMath::Abs(par[2]))/fR);
255 (5*TMath::Sqrt(cov[2]) + 0.5*fDz + 2.5*TMath::Abs(par[3]));
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();
264 // find the clusters in the window of the track
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;
271 Double_t dph=TMath::Abs(c->GetPhi()-phi);
272 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
273 if (TMath::Abs(dph)>dphi) continue;
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);
284 //start fine propagation
286 Int_t nStepsDone = 0;
287 for( Int_t istep=0; istep<nSteps; istep++){
289 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
290 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
293 Double_t ysect=trackTOFin->GetYat(xs,skip);
296 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
299 } else if (ysect <-ymax) {
300 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
305 if(!trackTOFin->PropagateTo(xs)) {
311 // store the running point (Globalrf) - fine propagation
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();
323 for (Int_t istep=0; istep<nStepsDone; istep++) {
325 Bool_t isInside =kFALSE;
326 Float_t ctrackPos[3];
328 ctrackPos[0]= trackPos[0][istep];
329 ctrackPos[1]= trackPos[1][istep];
330 ctrackPos[2]= trackPos[2][istep];
332 //now see whether the track matches any of the TOF clusters
334 for (Int_t i=0; i<nc; i++){
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));
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
353 } //end for on the clusters
357 } //end for on the steps
369 // now choose the cluster to be matched with the track.
374 Float_t mindist=1000.;
375 for (Int_t iclus= 0; iclus<nfound;iclus++){
376 if (dist[iclus]< mindist){
377 mindist = dist[iclus];
379 idclus =index[iclus];
380 recL=crecL[iclus]+fDx*0.5;
384 AliTOFcluster *c=fClusters[idclus];
387 // Track length correction for matching Step 2
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]);
395 recL=trackPos[3][70]+dlt;
399 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
401 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
403 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
413 //Double_t tof=50*c->GetTDC()+32; // in ps
414 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+32; // in ps
415 t->SetTOFsignal(tof);
416 t->SetTOFcluster(c->GetIndex());
417 Double_t time[10]; t->GetIntegratedTimes(time);
418 Double_t mom=t->GetP();
419 for(Int_t j=0;j<=AliPID::kSPECIES;j++){
420 Double_t mass=AliPID::ParticleMass(j);
421 time[j]+=(recL-trackPos[3][0])/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
424 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
425 trackTOFout->PropagateTo(xpos);
426 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
427 t->SetIntegratedLength(recL);
428 t->SetIntegratedTimes(time);
432 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
433 for (Int_t ii=0;ii<6;ii++) delete [] clind[ii];
435 //_________________________________________________________________________
436 Int_t AliTOFtracker::LoadClusters(TTree *dTree) {
437 //--------------------------------------------------------------------
438 //This function loads the TOF clusters
439 //--------------------------------------------------------------------
441 TBranch *branch=dTree->GetBranch("TOF");
443 AliError("can't get the branch with the TOF digits !");
447 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
448 branch->SetAddress(&digits);
451 Int_t nd=digits->GetEntriesFast();
452 AliInfo(Form("number of digits: %d",nd));
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();
463 fGeom->GetPos(dig,g);
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();
470 AliTOFcluster *cl=new AliTOFcluster(h,d->GetTracks(),dig,i);
476 //_________________________________________________________________________
477 void AliTOFtracker::UnloadClusters() {
478 //--------------------------------------------------------------------
479 //This function unloads TOF clusters
480 //--------------------------------------------------------------------
481 for (Int_t i=0; i<fN; i++) delete fClusters[i];
485 //_________________________________________________________________________
486 Int_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) {
491 AliError("Too many clusters !");
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++;
503 //_________________________________________________________________________
504 Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
505 //--------------------------------------------------------------------
506 // This function returns the index of the nearest cluster
507 //--------------------------------------------------------------------
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;