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 //--------------------------------------------------------------------
27 #include "TClonesArray.h"
31 #include "AliModule.h"
33 //#include "AliTOFdigit.h"
34 #include "AliTOFcluster.h"
35 #include "AliTOFtrack.h"
36 #include "AliTOFGeometry.h"
37 #include "AliTOFtracker.h"
39 ClassImp(AliTOFtracker)
41 //_____________________________________________________________________________
42 AliTOFtracker::AliTOFtracker(AliTOFGeometry * geom, Double_t parPID[2]) {
43 //AliTOFtracker main Ctor
53 fTOFpid = new AliTOFpidESD(parPID);
57 fDy=AliTOFGeometry::XPad();
58 fDz=AliTOFGeometry::ZPad();
63 Init(); // temporary solution to know about Holes/no Holes
65 //_____________________________________________________________________________
66 AliTOFtracker::AliTOFtracker(const AliTOFtracker &t):AliTracker() {
67 //AliTOFtracker copy Ctor
71 fNseedsTOF=t.fNseedsTOF;
72 fngoodmatch=t.fngoodmatch;
73 fnbadmatch=t.fnbadmatch;
74 fnunmatch=t.fnunmatch;
79 fTOFHeigth=t.fTOFHeigth;
88 //_____________________________________________________________________________
89 void AliTOFtracker::Init() {
91 // temporary solution to know about Holes/no Holes, will be implemented as
92 // an AliTOFGeometry getter
94 AliModule* frame=gAlice->GetModule("FRAME");
97 AliError("Could Not load FRAME! Assume Frame with Holes");
100 if(frame->IsVersion()==1) {fHoles=false;}
104 //_____________________________________________________________________________
105 Int_t AliTOFtracker::PropagateBack(AliESD* event) {
107 // Gets seeds from ESD event and Match with TOF Clusters
111 //Initialise some counters
120 Int_t ntrk=event->GetNumberOfTracks();
122 fSeeds= new TClonesArray("AliESDtrack",ntrk);
123 TClonesArray &aESDTrack = *fSeeds;
126 //Load ESD tracks into a local Array of ESD Seeds
128 for (Int_t i=0; i<fNseeds; i++) {
129 AliESDtrack *t=event->GetTrack(i);
130 new(aESDTrack[i]) AliESDtrack(*t);
133 //Prepare ESD tracks candidates for TOF Matching
136 //First Step with Strict Matching Criterion
139 for (Int_t ijk=0; ijk<fN; ijk++) {
140 AliInfo(Form("%4i %4i %f %f %f %f %f %2i %1i %2i %1i %2i",ijk, fClusters[ijk]->GetIndex(),fClusters[ijk]->GetZ(),fClusters[ijk]->GetR(),fClusters[ijk]->GetPhi(), fClusters[ijk]->GetTDC(),fClusters[ijk]->GetADC(),fClusters[ijk]->GetDetInd(0),fClusters[ijk]->GetDetInd(1),fClusters[ijk]->GetDetInd(2),fClusters[ijk]->GetDetInd(3),fClusters[ijk]->GetDetInd(4)));
144 //Second Step with Looser Matching Criterion
147 AliInfo(Form("Number of matched tracks: %d",fnmatch));
148 AliInfo(Form("Number of good matched tracks: %d",fngoodmatch));
149 AliInfo(Form("Number of bad matched tracks: %d",fnbadmatch));
151 //Update the matched ESD tracks
153 for (Int_t i=0; i<ntrk; i++) {
154 AliESDtrack *t=event->GetTrack(i);
155 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
156 if(seed->GetTOFsignal()>0){
157 t->SetTOFsignal(seed->GetTOFsignal());
158 t->SetTOFcluster(seed->GetTOFcluster());
159 AliTOFtrack *track = new AliTOFtrack(*seed);
160 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
167 fTOFpid->MakePID(event);
182 //_________________________________________________________________________
183 void AliTOFtracker::CollectESD() {
184 //prepare the set of ESD tracks to be matched to clusters in TOF
186 fTracks= new TClonesArray("AliTOFtrack");
187 TClonesArray &aTOFTrack = *fTracks;
188 for (Int_t i=0; i<fNseeds; i++) {
190 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
191 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
193 // TRD good tracks, already propagated at 371 cm
195 AliTOFtrack *track = new AliTOFtrack(*t); // New
196 Double_t x = track->GetX(); //New
198 if (((t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
199 ( x >= AliTOFGeometry::RinTOF()) ){
200 track->SetSeedIndex(i);
201 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
202 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
207 // Propagate the rest of TPCbp
210 if(track->PropagateToInnerTOF(fHoles)){ // temporary solution
211 // if(track->PropagateToInnerTOF(fGeom->GetHoles())){
212 track->SetSeedIndex(i);
213 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
214 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
221 AliInfo(Form("Number of TOF seedds %i",fNseedsTOF));
223 // Sort according uncertainties on track position
227 //_________________________________________________________________________
228 void AliTOFtracker::MatchTracks( Bool_t mLastStep){
230 //Match ESD tracks to clusters in TOF
232 Int_t nSteps=(Int_t)(fTOFHeigth/0.1);
234 //PH Arrays (moved outside of the loop)
235 Float_t * trackPos[4];
236 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
238 for (Int_t ii=0;ii<6;ii++) clind[ii] = new Int_t[fN];
240 for (Int_t i=0; i<fNseedsTOF; i++) {
242 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(i);
243 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
244 if(t->GetTOFsignal()>0. ) continue;
245 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
251 Float_t cxpos[10000];
252 Float_t crecL[10000];
254 // Determine a window around the track
257 trackTOFin->GetExternalParameters(x,par);
259 trackTOFin->GetExternalCovariance(cov);
260 Float_t scalefact=3.;
263 ((5*TMath::Sqrt(cov[0]) + 0.5*fDy + 2.5*TMath::Abs(par[2]))/fR);
266 (5*TMath::Sqrt(cov[2]) + 0.5*fDz + 2.5*TMath::Abs(par[3]));
268 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
269 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
270 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
275 // find the clusters in the window of the track
277 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
279 AliTOFcluster *c=fClusters[k];
280 if (c->GetZ() > z+dz) break;
281 if (c->IsUsed()) continue;
283 //AliInfo(Form(" fClusters[k]->GetZ() (%f) z-dz (%f) %4i ", fClusters[k]->GetZ(), z-dz, k));
285 Double_t dph=TMath::Abs(c->GetPhi()-phi);
286 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
287 if (TMath::Abs(dph)>dphi) continue;
289 clind[0][nc] = c->GetDetInd(0);
290 clind[1][nc] = c->GetDetInd(1);
291 clind[2][nc] = c->GetDetInd(2);
292 clind[3][nc] = c->GetDetInd(3);
293 clind[4][nc] = c->GetDetInd(4);
298 //if (nc) AliInfo(Form("seed for TOF %4i and number of clusters in the track window %4i (cluster index %4i) %4i",i,nc, clind[5][0], fN));
300 //start fine propagation
302 Int_t nStepsDone = 0;
303 for( Int_t istep=0; istep<nSteps; istep++){
305 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
306 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
309 Double_t ysect=trackTOFin->GetYat(xs,skip);
312 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
315 } else if (ysect <-ymax) {
316 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
321 if(!trackTOFin->PropagateTo(xs)) {
327 // store the running point (Globalrf) - fine propagation
330 trackTOFin->GetGlobalXYZ(x,y,z);
331 trackPos[0][istep]= (Float_t) x;
332 trackPos[1][istep]= (Float_t) y;
333 trackPos[2][istep]= (Float_t) z;
334 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
339 for (Int_t istep=0; istep<nStepsDone; istep++) {
341 Bool_t isInside =kFALSE;
342 Float_t ctrackPos[3];
344 ctrackPos[0]= trackPos[0][istep];
345 ctrackPos[1]= trackPos[1][istep];
346 ctrackPos[2]= trackPos[2][istep];
348 //now see whether the track matches any of the TOF clusters
350 for (Int_t i=0; i<nc; i++){
352 cind[0]= clind[0][i];
353 cind[1]= clind[1][i];
354 cind[2]= clind[2][i];
355 cind[3]= clind[3][i];
356 cind[4]= clind[4][i];
357 Bool_t accept = kFALSE;
358 if( mLastStep)accept = (fGeom->DistanceToPad(cind,ctrackPos)<fdCut);
359 if(!mLastStep)accept = (fGeom->IsInsideThePad(cind,ctrackPos));
361 if(!mLastStep)isInside=kTRUE;
362 dist[nfound]=fGeom->DistanceToPad(cind,ctrackPos);
363 crecL[nfound]=trackPos[3][istep];
364 index[nfound]=clind[5][i]; // store cluster id
365 cxpos[nfound]=AliTOFGeometry::RinTOF()+istep*0.1; //store prop.radius
369 } //end for on the clusters
373 } //end for on the steps
385 // now choose the cluster to be matched with the track.
390 Float_t mindist=1000.;
391 for (Int_t iclus= 0; iclus<nfound;iclus++){
392 if (dist[iclus]< mindist){
393 mindist = dist[iclus];
395 idclus =index[iclus];
396 recL=crecL[iclus]+fDx*0.5;
400 AliTOFcluster *c=fClusters[idclus];
401 c->Use(); //AliInfo(Form("I am usig the cluster"));
403 // Track length correction for matching Step 2
406 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
407 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
408 +trackPos[1][70]*trackPos[1][70]
409 +trackPos[2][70]*trackPos[2][70]);
411 recL=trackPos[3][70]+dlt;
415 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
417 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
419 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
429 //Double_t tof=50*c->GetTDC()+32; // in ps
430 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+32; // in ps
431 t->SetTOFsignal(tof);
432 t->SetTOFcluster(c->GetIndex());
433 Double_t time[10]; t->GetIntegratedTimes(time);
434 Double_t mom=t->GetP();
435 for(Int_t j=0;j<=AliPID::kSPECIES;j++){
436 Double_t mass=AliPID::ParticleMass(j);
437 time[j]+=(recL-trackPos[3][0])/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
440 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
441 trackTOFout->PropagateTo(xpos);
442 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
443 t->SetIntegratedLength(recL);
444 t->SetIntegratedTimes(time);
448 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
449 for (Int_t ii=0;ii<6;ii++) delete [] clind[ii];
451 //_________________________________________________________________________
452 Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
453 //--------------------------------------------------------------------
454 //This function loads the TOF clusters
455 //--------------------------------------------------------------------
457 TBranch *branch=cTree->GetBranch("TOF");
459 AliError("can't get the branch with the TOF clusters !");
463 TClonesArray dummy("AliTOFcluster",10000), *clusters=&dummy;
464 branch->SetAddress(&clusters);
467 Int_t nc=clusters->GetEntriesFast();
468 AliInfo(Form("Number of clusters: %d",nc));
470 for (Int_t i=0; i<nc; i++) {
471 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
473 for (Int_t jj=0; jj<5; jj++) dig[jj]=c->GetDetInd(jj);
483 for (Int_t jj=0; jj<3; jj++) indexDig[jj] = c->GetLabel(jj);
485 AliTOFcluster *cl=new AliTOFcluster(h,c->GetTracks(),dig,i);
488 // fClusters[i]=c; fN++;
489 fClusters[i]=new AliTOFcluster(*c); fN++;
491 //AliInfo(Form("%4i %4i %f %f %f %f %f %2i %1i %2i %1i %2i",i, fClusters[i]->GetIndex(),fClusters[i]->GetZ(),fClusters[i]->GetR(),fClusters[i]->GetPhi(), fClusters[i]->GetTDC(),fClusters[i]->GetADC(),fClusters[i]->GetDetInd(0),fClusters[i]->GetDetInd(1),fClusters[i]->GetDetInd(2),fClusters[i]->GetDetInd(3),fClusters[i]->GetDetInd(4)));
492 //AliInfo(Form("%i %f",i, fClusters[i]->GetZ()));
495 //AliInfo(Form("Number of clusters: %d",fN));
499 //_________________________________________________________________________
500 void AliTOFtracker::UnloadClusters() {
501 //--------------------------------------------------------------------
502 //This function unloads TOF clusters
503 //--------------------------------------------------------------------
504 for (Int_t i=0; i<fN; i++) {
511 //_________________________________________________________________________
512 Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
513 //--------------------------------------------------------------------
514 // This function returns the index of the nearest cluster
515 //--------------------------------------------------------------------
517 if (z <= fClusters[0]->GetZ()) return 0;
518 if (z > fClusters[fN-1]->GetZ()) return fN;
519 Int_t b=0, e=fN-1, m=(b+e)/2;
520 for (; b<e; m=(b+e)/2) {
521 if (z > fClusters[m]->GetZ()) b=m+1;