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"
42 #include "AliESDpid.h"
44 #include "AliTrackPointArray.h"
45 #include "AliCDBManager.h"
47 //#include "AliTOFpidESD.h"
48 #include "AliTOFRecoParam.h"
49 #include "AliTOFReconstructor.h"
50 #include "AliTOFcluster.h"
51 #include "AliTOFGeometry.h"
52 #include "AliTOFtracker.h"
53 #include "AliTOFtrack.h"
55 extern TGeoManager *gGeoManager;
58 ClassImp(AliTOFtracker)
60 //_____________________________________________________________________________
61 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())){
113 delete fHDigClusTime;
119 delete fHRecSigYVsPWin;
120 delete fHRecSigZVsPWin;
134 //_____________________________________________________________________________
135 void AliTOFtracker::GetPidSettings(AliESDpid *esdPID) {
137 // Sets TOF resolution from RecoParams
140 esdPID->GetTOFResponse().SetTimeResolution(fkRecoParam->GetTimeResolution());
142 AliWarning("fkRecoParam not yet set; cannot set PID settings");
144 //_____________________________________________________________________________
145 Int_t AliTOFtracker::PropagateBack(AliESDEvent * const event) {
147 // Gets seeds from ESD event and Match with TOF Clusters
150 // initialize RecoParam for current event
151 AliDebug(1,"Initializing params for TOF");
153 fkRecoParam = AliTOFReconstructor::GetRecoParam(); // instantiate reco param from STEER...
155 if (fkRecoParam == 0x0) {
156 AliFatal("No Reco Param found for TOF!!!");
158 //fkRecoParam->Dump();
159 //if(fkRecoParam->GetApplyPbPbCuts())fkRecoParam=fkRecoParam->GetPbPbparam();
160 //fkRecoParam->PrintParameters();
162 //Initialise some counters
171 Int_t ntrk=event->GetNumberOfTracks();
173 TClonesArray &aESDTrack = *fSeeds;
176 //Load ESD tracks into a local Array of ESD Seeds
178 for (Int_t i=0; i<fNseeds; i++) {
179 AliESDtrack *t=event->GetTrack(i);
180 new(aESDTrack[i]) AliESDtrack(*t);
183 //Prepare ESD tracks candidates for TOF Matching
186 //First Step with Strict Matching Criterion
189 //Second Step with Looser Matching Criterion
192 AliInfo(Form("Number of matched tracks = %d (good = %d, bad = %d)",fnmatch,fngoodmatch,fnbadmatch));
194 //Update the matched ESD tracks
196 for (Int_t i=0; i<ntrk; i++) {
197 AliESDtrack *t=event->GetTrack(i);
198 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
200 if ( (seed->GetStatus()&AliESDtrack::kTOFin)!=0 ) {
201 t->SetStatus(AliESDtrack::kTOFin);
202 //if(seed->GetTOFsignal()>0){
203 if ( (seed->GetStatus()&AliESDtrack::kTOFout)!=0 ) {
204 t->SetStatus(AliESDtrack::kTOFout);
205 t->SetTOFsignal(seed->GetTOFsignal());
206 t->SetTOFcluster(seed->GetTOFcluster());
207 t->SetTOFsignalToT(seed->GetTOFsignalToT());
208 t->SetTOFsignalRaw(seed->GetTOFsignalRaw());
209 t->SetTOFsignalDz(seed->GetTOFsignalDz());
210 t->SetTOFsignalDx(seed->GetTOFsignalDx());
211 t->SetTOFDeltaBC(seed->GetTOFDeltaBC());
212 t->SetTOFL0L1(seed->GetTOFL0L1());
213 t->SetTOFCalChannel(seed->GetTOFCalChannel());
214 Int_t tlab[3]; seed->GetTOFLabel(tlab);
215 t->SetTOFLabel(tlab);
217 Double_t alphaA = dynamic_cast<AliExternalTrackParam*>(t)->GetAlpha();
218 Double_t xA = dynamic_cast<AliExternalTrackParam*>(t)->GetX();
219 Double_t yA = dynamic_cast<AliExternalTrackParam*>(t)->GetY();
220 Double_t zA = dynamic_cast<AliExternalTrackParam*>(t)->GetZ();
221 Double_t p1A = dynamic_cast<AliExternalTrackParam*>(t)->GetSnp();
222 Double_t p2A = dynamic_cast<AliExternalTrackParam*>(t)->GetTgl();
223 Double_t p3A = dynamic_cast<AliExternalTrackParam*>(t)->GetSigned1Pt();
224 const Double_t *covA = dynamic_cast<AliExternalTrackParam*>(t)->GetCovariance();
226 // Make attention, please:
227 // AliESDtrack::fTOFInfo array does not be stored in the AliESDs.root file
228 // it is there only for a check during the reconstruction step.
229 Float_t info[10]; seed->GetTOFInfo(info);
231 AliDebug(3,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
234 // by calling the AliESDtrack::UpdateTrackParams,
235 // the current track parameters are changed
236 // and it could cause refit problems.
237 // We need to update only the following track parameters:
238 // the track length and expected times.
239 // Removed AliESDtrack::UpdateTrackParams call
240 // Called AliESDtrack::SetIntegratedTimes(...) and
241 // AliESDtrack::SetIntegratedLength() routines.
243 AliTOFtrack *track = new AliTOFtrack(*seed);
244 t->UpdateTrackParams(track,AliESDtrack::kTOFout); // to be checked - AdC
246 Double_t time[10]; t->GetIntegratedTimes(time);
249 Double_t time[10]; seed->GetIntegratedTimes(time);
250 t->SetIntegratedTimes(time);
252 Double_t length = seed->GetIntegratedLength();
253 t->SetIntegratedLength(length);
255 Double_t alphaB = dynamic_cast<AliExternalTrackParam*>(t)->GetAlpha();
256 Double_t xB = dynamic_cast<AliExternalTrackParam*>(t)->GetX();
257 Double_t yB = dynamic_cast<AliExternalTrackParam*>(t)->GetY();
258 Double_t zB = dynamic_cast<AliExternalTrackParam*>(t)->GetZ();
259 Double_t p1B = dynamic_cast<AliExternalTrackParam*>(t)->GetSnp();
260 Double_t p2B = dynamic_cast<AliExternalTrackParam*>(t)->GetTgl();
261 Double_t p3B = dynamic_cast<AliExternalTrackParam*>(t)->GetSigned1Pt();
262 const Double_t *covB = dynamic_cast<AliExternalTrackParam*>(t)->GetCovariance();
263 AliDebug(2,"Track params -now(before)-:");
264 AliDebug(2,Form(" X: %f(%f), Y: %f(%f), Z: %f(%f) --- alpha: %f(%f)",
269 AliDebug(2,Form(" p1: %f(%f), p2: %f(%f), p3: %f(%f)",
273 AliDebug(2,Form(" cov1: %f(%f), cov2: %f(%f), cov3: %f(%f)"
274 " cov4: %f(%f), cov5: %f(%f), cov6: %f(%f)"
275 " cov7: %f(%f), cov8: %f(%f), cov9: %f(%f)"
276 " cov10: %f(%f), cov11: %f(%f), cov12: %f(%f)"
277 " cov13: %f(%f), cov14: %f(%f), cov15: %f(%f)",
294 AliDebug(3,Form(" TOF params: %6d %f %f %f %f %f %6d %3d %f %f %f %f %f %f",
296 t->GetTOFsignalRaw(),
298 t->GetTOFsignalToT(),
301 t->GetTOFCalChannel(),
303 t->GetIntegratedLength(),
304 time[0], time[1], time[2], time[3], time[4]
312 // Now done in AliESDpid
313 // fPid->MakePID(event,timeZero);
320 //_________________________________________________________________________
321 void AliTOFtracker::CollectESD() {
322 //prepare the set of ESD tracks to be matched to clusters in TOF
327 TClonesArray &aTOFTrack = *fTracks;
328 for (Int_t i=0; i<fNseeds; i++) {
330 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
331 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
333 AliTOFtrack *track = new AliTOFtrack(*t); // New
334 Float_t x = (Float_t)track->GetX(); //New
336 // TRD 'good' tracks, already propagated at 371 cm
337 if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
338 ( x >= AliTOFGeometry::Rmin() ) ) {
339 if ( track->PropagateToInnerTOF() ) {
341 AliDebug(1,Form(" TRD propagated track till rho = %fcm."
342 " And then the track has been propagated till rho = %fcm.",
343 x, (Float_t)track->GetX()));
345 track->SetSeedIndex(i);
346 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
347 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
354 // Propagate the rest of TPCbp
356 if ( track->PropagateToInnerTOF() ) {
358 AliDebug(1,Form(" TPC propagated track till rho = %fcm."
359 " And then the track has been propagated till rho = %fcm.",
360 x, (Float_t)track->GetX()));
362 track->SetSeedIndex(i);
363 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
364 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
372 AliInfo(Form("Number of TOF seeds = %d (Type 1 = %d, Type 2 = %d)",fNseedsTOF,seedsTOF1,seedsTOF2));
374 // Sort according uncertainties on track position
378 //_________________________________________________________________________
379 void AliTOFtracker::MatchTracks( Bool_t mLastStep){
382 // Parameters used/regulating the reconstruction
384 static Float_t corrLen=0.75;
385 static Float_t detDepth=15.3;
386 static Float_t padDepth=0.5;
388 const Float_t kSpeedOfLight= 2.99792458e-2; // speed of light [cm/ps]
389 const Float_t kTimeOffset = 32.; // time offset for tracking algorithm [ps]
391 Float_t dY=AliTOFGeometry::XPad();
392 Float_t dZ=AliTOFGeometry::ZPad();
394 Float_t sensRadius = fkRecoParam->GetSensRadius();
395 Float_t stepSize = fkRecoParam->GetStepSize();
396 Float_t scaleFact = fkRecoParam->GetWindowScaleFact();
397 Float_t dyMax=fkRecoParam->GetWindowSizeMaxY();
398 Float_t dzMax=fkRecoParam->GetWindowSizeMaxZ();
399 Float_t dCut=fkRecoParam->GetDistanceCut();
400 Double_t maxChi2=fkRecoParam->GetMaxChi2TRD();
401 Bool_t timeWalkCorr = fkRecoParam->GetTimeWalkCorr();
403 AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++ \n");
404 AliDebug(1,Form("TOF sens radius: %f",sensRadius));
405 AliDebug(1,Form("TOF step size: %f",stepSize));
406 AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
407 AliDebug(1,Form("TOF Window max dy: %f",dyMax));
408 AliDebug(1,Form("TOF Window max dz: %f",dzMax));
409 AliDebug(1,Form("TOF distance Cut: %f",dCut));
410 AliDebug(1,Form("TOF Max Chi2: %f",maxChi2));
411 AliDebug(1,Form("Time Walk Correction? : %d",timeWalkCorr));
414 //Match ESD tracks to clusters in TOF
416 // Get the number of propagation steps
417 Int_t nSteps=(Int_t)(detDepth/stepSize);
419 //PH Arrays (moved outside of the loop)
420 Float_t * trackPos[4];
421 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
422 Int_t * clind = new Int_t[fN];
425 const Int_t kNfoundMax = 10000; // related to nSteps value
426 Int_t index[kNfoundMax];
427 Float_t dist[kNfoundMax];
428 Float_t distZ[kNfoundMax];
429 Float_t distY[kNfoundMax]; // delta(rhoXphi) // AdC
430 Float_t cxpos[kNfoundMax];
431 Float_t crecL[kNfoundMax];
432 const Int_t kNclusterMax = 1000; // related to fN value
433 TGeoHMatrix global[kNclusterMax];
436 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
438 for (Int_t ii=0; ii<kNfoundMax; ii++) {
446 for (Int_t ii=0; ii<kNclusterMax; ii++)
449 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
450 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
451 //if ( t->GetTOFsignal()>0. ) continue;
452 if ( (t->GetStatus()&AliESDtrack::kTOFout)!=0 ) continue;
453 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
455 // Determine a window around the track
457 trackTOFin->GetExternalParameters(x,par);
459 trackTOFin->GetExternalCovariance(cov);
461 if (cov[0]<0. || cov[2]<0.) {
462 AliWarning(Form("Very strange track (%d)! At least one of its covariance matrix diagonal elements is negative!",iseed));
469 ((5*TMath::Sqrt(TMath::Abs(cov[0])) + 0.5*dY + 2.5*TMath::Abs(par[2]))/sensRadius);
472 (5*TMath::Sqrt(TMath::Abs(cov[2])) + 0.5*dZ + 2.5*TMath::Abs(par[3]));
474 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
475 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
476 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
479 //upper limit on window's size.
481 if(dz> dzMax) dz=dzMax;
482 if(dphi*sensRadius> dyMax) dphi=dyMax/sensRadius;
487 // find the clusters in the window of the track
489 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
491 if (nc>=kNclusterMax) {
492 AliWarning("No more matchable clusters can be stored! Please, increase the corresponding vectors size.");
496 AliTOFcluster *c=fClusters[k];
497 if (c->GetZ() > z+dz) break;
498 if (c->IsUsed()) continue;
500 if (!c->GetStatus()) {
501 AliDebug(1,"Cluster in channel declared bad!");
502 continue; // skip bad channels as declared in OCDB
505 Double_t dph=TMath::Abs(c->GetPhi()-phi);
506 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
507 if (TMath::Abs(dph)>dphi) continue;
509 Double_t yc=(c->GetPhi() - trackTOFin->GetAlpha())*c->GetR();
510 Double_t p[2]={yc, c->GetZ()};
511 Double_t cov2[3]= {dY*dY/12., 0., dZ*dZ/12.};
512 if (trackTOFin->AliExternalTrackParam::GetPredictedChi2(p,cov2) > maxChi2)continue;
517 ind[0]=c->GetDetInd(0);
518 ind[1]=c->GetDetInd(1);
519 ind[2]=c->GetDetInd(2);
520 ind[3]=c->GetDetInd(3);
521 ind[4]=c->GetDetInd(4);
522 fGeom->GetVolumePath(ind,path);
523 gGeoManager->cd(path);
524 global[nc] = *gGeoManager->GetCurrentMatrix();
528 AliDebug(1,Form(" Number of matchable TOF clusters for the track number %d: %d",iseed,nc));
530 //start fine propagation
532 Int_t nStepsDone = 0;
533 for( Int_t istep=0; istep<nSteps; istep++){
535 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
536 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
539 Double_t ysect=trackTOFin->GetYat(xs,skip);
542 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
545 } else if (ysect <-ymax) {
546 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
551 if(!trackTOFin->PropagateTo(xs)) {
557 // store the running point (Globalrf) - fine propagation
560 trackTOFin->GetXYZ(r);
561 trackPos[0][istep]= (Float_t) r[0];
562 trackPos[1][istep]= (Float_t) r[1];
563 trackPos[2][istep]= (Float_t) r[2];
564 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
569 Bool_t accept = kFALSE;
570 Bool_t isInside = kFALSE;
571 for (Int_t istep=0; istep<nStepsDone; istep++) {
573 if (nfound>=kNfoundMax) {
574 AliWarning("No more track positions can be stored! Please, increase the corresponding vectors size.");
578 Float_t ctrackPos[3];
579 ctrackPos[0] = trackPos[0][istep];
580 ctrackPos[1] = trackPos[1][istep];
581 ctrackPos[2] = trackPos[2][istep];
583 //now see whether the track matches any of the TOF clusters
587 for (Int_t i=0; i<nc; i++) {
588 isInside = fGeom->IsInsideThePad(global[i],ctrackPos,dist3d);
591 Float_t yLoc = dist3d[1];
592 Float_t rLoc = TMath::Sqrt(dist3d[0]*dist3d[0]+dist3d[2]*dist3d[2]);
593 accept = (TMath::Abs(yLoc)<padDepth*0.5 && rLoc<dCut);
594 AliDebug(2," I am in the case mLastStep==kTRUE ");
601 dist[nfound] = TMath::Sqrt(dist3d[0]*dist3d[0] +
602 dist3d[1]*dist3d[1] +
603 dist3d[2]*dist3d[2]);
604 AliDebug(2,Form(" dist3dLoc[0] = %f, dist3dLoc[1] = %f, dist3dLoc[2] = %f ",
605 dist3d[0],dist3d[1],dist3d[2]));
606 distZ[nfound] = dist3d[2]; // Z distance in the RF of the
607 // hit pad closest to the
608 // reconstructed track
609 distY[nfound] = dist3d[0]; // X distance in the RF of the
610 // hit pad closest to the
611 // reconstructed track
612 // It corresponds to Y coordinate
616 AliDebug(2,Form(" dist3dLoc[0] = %f --- distY[%d] = %f",
617 dist3d[0],nfound,distY[nfound]));
618 AliDebug(2,Form(" dist3dLoc[2] = %f --- distZ[%d] = %f",
619 dist3d[2],nfound,distZ[nfound]));
622 crecL[nfound] = trackPos[3][istep];
623 index[nfound] = clind[i]; // store cluster id
624 cxpos[nfound] = AliTOFGeometry::RinTOF()+istep*0.1; //store prop.radius
626 if(accept &&!mLastStep)break;
629 } //end for on the clusters
630 if(accept &&!mLastStep)break;
631 } //end for on the steps
633 AliDebug(1,Form(" Number of track points for the track number %d: %d",iseed,nfound));
644 // now choose the cluster to be matched with the track.
649 Float_t mindist=1000.;
652 for (Int_t iclus= 0; iclus<nfound;iclus++){
653 if (dist[iclus]< mindist){
654 mindist = dist[iclus];
655 mindistZ = distZ[iclus]; // Z distance in the RF of the hit
656 // pad closest to the reconstructed
658 mindistY = distY[iclus]; // Y distance in the RF of the hit
659 // pad closest to the reconstructed
662 idclus =index[iclus];
663 recL=crecL[iclus]+corrLen*0.5;
668 AliTOFcluster *c=fClusters[idclus];
670 Float_t tiltangle = AliTOFGeometry::GetAngles(c->GetDetInd(1),c->GetDetInd(2))*TMath::DegToRad();
671 Float_t localCheck=-mindistZ;
672 localCheck/=TMath::Cos(tiltangle); // Z (tracking/ALICE RF) component of
673 // the distance between the
674 // reconstructed track and the
675 // TOF closest cluster
677 AliDebug(2, Form("%7d %7d %10d %10d %10d %10d %7d",
680 TMath::Abs(trackTOFin->GetLabel()),
681 c->GetLabel(0), c->GetLabel(1), c->GetLabel(2),
686 // Track length correction for matching Step 2
689 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
690 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
691 +trackPos[1][70]*trackPos[1][70]
692 +trackPos[2][70]*trackPos[2][70]);
694 recL=trackPos[3][70]+dlt;
698 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
700 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
702 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
706 AliDebug(2,Form(" track label good %5d",trackTOFin->GetLabel()));
712 AliDebug(2,Form(" track label bad %5d",trackTOFin->GetLabel()));
718 // Store quantities to be used in the TOF Calibration
719 Float_t tToT=AliTOFGeometry::ToTBinWidth()*c->GetToT()*1E-3; // in ns
720 t->SetTOFsignalToT(tToT);
721 Float_t rawTime=AliTOFGeometry::TdcBinWidth()*c->GetTDCRAW()+kTimeOffset; // RAW time,in ps
722 t->SetTOFsignalRaw(rawTime);
723 t->SetTOFsignalDz(mindistZ);
724 t->SetTOFsignalDx(mindistY);
725 t->SetTOFDeltaBC(c->GetDeltaBC());
726 t->SetTOFL0L1(c->GetL0L1Latency());
728 Float_t info[10] = {mindist,mindistY,mindistZ,
729 0.,0.,0.,0.,0.,0.,0.};
731 AliDebug(2,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
735 ind[0]=c->GetDetInd(0);
736 ind[1]=c->GetDetInd(1);
737 ind[2]=c->GetDetInd(2);
738 ind[3]=c->GetDetInd(3);
739 ind[4]=c->GetDetInd(4);
740 Int_t calindex = AliTOFGeometry::GetIndex(ind);
741 t->SetTOFCalChannel(calindex);
743 // keep track of the track labels in the matched cluster
745 tlab[0]=c->GetLabel(0);
746 tlab[1]=c->GetLabel(1);
747 tlab[2]=c->GetLabel(2);
748 AliDebug(2,Form(" tdc time of the matched track %6d = ",c->GetTDC()));
749 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+kTimeOffset; // in ps
750 AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
751 Double_t tofcorr=tof;
752 if(timeWalkCorr)tofcorr=CorrectTimeWalk(mindistZ,tof);
753 AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));
754 //Set TOF time signal and pointer to the matched cluster
755 t->SetTOFsignal(tofcorr);
756 t->SetTOFcluster(idclus); // pointing to the recPoints tree
758 AliDebug(2,Form(" Setting TOF raw time: %f, z distance: %f corrected time: %f ",rawTime,mindistZ,tofcorr));
761 Double_t time[AliPID::kSPECIES]; t->GetIntegratedTimes(time); // in ps
762 Double_t mom=t->GetP();
763 AliDebug(2,Form(" Momentum for track %d -> %f", iseed,mom));
764 for (Int_t j=0;j<AliPID::kSPECIES;j++) {
765 Double_t mass=AliPID::ParticleMass(j);
766 time[j]+=(recL-trackPos[3][0])/kSpeedOfLight*TMath::Sqrt(mom*mom+mass*mass)/mom;
769 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
770 trackTOFout->PropagateTo(xpos);
772 // Fill the track residual histograms.
773 FillResiduals(trackTOFout,c,kFALSE);
775 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
776 t->SetIntegratedLength(recL);
777 t->SetIntegratedTimes(time);
778 t->SetTOFLabel(tlab);
781 // Fill Reco-QA histos for Reconstruction
782 fHRecNClus->Fill(nc);
783 fHRecDist->Fill(mindist);
784 fHRecSigYVsP->Fill(mom,TMath::Sqrt(cov[0]));
785 fHRecSigZVsP->Fill(mom,TMath::Sqrt(cov[2]));
786 fHRecSigYVsPWin->Fill(mom,dphi*sensRadius);
787 fHRecSigZVsPWin->Fill(mom,dz);
789 // Fill Tree for on-the-fly offline Calibration
791 if ( !((t->GetStatus() & AliESDtrack::kTIME)==0 ) ) {
802 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
806 //_________________________________________________________________________
807 Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
808 //--------------------------------------------------------------------
809 //This function loads the TOF clusters
810 //--------------------------------------------------------------------
812 Int_t npadX = AliTOFGeometry::NpadX();
813 Int_t npadZ = AliTOFGeometry::NpadZ();
814 Int_t nStripA = AliTOFGeometry::NStripA();
815 Int_t nStripB = AliTOFGeometry::NStripB();
816 Int_t nStripC = AliTOFGeometry::NStripC();
818 TBranch *branch=cTree->GetBranch("TOF");
820 AliError("can't get the branch with the TOF clusters !");
824 static TClonesArray dummy("AliTOFcluster",10000);
826 TClonesArray *clusters=&dummy;
827 branch->SetAddress(&clusters);
830 Int_t nc=clusters->GetEntriesFast();
831 fHDigNClus->Fill(nc);
833 AliInfo(Form("Number of clusters: %d",nc));
835 for (Int_t i=0; i<nc; i++) {
836 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
837 //PH fClusters[i]=new AliTOFcluster(*c); fN++;
838 fClusters[i]=c; fN++;
840 // Fill Digits QA histos
842 Int_t isector = c->GetDetInd(0);
843 Int_t iplate = c->GetDetInd(1);
844 Int_t istrip = c->GetDetInd(2);
845 Int_t ipadX = c->GetDetInd(4);
846 Int_t ipadZ = c->GetDetInd(3);
848 Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
849 Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
851 Int_t stripOffset = 0;
857 stripOffset = nStripC;
860 stripOffset = nStripC+nStripB;
863 stripOffset = nStripC+nStripB+nStripA;
866 stripOffset = nStripC+nStripB+nStripA+nStripB;
869 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
872 Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
873 Int_t phiindex=npadX*isector+ipadX+1;
874 fHDigClusMap->Fill(zindex,phiindex);
875 fHDigClusTime->Fill(time);
876 fHDigClusToT->Fill(tot);
883 //_________________________________________________________________________
884 void AliTOFtracker::UnloadClusters() {
885 //--------------------------------------------------------------------
886 //This function unloads TOF clusters
887 //--------------------------------------------------------------------
888 for (Int_t i=0; i<fN; i++) {
889 //PH delete fClusters[i];
895 //_________________________________________________________________________
896 Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
897 //--------------------------------------------------------------------
898 // This function returns the index of the nearest cluster
899 //--------------------------------------------------------------------
901 if (z <= fClusters[0]->GetZ()) return 0;
902 if (z > fClusters[fN-1]->GetZ()) return fN;
903 Int_t b=0, e=fN-1, m=(b+e)/2;
904 for (; b<e; m=(b+e)/2) {
905 if (z > fClusters[m]->GetZ()) b=m+1;
911 //_________________________________________________________________________
912 Bool_t AliTOFtracker::GetTrackPoint(Int_t index, AliTrackPoint& p) const
914 // Get track space point with index i
915 // Coordinates are in the global system
916 AliTOFcluster *cl = fClusters[index];
918 xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
919 xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
921 Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
922 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
923 Float_t tiltangle = AliTOFGeometry::GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
924 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
925 Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
926 Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
928 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
929 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
930 cov[2] = -cosphi*sinth*costh*sigmaz2;
931 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
932 cov[4] = -sinphi*sinth*costh*sigmaz2;
933 cov[5] = costh*costh*sigmaz2;
934 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
936 // Detector numbering scheme
937 Int_t nSector = AliTOFGeometry::NSectors();
938 Int_t nPlate = AliTOFGeometry::NPlates();
939 Int_t nStripA = AliTOFGeometry::NStripA();
940 Int_t nStripB = AliTOFGeometry::NStripB();
941 Int_t nStripC = AliTOFGeometry::NStripC();
943 Int_t isector = cl->GetDetInd(0);
944 if (isector >= nSector)
945 AliError(Form("Wrong sector number in TOF (%d) !",isector));
946 Int_t iplate = cl->GetDetInd(1);
947 if (iplate >= nPlate)
948 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
949 Int_t istrip = cl->GetDetInd(2);
951 Int_t stripOffset = 0;
957 stripOffset = nStripC;
960 stripOffset = nStripC+nStripB;
963 stripOffset = nStripC+nStripB+nStripA;
966 stripOffset = nStripC+nStripB+nStripA+nStripB;
969 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
973 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
976 UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
977 p.SetVolumeID((UShort_t)volid);
980 //_________________________________________________________________________
981 void AliTOFtracker::InitCheckHists() {
983 //Init histos for Digits/Reco QA and Calibration
986 TDirectory *dir = gDirectory;
987 TFile *logFileTOF = 0;
989 TSeqCollection *list = gROOT->GetListOfFiles();
990 int n = list->GetEntries();
991 Bool_t isThere=kFALSE;
992 for(int i=0; i<n; i++) {
993 logFileTOF = (TFile*)list->At(i);
994 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
1000 if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
1003 fCalTree = new TTree("CalTree", "Tree for TOF calibration");
1004 fCalTree->Branch("TOFchannelindex",&fIch,"iTOFch/I");
1005 fCalTree->Branch("ToT",&fToT,"TOFToT/F");
1006 fCalTree->Branch("TOFtime",&fTime,"TOFtime/F");
1007 fCalTree->Branch("PionExpTime",&fExpTimePi,"PiExpTime/F");
1008 fCalTree->Branch("KaonExpTime",&fExpTimeKa,"KaExpTime/F");
1009 fCalTree->Branch("ProtonExpTime",&fExpTimePr,"PrExpTime/F");
1012 fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);
1013 fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);
1014 fHDigClusTime = new TH1F("TOFDig_ClusTime", "",2000,0.,200.);
1015 fHDigClusToT = new TH1F("TOFDig_ClusToT", "",500,0.,100);
1018 fHRecNClus =new TH1F("TOFRec_NClusW", "",50,0.5,50.5);
1019 fHRecDist=new TH1F("TOFRec_Dist", "",50,0.5,10.5);
1020 fHRecSigYVsP=new TH2F("TOFDig_SigYVsP", "",40,0.,4.,100, 0.,5.);
1021 fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
1022 fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
1023 fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
1029 //_________________________________________________________________________
1030 void AliTOFtracker::SaveCheckHists() {
1032 //write histos for Digits/Reco QA and Calibration
1034 TDirectory *dir = gDirectory;
1035 TFile *logFileTOF = 0;
1037 TSeqCollection *list = gROOT->GetListOfFiles();
1038 int n = list->GetEntries();
1039 Bool_t isThere=kFALSE;
1040 for(int i=0; i<n; i++) {
1041 logFileTOF = (TFile*)list->At(i);
1042 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
1049 AliError(Form("File TOFQA.root not found!! not wring histograms...."));
1053 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
1054 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
1055 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
1056 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
1057 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
1058 fHRecDist->Write(fHRecDist->GetName(), TObject::kOverwrite);
1059 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
1060 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
1061 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
1062 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
1063 fCalTree->Write(fCalTree->GetName(),TObject::kOverwrite);
1064 logFileTOF->Flush();
1068 //_________________________________________________________________________
1069 Float_t AliTOFtracker::CorrectTimeWalk( Float_t dist, Float_t tof) const {
1071 //dummy, for the moment
1073 if(dist<AliTOFGeometry::ZPad()*0.5){
1075 //place here the actual correction
1081 //_________________________________________________________________________
1083 void AliTOFtracker::FillClusterArray(TObjArray* arr) const
1086 // Returns the TOF cluster array
1092 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
1095 //_________________________________________________________________________