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 (good = %d, bad = %d)",fnmatch,fngoodmatch,fnbadmatch));
191 //Update the matched ESD tracks
193 for (Int_t i=0; i<ntrk; i++) {
194 AliESDtrack *t=event->GetTrack(i);
195 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
197 if ( (seed->GetStatus()&AliESDtrack::kTOFin)!=0 ) {
198 t->SetStatus(AliESDtrack::kTOFin);
199 //if(seed->GetTOFsignal()>0){
200 if ( (seed->GetStatus()&AliESDtrack::kTOFout)!=0 ) {
201 t->SetStatus(AliESDtrack::kTOFout);
202 t->SetTOFsignal(seed->GetTOFsignal());
203 t->SetTOFcluster(seed->GetTOFcluster());
204 t->SetTOFsignalToT(seed->GetTOFsignalToT());
205 t->SetTOFsignalRaw(seed->GetTOFsignalRaw());
206 t->SetTOFsignalDz(seed->GetTOFsignalDz());
207 t->SetTOFsignalDx(seed->GetTOFsignalDx());
208 t->SetTOFCalChannel(seed->GetTOFCalChannel());
209 Int_t tlab[3]; seed->GetTOFLabel(tlab);
210 t->SetTOFLabel(tlab);
212 Double_t alphaA = dynamic_cast<AliExternalTrackParam*>(t)->GetAlpha();
213 Double_t xA = dynamic_cast<AliExternalTrackParam*>(t)->GetX();
214 Double_t yA = dynamic_cast<AliExternalTrackParam*>(t)->GetY();
215 Double_t zA = dynamic_cast<AliExternalTrackParam*>(t)->GetZ();
216 Double_t p1A = dynamic_cast<AliExternalTrackParam*>(t)->GetSnp();
217 Double_t p2A = dynamic_cast<AliExternalTrackParam*>(t)->GetTgl();
218 Double_t p3A = dynamic_cast<AliExternalTrackParam*>(t)->GetSigned1Pt();
219 const Double_t *covA = dynamic_cast<AliExternalTrackParam*>(t)->GetCovariance();
221 // Make attention, please:
222 // AliESDtrack::fTOFInfo array does not be stored in the AliESDs.root file
223 // it is there only for a check during the reconstruction step.
224 Float_t info[10]; seed->GetTOFInfo(info);
226 AliDebug(3,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
229 // by calling the AliESDtrack::UpdateTrackParams,
230 // the current track parameters are changed
231 // and it could cause refit problems.
232 // We need to update only the following track parameters:
233 // the track length and expected times.
234 // Removed AliESDtrack::UpdateTrackParams call
235 // Called AliESDtrack::SetIntegratedTimes(...) and
236 // AliESDtrack::SetIntegratedLength() routines.
238 AliTOFtrack *track = new AliTOFtrack(*seed);
239 t->UpdateTrackParams(track,AliESDtrack::kTOFout); // to be checked - AdC
241 Double_t time[10]; t->GetIntegratedTimes(time);
244 Double_t time[10]; seed->GetIntegratedTimes(time);
245 t->SetIntegratedTimes(time);
247 Double_t length = seed->GetIntegratedLength();
248 t->SetIntegratedLength(length);
250 Double_t alphaB = dynamic_cast<AliExternalTrackParam*>(t)->GetAlpha();
251 Double_t xB = dynamic_cast<AliExternalTrackParam*>(t)->GetX();
252 Double_t yB = dynamic_cast<AliExternalTrackParam*>(t)->GetY();
253 Double_t zB = dynamic_cast<AliExternalTrackParam*>(t)->GetZ();
254 Double_t p1B = dynamic_cast<AliExternalTrackParam*>(t)->GetSnp();
255 Double_t p2B = dynamic_cast<AliExternalTrackParam*>(t)->GetTgl();
256 Double_t p3B = dynamic_cast<AliExternalTrackParam*>(t)->GetSigned1Pt();
257 const Double_t *covB = dynamic_cast<AliExternalTrackParam*>(t)->GetCovariance();
258 AliDebug(2,"Track params -now(before)-:");
259 AliDebug(2,Form(" X: %f(%f), Y: %f(%f), Z: %f(%f) --- alpha: %f(%f)",
264 AliDebug(2,Form(" p1: %f(%f), p2: %f(%f), p3: %f(%f)",
268 AliDebug(2,Form(" cov1: %f(%f), cov2: %f(%f), cov3: %f(%f)"
269 " cov4: %f(%f), cov5: %f(%f), cov6: %f(%f)"
270 " cov7: %f(%f), cov8: %f(%f), cov9: %f(%f)"
271 " cov10: %f(%f), cov11: %f(%f), cov12: %f(%f)"
272 " cov13: %f(%f), cov14: %f(%f), cov15: %f(%f)",
289 AliDebug(3,Form(" TOF params: %6d %f %f %f %f %f %6d %3d %f %f %f %f %f %f",
291 t->GetTOFsignalRaw(),
293 t->GetTOFsignalToT(),
296 t->GetTOFCalChannel(),
298 t->GetIntegratedLength(),
299 time[0], time[1], time[2], time[3], time[4]
306 //Handle Time Zero information
308 Double_t timeZero=0.;
309 Double_t timeZeroMax=99999.;
310 Bool_t usetimeZero = fRecoParam->UseTimeZero();
311 Bool_t timeZeroFromT0 = fRecoParam->GetTimeZerofromT0();
312 Bool_t timeZeroFromTOF = fRecoParam->GetTimeZerofromTOF();
314 AliDebug(2,Form("Use Time Zero?: %d",usetimeZero));
315 AliDebug(2,Form("Time Zero from T0? : %d",timeZeroFromT0));
316 AliDebug(2,Form("Time Zero From TOF? : %d",timeZeroFromTOF));
320 timeZero=GetTimeZerofromT0(event);
322 if(timeZeroFromTOF && (timeZero>timeZeroMax || !timeZeroFromT0)){
323 timeZero=GetTimeZerofromTOF(event);
326 AliDebug(2,Form("time Zero used in PID: %f",timeZero));
328 fPid->MakePID(event,timeZero);
335 //_________________________________________________________________________
336 void AliTOFtracker::CollectESD() {
337 //prepare the set of ESD tracks to be matched to clusters in TOF
342 TClonesArray &aTOFTrack = *fTracks;
343 for (Int_t i=0; i<fNseeds; i++) {
345 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
346 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
348 AliTOFtrack *track = new AliTOFtrack(*t); // New
349 Float_t x = (Float_t)track->GetX(); //New
351 // TRD 'good' tracks, already propagated at 371 cm
352 if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
353 ( x >= AliTOFGeometry::Rmin() ) ) {
354 if ( track->PropagateToInnerTOF() ) {
356 AliDebug(1,Form(" TRD propagated track till rho = %fcm."
357 " And then the track has been propagated till rho = %fcm.",
358 x, (Float_t)track->GetX()));
360 track->SetSeedIndex(i);
361 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
362 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
369 // Propagate the rest of TPCbp
371 if ( track->PropagateToInnerTOF() ) {
373 AliDebug(1,Form(" TPC propagated track till rho = %fcm."
374 " And then the track has been propagated till rho = %fcm.",
375 x, (Float_t)track->GetX()));
377 track->SetSeedIndex(i);
378 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
379 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
387 AliInfo(Form("Number of TOF seeds = %d (Type 1 = %d, Type 2 = %d)",fNseedsTOF,seedsTOF1,seedsTOF2));
389 // Sort according uncertainties on track position
393 //_________________________________________________________________________
394 void AliTOFtracker::MatchTracks( Bool_t mLastStep){
397 // Parameters used/regulating the reconstruction
399 static Float_t corrLen=0.75;
400 static Float_t detDepth=15.3;
401 static Float_t padDepth=0.5;
403 const Float_t kSpeedOfLight= 2.99792458e-2; // speed of light [cm/ps]
404 const Float_t kTimeOffset = 32.; // time offset for tracking algorithm [ps]
406 Float_t dY=AliTOFGeometry::XPad();
407 Float_t dZ=AliTOFGeometry::ZPad();
409 Float_t sensRadius = fRecoParam->GetSensRadius();
410 Float_t stepSize = fRecoParam->GetStepSize();
411 Float_t scaleFact = fRecoParam->GetWindowScaleFact();
412 Float_t dyMax=fRecoParam->GetWindowSizeMaxY();
413 Float_t dzMax=fRecoParam->GetWindowSizeMaxZ();
414 Float_t dCut=fRecoParam->GetDistanceCut();
415 Double_t maxChi2=fRecoParam->GetMaxChi2TRD();
416 Bool_t timeWalkCorr = fRecoParam->GetTimeWalkCorr();
418 AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++ \n");
419 AliDebug(1,Form("TOF sens radius: %f",sensRadius));
420 AliDebug(1,Form("TOF step size: %f",stepSize));
421 AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
422 AliDebug(1,Form("TOF Window max dy: %f",dyMax));
423 AliDebug(1,Form("TOF Window max dz: %f",dzMax));
424 AliDebug(1,Form("TOF distance Cut: %f",dCut));
425 AliDebug(1,Form("TOF Max Chi2: %f",maxChi2));
426 AliDebug(1,Form("Time Walk Correction? : %d",timeWalkCorr));
429 //Match ESD tracks to clusters in TOF
431 // Get the number of propagation steps
432 Int_t nSteps=(Int_t)(detDepth/stepSize);
434 //PH Arrays (moved outside of the loop)
435 Float_t * trackPos[4];
436 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
437 Int_t * clind = new Int_t[fN];
440 const Int_t kNfoundMax = 10000; // related to nSteps value
441 Int_t index[kNfoundMax];
442 Float_t dist[kNfoundMax];
443 Float_t distZ[kNfoundMax];
444 Float_t distY[kNfoundMax]; // delta(rhoXphi) // AdC
445 Float_t cxpos[kNfoundMax];
446 Float_t crecL[kNfoundMax];
447 const Int_t kNclusterMax = 1000; // related to fN value
448 TGeoHMatrix global[kNclusterMax];
451 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
453 for (Int_t ii=0; ii<kNfoundMax; ii++) {
461 for (Int_t ii=0; ii<kNclusterMax; ii++)
464 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
465 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
466 //if ( t->GetTOFsignal()>0. ) continue;
467 if ( (t->GetStatus()&AliESDtrack::kTOFout)!=0 ) continue;
468 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
470 // Determine a window around the track
472 trackTOFin->GetExternalParameters(x,par);
474 trackTOFin->GetExternalCovariance(cov);
476 if (cov[0]<0. || cov[2]<0.) {
477 AliWarning(Form("Very strange track (%d)! At least one of its covariance matrix diagonal elements is negative!",iseed));
484 ((5*TMath::Sqrt(TMath::Abs(cov[0])) + 0.5*dY + 2.5*TMath::Abs(par[2]))/sensRadius);
487 (5*TMath::Sqrt(TMath::Abs(cov[2])) + 0.5*dZ + 2.5*TMath::Abs(par[3]));
489 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
490 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
491 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
494 //upper limit on window's size.
496 if(dz> dzMax) dz=dzMax;
497 if(dphi*sensRadius> dyMax) dphi=dyMax/sensRadius;
502 // find the clusters in the window of the track
504 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
506 if (nc>=kNclusterMax) {
507 AliWarning("No more matchable clusters can be stored! Please, increase the corresponding vectors size.");
511 AliTOFcluster *c=fClusters[k];
512 if (c->GetZ() > z+dz) break;
513 if (c->IsUsed()) continue;
515 if (!c->GetStatus()) {
516 AliDebug(1,"Cluster in channel declared bad!");
517 continue; // skip bad channels as declared in OCDB
520 Double_t dph=TMath::Abs(c->GetPhi()-phi);
521 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
522 if (TMath::Abs(dph)>dphi) continue;
524 Double_t yc=(c->GetPhi() - trackTOFin->GetAlpha())*c->GetR();
525 Double_t p[2]={yc, c->GetZ()};
526 Double_t cov2[3]= {dY*dY/12., 0., dZ*dZ/12.};
527 if (trackTOFin->AliExternalTrackParam::GetPredictedChi2(p,cov2) > maxChi2)continue;
532 ind[0]=c->GetDetInd(0);
533 ind[1]=c->GetDetInd(1);
534 ind[2]=c->GetDetInd(2);
535 ind[3]=c->GetDetInd(3);
536 ind[4]=c->GetDetInd(4);
537 fGeom->GetVolumePath(ind,path);
538 gGeoManager->cd(path);
539 global[nc] = *gGeoManager->GetCurrentMatrix();
543 AliDebug(1,Form(" Number of matchable TOF clusters for the track number %d: %d",iseed,nc));
545 //start fine propagation
547 Int_t nStepsDone = 0;
548 for( Int_t istep=0; istep<nSteps; istep++){
550 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
551 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
554 Double_t ysect=trackTOFin->GetYat(xs,skip);
557 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
560 } else if (ysect <-ymax) {
561 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
566 if(!trackTOFin->PropagateTo(xs)) {
572 // store the running point (Globalrf) - fine propagation
575 trackTOFin->GetXYZ(r);
576 trackPos[0][istep]= (Float_t) r[0];
577 trackPos[1][istep]= (Float_t) r[1];
578 trackPos[2][istep]= (Float_t) r[2];
579 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
584 Bool_t accept = kFALSE;
585 Bool_t isInside = kFALSE;
586 for (Int_t istep=0; istep<nStepsDone; istep++) {
588 if (nfound>=kNfoundMax) {
589 AliWarning("No more track positions can be stored! Please, increase the corresponding vectors size.");
593 Float_t ctrackPos[3];
594 ctrackPos[0] = trackPos[0][istep];
595 ctrackPos[1] = trackPos[1][istep];
596 ctrackPos[2] = trackPos[2][istep];
598 //now see whether the track matches any of the TOF clusters
602 for (Int_t i=0; i<nc; i++) {
603 isInside = fGeom->IsInsideThePad(global[i],ctrackPos,dist3d);
606 Float_t yLoc = dist3d[1];
607 Float_t rLoc = TMath::Sqrt(dist3d[0]*dist3d[0]+dist3d[2]*dist3d[2]);
608 accept = (TMath::Abs(yLoc)<padDepth*0.5 && rLoc<dCut);
609 AliDebug(2," I am in the case mLastStep==kTRUE ");
616 dist[nfound] = TMath::Sqrt(dist3d[0]*dist3d[0] +
617 dist3d[1]*dist3d[1] +
618 dist3d[2]*dist3d[2]);
619 AliDebug(2,Form(" dist3dLoc[0] = %f, dist3dLoc[1] = %f, dist3dLoc[2] = %f ",
620 dist3d[0],dist3d[1],dist3d[2]));
621 distZ[nfound] = dist3d[2]; // Z distance in the RF of the
622 // hit pad closest to the
623 // reconstructed track
624 distY[nfound] = dist3d[0]; // X distance in the RF of the
625 // hit pad closest to the
626 // reconstructed track
627 // It corresponds to Y coordinate
631 AliDebug(2,Form(" dist3dLoc[0] = %f --- distY[%d] = %f",
632 dist3d[0],nfound,distY[nfound]));
633 AliDebug(2,Form(" dist3dLoc[2] = %f --- distZ[%d] = %f",
634 dist3d[2],nfound,distZ[nfound]));
637 crecL[nfound] = trackPos[3][istep];
638 index[nfound] = clind[i]; // store cluster id
639 cxpos[nfound] = AliTOFGeometry::RinTOF()+istep*0.1; //store prop.radius
641 if(accept &&!mLastStep)break;
644 } //end for on the clusters
645 if(accept &&!mLastStep)break;
646 } //end for on the steps
648 AliDebug(1,Form(" Number of track points for the track number %d: %d",iseed,nfound));
659 // now choose the cluster to be matched with the track.
664 Float_t mindist=1000.;
667 for (Int_t iclus= 0; iclus<nfound;iclus++){
668 if (dist[iclus]< mindist){
669 mindist = dist[iclus];
670 mindistZ = distZ[iclus]; // Z distance in the RF of the hit
671 // pad closest to the reconstructed
673 mindistY = distY[iclus]; // Y distance in the RF of the hit
674 // pad closest to the reconstructed
677 idclus =index[iclus];
678 recL=crecL[iclus]+corrLen*0.5;
683 AliTOFcluster *c=fClusters[idclus];
685 Float_t tiltangle = AliTOFGeometry::GetAngles(c->GetDetInd(1),c->GetDetInd(2))*TMath::DegToRad();
686 Float_t localCheck=-mindistZ;
687 localCheck/=TMath::Cos(tiltangle); // Z (tracking/ALICE RF) component of
688 // the distance between the
689 // reconstructed track and the
690 // TOF closest cluster
692 AliDebug(2, Form("%7d %7d %10d %10d %10d %10d %7d",
695 TMath::Abs(trackTOFin->GetLabel()),
696 c->GetLabel(0), c->GetLabel(1), c->GetLabel(2),
701 // Track length correction for matching Step 2
704 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
705 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
706 +trackPos[1][70]*trackPos[1][70]
707 +trackPos[2][70]*trackPos[2][70]);
709 recL=trackPos[3][70]+dlt;
713 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
715 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
717 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
721 AliDebug(2,Form(" track label good %5d",trackTOFin->GetLabel()));
727 AliDebug(2,Form(" track label bad %5d",trackTOFin->GetLabel()));
733 // Store quantities to be used in the TOF Calibration
734 Float_t tToT=AliTOFGeometry::ToTBinWidth()*c->GetToT()*1E-3; // in ns
735 t->SetTOFsignalToT(tToT);
736 Float_t rawTime=AliTOFGeometry::TdcBinWidth()*c->GetTDCRAW()+kTimeOffset; // RAW time,in ps
737 t->SetTOFsignalRaw(rawTime);
738 t->SetTOFsignalDz(mindistZ);
739 t->SetTOFsignalDx(mindistY);
741 Float_t info[10] = {mindist,mindistY,mindistZ,
742 0.,0.,0.,0.,0.,0.,0.};
744 AliDebug(2,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
748 ind[0]=c->GetDetInd(0);
749 ind[1]=c->GetDetInd(1);
750 ind[2]=c->GetDetInd(2);
751 ind[3]=c->GetDetInd(3);
752 ind[4]=c->GetDetInd(4);
753 Int_t calindex = AliTOFGeometry::GetIndex(ind);
754 t->SetTOFCalChannel(calindex);
756 // keep track of the track labels in the matched cluster
758 tlab[0]=c->GetLabel(0);
759 tlab[1]=c->GetLabel(1);
760 tlab[2]=c->GetLabel(2);
761 AliDebug(2,Form(" tdc time of the matched track %6d = ",c->GetTDC()));
762 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+kTimeOffset; // in ps
763 AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
764 Double_t tofcorr=tof;
765 if(timeWalkCorr)tofcorr=CorrectTimeWalk(mindistZ,tof);
766 AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));
767 //Set TOF time signal and pointer to the matched cluster
768 t->SetTOFsignal(tofcorr);
769 t->SetTOFcluster(idclus); // pointing to the recPoints tree
771 AliDebug(2,Form(" Setting TOF raw time: %f, z distance: %f corrected time: %f ",rawTime,mindistZ,tofcorr));
774 Double_t time[AliPID::kSPECIES]; t->GetIntegratedTimes(time); // in ps
775 Double_t mom=t->GetP();
776 AliDebug(2,Form(" Momentum for track %d -> %f", iseed,mom));
777 for (Int_t j=0;j<AliPID::kSPECIES;j++) {
778 Double_t mass=AliPID::ParticleMass(j);
779 time[j]+=(recL-trackPos[3][0])/kSpeedOfLight*TMath::Sqrt(mom*mom+mass*mass)/mom;
782 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
783 trackTOFout->PropagateTo(xpos);
785 // Fill the track residual histograms.
786 FillResiduals(trackTOFout,c,kFALSE);
788 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
789 t->SetIntegratedLength(recL);
790 t->SetIntegratedTimes(time);
791 t->SetTOFLabel(tlab);
794 // Fill Reco-QA histos for Reconstruction
795 fHRecNClus->Fill(nc);
796 fHRecDist->Fill(mindist);
797 fHRecSigYVsP->Fill(mom,TMath::Sqrt(cov[0]));
798 fHRecSigZVsP->Fill(mom,TMath::Sqrt(cov[2]));
799 fHRecSigYVsPWin->Fill(mom,dphi*sensRadius);
800 fHRecSigZVsPWin->Fill(mom,dz);
802 // Fill Tree for on-the-fly offline Calibration
804 if ( !((t->GetStatus() & AliESDtrack::kTIME)==0 ) ) {
815 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
819 //_________________________________________________________________________
820 Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
821 //--------------------------------------------------------------------
822 //This function loads the TOF clusters
823 //--------------------------------------------------------------------
825 Int_t npadX = AliTOFGeometry::NpadX();
826 Int_t npadZ = AliTOFGeometry::NpadZ();
827 Int_t nStripA = AliTOFGeometry::NStripA();
828 Int_t nStripB = AliTOFGeometry::NStripB();
829 Int_t nStripC = AliTOFGeometry::NStripC();
831 TBranch *branch=cTree->GetBranch("TOF");
833 AliError("can't get the branch with the TOF clusters !");
837 static TClonesArray dummy("AliTOFcluster",10000);
839 TClonesArray *clusters=&dummy;
840 branch->SetAddress(&clusters);
843 Int_t nc=clusters->GetEntriesFast();
844 fHDigNClus->Fill(nc);
846 AliInfo(Form("Number of clusters: %d",nc));
848 for (Int_t i=0; i<nc; i++) {
849 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
850 //PH fClusters[i]=new AliTOFcluster(*c); fN++;
851 fClusters[i]=c; fN++;
853 // Fill Digits QA histos
855 Int_t isector = c->GetDetInd(0);
856 Int_t iplate = c->GetDetInd(1);
857 Int_t istrip = c->GetDetInd(2);
858 Int_t ipadX = c->GetDetInd(4);
859 Int_t ipadZ = c->GetDetInd(3);
861 Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
862 Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
864 Int_t stripOffset = 0;
870 stripOffset = nStripC;
873 stripOffset = nStripC+nStripB;
876 stripOffset = nStripC+nStripB+nStripA;
879 stripOffset = nStripC+nStripB+nStripA+nStripB;
882 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
885 Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
886 Int_t phiindex=npadX*isector+ipadX+1;
887 fHDigClusMap->Fill(zindex,phiindex);
888 fHDigClusTime->Fill(time);
889 fHDigClusToT->Fill(tot);
896 //_________________________________________________________________________
897 void AliTOFtracker::UnloadClusters() {
898 //--------------------------------------------------------------------
899 //This function unloads TOF clusters
900 //--------------------------------------------------------------------
901 for (Int_t i=0; i<fN; i++) {
902 //PH delete fClusters[i];
908 //_________________________________________________________________________
909 Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
910 //--------------------------------------------------------------------
911 // This function returns the index of the nearest cluster
912 //--------------------------------------------------------------------
914 if (z <= fClusters[0]->GetZ()) return 0;
915 if (z > fClusters[fN-1]->GetZ()) return fN;
916 Int_t b=0, e=fN-1, m=(b+e)/2;
917 for (; b<e; m=(b+e)/2) {
918 if (z > fClusters[m]->GetZ()) b=m+1;
924 //_________________________________________________________________________
925 Bool_t AliTOFtracker::GetTrackPoint(Int_t index, AliTrackPoint& p) const
927 // Get track space point with index i
928 // Coordinates are in the global system
929 AliTOFcluster *cl = fClusters[index];
931 xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
932 xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
934 Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
935 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
936 Float_t tiltangle = AliTOFGeometry::GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
937 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
938 Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
939 Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
941 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
942 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
943 cov[2] = -cosphi*sinth*costh*sigmaz2;
944 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
945 cov[4] = -sinphi*sinth*costh*sigmaz2;
946 cov[5] = costh*costh*sigmaz2;
947 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
949 // Detector numbering scheme
950 Int_t nSector = AliTOFGeometry::NSectors();
951 Int_t nPlate = AliTOFGeometry::NPlates();
952 Int_t nStripA = AliTOFGeometry::NStripA();
953 Int_t nStripB = AliTOFGeometry::NStripB();
954 Int_t nStripC = AliTOFGeometry::NStripC();
956 Int_t isector = cl->GetDetInd(0);
957 if (isector >= nSector)
958 AliError(Form("Wrong sector number in TOF (%d) !",isector));
959 Int_t iplate = cl->GetDetInd(1);
960 if (iplate >= nPlate)
961 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
962 Int_t istrip = cl->GetDetInd(2);
964 Int_t stripOffset = 0;
970 stripOffset = nStripC;
973 stripOffset = nStripC+nStripB;
976 stripOffset = nStripC+nStripB+nStripA;
979 stripOffset = nStripC+nStripB+nStripA+nStripB;
982 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
986 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
989 UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
990 p.SetVolumeID((UShort_t)volid);
993 //_________________________________________________________________________
994 void AliTOFtracker::InitCheckHists() {
996 //Init histos for Digits/Reco QA and Calibration
999 TDirectory *dir = gDirectory;
1000 TFile *logFileTOF = 0;
1002 TSeqCollection *list = gROOT->GetListOfFiles();
1003 int n = list->GetEntries();
1004 Bool_t isThere=kFALSE;
1005 for(int i=0; i<n; i++) {
1006 logFileTOF = (TFile*)list->At(i);
1007 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
1013 if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
1016 fCalTree = new TTree("CalTree", "Tree for TOF calibration");
1017 fCalTree->Branch("TOFchannelindex",&fIch,"iTOFch/I");
1018 fCalTree->Branch("ToT",&fToT,"TOFToT/F");
1019 fCalTree->Branch("TOFtime",&fTime,"TOFtime/F");
1020 fCalTree->Branch("PionExpTime",&fExpTimePi,"PiExpTime/F");
1021 fCalTree->Branch("KaonExpTime",&fExpTimeKa,"KaExpTime/F");
1022 fCalTree->Branch("ProtonExpTime",&fExpTimePr,"PrExpTime/F");
1025 fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);
1026 fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);
1027 fHDigClusTime = new TH1F("TOFDig_ClusTime", "",2000,0.,200.);
1028 fHDigClusToT = new TH1F("TOFDig_ClusToT", "",500,0.,100);
1031 fHRecNClus =new TH1F("TOFRec_NClusW", "",50,0.5,50.5);
1032 fHRecDist=new TH1F("TOFRec_Dist", "",50,0.5,10.5);
1033 fHRecSigYVsP=new TH2F("TOFDig_SigYVsP", "",40,0.,4.,100, 0.,5.);
1034 fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
1035 fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
1036 fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
1042 //_________________________________________________________________________
1043 void AliTOFtracker::SaveCheckHists() {
1045 //write histos for Digits/Reco QA and Calibration
1047 TDirectory *dir = gDirectory;
1048 TFile *logFileTOF = 0;
1050 TSeqCollection *list = gROOT->GetListOfFiles();
1051 int n = list->GetEntries();
1052 Bool_t isThere=kFALSE;
1053 for(int i=0; i<n; i++) {
1054 logFileTOF = (TFile*)list->At(i);
1055 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
1062 AliError(Form("File TOFQA.root not found!! not wring histograms...."));
1066 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
1067 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
1068 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
1069 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
1070 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
1071 fHRecDist->Write(fHRecDist->GetName(), TObject::kOverwrite);
1072 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
1073 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
1074 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
1075 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
1076 fCalTree->Write(fCalTree->GetName(),TObject::kOverwrite);
1077 logFileTOF->Flush();
1081 //_________________________________________________________________________
1082 Float_t AliTOFtracker::CorrectTimeWalk( Float_t dist, Float_t tof) {
1084 //dummy, for the moment
1086 if(dist<AliTOFGeometry::ZPad()*0.5){
1088 //place here the actual correction
1094 //_________________________________________________________________________
1095 Float_t AliTOFtracker::GetTimeZerofromT0(AliESDEvent *event) const {
1097 //Returns TimeZero as measured by T0 detector
1099 return event->GetT0();
1101 //_________________________________________________________________________
1102 Float_t AliTOFtracker::GetTimeZerofromTOF(AliESDEvent * /*event*/) const {
1104 //dummy, for the moment. T0 algorithm using tracks on TOF
1106 //place T0 algo here...
1110 //_________________________________________________________________________
1112 void AliTOFtracker::FillClusterArray(TObjArray* arr) const
1115 // Returns the TOF cluster array
1121 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
1124 //_________________________________________________________________________