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