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