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