]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TOF/AliTOFtrackerV1.cxx
Remove old raw reader class
[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 <TObjArray.h>
34#include <TTree.h>
35#include <TFile.h>
36#include <TH1F.h>
37#include <TH2F.h>
38#include <TSeqCollection.h>
39
40#include "AliESDtrack.h"
41#include "AliESDEvent.h"
42#include "AliESDpid.h"
43#include "AliLog.h"
44#include "AliTrackPointArray.h"
45#include "AliGeomManager.h"
46#include "AliCDBManager.h"
47
48#include "AliTOFRecoParam.h"
49#include "AliTOFReconstructor.h"
50#include "AliTOFcluster.h"
51#include "AliTOFGeometry.h"
52#include "AliTOFtrackerV1.h"
53#include "AliTOFtrack.h"
54
55extern TROOT *gROOT;
56
57ClassImp(AliTOFtrackerV1)
58
59//_____________________________________________________________________________
60AliTOFtrackerV1::AliTOFtrackerV1():
61 fkRecoParam(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 TObjArray(100)),
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 fkRecoParam;
98 }
99 delete fHDigClusMap;
100 delete fHDigNClus;
101 delete fHDigClusTime;
102 delete fHDigClusToT;
103 delete fHRecNClus;
104 delete fHRecChi2;
105 delete fHRecDistZ;
106 delete fHRecSigYVsP;
107 delete fHRecSigZVsP;
108 delete fHRecSigYVsPWin;
109 delete fHRecSigZVsPWin;
110 if (fTracks){
111 fTracks->Delete();
112 delete fTracks;
113 fTracks=0x0;
114 }
115 if (fSeeds){
116 fSeeds->Delete();
117 delete fSeeds;
118 fSeeds=0x0;
119 }
120}
121//_____________________________________________________________________________
122void AliTOFtrackerV1::GetPidSettings(AliESDpid *esdPID) {
123 //
124 // Sets TOF resolution from RecoParams
125 //
126 if (fkRecoParam)
127 esdPID->GetTOFResponse().SetTimeResolution(fkRecoParam->GetTimeResolution());
128 else
129 AliWarning("fkRecoParam not yet set; cannot set PID settings");
130}
131//_____________________________________________________________________________
132Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent * const event) {
133 //
134 // Gets seeds from ESD event and Match with TOF Clusters
135 //
136
137 // initialize RecoParam for current event
138 AliDebug(1,"Initializing params for TOF");
139
140 fkRecoParam = AliTOFReconstructor::GetRecoParam(); // instantiate reco param from STEER...
141
142 if (fkRecoParam == 0x0) {
143 AliFatal("No Reco Param found for TOF!!!");
144 }
145 //fkRecoParam->Dump();
146 //if(fkRecoParam->GetApplyPbPbCuts())fkRecoParam=fkRecoParam->GetPbPbparam();
147 //fkRecoParam->PrintParameters();
148
149 //Initialise some counters
150
151 fNseeds=0;
152 fNseedsTOF=0;
153 fngoodmatch=0;
154 fnbadmatch=0;
155 fnunmatch=0;
156 fnmatch=0;
157
158 Int_t ntrk=event->GetNumberOfTracks();
159 fNseeds = ntrk;
160
161 //Load ESD tracks into a local Array of ESD Seeds
162 for (Int_t i=0; i<fNseeds; i++)
163 fSeeds->AddLast(event->GetTrack(i));
164
165 //Prepare ESD tracks candidates for TOF Matching
166 CollectESD();
167
168 //Matching Step
169 MatchTracks();
170
171 AliInfo(Form("Number of matched tracks = %d (good = %d, bad = %d)",fnmatch,fngoodmatch,fnbadmatch));
172
173 //Update the matched ESD tracks
174
175 for (Int_t i=0; i<ntrk; i++) {
176 AliESDtrack *t=event->GetTrack(i);
177 AliESDtrack *seed =(AliESDtrack*)fSeeds->At(i);
178
179 if ( (seed->GetStatus()&AliESDtrack::kTOFin)!=0 ) {
180 t->SetStatus(AliESDtrack::kTOFin);
181 //if(seed->GetTOFsignal()>0){
182 if ( (seed->GetStatus()&AliESDtrack::kTOFout)!=0 ) {
183 t->SetStatus(AliESDtrack::kTOFout);
184 t->SetTOFsignal(seed->GetTOFsignal());
185 t->SetTOFcluster(seed->GetTOFcluster());
186 t->SetTOFsignalToT(seed->GetTOFsignalToT());
187 t->SetTOFsignalRaw(seed->GetTOFsignalRaw());
188 t->SetTOFsignalDz(seed->GetTOFsignalDz());
189 t->SetTOFsignalDx(seed->GetTOFsignalDx());
190 t->SetTOFDeltaBC(seed->GetTOFDeltaBC());
191 t->SetTOFL0L1(seed->GetTOFL0L1());
192 t->SetTOFCalChannel(seed->GetTOFCalChannel());
193 Int_t tlab[3]; seed->GetTOFLabel(tlab);
194 t->SetTOFLabel(tlab);
195
196 Double_t alphaA = (Double_t)t->GetAlpha();
197 Double_t xA = (Double_t)t->GetX();
198 Double_t yA = (Double_t)t->GetY();
199 Double_t zA = (Double_t)t->GetZ();
200 Double_t p1A = (Double_t)t->GetSnp();
201 Double_t p2A = (Double_t)t->GetTgl();
202 Double_t p3A = (Double_t)t->GetSigned1Pt();
203 const Double_t *covA = (Double_t*)t->GetCovariance();
204
205 // Make attention, please:
206 // AliESDtrack::fTOFInfo array does not be stored in the AliESDs.root file
207 // it is there only for a check during the reconstruction step.
208 Float_t info[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
209 seed->GetTOFInfo(info);
210 t->SetTOFInfo(info);
211 AliDebug(2,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
212
213 // Check done:
214 // by calling the AliESDtrack::UpdateTrackParams,
215 // the current track parameters are changed
216 // and it could cause refit problems.
217 // We need to update only the following track parameters:
218 // the track length and expected times.
219 // Removed AliESDtrack::UpdateTrackParams call
220 // Called AliESDtrack::SetIntegratedTimes(...) and
221 // AliESDtrack::SetIntegratedLength() routines.
222 /*
223 AliTOFtrack *track = new AliTOFtrack(*seed);
224 t->UpdateTrackParams(track,AliESDtrack::kTOFout); // to be checked - AdC
225 delete track;
226 Double_t time[10]; t->GetIntegratedTimes(time);
227 */
228
229 Double_t time[10]; seed->GetIntegratedTimes(time);
230 t->SetIntegratedTimes(time);
231
232 Double_t length = seed->GetIntegratedLength();
233 t->SetIntegratedLength(length);
234
235 Double_t alphaB = (Double_t)t->GetAlpha();
236 Double_t xB = (Double_t)t->GetX();
237 Double_t yB = (Double_t)t->GetY();
238 Double_t zB = (Double_t)t->GetZ();
239 Double_t p1B = (Double_t)t->GetSnp();
240 Double_t p2B = (Double_t)t->GetTgl();
241 Double_t p3B = (Double_t)t->GetSigned1Pt();
242 const Double_t *covB = (Double_t*)t->GetCovariance();
243 AliDebug(2,"Track params -now(before)-:");
244 AliDebug(2,Form(" X: %f(%f), Y: %f(%f), Z: %f(%f) --- alpha: %f(%f)",
245 xB,xA,
246 yB,yA,
247 zB,zA,
248 alphaB,alphaA));
249 AliDebug(2,Form(" p1: %f(%f), p2: %f(%f), p3: %f(%f)",
250 p1B,p1A,
251 p2B,p2A,
252 p3B,p3A));
253 AliDebug(2,Form(" cov1: %f(%f), cov2: %f(%f), cov3: %f(%f)"
254 " cov4: %f(%f), cov5: %f(%f), cov6: %f(%f)"
255 " cov7: %f(%f), cov8: %f(%f), cov9: %f(%f)"
256 " cov10: %f(%f), cov11: %f(%f), cov12: %f(%f)"
257 " cov13: %f(%f), cov14: %f(%f), cov15: %f(%f)",
258 covB[0],covA[0],
259 covB[1],covA[1],
260 covB[2],covA[2],
261 covB[3],covA[3],
262 covB[4],covA[4],
263 covB[5],covA[5],
264 covB[6],covA[6],
265 covB[7],covA[7],
266 covB[8],covA[8],
267 covB[9],covA[9],
268 covB[10],covA[10],
269 covB[11],covA[11],
270 covB[12],covA[12],
271 covB[13],covA[13],
272 covB[14],covA[14]
273 ));
274 AliDebug(3,Form(" %6d %f %f %f %f %f %6d %3d %f %f %f %f %f %f",
275 i,
276 t->GetTOFsignalRaw(),
277 t->GetTOFsignal(),
278 t->GetTOFsignalToT(),
279 t->GetTOFsignalDz(),
280 t->GetTOFsignalDx(),
281 t->GetTOFCalChannel(),
282 t->GetTOFcluster(),
283 t->GetIntegratedLength(),
284 time[0], time[1], time[2], time[3], time[4]
285 )
286 );
287 }
288 }
289 }
290
291 fSeeds->Clear();
292 fTracks->Delete();
293 return 0;
294
295}
296//_________________________________________________________________________
297void AliTOFtrackerV1::CollectESD() {
298 //prepare the set of ESD tracks to be matched to clusters in TOF
299
300 Int_t seedsTOF1=0;
301 Int_t seedsTOF2=0;
302
303 TClonesArray &aTOFTrack = *fTracks;
304 for (Int_t i=0; i<fNseeds; i++) {
305
306 AliESDtrack *t =(AliESDtrack*)fSeeds->At(i);
307 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
308
309 AliTOFtrack *track = new AliTOFtrack(*t); // New
310 Float_t x = (Float_t)track->GetX(); //New
311
312 // TRD 'good' tracks, already propagated at 371 cm
313 if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
314 ( x >= AliTOFGeometry::Rmin() ) ) {
315 if ( track->PropagateToInnerTOF() ) {
316
317 AliDebug(1,Form(" TRD propagated track till rho = %fcm."
318 " And then the track has been propagated till rho = %fcm.",
319 x, (Float_t)track->GetX()));
320
321 track->SetSeedIndex(i);
322 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
323 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
324 fNseedsTOF++;
325 seedsTOF1++;
326 }
327 delete track;
328 }
329
330 // Propagate the rest of TPCbp
331 else {
332 if ( track->PropagateToInnerTOF() ) {
333
334 AliDebug(1,Form(" TRD propagated track till rho = %fcm."
335 " And then the track has been propagated till rho = %fcm.",
336 x, (Float_t)track->GetX()));
337
338 track->SetSeedIndex(i);
339 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
340 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
341 fNseedsTOF++;
342 seedsTOF2++;
343 }
344 delete track;
345 }
346 }
347
348 AliInfo(Form("Number of TOF seeds = %d (Type 1 = %d, Type 2 = %d)",fNseedsTOF,seedsTOF1,seedsTOF2));
349
350 // Sort according uncertainties on track position
351 fTracks->Sort();
352
353}
354//_________________________________________________________________________
355void AliTOFtrackerV1::MatchTracks( ){
356 //
357 //Match ESD tracks to clusters in TOF
358 //
359
360
361 // Parameters regulating the reconstruction
362 Float_t dY=AliTOFGeometry::XPad();
363 Float_t dZ=AliTOFGeometry::ZPad();
364
365 const Float_t kTimeOffset = 0.; // time offset for tracking algorithm [ps]
366
367 const Int_t kncmax = 100;
368 Float_t sensRadius = fkRecoParam->GetSensRadius();
369 Float_t scaleFact = fkRecoParam->GetWindowScaleFact();
370 Float_t dyMax=fkRecoParam->GetWindowSizeMaxY();
371 Float_t dzMax=fkRecoParam->GetWindowSizeMaxZ();
372 Double_t maxChi2=fkRecoParam->GetMaxChi2();
373 Bool_t timeWalkCorr = fkRecoParam->GetTimeWalkCorr();
374 AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++ \n");
375 AliDebug(1,Form("TOF sens radius: %f",sensRadius));
376 AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
377 AliDebug(1,Form("TOF Window max dy: %f",dyMax));
378 AliDebug(1,Form("TOF Window max dz: %f",dzMax));
379 AliDebug(1,Form("TOF Max Chi2: %f",maxChi2));
380 AliDebug(1,Form("Time Walk Correction? : %d",timeWalkCorr));
381
382
383 //The matching loop
384 for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
385
386 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
387 AliESDtrack *t =(AliESDtrack*)fSeeds->At(track->GetSeedIndex());
388 //if ( t->GetTOFsignal()>0. ) continue;
389 if ( (t->GetStatus()&AliESDtrack::kTOFout)!=0 ) continue;
390 AliTOFtrack *trackTOFin = new AliTOFtrack(*track);
391
392 // Determine a window around the track
393 Double_t x,par[5]; trackTOFin->GetExternalParameters(x,par);
394 Double_t cov[15]; trackTOFin->GetExternalCovariance(cov);
395
396 if (cov[0]<0. || cov[2]<0.) {
397 AliWarning(Form("Very strange track (%d)! At least one of its covariance matrix diagonal elements is negative!",iseed));
398 //delete trackTOFin;
399 //continue;
400 }
401
402 Double_t z = par[1];
403 Double_t dz = scaleFact*3.*TMath::Sqrt(TMath::Abs(cov[2])+dZ*dZ/12.);
404 Double_t dphi = scaleFact*3.*TMath::Sqrt(TMath::Abs(cov[0])+dY*dY/12.)/sensRadius;
405
406 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
407 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
408 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
409
410 //upper limit on window's size.
411 if (dz> dzMax) dz=dzMax;
412 if (dphi*sensRadius> dyMax) dphi=dyMax/sensRadius;
413
414 // find the clusters inside the selected window
415 Int_t nc=0;
416 AliTOFcluster *clusters[kncmax]; // pointers to the clusters in the window
417 Int_t index[kncmax];//to keep track of the cluster index
418 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
419 AliTOFcluster *c=fClusters[k];
420 // if(nc>kncmax)break; /* R+ fix (buffer overflow) */
421 if (nc>=kncmax) {
422 AliWarning("No more matchable clusters can be stored! Please, increase the corresponding vectors size.");
423 break; /* R+ fix (buffer overflow protection) */
424 }
425 if (c->GetZ() > z+dz) break;
426 if (c->IsUsed()) continue;
427 if (!c->GetStatus()) {
428 AliDebug(1,"Cluster in channel declared bad!");
429 continue; // skip bad channels as declared in OCDB
430 }
431 Float_t xyz[3]; c->GetGlobalXYZ(xyz);
432 Double_t clPhi=TMath::ATan2(xyz[1],xyz[0]);
433 Double_t dph=TMath::Abs(clPhi-phi);
434 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
435 if (TMath::Abs(dph)>dphi) continue;
436 clusters[nc]=c;
437 index[nc] = k;
438 nc++;
439 }
440
441 AliDebug(1,Form(" Number of matchable TOF clusters for the track number %d: %d",iseed,nc));
442
443 //start propagation: go to the average TOF pad middle plane at ~379.5 cm
444
445 Float_t xTOF = sensRadius;
446 Double_t ymax = xTOF*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
447 Bool_t skip = kFALSE;
448 Double_t ysect = trackTOFin->GetYat(xTOF,skip);
449 if (skip) break;
450 if (ysect > ymax) {
451 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
452 break;
453 }
454 } else if (ysect <-ymax) {
455 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
456 break;
457 }
458 }
459 if(!trackTOFin->PropagateTo(xTOF)) {
460 break;
461 }
462
463
464 AliTOFcluster *bestCluster=0;
465 Double_t bestChi2=maxChi2;
466 Int_t idclus=-1;
467 // for (Int_t i=0; i<nc; i++){ /* R+ fix (unsafe) */
468 for (Int_t i=0; i<nc && i<kncmax; i++){ /* R+ fix (buffer overflow protection) */
469 AliTOFcluster *c=clusters[i]; // one of the preselected clusters
470 Double_t chi2=trackTOFin->GetPredictedChi2((AliCluster3D*)c);
471 if (chi2 >= bestChi2) continue;
472 bestChi2=chi2;
473 bestCluster=c;
474 idclus=index[i];
475 }
476
477 if (!bestCluster) { // no matching , go to the next track
478 fnunmatch++;
479 delete trackTOFin;
480 continue;
481 }
482
483 fnmatch++;
484
485 AliDebug(2, Form("%7i %7i %10i %10i %10i %10i %7i",
486 iseed,
487 fnmatch-1,
488 TMath::Abs(trackTOFin->GetLabel()),
489 bestCluster->GetLabel(0),
490 bestCluster->GetLabel(1),
491 bestCluster->GetLabel(2),
492 idclus)); // AdC
493
494 bestCluster->Use();
495 if (
496 (bestCluster->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
497 ||
498 (bestCluster->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
499 ||
500 (bestCluster->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
501 ) {
502 fngoodmatch++;
503 AliDebug(2,Form(" track label good %5d",trackTOFin->GetLabel()));
504
505 }
506 else{
507 fnbadmatch++;
508 AliDebug(2,Form(" track label bad %5d",trackTOFin->GetLabel()));
509 }
510
511 //Propagate the track to the best matched cluster
512 trackTOFin->PropagateTo(bestCluster);
513
514 // Fill the track residual histograms.
515 FillResiduals(trackTOFin,bestCluster,kFALSE);
516
517 //now take the local distance in Z from the pad center for time walk correction
518 Float_t tiltangle = AliTOFGeometry::GetAngles(bestCluster->GetDetInd(1),bestCluster->GetDetInd(2))*TMath::DegToRad();
519 Double_t dzTW=trackTOFin->GetZ()-bestCluster->GetZ(); // in cm - in the ALICE RF -
520 dzTW/=TMath::Cos(tiltangle); // from ALICE/tracking RF to pad RF (1)
521 dzTW=-dzTW; // from ALICE/tracking RF to pad RF (2)
522 if (tiltangle!=0.) AliDebug(2,Form(" rho_track = %f --- rho_cluster = %f ",trackTOFin->GetX(),bestCluster->GetX()));
523
524 //update the ESD track and delete the TOFtrack
525 t->UpdateTrackParams(trackTOFin,AliESDtrack::kTOFout);
526
527 // Store quantities to be used in the TOF Calibration
528 Float_t tToT=AliTOFGeometry::ToTBinWidth()*bestCluster->GetToT()*1E-3; // in ns
529 t->SetTOFsignalToT(tToT);
530 Float_t rawTime=AliTOFGeometry::TdcBinWidth()*bestCluster->GetTDCRAW()+kTimeOffset; // RAW time,in ps
531 t->SetTOFsignalRaw(rawTime);
532 t->SetTOFsignalDz(dzTW);
533
534 Float_t deltaY = trackTOFin->GetY()-bestCluster->GetY();
535 t->SetTOFsignalDx(deltaY);
536
537 t->SetTOFDeltaBC(bestCluster->GetDeltaBC());
538 t->SetTOFL0L1(bestCluster->GetL0L1Latency());
539
540 Float_t distR = (trackTOFin->GetX()-bestCluster->GetX())*
541 (trackTOFin->GetX()-bestCluster->GetX());
542 distR+=deltaY*deltaY;
543 distR+=dzTW*dzTW;
544 distR = TMath::Sqrt(distR);
545 Float_t info[10] = {distR, deltaY, dzTW,
546 0.,0.,0.,0.,0.,0.,0.};
547 t->SetTOFInfo(info);
548
549 Int_t ind[5];
550 ind[0]=bestCluster->GetDetInd(0);
551 ind[1]=bestCluster->GetDetInd(1);
552 ind[2]=bestCluster->GetDetInd(2);
553 ind[3]=bestCluster->GetDetInd(3);
554 ind[4]=bestCluster->GetDetInd(4);
555 Int_t calindex = AliTOFGeometry::GetIndex(ind);
556 t->SetTOFCalChannel(calindex);
557
558 // keep track of the track labels in the matched cluster
559 Int_t tlab[3];
560 tlab[0]=bestCluster->GetLabel(0);
561 tlab[1]=bestCluster->GetLabel(1);
562 tlab[2]=bestCluster->GetLabel(2);
563 AliDebug(2,Form(" tdc time of the matched track %6d = ",bestCluster->GetTDC()));
564 Double_t tof=AliTOFGeometry::TdcBinWidth()*bestCluster->GetTDC()+kTimeOffset; // in ps
565 AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
566 Double_t tofcorr=tof;
567 if(timeWalkCorr)tofcorr=CorrectTimeWalk(dzTW,tof);
568 AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));
569 //Set TOF time signal and pointer to the matched cluster
570 t->SetTOFsignal(tofcorr);
571 t->SetTOFcluster(idclus); // pointing to the recPoints tree
572 t->SetTOFLabel(tlab);
573
574 AliDebug(2,Form(" Setting TOF raw time: %f z distance: %f corrected time: %f",rawTime,dzTW,tofcorr));
575
576 Double_t mom=t->GetP();
577 AliDebug(2,Form(" Momentum for track %d -> %f", iseed,mom));
578 // Fill Reco-QA histos for Reconstruction
579 fHRecNClus->Fill(nc);
580 fHRecChi2->Fill(bestChi2);
581 fHRecDistZ->Fill(dzTW);
582 if (cov[0]>=0.)
583 fHRecSigYVsP->Fill(mom,TMath::Sqrt(cov[0]));
584 else
585 fHRecSigYVsP->Fill(mom,-TMath::Sqrt(-cov[0]));
586 if (cov[2]>=0.)
587 fHRecSigZVsP->Fill(mom,TMath::Sqrt(cov[2]));
588 else
589 fHRecSigZVsP->Fill(mom,-TMath::Sqrt(-cov[2]));
590 fHRecSigYVsPWin->Fill(mom,dphi*sensRadius);
591 fHRecSigZVsPWin->Fill(mom,dz);
592
593 // Fill Tree for on-the-fly offline Calibration
594 // no longer there - all info is in the ESDs now
595
596 delete trackTOFin;
597 }
598
599}
600//_________________________________________________________________________
601Int_t AliTOFtrackerV1::LoadClusters(TTree *cTree) {
602 //--------------------------------------------------------------------
603 //This function loads the TOF clusters
604 //--------------------------------------------------------------------
605
606 Int_t npadX = AliTOFGeometry::NpadX();
607 Int_t npadZ = AliTOFGeometry::NpadZ();
608 Int_t nStripA = AliTOFGeometry::NStripA();
609 Int_t nStripB = AliTOFGeometry::NStripB();
610 Int_t nStripC = AliTOFGeometry::NStripC();
611
612 TBranch *branch=cTree->GetBranch("TOF");
613 if (!branch) {
614 AliError("can't get the branch with the TOF clusters !");
615 return 1;
616 }
617
618 static TClonesArray dummy("AliTOFcluster",10000);
619 dummy.Clear();
620 TClonesArray *clusters=&dummy;
621 branch->SetAddress(&clusters);
622
623 cTree->GetEvent(0);
624 Int_t nc=clusters->GetEntriesFast();
625 fHDigNClus->Fill(nc);
626
627 AliInfo(Form("Number of clusters: %d",nc));
628
629 for (Int_t i=0; i<nc; i++) {
630 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
631//PH fClusters[i]=new AliTOFcluster(*c); fN++;
632 fClusters[i]=c; fN++;
633
634 // Fill Digits QA histos
635
636 Int_t isector = c->GetDetInd(0);
637 Int_t iplate = c->GetDetInd(1);
638 Int_t istrip = c->GetDetInd(2);
639 Int_t ipadX = c->GetDetInd(4);
640 Int_t ipadZ = c->GetDetInd(3);
641
642 Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
643 Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
644
645 Int_t stripOffset = 0;
646 switch (iplate) {
647 case 0:
648 stripOffset = 0;
649 break;
650 case 1:
651 stripOffset = nStripC;
652 break;
653 case 2:
654 stripOffset = nStripC+nStripB;
655 break;
656 case 3:
657 stripOffset = nStripC+nStripB+nStripA;
658 break;
659 case 4:
660 stripOffset = nStripC+nStripB+nStripA+nStripB;
661 break;
662 default:
663 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
664 break;
665 };
666 Int_t zindex=npadZ*(istrip+stripOffset)+(ipadZ+1);
667 Int_t phiindex=npadX*isector+ipadX+1;
668 fHDigClusMap->Fill(zindex,phiindex);
669 fHDigClusTime->Fill(time);
670 fHDigClusToT->Fill(tot);
671 }
672
673
674 return 0;
675}
676//_________________________________________________________________________
677void AliTOFtrackerV1::UnloadClusters() {
678 //--------------------------------------------------------------------
679 //This function unloads TOF clusters
680 //--------------------------------------------------------------------
681 for (Int_t i=0; i<fN; i++) {
682//PH delete fClusters[i];
683 fClusters[i] = 0x0;
684 }
685 fN=0;
686}
687
688//_________________________________________________________________________
689Int_t AliTOFtrackerV1::FindClusterIndex(Double_t z) const {
690 //--------------------------------------------------------------------
691 // This function returns the index of the nearest cluster
692 //--------------------------------------------------------------------
693 //MOD
694 //Here we need to get the Z in the tracking system
695
696 if (fN==0) return 0;
697 if (z <= fClusters[0]->GetZ()) return 0;
698 if (z > fClusters[fN-1]->GetZ()) return fN;
699 Int_t b=0, e=fN-1, m=(b+e)/2;
700 for (; b<e; m=(b+e)/2) {
701 if (z > fClusters[m]->GetZ()) b=m+1;
702 else e=m;
703 }
704 return m;
705}
706
707//_________________________________________________________________________
708Bool_t AliTOFtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint& p) const
709{
710 // Get track space point with index i
711 // Coordinates are in the global system
712 AliTOFcluster *cl = fClusters[index];
713 Float_t xyz[3];
714 cl->GetGlobalXYZ(xyz);
715 Float_t phi=TMath::ATan2(xyz[1],xyz[0]);
716 Float_t phiangle = (Int_t(phi*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
717 Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
718 Float_t tiltangle = AliTOFGeometry::GetAngles(cl->GetDetInd(1),cl->GetDetInd(2))*TMath::DegToRad();
719 Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
720 Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
721 Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
722 Float_t cov[6];
723 cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
724 cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
725 cov[2] = -cosphi*sinth*costh*sigmaz2;
726 cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
727 cov[4] = -sinphi*sinth*costh*sigmaz2;
728 cov[5] = costh*costh*sigmaz2;
729 p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
730
731 // Detector numbering scheme
732 Int_t nSector = AliTOFGeometry::NSectors();
733 Int_t nPlate = AliTOFGeometry::NPlates();
734 Int_t nStripA = AliTOFGeometry::NStripA();
735 Int_t nStripB = AliTOFGeometry::NStripB();
736 Int_t nStripC = AliTOFGeometry::NStripC();
737
738 Int_t isector = cl->GetDetInd(0);
739 if (isector >= nSector)
740 AliError(Form("Wrong sector number in TOF (%d) !",isector));
741 Int_t iplate = cl->GetDetInd(1);
742 if (iplate >= nPlate)
743 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
744 Int_t istrip = cl->GetDetInd(2);
745
746 Int_t stripOffset = 0;
747 switch (iplate) {
748 case 0:
749 stripOffset = 0;
750 break;
751 case 1:
752 stripOffset = nStripC;
753 break;
754 case 2:
755 stripOffset = nStripC+nStripB;
756 break;
757 case 3:
758 stripOffset = nStripC+nStripB+nStripA;
759 break;
760 case 4:
761 stripOffset = nStripC+nStripB+nStripA+nStripB;
762 break;
763 default:
764 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
765 break;
766 };
767
768 Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
769 stripOffset +
770 istrip;
771 UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
772 p.SetVolumeID((UShort_t)volid);
773 return kTRUE;
774}
775//_________________________________________________________________________
776void AliTOFtrackerV1::InitCheckHists() {
777
778 //Init histos for Digits/Reco QA and Calibration
779
780 TDirectory *dir = gDirectory;
781 TFile *logFileTOF = 0;
782
783 TSeqCollection *list = gROOT->GetListOfFiles();
784 int n = list->GetEntries();
785 Bool_t isThere=kFALSE;
786 for(int i=0; i<n; i++) {
787 logFileTOF = (TFile*)list->At(i);
788 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
789 isThere=kTRUE;
790 break;
791 }
792 }
793
794 if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
795 logFileTOF->cd();
796
797 //Digits "QA"
798 fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);
799 fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);
800 fHDigClusTime = new TH1F("TOFDig_ClusTime", "",2000,0.,200.);
801 fHDigClusToT = new TH1F("TOFDig_ClusToT", "",500,0.,100);
802
803 //Reco "QA"
804 fHRecNClus =new TH1F("TOFRec_NClusW", "",50,0.5,50.5);
805 fHRecDistZ=new TH1F("TOFRec_DistZ", "",50,0.5,10.5);
806 fHRecChi2=new TH1F("TOFRec_Chi2", "",100,0.,10.);
807 fHRecSigYVsP=new TH2F("TOFDig_SigYVsP", "",40,0.,4.,100, 0.,5.);
808 fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
809 fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
810 fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
811
812 dir->cd();
813
814}
815
816//_________________________________________________________________________
817void AliTOFtrackerV1::SaveCheckHists() {
818
819 //write histos for Digits/Reco QA and Calibration
820
821 TDirectory *dir = gDirectory;
822 TFile *logFile = 0;
823 TFile *logFileTOF = 0;
824
825 TSeqCollection *list = gROOT->GetListOfFiles();
826 int n = list->GetEntries();
827 for(int i=0; i<n; i++) {
828 logFile = (TFile*)list->At(i);
829 if (strstr(logFile->GetName(), "AliESDs.root")) break;
830 }
831
832 Bool_t isThere=kFALSE;
833 for(int i=0; i<n; i++) {
834 logFileTOF = (TFile*)list->At(i);
835 if (strstr(logFileTOF->GetName(), "TOFQA.root")){
836 isThere=kTRUE;
837 break;
838 }
839 }
840
841 if(!isThere) {
842 AliError(Form("File TOFQA.root not found!! not wring histograms...."));
843 return;
844 }
845 logFile->cd();
846 fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
847 fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
848 fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
849 fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
850 fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
851 fHRecChi2->Write(fHRecChi2->GetName(), TObject::kOverwrite);
852 fHRecDistZ->Write(fHRecDistZ->GetName(), TObject::kOverwrite);
853 fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
854 fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
855 fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
856 fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
857 logFile->Flush();
858
859 dir->cd();
860
861 }
862//_________________________________________________________________________
863Float_t AliTOFtrackerV1::CorrectTimeWalk( Float_t dist, Float_t tof) const {
864
865 //dummy, for the moment
866 Float_t tofcorr=0.;
867 if(dist<AliTOFGeometry::ZPad()*0.5){
868 tofcorr=tof;
869 //place here the actual correction
870 }else{
871 tofcorr=tof;
872 }
873 return tofcorr;
874}
875//_________________________________________________________________________
876Float_t AliTOFtrackerV1::GetTimeZerofromT0(const AliESDEvent * const event) const {
877
878 //Returns TimeZero as measured by T0 detector
879
880 return event->GetT0();
881}
882//_________________________________________________________________________
883Float_t AliTOFtrackerV1::GetTimeZerofromTOF(AliESDEvent * /*event*/) const {
884
885 //dummy, for the moment. T0 algorithm using tracks on TOF
886 {
887 //place T0 algo here...
888 }
889 return 0.;
890}
891//_________________________________________________________________________
892
893void AliTOFtrackerV1::FillClusterArray(TObjArray* arr) const
894{
895 //
896 // Returns the TOF cluster array
897 //
898
899 if (fN==0)
900 arr = 0x0;
901 else
902 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
903
904}