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