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]):
54 fTOFpid(new AliTOFpidESD(parPID)),
74 //AliTOFtracker main Ctor
77 fDy=AliTOFGeometry::XPad();
78 fDz=AliTOFGeometry::ZPad();
79 fHoles = fGeom->GetHoles();
81 //_____________________________________________________________________________
82 AliTOFtracker::AliTOFtracker(const AliTOFtracker &t):
105 //AliTOFtracker copy Ctor
109 fNseedsTOF=t.fNseedsTOF;
110 fngoodmatch=t.fngoodmatch;
111 fnbadmatch=t.fnbadmatch;
112 fnunmatch=t.fnunmatch;
117 fTOFHeigth=t.fTOFHeigth;
129 //_____________________________________________________________________________
130 AliTOFtracker& AliTOFtracker::operator=(const AliTOFtracker &t)
132 //AliTOFtracker assignment operator
134 this->fHoles=t.fHoles;
135 this->fNseeds=t.fNseeds;
136 this->fNseedsTOF=t.fNseedsTOF;
137 this->fngoodmatch=t.fngoodmatch;
138 this->fnbadmatch=t.fnbadmatch;
139 this->fnunmatch=t.fnunmatch;
140 this->fnmatch=t.fnmatch;
141 this->fGeom = t.fGeom;
142 this->fTOFpid = t.fTOFpid;
144 this->fTOFHeigth=t.fTOFHeigth;
149 this->fDzMax=t.fDzMax;
150 this->fDyMax=t.fDyMax;
151 this->fSeeds=t.fSeeds;
152 this->fTracks=t.fTracks;
158 //_____________________________________________________________________________
159 Int_t AliTOFtracker::PropagateBack(AliESD* event) {
161 // Gets seeds from ESD event and Match with TOF Clusters
165 //Initialise some counters
174 Int_t ntrk=event->GetNumberOfTracks();
176 fSeeds= new TClonesArray("AliESDtrack",ntrk);
177 TClonesArray &aESDTrack = *fSeeds;
180 //Load ESD tracks into a local Array of ESD Seeds
182 for (Int_t i=0; i<fNseeds; i++) {
183 AliESDtrack *t=event->GetTrack(i);
184 new(aESDTrack[i]) AliESDtrack(*t);
187 //Prepare ESD tracks candidates for TOF Matching
190 //First Step with Strict Matching Criterion
193 for (Int_t ijk=0; ijk<fN; ijk++) {
194 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)));
198 //Second Step with Looser Matching Criterion
201 AliInfo(Form("Number of matched tracks: %d",fnmatch));
202 AliInfo(Form("Number of good matched tracks: %d",fngoodmatch));
203 AliInfo(Form("Number of bad matched tracks: %d",fnbadmatch));
205 //Update the matched ESD tracks
207 for (Int_t i=0; i<ntrk; i++) {
208 AliESDtrack *t=event->GetTrack(i);
209 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
210 if(seed->GetTOFsignal()>0){
211 t->SetTOFsignal(seed->GetTOFsignal());
212 t->SetTOFcluster(seed->GetTOFcluster());
213 t->SetTOFsignalToT(seed->GetTOFsignalToT());
214 t->SetTOFCalChannel(seed->GetTOFCalChannel());
215 Int_t tlab[3]; seed->GetTOFLabel(tlab);
216 t->SetTOFLabel(tlab);
217 AliTOFtrack *track = new AliTOFtrack(*seed);
218 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
225 fTOFpid->MakePID(event);
240 //_________________________________________________________________________
241 void AliTOFtracker::CollectESD() {
242 //prepare the set of ESD tracks to be matched to clusters in TOF
244 fTracks= new TClonesArray("AliTOFtrack");
245 TClonesArray &aTOFTrack = *fTracks;
246 for (Int_t i=0; i<fNseeds; i++) {
248 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
249 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
251 // TRD good tracks, already propagated at 371 cm
253 AliTOFtrack *track = new AliTOFtrack(*t); // New
254 Double_t x = track->GetX(); //New
256 if (((t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
257 ( x >= fGeom->RinTOF()) ){
258 track->SetSeedIndex(i);
259 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
260 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
265 // Propagate the rest of TPCbp
268 if(track->PropagateToInnerTOF(fHoles)){ // temporary solution
269 // if(track->PropagateToInnerTOF(fGeom->GetHoles())){
270 track->SetSeedIndex(i);
271 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
272 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
279 AliInfo(Form("Number of TOF seedds %i",fNseedsTOF));
281 // Sort according uncertainties on track position
285 //_________________________________________________________________________
286 void AliTOFtracker::MatchTracks( Bool_t mLastStep){
288 //Match ESD tracks to clusters in TOF
291 Int_t nSteps=(Int_t)(fTOFHeigth/0.1);
293 AliTOFcalib *calib = new AliTOFcalib(fGeom);
294 //PH Arrays (moved outside of the loop)
295 Float_t * trackPos[4];
296 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
298 for (Int_t ii=0;ii<6;ii++) clind[ii] = new Int_t[fN];
300 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
302 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
303 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
304 if(t->GetTOFsignal()>0. ) continue;
305 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
311 Float_t cxpos[10000];
312 Float_t crecL[10000];
313 TGeoHMatrix global[1000];
315 // Determine a window around the track
318 trackTOFin->GetExternalParameters(x,par);
320 trackTOFin->GetExternalCovariance(cov);
321 Float_t scalefact=3.;
324 ((5*TMath::Sqrt(cov[0]) + 0.5*fDy + 2.5*TMath::Abs(par[2]))/fR);
327 (5*TMath::Sqrt(cov[2]) + 0.5*fDz + 2.5*TMath::Abs(par[3]));
329 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
330 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
331 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
334 //upper limit on window's size.
336 if(dz> fDzMax) dz=fDzMax;
337 if(dphi*fR>fDyMax) dphi=fDyMax/fR;
342 // find the clusters in the window of the track
344 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
346 AliTOFcluster *c=fClusters[k];
347 if (c->GetZ() > z+dz) break;
348 if (c->IsUsed()) continue;
349 if (!c->GetStatus()) continue; // skip bad channels as declared in OCDB
351 //AliInfo(Form(" fClusters[k]->GetZ() (%f) z-dz (%f) %4i ", fClusters[k]->GetZ(), z-dz, k));
353 Double_t dph=TMath::Abs(c->GetPhi()-phi);
354 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
355 if (TMath::Abs(dph)>dphi) continue;
357 clind[0][nc] = c->GetDetInd(0);
358 clind[1][nc] = c->GetDetInd(1);
359 clind[2][nc] = c->GetDetInd(2);
360 clind[3][nc] = c->GetDetInd(3);
361 clind[4][nc] = c->GetDetInd(4);
370 fGeom->GetVolumePath(ind,path);
371 gGeoManager->cd(path);
372 global[nc] = *gGeoManager->GetCurrentMatrix();
376 //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));
378 //start fine propagation
380 Int_t nStepsDone = 0;
381 for( Int_t istep=0; istep<nSteps; istep++){
383 Float_t xs=fGeom->RinTOF()+istep*0.1;
384 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
387 Double_t ysect=trackTOFin->GetYat(xs,skip);
390 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
393 } else if (ysect <-ymax) {
394 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
399 if(!trackTOFin->PropagateTo(xs)) {
405 // store the running point (Globalrf) - fine propagation
408 trackTOFin->GetGlobalXYZ(x,y,z);
409 trackPos[0][istep]= (Float_t) x;
410 trackPos[1][istep]= (Float_t) y;
411 trackPos[2][istep]= (Float_t) z;
412 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
417 for (Int_t istep=0; istep<nStepsDone; istep++) {
419 Bool_t isInside =kFALSE;
420 Float_t ctrackPos[3];
422 ctrackPos[0]= trackPos[0][istep];
423 ctrackPos[1]= trackPos[1][istep];
424 ctrackPos[2]= trackPos[2][istep];
426 //now see whether the track matches any of the TOF clusters
428 for (Int_t i=0; i<nc; i++){
430 cind[0]= clind[0][i];
431 cind[1]= clind[1][i];
432 cind[2]= clind[2][i];
433 cind[3]= clind[3][i];
434 cind[4]= clind[4][i];
435 Bool_t accept = kFALSE;
436 if( mLastStep)accept = (fGeom->DistanceToPad(cind,global[i],ctrackPos)<fdCut);
437 if(!mLastStep)accept = (fGeom->IsInsideThePad(cind,global[i],ctrackPos));
439 if(!mLastStep)isInside=kTRUE;
440 dist[nfound]=fGeom->DistanceToPad(cind,global[i],ctrackPos);
441 crecL[nfound]=trackPos[3][istep];
442 index[nfound]=clind[5][i]; // store cluster id
443 cxpos[nfound]=fGeom->RinTOF()+istep*0.1; //store prop.radius
447 } //end for on the clusters
451 } //end for on the steps
463 // now choose the cluster to be matched with the track.
468 Float_t mindist=1000.;
469 for (Int_t iclus= 0; iclus<nfound;iclus++){
470 if (dist[iclus]< mindist){
471 mindist = dist[iclus];
473 idclus =index[iclus];
474 recL=crecL[iclus]+fDx*0.5;
478 AliTOFcluster *c=fClusters[idclus];
479 c->Use(); //AliInfo(Form("I am using the cluster"));
481 // Track length correction for matching Step 2
484 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
485 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
486 +trackPos[1][70]*trackPos[1][70]
487 +trackPos[2][70]*trackPos[2][70]);
489 recL=trackPos[3][70]+dlt;
493 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
495 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
497 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
501 //AliInfo(Form(" track label good %5i",trackTOFin->GetLabel()));
507 //AliInfo(Form(" track label bad %5i",trackTOFin->GetLabel()));
513 // Store quantities to be used in the TOF Calibration
514 Float_t tToT=c->GetToT(); // in ps
515 t->SetTOFsignalToT(tToT);
517 ind[0]=c->GetDetInd(0);
518 ind[1]=c->GetDetInd(1);
519 ind[2]=c->GetDetInd(2);
520 ind[3]=c->GetDetInd(3);
521 ind[4]=c->GetDetInd(4);
522 Int_t calindex = calib->GetIndex(ind);
523 t->SetTOFCalChannel(calindex);
525 // keep track of the track labels in the matched cluster
527 tlab[0]=c->GetLabel(0);
528 tlab[1]=c->GetLabel(1);
529 tlab[2]=c->GetLabel(2);
531 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+32; // in ps
532 t->SetTOFsignal(tof);
533 //t->SetTOFcluster(c->GetIndex()); // pointing to the digits tree
534 t->SetTOFcluster(idclus); // pointing to the recPoints tree
535 Double_t time[10]; t->GetIntegratedTimes(time);
536 Double_t mom=t->GetP();
537 for(Int_t j=0;j<=AliPID::kSPECIES;j++){
538 Double_t mass=AliPID::ParticleMass(j);
539 time[j]+=(recL-trackPos[3][0])/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
542 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
543 trackTOFout->PropagateTo(xpos);
544 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
545 t->SetIntegratedLength(recL);
546 t->SetIntegratedTimes(time);
547 t->SetTOFLabel(tlab);
551 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
552 for (Int_t ii=0;ii<6;ii++) delete [] clind[ii];
555 //_________________________________________________________________________
556 Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
557 //--------------------------------------------------------------------
558 //This function loads the TOF clusters
559 //--------------------------------------------------------------------
561 TBranch *branch=cTree->GetBranch("TOF");
563 AliError("can't get the branch with the TOF clusters !");
567 TClonesArray dummy("AliTOFcluster",10000), *clusters=&dummy;
568 branch->SetAddress(&clusters);
571 Int_t nc=clusters->GetEntriesFast();
572 AliInfo(Form("Number of clusters: %d",nc));
574 for (Int_t i=0; i<nc; i++) {
575 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
576 fClusters[i]=new AliTOFcluster(*c); fN++;
577 //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)));
578 //AliInfo(Form("%i %f",i, fClusters[i]->GetZ()));
581 //AliInfo(Form("Number of clusters: %d",fN));
585 //_________________________________________________________________________
586 void AliTOFtracker::UnloadClusters() {
587 //--------------------------------------------------------------------
588 //This function unloads TOF clusters
589 //--------------------------------------------------------------------
590 for (Int_t i=0; i<fN; i++) {
597 //_________________________________________________________________________
598 Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
599 //--------------------------------------------------------------------
600 // This function returns the index of the nearest cluster
601 //--------------------------------------------------------------------
603 if (z <= fClusters[0]->GetZ()) return 0;
604 if (z > fClusters[fN-1]->GetZ()) return fN;
605 Int_t b=0, e=fN-1, m=(b+e)/2;
606 for (; b<e; m=(b+e)/2) {
607 if (z > fClusters[m]->GetZ()) b=m+1;
613 //_________________________________________________________________________
614 Bool_t AliTOFtracker::GetTrackPoint(Int_t index, AliTrackPoint& p) const
616 // Get track space point with index i
617 // Coordinates are in the global system
618 AliTOFcluster *cl = fClusters[index];
620 xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
621 xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
623 Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
624 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
625 Float_t tiltangle = fGeom->GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
626 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
627 Float_t sigmay2 = fGeom->XPad()*fGeom->XPad()/12.;
628 Float_t sigmaz2 = fGeom->ZPad()*fGeom->ZPad()/12.;
630 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
631 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
632 cov[2] = -cosphi*sinth*costh*sigmaz2;
633 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
634 cov[4] = -sinphi*sinth*costh*sigmaz2;
635 cov[5] = costh*costh*sigmaz2;
636 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
638 // Detector numbering scheme
639 Int_t nSector = fGeom->NSectors();
640 Int_t nPlate = fGeom->NPlates();
641 Int_t nStripA = fGeom->NStripA();
642 Int_t nStripB = fGeom->NStripB();
643 Int_t nStripC = fGeom->NStripC();
645 Int_t isector = cl->GetDetInd(0);
646 if (isector >= nSector)
647 AliError(Form("Wrong sector number in TOF (%d) !",isector));
648 Int_t iplate = cl->GetDetInd(1);
649 if (iplate >= nPlate)
650 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
651 Int_t istrip = cl->GetDetInd(2);
653 Int_t stripOffset = 0;
659 stripOffset = nStripC;
662 stripOffset = nStripC+nStripB;
665 stripOffset = nStripC+nStripB+nStripA;
668 stripOffset = nStripC+nStripB+nStripA+nStripB;
671 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
675 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
678 UShort_t volid = AliAlignObj::LayerToVolUID(AliAlignObj::kTOF,idet);
679 p.SetVolumeID((UShort_t)volid);