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);
199 if ( (seed->GetStatus()&AliESDtrack::kTOFin)!=0 ) {
200 t->SetStatus(AliESDtrack::kTOFin);
201 //if(seed->GetTOFsignal()>0){
202 if ( (seed->GetStatus()&AliESDtrack::kTOFout)!=0 ) {
203 t->SetStatus(AliESDtrack::kTOFout);
204 t->SetTOFsignal(seed->GetTOFsignal());
205 t->SetTOFcluster(seed->GetTOFcluster());
206 t->SetTOFsignalToT(seed->GetTOFsignalToT());
207 t->SetTOFsignalRaw(seed->GetTOFsignalRaw());
208 t->SetTOFsignalDz(seed->GetTOFsignalDz());
209 t->SetTOFsignalDx(seed->GetTOFsignalDx());
210 t->SetTOFCalChannel(seed->GetTOFCalChannel());
211 Int_t tlab[3]; seed->GetTOFLabel(tlab);
212 t->SetTOFLabel(tlab);
214 Float_t info[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
215 seed->GetTOFInfo(info);
217 AliDebug(2,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
219 AliTOFtrack *track = new AliTOFtrack(*seed);
220 t->UpdateTrackParams(track,AliESDtrack::kTOFout); // to be checked - AdC
222 Double_t time[10]; t->GetIntegratedTimes(time);
223 AliDebug(2,Form(" %6d %f %f %f %f %f %6d %3d %f %f %f %f %f %f",
225 t->GetTOFsignalRaw(),
227 t->GetTOFsignalToT(),
230 t->GetTOFCalChannel(),
232 t->GetIntegratedLength(),
233 time[0], time[1], time[2], time[3], time[4]
240 //Handle Time Zero information
242 Double_t timeZero=0.;
243 Double_t timeZeroMax=99999.;
244 Bool_t usetimeZero = fRecoParam->UseTimeZero();
245 Bool_t timeZeroFromT0 = fRecoParam->GetTimeZerofromT0();
246 Bool_t timeZeroFromTOF = fRecoParam->GetTimeZerofromTOF();
248 AliDebug(2,Form("Use Time Zero?: %d",usetimeZero));
249 AliDebug(2,Form("Time Zero from T0? : %d",timeZeroFromT0));
250 AliDebug(2,Form("Time Zero From TOF? : %d",timeZeroFromTOF));
254 timeZero=GetTimeZerofromT0(event);
256 if(timeZeroFromTOF && (timeZero>timeZeroMax || !timeZeroFromT0)){
257 timeZero=GetTimeZerofromTOF(event);
260 AliDebug(2,Form("time Zero used in PID: %f",timeZero));
262 fPid->MakePID(event,timeZero);
269 //_________________________________________________________________________
270 void AliTOFtracker::CollectESD() {
271 //prepare the set of ESD tracks to be matched to clusters in TOF
276 TClonesArray &aTOFTrack = *fTracks;
277 for (Int_t i=0; i<fNseeds; i++) {
279 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
280 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
282 AliTOFtrack *track = new AliTOFtrack(*t); // New
283 Float_t x = (Float_t)track->GetX(); //New
285 // TRD 'good' tracks, already propagated at 371 cm
286 if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
287 ( x >= AliTOFGeometry::Rmin() ) ) {
288 if ( track->PropagateToInnerTOF() ) {
290 AliDebug(1,Form(" TRD propagated track till rho = %fcm."
291 " And then the track has been propagated till rho = %fcm.",
292 x, (Float_t)track->GetX()));
294 track->SetSeedIndex(i);
295 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
296 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
303 // Propagate the rest of TPCbp
305 if ( track->PropagateToInnerTOF() ) {
307 AliDebug(1,Form(" TPC propagated track till rho = %fcm."
308 " And then the track has been propagated till rho = %fcm.",
309 x, (Float_t)track->GetX()));
311 track->SetSeedIndex(i);
312 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
313 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
321 AliInfo(Form("Number of TOF seeds %d",fNseedsTOF));
322 AliInfo(Form("Number of TOF seeds Type 1 %d",seedsTOF1));
323 AliInfo(Form("Number of TOF seeds Type 2 %d",seedsTOF2));
325 // Sort according uncertainties on track position
329 //_________________________________________________________________________
330 void AliTOFtracker::MatchTracks( Bool_t mLastStep){
333 // Parameters used/regulating the reconstruction
335 static Float_t corrLen=0.75;
336 static Float_t detDepth=15.3;
337 static Float_t padDepth=0.5;
339 const Float_t kSpeedOfLight= 2.99792458e-2; // speed of light [cm/ps]
340 const Float_t kTimeOffset = 32.; // time offset for tracking algorithm [ps]
342 Float_t dY=AliTOFGeometry::XPad();
343 Float_t dZ=AliTOFGeometry::ZPad();
345 Float_t sensRadius = fRecoParam->GetSensRadius();
346 Float_t stepSize = fRecoParam->GetStepSize();
347 Float_t scaleFact = fRecoParam->GetWindowScaleFact();
348 Float_t dyMax=fRecoParam->GetWindowSizeMaxY();
349 Float_t dzMax=fRecoParam->GetWindowSizeMaxZ();
350 Float_t dCut=fRecoParam->GetDistanceCut();
351 Double_t maxChi2=fRecoParam->GetMaxChi2TRD();
352 Bool_t timeWalkCorr = fRecoParam->GetTimeWalkCorr();
354 AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++ \n");
355 AliDebug(1,Form("TOF sens radius: %f",sensRadius));
356 AliDebug(1,Form("TOF step size: %f",stepSize));
357 AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
358 AliDebug(1,Form("TOF Window max dy: %f",dyMax));
359 AliDebug(1,Form("TOF Window max dz: %f",dzMax));
360 AliDebug(1,Form("TOF distance Cut: %f",dCut));
361 AliDebug(1,Form("TOF Max Chi2: %f",maxChi2));
362 AliDebug(1,Form("Time Walk Correction? : %d",timeWalkCorr));
365 //Match ESD tracks to clusters in TOF
367 // Get the number of propagation steps
368 Int_t nSteps=(Int_t)(detDepth/stepSize);
370 //PH Arrays (moved outside of the loop)
371 Float_t * trackPos[4];
372 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
373 Int_t * clind = new Int_t[fN];
376 const Int_t kNfoundMax = 10000; // related to nSteps value
377 Int_t index[kNfoundMax];
378 Float_t dist[kNfoundMax];
379 Float_t distZ[kNfoundMax];
380 Float_t distY[kNfoundMax]; // delta(rhoXphi) // AdC
381 Float_t cxpos[kNfoundMax];
382 Float_t crecL[kNfoundMax];
383 const Int_t kNclusterMax = 1000; // related to fN value
384 TGeoHMatrix global[kNclusterMax];
387 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
389 for (Int_t ii=0; ii<kNfoundMax; ii++) {
397 for (Int_t ii=0; ii<kNclusterMax; ii++)
400 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
401 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
402 //if ( t->GetTOFsignal()>0. ) continue;
403 if ( (t->GetStatus()&AliESDtrack::kTOFout)!=0 ) continue;
404 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
406 // Determine a window around the track
408 trackTOFin->GetExternalParameters(x,par);
410 trackTOFin->GetExternalCovariance(cov);
412 if (cov[0]<0. || cov[2]<0.) {
413 AliWarning(Form("Very strange track (%d)! At least one of its covariance matrix diagonal elements is negative!",iseed));
420 ((5*TMath::Sqrt(TMath::Abs(cov[0])) + 0.5*dY + 2.5*TMath::Abs(par[2]))/sensRadius);
423 (5*TMath::Sqrt(TMath::Abs(cov[2])) + 0.5*dZ + 2.5*TMath::Abs(par[3]));
425 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
426 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
427 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
430 //upper limit on window's size.
432 if(dz> dzMax) dz=dzMax;
433 if(dphi*sensRadius> dyMax) dphi=dyMax/sensRadius;
438 // find the clusters in the window of the track
440 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
442 if (nc>=kNclusterMax) {
443 AliWarning("No more matchable clusters can be stored! Please, increase the corresponding vectors size.");
447 AliTOFcluster *c=fClusters[k];
448 if (c->GetZ() > z+dz) break;
449 if (c->IsUsed()) continue;
451 if (!c->GetStatus()) {
452 AliDebug(1,"Cluster in channel declared bad!");
453 continue; // skip bad channels as declared in OCDB
456 Double_t dph=TMath::Abs(c->GetPhi()-phi);
457 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
458 if (TMath::Abs(dph)>dphi) continue;
460 Double_t yc=(c->GetPhi() - trackTOFin->GetAlpha())*c->GetR();
461 Double_t p[2]={yc, c->GetZ()};
462 Double_t cov2[3]= {dY*dY/12., 0., dZ*dZ/12.};
463 if (trackTOFin->AliExternalTrackParam::GetPredictedChi2(p,cov2) > maxChi2)continue;
468 ind[0]=c->GetDetInd(0);
469 ind[1]=c->GetDetInd(1);
470 ind[2]=c->GetDetInd(2);
471 ind[3]=c->GetDetInd(3);
472 ind[4]=c->GetDetInd(4);
473 fGeom->GetVolumePath(ind,path);
474 gGeoManager->cd(path);
475 global[nc] = *gGeoManager->GetCurrentMatrix();
479 AliDebug(1,Form(" Number of matchable TOF clusters for the track number %d: %d",iseed,nc));
481 //start fine propagation
483 Int_t nStepsDone = 0;
484 for( Int_t istep=0; istep<nSteps; istep++){
486 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
487 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
490 Double_t ysect=trackTOFin->GetYat(xs,skip);
493 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
496 } else if (ysect <-ymax) {
497 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
502 if(!trackTOFin->PropagateTo(xs)) {
508 // store the running point (Globalrf) - fine propagation
511 trackTOFin->GetXYZ(r);
512 trackPos[0][istep]= (Float_t) r[0];
513 trackPos[1][istep]= (Float_t) r[1];
514 trackPos[2][istep]= (Float_t) r[2];
515 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
520 Bool_t accept = kFALSE;
521 Bool_t isInside = kFALSE;
522 for (Int_t istep=0; istep<nStepsDone; istep++) {
524 if (nfound>=kNfoundMax) {
525 AliWarning("No more track positions can be stored! Please, increase the corresponding vectors size.");
529 Float_t ctrackPos[3];
530 ctrackPos[0] = trackPos[0][istep];
531 ctrackPos[1] = trackPos[1][istep];
532 ctrackPos[2] = trackPos[2][istep];
534 //now see whether the track matches any of the TOF clusters
538 for (Int_t i=0; i<nc; i++) {
539 isInside = fGeom->IsInsideThePad(global[i],ctrackPos,dist3d);
542 Float_t yLoc = dist3d[1];
543 Float_t rLoc = TMath::Sqrt(dist3d[0]*dist3d[0]+dist3d[2]*dist3d[2]);
544 accept = (TMath::Abs(yLoc)<padDepth*0.5 && rLoc<dCut);
545 AliDebug(2," I am in the case mLastStep==kTRUE ");
552 dist[nfound] = TMath::Sqrt(dist3d[0]*dist3d[0] +
553 dist3d[1]*dist3d[1] +
554 dist3d[2]*dist3d[2]);
555 AliDebug(2,Form(" dist3dLoc[0] = %f, dist3dLoc[1] = %f, dist3dLoc[2] = %f ",
556 dist3d[0],dist3d[1],dist3d[2]));
557 distZ[nfound] = dist3d[2]; // Z distance in the RF of the
558 // hit pad closest to the
559 // reconstructed track
560 distY[nfound] = dist3d[0]; // X distance in the RF of the
561 // hit pad closest to the
562 // reconstructed track
563 // It corresponds to Y coordinate
567 AliDebug(2,Form(" dist3dLoc[0] = %f --- distY[%d] = %f",
568 dist3d[0],nfound,distY[nfound]));
569 AliDebug(2,Form(" dist3dLoc[2] = %f --- distZ[%d] = %f",
570 dist3d[2],nfound,distZ[nfound]));
573 crecL[nfound] = trackPos[3][istep];
574 index[nfound] = clind[i]; // store cluster id
575 cxpos[nfound] = AliTOFGeometry::RinTOF()+istep*0.1; //store prop.radius
577 if(accept &&!mLastStep)break;
580 } //end for on the clusters
581 if(accept &&!mLastStep)break;
582 } //end for on the steps
584 AliDebug(1,Form(" Number of track points for the track number %d: %d",iseed,nfound));
595 // now choose the cluster to be matched with the track.
600 Float_t mindist=1000.;
603 for (Int_t iclus= 0; iclus<nfound;iclus++){
604 if (dist[iclus]< mindist){
605 mindist = dist[iclus];
606 mindistZ = distZ[iclus]; // Z distance in the RF of the hit
607 // pad closest to the reconstructed
609 mindistY = distY[iclus]; // Y distance in the RF of the hit
610 // pad closest to the reconstructed
613 idclus =index[iclus];
614 recL=crecL[iclus]+corrLen*0.5;
619 AliTOFcluster *c=fClusters[idclus];
621 Float_t tiltangle = AliTOFGeometry::GetAngles(c->GetDetInd(1),c->GetDetInd(2))*TMath::DegToRad();
622 Float_t localCheck=-mindistZ;
623 localCheck/=TMath::Cos(tiltangle); // Z (tracking/ALICE RF) component of
624 // the distance between the
625 // reconstructed track and the
626 // TOF closest cluster
628 AliDebug(2, Form("%7d %7d %10d %10d %10d %10d %7d",
631 TMath::Abs(trackTOFin->GetLabel()),
632 c->GetLabel(0), c->GetLabel(1), c->GetLabel(2),
637 // Track length correction for matching Step 2
640 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
641 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
642 +trackPos[1][70]*trackPos[1][70]
643 +trackPos[2][70]*trackPos[2][70]);
645 recL=trackPos[3][70]+dlt;
649 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
651 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
653 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
657 AliDebug(2,Form(" track label good %5d",trackTOFin->GetLabel()));
663 AliDebug(2,Form(" track label bad %5d",trackTOFin->GetLabel()));
669 // Store quantities to be used in the TOF Calibration
670 Float_t tToT=AliTOFGeometry::ToTBinWidth()*c->GetToT()*1E-3; // in ns
671 t->SetTOFsignalToT(tToT);
672 Float_t rawTime=AliTOFGeometry::TdcBinWidth()*c->GetTDCRAW()+kTimeOffset; // RAW time,in ps
673 t->SetTOFsignalRaw(rawTime);
674 t->SetTOFsignalDz(mindistZ);
675 t->SetTOFsignalDx(mindistY);
677 Float_t info[10] = {mindist,mindistY,mindistZ,
678 0.,0.,0.,0.,0.,0.,0.};
680 AliDebug(2,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
684 ind[0]=c->GetDetInd(0);
685 ind[1]=c->GetDetInd(1);
686 ind[2]=c->GetDetInd(2);
687 ind[3]=c->GetDetInd(3);
688 ind[4]=c->GetDetInd(4);
689 Int_t calindex = AliTOFGeometry::GetIndex(ind);
690 t->SetTOFCalChannel(calindex);
692 // keep track of the track labels in the matched cluster
694 tlab[0]=c->GetLabel(0);
695 tlab[1]=c->GetLabel(1);
696 tlab[2]=c->GetLabel(2);
697 AliDebug(2,Form(" tdc time of the matched track %6d = ",c->GetTDC()));
698 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+kTimeOffset; // in ps
699 AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
700 Double_t tofcorr=tof;
701 if(timeWalkCorr)tofcorr=CorrectTimeWalk(mindistZ,tof);
702 AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));
703 //Set TOF time signal and pointer to the matched cluster
704 t->SetTOFsignal(tofcorr);
705 t->SetTOFcluster(idclus); // pointing to the recPoints tree
707 AliDebug(2,Form(" Setting TOF raw time: %f, z distance: %f corrected time: %f ",rawTime,mindistZ,tofcorr));
710 Double_t time[AliPID::kSPECIES]; t->GetIntegratedTimes(time); // in ps
711 Double_t mom=t->GetP();
712 AliDebug(2,Form(" Momentum for track %d -> %f", iseed,mom));
713 for (Int_t j=0;j<AliPID::kSPECIES;j++) {
714 Double_t mass=AliPID::ParticleMass(j);
715 time[j]+=(recL-trackPos[3][0])/kSpeedOfLight*TMath::Sqrt(mom*mom+mass*mass)/mom;
718 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
719 trackTOFout->PropagateTo(xpos);
721 // Fill the track residual histograms.
722 FillResiduals(trackTOFout,c,kFALSE);
724 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
725 t->SetIntegratedLength(recL);
726 t->SetIntegratedTimes(time);
727 t->SetTOFLabel(tlab);
730 // Fill Reco-QA histos for Reconstruction
731 fHRecNClus->Fill(nc);
732 fHRecDist->Fill(mindist);
733 fHRecSigYVsP->Fill(mom,TMath::Sqrt(cov[0]));
734 fHRecSigZVsP->Fill(mom,TMath::Sqrt(cov[2]));
735 fHRecSigYVsPWin->Fill(mom,dphi*sensRadius);
736 fHRecSigZVsPWin->Fill(mom,dz);
738 // Fill Tree for on-the-fly offline Calibration
740 if ( !((t->GetStatus() & AliESDtrack::kTIME)==0 ) ) {
751 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
755 //_________________________________________________________________________
756 Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
757 //--------------------------------------------------------------------
758 //This function loads the TOF clusters
759 //--------------------------------------------------------------------
761 Int_t npadX = AliTOFGeometry::NpadX();
762 Int_t npadZ = AliTOFGeometry::NpadZ();
763 Int_t nStripA = AliTOFGeometry::NStripA();
764 Int_t nStripB = AliTOFGeometry::NStripB();
765 Int_t nStripC = AliTOFGeometry::NStripC();
767 TBranch *branch=cTree->GetBranch("TOF");
769 AliError("can't get the branch with the TOF clusters !");
773 static TClonesArray dummy("AliTOFcluster",10000);
775 TClonesArray *clusters=&dummy;
776 branch->SetAddress(&clusters);
779 Int_t nc=clusters->GetEntriesFast();
780 fHDigNClus->Fill(nc);
782 AliInfo(Form("Number of clusters: %d",nc));
784 for (Int_t i=0; i<nc; i++) {
785 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
786 //PH fClusters[i]=new AliTOFcluster(*c); fN++;
787 fClusters[i]=c; fN++;
789 // Fill Digits QA histos
791 Int_t isector = c->GetDetInd(0);
792 Int_t iplate = c->GetDetInd(1);
793 Int_t istrip = c->GetDetInd(2);
794 Int_t ipadX = c->GetDetInd(4);
795 Int_t ipadZ = c->GetDetInd(3);
797 Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
798 Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
800 Int_t stripOffset = 0;
806 stripOffset = nStripC;
809 stripOffset = nStripC+nStripB;
812 stripOffset = nStripC+nStripB+nStripA;
815 stripOffset = nStripC+nStripB+nStripA+nStripB;
818 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
821 Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
822 Int_t phiindex=npadX*isector+ipadX+1;
823 fHDigClusMap->Fill(zindex,phiindex);
824 fHDigClusTime->Fill(time);
825 fHDigClusToT->Fill(tot);
832 //_________________________________________________________________________
833 void AliTOFtracker::UnloadClusters() {
834 //--------------------------------------------------------------------
835 //This function unloads TOF clusters
836 //--------------------------------------------------------------------
837 for (Int_t i=0; i<fN; i++) {
838 //PH delete fClusters[i];
844 //_________________________________________________________________________
845 Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
846 //--------------------------------------------------------------------
847 // This function returns the index of the nearest cluster
848 //--------------------------------------------------------------------
850 if (z <= fClusters[0]->GetZ()) return 0;
851 if (z > fClusters[fN-1]->GetZ()) return fN;
852 Int_t b=0, e=fN-1, m=(b+e)/2;
853 for (; b<e; m=(b+e)/2) {
854 if (z > fClusters[m]->GetZ()) b=m+1;
860 //_________________________________________________________________________
861 Bool_t AliTOFtracker::GetTrackPoint(Int_t index, AliTrackPoint& p) const
863 // Get track space point with index i
864 // Coordinates are in the global system
865 AliTOFcluster *cl = fClusters[index];
867 xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
868 xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
870 Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
871 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
872 Float_t tiltangle = AliTOFGeometry::GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
873 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
874 Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
875 Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
877 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
878 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
879 cov[2] = -cosphi*sinth*costh*sigmaz2;
880 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
881 cov[4] = -sinphi*sinth*costh*sigmaz2;
882 cov[5] = costh*costh*sigmaz2;
883 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
885 // Detector numbering scheme
886 Int_t nSector = AliTOFGeometry::NSectors();
887 Int_t nPlate = AliTOFGeometry::NPlates();
888 Int_t nStripA = AliTOFGeometry::NStripA();
889 Int_t nStripB = AliTOFGeometry::NStripB();
890 Int_t nStripC = AliTOFGeometry::NStripC();
892 Int_t isector = cl->GetDetInd(0);
893 if (isector >= nSector)
894 AliError(Form("Wrong sector number in TOF (%d) !",isector));
895 Int_t iplate = cl->GetDetInd(1);
896 if (iplate >= nPlate)
897 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
898 Int_t istrip = cl->GetDetInd(2);
900 Int_t stripOffset = 0;
906 stripOffset = nStripC;
909 stripOffset = nStripC+nStripB;
912 stripOffset = nStripC+nStripB+nStripA;
915 stripOffset = nStripC+nStripB+nStripA+nStripB;
918 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
922 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
925 UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
926 p.SetVolumeID((UShort_t)volid);
929 //_________________________________________________________________________
930 void AliTOFtracker::InitCheckHists() {
932 //Init histos for Digits/Reco QA and Calibration
935 TDirectory *dir = gDirectory;
936 TFile *logFileTOF = 0;
938 TSeqCollection *list = gROOT->GetListOfFiles();
939 int n = list->GetEntries();
940 Bool_t isThere=kFALSE;
941 for(int i=0; i<n; i++) {
942 logFileTOF = (TFile*)list->At(i);
943 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
949 if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
952 fCalTree = new TTree("CalTree", "Tree for TOF calibration");
953 fCalTree->Branch("TOFchannelindex",&fIch,"iTOFch/I");
954 fCalTree->Branch("ToT",&fToT,"TOFToT/F");
955 fCalTree->Branch("TOFtime",&fTime,"TOFtime/F");
956 fCalTree->Branch("PionExpTime",&fExpTimePi,"PiExpTime/F");
957 fCalTree->Branch("KaonExpTime",&fExpTimeKa,"KaExpTime/F");
958 fCalTree->Branch("ProtonExpTime",&fExpTimePr,"PrExpTime/F");
961 fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);
962 fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);
963 fHDigClusTime = new TH1F("TOFDig_ClusTime", "",2000,0.,200.);
964 fHDigClusToT = new TH1F("TOFDig_ClusToT", "",500,0.,100);
967 fHRecNClus =new TH1F("TOFRec_NClusW", "",50,0.5,50.5);
968 fHRecDist=new TH1F("TOFRec_Dist", "",50,0.5,10.5);
969 fHRecSigYVsP=new TH2F("TOFDig_SigYVsP", "",40,0.,4.,100, 0.,5.);
970 fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
971 fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
972 fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
978 //_________________________________________________________________________
979 void AliTOFtracker::SaveCheckHists() {
981 //write histos for Digits/Reco QA and Calibration
983 TDirectory *dir = gDirectory;
984 TFile *logFileTOF = 0;
986 TSeqCollection *list = gROOT->GetListOfFiles();
987 int n = list->GetEntries();
988 Bool_t isThere=kFALSE;
989 for(int i=0; i<n; i++) {
990 logFileTOF = (TFile*)list->At(i);
991 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
998 AliError(Form("File TOFQA.root not found!! not wring histograms...."));
1002 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
1003 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
1004 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
1005 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
1006 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
1007 fHRecDist->Write(fHRecDist->GetName(), TObject::kOverwrite);
1008 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
1009 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
1010 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
1011 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
1012 fCalTree->Write(fCalTree->GetName(),TObject::kOverwrite);
1013 logFileTOF->Flush();
1017 //_________________________________________________________________________
1018 Float_t AliTOFtracker::CorrectTimeWalk( Float_t dist, Float_t tof) {
1020 //dummy, for the moment
1022 if(dist<AliTOFGeometry::ZPad()*0.5){
1024 //place here the actual correction
1030 //_________________________________________________________________________
1031 Float_t AliTOFtracker::GetTimeZerofromT0(AliESDEvent *event) const {
1033 //Returns TimeZero as measured by T0 detector
1035 return event->GetT0();
1037 //_________________________________________________________________________
1038 Float_t AliTOFtracker::GetTimeZerofromTOF(AliESDEvent * /*event*/) const {
1040 //dummy, for the moment. T0 algorithm using tracks on TOF
1042 //place T0 algo here...
1046 //_________________________________________________________________________
1048 void AliTOFtracker::FillClusterArray(TObjArray* arr) const
1051 // Returns the TOF cluster array
1057 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
1060 //_________________________________________________________________________