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 "AliTOFcluster.h"
34 #include "AliTOFtrack.h"
35 #include "AliTOFGeometry.h"
36 #include "AliTOFtracker.h"
39 #include "AliTrackPointArray.h"
40 #include "AliAlignObj.h"
41 #include "AliTOFcalib.h"
43 ClassImp(AliTOFtracker)
45 //_____________________________________________________________________________
46 AliTOFtracker::AliTOFtracker(AliTOFGeometry * geom, Double_t parPID[2]) {
47 //AliTOFtracker main Ctor
57 fTOFpid = new AliTOFpidESD(parPID);
61 fDy=AliTOFGeometry::XPad();
62 fDz=AliTOFGeometry::ZPad();
69 fHoles = fGeom->GetHoles();
71 //_____________________________________________________________________________
72 AliTOFtracker::AliTOFtracker(const AliTOFtracker &t):AliTracker() {
73 //AliTOFtracker copy Ctor
77 fNseedsTOF=t.fNseedsTOF;
78 fngoodmatch=t.fngoodmatch;
79 fnbadmatch=t.fnbadmatch;
80 fnunmatch=t.fnunmatch;
85 fTOFHeigth=t.fTOFHeigth;
96 //_____________________________________________________________________________
97 Int_t AliTOFtracker::PropagateBack(AliESD* event) {
99 // Gets seeds from ESD event and Match with TOF Clusters
103 //Initialise some counters
112 Int_t ntrk=event->GetNumberOfTracks();
114 fSeeds= new TClonesArray("AliESDtrack",ntrk);
115 TClonesArray &aESDTrack = *fSeeds;
118 //Load ESD tracks into a local Array of ESD Seeds
120 for (Int_t i=0; i<fNseeds; i++) {
121 AliESDtrack *t=event->GetTrack(i);
122 new(aESDTrack[i]) AliESDtrack(*t);
125 //Prepare ESD tracks candidates for TOF Matching
128 //First Step with Strict Matching Criterion
131 for (Int_t ijk=0; ijk<fN; ijk++) {
132 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)));
136 //Second Step with Looser Matching Criterion
139 AliInfo(Form("Number of matched tracks: %d",fnmatch));
140 AliInfo(Form("Number of good matched tracks: %d",fngoodmatch));
141 AliInfo(Form("Number of bad matched tracks: %d",fnbadmatch));
143 //Update the matched ESD tracks
145 for (Int_t i=0; i<ntrk; i++) {
146 AliESDtrack *t=event->GetTrack(i);
147 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
148 if(seed->GetTOFsignal()>0){
149 t->SetTOFsignal(seed->GetTOFsignal());
150 t->SetTOFcluster(seed->GetTOFcluster());
151 t->SetTOFsignalToT(seed->GetTOFsignalToT());
152 t->SetTOFCalChannel(seed->GetTOFCalChannel());
153 AliTOFtrack *track = new AliTOFtrack(*seed);
154 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
161 fTOFpid->MakePID(event);
176 //_________________________________________________________________________
177 void AliTOFtracker::CollectESD() {
178 //prepare the set of ESD tracks to be matched to clusters in TOF
180 fTracks= new TClonesArray("AliTOFtrack");
181 TClonesArray &aTOFTrack = *fTracks;
182 for (Int_t i=0; i<fNseeds; i++) {
184 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
185 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
187 // TRD good tracks, already propagated at 371 cm
189 AliTOFtrack *track = new AliTOFtrack(*t); // New
190 Double_t x = track->GetX(); //New
192 if (((t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
193 ( x >= fGeom->RinTOF()) ){
194 track->SetSeedIndex(i);
195 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
196 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
201 // Propagate the rest of TPCbp
204 if(track->PropagateToInnerTOF(fHoles)){ // temporary solution
205 // if(track->PropagateToInnerTOF(fGeom->GetHoles())){
206 track->SetSeedIndex(i);
207 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
208 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
215 AliInfo(Form("Number of TOF seedds %i",fNseedsTOF));
217 // Sort according uncertainties on track position
221 //_________________________________________________________________________
222 void AliTOFtracker::MatchTracks( Bool_t mLastStep){
224 //Match ESD tracks to clusters in TOF
227 Int_t nSteps=(Int_t)(fTOFHeigth/0.1);
229 AliTOFcalib *calib = new AliTOFcalib(fGeom);
230 //PH Arrays (moved outside of the loop)
231 Float_t * trackPos[4];
232 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
234 for (Int_t ii=0;ii<6;ii++) clind[ii] = new Int_t[fN];
236 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
238 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
239 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
240 if(t->GetTOFsignal()>0. ) continue;
241 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
247 Float_t cxpos[10000];
248 Float_t crecL[10000];
249 TGeoHMatrix global[1000];
251 // Determine a window around the track
254 trackTOFin->GetExternalParameters(x,par);
256 trackTOFin->GetExternalCovariance(cov);
257 Float_t scalefact=3.;
260 ((5*TMath::Sqrt(cov[0]) + 0.5*fDy + 2.5*TMath::Abs(par[2]))/fR);
263 (5*TMath::Sqrt(cov[2]) + 0.5*fDz + 2.5*TMath::Abs(par[3]));
265 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
266 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
267 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
270 //upper limit on window's size.
272 if(dz> fDzMax) dz=fDzMax;
273 if(dphi*fR>fDyMax) dphi=fDyMax/fR;
278 // find the clusters in the window of the track
280 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
282 AliTOFcluster *c=fClusters[k];
283 if (c->GetZ() > z+dz) break;
284 if (c->IsUsed()) continue;
286 //AliInfo(Form(" fClusters[k]->GetZ() (%f) z-dz (%f) %4i ", fClusters[k]->GetZ(), z-dz, k));
288 Double_t dph=TMath::Abs(c->GetPhi()-phi);
289 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
290 if (TMath::Abs(dph)>dphi) continue;
292 clind[0][nc] = c->GetDetInd(0);
293 clind[1][nc] = c->GetDetInd(1);
294 clind[2][nc] = c->GetDetInd(2);
295 clind[3][nc] = c->GetDetInd(3);
296 clind[4][nc] = c->GetDetInd(4);
305 fGeom->GetVolumePath(ind,path);
306 gGeoManager->cd(path);
307 global[nc] = *gGeoManager->GetCurrentMatrix();
311 //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));
313 //start fine propagation
315 Int_t nStepsDone = 0;
316 for( Int_t istep=0; istep<nSteps; istep++){
318 Float_t xs=fGeom->RinTOF()+istep*0.1;
319 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
322 Double_t ysect=trackTOFin->GetYat(xs,skip);
325 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
328 } else if (ysect <-ymax) {
329 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
334 if(!trackTOFin->PropagateTo(xs)) {
340 // store the running point (Globalrf) - fine propagation
343 trackTOFin->GetGlobalXYZ(x,y,z);
344 trackPos[0][istep]= (Float_t) x;
345 trackPos[1][istep]= (Float_t) y;
346 trackPos[2][istep]= (Float_t) z;
347 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
352 for (Int_t istep=0; istep<nStepsDone; istep++) {
354 Bool_t isInside =kFALSE;
355 Float_t ctrackPos[3];
357 ctrackPos[0]= trackPos[0][istep];
358 ctrackPos[1]= trackPos[1][istep];
359 ctrackPos[2]= trackPos[2][istep];
361 //now see whether the track matches any of the TOF clusters
363 for (Int_t i=0; i<nc; i++){
365 cind[0]= clind[0][i];
366 cind[1]= clind[1][i];
367 cind[2]= clind[2][i];
368 cind[3]= clind[3][i];
369 cind[4]= clind[4][i];
370 Bool_t accept = kFALSE;
371 if( mLastStep)accept = (fGeom->DistanceToPad(cind,global[i],ctrackPos)<fdCut);
372 if(!mLastStep)accept = (fGeom->IsInsideThePad(cind,global[i],ctrackPos));
374 if(!mLastStep)isInside=kTRUE;
375 dist[nfound]=fGeom->DistanceToPad(cind,global[i],ctrackPos);
376 crecL[nfound]=trackPos[3][istep];
377 index[nfound]=clind[5][i]; // store cluster id
378 cxpos[nfound]=fGeom->RinTOF()+istep*0.1; //store prop.radius
382 } //end for on the clusters
386 } //end for on the steps
398 // now choose the cluster to be matched with the track.
403 Float_t mindist=1000.;
404 for (Int_t iclus= 0; iclus<nfound;iclus++){
405 if (dist[iclus]< mindist){
406 mindist = dist[iclus];
408 idclus =index[iclus];
409 recL=crecL[iclus]+fDx*0.5;
413 AliTOFcluster *c=fClusters[idclus];
414 c->Use(); //AliInfo(Form("I am using the cluster"));
416 // Track length correction for matching Step 2
419 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
420 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
421 +trackPos[1][70]*trackPos[1][70]
422 +trackPos[2][70]*trackPos[2][70]);
424 recL=trackPos[3][70]+dlt;
428 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
430 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
432 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
436 //AliInfo(Form(" track label good %5i",trackTOFin->GetLabel()));
442 //AliInfo(Form(" track label bad %5i",trackTOFin->GetLabel()));
448 // Store quantities to be used in the TOF Calibration
449 Float_t ToT=c->GetToT(); // in ps
450 t->SetTOFsignalToT(ToT);
452 ind[0]=c->GetDetInd(0);
453 ind[1]=c->GetDetInd(1);
454 ind[2]=c->GetDetInd(2);
455 ind[3]=c->GetDetInd(3);
456 ind[4]=c->GetDetInd(4);
457 Int_t calindex = calib->GetIndex(ind);
458 t->SetTOFCalChannel(calindex);
460 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+32; // in ps
461 t->SetTOFsignal(tof);
462 //t->SetTOFcluster(c->GetIndex()); // pointing to the digits tree
463 t->SetTOFcluster(idclus); // pointing to the recPoints tree
464 Double_t time[10]; t->GetIntegratedTimes(time);
465 Double_t mom=t->GetP();
466 for(Int_t j=0;j<=AliPID::kSPECIES;j++){
467 Double_t mass=AliPID::ParticleMass(j);
468 time[j]+=(recL-trackPos[3][0])/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
471 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
472 trackTOFout->PropagateTo(xpos);
473 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
474 t->SetIntegratedLength(recL);
475 t->SetIntegratedTimes(time);
479 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
480 for (Int_t ii=0;ii<6;ii++) delete [] clind[ii];
483 //_________________________________________________________________________
484 Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
485 //--------------------------------------------------------------------
486 //This function loads the TOF clusters
487 //--------------------------------------------------------------------
489 TBranch *branch=cTree->GetBranch("TOF");
491 AliError("can't get the branch with the TOF clusters !");
495 TClonesArray dummy("AliTOFcluster",10000), *clusters=&dummy;
496 branch->SetAddress(&clusters);
499 Int_t nc=clusters->GetEntriesFast();
500 AliInfo(Form("Number of clusters: %d",nc));
502 for (Int_t i=0; i<nc; i++) {
503 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
504 fClusters[i]=new AliTOFcluster(*c); fN++;
505 //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)));
506 //AliInfo(Form("%i %f",i, fClusters[i]->GetZ()));
509 //AliInfo(Form("Number of clusters: %d",fN));
513 //_________________________________________________________________________
514 void AliTOFtracker::UnloadClusters() {
515 //--------------------------------------------------------------------
516 //This function unloads TOF clusters
517 //--------------------------------------------------------------------
518 for (Int_t i=0; i<fN; i++) {
525 //_________________________________________________________________________
526 Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
527 //--------------------------------------------------------------------
528 // This function returns the index of the nearest cluster
529 //--------------------------------------------------------------------
531 if (z <= fClusters[0]->GetZ()) return 0;
532 if (z > fClusters[fN-1]->GetZ()) return fN;
533 Int_t b=0, e=fN-1, m=(b+e)/2;
534 for (; b<e; m=(b+e)/2) {
535 if (z > fClusters[m]->GetZ()) b=m+1;
541 //_________________________________________________________________________
542 Bool_t AliTOFtracker::GetTrackPoint(Int_t index, AliTrackPoint& p) const
544 // Get track space point with index i
545 // Coordinates are in the global system
546 AliTOFcluster *cl = fClusters[index];
548 xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
549 xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
551 Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
552 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
553 Float_t tiltangle = fGeom->GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
554 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
555 Float_t sigmay2 = fGeom->XPad()*fGeom->XPad()/12.;
556 Float_t sigmaz2 = fGeom->ZPad()*fGeom->ZPad()/12.;
558 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
559 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
560 cov[2] = -cosphi*sinth*costh*sigmaz2;
561 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
562 cov[4] = -sinphi*sinth*costh*sigmaz2;
563 cov[5] = costh*costh*sigmaz2;
564 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
566 // Detector numbering scheme
567 Int_t nSector = fGeom->NSectors();
568 Int_t nPlate = fGeom->NPlates();
569 Int_t nStripA = fGeom->NStripA();
570 Int_t nStripB = fGeom->NStripB();
571 Int_t nStripC = fGeom->NStripC();
573 Int_t isector = cl->GetDetInd(0);
574 if (isector >= nSector)
575 AliError(Form("Wrong sector number in TOF (%d) !",isector));
576 Int_t iplate = cl->GetDetInd(1);
577 if (iplate >= nPlate)
578 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
579 Int_t istrip = cl->GetDetInd(2);
581 Int_t stripOffset = 0;
587 stripOffset = nStripC;
590 stripOffset = nStripC+nStripB;
593 stripOffset = nStripC+nStripB+nStripA;
596 stripOffset = nStripC+nStripB+nStripA+nStripB;
599 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
603 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
606 UShort_t volid = AliAlignObj::LayerToVolUID(AliAlignObj::kTOF,idet);
607 p.SetVolumeID((UShort_t)volid);