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 //-------------------------------------------------------------------------
25 #include <TGeoManager.h>
28 #include "AliTracker.h"
29 #include "AliCluster.h"
30 #include "AliKalmanTrack.h"
32 extern TGeoManager *gGeoManager;
34 Bool_t AliTracker::fgUniformField=kTRUE;
35 Double_t AliTracker::fgBz=kAlmost0Field;
36 const AliMagF *AliTracker::fgkFieldMap=0;
40 AliTracker::AliTracker():
49 //--------------------------------------------------------------------
50 // The default constructor.
51 //--------------------------------------------------------------------
52 if (!fgkFieldMap) AliWarning("Field map is not set. Call AliTracker::SetFieldMap before creating a tracker!");
55 //__________________________________________________________________________
56 AliTracker::AliTracker(const AliTracker &atr):
65 //--------------------------------------------------------------------
66 // The default constructor.
67 //--------------------------------------------------------------------
68 if (!fgkFieldMap) AliWarning("Field map is not set. Call AliTracker::SetFieldMap before creating a tracker!");
71 //__________________________________________________________________________
72 void AliTracker::SetFieldMap(const AliMagF* map, Bool_t uni) {
73 //--------------------------------------------------------------------
74 //This passes the field map to the reconstruction.
75 //--------------------------------------------------------------------
76 if (map==0) AliFatalClass("Can't access the field map !");
79 AliWarningClass("The magnetic field map has been already set !");
86 //Float_t r[3]={0.,0.,0.},b[3]; map->Field(r,b);
89 Double_t bz=-map->SolenoidField();
90 fgBz=TMath::Sign(kAlmost0Field,bz) + bz;
94 //__________________________________________________________________________
95 void AliTracker::CookLabel(AliKalmanTrack *t, Float_t wrong) const {
96 //--------------------------------------------------------------------
97 //This function "cooks" a track label. If label<0, this track is fake.
98 //--------------------------------------------------------------------
99 Int_t noc=t->GetNumberOfClusters();
100 Int_t *lb=new Int_t[noc];
101 Int_t *mx=new Int_t[noc];
102 AliCluster **clusters=new AliCluster*[noc];
105 for (i=0; i<noc; i++) {
107 Int_t index=t->GetClusterIndex(i);
108 clusters[i]=GetCluster(index);
112 for (i=0; i<noc; i++) {
113 AliCluster *c=clusters[i];
114 lab=TMath::Abs(c->GetLabel(0));
116 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
122 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
124 for (i=0; i<noc; i++) {
125 AliCluster *c=clusters[i];
126 //if (TMath::Abs(c->GetLabel(1)) == lab ||
127 // TMath::Abs(c->GetLabel(2)) == lab ) max++;
128 if (TMath::Abs(c->GetLabel(0)!=lab))
129 if (TMath::Abs(c->GetLabel(1)) == lab ||
130 TMath::Abs(c->GetLabel(2)) == lab ) max++;
133 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
134 t->SetFakeRatio((1.- Float_t(max)/noc));
142 //____________________________________________________________________________
143 void AliTracker::UseClusters(const AliKalmanTrack *t, Int_t from) const {
144 //------------------------------------------------------------------
145 //This function marks clusters associated with the track.
146 //------------------------------------------------------------------
147 Int_t noc=t->GetNumberOfClusters();
148 for (Int_t i=from; i<noc; i++) {
149 Int_t index=t->GetClusterIndex(i);
150 AliCluster *c=GetCluster(index);
155 Double_t AliTracker::GetBz(Float_t *r) {
156 //------------------------------------------------------------------
157 // Returns Bz (kG) at the point "r" .
158 //------------------------------------------------------------------
159 Float_t b[3]; fgkFieldMap->Field(r,b);
160 Double_t bz=-Double_t(b[2]);
161 return (TMath::Sign(kAlmost0Field,bz) + bz);
165 AliTracker::MeanMaterialBudget(Double_t *start,Double_t *end,Double_t *mparam)
168 // Calculate mean material budget and material properties between
169 // the points "start" and "end".
171 // "mparam" - parameters used for the energy and multiple scattering
174 // mparam[0] - mean density: sum(x_i*rho_i)/sum(x_i) [g/cm3]
175 // mparam[1] - equivalent rad length fraction: sum(x_i/X0_i) [adimensional]
176 // mparam[2] - mean A: sum(x_i*A_i)/sum(x_i) [adimensional]
177 // mparam[3] - mean Z: sum(x_i*Z_i)/sum(x_i) [adimensional]
178 // mparam[4] - length: sum(x_i) [cm]
179 // mparam[5] - Z/A mean: sum(x_i*Z_i/A_i)/sum(x_i) [adimensional]
180 // mparam[6] - number of boundary crosses
182 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
184 // Corrections and improvements by
185 // Andrea Dainese, Andrea.Dainese@lnl.infn.it,
186 // Andrei Gheata, Andrei.Gheata@cern.ch
189 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0;
190 mparam[4]=0; mparam[5]=0; mparam[6]=0;
192 Double_t bparam[6]; // total parameters
193 Double_t lparam[6]; // local parameters
195 for (Int_t i=0;i<6;i++) bparam[i]=0;
198 printf("ERROR: no TGeo\n");
204 length = TMath::Sqrt((end[0]-start[0])*(end[0]-start[0])+
205 (end[1]-start[1])*(end[1]-start[1])+
206 (end[2]-start[2])*(end[2]-start[2]));
208 if (length<TGeoShape::Tolerance()) return 0.0;
209 Double_t invlen = 1./length;
210 dir[0] = (end[0]-start[0])*invlen;
211 dir[1] = (end[1]-start[1])*invlen;
212 dir[2] = (end[2]-start[2])*invlen;
214 // Initialize start point and direction
215 TGeoNode *currentnode = 0;
216 TGeoNode *startnode = gGeoManager->InitTrack(start, dir);
217 //printf("%s length=%f\n",gGeoManager->GetPath(),length);
219 printf("ERROR: start point out of geometry\n");
222 TGeoMaterial *material = startnode->GetVolume()->GetMedium()->GetMaterial();
223 lparam[0] = material->GetDensity();
224 lparam[1] = material->GetRadLen();
225 lparam[2] = material->GetA();
226 lparam[3] = material->GetZ();
228 lparam[5] = lparam[3]/lparam[2];
229 if (material->IsMixture()) {
230 TGeoMixture * mixture = (TGeoMixture*)material;
233 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
234 sum += mixture->GetWmixt()[iel];
235 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
240 // Locate next boundary within length without computing safety.
241 // Propagate either with length (if no boundary found) or just cross boundary
242 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
243 Double_t step = 0.0; // Step made
244 Double_t snext = gGeoManager->GetStep();
245 // If no boundary within proposed length, return current density
246 if (!gGeoManager->IsOnBoundary()) {
247 mparam[0] = lparam[0];
248 mparam[1] = lparam[4]/lparam[1];
249 mparam[2] = lparam[2];
250 mparam[3] = lparam[3];
251 mparam[4] = lparam[4];
254 // Try to cross the boundary and see what is next
256 while (length>TGeoShape::Tolerance()) {
257 currentnode = gGeoManager->GetCurrentNode();
258 if (snext<2.*TGeoShape::Tolerance()) nzero++;
261 // This means navigation has problems on one boundary
262 // Try to cross by making a small step
263 printf("ERROR: cannot cross boundary\n");
264 mparam[0] = bparam[0]/step;
265 mparam[1] = bparam[1];
266 mparam[2] = bparam[2]/step;
267 mparam[3] = bparam[3]/step;
268 mparam[5] = bparam[5]/step;
270 mparam[0] = 0.; // if crash of navigation take mean density 0
271 mparam[1] = 1000000; // and infinite rad length
272 return bparam[0]/step;
276 bparam[1] += snext/lparam[1];
277 bparam[2] += snext*lparam[2];
278 bparam[3] += snext*lparam[3];
279 bparam[5] += snext*lparam[5];
280 bparam[0] += snext*lparam[0];
282 if (snext>=length) break;
283 if (!currentnode) break;
285 //printf("%s snext=%f length=%f\n", currentnode->GetName(),snext,length);
286 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
287 lparam[0] = material->GetDensity();
288 lparam[1] = material->GetRadLen();
289 lparam[2] = material->GetA();
290 lparam[3] = material->GetZ();
291 //printf(" %f %f %f %f\n",lparam[0],lparam[1],lparam[2],lparam[3]);
292 lparam[5] = lparam[3]/lparam[2];
293 if (material->IsMixture()) {
294 TGeoMixture * mixture = (TGeoMixture*)material;
297 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
298 sum+= mixture->GetWmixt()[iel];
299 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
303 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
304 snext = gGeoManager->GetStep();
305 //printf("snext %f\n",snext);
307 mparam[0] = bparam[0]/step;
308 mparam[1] = bparam[1];
309 mparam[2] = bparam[2]/step;
310 mparam[3] = bparam[3]/step;
311 mparam[5] = bparam[5]/step;
312 return bparam[0]/step;
317 AliTracker::PropagateTrackTo(AliExternalTrackParam *track, Double_t xToGo,
318 Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp){
319 //----------------------------------------------------------------
321 // Propagates the track to the plane X=xk (cm) using the magnetic field map
322 // and correcting for the crossed material.
324 // mass - mass used in propagation - used for energy loss correction
325 // maxStep - maximal step for propagation
327 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
329 //----------------------------------------------------------------
330 const Double_t kEpsilon = 0.00001;
331 Double_t xpos = track->GetX();
332 Double_t dir = (xpos<xToGo) ? 1.:-1.;
334 while ( (xToGo-xpos)*dir > kEpsilon){
335 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
336 Double_t x = xpos+step;
337 Double_t xyz0[3],xyz1[3],param[7];
338 track->GetXYZ(xyz0); //starting global position
340 Double_t bz=GetBz(xyz0); // getting the local Bz
342 if (!track->GetXYZAt(x,bz,xyz1)) return kFALSE; // no prolongation
343 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
345 if (TMath::Abs(track->GetSnpAt(x,bz)) >= maxSnp) return kFALSE;
346 if (!track->PropagateTo(x,bz)) return kFALSE;
348 MeanMaterialBudget(xyz0,xyz1,param);
349 Double_t xrho=param[0]*param[4], xx0=param[1];
351 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
353 if (TMath::Abs(track->GetSnp()) >= maxSnp) return kFALSE;
354 track->GetXYZ(xyz0); // global position
355 Double_t alphan = TMath::ATan2(xyz0[1], xyz0[0]);
357 Double_t ca=TMath::Cos(alphan-track->GetAlpha()),
358 sa=TMath::Sin(alphan-track->GetAlpha());
359 Double_t sf=track->GetSnp(), cf=TMath::Sqrt(1.- sf*sf);
360 Double_t sinNew = sf*ca - cf*sa;
361 if (TMath::Abs(sinNew) >= maxSnp) return kFALSE;
362 if (!track->Rotate(alphan)) return kFALSE;
364 xpos = track->GetX();