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