]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFtrackerV1.cxx
Border between central and intermediate TOF modules: correction
[u/mrichter/AliRoot.git] / TOF / AliTOFtrackerV1.cxx
CommitLineData
d686d062 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**************************************************************************/
15
16//--------------------------------------------------------------------//
17// //
3a646035 18// AliTOFtrackerV1 Class //
d686d062 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
29#include <Rtypes.h>
30#include <TROOT.h>
31
32#include <TClonesArray.h>
33#include <TTree.h>
34#include <TFile.h>
35#include <TH1F.h>
36#include <TH2F.h>
5c7c93fa 37#include <TSeqCollection.h>
d686d062 38
d686d062 39#include "AliESDtrack.h"
40#include "AliESDEvent.h"
41#include "AliLog.h"
42#include "AliTrackPointArray.h"
5c7c93fa 43#include "AliGeomManager.h"
44#include "AliCDBManager.h"
d686d062 45
d686d062 46#include "AliTOFRecoParam.h"
3a646035 47#include "AliTOFReconstructor.h"
d686d062 48#include "AliTOFcluster.h"
ca270b6d 49#include "AliTOFGeometry.h"
d686d062 50#include "AliTOFtrackerV1.h"
51#include "AliTOFtrack.h"
5c7c93fa 52#include "AliTOFpidESD.h"
d0c2872c 53
d686d062 54extern TROOT *gROOT;
55
56ClassImp(AliTOFtrackerV1)
57
58//_____________________________________________________________________________
59AliTOFtrackerV1::AliTOFtrackerV1():
60 fRecoParam(0x0),
d686d062 61 fPid(0x0),
62 fN(0),
63 fNseeds(0),
64 fNseedsTOF(0),
65 fngoodmatch(0),
66 fnbadmatch(0),
67 fnunmatch(0),
68 fnmatch(0),
b42a5ea1 69 fTracks(new TClonesArray("AliTOFtrack")),
70 fSeeds(new TClonesArray("AliESDtrack")),
d686d062 71 fHDigClusMap(0x0),
72 fHDigNClus(0x0),
73 fHDigClusTime(0x0),
74 fHDigClusToT(0x0),
75 fHRecNClus(0x0),
76 fHRecChi2(0x0),
77 fHRecDistZ(0x0),
78 fHRecSigYVsP(0x0),
79 fHRecSigZVsP(0x0),
80 fHRecSigYVsPWin(0x0),
81 fHRecSigZVsPWin(0x0)
82 {
83 //AliTOFtrackerV1 main Ctor
3a646035 84
d686d062 85 InitCheckHists();
86
d686d062 87}
88//_____________________________________________________________________________
89AliTOFtrackerV1::~AliTOFtrackerV1() {
90 //
91 // Dtor
92 //
93
94 SaveCheckHists();
95
5d456bcd 96 if(!(AliCDBManager::Instance()->GetCacheFlag())){
97 delete fRecoParam;
98 }
d686d062 99 delete fPid;
100 delete fHDigClusMap;
101 delete fHDigNClus;
102 delete fHDigClusTime;
103 delete fHDigClusToT;
104 delete fHRecNClus;
105 delete fHRecChi2;
106 delete fHRecDistZ;
107 delete fHRecSigYVsP;
108 delete fHRecSigZVsP;
109 delete fHRecSigYVsPWin;
110 delete fHRecSigZVsPWin;
b42a5ea1 111 if (fTracks){
112 fTracks->Delete();
113 delete fTracks;
114 fTracks=0x0;
115 }
116 if (fSeeds){
117 fSeeds->Delete();
118 delete fSeeds;
119 fSeeds=0x0;
120 }
d686d062 121}
122//_____________________________________________________________________________
123Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent* event) {
124 //
125 // Gets seeds from ESD event and Match with TOF Clusters
126 //
127
3a646035 128 // initialize RecoParam for current event
129
130 AliInfo("Initializing params for TOF... ");
131
132 fRecoParam = AliTOFReconstructor::GetRecoParam(); // instantiate reco param from STEER...
90b234fe 133
3a646035 134 if (fRecoParam == 0x0) {
135 AliFatal("No Reco Param found for TOF!!!");
136 }
137 //fRecoParam->Dump();
a825d829 138 //if(fRecoParam->GetApplyPbPbCuts())fRecoParam=fRecoParam->GetPbPbparam();
90b234fe 139 //fRecoParam->PrintParameters();
140
3a646035 141 Double_t parPID[2];
142 parPID[0]=fRecoParam->GetTimeResolution();
143 parPID[1]=fRecoParam->GetTimeNSigma();
144 fPid=new AliTOFpidESD(parPID);
d686d062 145
146 //Initialise some counters
147
148 fNseeds=0;
149 fNseedsTOF=0;
150 fngoodmatch=0;
151 fnbadmatch=0;
152 fnunmatch=0;
153 fnmatch=0;
154
155 Int_t ntrk=event->GetNumberOfTracks();
156 fNseeds = ntrk;
d686d062 157 TClonesArray &aESDTrack = *fSeeds;
158
159
160 //Load ESD tracks into a local Array of ESD Seeds
161
162 for (Int_t i=0; i<fNseeds; i++) {
163 AliESDtrack *t=event->GetTrack(i);
164 new(aESDTrack[i]) AliESDtrack(*t);
165 }
166
167 //Prepare ESD tracks candidates for TOF Matching
168 CollectESD();
169
170 //Matching Step
171 MatchTracks();
172
173 AliInfo(Form("Number of matched tracks: %d",fnmatch));
174 AliInfo(Form("Number of good matched tracks: %d",fngoodmatch));
175 AliInfo(Form("Number of bad matched tracks: %d",fnbadmatch));
176
177 //Update the matched ESD tracks
178
179 for (Int_t i=0; i<ntrk; i++) {
180 AliESDtrack *t=event->GetTrack(i);
181 AliESDtrack *seed =(AliESDtrack*)fSeeds->UncheckedAt(i);
6819758a 182
af61c656 183 if ( (seed->GetStatus()&AliESDtrack::kTOFin)!=0 ) {
184 t->SetStatus(AliESDtrack::kTOFin);
185 //if(seed->GetTOFsignal()>0){
186 if ( (seed->GetStatus()&AliESDtrack::kTOFout)!=0 ) {
187 t->SetStatus(AliESDtrack::kTOFout);
188 t->SetTOFsignal(seed->GetTOFsignal());
189 t->SetTOFcluster(seed->GetTOFcluster());
190 t->SetTOFsignalToT(seed->GetTOFsignalToT());
191 t->SetTOFsignalRaw(seed->GetTOFsignalRaw());
192 t->SetTOFsignalDz(seed->GetTOFsignalDz());
46d7d82e 193 t->SetTOFsignalDx(seed->GetTOFsignalDx());
af61c656 194 t->SetTOFCalChannel(seed->GetTOFCalChannel());
195 Int_t tlab[3]; seed->GetTOFLabel(tlab);
196 t->SetTOFLabel(tlab);
24322e5c 197
e81ea7b6 198 Double_t alphaA = dynamic_cast<AliExternalTrackParam*>(t)->GetAlpha();
199 Double_t xA = dynamic_cast<AliExternalTrackParam*>(t)->GetX();
200 Double_t yA = dynamic_cast<AliExternalTrackParam*>(t)->GetY();
201 Double_t zA = dynamic_cast<AliExternalTrackParam*>(t)->GetZ();
202 Double_t p1A = dynamic_cast<AliExternalTrackParam*>(t)->GetSnp();
203 Double_t p2A = dynamic_cast<AliExternalTrackParam*>(t)->GetTgl();
204 Double_t p3A = dynamic_cast<AliExternalTrackParam*>(t)->GetSigned1Pt();
205 const Double_t *covA = dynamic_cast<AliExternalTrackParam*>(t)->GetCovariance();
206
207 // Make attention, please:
208 // AliESDtrack::fTOFInfo array does not be stored in the AliESDs.root file
209 // it is there only for a check during the reconstruction step.
24322e5c 210 Float_t info[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
211 seed->GetTOFInfo(info);
212 t->SetTOFInfo(info);
213 AliDebug(2,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
214
e81ea7b6 215 // Check done:
216 // by calling the AliESDtrack::UpdateTrackParams,
217 // the current track parameters are changed
218 // and it could cause refit problems.
219 // We need to update only the following track parameters:
220 // the track length and expected times.
221 // Removed AliESDtrack::UpdateTrackParams call
222 // Called AliESDtrack::SetIntegratedTimes(...) and
223 // AliESDtrack::SetIntegratedLength() routines.
224 /*
225 AliTOFtrack *track = new AliTOFtrack(*seed);
226 t->UpdateTrackParams(track,AliESDtrack::kTOFout); // to be checked - AdC
227 delete track;
228 Double_t time[10]; t->GetIntegratedTimes(time);
229 */
230
231 Double_t time[10]; seed->GetIntegratedTimes(time);
232 t->SetIntegratedTimes(time);
233
234 Double_t length = seed->GetIntegratedLength();
235 t->SetIntegratedLength(length);
236
237 Double_t alphaB = dynamic_cast<AliExternalTrackParam*>(t)->GetAlpha();
238 Double_t xB = dynamic_cast<AliExternalTrackParam*>(t)->GetX();
239 Double_t yB = dynamic_cast<AliExternalTrackParam*>(t)->GetY();
240 Double_t zB = dynamic_cast<AliExternalTrackParam*>(t)->GetZ();
241 Double_t p1B = dynamic_cast<AliExternalTrackParam*>(t)->GetSnp();
242 Double_t p2B = dynamic_cast<AliExternalTrackParam*>(t)->GetTgl();
243 Double_t p3B = dynamic_cast<AliExternalTrackParam*>(t)->GetSigned1Pt();
244 const Double_t *covB = dynamic_cast<AliExternalTrackParam*>(t)->GetCovariance();
245 AliDebug(2,"Track params -now(before)-:");
246 AliDebug(2,Form(" X: %f(%f), Y: %f(%f), Z: %f(%f) --- alpha: %f(%f)",
247 xB,xA,
248 yB,yA,
249 zB,zA,
250 alphaB,alphaA));
251 AliDebug(2,Form(" p1: %f(%f), p2: %f(%f), p3: %f(%f)",
252 p1B,p1A,
253 p2B,p2A,
254 p3B,p3A));
255 AliDebug(2,Form(" cov1: %f(%f), cov2: %f(%f), cov3: %f(%f)"
256 " cov4: %f(%f), cov5: %f(%f), cov6: %f(%f)"
257 " cov7: %f(%f), cov8: %f(%f), cov9: %f(%f)"
258 " cov10: %f(%f), cov11: %f(%f), cov12: %f(%f)"
259 " cov13: %f(%f), cov14: %f(%f), cov15: %f(%f)",
260 covB[0],covA[0],
261 covB[1],covA[1],
262 covB[2],covA[2],
263 covB[3],covA[3],
264 covB[4],covA[4],
265 covB[5],covA[5],
266 covB[6],covA[6],
267 covB[7],covA[7],
268 covB[8],covA[8],
269 covB[9],covA[9],
270 covB[10],covA[10],
271 covB[11],covA[11],
272 covB[12],covA[12],
273 covB[13],covA[13],
274 covB[14],covA[14]
275 ));
276 AliDebug(3,Form(" %6d %f %f %f %f % %6d %3d %f %f %f %f %f %f",
af61c656 277 i,
278 t->GetTOFsignalRaw(),
279 t->GetTOFsignal(),
280 t->GetTOFsignalToT(),
281 t->GetTOFsignalDz(),
46d7d82e 282 t->GetTOFsignalDx(),
af61c656 283 t->GetTOFCalChannel(),
284 t->GetTOFcluster(),
285 t->GetIntegratedLength(),
286 time[0], time[1], time[2], time[3], time[4]
287 )
288 );
289 }
d686d062 290 }
291 }
292
293 //Handle Time Zero information
294
295 Double_t timeZero=0.;
296 Double_t timeZeroMax=99999.;
297 Bool_t usetimeZero = fRecoParam->UseTimeZero();
298 Bool_t timeZeroFromT0 = fRecoParam->GetTimeZerofromT0();
299 Bool_t timeZeroFromTOF = fRecoParam->GetTimeZerofromTOF();
300
53884c34 301 AliDebug(2,Form("Use Time Zero?: %d",usetimeZero));
302 AliDebug(2,Form("Time Zero from T0? : %d",timeZeroFromT0));
303 AliDebug(2,Form("Time Zero From TOF? : %d",timeZeroFromTOF));
d686d062 304
305 if(usetimeZero){
306 if(timeZeroFromT0){
307 timeZero=GetTimeZerofromT0(event);
308 }
309 if(timeZeroFromTOF && (timeZero>timeZeroMax || !timeZeroFromT0)){
310 timeZero=GetTimeZerofromTOF(event);
311 }
312 }
313 AliDebug(2,Form("time Zero used in PID: %f",timeZero));
314 //Make TOF PID
315 fPid->MakePID(event,timeZero);
316
b42a5ea1 317 fSeeds->Clear();
318 fTracks->Clear();
d686d062 319 return 0;
320
321}
322//_________________________________________________________________________
323void AliTOFtrackerV1::CollectESD() {
324 //prepare the set of ESD tracks to be matched to clusters in TOF
325
326 Int_t seedsTOF1=0;
327 Int_t seedsTOF2=0;
328
d686d062 329 TClonesArray &aTOFTrack = *fTracks;
330 for (Int_t i=0; i<fNseeds; i++) {
331
332 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
333 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
334
d686d062 335 AliTOFtrack *track = new AliTOFtrack(*t); // New
af61c656 336 Float_t x = (Float_t)track->GetX(); //New
337
338 // TRD 'good' tracks, already propagated at 371 cm
339 if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
340 ( x >= AliTOFGeometry::Rmin() ) ) {
341 if ( track->PropagateToInnerTOF() ) {
342
343 AliDebug(1,Form(" TRD propagated track till rho = %fcm."
344 " And then the track has been propagated till rho = %fcm.",
345 x, (Float_t)track->GetX()));
346
347 track->SetSeedIndex(i);
348 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
349 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
350 fNseedsTOF++;
351 seedsTOF1++;
352 }
d686d062 353 delete track;
354 }
355
af61c656 356 // Propagate the rest of TPCbp
d686d062 357 else {
af61c656 358 if ( track->PropagateToInnerTOF() ) {
359
360 AliDebug(1,Form(" TRD propagated track till rho = %fcm."
361 " And then the track has been propagated till rho = %fcm.",
362 x, (Float_t)track->GetX()));
363
d686d062 364 track->SetSeedIndex(i);
af61c656 365 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
d686d062 366 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
367 fNseedsTOF++;
368 seedsTOF2++;
369 }
370 delete track;
371 }
372 }
373
6819758a 374 AliInfo(Form("Number of TOF seeds %d",fNseedsTOF));
375 AliInfo(Form("Number of TOF seeds Type 1 %d",seedsTOF1));
376 AliInfo(Form("Number of TOF seeds Type 2 %d",seedsTOF2));
d686d062 377
378 // Sort according uncertainties on track position
379 fTracks->Sort();
380
381}
382//_________________________________________________________________________
383void AliTOFtrackerV1::MatchTracks( ){
384 //
385 //Match ESD tracks to clusters in TOF
386 //
387
388
389 // Parameters regulating the reconstruction
ca270b6d 390 Float_t dY=AliTOFGeometry::XPad();
391 Float_t dZ=AliTOFGeometry::ZPad();
d686d062 392
6819758a 393 const Float_t kTimeOffset = 32.; // time offset for tracking algorithm [ps]
394
3da9d64f 395 const Int_t kncmax = 100;
d686d062 396 Float_t sensRadius = fRecoParam->GetSensRadius();
397 Float_t scaleFact = fRecoParam->GetWindowScaleFact();
398 Float_t dyMax=fRecoParam->GetWindowSizeMaxY();
399 Float_t dzMax=fRecoParam->GetWindowSizeMaxZ();
400 Double_t maxChi2=fRecoParam->GetMaxChi2();
401 Bool_t timeWalkCorr = fRecoParam->GetTimeWalkCorr();
402 AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++ \n");
403 AliDebug(1,Form("TOF sens radius: %f",sensRadius));
404 AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
405 AliDebug(1,Form("TOF Window max dy: %f",dyMax));
406 AliDebug(1,Form("TOF Window max dz: %f",dzMax));
407 AliDebug(1,Form("TOF Max Chi2: %f",maxChi2));
408 AliDebug(1,Form("Time Walk Correction? : %d",timeWalkCorr));
409
410
411 //The matching loop
d686d062 412 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
413
414 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
415 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
af61c656 416 //if ( t->GetTOFsignal()>0. ) continue;
417 if ( (t->GetStatus()&AliESDtrack::kTOFout)!=0 ) continue;
d686d062 418 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
419
420 // Determine a window around the track
421 Double_t x,par[5]; trackTOFin->GetExternalParameters(x,par);
422 Double_t cov[15]; trackTOFin->GetExternalCovariance(cov);
423
53884c34 424 if (cov[0]<0. || cov[2]<0.) {
425 AliWarning(Form("Very strange track (%d)! At least one of its covariance matrix diagonal elements is negative!",iseed));
ecd795d8 426 //delete trackTOFin;
427 //continue;
53884c34 428 }
429
d686d062 430 Double_t z = par[1];
ecd795d8 431 Double_t dz = scaleFact*3.*TMath::Sqrt(TMath::Abs(cov[2])+dZ*dZ/12.);
432 Double_t dphi = scaleFact*3.*TMath::Sqrt(TMath::Abs(cov[0])+dY*dY/12.)/sensRadius;
d686d062 433
434 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
435 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
436 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
437
438 //upper limit on window's size.
439 if(dz> dzMax) dz=dzMax;
440 if(dphi*sensRadius> dyMax) dphi=dyMax/sensRadius;
441
d686d062 442 // find the clusters inside the selected window
443 Int_t nc=0;
3da9d64f 444 AliTOFcluster *clusters[kncmax]; // pointers to the clusters in the window
445 Int_t index[kncmax];//to keep track of the cluster index
d686d062 446 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
447 AliTOFcluster *c=fClusters[k];
c0b60ae7 448 // if(nc>kncmax)break; /* R+ fix (buffer overflow) */
53884c34 449 if (nc>=kncmax) {
450 AliWarning("No more matchable clusters can be stored! Please, increase the corresponding vectors size.");
451 break; /* R+ fix (buffer overflow protection) */
452 }
d686d062 453 if(c->GetZ() > z+dz) break;
454 if(c->IsUsed()) continue;
17149e6b 455 if(!c->GetStatus()) {
53884c34 456 AliDebug(1,"Cluster in channel declared bad!");
457 continue; // skip bad channels as declared in OCDB
17149e6b 458 }
d686d062 459 Float_t xyz[3]; c->GetGlobalXYZ(xyz);
460 Double_t clPhi=TMath::ATan2(xyz[1],xyz[0]);
461 Double_t dph=TMath::Abs(clPhi-phi);
462 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
463 if (TMath::Abs(dph)>dphi) continue;
464 clusters[nc]=c;
465 index[nc] = k;
466 nc++;
467 }
468
53884c34 469 AliDebug(1,Form(" Number of matchable TOF clusters for the track number %d: %d",iseed,nc));
470
8dacd1bb 471 //start propagation: go to the average TOF pad middle plane at ~379.5 cm
d686d062 472
473 Float_t xTOF = sensRadius;
ca270b6d 474 Double_t ymax = xTOF*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
d686d062 475 Bool_t skip = kFALSE;
476 Double_t ysect = trackTOFin->GetYat(xTOF,skip);
477 if (skip) break;
478 if (ysect > ymax) {
ca270b6d 479 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
d686d062 480 break;
481 }
482 } else if (ysect <-ymax) {
13c769b4 483 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
d686d062 484 break;
485 }
486 }
487 if(!trackTOFin->PropagateTo(xTOF)) {
488 break;
489 }
490
491
492 AliTOFcluster *bestCluster=0;
493 Double_t bestChi2=maxChi2;
494 Int_t idclus=-1;
c0b60ae7 495 // for (Int_t i=0; i<nc; i++){ /* R+ fix (unsafe) */
496 for (Int_t i=0; i<nc && i<kncmax; i++){ /* R+ fix (buffer overflow protection) */
d686d062 497 AliTOFcluster *c=clusters[i]; // one of the preselected clusters
498 Double_t chi2=trackTOFin->GetPredictedChi2((AliCluster3D*)c);
499 if (chi2 >= bestChi2) continue;
500 bestChi2=chi2;
501 bestCluster=c;
502 idclus=index[i];
503 }
504
505 if (!bestCluster) { // no matching , go to the next track
506 fnunmatch++;
507 delete trackTOFin;
508 continue;
509 }
510
511 fnmatch++;
32ead898 512
3a646035 513 AliDebug(2, Form("%7i %7i %10i %10i %10i %10i %7i",
32ead898 514 iseed,
3a646035 515 fnmatch-1,
32ead898 516 TMath::Abs(trackTOFin->GetLabel()),
517 bestCluster->GetLabel(0),
518 bestCluster->GetLabel(1),
3a646035 519 bestCluster->GetLabel(2),
520 idclus)); // AdC
32ead898 521
d686d062 522 bestCluster->Use();
523 if (
524 (bestCluster->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
525 ||
526 (bestCluster->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
527 ||
528 (bestCluster->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
529 ) {
530 fngoodmatch++;
6819758a 531 AliDebug(2,Form(" track label good %5d",trackTOFin->GetLabel()));
d686d062 532
533 }
534 else{
535 fnbadmatch++;
6819758a 536 AliDebug(2,Form(" track label bad %5d",trackTOFin->GetLabel()));
d686d062 537 }
538
539 //Propagate the track to the best matched cluster
540 trackTOFin->PropagateTo(bestCluster);
541
77a9ea9a 542 // Fill the track residual histograms.
543 FillResiduals(trackTOFin,bestCluster,kFALSE);
d686d062 544
545 //now take the local distance in Z from the pad center for time walk correction
ca270b6d 546 Float_t tiltangle = AliTOFGeometry::GetAngles(bestCluster->GetDetInd(1),bestCluster->GetDetInd(2))*TMath::DegToRad();
6819758a 547 Double_t dzTW=trackTOFin->GetZ()-bestCluster->GetZ(); // in cm - in the ALICE RF -
548 dzTW/=TMath::Cos(tiltangle); // from ALICE/tracking RF to pad RF (1)
549 dzTW=-dzTW; // from ALICE/tracking RF to pad RF (2)
550 if (tiltangle!=0.) AliDebug(2,Form(" rho_track = %f --- rho_cluster = %f ",trackTOFin->GetX(),bestCluster->GetX()));
d686d062 551
552 //update the ESD track and delete the TOFtrack
af61c656 553 t->UpdateTrackParams(trackTOFin,AliESDtrack::kTOFout);
d686d062 554
555 // Store quantities to be used in the TOF Calibration
ca270b6d 556 Float_t tToT=AliTOFGeometry::ToTBinWidth()*bestCluster->GetToT()*1E-3; // in ns
d686d062 557 t->SetTOFsignalToT(tToT);
6819758a 558 Float_t rawTime=AliTOFGeometry::TdcBinWidth()*bestCluster->GetTDCRAW()+kTimeOffset; // RAW time,in ps
d686d062 559 t->SetTOFsignalRaw(rawTime);
560 t->SetTOFsignalDz(dzTW);
6819758a 561
24322e5c 562 Float_t deltaY = trackTOFin->GetY()-bestCluster->GetY();
46d7d82e 563 t->SetTOFsignalDx(deltaY);
24322e5c 564
565 Float_t distR = (trackTOFin->GetX()-bestCluster->GetX())*
566 (trackTOFin->GetX()-bestCluster->GetX());
567 distR+=deltaY*deltaY;
568 distR+=dzTW*dzTW;
569 distR = TMath::Sqrt(distR);
570 Float_t info[10] = {distR, deltaY, dzTW,
571 0.,0.,0.,0.,0.,0.,0.};
572 t->SetTOFInfo(info);
573
d686d062 574 Int_t ind[5];
575 ind[0]=bestCluster->GetDetInd(0);
576 ind[1]=bestCluster->GetDetInd(1);
577 ind[2]=bestCluster->GetDetInd(2);
578 ind[3]=bestCluster->GetDetInd(3);
579 ind[4]=bestCluster->GetDetInd(4);
ca270b6d 580 Int_t calindex = AliTOFGeometry::GetIndex(ind);
d686d062 581 t->SetTOFCalChannel(calindex);
582
583 // keep track of the track labels in the matched cluster
584 Int_t tlab[3];
585 tlab[0]=bestCluster->GetLabel(0);
586 tlab[1]=bestCluster->GetLabel(1);
587 tlab[2]=bestCluster->GetLabel(2);
6819758a 588 AliDebug(2,Form(" tdc time of the matched track %6d = ",bestCluster->GetTDC()));
589 Double_t tof=AliTOFGeometry::TdcBinWidth()*bestCluster->GetTDC()+kTimeOffset; // in ps
590 AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
d686d062 591 Double_t tofcorr=tof;
592 if(timeWalkCorr)tofcorr=CorrectTimeWalk(dzTW,tof);
593 AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));
594 //Set TOF time signal and pointer to the matched cluster
595 t->SetTOFsignal(tofcorr);
596 t->SetTOFcluster(idclus); // pointing to the recPoints tree
597 t->SetTOFLabel(tlab);
598
6819758a 599 AliDebug(2,Form(" Setting TOF raw time: %f z distance: %f corrected time: %f",rawTime,dzTW,tofcorr));
600
d686d062 601 Double_t mom=t->GetP();
53884c34 602 AliDebug(2,Form(" Momentum for track %d -> %f", iseed,mom));
d686d062 603 // Fill Reco-QA histos for Reconstruction
604 fHRecNClus->Fill(nc);
605 fHRecChi2->Fill(bestChi2);
606 fHRecDistZ->Fill(dzTW);
607 fHRecSigYVsP->Fill(mom,TMath::Sqrt(cov[0]));
608 fHRecSigZVsP->Fill(mom,TMath::Sqrt(cov[2]));
609 fHRecSigYVsPWin->Fill(mom,dphi*sensRadius);
610 fHRecSigZVsPWin->Fill(mom,dz);
611
612 // Fill Tree for on-the-fly offline Calibration
613 // no longer there - all info is in the ESDs now
614
af61c656 615 delete trackTOFin;
d686d062 616 }
d686d062 617
618}
619//_________________________________________________________________________
620Int_t AliTOFtrackerV1::LoadClusters(TTree *cTree) {
621 //--------------------------------------------------------------------
622 //This function loads the TOF clusters
623 //--------------------------------------------------------------------
624
ca270b6d 625 Int_t npadX = AliTOFGeometry::NpadX();
626 Int_t npadZ = AliTOFGeometry::NpadZ();
627 Int_t nStripA = AliTOFGeometry::NStripA();
628 Int_t nStripB = AliTOFGeometry::NStripB();
629 Int_t nStripC = AliTOFGeometry::NStripC();
d686d062 630
631 TBranch *branch=cTree->GetBranch("TOF");
632 if (!branch) {
633 AliError("can't get the branch with the TOF clusters !");
634 return 1;
635 }
636
b42a5ea1 637 static TClonesArray dummy("AliTOFcluster",10000);
638 dummy.Clear();
639 TClonesArray *clusters=&dummy;
d686d062 640 branch->SetAddress(&clusters);
641
642 cTree->GetEvent(0);
643 Int_t nc=clusters->GetEntriesFast();
644 fHDigNClus->Fill(nc);
645
b42a5ea1 646 AliInfo(Form("Number of clusters: %d",nc));
647
d686d062 648 for (Int_t i=0; i<nc; i++) {
649 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
16a2e36a 650//PH fClusters[i]=new AliTOFcluster(*c); fN++;
651 fClusters[i]=c; fN++;
d686d062 652
653 // Fill Digits QA histos
654
655 Int_t isector = c->GetDetInd(0);
656 Int_t iplate = c->GetDetInd(1);
657 Int_t istrip = c->GetDetInd(2);
658 Int_t ipadX = c->GetDetInd(4);
659 Int_t ipadZ = c->GetDetInd(3);
660
ca270b6d 661 Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
662 Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
d686d062 663
664 Int_t stripOffset = 0;
665 switch (iplate) {
666 case 0:
667 stripOffset = 0;
668 break;
669 case 1:
670 stripOffset = nStripC;
671 break;
672 case 2:
673 stripOffset = nStripC+nStripB;
674 break;
675 case 3:
676 stripOffset = nStripC+nStripB+nStripA;
677 break;
678 case 4:
679 stripOffset = nStripC+nStripB+nStripA+nStripB;
680 break;
681 default:
682 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
683 break;
684 };
685 Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
686 Int_t phiindex=npadX*isector+ipadX+1;
687 fHDigClusMap->Fill(zindex,phiindex);
688 fHDigClusTime->Fill(time);
689 fHDigClusToT->Fill(tot);
690 }
691
692
693 return 0;
694}
695//_________________________________________________________________________
696void AliTOFtrackerV1::UnloadClusters() {
697 //--------------------------------------------------------------------
698 //This function unloads TOF clusters
699 //--------------------------------------------------------------------
700 for (Int_t i=0; i<fN; i++) {
16a2e36a 701//PH delete fClusters[i];
d686d062 702 fClusters[i] = 0x0;
703 }
704 fN=0;
705}
706
707//_________________________________________________________________________
708Int_t AliTOFtrackerV1::FindClusterIndex(Double_t z) const {
709 //--------------------------------------------------------------------
710 // This function returns the index of the nearest cluster
711 //--------------------------------------------------------------------
712 //MOD
713 //Here we need to get the Z in the tracking system
714
715 if (fN==0) return 0;
716 if (z <= fClusters[0]->GetZ()) return 0;
717 if (z > fClusters[fN-1]->GetZ()) return fN;
718 Int_t b=0, e=fN-1, m=(b+e)/2;
719 for (; b<e; m=(b+e)/2) {
720 if (z > fClusters[m]->GetZ()) b=m+1;
721 else e=m;
722 }
723 return m;
724}
725
726//_________________________________________________________________________
727Bool_t AliTOFtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint& p) const
728{
729 // Get track space point with index i
730 // Coordinates are in the global system
731 AliTOFcluster *cl = fClusters[index];
732 Float_t xyz[3];
733 cl->GetGlobalXYZ(xyz);
734 Float_t phi=TMath::ATan2(xyz[1],xyz[0]);
735 Float_t phiangle = (Int_t(phi*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
736 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
ca270b6d 737 Float_t tiltangle = AliTOFGeometry::GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
d686d062 738 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
ca270b6d 739 Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
740 Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
d686d062 741 Float_t cov[6];
742 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
743 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
744 cov[2] = -cosphi*sinth*costh*sigmaz2;
745 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
746 cov[4] = -sinphi*sinth*costh*sigmaz2;
747 cov[5] = costh*costh*sigmaz2;
748 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
749
750 // Detector numbering scheme
ca270b6d 751 Int_t nSector = AliTOFGeometry::NSectors();
752 Int_t nPlate = AliTOFGeometry::NPlates();
753 Int_t nStripA = AliTOFGeometry::NStripA();
754 Int_t nStripB = AliTOFGeometry::NStripB();
755 Int_t nStripC = AliTOFGeometry::NStripC();
d686d062 756
757 Int_t isector = cl->GetDetInd(0);
758 if (isector >= nSector)
759 AliError(Form("Wrong sector number in TOF (%d) !",isector));
760 Int_t iplate = cl->GetDetInd(1);
761 if (iplate >= nPlate)
762 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
763 Int_t istrip = cl->GetDetInd(2);
764
765 Int_t stripOffset = 0;
766 switch (iplate) {
767 case 0:
768 stripOffset = 0;
769 break;
770 case 1:
771 stripOffset = nStripC;
772 break;
773 case 2:
774 stripOffset = nStripC+nStripB;
775 break;
776 case 3:
777 stripOffset = nStripC+nStripB+nStripA;
778 break;
779 case 4:
780 stripOffset = nStripC+nStripB+nStripA+nStripB;
781 break;
782 default:
783 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
784 break;
785 };
786
787 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
788 stripOffset +
789 istrip;
790 UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
791 p.SetVolumeID((UShort_t)volid);
792 return kTRUE;
793}
794//_________________________________________________________________________
795void AliTOFtrackerV1::InitCheckHists() {
796
797 //Init histos for Digits/Reco QA and Calibration
798
3a646035 799 TDirectory *dir = gDirectory;
800 TFile *logFileTOF = 0;
801
802 TSeqCollection *list = gROOT->GetListOfFiles();
803 int n = list->GetEntries();
804 Bool_t isThere=kFALSE;
805 for(int i=0; i<n; i++) {
806 logFileTOF = (TFile*)list->At(i);
807 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
808 isThere=kTRUE;
809 break;
810 }
811 }
812
813 if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
814 logFileTOF->cd();
815
d686d062 816 //Digits "QA"
817 fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);
818 fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);
819 fHDigClusTime = new TH1F("TOFDig_ClusTime", "",2000,0.,200.);
820 fHDigClusToT = new TH1F("TOFDig_ClusToT", "",500,0.,100);
821
822 //Reco "QA"
823 fHRecNClus =new TH1F("TOFRec_NClusW", "",50,0.5,50.5);
824 fHRecDistZ=new TH1F("TOFRec_DistZ", "",50,0.5,10.5);
825 fHRecChi2=new TH1F("TOFRec_Chi2", "",100,0.,10.);
826 fHRecSigYVsP=new TH2F("TOFDig_SigYVsP", "",40,0.,4.,100, 0.,5.);
827 fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
828 fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
829 fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
3a646035 830
831 dir->cd();
832
d686d062 833}
834
835//_________________________________________________________________________
836void AliTOFtrackerV1::SaveCheckHists() {
837
838 //write histos for Digits/Reco QA and Calibration
839
840 TDirectory *dir = gDirectory;
841 TFile *logFile = 0;
842 TFile *logFileTOF = 0;
843
844 TSeqCollection *list = gROOT->GetListOfFiles();
845 int n = list->GetEntries();
846 for(int i=0; i<n; i++) {
847 logFile = (TFile*)list->At(i);
848 if (strstr(logFile->GetName(), "AliESDs.root")) break;
849 }
850
851 Bool_t isThere=kFALSE;
852 for(int i=0; i<n; i++) {
853 logFileTOF = (TFile*)list->At(i);
854 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
855 isThere=kTRUE;
856 break;
857 }
858 }
859
3a646035 860 if(!isThere) {
861 AliError(Form("File TOFQA.root not found!! not wring histograms...."));
862 return;
863 }
d686d062 864 logFile->cd();
865 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
866 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
867 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
868 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
869 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
870 fHRecChi2->Write(fHRecChi2->GetName(), TObject::kOverwrite);
871 fHRecDistZ->Write(fHRecDistZ->GetName(), TObject::kOverwrite);
872 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
873 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
874 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
875 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
876 logFile->Flush();
877
d686d062 878 dir->cd();
3a646035 879
d686d062 880 }
881//_________________________________________________________________________
882Float_t AliTOFtrackerV1::CorrectTimeWalk( Float_t dist, Float_t tof) {
883
884 //dummy, for the moment
885 Float_t tofcorr=0.;
ca270b6d 886 if(dist<AliTOFGeometry::ZPad()*0.5){
d686d062 887 tofcorr=tof;
888 //place here the actual correction
889 }else{
890 tofcorr=tof;
891 }
892 return tofcorr;
893}
894//_________________________________________________________________________
895Float_t AliTOFtrackerV1::GetTimeZerofromT0(AliESDEvent *event) const {
896
897 //Returns TimeZero as measured by T0 detector
898
899 return event->GetT0();
900}
901//_________________________________________________________________________
902Float_t AliTOFtrackerV1::GetTimeZerofromTOF(AliESDEvent * /*event*/) const {
903
904 //dummy, for the moment. T0 algorithm using tracks on TOF
905 {
906 //place T0 algo here...
907 }
908 return 0.;
909}
128563f6 910//_________________________________________________________________________
911
912void AliTOFtrackerV1::FillClusterArray(TObjArray* arr) const
913{
914 //
915 // Returns the TOF cluster array
916 //
917
918 if (fN==0)
919 arr = 0x0;
920 else
921 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
922
923}