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>
30 #include "AliTracker.h"
31 #include "AliGeomManager.h"
32 #include "AliCluster.h"
33 #include "AliKalmanTrack.h"
34 #include "AliGlobalQADataMaker.h"
36 extern TGeoManager *gGeoManager;
38 Bool_t AliTracker::fFillResiduals=kFALSE;
39 TObjArray **AliTracker::fResiduals=NULL;
40 AliRecoParam::EventSpecie_t AliTracker::fEventSpecie=AliRecoParam::kDefault;
44 AliTracker::AliTracker():
54 //--------------------------------------------------------------------
55 // The default constructor.
56 //--------------------------------------------------------------------
57 if (!TGeoGlobalMagField::Instance()->GetField())
58 AliWarning("Field map is not set.");
61 //__________________________________________________________________________
62 AliTracker::AliTracker(const AliTracker &atr):
70 fEventInfo(atr.fEventInfo)
72 //--------------------------------------------------------------------
73 // The default constructor.
74 //--------------------------------------------------------------------
75 if (!TGeoGlobalMagField::Instance()->GetField())
76 AliWarning("Field map is not set.");
79 //__________________________________________________________________________
80 Double_t AliTracker::GetBz()
82 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
83 if (!fld) return 0.5*kAlmost0Field;
84 Double_t bz = fld->SolenoidField();
85 return TMath::Sign(0.5*kAlmost0Field,bz) + bz;
88 //__________________________________________________________________________
89 Double_t AliTracker::GetBz(const Double_t *r) {
90 //------------------------------------------------------------------
91 // Returns Bz (kG) at the point "r" .
92 //------------------------------------------------------------------
93 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
94 if (!fld) return 0.5*kAlmost0Field;
95 Double_t bz = fld->GetBz(r);
96 return TMath::Sign(0.5*kAlmost0Field,bz) + bz;
99 //__________________________________________________________________________
100 void AliTracker::GetBxByBz(const Double_t r[3], Double_t b[3]) {
101 //------------------------------------------------------------------
102 // Returns Bx, By and Bz (kG) at the point "r" .
103 //------------------------------------------------------------------
104 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
107 b[2] = 0.5*kAlmost0Field;
111 if (fld->IsUniform()) {
113 b[2] = fld->SolenoidField();
117 b[2] = (TMath::Sign(0.5*kAlmost0Field,b[2]) + b[2]);
121 //__________________________________________________________________________
122 void AliTracker::FillClusterArray(TObjArray* /*array*/) const
124 // Publishes all pointers to clusters known to the tracker into the
125 // passed object array.
126 // The ownership is not transfered - the caller is not expected to delete
129 AliWarning("should be overriden by a sub-class.");
132 //__________________________________________________________________________
133 void AliTracker::CookLabel(AliKalmanTrack *t, Float_t wrong) const {
134 //--------------------------------------------------------------------
135 //This function "cooks" a track label. If label<0, this track is fake.
136 //--------------------------------------------------------------------
137 Int_t noc=t->GetNumberOfClusters();
139 Int_t *lb=new Int_t[noc];
140 Int_t *mx=new Int_t[noc];
141 AliCluster **clusters=new AliCluster*[noc];
144 for (i=0; i<noc; i++) {
146 Int_t index=t->GetClusterIndex(i);
147 clusters[i]=GetCluster(index);
151 for (i=0; i<noc; i++) {
152 AliCluster *c=clusters[i];
153 lab=TMath::Abs(c->GetLabel(0));
155 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
161 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
163 for (i=0; i<noc; i++) {
164 AliCluster *c=clusters[i];
165 //if (TMath::Abs(c->GetLabel(1)) == lab ||
166 // TMath::Abs(c->GetLabel(2)) == lab ) max++;
167 if (TMath::Abs(c->GetLabel(0)!=lab))
168 if (TMath::Abs(c->GetLabel(1)) == lab ||
169 TMath::Abs(c->GetLabel(2)) == lab ) max++;
172 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
173 t->SetFakeRatio((1.- Float_t(max)/noc));
181 //____________________________________________________________________________
182 void AliTracker::UseClusters(const AliKalmanTrack *t, Int_t from) const {
183 //------------------------------------------------------------------
184 //This function marks clusters associated with the track.
185 //------------------------------------------------------------------
186 Int_t noc=t->GetNumberOfClusters();
187 for (Int_t i=from; i<noc; i++) {
188 Int_t index=t->GetClusterIndex(i);
189 AliCluster *c=GetCluster(index);
194 Double_t AliTracker::MeanMaterialBudget(const Double_t *start, const Double_t *end, Double_t *mparam)
197 // Calculate mean material budget and material properties between
198 // the points "start" and "end".
200 // "mparam" - parameters used for the energy and multiple scattering
203 // mparam[0] - mean density: sum(x_i*rho_i)/sum(x_i) [g/cm3]
204 // mparam[1] - equivalent rad length fraction: sum(x_i/X0_i) [adimensional]
205 // mparam[2] - mean A: sum(x_i*A_i)/sum(x_i) [adimensional]
206 // mparam[3] - mean Z: sum(x_i*Z_i)/sum(x_i) [adimensional]
207 // mparam[4] - length: sum(x_i) [cm]
208 // mparam[5] - Z/A mean: sum(x_i*Z_i/A_i)/sum(x_i) [adimensional]
209 // mparam[6] - number of boundary crosses
211 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
213 // Corrections and improvements by
214 // Andrea Dainese, Andrea.Dainese@lnl.infn.it,
215 // Andrei Gheata, Andrei.Gheata@cern.ch
218 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0;
219 mparam[4]=0; mparam[5]=0; mparam[6]=0;
221 Double_t bparam[6]; // total parameters
222 Double_t lparam[6]; // local parameters
224 for (Int_t i=0;i<6;i++) bparam[i]=0;
227 printf("ERROR: no TGeo\n");
233 length = TMath::Sqrt((end[0]-start[0])*(end[0]-start[0])+
234 (end[1]-start[1])*(end[1]-start[1])+
235 (end[2]-start[2])*(end[2]-start[2]));
237 if (length<TGeoShape::Tolerance()) return 0.0;
238 Double_t invlen = 1./length;
239 dir[0] = (end[0]-start[0])*invlen;
240 dir[1] = (end[1]-start[1])*invlen;
241 dir[2] = (end[2]-start[2])*invlen;
243 // Initialize start point and direction
244 TGeoNode *currentnode = 0;
245 TGeoNode *startnode = gGeoManager->InitTrack(start, dir);
246 //printf("%s length=%f\n",gGeoManager->GetPath(),length);
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 printf("ERROR: 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 //printf("%s snext=%f length=%f\n", currentnode->GetName(),snext,length);
316 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
317 lparam[0] = material->GetDensity();
318 lparam[1] = material->GetRadLen();
319 lparam[2] = material->GetA();
320 lparam[3] = material->GetZ();
321 //printf(" %f %f %f %f\n",lparam[0],lparam[1],lparam[2],lparam[3]);
322 lparam[5] = lparam[3]/lparam[2];
323 if (material->IsMixture()) {
324 TGeoMixture * mixture = (TGeoMixture*)material;
327 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
328 sum+= mixture->GetWmixt()[iel];
329 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
333 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
334 snext = gGeoManager->GetStep();
335 //printf("snext %f\n",snext);
337 mparam[0] = bparam[0]/step;
338 mparam[1] = bparam[1];
339 mparam[2] = bparam[2]/step;
340 mparam[3] = bparam[3]/step;
341 mparam[5] = bparam[5]/step;
342 return bparam[0]/step;
347 AliTracker::PropagateTrackTo(AliExternalTrackParam *track, Double_t xToGo,
348 Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp){
349 //----------------------------------------------------------------
351 // Propagates the track to the plane X=xk (cm) using the magnetic field map
352 // and correcting for the crossed material.
354 // mass - mass used in propagation - used for energy loss correction
355 // maxStep - maximal step for propagation
357 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
359 //----------------------------------------------------------------
360 const Double_t kEpsilon = 0.00001;
361 Double_t xpos = track->GetX();
362 Double_t dir = (xpos<xToGo) ? 1.:-1.;
364 while ( (xToGo-xpos)*dir > kEpsilon){
365 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
366 Double_t x = xpos+step;
367 Double_t xyz0[3],xyz1[3],param[7];
368 track->GetXYZ(xyz0); //starting global position
370 Double_t bz=GetBz(xyz0); // getting the local Bz
372 if (!track->GetXYZAt(x,bz,xyz1)) return kFALSE; // no prolongation
373 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
375 if (TMath::Abs(track->GetSnpAt(x,bz)) >= maxSnp) return kFALSE;
376 if (!track->PropagateTo(x,bz)) return kFALSE;
378 MeanMaterialBudget(xyz0,xyz1,param);
379 Double_t xrho=param[0]*param[4], xx0=param[1];
381 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
383 if (TMath::Abs(track->GetSnp()) >= maxSnp) return kFALSE;
384 track->GetXYZ(xyz0); // global position
385 Double_t alphan = TMath::ATan2(xyz0[1], xyz0[0]);
387 Double_t ca=TMath::Cos(alphan-track->GetAlpha()),
388 sa=TMath::Sin(alphan-track->GetAlpha());
389 Double_t sf=track->GetSnp(), cf=TMath::Sqrt((1.-sf)*(1.+sf));
390 Double_t sinNew = sf*ca - cf*sa;
391 if (TMath::Abs(sinNew) >= maxSnp) return kFALSE;
392 if (!track->Rotate(alphan)) return kFALSE;
394 xpos = track->GetX();
400 AliTracker::PropagateTrackToBxByBz(AliExternalTrackParam *track,
402 Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp){
403 //----------------------------------------------------------------
405 // Propagates the track to the plane X=xk (cm)
406 // taking into account all the three components of the magnetic field
407 // and correcting for the crossed material.
409 // mass - mass used in propagation - used for energy loss correction
410 // maxStep - maximal step for propagation
412 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
414 //----------------------------------------------------------------
415 const Double_t kEpsilon = 0.00001;
416 Double_t xpos = track->GetX();
417 Double_t dir = (xpos<xToGo) ? 1.:-1.;
419 while ( (xToGo-xpos)*dir > kEpsilon){
420 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
421 Double_t x = xpos+step;
422 Double_t xyz0[3],xyz1[3],param[7];
423 track->GetXYZ(xyz0); //starting global position
425 Double_t b[3]; GetBxByBz(xyz0,b); // getting the local Bx, By and Bz
427 if (!track->GetXYZAt(x,b[2],xyz1)) return kFALSE; // no prolongation
428 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
430 if (TMath::Abs(track->GetSnpAt(x,b[2])) >= maxSnp) return kFALSE;
431 if (!track->PropagateToBxByBz(x,b)) return kFALSE;
433 MeanMaterialBudget(xyz0,xyz1,param);
434 Double_t xrho=param[0]*param[4], xx0=param[1];
436 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
438 if (TMath::Abs(track->GetSnp()) >= maxSnp) return kFALSE;
439 track->GetXYZ(xyz0); // global position
440 Double_t alphan = TMath::ATan2(xyz0[1], xyz0[0]);
442 Double_t ca=TMath::Cos(alphan-track->GetAlpha()),
443 sa=TMath::Sin(alphan-track->GetAlpha());
444 Double_t sf=track->GetSnp(), cf=TMath::Sqrt((1.-sf)*(1.+sf));
445 Double_t sinNew = sf*ca - cf*sa;
446 if (TMath::Abs(sinNew) >= maxSnp) return kFALSE;
447 if (!track->Rotate(alphan)) return kFALSE;
449 xpos = track->GetX();
454 void AliTracker::FillResiduals(const AliExternalTrackParam *t,
455 Double_t *p, Double_t *cov,
456 UShort_t id, Bool_t updated) {
458 // This function fills the histograms of residuals
459 // The array of these histos is external for this AliTracker class.
460 // Normally, this array belong to AliGlobalQADataMaker class.
462 if (!fFillResiduals) return;
463 if (!fResiduals) return;
465 const Double_t *residuals=t->GetResiduals(p,cov,updated);
466 if (!residuals) return;
469 Int_t esIndex = AliRecoParam::AConvert(fEventSpecie) ;
470 AliGeomManager::ELayerID layer=AliGeomManager::VolUIDToLayer(id);
471 h=(TH1F*)fResiduals[esIndex]->At(2*layer-2);
472 h->Fill(residuals[0]);
473 h=(TH1F*)fResiduals[esIndex]->At(2*layer-1);
474 h->Fill(residuals[1]);
477 if (p[1]<0) { // SSD1 absolute residuals
478 ((TH1F*)fResiduals[esIndex]->At(40))->Fill(t->GetY()-p[0]); //C side
479 ((TH1F*)fResiduals[esIndex]->At(41))->Fill(t->GetZ()-p[1]);
481 ((TH1F*)fResiduals[esIndex]->At(42))->Fill(t->GetY()-p[0]); //A side
482 ((TH1F*)fResiduals[esIndex]->At(43))->Fill(t->GetZ()-p[1]);
485 if (layer==6) { // SSD2 absolute residuals
487 ((TH1F*)fResiduals[esIndex]->At(44))->Fill(t->GetY()-p[0]); //C side
488 ((TH1F*)fResiduals[esIndex]->At(45))->Fill(t->GetZ()-p[1]);
490 ((TH1F*)fResiduals[esIndex]->At(46))->Fill(t->GetY()-p[0]); //A side
491 ((TH1F*)fResiduals[esIndex]->At(47))->Fill(t->GetZ()-p[1]);
497 void AliTracker::FillResiduals(const AliExternalTrackParam *t,
498 const AliCluster *c, Bool_t /*updated*/) {
500 // This function fills the histograms of residuals
501 // The array of these histos is external for this AliTracker class.
502 // Normally, this array belong to AliGlobalQADataMaker class.
504 // For the moment, the residuals are absolute !
507 if (!fFillResiduals) return;
508 if (!fResiduals) return;
510 UShort_t id=c->GetVolumeId();
511 const TGeoHMatrix *matrixT2L=AliGeomManager::GetTracking2LocalMatrix(id);
513 // Position of the cluster in the tracking c.s.
514 Double_t clsTrk[3]={c->GetX(), c->GetY(), c->GetZ()};
515 // Position of the cluster in the local module c.s.
516 Double_t clsLoc[3]={0.,0.,0.};
517 matrixT2L->LocalToMaster(clsTrk,clsLoc);
520 // Position of the intersection point in the tracking c.s.
521 Double_t trkTrk[3]={t->GetX(),t->GetY(),t->GetZ()};
522 // Position of the intersection point in the local module c.s.
523 Double_t trkLoc[3]={0.,0.,0.};
524 matrixT2L->LocalToMaster(trkTrk,trkLoc);
526 Double_t residuals[2]={trkLoc[0]-clsLoc[0], trkLoc[2]-clsLoc[2]};
529 Int_t esIndex = AliRecoParam::AConvert(fEventSpecie) ;
530 AliGeomManager::ELayerID layer=AliGeomManager::VolUIDToLayer(id);
531 h=(TH1F*)fResiduals[esIndex]->At(2*layer-2);
532 h->Fill(residuals[0]);
533 h=(TH1F*)fResiduals[esIndex]->At(2*layer-1);
534 h->Fill(residuals[1]);