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