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