]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFtrackerMI.cxx
Better implementation of copy-constructor and operator=
[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
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
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*
352 ((5*TMath::Sqrt(cov[0]) + 3.*fDy +10.*TMath::Abs(par[2]))/fR);
353 Double_t dz=
354 scalefact*
355 (5*TMath::Sqrt(cov[2]) + 3.*fDz +10.*TMath::Abs(par[3]));
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]];
d88fbf15 389 GetLinearDistances(trackTOFin,cluster, distances);
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 //
404 //length and TOF updates
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.);
d88fbf15 530 t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
531 t->SetIntegratedLength(length[igold]);
532 t->SetIntegratedTimes(times[igold]);
533 t->SetTOFLabel(tlab);
534 //
535 delete trackTOFin;
536 delete trackTOFout;
537 //
538 }
539 //
540 //
541 //
542 for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
128563f6 543 delete [] clind;
3a646035 544 //delete calib; // AdC
d88fbf15 545}
d88fbf15 546//_________________________________________________________________________
128563f6 547
d88fbf15 548Int_t AliTOFtrackerMI::LoadClusters(TTree *cTree) {
549 //--------------------------------------------------------------------
550 //This function loads the TOF clusters
551 //--------------------------------------------------------------------
552
553 TBranch *branch=cTree->GetBranch("TOF");
554 if (!branch) {
555 AliError("can't get the branch with the TOF clusters !");
556 return 1;
557 }
558
b42a5ea1 559 static TClonesArray dummy("AliTOFcluster",10000);
560 dummy.Clear();
561 TClonesArray *clusters=&dummy;
d88fbf15 562 branch->SetAddress(&clusters);
563
564 cTree->GetEvent(0);
565 Int_t nc=clusters->GetEntriesFast();
566 AliInfo(Form("Number of clusters: %d",nc));
567
568 for (Int_t i=0; i<nc; i++) {
569 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
d88fbf15 570
d88fbf15 571 fClusters[i]=new AliTOFcluster(*c); fN++;
572
573 //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)));
574 //AliInfo(Form("%i %f",i, fClusters[i]->GetZ()));
575 }
576
577 //AliInfo(Form("Number of clusters: %d",fN));
578
579 return 0;
580}
581//_________________________________________________________________________
582void AliTOFtrackerMI::UnloadClusters() {
583 //--------------------------------------------------------------------
584 //This function unloads TOF clusters
585 //--------------------------------------------------------------------
586 for (Int_t i=0; i<fN; i++) {
587 delete fClusters[i];
588 fClusters[i] = 0x0;
589 }
590 fN=0;
591}
592
593
594
595
596//_________________________________________________________________________
597Int_t AliTOFtrackerMI::InsertCluster(AliTOFcluster *c) {
598 //--------------------------------------------------------------------
599 //This function adds a cluster to the array of clusters sorted in Z
600 //--------------------------------------------------------------------
601 if (fN==kMaxCluster) {
0e46b9ae 602 AliError("Too many clusters !");
d88fbf15 603 return 1;
604 }
605
606 if (fN==0) {fClusters[fN++]=c; return 0;}
607 Int_t i=FindClusterIndex(c->GetZ());
608 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTOFcluster*));
609 fClusters[i]=c; fN++;
610
611 return 0;
612}
613
614//_________________________________________________________________________
615Int_t AliTOFtrackerMI::FindClusterIndex(Double_t z) const {
616 //--------------------------------------------------------------------
617 // This function returns the index of the nearest cluster
618 //--------------------------------------------------------------------
619 if (fN==0) return 0;
620 if (z <= fClusters[0]->GetZ()) return 0;
621 if (z > fClusters[fN-1]->GetZ()) return fN;
622 Int_t b=0, e=fN-1, m=(b+e)/2;
623 for (; b<e; m=(b+e)/2) {
624 if (z > fClusters[m]->GetZ()) b=m+1;
625 else e=m;
626 }
627 return m;
628}
629
630
631
632Float_t AliTOFtrackerMI::GetLinearDistances(AliTOFtrack * track, AliTOFcluster *cluster, Float_t distances[5])
633{
634 //
635 // calclates distance between cluster and track
636 // use linear aproximation
637 //
638 const Float_t kRaddeg = 180/3.14159265358979312;
639 //
640 // Float_t tiltangle = fGeom->GetAngles(cluster->fdetIndex[1],cluster->fdetIndex[2])/kRaddeg; //tiltangle
641 Int_t cind[5];
642 cind[0]= cluster->GetDetInd(0);
643 cind[1]= cluster->GetDetInd(1);
644 cind[2]= cluster->GetDetInd(2);
645 cind[3]= cluster->GetDetInd(3);
646 cind[4]= cluster->GetDetInd(4);
96f01799 647 Float_t tiltangle = AliTOFGeometry::GetAngles(cluster->GetDetInd(1),cluster->GetDetInd(2))/kRaddeg; //tiltangle
d88fbf15 648
649 Float_t cpos[3]; //cluster position
650 Float_t cpos0[3]; //cluster position
651 // fGeom->GetPos(cluster->fdetIndex,cpos);
652 //fGeom->GetPos(cluster->fdetIndex,cpos0);
653 //
654 fGeom->GetPos(cind,cpos);
655 fGeom->GetPos(cind,cpos0);
656
657 Float_t phi = TMath::ATan2(cpos[1],cpos[0]);
658 if(phi<0) phi=2.*TMath::Pi()+phi;
659 // Get the local angle in the sector philoc
660 Float_t phiangle = (Int_t (phi*kRaddeg/20.) + 0.5)*20./kRaddeg;
661 //
662 Double_t v0[3];
663 Double_t dir[3];
6c94f330 664 track->GetXYZ(v0);
665 track->GetPxPyPz(dir);
d88fbf15 666 dir[0]/=track->GetP();
667 dir[1]/=track->GetP();
668 dir[2]/=track->GetP();
669 //
670 //
671 //rotate 0
672 Float_t sinphi = TMath::Sin(phiangle);
673 Float_t cosphi = TMath::Cos(phiangle);
674 Float_t sinth = TMath::Sin(tiltangle);
675 Float_t costh = TMath::Cos(tiltangle);
676 //
677 Float_t temp;
678 temp = cpos[0]*cosphi+cpos[1]*sinphi;
679 cpos[1] = -cpos[0]*sinphi+cpos[1]*cosphi;
680 cpos[0] = temp;
681 temp = v0[0]*cosphi+v0[1]*sinphi;
682 v0[1] = -v0[0]*sinphi+v0[1]*cosphi;
683 v0[0] = temp;
684 //
685 temp = cpos[0]*costh+cpos[2]*sinth;
686 cpos[2] = -cpos[0]*sinth+cpos[2]*costh;
687 cpos[0] = temp;
688 temp = v0[0]*costh+v0[2]*sinth;
689 v0[2] = -v0[0]*sinth+v0[2]*costh;
690 v0[0] = temp;
691 //
692 //
693 //rotate direction vector
694 //
695 temp = dir[0]*cosphi+dir[1]*sinphi;
696 dir[1] = -dir[0]*sinphi+dir[1]*cosphi;
697 dir[0] = temp;
698 //
699 temp = dir[0]*costh+dir[2]*sinth;
700 dir[2] = -dir[0]*sinth+dir[2]*costh;
701 dir[0] = temp;
702 //
703 Float_t v3[3];
704 Float_t k = (cpos[0]-v0[0])/dir[0];
705 v3[0] = v0[0]+k*dir[0];
706 v3[1] = v0[1]+k*dir[1];
707 v3[2] = v0[2]+k*dir[2];
708 //
709 distances[0] = v3[0]-cpos[0];
710 distances[1] = v3[1]-cpos[1];
711 distances[2] = v3[2]-cpos[2];
712 distances[3] = TMath::Sqrt( distances[0]*distances[0]+distances[1]*distances[1]+distances[2]*distances[2]); //distance
713 distances[4] = k; //length
714
715 //
716 // Debuging part of the matching
717 //
718 if (track->GetLabel()==cluster->GetLabel(0) ||track->GetLabel()==cluster->GetLabel(1) ){
719 TTreeSRedirector& cstream = *fDebugStreamer;
720 Float_t tdc = cluster->GetTDC();
721 cstream<<"Tracks"<<
722 "TOF.="<<track<<
723 "Cx="<<cpos0[0]<<
724 "Cy="<<cpos0[1]<<
725 "Cz="<<cpos0[2]<<
726 "Dist="<<k<<
727 "Dist0="<<distances[0]<<
728 "Dist1="<<distances[1]<<
729 "Dist2="<<distances[2]<<
730 "TDC="<<tdc<<
731 "\n";
732 }
733 return distances[3];
734}
735
736
737
738void AliTOFtrackerMI::GetLikelihood(Float_t dy, Float_t dz, const Double_t *cov, AliTOFtrack * /*track*/, Float_t & py, Float_t &pz)
739{
740 //
741 // get likelihood - track covariance taken
742 // 75 % of gauss with expected sigma
743 // 25 % of gauss with extended sigma
744
745 Double_t kMaxSigmaY = 0.6; // ~ 90% of TRD tracks
746 Double_t kMaxSigmaZ = 1.2; // ~ 90% of TRD tracks
747 Double_t kMeanSigmaY = 0.25; // mean TRD sigma
748 Double_t kMeanSigmaZ = 0.5; // mean TRD sigma
749
750
751 Float_t normwidth, normd, p0,p1;
752 Float_t sigmay = TMath::Max(TMath::Sqrt(cov[0]+kMeanSigmaY*kMeanSigmaY),kMaxSigmaY);
753 Float_t sigmaz = TMath::Max(TMath::Sqrt(cov[2]+kMeanSigmaZ*kMeanSigmaZ),kMaxSigmaZ);
754
755 py=0;
756 pz=0;
757 //
758 // py calculation - 75% admixture of original sigma - 25% tails
759 //
760 normwidth = fDy/sigmay;
761 normd = dy/sigmay;
762 p0 = 0.5*(1+TMath::Erf(normd-normwidth*0.5));
763 p1 = 0.5*(1+TMath::Erf(normd+normwidth*0.5));
764 py+= 0.75*(p1-p0);
765 //
766 normwidth = fDy/(3.*sigmay);
767 normd = dy/(3.*sigmay);
768 p0 = 0.5*(1+TMath::Erf(normd-normwidth*0.5));
769 p1 = 0.5*(1+TMath::Erf(normd+normwidth*0.5));
770 py+= 0.25*(p1-p0);
771 //
772 // pz calculation - 75% admixture of original sigma - 25% tails
773 //
774 normwidth = fDz/sigmaz;
775 normd = dz/sigmaz;
776 p0 = 0.5*(1+TMath::Erf(normd-normwidth*0.5));
777 p1 = 0.5*(1+TMath::Erf(normd+normwidth*0.5));
778 pz+= 0.75*(p1-p0);
779 //
780 normwidth = fDz/(3.*sigmaz);
781 normd = dz/(3.*sigmaz);
782 p0 = 0.5*(1+TMath::Erf(normd-normwidth*0.5));
783 p1 = 0.5*(1+TMath::Erf(normd+normwidth*0.5));
784 pz+= 0.25*(p1-p0);
785}
128563f6 786//_________________________________________________________________________
787
788void AliTOFtrackerMI::FillClusterArray(TObjArray* arr) const
789{
790 //
791 // Returns the TOF cluster array
792 //
793
794 if (fN==0)
795 arr = 0x0;
796 else
797 for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
798
799}