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