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