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