1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Implementation of the AliTracker class
20 // that is the base for AliTPCtracker, AliITStrackerV2 and AliTRDtracker
21 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
22 //-------------------------------------------------------------------------
26 #include <TGeoManager.h>
27 #include <TGeoMatrix.h>
31 #include "AliTracker.h"
32 #include "AliGeomManager.h"
33 #include "AliCluster.h"
34 #include "AliKalmanTrack.h"
35 #include "AliGlobalQADataMaker.h"
37 extern TGeoManager *gGeoManager;
39 Bool_t AliTracker::fFillResiduals=kFALSE;
40 TObjArray **AliTracker::fResiduals=NULL;
41 AliRecoParam::EventSpecie_t AliTracker::fEventSpecie=AliRecoParam::kDefault;
45 AliTracker::AliTracker():
55 //--------------------------------------------------------------------
56 // The default constructor.
57 //--------------------------------------------------------------------
58 if (!TGeoGlobalMagField::Instance()->GetField())
59 AliWarning("Field map is not set.");
62 //__________________________________________________________________________
63 AliTracker::AliTracker(const AliTracker &atr):
71 fEventInfo(atr.fEventInfo)
73 //--------------------------------------------------------------------
74 // The default constructor.
75 //--------------------------------------------------------------------
76 if (!TGeoGlobalMagField::Instance()->GetField())
77 AliWarning("Field map is not set.");
80 //__________________________________________________________________________
81 Double_t AliTracker::GetBz()
83 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
84 if (!fld) return 0.5*kAlmost0Field;
85 Double_t bz = fld->SolenoidField();
86 return TMath::Sign(0.5*kAlmost0Field,bz) + bz;
89 //__________________________________________________________________________
90 Double_t AliTracker::GetBz(const Double_t *r) {
91 //------------------------------------------------------------------
92 // Returns Bz (kG) at the point "r" .
93 //------------------------------------------------------------------
94 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
95 if (!fld) return 0.5*kAlmost0Field;
96 Double_t bz = fld->GetBz(r);
97 return TMath::Sign(0.5*kAlmost0Field,bz) + bz;
100 //__________________________________________________________________________
101 void AliTracker::GetBxByBz(const Double_t r[3], Double_t b[3]) {
102 //------------------------------------------------------------------
103 // Returns Bx, By and Bz (kG) at the point "r" .
104 //------------------------------------------------------------------
105 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
108 b[2] = 0.5*kAlmost0Field;
112 if (fld->IsUniform()) {
114 b[2] = fld->SolenoidField();
118 b[2] = (TMath::Sign(0.5*kAlmost0Field,b[2]) + b[2]);
122 //__________________________________________________________________________
123 void AliTracker::FillClusterArray(TObjArray* /*array*/) const
125 // Publishes all pointers to clusters known to the tracker into the
126 // passed object array.
127 // The ownership is not transfered - the caller is not expected to delete
130 AliWarning("should be overriden by a sub-class.");
133 //__________________________________________________________________________
134 void AliTracker::CookLabel(AliKalmanTrack *t, Float_t wrong) const {
135 //--------------------------------------------------------------------
136 //This function "cooks" a track label. If label<0, this track is fake.
137 //--------------------------------------------------------------------
138 Int_t noc=t->GetNumberOfClusters();
140 Int_t *lb=new Int_t[noc];
141 Int_t *mx=new Int_t[noc];
142 AliCluster **clusters=new AliCluster*[noc];
145 for (i=0; i<noc; i++) {
147 Int_t index=t->GetClusterIndex(i);
148 clusters[i]=GetCluster(index);
152 for (i=0; i<noc; i++) {
153 AliCluster *c=clusters[i];
154 lab=TMath::Abs(c->GetLabel(0));
156 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
162 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
164 for (i=0; i<noc; i++) {
165 AliCluster *c=clusters[i];
166 //if (TMath::Abs(c->GetLabel(1)) == lab ||
167 // TMath::Abs(c->GetLabel(2)) == lab ) max++;
168 if (TMath::Abs(c->GetLabel(0)!=lab))
169 if (TMath::Abs(c->GetLabel(1)) == lab ||
170 TMath::Abs(c->GetLabel(2)) == lab ) max++;
173 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
174 t->SetFakeRatio((1.- Float_t(max)/noc));
182 //____________________________________________________________________________
183 void AliTracker::UseClusters(const AliKalmanTrack *t, Int_t from) const {
184 //------------------------------------------------------------------
185 //This function marks clusters associated with the track.
186 //------------------------------------------------------------------
187 Int_t noc=t->GetNumberOfClusters();
188 for (Int_t i=from; i<noc; i++) {
189 Int_t index=t->GetClusterIndex(i);
190 AliCluster *c=GetCluster(index);
195 Double_t AliTracker::MeanMaterialBudget(const Double_t *start, const Double_t *end, Double_t *mparam)
198 // Calculate mean material budget and material properties between
199 // the points "start" and "end".
201 // "mparam" - parameters used for the energy and multiple scattering
204 // mparam[0] - mean density: sum(x_i*rho_i)/sum(x_i) [g/cm3]
205 // mparam[1] - equivalent rad length fraction: sum(x_i/X0_i) [adimensional]
206 // mparam[2] - mean A: sum(x_i*A_i)/sum(x_i) [adimensional]
207 // mparam[3] - mean Z: sum(x_i*Z_i)/sum(x_i) [adimensional]
208 // mparam[4] - length: sum(x_i) [cm]
209 // mparam[5] - Z/A mean: sum(x_i*Z_i/A_i)/sum(x_i) [adimensional]
210 // mparam[6] - number of boundary crosses
212 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
214 // Corrections and improvements by
215 // Andrea Dainese, Andrea.Dainese@lnl.infn.it,
216 // Andrei Gheata, Andrei.Gheata@cern.ch
219 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0;
220 mparam[4]=0; mparam[5]=0; mparam[6]=0;
222 Double_t bparam[6]; // total parameters
223 Double_t lparam[6]; // local parameters
225 for (Int_t i=0;i<6;i++) bparam[i]=0;
228 AliErrorClass("No TGeo\n");
234 length = TMath::Sqrt((end[0]-start[0])*(end[0]-start[0])+
235 (end[1]-start[1])*(end[1]-start[1])+
236 (end[2]-start[2])*(end[2]-start[2]));
238 if (length<TGeoShape::Tolerance()) return 0.0;
239 Double_t invlen = 1./length;
240 dir[0] = (end[0]-start[0])*invlen;
241 dir[1] = (end[1]-start[1])*invlen;
242 dir[2] = (end[2]-start[2])*invlen;
244 // Initialize start point and direction
245 TGeoNode *currentnode = 0;
246 TGeoNode *startnode = gGeoManager->InitTrack(start, dir);
248 AliErrorClass(Form("start point out of geometry: x %f, y %f, z %f",
249 start[0],start[1],start[2]));
252 TGeoMaterial *material = startnode->GetVolume()->GetMedium()->GetMaterial();
253 lparam[0] = material->GetDensity();
254 lparam[1] = material->GetRadLen();
255 lparam[2] = material->GetA();
256 lparam[3] = material->GetZ();
258 lparam[5] = lparam[3]/lparam[2];
259 if (material->IsMixture()) {
260 TGeoMixture * mixture = (TGeoMixture*)material;
263 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
264 sum += mixture->GetWmixt()[iel];
265 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
270 // Locate next boundary within length without computing safety.
271 // Propagate either with length (if no boundary found) or just cross boundary
272 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
273 Double_t step = 0.0; // Step made
274 Double_t snext = gGeoManager->GetStep();
275 // If no boundary within proposed length, return current density
276 if (!gGeoManager->IsOnBoundary()) {
277 mparam[0] = lparam[0];
278 mparam[1] = lparam[4]/lparam[1];
279 mparam[2] = lparam[2];
280 mparam[3] = lparam[3];
281 mparam[4] = lparam[4];
284 // Try to cross the boundary and see what is next
286 while (length>TGeoShape::Tolerance()) {
287 currentnode = gGeoManager->GetCurrentNode();
288 if (snext<2.*TGeoShape::Tolerance()) nzero++;
291 // This means navigation has problems on one boundary
292 // Try to cross by making a small step
293 AliErrorClass("Cannot cross boundary\n");
294 mparam[0] = bparam[0]/step;
295 mparam[1] = bparam[1];
296 mparam[2] = bparam[2]/step;
297 mparam[3] = bparam[3]/step;
298 mparam[5] = bparam[5]/step;
300 mparam[0] = 0.; // if crash of navigation take mean density 0
301 mparam[1] = 1000000; // and infinite rad length
302 return bparam[0]/step;
306 bparam[1] += snext/lparam[1];
307 bparam[2] += snext*lparam[2];
308 bparam[3] += snext*lparam[3];
309 bparam[5] += snext*lparam[5];
310 bparam[0] += snext*lparam[0];
312 if (snext>=length) break;
313 if (!currentnode) break;
315 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
316 lparam[0] = material->GetDensity();
317 lparam[1] = material->GetRadLen();
318 lparam[2] = material->GetA();
319 lparam[3] = material->GetZ();
320 lparam[5] = lparam[3]/lparam[2];
321 if (material->IsMixture()) {
322 TGeoMixture * mixture = (TGeoMixture*)material;
325 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
326 sum+= mixture->GetWmixt()[iel];
327 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
331 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
332 snext = gGeoManager->GetStep();
334 mparam[0] = bparam[0]/step;
335 mparam[1] = bparam[1];
336 mparam[2] = bparam[2]/step;
337 mparam[3] = bparam[3]/step;
338 mparam[5] = bparam[5]/step;
339 return bparam[0]/step;
344 AliTracker::PropagateTrackTo(AliExternalTrackParam *track, Double_t xToGo,
345 Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp, Double_t sign){
346 //----------------------------------------------------------------
348 // Propagates the track to the plane X=xk (cm) using the magnetic field map
349 // and correcting for the crossed material.
351 // mass - mass used in propagation - used for energy loss correction
352 // maxStep - maximal step for propagation
354 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
356 //----------------------------------------------------------------
357 const Double_t kEpsilon = 0.00001;
358 Double_t xpos = track->GetX();
359 Double_t dir = (xpos<xToGo) ? 1.:-1.;
361 while ( (xToGo-xpos)*dir > kEpsilon){
362 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
363 Double_t x = xpos+step;
364 Double_t xyz0[3],xyz1[3],param[7];
365 track->GetXYZ(xyz0); //starting global position
367 Double_t bz=GetBz(xyz0); // getting the local Bz
369 if (!track->GetXYZAt(x,bz,xyz1)) return kFALSE; // no prolongation
370 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
372 if (TMath::Abs(track->GetSnpAt(x,bz)) >= maxSnp) return kFALSE;
373 if (!track->PropagateTo(x,bz)) return kFALSE;
375 MeanMaterialBudget(xyz0,xyz1,param);
376 Double_t xrho=param[0]*param[4]*sign, xx0=param[1];
378 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
380 if (TMath::Abs(track->GetSnp()) >= maxSnp) return kFALSE;
381 track->GetXYZ(xyz0); // global position
382 Double_t alphan = TMath::ATan2(xyz0[1], xyz0[0]);
384 Double_t ca=TMath::Cos(alphan-track->GetAlpha()),
385 sa=TMath::Sin(alphan-track->GetAlpha());
386 Double_t sf=track->GetSnp(), cf=TMath::Sqrt((1.-sf)*(1.+sf));
387 Double_t sinNew = sf*ca - cf*sa;
388 if (TMath::Abs(sinNew) >= maxSnp) return kFALSE;
389 if (!track->Rotate(alphan)) return kFALSE;
391 xpos = track->GetX();
397 AliTracker::PropagateTrackToBxByBz(AliExternalTrackParam *track,
399 Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp,Double_t sign){
400 //----------------------------------------------------------------
402 // Propagates the track to the plane X=xk (cm)
403 // taking into account all the three components of the magnetic field
404 // and correcting for the crossed material.
406 // mass - mass used in propagation - used for energy loss correction
407 // maxStep - maximal step for propagation
409 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
411 //----------------------------------------------------------------
412 const Double_t kEpsilon = 0.00001;
413 Double_t xpos = track->GetX();
414 Double_t dir = (xpos<xToGo) ? 1.:-1.;
416 while ( (xToGo-xpos)*dir > kEpsilon){
417 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
418 Double_t x = xpos+step;
419 Double_t xyz0[3],xyz1[3],param[7];
420 track->GetXYZ(xyz0); //starting global position
422 Double_t b[3]; GetBxByBz(xyz0,b); // getting the local Bx, By and Bz
424 if (!track->GetXYZAt(x,b[2],xyz1)) return kFALSE; // no prolongation
425 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
427 if (TMath::Abs(track->GetSnpAt(x,b[2])) >= maxSnp) return kFALSE;
428 if (!track->PropagateToBxByBz(x,b)) return kFALSE;
430 MeanMaterialBudget(xyz0,xyz1,param);
431 Double_t xrho=param[0]*param[4]*sign, xx0=param[1];
433 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
435 if (TMath::Abs(track->GetSnp()) >= maxSnp) return kFALSE;
436 track->GetXYZ(xyz0); // global position
437 Double_t alphan = TMath::ATan2(xyz0[1], xyz0[0]);
439 Double_t ca=TMath::Cos(alphan-track->GetAlpha()),
440 sa=TMath::Sin(alphan-track->GetAlpha());
441 Double_t sf=track->GetSnp(), cf=TMath::Sqrt((1.-sf)*(1.+sf));
442 Double_t sinNew = sf*ca - cf*sa;
443 if (TMath::Abs(sinNew) >= maxSnp) return kFALSE;
444 if (!track->Rotate(alphan)) return kFALSE;
446 xpos = track->GetX();
451 void AliTracker::FillResiduals(const AliExternalTrackParam *t,
452 Double_t *p, Double_t *cov,
453 UShort_t id, Bool_t updated) {
455 // This function fills the histograms of residuals
456 // The array of these histos is external for this AliTracker class.
457 // Normally, this array belong to AliGlobalQADataMaker class.
459 if (!fFillResiduals) return;
460 if (!fResiduals) return;
462 const Double_t *residuals=t->GetResiduals(p,cov,updated);
463 if (!residuals) return;
466 Int_t esIndex = AliRecoParam::AConvert(fEventSpecie) ;
467 AliGeomManager::ELayerID layer=AliGeomManager::VolUIDToLayer(id);
468 h=(TH1F*)fResiduals[esIndex]->At(2*layer-2);
469 if (h) h->Fill(residuals[0]);
470 h=(TH1F*)fResiduals[esIndex]->At(2*layer-1);
471 if (h) h->Fill(residuals[1]);
474 if (p[1]<0) { // SSD1 absolute residuals
475 h = (TH1F*)fResiduals[esIndex]->At(40);
476 if (h) h->Fill(t->GetY()-p[0]); //C side
477 h = (TH1F*)fResiduals[esIndex]->At(41);
478 if (h) h->Fill(t->GetZ()-p[1]);
480 h = (TH1F*)fResiduals[esIndex]->At(42);
481 if (h) h->Fill(t->GetY()-p[0]); //A side
482 h = (TH1F*)fResiduals[esIndex]->At(43);
483 if (h) h->Fill(t->GetZ()-p[1]);
486 if (layer==6) { // SSD2 absolute residuals
488 h = (TH1F*)fResiduals[esIndex]->At(44);
489 if (h) h->Fill(t->GetY()-p[0]); //C side
490 h = (TH1F*)fResiduals[esIndex]->At(45);
491 if (h) h->Fill(t->GetZ()-p[1]);
493 h = (TH1F*)fResiduals[esIndex]->At(46);
494 if (h) h->Fill(t->GetY()-p[0]); //A side
495 h = (TH1F*)fResiduals[esIndex]->At(47);
496 if (h) h->Fill(t->GetZ()-p[1]);
502 void AliTracker::FillResiduals(const AliExternalTrackParam *t,
503 const AliCluster *c, Bool_t /*updated*/) {
505 // This function fills the histograms of residuals
506 // The array of these histos is external for this AliTracker class.
507 // Normally, this array belong to AliGlobalQADataMaker class.
509 // For the moment, the residuals are absolute !
512 if (!fFillResiduals) return;
513 if (!fResiduals) return;
515 UShort_t id=c->GetVolumeId();
516 const TGeoHMatrix *matrixT2L=AliGeomManager::GetTracking2LocalMatrix(id);
518 // Position of the cluster in the tracking c.s.
519 Double_t clsTrk[3]={c->GetX(), c->GetY(), c->GetZ()};
520 // Position of the cluster in the local module c.s.
521 Double_t clsLoc[3]={0.,0.,0.};
522 matrixT2L->LocalToMaster(clsTrk,clsLoc);
525 // Position of the intersection point in the tracking c.s.
526 Double_t trkTrk[3]={t->GetX(),t->GetY(),t->GetZ()};
527 // Position of the intersection point in the local module c.s.
528 Double_t trkLoc[3]={0.,0.,0.};
529 matrixT2L->LocalToMaster(trkTrk,trkLoc);
531 Double_t residuals[2]={trkLoc[0]-clsLoc[0], trkLoc[2]-clsLoc[2]};
534 Int_t esIndex = AliRecoParam::AConvert(fEventSpecie) ;
535 AliGeomManager::ELayerID layer=AliGeomManager::VolUIDToLayer(id);
536 h=(TH1F*)fResiduals[esIndex]->At(2*layer-2);
537 if (h) h->Fill(residuals[0]);
538 h=(TH1F*)fResiduals[esIndex]->At(2*layer-1);
539 if (h) h->Fill(residuals[1]);
543 Double_t AliTracker::GetTrackPredictedChi2(AliExternalTrackParam *track,
544 Double_t mass, Double_t step,
545 const AliExternalTrackParam *backup) {
547 // This function brings the "track" with particle "mass" [GeV]
548 // to the same local coord. system and the same reference plane as
549 // of the "backup", doing it in "steps" [cm].
550 // Then, it calculates the 5D predicted Chi2 for these two tracks
552 Double_t chi2=kVeryBig;
553 Double_t alpha=backup->GetAlpha();
554 if (!track->Rotate(alpha)) return chi2;
556 Double_t xb=backup->GetX();
557 Double_t sign=(xb < track->GetX()) ? 1. : -1.;
558 if (!PropagateTrackTo(track,xb,mass,step,kFALSE,kAlmost1,sign)) return chi2;
560 chi2=track->GetPredictedChi2(backup);