]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFtracker.cxx
Changed default values of cuts
[u/mrichter/AliRoot.git] / TOF / AliTOFtracker.cxx
CommitLineData
596a855f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
0e46b9ae 15
16//--------------------------------------------------------------------//
17// //
18// AliTOFtracker Class //
19// Task: Perform association of the ESD tracks to TOF Clusters //
20// and Update ESD track with associated TOF Cluster parameters //
21// //
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 //
26// //
27//--------------------------------------------------------------------//
28
08048cd3 29#include <Rtypes.h>
30#include <TROOT.h>
571dda3d 31
5c7c93fa 32#include <TSeqCollection.h>
08048cd3 33#include <TClonesArray.h>
34#include <TGeoManager.h>
35#include <TTree.h>
36#include <TFile.h>
37#include <TH2F.h>
571dda3d 38
5c7c93fa 39#include "AliGeomManager.h"
0e46b9ae 40#include "AliESDtrack.h"
af885e0f 41#include "AliESDEvent.h"
d076c8d5 42#include "AliLog.h"
0e46b9ae 43#include "AliTrackPointArray.h"
5c7c93fa 44#include "AliCDBManager.h"
596a855f 45
5c7c93fa 46#include "AliTOFpidESD.h"
e0ddb533 47#include "AliTOFRecoParam.h"
3a646035 48#include "AliTOFReconstructor.h"
571dda3d 49#include "AliTOFcluster.h"
ba66add8 50#include "AliTOFGeometry.h"
571dda3d 51#include "AliTOFtracker.h"
0e46b9ae 52#include "AliTOFtrack.h"
571dda3d 53
0e46b9ae 54extern TGeoManager *gGeoManager;
d200609f 55extern TROOT *gROOT;
d4754572 56
596a855f 57ClassImp(AliTOFtracker)
58
74ea065c 59//_____________________________________________________________________________
e0ddb533 60AliTOFtracker::AliTOFtracker():
61 fRecoParam(0x0),
62 fGeom(0x0),
63 fPid(0x0),
58d8d9a3 64 fN(0),
65 fNseeds(0),
66 fNseedsTOF(0),
67 fngoodmatch(0),
68 fnbadmatch(0),
69 fnunmatch(0),
70 fnmatch(0),
9d802709 71 fTracks(new TClonesArray("AliTOFtrack")),
72 fSeeds(new TClonesArray("AliESDtrack")),
5664c6ed 73 fHDigClusMap(0x0),
74 fHDigNClus(0x0),
75 fHDigClusTime(0x0),
76 fHDigClusToT(0x0),
77 fHRecNClus(0x0),
78 fHRecDist(0x0),
79 fHRecSigYVsP(0x0),
80 fHRecSigZVsP(0x0),
81 fHRecSigYVsPWin(0x0),
82 fHRecSigZVsPWin(0x0),
83 fCalTree(0x0),
84 fIch(-1),
85 fToT(-1.),
86 fTime(-1.),
87 fExpTimePi(-1.),
88 fExpTimeKa(-1.),
89 fExpTimePr(-1.)
58d8d9a3 90 {
74ea065c 91 //AliTOFtracker main Ctor
e0ddb533 92
91219c0b 93 // Gettimg the geometry
ba66add8 94 fGeom= new AliTOFGeometry();
3a646035 95
e0ddb533 96 InitCheckHists();
3a646035 97
7aeeaf38 98}
5664c6ed 99//_____________________________________________________________________________
100AliTOFtracker::~AliTOFtracker() {
101 //
102 // Dtor
103 //
e0ddb533 104
5664c6ed 105 SaveCheckHists();
e0ddb533 106
5d456bcd 107 if(!(AliCDBManager::Instance()->GetCacheFlag())){
108 delete fRecoParam;
109 }
e0ddb533 110 delete fGeom;
111 delete fPid;
5664c6ed 112 delete fHDigClusMap;
113 delete fHDigNClus;
114 delete fHDigClusTime;
115 delete fHDigClusToT;
116 delete fHRecNClus;
117 delete fHRecDist;
118 delete fHRecSigYVsP;
119 delete fHRecSigZVsP;
120 delete fHRecSigYVsPWin;
121 delete fHRecSigZVsPWin;
122 delete fCalTree;
9d802709 123 if (fTracks){
124 fTracks->Delete();
125 delete fTracks;
126 fTracks=0x0;
127 }
128 if (fSeeds){
129 fSeeds->Delete();
130 delete fSeeds;
131 fSeeds=0x0;
132 }
133
5664c6ed 134}
74ea065c 135//_____________________________________________________________________________
af885e0f 136Int_t AliTOFtracker::PropagateBack(AliESDEvent* event) {
74ea065c 137 //
138 // Gets seeds from ESD event and Match with TOF Clusters
139 //
140
3a646035 141 // initialize RecoParam for current event
142
143 AliInfo("Initializing params for TOF... ");
144
145 fRecoParam = AliTOFReconstructor::GetRecoParam(); // instantiate reco param from STEER...
90b234fe 146
3a646035 147 if (fRecoParam == 0x0) {
148 AliFatal("No Reco Param found for TOF!!!");
149 }
150 //fRecoParam->Dump();
a825d829 151 //if(fRecoParam->GetApplyPbPbCuts())fRecoParam=fRecoParam->GetPbPbparam();
90b234fe 152 //fRecoParam->PrintParameters();
153
3a646035 154 Double_t parPID[2];
155 parPID[0]=fRecoParam->GetTimeResolution();
156 parPID[1]=fRecoParam->GetTimeNSigma();
157 fPid=new AliTOFpidESD(parPID);
74ea065c 158
159 //Initialise some counters
160
161 fNseeds=0;
162 fNseedsTOF=0;
163 fngoodmatch=0;
164 fnbadmatch=0;
165 fnunmatch=0;
166 fnmatch=0;
167
168 Int_t ntrk=event->GetNumberOfTracks();
169 fNseeds = ntrk;
74ea065c 170 TClonesArray &aESDTrack = *fSeeds;
171
172
173 //Load ESD tracks into a local Array of ESD Seeds
174
175 for (Int_t i=0; i<fNseeds; i++) {
176 AliESDtrack *t=event->GetTrack(i);
177 new(aESDTrack[i]) AliESDtrack(*t);
178 }
179
180 //Prepare ESD tracks candidates for TOF Matching
181 CollectESD();
182
183 //First Step with Strict Matching Criterion
184 MatchTracks(kFALSE);
185
186 //Second Step with Looser Matching Criterion
187 MatchTracks(kTRUE);
188
d076c8d5 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));
74ea065c 192
193 //Update the matched ESD tracks
194
195 for (Int_t i=0; i<ntrk; i++) {
196 AliESDtrack *t=event->GetTrack(i);
197 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
ff826920 198
af61c656 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());
46d7d82e 209 t->SetTOFsignalDx(seed->GetTOFsignalDx());
af61c656 210 t->SetTOFCalChannel(seed->GetTOFCalChannel());
211 Int_t tlab[3]; seed->GetTOFLabel(tlab);
212 t->SetTOFLabel(tlab);
213
24322e5c 214 Float_t info[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
215 seed->GetTOFInfo(info);
216 t->SetTOFInfo(info);
217 AliDebug(2,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
218
af61c656 219 AliTOFtrack *track = new AliTOFtrack(*seed);
220 t->UpdateTrackParams(track,AliESDtrack::kTOFout); // to be checked - AdC
221 delete track;
222 Double_t time[10]; t->GetIntegratedTimes(time);
46d7d82e 223 AliDebug(2,Form(" %6d %f %f %f %f %f %6d %3d %f %f %f %f %f %f",
af61c656 224 i,
225 t->GetTOFsignalRaw(),
226 t->GetTOFsignal(),
227 t->GetTOFsignalToT(),
228 t->GetTOFsignalDz(),
46d7d82e 229 t->GetTOFsignalDx(),
af61c656 230 t->GetTOFCalChannel(),
231 t->GetTOFcluster(),
232 t->GetIntegratedLength(),
233 time[0], time[1], time[2], time[3], time[4]
234 )
235 );
236 }
74ea065c 237 }
238 }
239
e0ddb533 240 //Handle Time Zero information
91219c0b 241
e0ddb533 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();
91219c0b 247
53884c34 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));
e0ddb533 251
252 if(usetimeZero){
253 if(timeZeroFromT0){
254 timeZero=GetTimeZerofromT0(event);
255 }
256 if(timeZeroFromTOF && (timeZero>timeZeroMax || !timeZeroFromT0)){
257 timeZero=GetTimeZerofromTOF(event);
258 }
259 }
260 AliDebug(2,Form("time Zero used in PID: %f",timeZero));
74ea065c 261 //Make TOF PID
e0ddb533 262 fPid->MakePID(event,timeZero);
74ea065c 263
9d802709 264 fSeeds->Clear();
265 fTracks->Clear();
74ea065c 266 return 0;
267
268}
269//_________________________________________________________________________
270void AliTOFtracker::CollectESD() {
271 //prepare the set of ESD tracks to be matched to clusters in TOF
5478df1f 272
273 Int_t seedsTOF1=0;
274 Int_t seedsTOF2=0;
74ea065c 275
74ea065c 276 TClonesArray &aTOFTrack = *fTracks;
277 for (Int_t i=0; i<fNseeds; i++) {
278
279 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
280 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
281
56da420e 282 AliTOFtrack *track = new AliTOFtrack(*t); // New
af61c656 283 Float_t x = (Float_t)track->GetX(); //New
284
285 // TRD 'good' tracks, already propagated at 371 cm
286 if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
287 ( x >= AliTOFGeometry::Rmin() ) ) {
288 if ( track->PropagateToInnerTOF() ) {
289
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()));
293
294 track->SetSeedIndex(i);
295 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
296 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
297 fNseedsTOF++;
298 seedsTOF1++;
299 }
74ea065c 300 delete track;
301 }
302
303 // Propagate the rest of TPCbp
74ea065c 304 else {
af61c656 305 if ( track->PropagateToInnerTOF() ) {
306
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()));
310
74ea065c 311 track->SetSeedIndex(i);
af61c656 312 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
74ea065c 313 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
314 fNseedsTOF++;
5478df1f 315 seedsTOF2++;
74ea065c 316 }
317 delete track;
318 }
319 }
320
6819758a 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));
7b61cd9c 324
74ea065c 325 // Sort according uncertainties on track position
326 fTracks->Sort();
327
328}
329//_________________________________________________________________________
330void AliTOFtracker::MatchTracks( Bool_t mLastStep){
331
e0ddb533 332
333 // Parameters used/regulating the reconstruction
334
335 static Float_t corrLen=0.75;
336 static Float_t detDepth=15.3;
d01bf4f4 337 static Float_t padDepth=0.5;
e0ddb533 338
6819758a 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]
341
ba66add8 342 Float_t dY=AliTOFGeometry::XPad();
343 Float_t dZ=AliTOFGeometry::ZPad();
e0ddb533 344
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();
ac359ffe 351 Double_t maxChi2=fRecoParam->GetMaxChi2TRD();
e0ddb533 352 Bool_t timeWalkCorr = fRecoParam->GetTimeWalkCorr();
a838421b 353 if(!mLastStep){
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));
363 }
74ea065c 364
53884c34 365 //Match ESD tracks to clusters in TOF
a533f541 366
e0ddb533 367 // Get the number of propagation steps
e0ddb533 368 Int_t nSteps=(Int_t)(detDepth/stepSize);
7bf28302 369
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];
128563f6 373 Int_t * clind = new Int_t[fN];
74ea065c 374
53884c34 375 // Some init
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];
24322e5c 380 Float_t distY[kNfoundMax]; // delta(rhoXphi) // AdC
53884c34 381 Float_t cxpos[kNfoundMax];
382 Float_t crecL[kNfoundMax];
383 const Int_t kNclusterMax = 1000; // related to fN value
384 TGeoHMatrix global[kNclusterMax];
385
af61c656 386 //The matching loop
c0545837 387 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
74ea065c 388
53884c34 389 for (Int_t ii=0; ii<kNfoundMax; ii++) {
390 index[ii] = -1;
391 dist[ii] = 9999.;
392 distZ[ii] = 9999.;
24322e5c 393 distY[ii] = 9999.;
53884c34 394 cxpos[ii] = 9999.;
395 crecL[ii] = 0.;
396 }
397 for (Int_t ii=0; ii<kNclusterMax; ii++)
398 global[ii] = 0x0;
399
c0545837 400 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
74ea065c 401 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
af61c656 402 //if ( t->GetTOFsignal()>0. ) continue;
403 if ( (t->GetStatus()&AliESDtrack::kTOFout)!=0 ) continue;
74ea065c 404 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
74ea065c 405
74ea065c 406 // Determine a window around the track
74ea065c 407 Double_t x,par[5];
408 trackTOFin->GetExternalParameters(x,par);
409 Double_t cov[15];
410 trackTOFin->GetExternalCovariance(cov);
6c94f330 411
53884c34 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));
ecd795d8 414 //delete trackTOFin;
415 //continue;
53884c34 416 }
417
74ea065c 418 Double_t dphi=
e0ddb533 419 scaleFact*
ecd795d8 420 ((5*TMath::Sqrt(TMath::Abs(cov[0])) + 0.5*dY + 2.5*TMath::Abs(par[2]))/sensRadius);
74ea065c 421 Double_t dz=
e0ddb533 422 scaleFact*
ecd795d8 423 (5*TMath::Sqrt(TMath::Abs(cov[2])) + 0.5*dZ + 2.5*TMath::Abs(par[3]));
6c94f330 424
74ea065c 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();
428 Double_t z=par[1];
429
c0545837 430 //upper limit on window's size.
431
e0ddb533 432 if(dz> dzMax) dz=dzMax;
433 if(dphi*sensRadius> dyMax) dphi=dyMax/sensRadius;
c0545837 434
435
74ea065c 436 Int_t nc=0;
7b61cd9c 437
74ea065c 438 // find the clusters in the window of the track
439
440 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
7b61cd9c 441
53884c34 442 if (nc>=kNclusterMax) {
443 AliWarning("No more matchable clusters can be stored! Please, increase the corresponding vectors size.");
444 break;
445 }
446
74ea065c 447 AliTOFcluster *c=fClusters[k];
448 if (c->GetZ() > z+dz) break;
449 if (c->IsUsed()) continue;
11c7ff68 450
17149e6b 451 if (!c->GetStatus()) {
53884c34 452 AliDebug(1,"Cluster in channel declared bad!");
453 continue; // skip bad channels as declared in OCDB
17149e6b 454 }
7b61cd9c 455
74ea065c 456 Double_t dph=TMath::Abs(c->GetPhi()-phi);
457 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
9b49e4c9 458 if (TMath::Abs(dph)>dphi) continue;
ba66add8 459
6c94f330 460 Double_t yc=(c->GetPhi() - trackTOFin->GetAlpha())*c->GetR();
461 Double_t p[2]={yc, c->GetZ()};
3c609b5c 462 Double_t cov2[3]= {dY*dY/12., 0., dZ*dZ/12.};
463 if (trackTOFin->AliExternalTrackParam::GetPredictedChi2(p,cov2) > maxChi2)continue;
6c94f330 464
128563f6 465 clind[nc] = k;
c0545837 466 Char_t path[100];
467 Int_t ind[5];
128563f6 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);
c0545837 473 fGeom->GetVolumePath(ind,path);
474 gGeoManager->cd(path);
475 global[nc] = *gGeoManager->GetCurrentMatrix();
74ea065c 476 nc++;
477 }
478
53884c34 479 AliDebug(1,Form(" Number of matchable TOF clusters for the track number %d: %d",iseed,nc));
480
74ea065c 481 //start fine propagation
482
483 Int_t nStepsDone = 0;
484 for( Int_t istep=0; istep<nSteps; istep++){
485
ba66add8 486 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
487 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
74ea065c 488
489 Bool_t skip=kFALSE;
490 Double_t ysect=trackTOFin->GetYat(xs,skip);
6c94f330 491 if (skip) break;
74ea065c 492 if (ysect > ymax) {
ba66add8 493 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
74ea065c 494 break;
495 }
496 } else if (ysect <-ymax) {
13c769b4 497 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
74ea065c 498 break;
499 }
500 }
501
502 if(!trackTOFin->PropagateTo(xs)) {
503 break;
504 }
505
506 nStepsDone++;
507
508 // store the running point (Globalrf) - fine propagation
509
6c94f330 510 Double_t r[3];
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];
74ea065c 515 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
516 }
517
518
519 Int_t nfound = 0;
d01bf4f4 520 Bool_t accept = kFALSE;
6819758a 521 Bool_t isInside = kFALSE;
74ea065c 522 for (Int_t istep=0; istep<nStepsDone; istep++) {
523
53884c34 524 if (nfound>=kNfoundMax) {
525 AliWarning("No more track positions can be stored! Please, increase the corresponding vectors size.");
526 break;
527 }
74ea065c 528
53884c34 529 Float_t ctrackPos[3];
ff826920 530 ctrackPos[0] = trackPos[0][istep];
531 ctrackPos[1] = trackPos[1][istep];
532 ctrackPos[2] = trackPos[2][istep];
74ea065c 533
534 //now see whether the track matches any of the TOF clusters
535
524da123 536 Float_t dist3d[3];
ff826920 537 accept = kFALSE;
538 for (Int_t i=0; i<nc; i++) {
524da123 539 isInside = fGeom->IsInsideThePad(global[i],ctrackPos,dist3d);
d01bf4f4 540
6819758a 541 if ( mLastStep ) {
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 ");
d01bf4f4 546 }
ff826920 547 else {
d01bf4f4 548 accept = isInside;
549 }
ff826920 550 if (accept) {
6819758a 551
552 dist[nfound] = TMath::Sqrt(dist3d[0]*dist3d[0] +
553 dist3d[1]*dist3d[1] +
554 dist3d[2]*dist3d[2]);
53884c34 555 AliDebug(2,Form(" dist3dLoc[0] = %f, dist3dLoc[1] = %f, dist3dLoc[2] = %f ",
6819758a 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
24322e5c 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
564 // in tracking RF
565
6819758a 566
24322e5c 567 AliDebug(2,Form(" dist3dLoc[0] = %f --- distY[%d] = %f",
568 dist3d[0],nfound,distY[nfound]));
53884c34 569 AliDebug(2,Form(" dist3dLoc[2] = %f --- distZ[%d] = %f",
6819758a 570 dist3d[2],nfound,distZ[nfound]));
571
24322e5c 572
ff826920 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
74ea065c 576 nfound++;
d01bf4f4 577 if(accept &&!mLastStep)break;
74ea065c 578 }//end if accept
524da123 579
74ea065c 580 } //end for on the clusters
d01bf4f4 581 if(accept &&!mLastStep)break;
74ea065c 582 } //end for on the steps
583
53884c34 584 AliDebug(1,Form(" Number of track points for the track number %d: %d",iseed,nfound));
9b49e4c9 585
586
74ea065c 587 if (nfound == 0 ) {
588 fnunmatch++;
7bf28302 589 delete trackTOFin;
74ea065c 590 continue;
591 }
592
593 fnmatch++;
594
595 // now choose the cluster to be matched with the track.
596
90b234fe 597 Int_t idclus=-1;
74ea065c 598 Float_t recL = 0.;
599 Float_t xpos=0.;
600 Float_t mindist=1000.;
e0ddb533 601 Float_t mindistZ=0.;
24322e5c 602 Float_t mindistY=0.;
74ea065c 603 for (Int_t iclus= 0; iclus<nfound;iclus++){
604 if (dist[iclus]< mindist){
605 mindist = dist[iclus];
6819758a 606 mindistZ = distZ[iclus]; // Z distance in the RF of the hit
607 // pad closest to the reconstructed
608 // track
24322e5c 609 mindistY = distY[iclus]; // Y distance in the RF of the hit
610 // pad closest to the reconstructed
611 // track
74ea065c 612 xpos = cxpos[iclus];
613 idclus =index[iclus];
e0ddb533 614 recL=crecL[iclus]+corrLen*0.5;
74ea065c 615 }
616 }
617
d01bf4f4 618
74ea065c 619 AliTOFcluster *c=fClusters[idclus];
6819758a 620 /*
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
627 */
628 AliDebug(2, Form("%7d %7d %10d %10d %10d %10d %7d",
32ead898 629 iseed,
3a646035 630 fnmatch-1,
32ead898 631 TMath::Abs(trackTOFin->GetLabel()),
632 c->GetLabel(0), c->GetLabel(1), c->GetLabel(2),
633 idclus)); // AdC
634
e0ddb533 635 c->Use();
74ea065c 636
637 // Track length correction for matching Step 2
638
639 if(mLastStep){
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]);
644 Float_t dlt=rc-rt;
645 recL=trackPos[3][70]+dlt;
646 }
647
648 if (
649 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
650 ||
651 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
652 ||
653 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
654 ) {
655 fngoodmatch++;
d3c7bfac 656
6819758a 657 AliDebug(2,Form(" track label good %5d",trackTOFin->GetLabel()));
d3c7bfac 658
74ea065c 659 }
53884c34 660 else {
74ea065c 661 fnbadmatch++;
d3c7bfac 662
6819758a 663 AliDebug(2,Form(" track label bad %5d",trackTOFin->GetLabel()));
d3c7bfac 664
74ea065c 665 }
666
667 delete trackTOFin;
668
a533f541 669 // Store quantities to be used in the TOF Calibration
ba66add8 670 Float_t tToT=AliTOFGeometry::ToTBinWidth()*c->GetToT()*1E-3; // in ns
7aeeaf38 671 t->SetTOFsignalToT(tToT);
6819758a 672 Float_t rawTime=AliTOFGeometry::TdcBinWidth()*c->GetTDCRAW()+kTimeOffset; // RAW time,in ps
d321691a 673 t->SetTOFsignalRaw(rawTime);
674 t->SetTOFsignalDz(mindistZ);
46d7d82e 675 t->SetTOFsignalDx(mindistY);
6819758a 676
24322e5c 677 Float_t info[10] = {mindist,mindistY,mindistZ,
678 0.,0.,0.,0.,0.,0.,0.};
679 t->SetTOFInfo(info);
680 AliDebug(2,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
681
682
a533f541 683 Int_t ind[5];
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);
ba66add8 689 Int_t calindex = AliTOFGeometry::GetIndex(ind);
a533f541 690 t->SetTOFCalChannel(calindex);
11c7ff68 691
692 // keep track of the track labels in the matched cluster
693 Int_t tlab[3];
694 tlab[0]=c->GetLabel(0);
695 tlab[1]=c->GetLabel(1);
696 tlab[2]=c->GetLabel(2);
6819758a 697 AliDebug(2,Form(" tdc time of the matched track %6d = ",c->GetTDC()));
698 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+kTimeOffset; // in ps
5478df1f 699 AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
5478df1f 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);
ee77ad87 705 t->SetTOFcluster(idclus); // pointing to the recPoints tree
5478df1f 706
6819758a 707 AliDebug(2,Form(" Setting TOF raw time: %f, z distance: %f corrected time: %f ",rawTime,mindistZ,tofcorr));
708
5478df1f 709 //Tracking info
6819758a 710 Double_t time[AliPID::kSPECIES]; t->GetIntegratedTimes(time); // in ps
74ea065c 711 Double_t mom=t->GetP();
53884c34 712 AliDebug(2,Form(" Momentum for track %d -> %f", iseed,mom));
713 for (Int_t j=0;j<AliPID::kSPECIES;j++) {
304864ab 714 Double_t mass=AliPID::ParticleMass(j);
6819758a 715 time[j]+=(recL-trackPos[3][0])/kSpeedOfLight*TMath::Sqrt(mom*mom+mass*mass)/mom;
74ea065c 716 }
717
718 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
719 trackTOFout->PropagateTo(xpos);
77a9ea9a 720
721 // Fill the track residual histograms.
722 FillResiduals(trackTOFout,c,kFALSE);
723
af61c656 724 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
74ea065c 725 t->SetIntegratedLength(recL);
726 t->SetIntegratedTimes(time);
11c7ff68 727 t->SetTOFLabel(tlab);
5478df1f 728
729
5664c6ed 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]));
e0ddb533 735 fHRecSigYVsPWin->Fill(mom,dphi*sensRadius);
5664c6ed 736 fHRecSigZVsPWin->Fill(mom,dz);
737
738 // Fill Tree for on-the-fly offline Calibration
739
53884c34 740 if ( !((t->GetStatus() & AliESDtrack::kTIME)==0 ) ) {
5664c6ed 741 fIch=calindex;
742 fToT=tToT;
5478df1f 743 fTime=rawTime;
5664c6ed 744 fExpTimePi=time[2];
745 fExpTimeKa=time[3];
746 fExpTimePr=time[4];
747 fCalTree->Fill();
748 }
74ea065c 749 delete trackTOFout;
750 }
7bf28302 751 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
128563f6 752 delete [] clind;
ba66add8 753
74ea065c 754}
755//_________________________________________________________________________
7b61cd9c 756Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
74ea065c 757 //--------------------------------------------------------------------
758 //This function loads the TOF clusters
759 //--------------------------------------------------------------------
760
ba66add8 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();
5664c6ed 766
7b61cd9c 767 TBranch *branch=cTree->GetBranch("TOF");
74ea065c 768 if (!branch) {
7b61cd9c 769 AliError("can't get the branch with the TOF clusters !");
74ea065c 770 return 1;
771 }
772
9d802709 773 static TClonesArray dummy("AliTOFcluster",10000);
774 dummy.Clear();
775 TClonesArray *clusters=&dummy;
7b61cd9c 776 branch->SetAddress(&clusters);
74ea065c 777
7b61cd9c 778 cTree->GetEvent(0);
779 Int_t nc=clusters->GetEntriesFast();
5664c6ed 780 fHDigNClus->Fill(nc);
781
7b61cd9c 782 AliInfo(Form("Number of clusters: %d",nc));
74ea065c 783
7b61cd9c 784 for (Int_t i=0; i<nc; i++) {
785 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
7b61cd9c 786 fClusters[i]=new AliTOFcluster(*c); fN++;
5664c6ed 787
788 // Fill Digits QA histos
789
790 Int_t isector = c->GetDetInd(0);
791 Int_t iplate = c->GetDetInd(1);
792 Int_t istrip = c->GetDetInd(2);
793 Int_t ipadX = c->GetDetInd(4);
794 Int_t ipadZ = c->GetDetInd(3);
795
ba66add8 796 Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
797 Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
5664c6ed 798
799 Int_t stripOffset = 0;
800 switch (iplate) {
801 case 0:
802 stripOffset = 0;
803 break;
804 case 1:
805 stripOffset = nStripC;
806 break;
807 case 2:
808 stripOffset = nStripC+nStripB;
809 break;
810 case 3:
811 stripOffset = nStripC+nStripB+nStripA;
812 break;
813 case 4:
814 stripOffset = nStripC+nStripB+nStripA+nStripB;
815 break;
816 default:
817 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
818 break;
819 };
820 Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
821 Int_t phiindex=npadX*isector+ipadX+1;
822 fHDigClusMap->Fill(zindex,phiindex);
823 fHDigClusTime->Fill(time);
824 fHDigClusToT->Fill(tot);
825
7b61cd9c 826 }
74ea065c 827
74ea065c 828
829 return 0;
830}
831//_________________________________________________________________________
832void AliTOFtracker::UnloadClusters() {
833 //--------------------------------------------------------------------
834 //This function unloads TOF clusters
835 //--------------------------------------------------------------------
7b61cd9c 836 for (Int_t i=0; i<fN; i++) {
837 delete fClusters[i];
838 fClusters[i] = 0x0;
74ea065c 839 }
7b61cd9c 840 fN=0;
74ea065c 841}
842
843//_________________________________________________________________________
844Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
845 //--------------------------------------------------------------------
846 // This function returns the index of the nearest cluster
847 //--------------------------------------------------------------------
848 if (fN==0) return 0;
849 if (z <= fClusters[0]->GetZ()) return 0;
850 if (z > fClusters[fN-1]->GetZ()) return fN;
851 Int_t b=0, e=fN-1, m=(b+e)/2;
852 for (; b<e; m=(b+e)/2) {
853 if (z > fClusters[m]->GetZ()) b=m+1;
854 else e=m;
855 }
856 return m;
857}
d4754572 858
859//_________________________________________________________________________
860Bool_t AliTOFtracker::GetTrackPoint(Int_t index, AliTrackPoint& p) const
861{
862 // Get track space point with index i
863 // Coordinates are in the global system
864 AliTOFcluster *cl = fClusters[index];
865 Float_t xyz[3];
866 xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
867 xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
868 xyz[2] = cl->GetZ();
468f26c6 869 Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
870 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
ba66add8 871 Float_t tiltangle = AliTOFGeometry::GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
468f26c6 872 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
ba66add8 873 Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
874 Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
468f26c6 875 Float_t cov[6];
876 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
877 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
878 cov[2] = -cosphi*sinth*costh*sigmaz2;
879 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
880 cov[4] = -sinphi*sinth*costh*sigmaz2;
881 cov[5] = costh*costh*sigmaz2;
882 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
d4754572 883
884 // Detector numbering scheme
ba66add8 885 Int_t nSector = AliTOFGeometry::NSectors();
886 Int_t nPlate = AliTOFGeometry::NPlates();
887 Int_t nStripA = AliTOFGeometry::NStripA();
888 Int_t nStripB = AliTOFGeometry::NStripB();
889 Int_t nStripC = AliTOFGeometry::NStripC();
d4754572 890
891 Int_t isector = cl->GetDetInd(0);
892 if (isector >= nSector)
893 AliError(Form("Wrong sector number in TOF (%d) !",isector));
894 Int_t iplate = cl->GetDetInd(1);
895 if (iplate >= nPlate)
896 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
897 Int_t istrip = cl->GetDetInd(2);
898
899 Int_t stripOffset = 0;
900 switch (iplate) {
901 case 0:
902 stripOffset = 0;
903 break;
904 case 1:
905 stripOffset = nStripC;
906 break;
907 case 2:
908 stripOffset = nStripC+nStripB;
909 break;
910 case 3:
911 stripOffset = nStripC+nStripB+nStripA;
912 break;
913 case 4:
914 stripOffset = nStripC+nStripB+nStripA+nStripB;
915 break;
916 default:
917 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
918 break;
919 };
920
921 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
922 stripOffset +
923 istrip;
ae079791 924 UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
d4754572 925 p.SetVolumeID((UShort_t)volid);
926 return kTRUE;
927}
5664c6ed 928//_________________________________________________________________________
929void AliTOFtracker::InitCheckHists() {
930
931 //Init histos for Digits/Reco QA and Calibration
932
933
0366f10f 934 TDirectory *dir = gDirectory;
935 TFile *logFileTOF = 0;
936
937 TSeqCollection *list = gROOT->GetListOfFiles();
938 int n = list->GetEntries();
939 Bool_t isThere=kFALSE;
940 for(int i=0; i<n; i++) {
941 logFileTOF = (TFile*)list->At(i);
942 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
943 isThere=kTRUE;
944 break;
945 }
946 }
947
948 if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
949 logFileTOF->cd();
950
5664c6ed 951 fCalTree = new TTree("CalTree", "Tree for TOF calibration");
952 fCalTree->Branch("TOFchannelindex",&fIch,"iTOFch/I");
953 fCalTree->Branch("ToT",&fToT,"TOFToT/F");
954 fCalTree->Branch("TOFtime",&fTime,"TOFtime/F");
955 fCalTree->Branch("PionExpTime",&fExpTimePi,"PiExpTime/F");
956 fCalTree->Branch("KaonExpTime",&fExpTimeKa,"KaExpTime/F");
957 fCalTree->Branch("ProtonExpTime",&fExpTimePr,"PrExpTime/F");
958
959 //Digits "QA"
960 fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);
961 fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);
962 fHDigClusTime = new TH1F("TOFDig_ClusTime", "",2000,0.,200.);
963 fHDigClusToT = new TH1F("TOFDig_ClusToT", "",500,0.,100);
964
965 //Reco "QA"
966 fHRecNClus =new TH1F("TOFRec_NClusW", "",50,0.5,50.5);
967 fHRecDist=new TH1F("TOFRec_Dist", "",50,0.5,10.5);
968 fHRecSigYVsP=new TH2F("TOFDig_SigYVsP", "",40,0.,4.,100, 0.,5.);
969 fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
970 fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
971 fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
0366f10f 972
973 dir->cd();
974
5664c6ed 975}
976
977//_________________________________________________________________________
978void AliTOFtracker::SaveCheckHists() {
979
980 //write histos for Digits/Reco QA and Calibration
981
982 TDirectory *dir = gDirectory;
5664c6ed 983 TFile *logFileTOF = 0;
984
985 TSeqCollection *list = gROOT->GetListOfFiles();
d200609f 986 int n = list->GetEntries();
5664c6ed 987 Bool_t isThere=kFALSE;
d200609f 988 for(int i=0; i<n; i++) {
5664c6ed 989 logFileTOF = (TFile*)list->At(i);
990 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
991 isThere=kTRUE;
992 break;
993 }
994 }
995
0366f10f 996 if(!isThere) {
997 AliError(Form("File TOFQA.root not found!! not wring histograms...."));
998 return;
999 }
5664c6ed 1000 logFileTOF->cd();
1001 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
1002 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
1003 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
1004 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
1005 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
1006 fHRecDist->Write(fHRecDist->GetName(), TObject::kOverwrite);
1007 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
1008 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
1009 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
1010 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
1011 fCalTree->Write(fCalTree->GetName(),TObject::kOverwrite);
1012 logFileTOF->Flush();
1013
1014 dir->cd();
1015 }
e0ddb533 1016//_________________________________________________________________________
1017Float_t AliTOFtracker::CorrectTimeWalk( Float_t dist, Float_t tof) {
1018
1019 //dummy, for the moment
1020 Float_t tofcorr=0.;
ba66add8 1021 if(dist<AliTOFGeometry::ZPad()*0.5){
e0ddb533 1022 tofcorr=tof;
1023 //place here the actual correction
1024 }else{
1025 tofcorr=tof;
1026 }
1027 return tofcorr;
1028}
1029//_________________________________________________________________________
af885e0f 1030Float_t AliTOFtracker::GetTimeZerofromT0(AliESDEvent *event) const {
e0ddb533 1031
1032 //Returns TimeZero as measured by T0 detector
1033
1034 return event->GetT0();
1035}
1036//_________________________________________________________________________
af885e0f 1037Float_t AliTOFtracker::GetTimeZerofromTOF(AliESDEvent * /*event*/) const {
e0ddb533 1038
1039 //dummy, for the moment. T0 algorithm using tracks on TOF
1040 {
1041 //place T0 algo here...
1042 }
1043 return 0.;
1044}
128563f6 1045//_________________________________________________________________________
1046
1047void AliTOFtracker::FillClusterArray(TObjArray* arr) const
1048{
1049 //
1050 // Returns the TOF cluster array
1051 //
1052
1053 if (fN==0)
1054 arr = 0x0;
1055 else
1056 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
1057
1058}
ff826920 1059//_________________________________________________________________________
1060