iii) Add like-sign filter for on-the-fly V0 (B.Hippolyte)
[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
87}
88//_____________________________________________________________________________
d686d062 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
198 Float_t info[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
199 seed->GetTOFInfo(info);
200 t->SetTOFInfo(info);
201 AliDebug(2,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
202
af61c656 203 AliTOFtrack *track = new AliTOFtrack(*seed);
204 t->UpdateTrackParams(track,AliESDtrack::kTOFout); // to be checked - AdC
205 delete track;
206
207 Double_t time[10]; t->GetIntegratedTimes(time);
46d7d82e 208 AliDebug(2,Form(" %6d %f %f %f %f % %6d %3d %f %f %f %f %f %f",
af61c656 209 i,
210 t->GetTOFsignalRaw(),
211 t->GetTOFsignal(),
212 t->GetTOFsignalToT(),
213 t->GetTOFsignalDz(),
46d7d82e 214 t->GetTOFsignalDx(),
af61c656 215 t->GetTOFCalChannel(),
216 t->GetTOFcluster(),
217 t->GetIntegratedLength(),
218 time[0], time[1], time[2], time[3], time[4]
219 )
220 );
221 }
d686d062 222 }
223 }
224
225 //Handle Time Zero information
226
227 Double_t timeZero=0.;
228 Double_t timeZeroMax=99999.;
229 Bool_t usetimeZero = fRecoParam->UseTimeZero();
230 Bool_t timeZeroFromT0 = fRecoParam->GetTimeZerofromT0();
231 Bool_t timeZeroFromTOF = fRecoParam->GetTimeZerofromTOF();
232
53884c34 233 AliDebug(2,Form("Use Time Zero?: %d",usetimeZero));
234 AliDebug(2,Form("Time Zero from T0? : %d",timeZeroFromT0));
235 AliDebug(2,Form("Time Zero From TOF? : %d",timeZeroFromTOF));
d686d062 236
237 if(usetimeZero){
238 if(timeZeroFromT0){
239 timeZero=GetTimeZerofromT0(event);
240 }
241 if(timeZeroFromTOF && (timeZero>timeZeroMax || !timeZeroFromT0)){
242 timeZero=GetTimeZerofromTOF(event);
243 }
244 }
245 AliDebug(2,Form("time Zero used in PID: %f",timeZero));
246 //Make TOF PID
247 fPid->MakePID(event,timeZero);
248
b42a5ea1 249 fSeeds->Clear();
250 fTracks->Clear();
d686d062 251 return 0;
252
253}
254//_________________________________________________________________________
255void AliTOFtrackerV1::CollectESD() {
256 //prepare the set of ESD tracks to be matched to clusters in TOF
257
258 Int_t seedsTOF1=0;
259 Int_t seedsTOF2=0;
260
d686d062 261 TClonesArray &aTOFTrack = *fTracks;
262 for (Int_t i=0; i<fNseeds; i++) {
263
264 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
265 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
266
d686d062 267 AliTOFtrack *track = new AliTOFtrack(*t); // New
af61c656 268 Float_t x = (Float_t)track->GetX(); //New
269
270 // TRD 'good' tracks, already propagated at 371 cm
271 if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
272 ( x >= AliTOFGeometry::Rmin() ) ) {
273 if ( track->PropagateToInnerTOF() ) {
274
275 AliDebug(1,Form(" TRD propagated track till rho = %fcm."
276 " And then the track has been propagated till rho = %fcm.",
277 x, (Float_t)track->GetX()));
278
279 track->SetSeedIndex(i);
280 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
281 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
282 fNseedsTOF++;
283 seedsTOF1++;
284 }
d686d062 285 delete track;
286 }
287
af61c656 288 // Propagate the rest of TPCbp
d686d062 289 else {
af61c656 290 if ( track->PropagateToInnerTOF() ) {
291
292 AliDebug(1,Form(" TRD propagated track till rho = %fcm."
293 " And then the track has been propagated till rho = %fcm.",
294 x, (Float_t)track->GetX()));
295
d686d062 296 track->SetSeedIndex(i);
af61c656 297 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
d686d062 298 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
299 fNseedsTOF++;
300 seedsTOF2++;
301 }
302 delete track;
303 }
304 }
305
6819758a 306 AliInfo(Form("Number of TOF seeds %d",fNseedsTOF));
307 AliInfo(Form("Number of TOF seeds Type 1 %d",seedsTOF1));
308 AliInfo(Form("Number of TOF seeds Type 2 %d",seedsTOF2));
d686d062 309
310 // Sort according uncertainties on track position
311 fTracks->Sort();
312
313}
314//_________________________________________________________________________
315void AliTOFtrackerV1::MatchTracks( ){
316 //
317 //Match ESD tracks to clusters in TOF
318 //
319
320
321 // Parameters regulating the reconstruction
ca270b6d 322 Float_t dY=AliTOFGeometry::XPad();
323 Float_t dZ=AliTOFGeometry::ZPad();
d686d062 324
6819758a 325 const Float_t kTimeOffset = 32.; // time offset for tracking algorithm [ps]
326
3da9d64f 327 const Int_t kncmax = 100;
d686d062 328 Float_t sensRadius = fRecoParam->GetSensRadius();
329 Float_t scaleFact = fRecoParam->GetWindowScaleFact();
330 Float_t dyMax=fRecoParam->GetWindowSizeMaxY();
331 Float_t dzMax=fRecoParam->GetWindowSizeMaxZ();
332 Double_t maxChi2=fRecoParam->GetMaxChi2();
333 Bool_t timeWalkCorr = fRecoParam->GetTimeWalkCorr();
334 AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++ \n");
335 AliDebug(1,Form("TOF sens radius: %f",sensRadius));
336 AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
337 AliDebug(1,Form("TOF Window max dy: %f",dyMax));
338 AliDebug(1,Form("TOF Window max dz: %f",dzMax));
339 AliDebug(1,Form("TOF Max Chi2: %f",maxChi2));
340 AliDebug(1,Form("Time Walk Correction? : %d",timeWalkCorr));
341
342
343 //The matching loop
d686d062 344 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
345
346 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
347 AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(track->GetSeedIndex());
af61c656 348 //if ( t->GetTOFsignal()>0. ) continue;
349 if ( (t->GetStatus()&AliESDtrack::kTOFout)!=0 ) continue;
d686d062 350 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
351
352 // Determine a window around the track
353 Double_t x,par[5]; trackTOFin->GetExternalParameters(x,par);
354 Double_t cov[15]; trackTOFin->GetExternalCovariance(cov);
355
53884c34 356 if (cov[0]<0. || cov[2]<0.) {
357 AliWarning(Form("Very strange track (%d)! At least one of its covariance matrix diagonal elements is negative!",iseed));
ecd795d8 358 //delete trackTOFin;
359 //continue;
53884c34 360 }
361
d686d062 362 Double_t z = par[1];
ecd795d8 363 Double_t dz = scaleFact*3.*TMath::Sqrt(TMath::Abs(cov[2])+dZ*dZ/12.);
364 Double_t dphi = scaleFact*3.*TMath::Sqrt(TMath::Abs(cov[0])+dY*dY/12.)/sensRadius;
d686d062 365
366 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
367 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
368 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
369
370 //upper limit on window's size.
371 if(dz> dzMax) dz=dzMax;
372 if(dphi*sensRadius> dyMax) dphi=dyMax/sensRadius;
373
d686d062 374 // find the clusters inside the selected window
375 Int_t nc=0;
3da9d64f 376 AliTOFcluster *clusters[kncmax]; // pointers to the clusters in the window
377 Int_t index[kncmax];//to keep track of the cluster index
d686d062 378 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
379 AliTOFcluster *c=fClusters[k];
c0b60ae7 380 // if(nc>kncmax)break; /* R+ fix (buffer overflow) */
53884c34 381 if (nc>=kncmax) {
382 AliWarning("No more matchable clusters can be stored! Please, increase the corresponding vectors size.");
383 break; /* R+ fix (buffer overflow protection) */
384 }
d686d062 385 if(c->GetZ() > z+dz) break;
386 if(c->IsUsed()) continue;
17149e6b 387 if(!c->GetStatus()) {
53884c34 388 AliDebug(1,"Cluster in channel declared bad!");
389 continue; // skip bad channels as declared in OCDB
17149e6b 390 }
d686d062 391 Float_t xyz[3]; c->GetGlobalXYZ(xyz);
392 Double_t clPhi=TMath::ATan2(xyz[1],xyz[0]);
393 Double_t dph=TMath::Abs(clPhi-phi);
394 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
395 if (TMath::Abs(dph)>dphi) continue;
396 clusters[nc]=c;
397 index[nc] = k;
398 nc++;
399 }
400
53884c34 401 AliDebug(1,Form(" Number of matchable TOF clusters for the track number %d: %d",iseed,nc));
402
8dacd1bb 403 //start propagation: go to the average TOF pad middle plane at ~379.5 cm
d686d062 404
405 Float_t xTOF = sensRadius;
ca270b6d 406 Double_t ymax = xTOF*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
d686d062 407 Bool_t skip = kFALSE;
408 Double_t ysect = trackTOFin->GetYat(xTOF,skip);
409 if (skip) break;
410 if (ysect > ymax) {
ca270b6d 411 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
d686d062 412 break;
413 }
414 } else if (ysect <-ymax) {
13c769b4 415 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
d686d062 416 break;
417 }
418 }
419 if(!trackTOFin->PropagateTo(xTOF)) {
420 break;
421 }
422
423
424 AliTOFcluster *bestCluster=0;
425 Double_t bestChi2=maxChi2;
426 Int_t idclus=-1;
c0b60ae7 427 // for (Int_t i=0; i<nc; i++){ /* R+ fix (unsafe) */
428 for (Int_t i=0; i<nc && i<kncmax; i++){ /* R+ fix (buffer overflow protection) */
d686d062 429 AliTOFcluster *c=clusters[i]; // one of the preselected clusters
430 Double_t chi2=trackTOFin->GetPredictedChi2((AliCluster3D*)c);
431 if (chi2 >= bestChi2) continue;
432 bestChi2=chi2;
433 bestCluster=c;
434 idclus=index[i];
435 }
436
437 if (!bestCluster) { // no matching , go to the next track
438 fnunmatch++;
439 delete trackTOFin;
440 continue;
441 }
442
443 fnmatch++;
32ead898 444
3a646035 445 AliDebug(2, Form("%7i %7i %10i %10i %10i %10i %7i",
32ead898 446 iseed,
3a646035 447 fnmatch-1,
32ead898 448 TMath::Abs(trackTOFin->GetLabel()),
449 bestCluster->GetLabel(0),
450 bestCluster->GetLabel(1),
3a646035 451 bestCluster->GetLabel(2),
452 idclus)); // AdC
32ead898 453
d686d062 454 bestCluster->Use();
455 if (
456 (bestCluster->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
457 ||
458 (bestCluster->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
459 ||
460 (bestCluster->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
461 ) {
462 fngoodmatch++;
6819758a 463 AliDebug(2,Form(" track label good %5d",trackTOFin->GetLabel()));
d686d062 464
465 }
466 else{
467 fnbadmatch++;
6819758a 468 AliDebug(2,Form(" track label bad %5d",trackTOFin->GetLabel()));
d686d062 469 }
470
471 //Propagate the track to the best matched cluster
472 trackTOFin->PropagateTo(bestCluster);
473
77a9ea9a 474 // Fill the track residual histograms.
475 FillResiduals(trackTOFin,bestCluster,kFALSE);
d686d062 476
477 //now take the local distance in Z from the pad center for time walk correction
ca270b6d 478 Float_t tiltangle = AliTOFGeometry::GetAngles(bestCluster->GetDetInd(1),bestCluster->GetDetInd(2))*TMath::DegToRad();
6819758a 479 Double_t dzTW=trackTOFin->GetZ()-bestCluster->GetZ(); // in cm - in the ALICE RF -
480 dzTW/=TMath::Cos(tiltangle); // from ALICE/tracking RF to pad RF (1)
481 dzTW=-dzTW; // from ALICE/tracking RF to pad RF (2)
482 if (tiltangle!=0.) AliDebug(2,Form(" rho_track = %f --- rho_cluster = %f ",trackTOFin->GetX(),bestCluster->GetX()));
d686d062 483
484 //update the ESD track and delete the TOFtrack
af61c656 485 t->UpdateTrackParams(trackTOFin,AliESDtrack::kTOFout);
d686d062 486
487 // Store quantities to be used in the TOF Calibration
ca270b6d 488 Float_t tToT=AliTOFGeometry::ToTBinWidth()*bestCluster->GetToT()*1E-3; // in ns
d686d062 489 t->SetTOFsignalToT(tToT);
6819758a 490 Float_t rawTime=AliTOFGeometry::TdcBinWidth()*bestCluster->GetTDCRAW()+kTimeOffset; // RAW time,in ps
d686d062 491 t->SetTOFsignalRaw(rawTime);
492 t->SetTOFsignalDz(dzTW);
6819758a 493
24322e5c 494 Float_t deltaY = trackTOFin->GetY()-bestCluster->GetY();
46d7d82e 495 t->SetTOFsignalDx(deltaY);
24322e5c 496
497 Float_t distR = (trackTOFin->GetX()-bestCluster->GetX())*
498 (trackTOFin->GetX()-bestCluster->GetX());
499 distR+=deltaY*deltaY;
500 distR+=dzTW*dzTW;
501 distR = TMath::Sqrt(distR);
502 Float_t info[10] = {distR, deltaY, dzTW,
503 0.,0.,0.,0.,0.,0.,0.};
504 t->SetTOFInfo(info);
505
d686d062 506 Int_t ind[5];
507 ind[0]=bestCluster->GetDetInd(0);
508 ind[1]=bestCluster->GetDetInd(1);
509 ind[2]=bestCluster->GetDetInd(2);
510 ind[3]=bestCluster->GetDetInd(3);
511 ind[4]=bestCluster->GetDetInd(4);
ca270b6d 512 Int_t calindex = AliTOFGeometry::GetIndex(ind);
d686d062 513 t->SetTOFCalChannel(calindex);
514
515 // keep track of the track labels in the matched cluster
516 Int_t tlab[3];
517 tlab[0]=bestCluster->GetLabel(0);
518 tlab[1]=bestCluster->GetLabel(1);
519 tlab[2]=bestCluster->GetLabel(2);
6819758a 520 AliDebug(2,Form(" tdc time of the matched track %6d = ",bestCluster->GetTDC()));
521 Double_t tof=AliTOFGeometry::TdcBinWidth()*bestCluster->GetTDC()+kTimeOffset; // in ps
522 AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
d686d062 523 Double_t tofcorr=tof;
524 if(timeWalkCorr)tofcorr=CorrectTimeWalk(dzTW,tof);
525 AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));
526 //Set TOF time signal and pointer to the matched cluster
527 t->SetTOFsignal(tofcorr);
528 t->SetTOFcluster(idclus); // pointing to the recPoints tree
529 t->SetTOFLabel(tlab);
530
6819758a 531 AliDebug(2,Form(" Setting TOF raw time: %f z distance: %f corrected time: %f",rawTime,dzTW,tofcorr));
532
d686d062 533 Double_t mom=t->GetP();
53884c34 534 AliDebug(2,Form(" Momentum for track %d -> %f", iseed,mom));
d686d062 535 // Fill Reco-QA histos for Reconstruction
536 fHRecNClus->Fill(nc);
537 fHRecChi2->Fill(bestChi2);
538 fHRecDistZ->Fill(dzTW);
539 fHRecSigYVsP->Fill(mom,TMath::Sqrt(cov[0]));
540 fHRecSigZVsP->Fill(mom,TMath::Sqrt(cov[2]));
541 fHRecSigYVsPWin->Fill(mom,dphi*sensRadius);
542 fHRecSigZVsPWin->Fill(mom,dz);
543
544 // Fill Tree for on-the-fly offline Calibration
545 // no longer there - all info is in the ESDs now
546
af61c656 547 delete trackTOFin;
d686d062 548 }
d686d062 549
550}
551//_________________________________________________________________________
552Int_t AliTOFtrackerV1::LoadClusters(TTree *cTree) {
553 //--------------------------------------------------------------------
554 //This function loads the TOF clusters
555 //--------------------------------------------------------------------
556
ca270b6d 557 Int_t npadX = AliTOFGeometry::NpadX();
558 Int_t npadZ = AliTOFGeometry::NpadZ();
559 Int_t nStripA = AliTOFGeometry::NStripA();
560 Int_t nStripB = AliTOFGeometry::NStripB();
561 Int_t nStripC = AliTOFGeometry::NStripC();
d686d062 562
563 TBranch *branch=cTree->GetBranch("TOF");
564 if (!branch) {
565 AliError("can't get the branch with the TOF clusters !");
566 return 1;
567 }
568
b42a5ea1 569 static TClonesArray dummy("AliTOFcluster",10000);
570 dummy.Clear();
571 TClonesArray *clusters=&dummy;
d686d062 572 branch->SetAddress(&clusters);
573
574 cTree->GetEvent(0);
575 Int_t nc=clusters->GetEntriesFast();
576 fHDigNClus->Fill(nc);
577
b42a5ea1 578 AliInfo(Form("Number of clusters: %d",nc));
579
d686d062 580 for (Int_t i=0; i<nc; i++) {
581 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
16a2e36a 582//PH fClusters[i]=new AliTOFcluster(*c); fN++;
583 fClusters[i]=c; fN++;
d686d062 584
585 // Fill Digits QA histos
586
587 Int_t isector = c->GetDetInd(0);
588 Int_t iplate = c->GetDetInd(1);
589 Int_t istrip = c->GetDetInd(2);
590 Int_t ipadX = c->GetDetInd(4);
591 Int_t ipadZ = c->GetDetInd(3);
592
ca270b6d 593 Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
594 Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
d686d062 595
596 Int_t stripOffset = 0;
597 switch (iplate) {
598 case 0:
599 stripOffset = 0;
600 break;
601 case 1:
602 stripOffset = nStripC;
603 break;
604 case 2:
605 stripOffset = nStripC+nStripB;
606 break;
607 case 3:
608 stripOffset = nStripC+nStripB+nStripA;
609 break;
610 case 4:
611 stripOffset = nStripC+nStripB+nStripA+nStripB;
612 break;
613 default:
614 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
615 break;
616 };
617 Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
618 Int_t phiindex=npadX*isector+ipadX+1;
619 fHDigClusMap->Fill(zindex,phiindex);
620 fHDigClusTime->Fill(time);
621 fHDigClusToT->Fill(tot);
622 }
623
624
625 return 0;
626}
627//_________________________________________________________________________
628void AliTOFtrackerV1::UnloadClusters() {
629 //--------------------------------------------------------------------
630 //This function unloads TOF clusters
631 //--------------------------------------------------------------------
632 for (Int_t i=0; i<fN; i++) {
16a2e36a 633//PH delete fClusters[i];
d686d062 634 fClusters[i] = 0x0;
635 }
636 fN=0;
637}
638
639//_________________________________________________________________________
640Int_t AliTOFtrackerV1::FindClusterIndex(Double_t z) const {
641 //--------------------------------------------------------------------
642 // This function returns the index of the nearest cluster
643 //--------------------------------------------------------------------
644 //MOD
645 //Here we need to get the Z in the tracking system
646
647 if (fN==0) return 0;
648 if (z <= fClusters[0]->GetZ()) return 0;
649 if (z > fClusters[fN-1]->GetZ()) return fN;
650 Int_t b=0, e=fN-1, m=(b+e)/2;
651 for (; b<e; m=(b+e)/2) {
652 if (z > fClusters[m]->GetZ()) b=m+1;
653 else e=m;
654 }
655 return m;
656}
657
658//_________________________________________________________________________
659Bool_t AliTOFtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint& p) const
660{
661 // Get track space point with index i
662 // Coordinates are in the global system
663 AliTOFcluster *cl = fClusters[index];
664 Float_t xyz[3];
665 cl->GetGlobalXYZ(xyz);
666 Float_t phi=TMath::ATan2(xyz[1],xyz[0]);
667 Float_t phiangle = (Int_t(phi*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
668 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
ca270b6d 669 Float_t tiltangle = AliTOFGeometry::GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
d686d062 670 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
ca270b6d 671 Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
672 Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
d686d062 673 Float_t cov[6];
674 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
675 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
676 cov[2] = -cosphi*sinth*costh*sigmaz2;
677 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
678 cov[4] = -sinphi*sinth*costh*sigmaz2;
679 cov[5] = costh*costh*sigmaz2;
680 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
681
682 // Detector numbering scheme
ca270b6d 683 Int_t nSector = AliTOFGeometry::NSectors();
684 Int_t nPlate = AliTOFGeometry::NPlates();
685 Int_t nStripA = AliTOFGeometry::NStripA();
686 Int_t nStripB = AliTOFGeometry::NStripB();
687 Int_t nStripC = AliTOFGeometry::NStripC();
d686d062 688
689 Int_t isector = cl->GetDetInd(0);
690 if (isector >= nSector)
691 AliError(Form("Wrong sector number in TOF (%d) !",isector));
692 Int_t iplate = cl->GetDetInd(1);
693 if (iplate >= nPlate)
694 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
695 Int_t istrip = cl->GetDetInd(2);
696
697 Int_t stripOffset = 0;
698 switch (iplate) {
699 case 0:
700 stripOffset = 0;
701 break;
702 case 1:
703 stripOffset = nStripC;
704 break;
705 case 2:
706 stripOffset = nStripC+nStripB;
707 break;
708 case 3:
709 stripOffset = nStripC+nStripB+nStripA;
710 break;
711 case 4:
712 stripOffset = nStripC+nStripB+nStripA+nStripB;
713 break;
714 default:
715 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
716 break;
717 };
718
719 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
720 stripOffset +
721 istrip;
722 UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
723 p.SetVolumeID((UShort_t)volid);
724 return kTRUE;
725}
726//_________________________________________________________________________
727void AliTOFtrackerV1::InitCheckHists() {
728
729 //Init histos for Digits/Reco QA and Calibration
730
3a646035 731 TDirectory *dir = gDirectory;
732 TFile *logFileTOF = 0;
733
734 TSeqCollection *list = gROOT->GetListOfFiles();
735 int n = list->GetEntries();
736 Bool_t isThere=kFALSE;
737 for(int i=0; i<n; i++) {
738 logFileTOF = (TFile*)list->At(i);
739 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
740 isThere=kTRUE;
741 break;
742 }
743 }
744
745 if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
746 logFileTOF->cd();
747
d686d062 748 //Digits "QA"
749 fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);
750 fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);
751 fHDigClusTime = new TH1F("TOFDig_ClusTime", "",2000,0.,200.);
752 fHDigClusToT = new TH1F("TOFDig_ClusToT", "",500,0.,100);
753
754 //Reco "QA"
755 fHRecNClus =new TH1F("TOFRec_NClusW", "",50,0.5,50.5);
756 fHRecDistZ=new TH1F("TOFRec_DistZ", "",50,0.5,10.5);
757 fHRecChi2=new TH1F("TOFRec_Chi2", "",100,0.,10.);
758 fHRecSigYVsP=new TH2F("TOFDig_SigYVsP", "",40,0.,4.,100, 0.,5.);
759 fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
760 fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
761 fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
3a646035 762
763 dir->cd();
764
d686d062 765}
766
767//_________________________________________________________________________
768void AliTOFtrackerV1::SaveCheckHists() {
769
770 //write histos for Digits/Reco QA and Calibration
771
772 TDirectory *dir = gDirectory;
773 TFile *logFile = 0;
774 TFile *logFileTOF = 0;
775
776 TSeqCollection *list = gROOT->GetListOfFiles();
777 int n = list->GetEntries();
778 for(int i=0; i<n; i++) {
779 logFile = (TFile*)list->At(i);
780 if (strstr(logFile->GetName(), "AliESDs.root")) break;
781 }
782
783 Bool_t isThere=kFALSE;
784 for(int i=0; i<n; i++) {
785 logFileTOF = (TFile*)list->At(i);
786 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
787 isThere=kTRUE;
788 break;
789 }
790 }
791
3a646035 792 if(!isThere) {
793 AliError(Form("File TOFQA.root not found!! not wring histograms...."));
794 return;
795 }
d686d062 796 logFile->cd();
797 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
798 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
799 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
800 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
801 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
802 fHRecChi2->Write(fHRecChi2->GetName(), TObject::kOverwrite);
803 fHRecDistZ->Write(fHRecDistZ->GetName(), TObject::kOverwrite);
804 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
805 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
806 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
807 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
808 logFile->Flush();
809
d686d062 810 dir->cd();
3a646035 811
d686d062 812 }
813//_________________________________________________________________________
814Float_t AliTOFtrackerV1::CorrectTimeWalk( Float_t dist, Float_t tof) {
815
816 //dummy, for the moment
817 Float_t tofcorr=0.;
ca270b6d 818 if(dist<AliTOFGeometry::ZPad()*0.5){
d686d062 819 tofcorr=tof;
820 //place here the actual correction
821 }else{
822 tofcorr=tof;
823 }
824 return tofcorr;
825}
826//_________________________________________________________________________
827Float_t AliTOFtrackerV1::GetTimeZerofromT0(AliESDEvent *event) const {
828
829 //Returns TimeZero as measured by T0 detector
830
831 return event->GetT0();
832}
833//_________________________________________________________________________
834Float_t AliTOFtrackerV1::GetTimeZerofromTOF(AliESDEvent * /*event*/) const {
835
836 //dummy, for the moment. T0 algorithm using tracks on TOF
837 {
838 //place T0 algo here...
839 }
840 return 0.;
841}
128563f6 842//_________________________________________________________________________
843
844void AliTOFtrackerV1::FillClusterArray(TObjArray* arr) const
845{
846 //
847 // Returns the TOF cluster array
848 //
849
850 if (fN==0)
851 arr = 0x0;
852 else
853 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
854
855}