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 **************************************************************************/
16 //--------------------------------------------------------------------//
18 // AliTOFtracker Class //
19 // Task: Perform association of the ESD tracks to TOF Clusters //
20 // and Update ESD track with associated TOF Cluster parameters //
22 // -- Authors : S. Arcelli, C. Zampolli (Bologna University and INFN) //
23 // -- Contacts: Annalisa.De.Caro@cern.ch //
24 // -- : Chiara.Zampolli@bo.infn.it //
25 // -- : Silvia.Arcelli@bo.infn.it //
27 //--------------------------------------------------------------------//
31 #include "TClonesArray.h"
32 #include "TGeoManager.h"
35 #include "AliAlignObj.h"
36 #include "AliESDtrack.h"
39 #include "AliTrackPointArray.h"
41 #include "AliTOFcalib.h"
42 #include "AliTOFcluster.h"
43 #include "AliTOFGeometry.h"
44 #include "AliTOFtracker.h"
45 #include "AliTOFtrack.h"
47 extern TGeoManager *gGeoManager;
49 ClassImp(AliTOFtracker)
51 //_____________________________________________________________________________
52 AliTOFtracker::AliTOFtracker(AliTOFGeometry * geom, Double_t parPID[2]) {
53 //AliTOFtracker main Ctor
63 fTOFpid = new AliTOFpidESD(parPID);
67 fDy=AliTOFGeometry::XPad();
68 fDz=AliTOFGeometry::ZPad();
75 fHoles = fGeom->GetHoles();
77 //_____________________________________________________________________________
78 AliTOFtracker::AliTOFtracker(const AliTOFtracker &t):AliTracker() {
79 //AliTOFtracker copy Ctor
83 fNseedsTOF=t.fNseedsTOF;
84 fngoodmatch=t.fngoodmatch;
85 fnbadmatch=t.fnbadmatch;
86 fnunmatch=t.fnunmatch;
91 fTOFHeigth=t.fTOFHeigth;
103 //_____________________________________________________________________________
104 AliTOFtracker& AliTOFtracker::operator=(const AliTOFtracker &t)
106 //AliTOFtracker assignment operator
108 this->fHoles=t.fHoles;
109 this->fNseeds=t.fNseeds;
110 this->fNseedsTOF=t.fNseedsTOF;
111 this->fngoodmatch=t.fngoodmatch;
112 this->fnbadmatch=t.fnbadmatch;
113 this->fnunmatch=t.fnunmatch;
114 this->fnmatch=t.fnmatch;
115 this->fGeom = t.fGeom;
116 this->fTOFpid = t.fTOFpid;
118 this->fTOFHeigth=t.fTOFHeigth;
123 this->fDzMax=t.fDzMax;
124 this->fDyMax=t.fDyMax;
125 this->fSeeds=t.fSeeds;
126 this->fTracks=t.fTracks;
132 //_____________________________________________________________________________
133 Int_t AliTOFtracker::PropagateBack(AliESD* event) {
135 // Gets seeds from ESD event and Match with TOF Clusters
139 //Initialise some counters
148 Int_t ntrk=event->GetNumberOfTracks();
150 fSeeds= new TClonesArray("AliESDtrack",ntrk);
151 TClonesArray &aESDTrack = *fSeeds;
154 //Load ESD tracks into a local Array of ESD Seeds
156 for (Int_t i=0; i<fNseeds; i++) {
157 AliESDtrack *t=event->GetTrack(i);
158 new(aESDTrack[i]) AliESDtrack(*t);
161 //Prepare ESD tracks candidates for TOF Matching
164 //First Step with Strict Matching Criterion
167 for (Int_t ijk=0; ijk<fN; ijk++) {
168 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)));
172 //Second Step with Looser Matching Criterion
175 AliInfo(Form("Number of matched tracks: %d",fnmatch));
176 AliInfo(Form("Number of good matched tracks: %d",fngoodmatch));
177 AliInfo(Form("Number of bad matched tracks: %d",fnbadmatch));
179 //Update the matched ESD tracks
181 for (Int_t i=0; i<ntrk; i++) {
182 AliESDtrack *t=event->GetTrack(i);
183 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
184 if(seed->GetTOFsignal()>0){
185 t->SetTOFsignal(seed->GetTOFsignal());
186 t->SetTOFcluster(seed->GetTOFcluster());
187 t->SetTOFsignalToT(seed->GetTOFsignalToT());
188 t->SetTOFCalChannel(seed->GetTOFCalChannel());
189 AliTOFtrack *track = new AliTOFtrack(*seed);
190 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
197 fTOFpid->MakePID(event);
212 //_________________________________________________________________________
213 void AliTOFtracker::CollectESD() {
214 //prepare the set of ESD tracks to be matched to clusters in TOF
216 fTracks= new TClonesArray("AliTOFtrack");
217 TClonesArray &aTOFTrack = *fTracks;
218 for (Int_t i=0; i<fNseeds; i++) {
220 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
221 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
223 // TRD good tracks, already propagated at 371 cm
225 AliTOFtrack *track = new AliTOFtrack(*t); // New
226 Double_t x = track->GetX(); //New
228 if (((t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
229 ( x >= fGeom->RinTOF()) ){
230 track->SetSeedIndex(i);
231 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
232 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
237 // Propagate the rest of TPCbp
240 if(track->PropagateToInnerTOF(fHoles)){ // temporary solution
241 // if(track->PropagateToInnerTOF(fGeom->GetHoles())){
242 track->SetSeedIndex(i);
243 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
244 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
251 AliInfo(Form("Number of TOF seedds %i",fNseedsTOF));
253 // Sort according uncertainties on track position
257 //_________________________________________________________________________
258 void AliTOFtracker::MatchTracks( Bool_t mLastStep){
260 //Match ESD tracks to clusters in TOF
263 Int_t nSteps=(Int_t)(fTOFHeigth/0.1);
265 AliTOFcalib *calib = new AliTOFcalib(fGeom);
266 //PH Arrays (moved outside of the loop)
267 Float_t * trackPos[4];
268 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
270 for (Int_t ii=0;ii<6;ii++) clind[ii] = new Int_t[fN];
272 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
274 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
275 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
276 if(t->GetTOFsignal()>0. ) continue;
277 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
283 Float_t cxpos[10000];
284 Float_t crecL[10000];
285 TGeoHMatrix global[1000];
287 // Determine a window around the track
290 trackTOFin->GetExternalParameters(x,par);
292 trackTOFin->GetExternalCovariance(cov);
293 Float_t scalefact=3.;
296 ((5*TMath::Sqrt(cov[0]) + 0.5*fDy + 2.5*TMath::Abs(par[2]))/fR);
299 (5*TMath::Sqrt(cov[2]) + 0.5*fDz + 2.5*TMath::Abs(par[3]));
301 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
302 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
303 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
306 //upper limit on window's size.
308 if(dz> fDzMax) dz=fDzMax;
309 if(dphi*fR>fDyMax) dphi=fDyMax/fR;
314 // find the clusters in the window of the track
316 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
318 AliTOFcluster *c=fClusters[k];
319 if (c->GetZ() > z+dz) break;
320 if (c->IsUsed()) continue;
322 //AliInfo(Form(" fClusters[k]->GetZ() (%f) z-dz (%f) %4i ", fClusters[k]->GetZ(), z-dz, k));
324 Double_t dph=TMath::Abs(c->GetPhi()-phi);
325 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
326 if (TMath::Abs(dph)>dphi) continue;
328 clind[0][nc] = c->GetDetInd(0);
329 clind[1][nc] = c->GetDetInd(1);
330 clind[2][nc] = c->GetDetInd(2);
331 clind[3][nc] = c->GetDetInd(3);
332 clind[4][nc] = c->GetDetInd(4);
341 fGeom->GetVolumePath(ind,path);
342 gGeoManager->cd(path);
343 global[nc] = *gGeoManager->GetCurrentMatrix();
347 //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));
349 //start fine propagation
351 Int_t nStepsDone = 0;
352 for( Int_t istep=0; istep<nSteps; istep++){
354 Float_t xs=fGeom->RinTOF()+istep*0.1;
355 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
358 Double_t ysect=trackTOFin->GetYat(xs,skip);
361 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
364 } else if (ysect <-ymax) {
365 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
370 if(!trackTOFin->PropagateTo(xs)) {
376 // store the running point (Globalrf) - fine propagation
379 trackTOFin->GetGlobalXYZ(x,y,z);
380 trackPos[0][istep]= (Float_t) x;
381 trackPos[1][istep]= (Float_t) y;
382 trackPos[2][istep]= (Float_t) z;
383 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
388 for (Int_t istep=0; istep<nStepsDone; istep++) {
390 Bool_t isInside =kFALSE;
391 Float_t ctrackPos[3];
393 ctrackPos[0]= trackPos[0][istep];
394 ctrackPos[1]= trackPos[1][istep];
395 ctrackPos[2]= trackPos[2][istep];
397 //now see whether the track matches any of the TOF clusters
399 for (Int_t i=0; i<nc; i++){
401 cind[0]= clind[0][i];
402 cind[1]= clind[1][i];
403 cind[2]= clind[2][i];
404 cind[3]= clind[3][i];
405 cind[4]= clind[4][i];
406 Bool_t accept = kFALSE;
407 if( mLastStep)accept = (fGeom->DistanceToPad(cind,global[i],ctrackPos)<fdCut);
408 if(!mLastStep)accept = (fGeom->IsInsideThePad(cind,global[i],ctrackPos));
410 if(!mLastStep)isInside=kTRUE;
411 dist[nfound]=fGeom->DistanceToPad(cind,global[i],ctrackPos);
412 crecL[nfound]=trackPos[3][istep];
413 index[nfound]=clind[5][i]; // store cluster id
414 cxpos[nfound]=fGeom->RinTOF()+istep*0.1; //store prop.radius
418 } //end for on the clusters
422 } //end for on the steps
434 // now choose the cluster to be matched with the track.
439 Float_t mindist=1000.;
440 for (Int_t iclus= 0; iclus<nfound;iclus++){
441 if (dist[iclus]< mindist){
442 mindist = dist[iclus];
444 idclus =index[iclus];
445 recL=crecL[iclus]+fDx*0.5;
449 AliTOFcluster *c=fClusters[idclus];
450 c->Use(); //AliInfo(Form("I am using the cluster"));
452 // Track length correction for matching Step 2
455 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
456 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
457 +trackPos[1][70]*trackPos[1][70]
458 +trackPos[2][70]*trackPos[2][70]);
460 recL=trackPos[3][70]+dlt;
464 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
466 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
468 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
472 //AliInfo(Form(" track label good %5i",trackTOFin->GetLabel()));
478 //AliInfo(Form(" track label bad %5i",trackTOFin->GetLabel()));
484 // Store quantities to be used in the TOF Calibration
485 Float_t tToT=c->GetToT(); // in ps
486 t->SetTOFsignalToT(tToT);
488 ind[0]=c->GetDetInd(0);
489 ind[1]=c->GetDetInd(1);
490 ind[2]=c->GetDetInd(2);
491 ind[3]=c->GetDetInd(3);
492 ind[4]=c->GetDetInd(4);
493 Int_t calindex = calib->GetIndex(ind);
494 t->SetTOFCalChannel(calindex);
496 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+32; // in ps
497 t->SetTOFsignal(tof);
498 //t->SetTOFcluster(c->GetIndex()); // pointing to the digits tree
499 t->SetTOFcluster(idclus); // pointing to the recPoints tree
500 Double_t time[10]; t->GetIntegratedTimes(time);
501 Double_t mom=t->GetP();
502 for(Int_t j=0;j<=AliPID::kSPECIES;j++){
503 Double_t mass=AliPID::ParticleMass(j);
504 time[j]+=(recL-trackPos[3][0])/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
507 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
508 trackTOFout->PropagateTo(xpos);
509 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
510 t->SetIntegratedLength(recL);
511 t->SetIntegratedTimes(time);
515 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
516 for (Int_t ii=0;ii<6;ii++) delete [] clind[ii];
519 //_________________________________________________________________________
520 Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
521 //--------------------------------------------------------------------
522 //This function loads the TOF clusters
523 //--------------------------------------------------------------------
525 TBranch *branch=cTree->GetBranch("TOF");
527 AliError("can't get the branch with the TOF clusters !");
531 TClonesArray dummy("AliTOFcluster",10000), *clusters=&dummy;
532 branch->SetAddress(&clusters);
535 Int_t nc=clusters->GetEntriesFast();
536 AliInfo(Form("Number of clusters: %d",nc));
538 for (Int_t i=0; i<nc; i++) {
539 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
540 fClusters[i]=new AliTOFcluster(*c); fN++;
541 //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)));
542 //AliInfo(Form("%i %f",i, fClusters[i]->GetZ()));
545 //AliInfo(Form("Number of clusters: %d",fN));
549 //_________________________________________________________________________
550 void AliTOFtracker::UnloadClusters() {
551 //--------------------------------------------------------------------
552 //This function unloads TOF clusters
553 //--------------------------------------------------------------------
554 for (Int_t i=0; i<fN; i++) {
561 //_________________________________________________________________________
562 Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
563 //--------------------------------------------------------------------
564 // This function returns the index of the nearest cluster
565 //--------------------------------------------------------------------
567 if (z <= fClusters[0]->GetZ()) return 0;
568 if (z > fClusters[fN-1]->GetZ()) return fN;
569 Int_t b=0, e=fN-1, m=(b+e)/2;
570 for (; b<e; m=(b+e)/2) {
571 if (z > fClusters[m]->GetZ()) b=m+1;
577 //_________________________________________________________________________
578 Bool_t AliTOFtracker::GetTrackPoint(Int_t index, AliTrackPoint& p) const
580 // Get track space point with index i
581 // Coordinates are in the global system
582 AliTOFcluster *cl = fClusters[index];
584 xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
585 xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
587 Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
588 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
589 Float_t tiltangle = fGeom->GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
590 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
591 Float_t sigmay2 = fGeom->XPad()*fGeom->XPad()/12.;
592 Float_t sigmaz2 = fGeom->ZPad()*fGeom->ZPad()/12.;
594 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
595 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
596 cov[2] = -cosphi*sinth*costh*sigmaz2;
597 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
598 cov[4] = -sinphi*sinth*costh*sigmaz2;
599 cov[5] = costh*costh*sigmaz2;
600 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
602 // Detector numbering scheme
603 Int_t nSector = fGeom->NSectors();
604 Int_t nPlate = fGeom->NPlates();
605 Int_t nStripA = fGeom->NStripA();
606 Int_t nStripB = fGeom->NStripB();
607 Int_t nStripC = fGeom->NStripC();
609 Int_t isector = cl->GetDetInd(0);
610 if (isector >= nSector)
611 AliError(Form("Wrong sector number in TOF (%d) !",isector));
612 Int_t iplate = cl->GetDetInd(1);
613 if (iplate >= nPlate)
614 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
615 Int_t istrip = cl->GetDetInd(2);
617 Int_t stripOffset = 0;
623 stripOffset = nStripC;
626 stripOffset = nStripC+nStripB;
629 stripOffset = nStripC+nStripB+nStripA;
632 stripOffset = nStripC+nStripB+nStripA+nStripB;
635 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
639 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
642 UShort_t volid = AliAlignObj::LayerToVolUID(AliAlignObj::kTOF,idet);
643 p.SetVolumeID((UShort_t)volid);