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