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 //--------------------------------------------------------------------//
32 #include <TSeqCollection.h>
33 #include <TClonesArray.h>
34 #include <TGeoManager.h>
39 #include "AliGeomManager.h"
40 #include "AliESDtrack.h"
41 #include "AliESDEvent.h"
43 #include "AliTrackPointArray.h"
44 #include "AliCDBManager.h"
46 #include "AliTOFpidESD.h"
47 #include "AliTOFRecoParam.h"
48 #include "AliTOFReconstructor.h"
49 #include "AliTOFcluster.h"
50 #include "AliTOFGeometry.h"
51 #include "AliTOFtracker.h"
52 #include "AliTOFtrack.h"
54 extern TGeoManager *gGeoManager;
57 ClassImp(AliTOFtracker)
59 //_____________________________________________________________________________
60 AliTOFtracker::AliTOFtracker():
71 fTracks(new TClonesArray("AliTOFtrack")),
72 fSeeds(new TClonesArray("AliESDtrack")),
91 //AliTOFtracker main Ctor
93 // Gettimg the geometry
94 fGeom= new AliTOFGeometry();
99 //_____________________________________________________________________________
100 AliTOFtracker::~AliTOFtracker() {
107 if(!(AliCDBManager::Instance()->GetCacheFlag())){
114 delete fHDigClusTime;
120 delete fHRecSigYVsPWin;
121 delete fHRecSigZVsPWin;
135 //_____________________________________________________________________________
136 Int_t AliTOFtracker::PropagateBack(AliESDEvent* event) {
138 // Gets seeds from ESD event and Match with TOF Clusters
141 // initialize RecoParam for current event
143 AliInfo("Initializing params for TOF... ");
145 fRecoParam = AliTOFReconstructor::GetRecoParam(); // instantiate reco param from STEER...
147 if (fRecoParam == 0x0) {
148 AliFatal("No Reco Param found for TOF!!!");
150 //fRecoParam->Dump();
151 //if(fRecoParam->GetApplyPbPbCuts())fRecoParam=fRecoParam->GetPbPbparam();
152 //fRecoParam->PrintParameters();
155 parPID[0]=fRecoParam->GetTimeResolution();
156 parPID[1]=fRecoParam->GetTimeNSigma();
157 fPid=new AliTOFpidESD(parPID);
159 //Initialise some counters
168 Int_t ntrk=event->GetNumberOfTracks();
170 TClonesArray &aESDTrack = *fSeeds;
173 //Load ESD tracks into a local Array of ESD Seeds
175 for (Int_t i=0; i<fNseeds; i++) {
176 AliESDtrack *t=event->GetTrack(i);
177 new(aESDTrack[i]) AliESDtrack(*t);
180 //Prepare ESD tracks candidates for TOF Matching
183 //First Step with Strict Matching Criterion
186 //Second Step with Looser Matching Criterion
189 AliInfo(Form("Number of matched tracks: %d",fnmatch));
190 AliInfo(Form("Number of good matched tracks: %d",fngoodmatch));
191 AliInfo(Form("Number of bad matched tracks: %d",fnbadmatch));
193 //Update the matched ESD tracks
195 for (Int_t i=0; i<ntrk; i++) {
196 AliESDtrack *t=event->GetTrack(i);
197 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
198 if(seed->GetTOFsignal()>0){
199 t->SetTOFsignal(seed->GetTOFsignal());
200 t->SetTOFcluster(seed->GetTOFcluster());
201 t->SetTOFsignalToT(seed->GetTOFsignalToT());
202 t->SetTOFsignalRaw(seed->GetTOFsignalRaw());
203 t->SetTOFsignalDz(seed->GetTOFsignalDz());
204 t->SetTOFCalChannel(seed->GetTOFCalChannel());
205 Int_t tlab[3]; seed->GetTOFLabel(tlab);
206 t->SetTOFLabel(tlab);
207 AliTOFtrack *track = new AliTOFtrack(*seed);
208 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
210 Double_t time[10]; t->GetIntegratedTimes(time);
211 AliDebug(1,Form("%d %f %f %f %f %f",i,
223 //Handle Time Zero information
225 Double_t timeZero=0.;
226 Double_t timeZeroMax=99999.;
227 Bool_t usetimeZero = fRecoParam->UseTimeZero();
228 Bool_t timeZeroFromT0 = fRecoParam->GetTimeZerofromT0();
229 Bool_t timeZeroFromTOF = fRecoParam->GetTimeZerofromTOF();
231 AliDebug(1,Form("Use Time Zero?: %d",usetimeZero));
232 AliDebug(1,Form("Time Zero from T0? : %d",timeZeroFromT0));
233 AliDebug(1,Form("Time Zero From TOF? : %d",timeZeroFromTOF));
237 timeZero=GetTimeZerofromT0(event);
239 if(timeZeroFromTOF && (timeZero>timeZeroMax || !timeZeroFromT0)){
240 timeZero=GetTimeZerofromTOF(event);
243 AliDebug(2,Form("time Zero used in PID: %f",timeZero));
245 fPid->MakePID(event,timeZero);
252 //_________________________________________________________________________
253 void AliTOFtracker::CollectESD() {
254 //prepare the set of ESD tracks to be matched to clusters in TOF
259 TClonesArray &aTOFTrack = *fTracks;
260 for (Int_t i=0; i<fNseeds; i++) {
262 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
263 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
265 // TRD 'good' tracks, already propagated at 372 cm
267 AliTOFtrack *track = new AliTOFtrack(*t); // New
268 Double_t x = track->GetX(); //New
269 if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
270 ( x >= AliTOFGeometry::RinTOF() ) ) {
271 track->SetSeedIndex(i);
272 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
273 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
279 // Propagate the rest of TPCbp
282 if(track->PropagateToInnerTOF()){
283 track->SetSeedIndex(i);
284 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
285 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
293 AliInfo(Form("Number of TOF seeds %i",fNseedsTOF));
294 AliInfo(Form("Number of TOF seeds Type 1 %i",seedsTOF1));
295 AliInfo(Form("Number of TOF seeds Type 2 %i",seedsTOF2));
297 // Sort according uncertainties on track position
301 //_________________________________________________________________________
302 void AliTOFtracker::MatchTracks( Bool_t mLastStep){
305 // Parameters used/regulating the reconstruction
307 static Float_t corrLen=0.75;
308 static Float_t detDepth=15.3;
309 static Float_t padDepth=0.5;
311 Float_t dY=AliTOFGeometry::XPad();
312 Float_t dZ=AliTOFGeometry::ZPad();
314 Float_t sensRadius = fRecoParam->GetSensRadius();
315 Float_t stepSize = fRecoParam->GetStepSize();
316 Float_t scaleFact = fRecoParam->GetWindowScaleFact();
317 Float_t dyMax=fRecoParam->GetWindowSizeMaxY();
318 Float_t dzMax=fRecoParam->GetWindowSizeMaxZ();
319 Float_t dCut=fRecoParam->GetDistanceCut();
320 Double_t maxChi2=fRecoParam->GetMaxChi2TRD();
321 Bool_t timeWalkCorr = fRecoParam->GetTimeWalkCorr();
323 AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++ \n");
324 AliDebug(1,Form("TOF sens radius: %f",sensRadius));
325 AliDebug(1,Form("TOF step size: %f",stepSize));
326 AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
327 AliDebug(1,Form("TOF Window max dy: %f",dyMax));
328 AliDebug(1,Form("TOF Window max dz: %f",dzMax));
329 AliDebug(1,Form("TOF distance Cut: %f",dCut));
330 AliDebug(1,Form("TOF Max Chi2: %f",maxChi2));
331 AliDebug(1,Form("Time Walk Correction? : %d",timeWalkCorr));
333 //Match ESD tracks to clusters in TOF
336 // Get the number of propagation steps
338 Int_t nSteps=(Int_t)(detDepth/stepSize);
340 //PH Arrays (moved outside of the loop)
342 Float_t * trackPos[4];
343 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
344 Int_t * clind = new Int_t[fN];
346 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
348 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
349 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
350 if(t->GetTOFsignal()>0. ) continue;
351 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
357 Float_t distZ[10000];
358 Float_t cxpos[10000];
359 Float_t crecL[10000];
360 TGeoHMatrix global[1000];
362 // Determine a window around the track
365 trackTOFin->GetExternalParameters(x,par);
367 trackTOFin->GetExternalCovariance(cov);
371 ((5*TMath::Sqrt(cov[0]) + 0.5*dY + 2.5*TMath::Abs(par[2]))/sensRadius);
374 (5*TMath::Sqrt(cov[2]) + 0.5*dZ + 2.5*TMath::Abs(par[3]));
376 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
377 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
378 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
381 //upper limit on window's size.
383 if(dz> dzMax) dz=dzMax;
384 if(dphi*sensRadius> dyMax) dphi=dyMax/sensRadius;
389 // find the clusters in the window of the track
391 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
393 AliTOFcluster *c=fClusters[k];
394 if (c->GetZ() > z+dz) break;
395 if (c->IsUsed()) continue;
397 if (!c->GetStatus()) {
398 AliDebug(1,"Cluster in channel declared bad!");
399 continue; // skip bad channels as declared in OCDB
402 Double_t dph=TMath::Abs(c->GetPhi()-phi);
403 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
404 if (TMath::Abs(dph)>dphi) continue;
406 Double_t yc=(c->GetPhi() - trackTOFin->GetAlpha())*c->GetR();
407 Double_t p[2]={yc, c->GetZ()};
408 Double_t cov2[3]= {dY*dY/12., 0., dZ*dZ/12.};
409 if (trackTOFin->AliExternalTrackParam::GetPredictedChi2(p,cov2) > maxChi2)continue;
414 ind[0]=c->GetDetInd(0);
415 ind[1]=c->GetDetInd(1);
416 ind[2]=c->GetDetInd(2);
417 ind[3]=c->GetDetInd(3);
418 ind[4]=c->GetDetInd(4);
419 fGeom->GetVolumePath(ind,path);
420 gGeoManager->cd(path);
421 global[nc] = *gGeoManager->GetCurrentMatrix();
425 //start fine propagation
427 Int_t nStepsDone = 0;
428 for( Int_t istep=0; istep<nSteps; istep++){
430 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
431 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
434 Double_t ysect=trackTOFin->GetYat(xs,skip);
437 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
440 } else if (ysect <-ymax) {
441 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
446 if(!trackTOFin->PropagateTo(xs)) {
452 // store the running point (Globalrf) - fine propagation
455 trackTOFin->GetXYZ(r);
456 trackPos[0][istep]= (Float_t) r[0];
457 trackPos[1][istep]= (Float_t) r[1];
458 trackPos[2][istep]= (Float_t) r[2];
459 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
464 Bool_t accept = kFALSE;
465 Bool_t isInside =kFALSE;
466 for (Int_t istep=0; istep<nStepsDone; istep++) {
468 Float_t ctrackPos[3];
470 ctrackPos[0] = trackPos[0][istep];
471 ctrackPos[1] = trackPos[1][istep];
472 ctrackPos[2] = trackPos[2][istep];
474 //now see whether the track matches any of the TOF clusters
476 Float_t dist3dLoc[3];
478 for (Int_t i=0; i<nc; i++) {
479 isInside = fGeom->IsInsideThePad(global[i],ctrackPos,dist3dLoc);
482 Float_t yLoc = dist3dLoc[1];
483 Float_t rLoc = TMath::Sqrt(dist3dLoc[0]*dist3dLoc[0]+dist3dLoc[2]*dist3dLoc[2]);
484 accept = (TMath::Abs(yLoc)<padDepth*0.5 && rLoc<dCut);
491 dist[nfound] = TMath::Sqrt(dist3dLoc[0]*dist3dLoc[0] +
492 dist3dLoc[1]*dist3dLoc[1] +
493 dist3dLoc[2]*dist3dLoc[2]);
495 Float_t differenceT[3] = {0.,0.,0.};
496 PadRS2TrackingRS(ctrackPos, differenceT);
497 distZ[nfound] = differenceT[2];
499 AliDebug(1,Form(" dist3dLoc[2] = %f --- distZ[%d] = %f",
500 dist3dLoc[2],nfound,distZ[nfound]));
503 Double_t padl[3] = {0., 0., 0.};
504 Double_t padg[3] = {0., 0., 0.};
505 TGeoHMatrix inverse = global[i].Inverse();
506 inverse.MasterToLocal(padl,padg);
508 dist3d[0] = ctrackPos[0] - padg[0];
509 dist3d[1] = ctrackPos[1] - padg[1];
510 dist3d[2] = ctrackPos[2] - padg[2];
512 crecL[nfound] = trackPos[3][istep];
513 index[nfound] = clind[i]; // store cluster id
514 cxpos[nfound] = AliTOFGeometry::RinTOF()+istep*0.1; //store prop.radius
516 if(accept &&!mLastStep)break;
518 } //end for on the clusters
519 if(accept &&!mLastStep)break;
520 } //end for on the steps
532 // now choose the cluster to be matched with the track.
537 Float_t mindist=1000.;
539 for (Int_t iclus= 0; iclus<nfound;iclus++){
540 if (dist[iclus]< mindist){
541 mindist = dist[iclus];
542 mindistZ = distZ[iclus];
544 idclus =index[iclus];
545 recL=crecL[iclus]+corrLen*0.5;
550 AliTOFcluster *c=fClusters[idclus];
552 AliDebug(2, Form("%7i %7i %10i %10i %10i %10i %7i",
555 TMath::Abs(trackTOFin->GetLabel()),
556 c->GetLabel(0), c->GetLabel(1), c->GetLabel(2),
561 // Track length correction for matching Step 2
564 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
565 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
566 +trackPos[1][70]*trackPos[1][70]
567 +trackPos[2][70]*trackPos[2][70]);
569 recL=trackPos[3][70]+dlt;
573 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
575 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
577 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
581 AliDebug(2,Form(" track label good %5i",trackTOFin->GetLabel()));
587 AliDebug(2,Form(" track label bad %5i",trackTOFin->GetLabel()));
593 // Store quantities to be used in the TOF Calibration
594 Float_t tToT=AliTOFGeometry::ToTBinWidth()*c->GetToT()*1E-3; // in ns
595 t->SetTOFsignalToT(tToT);
596 Float_t rawTime=AliTOFGeometry::TdcBinWidth()*c->GetTDCRAW()+32; // RAW time,in ps
597 t->SetTOFsignalRaw(rawTime);
598 t->SetTOFsignalDz(mindistZ);
599 AliDebug(2,Form(" Setting TOF raw time: %f, z distance: %f time: %f = ",rawTime,mindistZ));
601 ind[0]=c->GetDetInd(0);
602 ind[1]=c->GetDetInd(1);
603 ind[2]=c->GetDetInd(2);
604 ind[3]=c->GetDetInd(3);
605 ind[4]=c->GetDetInd(4);
606 Int_t calindex = AliTOFGeometry::GetIndex(ind);
607 t->SetTOFCalChannel(calindex);
609 // keep track of the track labels in the matched cluster
611 tlab[0]=c->GetLabel(0);
612 tlab[1]=c->GetLabel(1);
613 tlab[2]=c->GetLabel(2);
614 AliDebug(2,Form(" tdc time of the matched track %i = ",c->GetTDC()));
615 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+32; // in ps
616 AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
617 Double_t tofcorr=tof;
618 if(timeWalkCorr)tofcorr=CorrectTimeWalk(mindistZ,tof);
619 AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));
620 //Set TOF time signal and pointer to the matched cluster
621 t->SetTOFsignal(tofcorr);
622 t->SetTOFcluster(idclus); // pointing to the recPoints tree
625 Double_t time[AliPID::kSPECIES]; t->GetIntegratedTimes(time);
626 Double_t mom=t->GetP();
627 AliDebug(1,Form("Momentum for track %d -> %f", iseed,mom));
628 for(Int_t j=0;j<AliPID::kSPECIES;j++){
629 Double_t mass=AliPID::ParticleMass(j);
630 time[j]+=(recL-trackPos[3][0])/2.99792458e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
633 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
634 trackTOFout->PropagateTo(xpos);
636 // Fill the track residual histograms.
637 FillResiduals(trackTOFout,c,kFALSE);
639 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
640 t->SetIntegratedLength(recL);
641 t->SetIntegratedTimes(time);
642 t->SetTOFLabel(tlab);
645 // Fill Reco-QA histos for Reconstruction
646 fHRecNClus->Fill(nc);
647 fHRecDist->Fill(mindist);
648 fHRecSigYVsP->Fill(mom,TMath::Sqrt(cov[0]));
649 fHRecSigZVsP->Fill(mom,TMath::Sqrt(cov[2]));
650 fHRecSigYVsPWin->Fill(mom,dphi*sensRadius);
651 fHRecSigZVsPWin->Fill(mom,dz);
653 // Fill Tree for on-the-fly offline Calibration
655 if ( !((t->GetStatus() & AliESDtrack::kTIME)==0 )){
666 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
670 //_________________________________________________________________________
671 Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
672 //--------------------------------------------------------------------
673 //This function loads the TOF clusters
674 //--------------------------------------------------------------------
676 Int_t npadX = AliTOFGeometry::NpadX();
677 Int_t npadZ = AliTOFGeometry::NpadZ();
678 Int_t nStripA = AliTOFGeometry::NStripA();
679 Int_t nStripB = AliTOFGeometry::NStripB();
680 Int_t nStripC = AliTOFGeometry::NStripC();
682 TBranch *branch=cTree->GetBranch("TOF");
684 AliError("can't get the branch with the TOF clusters !");
688 static TClonesArray dummy("AliTOFcluster",10000);
690 TClonesArray *clusters=&dummy;
691 branch->SetAddress(&clusters);
694 Int_t nc=clusters->GetEntriesFast();
695 fHDigNClus->Fill(nc);
697 AliInfo(Form("Number of clusters: %d",nc));
699 for (Int_t i=0; i<nc; i++) {
700 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
701 fClusters[i]=new AliTOFcluster(*c); fN++;
703 // Fill Digits QA histos
705 Int_t isector = c->GetDetInd(0);
706 Int_t iplate = c->GetDetInd(1);
707 Int_t istrip = c->GetDetInd(2);
708 Int_t ipadX = c->GetDetInd(4);
709 Int_t ipadZ = c->GetDetInd(3);
711 Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
712 Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
714 Int_t stripOffset = 0;
720 stripOffset = nStripC;
723 stripOffset = nStripC+nStripB;
726 stripOffset = nStripC+nStripB+nStripA;
729 stripOffset = nStripC+nStripB+nStripA+nStripB;
732 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
735 Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
736 Int_t phiindex=npadX*isector+ipadX+1;
737 fHDigClusMap->Fill(zindex,phiindex);
738 fHDigClusTime->Fill(time);
739 fHDigClusToT->Fill(tot);
746 //_________________________________________________________________________
747 void AliTOFtracker::UnloadClusters() {
748 //--------------------------------------------------------------------
749 //This function unloads TOF clusters
750 //--------------------------------------------------------------------
751 for (Int_t i=0; i<fN; i++) {
758 //_________________________________________________________________________
759 Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
760 //--------------------------------------------------------------------
761 // This function returns the index of the nearest cluster
762 //--------------------------------------------------------------------
764 if (z <= fClusters[0]->GetZ()) return 0;
765 if (z > fClusters[fN-1]->GetZ()) return fN;
766 Int_t b=0, e=fN-1, m=(b+e)/2;
767 for (; b<e; m=(b+e)/2) {
768 if (z > fClusters[m]->GetZ()) b=m+1;
774 //_________________________________________________________________________
775 Bool_t AliTOFtracker::GetTrackPoint(Int_t index, AliTrackPoint& p) const
777 // Get track space point with index i
778 // Coordinates are in the global system
779 AliTOFcluster *cl = fClusters[index];
781 xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
782 xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
784 Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
785 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
786 Float_t tiltangle = AliTOFGeometry::GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
787 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
788 Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
789 Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
791 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
792 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
793 cov[2] = -cosphi*sinth*costh*sigmaz2;
794 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
795 cov[4] = -sinphi*sinth*costh*sigmaz2;
796 cov[5] = costh*costh*sigmaz2;
797 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
799 // Detector numbering scheme
800 Int_t nSector = AliTOFGeometry::NSectors();
801 Int_t nPlate = AliTOFGeometry::NPlates();
802 Int_t nStripA = AliTOFGeometry::NStripA();
803 Int_t nStripB = AliTOFGeometry::NStripB();
804 Int_t nStripC = AliTOFGeometry::NStripC();
806 Int_t isector = cl->GetDetInd(0);
807 if (isector >= nSector)
808 AliError(Form("Wrong sector number in TOF (%d) !",isector));
809 Int_t iplate = cl->GetDetInd(1);
810 if (iplate >= nPlate)
811 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
812 Int_t istrip = cl->GetDetInd(2);
814 Int_t stripOffset = 0;
820 stripOffset = nStripC;
823 stripOffset = nStripC+nStripB;
826 stripOffset = nStripC+nStripB+nStripA;
829 stripOffset = nStripC+nStripB+nStripA+nStripB;
832 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
836 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
839 UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
840 p.SetVolumeID((UShort_t)volid);
843 //_________________________________________________________________________
844 void AliTOFtracker::InitCheckHists() {
846 //Init histos for Digits/Reco QA and Calibration
849 TDirectory *dir = gDirectory;
850 TFile *logFileTOF = 0;
852 TSeqCollection *list = gROOT->GetListOfFiles();
853 int n = list->GetEntries();
854 Bool_t isThere=kFALSE;
855 for(int i=0; i<n; i++) {
856 logFileTOF = (TFile*)list->At(i);
857 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
863 if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
866 fCalTree = new TTree("CalTree", "Tree for TOF calibration");
867 fCalTree->Branch("TOFchannelindex",&fIch,"iTOFch/I");
868 fCalTree->Branch("ToT",&fToT,"TOFToT/F");
869 fCalTree->Branch("TOFtime",&fTime,"TOFtime/F");
870 fCalTree->Branch("PionExpTime",&fExpTimePi,"PiExpTime/F");
871 fCalTree->Branch("KaonExpTime",&fExpTimeKa,"KaExpTime/F");
872 fCalTree->Branch("ProtonExpTime",&fExpTimePr,"PrExpTime/F");
875 fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);
876 fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);
877 fHDigClusTime = new TH1F("TOFDig_ClusTime", "",2000,0.,200.);
878 fHDigClusToT = new TH1F("TOFDig_ClusToT", "",500,0.,100);
881 fHRecNClus =new TH1F("TOFRec_NClusW", "",50,0.5,50.5);
882 fHRecDist=new TH1F("TOFRec_Dist", "",50,0.5,10.5);
883 fHRecSigYVsP=new TH2F("TOFDig_SigYVsP", "",40,0.,4.,100, 0.,5.);
884 fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
885 fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
886 fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
892 //_________________________________________________________________________
893 void AliTOFtracker::SaveCheckHists() {
895 //write histos for Digits/Reco QA and Calibration
897 TDirectory *dir = gDirectory;
898 TFile *logFileTOF = 0;
900 TSeqCollection *list = gROOT->GetListOfFiles();
901 int n = list->GetEntries();
902 Bool_t isThere=kFALSE;
903 for(int i=0; i<n; i++) {
904 logFileTOF = (TFile*)list->At(i);
905 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
912 AliError(Form("File TOFQA.root not found!! not wring histograms...."));
916 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
917 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
918 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
919 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
920 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
921 fHRecDist->Write(fHRecDist->GetName(), TObject::kOverwrite);
922 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
923 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
924 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
925 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
926 fCalTree->Write(fCalTree->GetName(),TObject::kOverwrite);
931 //_________________________________________________________________________
932 Float_t AliTOFtracker::CorrectTimeWalk( Float_t dist, Float_t tof) {
934 //dummy, for the moment
936 if(dist<AliTOFGeometry::ZPad()*0.5){
938 //place here the actual correction
944 //_________________________________________________________________________
945 Float_t AliTOFtracker::GetTimeZerofromT0(AliESDEvent *event) const {
947 //Returns TimeZero as measured by T0 detector
949 return event->GetT0();
951 //_________________________________________________________________________
952 Float_t AliTOFtracker::GetTimeZerofromTOF(AliESDEvent * /*event*/) const {
954 //dummy, for the moment. T0 algorithm using tracks on TOF
956 //place T0 algo here...
960 //_________________________________________________________________________
962 void AliTOFtracker::FillClusterArray(TObjArray* arr) const
965 // Returns the TOF cluster array
971 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
974 //_________________________________________________________________________
976 void AliTOFtracker::PadRS2TrackingRS(Float_t *ctrackPos, Float_t *differenceT)
979 // To convert the 3D distance ctrackPos, referred to the hit pad,
980 // into the 3D distance differenceT, referred to the tracking
984 for (Int_t ii=0; ii<3; ii++) differenceT[ii] = 0.;
986 AliDebug(1,Form(" track position in ALICE global Ref. frame -> %f, %f, %f",
987 ctrackPos[0],ctrackPos[1],ctrackPos[2]));
990 fGeom->GetSector(ctrackPos),
991 fGeom->GetPlate(ctrackPos),
992 fGeom->GetStrip(ctrackPos),
993 fGeom->GetPadZ(ctrackPos),
994 fGeom->GetPadX(ctrackPos)};
995 UShort_t alignableStripIndex = fGeom->GetAliSensVolIndex(detId[0],detId[1],detId[2]);
996 AliDebug(1,Form(" sector = %2d, plate = %1d, strip = %2d ---> stripIndex = %4d",
997 detId[0], detId[1], detId[2], alignableStripIndex));
999 // pad centre coordinates in the strip ref. frame
1000 Double_t padCentreL[3] = {(detId[4]-AliTOFGeometry::NpadX()/2)*AliTOFGeometry::XPad()+AliTOFGeometry::XPad()/2.,
1002 (detId[3]-AliTOFGeometry::NpadZ()/2)*AliTOFGeometry::XPad()+AliTOFGeometry::XPad()/2.};
1003 // pad centre coordinates in the strip tracking frame
1004 Double_t padCentreT[3] = {0., 0., 0.};
1005 TGeoHMatrix l2t = *AliGeomManager::GetTracking2LocalMatrix(alignableStripIndex);
1006 l2t.MasterToLocal(padCentreL,padCentreT);
1010 // pad centre coordinates in its ref. frame
1011 Double_t padCentreL2[3] = {0., 0., 0.};
1012 // pad centre coordinates in the ALICE global ref. frame
1013 Double_t padCentreG[3] = {0., 0., 0.};
1014 fGeom->GetVolumePath(detId,path);
1015 gGeoManager->cd(path);
1016 TGeoHMatrix g2l = *gGeoManager->GetCurrentMatrix();
1017 TGeoHMatrix l2g = g2l.Inverse();
1018 l2g.MasterToLocal(padCentreL2,padCentreG);
1022 // strip centre coordinates in its ref. frame
1023 Double_t stripCentreL[3] = {0., 0., 0.};
1024 // strip centre coordinates in the ALICE global ref. frame
1025 Double_t stripCentreG[3] = {0., 0., 0.};
1026 fGeom->GetVolumePath(detId[0],detId[1],detId[2],path2);
1027 gGeoManager->cd(path2);
1028 TGeoHMatrix g2lb = *gGeoManager->GetCurrentMatrix();
1029 TGeoHMatrix l2gb = g2lb.Inverse();
1030 l2gb.MasterToLocal(stripCentreL,stripCentreG);
1032 TGeoHMatrix g2t = 0;
1033 AliGeomManager::GetTrackingMatrix(alignableStripIndex, g2t);
1035 // track position in the ALICE global ref. frame
1037 for (Int_t ii=0; ii<3; ii++) posG[ii] = (Double_t)ctrackPos[ii];
1039 // strip centre coordinates in the tracking ref. frame
1040 Double_t stripCentreT[3] = {0., 0., 0.};
1041 // track position in the tracking ref. frame
1042 Double_t posT[3] = {0., 0., 0.};
1043 g2t.MasterToLocal(posG,posT);
1044 g2t.MasterToLocal(stripCentreG,stripCentreT);
1046 for (Int_t ii=0; ii<3; ii++)
1047 AliDebug(1,Form(" track position in ALICE global and tracking Ref. frames -> posG[%d] = %f --- posT[%d] = %f",
1048 ii, posG[ii], ii, posT[ii]));
1049 for (Int_t ii=0; ii<3; ii++)
1050 AliDebug(1,Form(" pad centre coordinates in its, the ALICE global and tracking Ref. frames -> padCentreL[%d] = %f --- padCentreG[%d] = %f --- padCentreT[%d] = %f",
1053 ii, padCentreT[ii]));
1054 for (Int_t ii=0; ii<3; ii++)
1055 AliDebug(1,Form(" strip centre coordinates in its, the ALICE global and tracking Ref. frames -> stripCentreL[%d] = %f --- stripCentreG[%d] = %f --- stripCentreT[%d] = %f",
1056 ii, stripCentreL[ii],
1057 ii, stripCentreG[ii],
1058 ii, stripCentreT[ii]));
1059 for (Int_t ii=0; ii<3; ii++)
1060 AliDebug(1,Form(" difference between the track position and the pad centre in the tracking Ref. frame -> posT[%d]-padCentreT[%d] = %f",
1062 posT[ii]-padCentreT[ii]));
1064 for (Int_t ii=0; ii<3; ii++) differenceT[ii] = (Float_t)(posT[ii]-padCentreT[ii]);