Improved memory leaks in AliTOFtracker* classes: additional solution for bug #66136
[u/mrichter/AliRoot.git] / TOF / AliTOFtrackerMI.cxx
CommitLineData
d88fbf15 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 **************************************************************************/
0e46b9ae 15
16//-----------------------------------------------------------------//
17// //
18// AliTOFtracker Class //
19// Task: Perform association of the ESD tracks to TOF Clusters //
20// and Update ESD track with associated TOF Cluster parameters //
21// //
22//-----------------------------------------------------------------//
d88fbf15 23
24#include <Rtypes.h>
0e46b9ae 25
d88fbf15 26#include "TClonesArray.h"
0841bd02 27#include "TObjArray.h"
0e46b9ae 28#include "TTree.h"
d88fbf15 29#include "TTreeStream.h"
0e46b9ae 30
af885e0f 31#include "AliESDEvent.h"
0e46b9ae 32#include "AliESDtrack.h"
10d100d4 33#include "AliESDpid.h"
0e46b9ae 34
e0ddb533 35#include "AliTOFRecoParam.h"
3a646035 36#include "AliTOFReconstructor.h"
0e46b9ae 37#include "AliTOFcluster.h"
96f01799 38#include "AliTOFGeometry.h"
0e46b9ae 39#include "AliTOFtrackerMI.h"
40#include "AliTOFtrack.h"
5c7c93fa 41
bb7e41dd 42#include "AliMathBase.h"
43
5c7c93fa 44class TGeoManager;
0e46b9ae 45
46extern TGeoManager *gGeoManager;
d88fbf15 47
48ClassImp(AliTOFtrackerMI)
49
50//_____________________________________________________________________________
e0ddb533 51AliTOFtrackerMI::AliTOFtrackerMI():
069bb393 52 fkRecoParam(0x0),
e0ddb533 53 fGeom(0x0),
58d8d9a3 54 fN(0),
55 fNseeds(0),
56 fNseedsTOF(0),
57 fngoodmatch(0),
58 fnbadmatch(0),
59 fnunmatch(0),
60 fnmatch(0),
8dacd1bb 61 fR(379.),
58d8d9a3 62 fTOFHeigth(15.3),
63 fdCut(3.),
64 fDx(1.5),
65 fDy(0),
66 fDz(0),
b42a5ea1 67 fTracks(new TClonesArray("AliTOFtrack")),
de60fa8a 68 fSeeds(new TObjArray(100)),
58d8d9a3 69 fDebugStreamer(0x0)
70 {
d88fbf15 71 //AliTOFtrackerMI main Ctor
72
96f01799 73 fDy=AliTOFGeometry::XPad();
74 fDz=AliTOFGeometry::ZPad();
e0ddb533 75 fDebugStreamer = new TTreeSRedirector("TOFdebug.root");
d88fbf15 76}
7aeeaf38 77
78//_____________________________________________________________________________
d88fbf15 79AliTOFtrackerMI::~AliTOFtrackerMI(){
80 //
069bb393 81 // Destructor
d88fbf15 82 //
83 if (fDebugStreamer) {
84 //fDebugStreamer->Close();
85 delete fDebugStreamer;
86 }
069bb393 87 delete fkRecoParam;
e0ddb533 88 delete fGeom;
b42a5ea1 89 if (fTracks){
90 fTracks->Delete();
91 delete fTracks;
92 fTracks=0x0;
93 }
94 if (fSeeds){
95 fSeeds->Delete();
96 delete fSeeds;
97 fSeeds=0x0;
98 }
d88fbf15 99}
10d100d4 100//_____________________________________________________________________________
101void AliTOFtrackerMI::GetPidSettings(AliESDpid *esdPID) {
102 //
103 // Sets TOF resolution from RecoParams
104 //
069bb393 105 if (fkRecoParam)
106 esdPID->GetTOFResponse().SetTimeResolution(fkRecoParam->GetTimeResolution());
10d100d4 107 else
069bb393 108 AliWarning("fkRecoParam not yet set; cannot set PID settings");
10d100d4 109}
d88fbf15 110
111//_____________________________________________________________________________
069bb393 112Int_t AliTOFtrackerMI::PropagateBack(AliESDEvent * const event) {
d88fbf15 113 //
114 // Gets seeds from ESD event and Match with TOF Clusters
115 //
116
3a646035 117 // initialize RecoParam for current event
bafe290d 118 AliDebug(1,"Initializing params for TOF");
3a646035 119
069bb393 120 fkRecoParam = AliTOFReconstructor::GetRecoParam(); // instantiate reco param from STEER...
90b234fe 121
069bb393 122 if (fkRecoParam == 0x0) {
3a646035 123 AliFatal("No Reco Param found for TOF!!!");
124 }
069bb393 125 //fkRecoParam->Dump();
126 //if(fkRecoParam->GetApplyPbPbCuts())fkRecoParam=fkRecoParam->GetPbPbparam();
127 //fkRecoParam->PrintParameters();
128
d88fbf15 129 //Initialise some counters
130
131 fNseeds=0;
132 fNseedsTOF=0;
133 fngoodmatch=0;
134 fnbadmatch=0;
135 fnunmatch=0;
136 fnmatch=0;
137
138 Int_t ntrk=event->GetNumberOfTracks();
139 fNseeds = ntrk;
d88fbf15 140
141 //Load ESD tracks into a local Array of ESD Seeds
0841bd02 142 for (Int_t i=0; i<fNseeds; i++)
143 fSeeds->AddLast(event->GetTrack(i));
d88fbf15 144
145 //Prepare ESD tracks candidates for TOF Matching
146 CollectESD();
147
148 //First Step with Strict Matching Criterion
149 //MatchTracks(kFALSE);
150
151 //Second Step with Looser Matching Criterion
152 //MatchTracks(kTRUE);
153 MatchTracksMI(kFALSE); // assign track to clusters
154 MatchTracksMI(kTRUE); // assign clusters to esd
155
bafe290d 156 AliInfo(Form("Number of matched tracks = %d (good = %d, bad = %d)",fnmatch,fngoodmatch,fnbadmatch));
d88fbf15 157
158 //Update the matched ESD tracks
159
160 for (Int_t i=0; i<ntrk; i++) {
161 AliESDtrack *t=event->GetTrack(i);
0841bd02 162 AliESDtrack *seed =(AliESDtrack*)fSeeds->At(i);
2188ddfc 163
164 if ( (seed->GetStatus()&AliESDtrack::kTOFin)!=0 ) {
165 t->SetStatus(AliESDtrack::kTOFin);
166 //if(seed->GetTOFsignal()>0){
167 if ( (seed->GetStatus()&AliESDtrack::kTOFout)!=0 ) {
e81ea7b6 168 t->SetStatus(AliESDtrack::kTOFout);
2188ddfc 169 t->SetTOFsignal(seed->GetTOFsignal());
170 t->SetTOFcluster(seed->GetTOFcluster());
e81ea7b6 171 Int_t tlab[3]; seed->GetTOFLabel(tlab);
2188ddfc 172 t->SetTOFLabel(tlab);
e81ea7b6 173
174 // Check done:
175 // by calling the AliESDtrack::UpdateTrackParams,
176 // the current track parameters are changed
177 // and it could cause refit problems.
178 // We need to update only the following track parameters:
179 // the track length and expected times.
180 // Removed AliESDtrack::UpdateTrackParams call
181 // Called AliESDtrack::SetIntegratedTimes(...) and
182 // AliESDtrack::SetIntegratedLength() routines.
183 /*
2188ddfc 184 AliTOFtrack *track = new AliTOFtrack(*seed);
2188ddfc 185 t->UpdateTrackParams(track,AliESDtrack::kTOFout);
e81ea7b6 186 delete track;
187 */
188
189 Double_t times[10]; seed->GetIntegratedTimes(times);
2188ddfc 190 t->SetIntegratedTimes(times);
e81ea7b6 191 t->SetIntegratedLength(seed->GetIntegratedLength());
2188ddfc 192 t->SetTOFsignalToT(seed->GetTOFsignalToT());
193 t->SetTOFCalChannel(seed->GetTOFCalChannel());
8b441e14 194 t->SetTOFDeltaBC(seed->GetTOFDeltaBC());
195 t->SetTOFL0L1(seed->GetTOFL0L1());
2188ddfc 196 //
e81ea7b6 197 // Make attention, please:
198 // AliESDtrack::fTOFInfo array does not be stored in the AliESDs.root file
199 // it is there only for a check during the reconstruction step.
24322e5c 200 Float_t info[10];
201 seed->GetTOFInfo(info);
2188ddfc 202 t->SetTOFInfo(info);
2188ddfc 203 }
d88fbf15 204 }
205 }
206
207
208 //Make TOF PID
d88fbf15 209
de60fa8a 210 fSeeds->Clear();
0841bd02 211 fTracks->Delete();
d88fbf15 212 return 0;
213
214}
215//_________________________________________________________________________
216void AliTOFtrackerMI::CollectESD() {
217 //prepare the set of ESD tracks to be matched to clusters in TOF
218
d88fbf15 219 TClonesArray &aTOFTrack = *fTracks;
220 Int_t c0=0;
221 Int_t c1=0;
222 for (Int_t i=0; i<fNseeds; i++) {
223
0841bd02 224 AliESDtrack *t =(AliESDtrack*)fSeeds->At(i);
d88fbf15 225 if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
226
d88fbf15 227 AliTOFtrack *track = new AliTOFtrack(*t); // New
2188ddfc 228 Float_t x = (Float_t)track->GetX(); //New
229
230 // TRD good tracks, already propagated at 371 cm
231 if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
232 ( x >= AliTOFGeometry::Rmin() ) ) {
233 if ( track->PropagateToInnerTOF() ) {
234 track->SetSeedIndex(i);
235 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
236 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
237 fNseedsTOF++;
238 c0++;
239 delete track;
240 }
d88fbf15 241 }
242
2188ddfc 243 // Propagate the rest of TPCbp
d88fbf15 244 else {
2188ddfc 245 if ( track->PropagateToInnerTOF() ) { // temporary solution
d88fbf15 246 track->SetSeedIndex(i);
2188ddfc 247 t->UpdateTrackParams(track,AliESDtrack::kTOFin);
d88fbf15 248 new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
249 fNseedsTOF++;
250 c1++;
251 }
252 delete track;
253 }
254 }
255 //
256 //
257 printf("TRD\tOn\t%d\tOff\t%d\n",c0,c1);
258
259 // Sort according uncertainties on track position
260 fTracks->Sort();
261
262}
263
d88fbf15 264//_________________________________________________________________________
069bb393 265void AliTOFtrackerMI::MatchTracks( Bool_t /*mLastStep*/) const {
d88fbf15 266 return;
267}
268//
269//
270//_________________________________________________________________________
271void AliTOFtrackerMI::MatchTracksMI(Bool_t mLastStep){
272
273 //Match ESD tracks to clusters in TOF
2bf66a2d 274 const Float_t kTofOffset = 26; // time offset
275 const Float_t kMinQuality = -6.; // minimal quality
276 const Float_t kMaxQualityD = 1.; // max delta quality if cluster used
277 const Float_t kForbiddenR = 0.1; // minimal PID according TPC
d88fbf15 278
279 static const Double_t kMasses[]={
280 0.000511, 0.105658, 0.139570, 0.493677, 0.938272, 1.875613
281 };
282
283 Int_t nSteps=(Int_t)(fTOFHeigth/0.1);
284
285 //PH Arrays (moved outside of the loop)
286 Float_t * trackPos[4];
287 for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
128563f6 288 Int_t * clind = new Int_t[fN];
d88fbf15 289
290 // Some init
53884c34 291 const Int_t kNclusterMax = 1000; // related to fN value
292 AliTOFcluster *clusters[kNclusterMax];
293 Int_t index[kNclusterMax];
294 Float_t quality[kNclusterMax];
295 Float_t dist3D[kNclusterMax][6];
296 Double_t times[kNclusterMax][6];
297 Float_t mintimedist[kNclusterMax];
298 Float_t likelihood[kNclusterMax];
299 Float_t length[kNclusterMax];
3c609b5c 300 Double_t tpcpid[5];
d88fbf15 301 dist3D[0][0]=1;
302
303 for (Int_t i=0; i<fNseedsTOF; i++) {
304
305 AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(i);
0841bd02 306 AliESDtrack *t =(AliESDtrack*)fSeeds->At(track->GetSeedIndex());
d88fbf15 307 Bool_t hasTime = ( (t->GetStatus()& AliESDtrack::kTIME)>0) ? kTRUE:kFALSE; // did we integrate time
308 Float_t trdquality = t->GetTRDQuality();
309 //
310 // Normalize tpc pid
311 //
312 t->GetTPCpid(tpcpid);
313 Double_t sumpid=0;
314 for (Int_t ipid=0;ipid<5;ipid++){
315 sumpid+=tpcpid[ipid];
316 }
317 for (Int_t ipid=0;ipid<5;ipid++){
318 if (sumpid>0) tpcpid[ipid]/=sumpid;
319 else{
320 tpcpid[ipid]=0.2;
321 }
322 }
323
324 if (trdquality<0) continue; // no chance
325 //
326 AliTOFtrack *trackTOFin =new AliTOFtrack(*track);
327 //
328 //propagat track to the middle of TOF
329 //
8dacd1bb 330 Float_t xs = 379.2; // should be defined in the TOF geometry
96f01799 331 Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
d3c7bfac 332 Bool_t skip=kFALSE;
d88fbf15 333 Double_t ysect=trackTOFin->GetYat(xs,skip);
334 if (skip){
8dacd1bb 335 xs = 373.;
96f01799 336 ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
d88fbf15 337 ysect=trackTOFin->GetYat(xs,skip);
338 }
339 if (ysect > ymax) {
96f01799 340 if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
d88fbf15 341 continue;
342 }
343 } else if (ysect <-ymax) {
96f01799 344 if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
d88fbf15 345 continue;
346 }
347 }
348 if(!trackTOFin->PropagateTo(xs)) {
349 continue;
350 }
351 //
352 // Determine a window around the track
353 //
354 Double_t x,par[5];
355 trackTOFin->GetExternalParameters(x,par);
356 Double_t cov[15];
357 trackTOFin->GetExternalCovariance(cov);
53884c34 358
359 if (cov[0]<0. || cov[2]<0.) {
360 AliWarning(Form("Very strange track (%d)! At least one of its covariance matrix diagonal elements is negative!",i));
ecd795d8 361 //delete trackTOFin;
362 //continue;
53884c34 363 }
364
d88fbf15 365 Float_t scalefact=3.;
366 Double_t dphi=
367 scalefact*
ecd795d8 368 ((5*TMath::Sqrt(TMath::Abs(cov[0])) + 3.*fDy + 10.*TMath::Abs(par[2]))/fR);
d88fbf15 369 Double_t dz=
370 scalefact*
ecd795d8 371 (5*TMath::Sqrt(TMath::Abs(cov[2])) + 3.*fDz + 10.*TMath::Abs(par[3]));
d88fbf15 372
373 Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
374 if (phi<-TMath::Pi())phi+=2*TMath::Pi();
375 if (phi>=TMath::Pi())phi-=2*TMath::Pi();
376 Double_t z=par[1];
377
378 Int_t nc =0;
379 Int_t nfound =0;
380 // find the clusters in the window of the track
381
382 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
53884c34 383
384 if (nc>=kNclusterMax) {
385 AliWarning("No more matchable clusters can be stored! Please, increase the corresponding vectors size.");
386 break;
387 }
388
d88fbf15 389 AliTOFcluster *c=fClusters[k];
390 if (c->GetZ() > z+dz) break;
391 // if (c->IsUsed()) continue;
392
393 Double_t dph=TMath::Abs(c->GetPhi()-phi);
394 if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
395 if (TMath::Abs(dph)>dphi) continue;
3c609b5c 396
128563f6 397 clind[nc] = k;
d88fbf15 398 nc++;
399 }
400
53884c34 401 AliDebug(1,Form(" Number of matchable TOF clusters for the track number %d: %d",i,nc));
402
d88fbf15 403 //
404 // select close clusters
405 //
406 Double_t mom=t->GetP();
407 // Bool_t dump = kTRUE;
408 for (Int_t icl=0; icl<nc; icl++){
409 Float_t distances[5];
53884c34 410
128563f6 411 index[nfound]=clind[icl];
412 AliTOFcluster *cluster = fClusters[clind[icl]];
2bf66a2d 413 GetLinearDistances(trackTOFin, cluster, distances);
d88fbf15 414 dist3D[nfound][0] = distances[4];
415 dist3D[nfound][1] = distances[1];
416 dist3D[nfound][2] = distances[2];
417 // cut on distance
418 if (TMath::Abs(dist3D[nfound][1])>20 || TMath::Abs(dist3D[nfound][2])>20) continue;
419 //
420 GetLikelihood(distances[1],distances[2],cov,trackTOFin, dist3D[nfound][3], dist3D[nfound][4]);
421 //
422 // cut on likelihood
423 if (dist3D[nfound][3]*dist3D[nfound][4]<0.00000000000001) continue; // log likelihood
424 if (TMath::Log(dist3D[nfound][3]*dist3D[nfound][4])<-9) continue; // log likelihood
425 //
426 clusters[nfound] = cluster;
427 //
2bf66a2d 428 //length and TOF updates
d88fbf15 429 trackTOFin->GetIntegratedTimes(times[nfound]);
430 length[nfound] = trackTOFin->GetIntegratedLength();
431 length[nfound]+=distances[4];
432 mintimedist[nfound]=1000;
96f01799 433 Double_t tof2=AliTOFGeometry::TdcBinWidth()*cluster->GetTDC()+kTofOffset; // in ps
d88fbf15 434 // Float_t tgamma = TMath::Sqrt(cluster->GetR()*cluster->GetR()+cluster->GetZ()*cluster->GetZ())/0.03; //time for "primary" gamma
435 //if (trackTOFin->GetPt()<0.7 && TMath::Abs(tgamma-tof2)<350) continue; // gamma conversion candidate - TEMPORARY
436 for(Int_t j=0;j<=5;j++){
437 Double_t mass=kMasses[j];
438 times[nfound][j]+=distances[4]/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom; // add time distance
439 if ( TMath::Abs(times[nfound][j]-tof2)<mintimedist[nfound] && tpcpid[j]>kForbiddenR){
440 mintimedist[nfound]=TMath::Abs(times[nfound][j]-tof2);
441 }
442 }
443 //
444 Float_t liketime = TMath::Exp(-mintimedist[nfound]/90.)+0.25*TMath::Exp(-mintimedist[nfound]/180.);
445 if (!hasTime) liketime=0.2;
446 likelihood[nfound] = TMath::Log(dist3D[nfound][3]*dist3D[nfound][4]*liketime);
447
448 if (TMath::Log(dist3D[nfound][3]*dist3D[nfound][4])<-1){
449 if (likelihood[nfound]<-9.) continue;
450 }
451 //
452 nfound++;
53884c34 453 }
454
455 AliDebug(1,Form(" Number of track points for the track number %d: %d",i,nfound));
456
d88fbf15 457 if (nfound == 0 ) {
458 fnunmatch++;
459 delete trackTOFin;
460 continue;
461 }
462 //
463 //choose the best cluster
464 //
53884c34 465 //Float_t quality[kNclusterMax];
466 //Int_t index[kNclusterMax];
467 for (Int_t kk=0; kk<kNclusterMax; kk++) quality[kk]=0;
d88fbf15 468 //
469 AliTOFcluster * cgold=0;
470 Int_t igold =-1;
471 for (Int_t icl=0;icl<nfound;icl++){
472 quality[icl] = dist3D[icl][3]*dist3D[icl][4];
473 }
474 TMath::Sort(nfound,quality,index,kTRUE);
475 igold = index[0];
476 cgold = clusters[igold];
477 if (nfound>1 &&likelihood[index[1]]>likelihood[index[0]]){
478 if ( quality[index[0]]<quality[index[1]]+0.5){
479 igold = index[1];
480 cgold = clusters[igold];
481 }
482 }
483 //
484 //
485 Float_t qualityGold = TMath::Log(0.0000001+(quality[igold]*(0.1+TMath::Exp(-mintimedist[igold]/80.))*(0.2+trdquality)));
486 if (!mLastStep){
487 if (cgold->GetQuality()<qualityGold) cgold->SetQuality(qualityGold);
488 continue;
489 }
490 //
491 if (mLastStep){
492 //signed better cluster
493 if (cgold->GetQuality()>qualityGold+kMaxQualityD) continue;
494 if (2.*qualityGold-cgold->GetQuality()<kMinQuality) continue;
495 }
496
497 Int_t inonfake=-1;
498
499 for (Int_t icl=0;icl<nfound;icl++){
500 if (
501 (clusters[index[icl]]->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
502 ||
503 (clusters[index[icl]]->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
504 ||
505 (clusters[index[icl]]->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
506 ) {
507 inonfake = icl;
508 break;
509 }
510 }
511 fnmatch++;;
512 if (inonfake==0) fngoodmatch++;
513 else{
514 fnbadmatch++;
515 }
516
517 Int_t tlab[3];
518 tlab[0]=cgold->GetLabel(0);
519 tlab[1]=cgold->GetLabel(1);
520 tlab[2]=cgold->GetLabel(2);
521 // Double_t tof2=25.*cgold->GetTDC()-350; // in ps
96f01799 522 Double_t tof2=AliTOFGeometry::TdcBinWidth()*cgold->GetTDC()+kTofOffset; // in ps
d88fbf15 523 Float_t tgamma = TMath::Sqrt(cgold->GetR()*cgold->GetR()+cgold->GetZ()*cgold->GetZ())/0.03;
24322e5c 524 Float_t info[10]={dist3D[igold][0],
525 dist3D[igold][1],
526 dist3D[igold][2],
527 dist3D[igold][3],
528 dist3D[igold][4],
529 mintimedist[igold],
530 -1,
531 tgamma,
532 qualityGold,
533 cgold->GetQuality()};
d88fbf15 534 // GetLinearDistances(trackTOFin,cgold,&info[6]);
535 if (inonfake>=0){
536 info[6] = inonfake;
537 // info[7] = mintimedist[index[inonfake]];
538 }
539 //
a533f541 540 // Store quantities to be used for TOF Calibration
7aeeaf38 541 Float_t tToT=cgold->GetToT(); // in ps
542 t->SetTOFsignalToT(tToT);
a533f541 543 Int_t ind[5];
544 ind[0]=cgold->GetDetInd(0);
545 ind[1]=cgold->GetDetInd(1);
546 ind[2]=cgold->GetDetInd(2);
547 ind[3]=cgold->GetDetInd(3);
548 ind[4]=cgold->GetDetInd(4);
96f01799 549 Int_t calindex = AliTOFGeometry::GetIndex(ind);
a533f541 550 t->SetTOFCalChannel(calindex);
551
d88fbf15 552 t->SetTOFInfo(info);
553 t->SetTOFsignal(tof2);
554 t->SetTOFcluster(cgold->GetIndex());
8b441e14 555 t->SetTOFDeltaBC(cgold->GetDeltaBC());
556 t->SetTOFL0L1(cgold->GetL0L1Latency());
32ead898 557
558 AliDebug(2, Form("%7i %7i %10i %10i %10i %10i %7i",
559 i,
3a646035 560 fnmatch-1,
32ead898 561 TMath::Abs(trackTOFin->GetLabel()),
562 tlab[0], tlab[1], tlab[2],
563 igold)); // AdC
564
d88fbf15 565 AliTOFtrack *trackTOFout = new AliTOFtrack(*t);
8dacd1bb 566 trackTOFout->PropagateTo(379.);
77a9ea9a 567
568 // Fill the track residual histograms.
569 FillResiduals(trackTOFout,cgold,kFALSE);
570
d88fbf15 571 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
572 t->SetIntegratedLength(length[igold]);
573 t->SetIntegratedTimes(times[igold]);
574 t->SetTOFLabel(tlab);
575 //
576 delete trackTOFin;
577 delete trackTOFout;
578 //
579 }
580 //
581 //
582 //
583 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
128563f6 584 delete [] clind;
3a646035 585 //delete calib; // AdC
d88fbf15 586}
d88fbf15 587//_________________________________________________________________________
128563f6 588
d88fbf15 589Int_t AliTOFtrackerMI::LoadClusters(TTree *cTree) {
590 //--------------------------------------------------------------------
591 //This function loads the TOF clusters
592 //--------------------------------------------------------------------
593
594 TBranch *branch=cTree->GetBranch("TOF");
595 if (!branch) {
596 AliError("can't get the branch with the TOF clusters !");
597 return 1;
598 }
599
b42a5ea1 600 static TClonesArray dummy("AliTOFcluster",10000);
601 dummy.Clear();
602 TClonesArray *clusters=&dummy;
d88fbf15 603 branch->SetAddress(&clusters);
604
605 cTree->GetEvent(0);
606 Int_t nc=clusters->GetEntriesFast();
607 AliInfo(Form("Number of clusters: %d",nc));
608
609 for (Int_t i=0; i<nc; i++) {
610 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
d88fbf15 611
16a2e36a 612//PH fClusters[i]=new AliTOFcluster(*c); fN++;
613 fClusters[i]=c; fN++;
d88fbf15 614
615 //AliInfo(Form("%4i %4i %f %f %f %f %f %2i %1i %2i %1i %2i",i, fClusters[i]->GetIndex(),fClusters[i]->GetZ(),fClusters[i]->GetR(),fClusters[i]->GetPhi(), fClusters[i]->GetTDC(),fClusters[i]->GetADC(),fClusters[i]->GetDetInd(0),fClusters[i]->GetDetInd(1),fClusters[i]->GetDetInd(2),fClusters[i]->GetDetInd(3),fClusters[i]->GetDetInd(4)));
616 //AliInfo(Form("%i %f",i, fClusters[i]->GetZ()));
617 }
618
619 //AliInfo(Form("Number of clusters: %d",fN));
620
621 return 0;
622}
623//_________________________________________________________________________
624void AliTOFtrackerMI::UnloadClusters() {
625 //--------------------------------------------------------------------
626 //This function unloads TOF clusters
627 //--------------------------------------------------------------------
628 for (Int_t i=0; i<fN; i++) {
16a2e36a 629//PH delete fClusters[i];
d88fbf15 630 fClusters[i] = 0x0;
631 }
632 fN=0;
633}
634
635
636
637
638//_________________________________________________________________________
639Int_t AliTOFtrackerMI::InsertCluster(AliTOFcluster *c) {
640 //--------------------------------------------------------------------
641 //This function adds a cluster to the array of clusters sorted in Z
642 //--------------------------------------------------------------------
643 if (fN==kMaxCluster) {
0e46b9ae 644 AliError("Too many clusters !");
d88fbf15 645 return 1;
646 }
647
648 if (fN==0) {fClusters[fN++]=c; return 0;}
649 Int_t i=FindClusterIndex(c->GetZ());
650 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTOFcluster*));
651 fClusters[i]=c; fN++;
652
653 return 0;
654}
655
656//_________________________________________________________________________
657Int_t AliTOFtrackerMI::FindClusterIndex(Double_t z) const {
658 //--------------------------------------------------------------------
659 // This function returns the index of the nearest cluster
660 //--------------------------------------------------------------------
661 if (fN==0) return 0;
662 if (z <= fClusters[0]->GetZ()) return 0;
663 if (z > fClusters[fN-1]->GetZ()) return fN;
664 Int_t b=0, e=fN-1, m=(b+e)/2;
665 for (; b<e; m=(b+e)/2) {
666 if (z > fClusters[m]->GetZ()) b=m+1;
667 else e=m;
668 }
669 return m;
670}
671
24322e5c 672//_________________________________________________________________________
d88fbf15 673Float_t AliTOFtrackerMI::GetLinearDistances(AliTOFtrack * track, AliTOFcluster *cluster, Float_t distances[5])
674{
675 //
676 // calclates distance between cluster and track
677 // use linear aproximation
678 //
24322e5c 679 //const Float_t kRaddeg = 180/3.14159265358979312;
680 const Float_t kRaddeg = TMath::RadToDeg();
d88fbf15 681 //
682 // Float_t tiltangle = fGeom->GetAngles(cluster->fdetIndex[1],cluster->fdetIndex[2])/kRaddeg; //tiltangle
683 Int_t cind[5];
684 cind[0]= cluster->GetDetInd(0);
685 cind[1]= cluster->GetDetInd(1);
686 cind[2]= cluster->GetDetInd(2);
687 cind[3]= cluster->GetDetInd(3);
688 cind[4]= cluster->GetDetInd(4);
96f01799 689 Float_t tiltangle = AliTOFGeometry::GetAngles(cluster->GetDetInd(1),cluster->GetDetInd(2))/kRaddeg; //tiltangle
d88fbf15 690
691 Float_t cpos[3]; //cluster position
692 Float_t cpos0[3]; //cluster position
693 // fGeom->GetPos(cluster->fdetIndex,cpos);
694 //fGeom->GetPos(cluster->fdetIndex,cpos0);
695 //
696 fGeom->GetPos(cind,cpos);
697 fGeom->GetPos(cind,cpos0);
698
699 Float_t phi = TMath::ATan2(cpos[1],cpos[0]);
700 if(phi<0) phi=2.*TMath::Pi()+phi;
701 // Get the local angle in the sector philoc
24322e5c 702 Float_t phiangle = (Int_t (phi*kRaddeg/20.) + 0.5)*20./kRaddeg;
d88fbf15 703 //
704 Double_t v0[3];
705 Double_t dir[3];
6c94f330 706 track->GetXYZ(v0);
707 track->GetPxPyPz(dir);
d88fbf15 708 dir[0]/=track->GetP();
709 dir[1]/=track->GetP();
710 dir[2]/=track->GetP();
711 //
712 //
713 //rotate 0
714 Float_t sinphi = TMath::Sin(phiangle);
715 Float_t cosphi = TMath::Cos(phiangle);
716 Float_t sinth = TMath::Sin(tiltangle);
717 Float_t costh = TMath::Cos(tiltangle);
718 //
719 Float_t temp;
720 temp = cpos[0]*cosphi+cpos[1]*sinphi;
721 cpos[1] = -cpos[0]*sinphi+cpos[1]*cosphi;
722 cpos[0] = temp;
24322e5c 723 temp = v0[0]*cosphi+v0[1]*sinphi;
d88fbf15 724 v0[1] = -v0[0]*sinphi+v0[1]*cosphi;
725 v0[0] = temp;
726 //
727 temp = cpos[0]*costh+cpos[2]*sinth;
728 cpos[2] = -cpos[0]*sinth+cpos[2]*costh;
729 cpos[0] = temp;
24322e5c 730 temp = v0[0]*costh+v0[2]*sinth;
731 v0[2] = -v0[0]*sinth+v0[2]*costh;
732 v0[0] = temp;
d88fbf15 733 //
734 //
735 //rotate direction vector
736 //
24322e5c 737 temp = dir[0]*cosphi+dir[1]*sinphi;
d88fbf15 738 dir[1] = -dir[0]*sinphi+dir[1]*cosphi;
739 dir[0] = temp;
740 //
24322e5c 741 temp = dir[0]*costh+dir[2]*sinth;
742 dir[2] = -dir[0]*sinth+dir[2]*costh;
743 dir[0] = temp;
d88fbf15 744 //
745 Float_t v3[3];
746 Float_t k = (cpos[0]-v0[0])/dir[0];
747 v3[0] = v0[0]+k*dir[0];
748 v3[1] = v0[1]+k*dir[1];
749 v3[2] = v0[2]+k*dir[2];
750 //
751 distances[0] = v3[0]-cpos[0];
752 distances[1] = v3[1]-cpos[1];
753 distances[2] = v3[2]-cpos[2];
754 distances[3] = TMath::Sqrt( distances[0]*distances[0]+distances[1]*distances[1]+distances[2]*distances[2]); //distance
755 distances[4] = k; //length
756
757 //
758 // Debuging part of the matching
759 //
24322e5c 760 if (track->GetLabel()==cluster->GetLabel(0) ||
761 track->GetLabel()==cluster->GetLabel(1) ||
762 track->GetLabel()==cluster->GetLabel(2) ){
d88fbf15 763 TTreeSRedirector& cstream = *fDebugStreamer;
764 Float_t tdc = cluster->GetTDC();
765 cstream<<"Tracks"<<
766 "TOF.="<<track<<
767 "Cx="<<cpos0[0]<<
768 "Cy="<<cpos0[1]<<
769 "Cz="<<cpos0[2]<<
770 "Dist="<<k<<
771 "Dist0="<<distances[0]<<
772 "Dist1="<<distances[1]<<
773 "Dist2="<<distances[2]<<
774 "TDC="<<tdc<<
775 "\n";
776 }
777 return distances[3];
778}
779
24322e5c 780//_________________________________________________________________________
069bb393 781void AliTOFtrackerMI::GetLikelihood(Float_t dy, Float_t dz, const Double_t *cov, AliTOFtrack * /*track*/, Float_t & py, Float_t &pz) const
d88fbf15 782{
783 //
784 // get likelihood - track covariance taken
785 // 75 % of gauss with expected sigma
786 // 25 % of gauss with extended sigma
787
788 Double_t kMaxSigmaY = 0.6; // ~ 90% of TRD tracks
789 Double_t kMaxSigmaZ = 1.2; // ~ 90% of TRD tracks
790 Double_t kMeanSigmaY = 0.25; // mean TRD sigma
791 Double_t kMeanSigmaZ = 0.5; // mean TRD sigma
792
793
794 Float_t normwidth, normd, p0,p1;
795 Float_t sigmay = TMath::Max(TMath::Sqrt(cov[0]+kMeanSigmaY*kMeanSigmaY),kMaxSigmaY);
796 Float_t sigmaz = TMath::Max(TMath::Sqrt(cov[2]+kMeanSigmaZ*kMeanSigmaZ),kMaxSigmaZ);
797
798 py=0;
799 pz=0;
800 //
801 // py calculation - 75% admixture of original sigma - 25% tails
802 //
803 normwidth = fDy/sigmay;
804 normd = dy/sigmay;
bb7e41dd 805 p0 = 0.5*(1+AliMathBase::ErfFast(normd-normwidth*0.5));
806 p1 = 0.5*(1+AliMathBase::ErfFast(normd+normwidth*0.5));
d88fbf15 807 py+= 0.75*(p1-p0);
808 //
809 normwidth = fDy/(3.*sigmay);
810 normd = dy/(3.*sigmay);
bb7e41dd 811 p0 = 0.5*(1+AliMathBase::ErfFast(normd-normwidth*0.5));
812 p1 = 0.5*(1+AliMathBase::ErfFast(normd+normwidth*0.5));
d88fbf15 813 py+= 0.25*(p1-p0);
814 //
815 // pz calculation - 75% admixture of original sigma - 25% tails
816 //
817 normwidth = fDz/sigmaz;
818 normd = dz/sigmaz;
bb7e41dd 819 p0 = 0.5*(1+AliMathBase::ErfFast(normd-normwidth*0.5));
820 p1 = 0.5*(1+AliMathBase::ErfFast(normd+normwidth*0.5));
d88fbf15 821 pz+= 0.75*(p1-p0);
822 //
823 normwidth = fDz/(3.*sigmaz);
824 normd = dz/(3.*sigmaz);
bb7e41dd 825 p0 = 0.5*(1+AliMathBase::ErfFast(normd-normwidth*0.5));
826 p1 = 0.5*(1+AliMathBase::ErfFast(normd+normwidth*0.5));
d88fbf15 827 pz+= 0.25*(p1-p0);
828}
128563f6 829//_________________________________________________________________________
830
831void AliTOFtrackerMI::FillClusterArray(TObjArray* arr) const
832{
833 //
834 // Returns the TOF cluster array
835 //
836
837 if (fN==0)
838 arr = 0x0;
839 else
840 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
841
842}