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