]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFtracker.cxx
PMD QA classes
[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
0e46b9ae 46#include "AliTOFcalib.h"
5c7c93fa 47#include "AliTOFpidESD.h"
e0ddb533 48#include "AliTOFRecoParam.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();
91219c0b 95 // Read the reconstruction parameters from the OCDB
ba66add8 96 AliTOFcalib* calib=new AliTOFcalib();
91219c0b 97 fRecoParam = (AliTOFRecoParam*)calib->ReadRecParFromCDB("TOF/Calib",-1);
91219c0b 98 if(fRecoParam->GetApplyPbPbCuts())fRecoParam=fRecoParam->GetPbPbparam();
e0ddb533 99 Double_t parPID[2];
100 parPID[0]=fRecoParam->GetTimeResolution();
101 parPID[1]=fRecoParam->GetTimeNSigma();
e0ddb533 102 fPid=new AliTOFpidESD(parPID);
103 InitCheckHists();
ba66add8 104 delete calib;
74ea065c 105}
106//_____________________________________________________________________________
58d8d9a3 107AliTOFtracker::AliTOFtracker(const AliTOFtracker &t):
108 AliTracker(),
e0ddb533 109 fRecoParam(0x0),
58d8d9a3 110 fGeom(0x0),
e0ddb533 111 fPid(0x0),
58d8d9a3 112 fN(0),
113 fNseeds(0),
114 fNseedsTOF(0),
115 fngoodmatch(0),
116 fnbadmatch(0),
117 fnunmatch(0),
118 fnmatch(0),
9d802709 119 fTracks(new TClonesArray("AliTOFtrack")),
120 fSeeds(new TClonesArray("AliESDtrack")),
5664c6ed 121 fHDigClusMap(0x0),
122 fHDigNClus(0x0),
123 fHDigClusTime(0x0),
124 fHDigClusToT(0x0),
125 fHRecNClus(0x0),
126 fHRecDist(0x0),
127 fHRecSigYVsP(0x0),
128 fHRecSigZVsP(0x0),
129 fHRecSigYVsPWin(0x0),
130 fHRecSigZVsPWin(0x0),
131 fCalTree(0x0),
132 fIch(-1),
133 fToT(-1.),
134 fTime(-1.),
135 fExpTimePi(-1.),
136 fExpTimeKa(-1.),
137 fExpTimePr(-1.)
58d8d9a3 138 {
74ea065c 139 //AliTOFtracker copy Ctor
140
e0ddb533 141 fNseeds=t.fNseeds;
74ea065c 142 fNseeds=t.fNseeds;
143 fNseedsTOF=t.fNseedsTOF;
144 fngoodmatch=t.fngoodmatch;
145 fnbadmatch=t.fnbadmatch;
146 fnunmatch=t.fnunmatch;
147 fnmatch=t.fnmatch;
e0ddb533 148 fRecoParam=t.fRecoParam;
e0ddb533 149 fPid=t.fPid;
74ea065c 150 fSeeds=t.fSeeds;
151 fTracks=t.fTracks;
152 fN=t.fN;
153}
7aeeaf38 154
155//_____________________________________________________________________________
156AliTOFtracker& AliTOFtracker::operator=(const AliTOFtracker &t)
157{
158 //AliTOFtracker assignment operator
159
7aeeaf38 160 this->fNseeds=t.fNseeds;
161 this->fNseedsTOF=t.fNseedsTOF;
162 this->fngoodmatch=t.fngoodmatch;
163 this->fnbadmatch=t.fnbadmatch;
164 this->fnunmatch=t.fnunmatch;
165 this->fnmatch=t.fnmatch;
e0ddb533 166 this->fRecoParam = t.fRecoParam;
ba66add8 167 this->fGeom=t.fGeom;
e0ddb533 168 this->fPid = t.fPid;
7aeeaf38 169 this->fSeeds=t.fSeeds;
170 this->fTracks=t.fTracks;
171 this->fN=t.fN;
172 return *this;
173
174}
5664c6ed 175//_____________________________________________________________________________
176AliTOFtracker::~AliTOFtracker() {
177 //
178 // Dtor
179 //
e0ddb533 180
5664c6ed 181 SaveCheckHists();
e0ddb533 182
5d456bcd 183 if(!(AliCDBManager::Instance()->GetCacheFlag())){
184 delete fRecoParam;
185 }
e0ddb533 186 delete fGeom;
187 delete fPid;
5664c6ed 188 delete fHDigClusMap;
189 delete fHDigNClus;
190 delete fHDigClusTime;
191 delete fHDigClusToT;
192 delete fHRecNClus;
193 delete fHRecDist;
194 delete fHRecSigYVsP;
195 delete fHRecSigZVsP;
196 delete fHRecSigYVsPWin;
197 delete fHRecSigZVsPWin;
198 delete fCalTree;
9d802709 199 if (fTracks){
200 fTracks->Delete();
201 delete fTracks;
202 fTracks=0x0;
203 }
204 if (fSeeds){
205 fSeeds->Delete();
206 delete fSeeds;
207 fSeeds=0x0;
208 }
209
5664c6ed 210}
74ea065c 211//_____________________________________________________________________________
af885e0f 212Int_t AliTOFtracker::PropagateBack(AliESDEvent* event) {
74ea065c 213 //
214 // Gets seeds from ESD event and Match with TOF Clusters
215 //
216
217
218 //Initialise some counters
219
220 fNseeds=0;
221 fNseedsTOF=0;
222 fngoodmatch=0;
223 fnbadmatch=0;
224 fnunmatch=0;
225 fnmatch=0;
226
227 Int_t ntrk=event->GetNumberOfTracks();
228 fNseeds = ntrk;
74ea065c 229 TClonesArray &aESDTrack = *fSeeds;
230
231
232 //Load ESD tracks into a local Array of ESD Seeds
233
234 for (Int_t i=0; i<fNseeds; i++) {
235 AliESDtrack *t=event->GetTrack(i);
236 new(aESDTrack[i]) AliESDtrack(*t);
237 }
238
239 //Prepare ESD tracks candidates for TOF Matching
240 CollectESD();
241
242 //First Step with Strict Matching Criterion
243 MatchTracks(kFALSE);
244
245 //Second Step with Looser Matching Criterion
246 MatchTracks(kTRUE);
247
d076c8d5 248 AliInfo(Form("Number of matched tracks: %d",fnmatch));
249 AliInfo(Form("Number of good matched tracks: %d",fngoodmatch));
250 AliInfo(Form("Number of bad matched tracks: %d",fnbadmatch));
74ea065c 251
252 //Update the matched ESD tracks
253
254 for (Int_t i=0; i<ntrk; i++) {
255 AliESDtrack *t=event->GetTrack(i);
256 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
257 if(seed->GetTOFsignal()>0){
258 t->SetTOFsignal(seed->GetTOFsignal());
259 t->SetTOFcluster(seed->GetTOFcluster());
a533f541 260 t->SetTOFsignalToT(seed->GetTOFsignalToT());
d321691a 261 t->SetTOFsignalRaw(seed->GetTOFsignalRaw());
262 t->SetTOFsignalDz(seed->GetTOFsignalDz());
a533f541 263 t->SetTOFCalChannel(seed->GetTOFCalChannel());
11c7ff68 264 Int_t tlab[3]; seed->GetTOFLabel(tlab);
265 t->SetTOFLabel(tlab);
74ea065c 266 AliTOFtrack *track = new AliTOFtrack(*seed);
a533f541 267 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
74ea065c 268 delete track;
269 }
270 }
271
e0ddb533 272 //Handle Time Zero information
91219c0b 273
e0ddb533 274 Double_t timeZero=0.;
275 Double_t timeZeroMax=99999.;
276 Bool_t usetimeZero = fRecoParam->UseTimeZero();
277 Bool_t timeZeroFromT0 = fRecoParam->GetTimeZerofromT0();
278 Bool_t timeZeroFromTOF = fRecoParam->GetTimeZerofromTOF();
91219c0b 279
a838421b 280 AliDebug(1,Form("Use Time Zero?: %d",usetimeZero));
281 AliDebug(1,Form("Time Zero from T0? : %d",timeZeroFromT0));
282 AliDebug(1,Form("Time Zero From TOF? : %d",timeZeroFromTOF));
e0ddb533 283
284 if(usetimeZero){
285 if(timeZeroFromT0){
286 timeZero=GetTimeZerofromT0(event);
287 }
288 if(timeZeroFromTOF && (timeZero>timeZeroMax || !timeZeroFromT0)){
289 timeZero=GetTimeZerofromTOF(event);
290 }
291 }
292 AliDebug(2,Form("time Zero used in PID: %f",timeZero));
74ea065c 293 //Make TOF PID
e0ddb533 294 fPid->MakePID(event,timeZero);
74ea065c 295
9d802709 296 fSeeds->Clear();
297 fTracks->Clear();
74ea065c 298 return 0;
299
300}
301//_________________________________________________________________________
302void AliTOFtracker::CollectESD() {
303 //prepare the set of ESD tracks to be matched to clusters in TOF
5478df1f 304
305 Int_t seedsTOF1=0;
306 Int_t seedsTOF2=0;
74ea065c 307
74ea065c 308 TClonesArray &aTOFTrack = *fTracks;
309 for (Int_t i=0; i<fNseeds; i++) {
310
311 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
312 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
313
8dacd1bb 314 // TRD 'good' tracks, already propagated at 372 cm
74ea065c 315
56da420e 316 AliTOFtrack *track = new AliTOFtrack(*t); // New
317 Double_t x = track->GetX(); //New
56da420e 318 if (((t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
ba66add8 319 ( x >= AliTOFGeometry::RinTOF()) ){
74ea065c 320 track->SetSeedIndex(i);
321 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
322 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
323 fNseedsTOF++;
5478df1f 324 seedsTOF1++;
74ea065c 325 delete track;
326 }
327
328 // Propagate the rest of TPCbp
329
330 else {
e0ddb533 331 if(track->PropagateToInnerTOF()){
74ea065c 332 track->SetSeedIndex(i);
333 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
334 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
335 fNseedsTOF++;
5478df1f 336 seedsTOF2++;
74ea065c 337 }
338 delete track;
339 }
340 }
341
5478df1f 342 AliInfo(Form("Number of TOF seeds %i",fNseedsTOF));
343 AliInfo(Form("Number of TOF seeds Type 1 %i",seedsTOF1));
344 AliInfo(Form("Number of TOF seeds Type 2 %i",seedsTOF2));
7b61cd9c 345
74ea065c 346 // Sort according uncertainties on track position
347 fTracks->Sort();
348
349}
350//_________________________________________________________________________
351void AliTOFtracker::MatchTracks( Bool_t mLastStep){
352
e0ddb533 353
354 // Parameters used/regulating the reconstruction
355
356 static Float_t corrLen=0.75;
357 static Float_t detDepth=15.3;
d01bf4f4 358 static Float_t padDepth=0.5;
e0ddb533 359
ba66add8 360 Float_t dY=AliTOFGeometry::XPad();
361 Float_t dZ=AliTOFGeometry::ZPad();
e0ddb533 362
363 Float_t sensRadius = fRecoParam->GetSensRadius();
364 Float_t stepSize = fRecoParam->GetStepSize();
365 Float_t scaleFact = fRecoParam->GetWindowScaleFact();
366 Float_t dyMax=fRecoParam->GetWindowSizeMaxY();
367 Float_t dzMax=fRecoParam->GetWindowSizeMaxZ();
368 Float_t dCut=fRecoParam->GetDistanceCut();
ac359ffe 369 Double_t maxChi2=fRecoParam->GetMaxChi2TRD();
e0ddb533 370 Bool_t timeWalkCorr = fRecoParam->GetTimeWalkCorr();
a838421b 371 if(!mLastStep){
372 AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++ \n");
373 AliDebug(1,Form("TOF sens radius: %f",sensRadius));
374 AliDebug(1,Form("TOF step size: %f",stepSize));
375 AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
376 AliDebug(1,Form("TOF Window max dy: %f",dyMax));
377 AliDebug(1,Form("TOF Window max dz: %f",dzMax));
378 AliDebug(1,Form("TOF distance Cut: %f",dCut));
379 AliDebug(1,Form("TOF Max Chi2: %f",maxChi2));
380 AliDebug(1,Form("Time Walk Correction? : %d",timeWalkCorr));
381 }
74ea065c 382 //Match ESD tracks to clusters in TOF
383
a533f541 384
e0ddb533 385 // Get the number of propagation steps
386
387 Int_t nSteps=(Int_t)(detDepth/stepSize);
7bf28302 388
389 //PH Arrays (moved outside of the loop)
e0ddb533 390
7bf28302 391 Float_t * trackPos[4];
392 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
128563f6 393 Int_t * clind = new Int_t[fN];
74ea065c 394
c0545837 395 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
74ea065c 396
c0545837 397 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
74ea065c 398 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
7bf28302 399 if(t->GetTOFsignal()>0. ) continue;
74ea065c 400 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
74ea065c 401
d3c7bfac 402 // Some init
74ea065c 403
404 Int_t index[10000];
405 Float_t dist[10000];
e0ddb533 406 Float_t distZ[10000];
74ea065c 407 Float_t cxpos[10000];
408 Float_t crecL[10000];
c0545837 409 TGeoHMatrix global[1000];
74ea065c 410
411 // Determine a window around the track
412
413 Double_t x,par[5];
414 trackTOFin->GetExternalParameters(x,par);
415 Double_t cov[15];
416 trackTOFin->GetExternalCovariance(cov);
6c94f330 417
74ea065c 418 Double_t dphi=
e0ddb533 419 scaleFact*
420 ((5*TMath::Sqrt(cov[0]) + 0.5*dY + 2.5*TMath::Abs(par[2]))/sensRadius);
74ea065c 421 Double_t dz=
e0ddb533 422 scaleFact*
423 (5*TMath::Sqrt(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
74ea065c 442 AliTOFcluster *c=fClusters[k];
443 if (c->GetZ() > z+dz) break;
444 if (c->IsUsed()) continue;
11c7ff68 445
446 if (!c->GetStatus()) continue; // skip bad channels as declared in OCDB
7b61cd9c 447
74ea065c 448 Double_t dph=TMath::Abs(c->GetPhi()-phi);
449 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
9b49e4c9 450 if (TMath::Abs(dph)>dphi) continue;
ba66add8 451
6c94f330 452 Double_t yc=(c->GetPhi() - trackTOFin->GetAlpha())*c->GetR();
453 Double_t p[2]={yc, c->GetZ()};
3c609b5c 454 Double_t cov2[3]= {dY*dY/12., 0., dZ*dZ/12.};
455 if (trackTOFin->AliExternalTrackParam::GetPredictedChi2(p,cov2) > maxChi2)continue;
6c94f330 456
128563f6 457 clind[nc] = k;
c0545837 458 Char_t path[100];
459 Int_t ind[5];
128563f6 460 ind[0]=c->GetDetInd(0);
461 ind[1]=c->GetDetInd(1);
462 ind[2]=c->GetDetInd(2);
463 ind[3]=c->GetDetInd(3);
464 ind[4]=c->GetDetInd(4);
c0545837 465 fGeom->GetVolumePath(ind,path);
466 gGeoManager->cd(path);
467 global[nc] = *gGeoManager->GetCurrentMatrix();
74ea065c 468 nc++;
469 }
470
471 //start fine propagation
472
473 Int_t nStepsDone = 0;
474 for( Int_t istep=0; istep<nSteps; istep++){
475
ba66add8 476 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
477 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
74ea065c 478
479 Bool_t skip=kFALSE;
480 Double_t ysect=trackTOFin->GetYat(xs,skip);
6c94f330 481 if (skip) break;
74ea065c 482 if (ysect > ymax) {
ba66add8 483 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
74ea065c 484 break;
485 }
486 } else if (ysect <-ymax) {
ba66add8 487 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
74ea065c 488 break;
489 }
490 }
491
492 if(!trackTOFin->PropagateTo(xs)) {
493 break;
494 }
495
496 nStepsDone++;
497
498 // store the running point (Globalrf) - fine propagation
499
6c94f330 500 Double_t r[3];
501 trackTOFin->GetXYZ(r);
502 trackPos[0][istep]= (Float_t) r[0];
503 trackPos[1][istep]= (Float_t) r[1];
504 trackPos[2][istep]= (Float_t) r[2];
74ea065c 505 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
506 }
507
508
509 Int_t nfound = 0;
d01bf4f4 510 Bool_t accept = kFALSE;
511 Bool_t isInside =kFALSE;
74ea065c 512 for (Int_t istep=0; istep<nStepsDone; istep++) {
513
74ea065c 514 Float_t ctrackPos[3];
515
516 ctrackPos[0]= trackPos[0][istep];
517 ctrackPos[1]= trackPos[1][istep];
518 ctrackPos[2]= trackPos[2][istep];
519
520 //now see whether the track matches any of the TOF clusters
521
d01bf4f4 522 Float_t dist3d[3];
523 accept=kFALSE;
74ea065c 524 for (Int_t i=0; i<nc; i++){
d01bf4f4 525 isInside=fGeom->IsInsideThePad(global[i],ctrackPos,dist3d);
526
527 if( mLastStep){
528 Float_t xLoc=dist3d[0];
529 Float_t rLoc=TMath::Sqrt(dist3d[1]*dist3d[1]+dist3d[2]*dist3d[2]);
530 accept = (TMath::Abs(xLoc)<padDepth*0.5 && rLoc<dCut);
531 }
532 else{
533 accept = isInside;
534 }
74ea065c 535 if(accept){
d01bf4f4 536 dist[nfound]=TMath::Sqrt(dist3d[0]*dist3d[0]+dist3d[1]*dist3d[1]+dist3d[2]*dist3d[2]);
e0ddb533 537 distZ[nfound]=dist3d[2];
74ea065c 538 crecL[nfound]=trackPos[3][istep];
128563f6 539 index[nfound]=clind[i]; // store cluster id
ba66add8 540 cxpos[nfound]=AliTOFGeometry::RinTOF()+istep*0.1; //store prop.radius
74ea065c 541 nfound++;
d01bf4f4 542 if(accept &&!mLastStep)break;
74ea065c 543 }//end if accept
544 } //end for on the clusters
d01bf4f4 545 if(accept &&!mLastStep)break;
74ea065c 546 } //end for on the steps
547
9b49e4c9 548
549
74ea065c 550 if (nfound == 0 ) {
551 fnunmatch++;
7bf28302 552 delete trackTOFin;
74ea065c 553 continue;
554 }
555
556 fnmatch++;
557
558 // now choose the cluster to be matched with the track.
559
560 Int_t idclus=0;
561 Float_t recL = 0.;
562 Float_t xpos=0.;
563 Float_t mindist=1000.;
e0ddb533 564 Float_t mindistZ=0.;
74ea065c 565 for (Int_t iclus= 0; iclus<nfound;iclus++){
566 if (dist[iclus]< mindist){
567 mindist = dist[iclus];
e0ddb533 568 mindistZ = distZ[iclus];
74ea065c 569 xpos = cxpos[iclus];
570 idclus =index[iclus];
e0ddb533 571 recL=crecL[iclus]+corrLen*0.5;
74ea065c 572 }
573 }
574
d01bf4f4 575
74ea065c 576 AliTOFcluster *c=fClusters[idclus];
e0ddb533 577 c->Use();
74ea065c 578
579 // Track length correction for matching Step 2
580
581 if(mLastStep){
582 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
583 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
584 +trackPos[1][70]*trackPos[1][70]
585 +trackPos[2][70]*trackPos[2][70]);
586 Float_t dlt=rc-rt;
587 recL=trackPos[3][70]+dlt;
588 }
589
590 if (
591 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
592 ||
593 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
594 ||
595 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
596 ) {
597 fngoodmatch++;
d3c7bfac 598
e0ddb533 599 AliDebug(2,Form(" track label good %5i",trackTOFin->GetLabel()));
d3c7bfac 600
74ea065c 601 }
602 else{
603 fnbadmatch++;
d3c7bfac 604
e0ddb533 605 AliDebug(2,Form(" track label bad %5i",trackTOFin->GetLabel()));
d3c7bfac 606
74ea065c 607 }
608
609 delete trackTOFin;
610
a533f541 611 // Store quantities to be used in the TOF Calibration
ba66add8 612 Float_t tToT=AliTOFGeometry::ToTBinWidth()*c->GetToT()*1E-3; // in ns
7aeeaf38 613 t->SetTOFsignalToT(tToT);
ba66add8 614 Float_t rawTime=AliTOFGeometry::TdcBinWidth()*c->GetTDCRAW()+32; // RAW time,in ps
d321691a 615 t->SetTOFsignalRaw(rawTime);
616 t->SetTOFsignalDz(mindistZ);
ba66add8 617 AliDebug(2,Form(" Setting TOF raw time: %f, z distance: %f time: %f = ",rawTime,mindistZ));
a533f541 618 Int_t ind[5];
619 ind[0]=c->GetDetInd(0);
620 ind[1]=c->GetDetInd(1);
621 ind[2]=c->GetDetInd(2);
622 ind[3]=c->GetDetInd(3);
623 ind[4]=c->GetDetInd(4);
ba66add8 624 Int_t calindex = AliTOFGeometry::GetIndex(ind);
a533f541 625 t->SetTOFCalChannel(calindex);
11c7ff68 626
627 // keep track of the track labels in the matched cluster
628 Int_t tlab[3];
629 tlab[0]=c->GetLabel(0);
630 tlab[1]=c->GetLabel(1);
631 tlab[2]=c->GetLabel(2);
5478df1f 632 AliDebug(2,Form(" tdc time of the matched track %i = ",c->GetTDC()));
ba66add8 633 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+32; // in ps
5478df1f 634 AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
5478df1f 635 Double_t tofcorr=tof;
636 if(timeWalkCorr)tofcorr=CorrectTimeWalk(mindistZ,tof);
637 AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));
638 //Set TOF time signal and pointer to the matched cluster
639 t->SetTOFsignal(tofcorr);
ee77ad87 640 t->SetTOFcluster(idclus); // pointing to the recPoints tree
5478df1f 641
5478df1f 642 //Tracking info
f222e1d2 643 Double_t time[AliPID::kSPECIES]; t->GetIntegratedTimes(time);
74ea065c 644 Double_t mom=t->GetP();
f222e1d2 645 for(Int_t j=0;j<AliPID::kSPECIES;j++){
304864ab 646 Double_t mass=AliPID::ParticleMass(j);
74ea065c 647 time[j]+=(recL-trackPos[3][0])/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
648 }
649
650 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
651 trackTOFout->PropagateTo(xpos);
652 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
653 t->SetIntegratedLength(recL);
654 t->SetIntegratedTimes(time);
11c7ff68 655 t->SetTOFLabel(tlab);
5478df1f 656
657
5664c6ed 658 // Fill Reco-QA histos for Reconstruction
659 fHRecNClus->Fill(nc);
660 fHRecDist->Fill(mindist);
661 fHRecSigYVsP->Fill(mom,TMath::Sqrt(cov[0]));
662 fHRecSigZVsP->Fill(mom,TMath::Sqrt(cov[2]));
e0ddb533 663 fHRecSigYVsPWin->Fill(mom,dphi*sensRadius);
5664c6ed 664 fHRecSigZVsPWin->Fill(mom,dz);
665
666 // Fill Tree for on-the-fly offline Calibration
667
668 if ( !((t->GetStatus() & AliESDtrack::kTIME)==0 )){
5664c6ed 669 fIch=calindex;
670 fToT=tToT;
5478df1f 671 fTime=rawTime;
5664c6ed 672 fExpTimePi=time[2];
673 fExpTimeKa=time[3];
674 fExpTimePr=time[4];
675 fCalTree->Fill();
676 }
74ea065c 677 delete trackTOFout;
678 }
7bf28302 679 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
128563f6 680 delete [] clind;
ba66add8 681
74ea065c 682}
683//_________________________________________________________________________
7b61cd9c 684Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
74ea065c 685 //--------------------------------------------------------------------
686 //This function loads the TOF clusters
687 //--------------------------------------------------------------------
688
ba66add8 689 Int_t npadX = AliTOFGeometry::NpadX();
690 Int_t npadZ = AliTOFGeometry::NpadZ();
691 Int_t nStripA = AliTOFGeometry::NStripA();
692 Int_t nStripB = AliTOFGeometry::NStripB();
693 Int_t nStripC = AliTOFGeometry::NStripC();
5664c6ed 694
7b61cd9c 695 TBranch *branch=cTree->GetBranch("TOF");
74ea065c 696 if (!branch) {
7b61cd9c 697 AliError("can't get the branch with the TOF clusters !");
74ea065c 698 return 1;
699 }
700
9d802709 701 static TClonesArray dummy("AliTOFcluster",10000);
702 dummy.Clear();
703 TClonesArray *clusters=&dummy;
7b61cd9c 704 branch->SetAddress(&clusters);
74ea065c 705
7b61cd9c 706 cTree->GetEvent(0);
707 Int_t nc=clusters->GetEntriesFast();
5664c6ed 708 fHDigNClus->Fill(nc);
709
7b61cd9c 710 AliInfo(Form("Number of clusters: %d",nc));
74ea065c 711
7b61cd9c 712 for (Int_t i=0; i<nc; i++) {
713 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
7b61cd9c 714 fClusters[i]=new AliTOFcluster(*c); fN++;
5664c6ed 715
716 // Fill Digits QA histos
717
718 Int_t isector = c->GetDetInd(0);
719 Int_t iplate = c->GetDetInd(1);
720 Int_t istrip = c->GetDetInd(2);
721 Int_t ipadX = c->GetDetInd(4);
722 Int_t ipadZ = c->GetDetInd(3);
723
ba66add8 724 Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
725 Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
5664c6ed 726
727 Int_t stripOffset = 0;
728 switch (iplate) {
729 case 0:
730 stripOffset = 0;
731 break;
732 case 1:
733 stripOffset = nStripC;
734 break;
735 case 2:
736 stripOffset = nStripC+nStripB;
737 break;
738 case 3:
739 stripOffset = nStripC+nStripB+nStripA;
740 break;
741 case 4:
742 stripOffset = nStripC+nStripB+nStripA+nStripB;
743 break;
744 default:
745 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
746 break;
747 };
748 Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
749 Int_t phiindex=npadX*isector+ipadX+1;
750 fHDigClusMap->Fill(zindex,phiindex);
751 fHDigClusTime->Fill(time);
752 fHDigClusToT->Fill(tot);
753
7b61cd9c 754 }
74ea065c 755
74ea065c 756
757 return 0;
758}
759//_________________________________________________________________________
760void AliTOFtracker::UnloadClusters() {
761 //--------------------------------------------------------------------
762 //This function unloads TOF clusters
763 //--------------------------------------------------------------------
7b61cd9c 764 for (Int_t i=0; i<fN; i++) {
765 delete fClusters[i];
766 fClusters[i] = 0x0;
74ea065c 767 }
7b61cd9c 768 fN=0;
74ea065c 769}
770
771//_________________________________________________________________________
772Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
773 //--------------------------------------------------------------------
774 // This function returns the index of the nearest cluster
775 //--------------------------------------------------------------------
776 if (fN==0) return 0;
777 if (z <= fClusters[0]->GetZ()) return 0;
778 if (z > fClusters[fN-1]->GetZ()) return fN;
779 Int_t b=0, e=fN-1, m=(b+e)/2;
780 for (; b<e; m=(b+e)/2) {
781 if (z > fClusters[m]->GetZ()) b=m+1;
782 else e=m;
783 }
784 return m;
785}
d4754572 786
787//_________________________________________________________________________
788Bool_t AliTOFtracker::GetTrackPoint(Int_t index, AliTrackPoint& p) const
789{
790 // Get track space point with index i
791 // Coordinates are in the global system
792 AliTOFcluster *cl = fClusters[index];
793 Float_t xyz[3];
794 xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
795 xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
796 xyz[2] = cl->GetZ();
468f26c6 797 Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
798 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
ba66add8 799 Float_t tiltangle = AliTOFGeometry::GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
468f26c6 800 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
ba66add8 801 Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
802 Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
468f26c6 803 Float_t cov[6];
804 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
805 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
806 cov[2] = -cosphi*sinth*costh*sigmaz2;
807 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
808 cov[4] = -sinphi*sinth*costh*sigmaz2;
809 cov[5] = costh*costh*sigmaz2;
810 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
d4754572 811
812 // Detector numbering scheme
ba66add8 813 Int_t nSector = AliTOFGeometry::NSectors();
814 Int_t nPlate = AliTOFGeometry::NPlates();
815 Int_t nStripA = AliTOFGeometry::NStripA();
816 Int_t nStripB = AliTOFGeometry::NStripB();
817 Int_t nStripC = AliTOFGeometry::NStripC();
d4754572 818
819 Int_t isector = cl->GetDetInd(0);
820 if (isector >= nSector)
821 AliError(Form("Wrong sector number in TOF (%d) !",isector));
822 Int_t iplate = cl->GetDetInd(1);
823 if (iplate >= nPlate)
824 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
825 Int_t istrip = cl->GetDetInd(2);
826
827 Int_t stripOffset = 0;
828 switch (iplate) {
829 case 0:
830 stripOffset = 0;
831 break;
832 case 1:
833 stripOffset = nStripC;
834 break;
835 case 2:
836 stripOffset = nStripC+nStripB;
837 break;
838 case 3:
839 stripOffset = nStripC+nStripB+nStripA;
840 break;
841 case 4:
842 stripOffset = nStripC+nStripB+nStripA+nStripB;
843 break;
844 default:
845 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
846 break;
847 };
848
849 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
850 stripOffset +
851 istrip;
ae079791 852 UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
d4754572 853 p.SetVolumeID((UShort_t)volid);
854 return kTRUE;
855}
5664c6ed 856//_________________________________________________________________________
857void AliTOFtracker::InitCheckHists() {
858
859 //Init histos for Digits/Reco QA and Calibration
860
861
862 fCalTree = new TTree("CalTree", "Tree for TOF calibration");
863 fCalTree->Branch("TOFchannelindex",&fIch,"iTOFch/I");
864 fCalTree->Branch("ToT",&fToT,"TOFToT/F");
865 fCalTree->Branch("TOFtime",&fTime,"TOFtime/F");
866 fCalTree->Branch("PionExpTime",&fExpTimePi,"PiExpTime/F");
867 fCalTree->Branch("KaonExpTime",&fExpTimeKa,"KaExpTime/F");
868 fCalTree->Branch("ProtonExpTime",&fExpTimePr,"PrExpTime/F");
869
870 //Digits "QA"
871 fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);
872 fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);
873 fHDigClusTime = new TH1F("TOFDig_ClusTime", "",2000,0.,200.);
874 fHDigClusToT = new TH1F("TOFDig_ClusToT", "",500,0.,100);
875
876 //Reco "QA"
877 fHRecNClus =new TH1F("TOFRec_NClusW", "",50,0.5,50.5);
878 fHRecDist=new TH1F("TOFRec_Dist", "",50,0.5,10.5);
879 fHRecSigYVsP=new TH2F("TOFDig_SigYVsP", "",40,0.,4.,100, 0.,5.);
880 fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
881 fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
882 fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
883}
884
885//_________________________________________________________________________
886void AliTOFtracker::SaveCheckHists() {
887
888 //write histos for Digits/Reco QA and Calibration
889
890 TDirectory *dir = gDirectory;
891 TFile *logFile = 0;
892 TFile *logFileTOF = 0;
893
894 TSeqCollection *list = gROOT->GetListOfFiles();
d200609f 895 int n = list->GetEntries();
896 for(int i=0; i<n; i++) {
5664c6ed 897 logFile = (TFile*)list->At(i);
898 if (strstr(logFile->GetName(), "AliESDs.root")) break;
899 }
900
901 Bool_t isThere=kFALSE;
d200609f 902 for(int i=0; i<n; i++) {
5664c6ed 903 logFileTOF = (TFile*)list->At(i);
904 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
905 isThere=kTRUE;
906 break;
907 }
908 }
909
910 logFile->cd();
911 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
912 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
913 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
914 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
915 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
916 fHRecDist->Write(fHRecDist->GetName(), TObject::kOverwrite);
917 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
918 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
919 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
920 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
d321691a 921 //fCalTree->Write(fCalTree->GetName(),TObject::kOverwrite);
5664c6ed 922 logFile->Flush();
923
924 if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
925 logFileTOF->cd();
926 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
927 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
928 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
929 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
930 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
931 fHRecDist->Write(fHRecDist->GetName(), TObject::kOverwrite);
932 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
933 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
934 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
935 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
936 fCalTree->Write(fCalTree->GetName(),TObject::kOverwrite);
937 logFileTOF->Flush();
938
939 dir->cd();
940 }
e0ddb533 941//_________________________________________________________________________
942Float_t AliTOFtracker::CorrectTimeWalk( Float_t dist, Float_t tof) {
943
944 //dummy, for the moment
945 Float_t tofcorr=0.;
ba66add8 946 if(dist<AliTOFGeometry::ZPad()*0.5){
e0ddb533 947 tofcorr=tof;
948 //place here the actual correction
949 }else{
950 tofcorr=tof;
951 }
952 return tofcorr;
953}
954//_________________________________________________________________________
af885e0f 955Float_t AliTOFtracker::GetTimeZerofromT0(AliESDEvent *event) const {
e0ddb533 956
957 //Returns TimeZero as measured by T0 detector
958
959 return event->GetT0();
960}
961//_________________________________________________________________________
af885e0f 962Float_t AliTOFtracker::GetTimeZerofromTOF(AliESDEvent * /*event*/) const {
e0ddb533 963
964 //dummy, for the moment. T0 algorithm using tracks on TOF
965 {
966 //place T0 algo here...
967 }
968 return 0.;
969}
128563f6 970//_________________________________________________________________________
971
972void AliTOFtracker::FillClusterArray(TObjArray* arr) const
973{
974 //
975 // Returns the TOF cluster array
976 //
977
978 if (fN==0)
979 arr = 0x0;
980 else
981 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
982
983}