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