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