]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFtracker.cxx
Moving classes from graphics to rec
[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
17149e6b 446 if (!c->GetStatus()) {
447 AliDebug(1,"Cluster in channel declared bad!");
448 continue; // skip bad channels as declared in OCDB
449 }
7b61cd9c 450
74ea065c 451 Double_t dph=TMath::Abs(c->GetPhi()-phi);
452 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
9b49e4c9 453 if (TMath::Abs(dph)>dphi) continue;
ba66add8 454
6c94f330 455 Double_t yc=(c->GetPhi() - trackTOFin->GetAlpha())*c->GetR();
456 Double_t p[2]={yc, c->GetZ()};
3c609b5c 457 Double_t cov2[3]= {dY*dY/12., 0., dZ*dZ/12.};
458 if (trackTOFin->AliExternalTrackParam::GetPredictedChi2(p,cov2) > maxChi2)continue;
6c94f330 459
128563f6 460 clind[nc] = k;
c0545837 461 Char_t path[100];
462 Int_t ind[5];
128563f6 463 ind[0]=c->GetDetInd(0);
464 ind[1]=c->GetDetInd(1);
465 ind[2]=c->GetDetInd(2);
466 ind[3]=c->GetDetInd(3);
467 ind[4]=c->GetDetInd(4);
c0545837 468 fGeom->GetVolumePath(ind,path);
469 gGeoManager->cd(path);
470 global[nc] = *gGeoManager->GetCurrentMatrix();
74ea065c 471 nc++;
472 }
473
474 //start fine propagation
475
476 Int_t nStepsDone = 0;
477 for( Int_t istep=0; istep<nSteps; istep++){
478
ba66add8 479 Float_t xs=AliTOFGeometry::RinTOF()+istep*0.1;
480 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
74ea065c 481
482 Bool_t skip=kFALSE;
483 Double_t ysect=trackTOFin->GetYat(xs,skip);
6c94f330 484 if (skip) break;
74ea065c 485 if (ysect > ymax) {
ba66add8 486 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
74ea065c 487 break;
488 }
489 } else if (ysect <-ymax) {
ba66add8 490 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
74ea065c 491 break;
492 }
493 }
494
495 if(!trackTOFin->PropagateTo(xs)) {
496 break;
497 }
498
499 nStepsDone++;
500
501 // store the running point (Globalrf) - fine propagation
502
6c94f330 503 Double_t r[3];
504 trackTOFin->GetXYZ(r);
505 trackPos[0][istep]= (Float_t) r[0];
506 trackPos[1][istep]= (Float_t) r[1];
507 trackPos[2][istep]= (Float_t) r[2];
74ea065c 508 trackPos[3][istep]= trackTOFin->GetIntegratedLength();
509 }
510
511
512 Int_t nfound = 0;
d01bf4f4 513 Bool_t accept = kFALSE;
514 Bool_t isInside =kFALSE;
74ea065c 515 for (Int_t istep=0; istep<nStepsDone; istep++) {
516
74ea065c 517 Float_t ctrackPos[3];
518
519 ctrackPos[0]= trackPos[0][istep];
520 ctrackPos[1]= trackPos[1][istep];
521 ctrackPos[2]= trackPos[2][istep];
522
523 //now see whether the track matches any of the TOF clusters
524
d01bf4f4 525 Float_t dist3d[3];
526 accept=kFALSE;
74ea065c 527 for (Int_t i=0; i<nc; i++){
d01bf4f4 528 isInside=fGeom->IsInsideThePad(global[i],ctrackPos,dist3d);
529
530 if( mLastStep){
531 Float_t xLoc=dist3d[0];
532 Float_t rLoc=TMath::Sqrt(dist3d[1]*dist3d[1]+dist3d[2]*dist3d[2]);
533 accept = (TMath::Abs(xLoc)<padDepth*0.5 && rLoc<dCut);
534 }
535 else{
536 accept = isInside;
537 }
74ea065c 538 if(accept){
d01bf4f4 539 dist[nfound]=TMath::Sqrt(dist3d[0]*dist3d[0]+dist3d[1]*dist3d[1]+dist3d[2]*dist3d[2]);
e0ddb533 540 distZ[nfound]=dist3d[2];
74ea065c 541 crecL[nfound]=trackPos[3][istep];
128563f6 542 index[nfound]=clind[i]; // store cluster id
ba66add8 543 cxpos[nfound]=AliTOFGeometry::RinTOF()+istep*0.1; //store prop.radius
74ea065c 544 nfound++;
d01bf4f4 545 if(accept &&!mLastStep)break;
74ea065c 546 }//end if accept
547 } //end for on the clusters
d01bf4f4 548 if(accept &&!mLastStep)break;
74ea065c 549 } //end for on the steps
550
9b49e4c9 551
552
74ea065c 553 if (nfound == 0 ) {
554 fnunmatch++;
7bf28302 555 delete trackTOFin;
74ea065c 556 continue;
557 }
558
559 fnmatch++;
560
561 // now choose the cluster to be matched with the track.
562
563 Int_t idclus=0;
564 Float_t recL = 0.;
565 Float_t xpos=0.;
566 Float_t mindist=1000.;
e0ddb533 567 Float_t mindistZ=0.;
74ea065c 568 for (Int_t iclus= 0; iclus<nfound;iclus++){
569 if (dist[iclus]< mindist){
570 mindist = dist[iclus];
e0ddb533 571 mindistZ = distZ[iclus];
74ea065c 572 xpos = cxpos[iclus];
573 idclus =index[iclus];
e0ddb533 574 recL=crecL[iclus]+corrLen*0.5;
74ea065c 575 }
576 }
577
d01bf4f4 578
74ea065c 579 AliTOFcluster *c=fClusters[idclus];
e0ddb533 580 c->Use();
74ea065c 581
582 // Track length correction for matching Step 2
583
584 if(mLastStep){
585 Float_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
586 Float_t rt=TMath::Sqrt(trackPos[0][70]*trackPos[0][70]
587 +trackPos[1][70]*trackPos[1][70]
588 +trackPos[2][70]*trackPos[2][70]);
589 Float_t dlt=rc-rt;
590 recL=trackPos[3][70]+dlt;
591 }
592
593 if (
594 (c->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
595 ||
596 (c->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
597 ||
598 (c->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
599 ) {
600 fngoodmatch++;
d3c7bfac 601
e0ddb533 602 AliDebug(2,Form(" track label good %5i",trackTOFin->GetLabel()));
d3c7bfac 603
74ea065c 604 }
605 else{
606 fnbadmatch++;
d3c7bfac 607
e0ddb533 608 AliDebug(2,Form(" track label bad %5i",trackTOFin->GetLabel()));
d3c7bfac 609
74ea065c 610 }
611
612 delete trackTOFin;
613
a533f541 614 // Store quantities to be used in the TOF Calibration
ba66add8 615 Float_t tToT=AliTOFGeometry::ToTBinWidth()*c->GetToT()*1E-3; // in ns
7aeeaf38 616 t->SetTOFsignalToT(tToT);
ba66add8 617 Float_t rawTime=AliTOFGeometry::TdcBinWidth()*c->GetTDCRAW()+32; // RAW time,in ps
d321691a 618 t->SetTOFsignalRaw(rawTime);
619 t->SetTOFsignalDz(mindistZ);
ba66add8 620 AliDebug(2,Form(" Setting TOF raw time: %f, z distance: %f time: %f = ",rawTime,mindistZ));
a533f541 621 Int_t ind[5];
622 ind[0]=c->GetDetInd(0);
623 ind[1]=c->GetDetInd(1);
624 ind[2]=c->GetDetInd(2);
625 ind[3]=c->GetDetInd(3);
626 ind[4]=c->GetDetInd(4);
ba66add8 627 Int_t calindex = AliTOFGeometry::GetIndex(ind);
a533f541 628 t->SetTOFCalChannel(calindex);
11c7ff68 629
630 // keep track of the track labels in the matched cluster
631 Int_t tlab[3];
632 tlab[0]=c->GetLabel(0);
633 tlab[1]=c->GetLabel(1);
634 tlab[2]=c->GetLabel(2);
5478df1f 635 AliDebug(2,Form(" tdc time of the matched track %i = ",c->GetTDC()));
ba66add8 636 Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+32; // in ps
5478df1f 637 AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
5478df1f 638 Double_t tofcorr=tof;
639 if(timeWalkCorr)tofcorr=CorrectTimeWalk(mindistZ,tof);
640 AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));
641 //Set TOF time signal and pointer to the matched cluster
642 t->SetTOFsignal(tofcorr);
ee77ad87 643 t->SetTOFcluster(idclus); // pointing to the recPoints tree
5478df1f 644
5478df1f 645 //Tracking info
f222e1d2 646 Double_t time[AliPID::kSPECIES]; t->GetIntegratedTimes(time);
74ea065c 647 Double_t mom=t->GetP();
f222e1d2 648 for(Int_t j=0;j<AliPID::kSPECIES;j++){
304864ab 649 Double_t mass=AliPID::ParticleMass(j);
74ea065c 650 time[j]+=(recL-trackPos[3][0])/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
651 }
652
653 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
654 trackTOFout->PropagateTo(xpos);
655 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
656 t->SetIntegratedLength(recL);
657 t->SetIntegratedTimes(time);
11c7ff68 658 t->SetTOFLabel(tlab);
5478df1f 659
660
5664c6ed 661 // Fill Reco-QA histos for Reconstruction
662 fHRecNClus->Fill(nc);
663 fHRecDist->Fill(mindist);
664 fHRecSigYVsP->Fill(mom,TMath::Sqrt(cov[0]));
665 fHRecSigZVsP->Fill(mom,TMath::Sqrt(cov[2]));
e0ddb533 666 fHRecSigYVsPWin->Fill(mom,dphi*sensRadius);
5664c6ed 667 fHRecSigZVsPWin->Fill(mom,dz);
668
669 // Fill Tree for on-the-fly offline Calibration
670
671 if ( !((t->GetStatus() & AliESDtrack::kTIME)==0 )){
5664c6ed 672 fIch=calindex;
673 fToT=tToT;
5478df1f 674 fTime=rawTime;
5664c6ed 675 fExpTimePi=time[2];
676 fExpTimeKa=time[3];
677 fExpTimePr=time[4];
678 fCalTree->Fill();
679 }
74ea065c 680 delete trackTOFout;
681 }
7bf28302 682 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
128563f6 683 delete [] clind;
ba66add8 684
74ea065c 685}
686//_________________________________________________________________________
7b61cd9c 687Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
74ea065c 688 //--------------------------------------------------------------------
689 //This function loads the TOF clusters
690 //--------------------------------------------------------------------
691
ba66add8 692 Int_t npadX = AliTOFGeometry::NpadX();
693 Int_t npadZ = AliTOFGeometry::NpadZ();
694 Int_t nStripA = AliTOFGeometry::NStripA();
695 Int_t nStripB = AliTOFGeometry::NStripB();
696 Int_t nStripC = AliTOFGeometry::NStripC();
5664c6ed 697
7b61cd9c 698 TBranch *branch=cTree->GetBranch("TOF");
74ea065c 699 if (!branch) {
7b61cd9c 700 AliError("can't get the branch with the TOF clusters !");
74ea065c 701 return 1;
702 }
703
9d802709 704 static TClonesArray dummy("AliTOFcluster",10000);
705 dummy.Clear();
706 TClonesArray *clusters=&dummy;
7b61cd9c 707 branch->SetAddress(&clusters);
74ea065c 708
7b61cd9c 709 cTree->GetEvent(0);
710 Int_t nc=clusters->GetEntriesFast();
5664c6ed 711 fHDigNClus->Fill(nc);
712
7b61cd9c 713 AliInfo(Form("Number of clusters: %d",nc));
74ea065c 714
7b61cd9c 715 for (Int_t i=0; i<nc; i++) {
716 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
7b61cd9c 717 fClusters[i]=new AliTOFcluster(*c); fN++;
5664c6ed 718
719 // Fill Digits QA histos
720
721 Int_t isector = c->GetDetInd(0);
722 Int_t iplate = c->GetDetInd(1);
723 Int_t istrip = c->GetDetInd(2);
724 Int_t ipadX = c->GetDetInd(4);
725 Int_t ipadZ = c->GetDetInd(3);
726
ba66add8 727 Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
728 Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
5664c6ed 729
730 Int_t stripOffset = 0;
731 switch (iplate) {
732 case 0:
733 stripOffset = 0;
734 break;
735 case 1:
736 stripOffset = nStripC;
737 break;
738 case 2:
739 stripOffset = nStripC+nStripB;
740 break;
741 case 3:
742 stripOffset = nStripC+nStripB+nStripA;
743 break;
744 case 4:
745 stripOffset = nStripC+nStripB+nStripA+nStripB;
746 break;
747 default:
748 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
749 break;
750 };
751 Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
752 Int_t phiindex=npadX*isector+ipadX+1;
753 fHDigClusMap->Fill(zindex,phiindex);
754 fHDigClusTime->Fill(time);
755 fHDigClusToT->Fill(tot);
756
7b61cd9c 757 }
74ea065c 758
74ea065c 759
760 return 0;
761}
762//_________________________________________________________________________
763void AliTOFtracker::UnloadClusters() {
764 //--------------------------------------------------------------------
765 //This function unloads TOF clusters
766 //--------------------------------------------------------------------
7b61cd9c 767 for (Int_t i=0; i<fN; i++) {
768 delete fClusters[i];
769 fClusters[i] = 0x0;
74ea065c 770 }
7b61cd9c 771 fN=0;
74ea065c 772}
773
774//_________________________________________________________________________
775Int_t AliTOFtracker::FindClusterIndex(Double_t z) const {
776 //--------------------------------------------------------------------
777 // This function returns the index of the nearest cluster
778 //--------------------------------------------------------------------
779 if (fN==0) return 0;
780 if (z <= fClusters[0]->GetZ()) return 0;
781 if (z > fClusters[fN-1]->GetZ()) return fN;
782 Int_t b=0, e=fN-1, m=(b+e)/2;
783 for (; b<e; m=(b+e)/2) {
784 if (z > fClusters[m]->GetZ()) b=m+1;
785 else e=m;
786 }
787 return m;
788}
d4754572 789
790//_________________________________________________________________________
791Bool_t AliTOFtracker::GetTrackPoint(Int_t index, AliTrackPoint& p) const
792{
793 // Get track space point with index i
794 // Coordinates are in the global system
795 AliTOFcluster *cl = fClusters[index];
796 Float_t xyz[3];
797 xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
798 xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
799 xyz[2] = cl->GetZ();
468f26c6 800 Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
801 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
ba66add8 802 Float_t tiltangle = AliTOFGeometry::GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
468f26c6 803 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
ba66add8 804 Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
805 Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
468f26c6 806 Float_t cov[6];
807 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
808 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
809 cov[2] = -cosphi*sinth*costh*sigmaz2;
810 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
811 cov[4] = -sinphi*sinth*costh*sigmaz2;
812 cov[5] = costh*costh*sigmaz2;
813 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
d4754572 814
815 // Detector numbering scheme
ba66add8 816 Int_t nSector = AliTOFGeometry::NSectors();
817 Int_t nPlate = AliTOFGeometry::NPlates();
818 Int_t nStripA = AliTOFGeometry::NStripA();
819 Int_t nStripB = AliTOFGeometry::NStripB();
820 Int_t nStripC = AliTOFGeometry::NStripC();
d4754572 821
822 Int_t isector = cl->GetDetInd(0);
823 if (isector >= nSector)
824 AliError(Form("Wrong sector number in TOF (%d) !",isector));
825 Int_t iplate = cl->GetDetInd(1);
826 if (iplate >= nPlate)
827 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
828 Int_t istrip = cl->GetDetInd(2);
829
830 Int_t stripOffset = 0;
831 switch (iplate) {
832 case 0:
833 stripOffset = 0;
834 break;
835 case 1:
836 stripOffset = nStripC;
837 break;
838 case 2:
839 stripOffset = nStripC+nStripB;
840 break;
841 case 3:
842 stripOffset = nStripC+nStripB+nStripA;
843 break;
844 case 4:
845 stripOffset = nStripC+nStripB+nStripA+nStripB;
846 break;
847 default:
848 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
849 break;
850 };
851
852 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
853 stripOffset +
854 istrip;
ae079791 855 UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
d4754572 856 p.SetVolumeID((UShort_t)volid);
857 return kTRUE;
858}
5664c6ed 859//_________________________________________________________________________
860void AliTOFtracker::InitCheckHists() {
861
862 //Init histos for Digits/Reco QA and Calibration
863
864
865 fCalTree = new TTree("CalTree", "Tree for TOF calibration");
866 fCalTree->Branch("TOFchannelindex",&fIch,"iTOFch/I");
867 fCalTree->Branch("ToT",&fToT,"TOFToT/F");
868 fCalTree->Branch("TOFtime",&fTime,"TOFtime/F");
869 fCalTree->Branch("PionExpTime",&fExpTimePi,"PiExpTime/F");
870 fCalTree->Branch("KaonExpTime",&fExpTimeKa,"KaExpTime/F");
871 fCalTree->Branch("ProtonExpTime",&fExpTimePr,"PrExpTime/F");
872
873 //Digits "QA"
874 fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);
875 fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);
876 fHDigClusTime = new TH1F("TOFDig_ClusTime", "",2000,0.,200.);
877 fHDigClusToT = new TH1F("TOFDig_ClusToT", "",500,0.,100);
878
879 //Reco "QA"
880 fHRecNClus =new TH1F("TOFRec_NClusW", "",50,0.5,50.5);
881 fHRecDist=new TH1F("TOFRec_Dist", "",50,0.5,10.5);
882 fHRecSigYVsP=new TH2F("TOFDig_SigYVsP", "",40,0.,4.,100, 0.,5.);
883 fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
884 fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
885 fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
886}
887
888//_________________________________________________________________________
889void AliTOFtracker::SaveCheckHists() {
890
891 //write histos for Digits/Reco QA and Calibration
892
893 TDirectory *dir = gDirectory;
894 TFile *logFile = 0;
895 TFile *logFileTOF = 0;
896
897 TSeqCollection *list = gROOT->GetListOfFiles();
d200609f 898 int n = list->GetEntries();
899 for(int i=0; i<n; i++) {
5664c6ed 900 logFile = (TFile*)list->At(i);
901 if (strstr(logFile->GetName(), "AliESDs.root")) break;
902 }
903
904 Bool_t isThere=kFALSE;
d200609f 905 for(int i=0; i<n; i++) {
5664c6ed 906 logFileTOF = (TFile*)list->At(i);
907 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
908 isThere=kTRUE;
909 break;
910 }
911 }
912
913 logFile->cd();
914 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
915 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
916 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
917 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
918 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
919 fHRecDist->Write(fHRecDist->GetName(), TObject::kOverwrite);
920 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
921 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
922 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
923 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
d321691a 924 //fCalTree->Write(fCalTree->GetName(),TObject::kOverwrite);
5664c6ed 925 logFile->Flush();
926
927 if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
928 logFileTOF->cd();
929 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
930 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
931 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
932 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
933 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
934 fHRecDist->Write(fHRecDist->GetName(), TObject::kOverwrite);
935 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
936 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
937 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
938 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
939 fCalTree->Write(fCalTree->GetName(),TObject::kOverwrite);
940 logFileTOF->Flush();
941
942 dir->cd();
943 }
e0ddb533 944//_________________________________________________________________________
945Float_t AliTOFtracker::CorrectTimeWalk( Float_t dist, Float_t tof) {
946
947 //dummy, for the moment
948 Float_t tofcorr=0.;
ba66add8 949 if(dist<AliTOFGeometry::ZPad()*0.5){
e0ddb533 950 tofcorr=tof;
951 //place here the actual correction
952 }else{
953 tofcorr=tof;
954 }
955 return tofcorr;
956}
957//_________________________________________________________________________
af885e0f 958Float_t AliTOFtracker::GetTimeZerofromT0(AliESDEvent *event) const {
e0ddb533 959
960 //Returns TimeZero as measured by T0 detector
961
962 return event->GetT0();
963}
964//_________________________________________________________________________
af885e0f 965Float_t AliTOFtracker::GetTimeZerofromTOF(AliESDEvent * /*event*/) const {
e0ddb533 966
967 //dummy, for the moment. T0 algorithm using tracks on TOF
968 {
969 //place T0 algo here...
970 }
971 return 0.;
972}
128563f6 973//_________________________________________________________________________
974
975void AliTOFtracker::FillClusterArray(TObjArray* arr) const
976{
977 //
978 // Returns the TOF cluster array
979 //
980
981 if (fN==0)
982 arr = 0x0;
983 else
984 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
985
986}