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