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 //--------------------------------------------------------------------
25 #include "AliTOFtracker.h"
26 #include "AliTOFtrack.h"
27 #include "TClonesArray.h"
29 #include "AliTOFdigit.h"
30 #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 Error("Init","Could Not load FRAME! Assume Frame with Holes \n");
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 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);
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);
165 //_________________________________________________________________________
166 void AliTOFtracker::CollectESD() {
167 //prepare the set of ESD tracks to be matched to clusters in TOF
169 fTracks= new TClonesArray("AliTOFtrack");
170 TClonesArray &aTOFTrack = *fTracks;
171 for (Int_t i=0; i<fNseeds; i++) {
173 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
174 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
176 // TRD good tracks, already propagated at 371 cm
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);
189 // Propagate the rest of TPCbp
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);
204 // Sort according uncertainties on track position
208 //_________________________________________________________________________
209 void AliTOFtracker::MatchTracks( Bool_t mLastStep){
211 //Match ESD tracks to clusters in TOF
213 static const Double_t kMasses[]={
214 0.000511, 0.105658, 0.139570, 0.493677, 0.938272, 1.875613
217 Int_t nSteps=(Int_t)(fTOFHeigth/0.1);
219 for (Int_t i=0; i<fNseedsTOF; i++) {
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;
230 Float_t cxpos[10000];
231 Float_t crecL[10000];
232 Float_t trackPos[4][nSteps];
234 // Determine a window around the track
237 trackTOFin->GetExternalParameters(x,par);
239 trackTOFin->GetExternalCovariance(cov);
240 Float_t scalefact=3.;
243 ((5*TMath::Sqrt(cov[0]) + 0.5*fDy + 2.5*TMath::Abs(par[2]))/fR);
246 (5*TMath::Sqrt(cov[2]) + 0.5*fDz + 2.5*TMath::Abs(par[3]));
248 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
249 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
250 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
256 // find the clusters in the window of the track
258 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
259 AliTOFcluster *c=fClusters[k];
260 if (c->GetZ() > z+dz) break;
261 if (c->IsUsed()) continue;
263 Double_t dph=TMath::Abs(c->GetPhi()-phi);
264 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
265 if (fabs(dph)>dphi) continue;
267 clind[0][nc] = c->GetDetInd(0);
268 clind[1][nc] = c->GetDetInd(1);
269 clind[2][nc] = c->GetDetInd(2);
270 clind[3][nc] = c->GetDetInd(3);
271 clind[4][nc] = c->GetDetInd(4);
276 //start fine propagation
278 Int_t nStepsDone = 0;
279 for( Int_t istep=0; istep<nSteps; istep++){
281 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
282 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
285 Double_t ysect=trackTOFin->GetYat(xs,skip);
288 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
291 } else if (ysect <-ymax) {
292 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
297 if(!trackTOFin->PropagateTo(xs)) {
303 // store the running point (Globalrf) - fine propagation
306 trackTOFin->GetGlobalXYZ(x,y,z);
307 trackPos[0][istep]= (Float_t) x;
308 trackPos[1][istep]= (Float_t) y;
309 trackPos[2][istep]= (Float_t) z;
310 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
315 for (Int_t istep=0; istep<nStepsDone; istep++) {
317 Bool_t isInside =kFALSE;
318 Float_t ctrackPos[3];
320 ctrackPos[0]= trackPos[0][istep];
321 ctrackPos[1]= trackPos[1][istep];
322 ctrackPos[2]= trackPos[2][istep];
324 //now see whether the track matches any of the TOF clusters
326 for (Int_t i=0; i<nc; i++){
328 cind[0]= clind[0][i];
329 cind[1]= clind[1][i];
330 cind[2]= clind[2][i];
331 cind[3]= clind[3][i];
332 cind[4]= clind[4][i];
333 Bool_t accept = kFALSE;
334 if( mLastStep)accept = (fGeom->DistanceToPad(cind,ctrackPos)<fdCut);
335 if(!mLastStep)accept = (fGeom->IsInsideThePad(cind,ctrackPos));
337 if(!mLastStep)isInside=kTRUE;
338 dist[nfound]=fGeom->DistanceToPad(cind,ctrackPos);
339 crecL[nfound]=trackPos[3][istep];
340 index[nfound]=clind[5][i]; // store cluster id
341 cxpos[nfound]=AliTOFGeometry::RinTOF()+istep*0.1; //store prop.radius
345 } //end for on the clusters
347 } //end for on the steps
356 // now choose the cluster to be matched with the track.
361 Float_t mindist=1000.;
362 for (Int_t iclus= 0; iclus<nfound;iclus++){
363 if (dist[iclus]< mindist){
364 mindist = dist[iclus];
366 idclus =index[iclus];
367 recL=crecL[iclus]+fDx*0.5;
371 AliTOFcluster *c=fClusters[idclus];
374 // Track length correction for matching Step 2
377 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
378 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
379 +trackPos[1][70]*trackPos[1][70]
380 +trackPos[2][70]*trackPos[2][70]);
382 recL=trackPos[3][70]+dlt;
386 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
388 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
390 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
400 Double_t tof=50*c->GetTDC()+32; // in ps
401 t->SetTOFsignal(tof);
402 t->SetTOFcluster(c->GetIndex());
403 Double_t time[10]; t->GetIntegratedTimes(time);
404 Double_t mom=t->GetP();
405 for(Int_t j=0;j<=5;j++){
406 Double_t mass=kMasses[j];
407 time[j]+=(recL-trackPos[3][0])/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
410 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
411 trackTOFout->PropagateTo(xpos);
412 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
413 t->SetIntegratedLength(recL);
414 t->SetIntegratedTimes(time);
419 //_________________________________________________________________________
420 Int_t AliTOFtracker::LoadClusters(TTree *dTree) {
421 //--------------------------------------------------------------------
422 //This function loads the TOF clusters
423 //--------------------------------------------------------------------
425 TBranch *branch=dTree->GetBranch("TOF");
427 Error("LoadClusters"," can't get the branch with the TOF digits !\n");
431 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
432 branch->SetAddress(&digits);
435 Int_t nd=digits->GetEntriesFast();
436 Info("LoadClusters","number of digits: %d",nd);
438 for (Int_t i=0; i<nd; i++) {
439 AliTOFdigit *d=(AliTOFdigit*)digits->UncheckedAt(i);
440 Int_t dig[5]; Float_t g[3];
441 dig[0]=d->GetSector();
442 dig[1]=d->GetPlate();
443 dig[2]=d->GetStrip();
447 fGeom->GetPos(dig,g);
450 h[0]=TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
451 h[1]=TMath::ATan2(g[1],g[0]); h[2]=g[2];
452 h[3]=d->GetTdc(); h[4]=d->GetAdc();
454 AliTOFcluster *cl=new AliTOFcluster(h,d->GetTracks(),dig,i);
460 //_________________________________________________________________________
461 void AliTOFtracker::UnloadClusters() {
462 //--------------------------------------------------------------------
463 //This function unloads TOF clusters
464 //--------------------------------------------------------------------
465 for (Int_t i=0; i<fN; i++) delete fClusters[i];
469 //_________________________________________________________________________
470 Int_t AliTOFtracker::InsertCluster(AliTOFcluster *c) {
471 //--------------------------------------------------------------------
472 //This function adds a cluster to the array of clusters sorted in Z
473 //--------------------------------------------------------------------
474 if (fN==kMaxCluster) {
475 Error("InsertCluster","Too many clusters !\n");
479 if (fN==0) {fClusters[fN++]=c; return 0;}
480 Int_t i=FindClusterIndex(c->GetZ());
481 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTOFcluster*));
482 fClusters[i]=c; fN++;
487 //_________________________________________________________________________
488 Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
489 //--------------------------------------------------------------------
490 // This function returns the index of the nearest cluster
491 //--------------------------------------------------------------------
493 if (z <= fClusters[0]->GetZ()) return 0;
494 if (z > fClusters[fN-1]->GetZ()) return fN;
495 Int_t b=0, e=fN-1, m=(b+e)/2;
496 for (; b<e; m=(b+e)/2) {
497 if (z > fClusters[m]->GetZ()) b=m+1;