]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTracker.cxx
Moved old AliMagFCheb to AliMagF, small fixes/optimizations in field classes
[u/mrichter/AliRoot.git] / STEER / AliTracker.cxx
CommitLineData
be9c5115 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 **************************************************************************/
15
acd84897 16/* $Id$ */
fb17acd4 17
be9c5115 18//-------------------------------------------------------------------------
19// Implementation of the AliTracker class
9b83b8cc 20// that is the base for AliTPCtracker, AliITStrackerV2 and AliTRDtracker
21// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
be9c5115 22//-------------------------------------------------------------------------
7d0f8548 23#include <TClass.h>
be9c5115 24#include <TMath.h>
e23a38cb 25#include <TH1F.h>
6e440ee5 26#include <TGeoManager.h>
9efabefd 27#include <TGeoMatrix.h>
be9c5115 28
7b5ef2e6 29#include "AliMagF.h"
be9c5115 30#include "AliTracker.h"
e23a38cb 31#include "AliGeomManager.h"
c84a5e9e 32#include "AliCluster.h"
7d0f8548 33#include "AliKalmanTrack.h"
41377c29 34
6e440ee5 35extern TGeoManager *gGeoManager;
36
7d0f8548 37Bool_t AliTracker::fgUniformField=kTRUE;
7b5ef2e6 38Double_t AliTracker::fgBz=kAlmost0Field;
3b242889 39const AliMagF *AliTracker::fgkFieldMap=0;
e23a38cb 40Bool_t AliTracker::fFillResiduals=kFALSE;
57acd2d2 41TObjArray **AliTracker::fResiduals=NULL;
42AliRecoParam::EventSpecie_t AliTracker::fEventSpecie=AliRecoParam::kDefault;
3b242889 43
be9c5115 44ClassImp(AliTracker)
45
3b242889 46AliTracker::AliTracker():
fe12e09c 47 TObject(),
3b242889 48 fX(0),
49 fY(0),
50 fZ(0),
51 fSigmaX(0.005),
52 fSigmaY(0.005),
57acd2d2 53 fSigmaZ(0.010)
3b242889 54{
55 //--------------------------------------------------------------------
56 // The default constructor.
57 //--------------------------------------------------------------------
c9b9861a 58 if (!fgkFieldMap) AliWarning("Field map is not set. Call AliTracker::SetFieldMap before creating a tracker!");
3b242889 59}
60
fe12e09c 61//__________________________________________________________________________
62AliTracker::AliTracker(const AliTracker &atr):
63 TObject(atr),
64 fX(atr.fX),
65 fY(atr.fY),
66 fZ(atr.fZ),
67 fSigmaX(atr.fSigmaX),
68 fSigmaY(atr.fSigmaY),
69 fSigmaZ(atr.fSigmaZ)
70{
71 //--------------------------------------------------------------------
72 // The default constructor.
73 //--------------------------------------------------------------------
74 if (!fgkFieldMap) AliWarning("Field map is not set. Call AliTracker::SetFieldMap before creating a tracker!");
75}
76
77//__________________________________________________________________________
7d0f8548 78void AliTracker::SetFieldMap(const AliMagF* map, Bool_t uni) {
79 //--------------------------------------------------------------------
80 //This passes the field map to the reconstruction.
81 //--------------------------------------------------------------------
82 if (map==0) AliFatalClass("Can't access the field map !");
83
729c2fa2 84 if (fgkFieldMap) {
85 AliWarningClass("The magnetic field map has been already set !");
86 return;
87 }
88
7d0f8548 89 fgUniformField=uni;
90 fgkFieldMap=map;
91
92 //Float_t r[3]={0.,0.,0.},b[3]; map->Field(r,b);
7ebb06c3 93 //Double_t bz=-b[2];
7d0f8548 94
7ebb06c3 95 Double_t bz=-map->SolenoidField();
7b5ef2e6 96 fgBz=TMath::Sign(kAlmost0Field,bz) + bz;
7d0f8548 97
98}
99
2f4c86d7 100//__________________________________________________________________________
101void AliTracker::FillClusterArray(TObjArray* /*array*/) const
102{
103 // Publishes all pointers to clusters known to the tracker into the
104 // passed object array.
105 // The ownership is not transfered - the caller is not expected to delete
106 // the clusters.
107
108 AliWarning("should be overriden by a sub-class.");
109}
110
be9c5115 111//__________________________________________________________________________
112void AliTracker::CookLabel(AliKalmanTrack *t, Float_t wrong) const {
113 //--------------------------------------------------------------------
114 //This function "cooks" a track label. If label<0, this track is fake.
115 //--------------------------------------------------------------------
116 Int_t noc=t->GetNumberOfClusters();
9b4aca55 117 if (noc<1) return;
be9c5115 118 Int_t *lb=new Int_t[noc];
119 Int_t *mx=new Int_t[noc];
120 AliCluster **clusters=new AliCluster*[noc];
121
122 Int_t i;
123 for (i=0; i<noc; i++) {
124 lb[i]=mx[i]=0;
125 Int_t index=t->GetClusterIndex(i);
126 clusters[i]=GetCluster(index);
127 }
128
129 Int_t lab=123456789;
130 for (i=0; i<noc; i++) {
131 AliCluster *c=clusters[i];
132 lab=TMath::Abs(c->GetLabel(0));
133 Int_t j;
134 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
135 lb[j]=lab;
136 (mx[j])++;
137 }
138
139 Int_t max=0;
140 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
141
142 for (i=0; i<noc; i++) {
143 AliCluster *c=clusters[i];
babd135a 144 //if (TMath::Abs(c->GetLabel(1)) == lab ||
145 // TMath::Abs(c->GetLabel(2)) == lab ) max++;
146 if (TMath::Abs(c->GetLabel(0)!=lab))
147 if (TMath::Abs(c->GetLabel(1)) == lab ||
148 TMath::Abs(c->GetLabel(2)) == lab ) max++;
be9c5115 149 }
150
151 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
babd135a 152 t->SetFakeRatio((1.- Float_t(max)/noc));
be9c5115 153 t->SetLabel(lab);
154
155 delete[] lb;
156 delete[] mx;
157 delete[] clusters;
158}
159
160//____________________________________________________________________________
161void AliTracker::UseClusters(const AliKalmanTrack *t, Int_t from) const {
162 //------------------------------------------------------------------
163 //This function marks clusters associated with the track.
164 //------------------------------------------------------------------
165 Int_t noc=t->GetNumberOfClusters();
166 for (Int_t i=from; i<noc; i++) {
167 Int_t index=t->GetClusterIndex(i);
168 AliCluster *c=GetCluster(index);
169 c->Use();
170 }
171}
7b5ef2e6 172
cb5b8b21 173Double_t AliTracker::GetBz(const Float_t *r) {
7b5ef2e6 174 //------------------------------------------------------------------
175 // Returns Bz (kG) at the point "r" .
176 //------------------------------------------------------------------
177 Float_t b[3]; fgkFieldMap->Field(r,b);
178 Double_t bz=-Double_t(b[2]);
179 return (TMath::Sign(kAlmost0Field,bz) + bz);
180}
6e440ee5 181
182Double_t
6b3a4c8e 183AliTracker::MeanMaterialBudget(const Double_t *start, const Double_t *end, Double_t *mparam)
6e440ee5 184{
185 //
186 // Calculate mean material budget and material properties between
187 // the points "start" and "end".
188 //
189 // "mparam" - parameters used for the energy and multiple scattering
190 // corrections:
191 //
192 // mparam[0] - mean density: sum(x_i*rho_i)/sum(x_i) [g/cm3]
193 // mparam[1] - equivalent rad length fraction: sum(x_i/X0_i) [adimensional]
194 // mparam[2] - mean A: sum(x_i*A_i)/sum(x_i) [adimensional]
195 // mparam[3] - mean Z: sum(x_i*Z_i)/sum(x_i) [adimensional]
196 // mparam[4] - length: sum(x_i) [cm]
197 // mparam[5] - Z/A mean: sum(x_i*Z_i/A_i)/sum(x_i) [adimensional]
198 // mparam[6] - number of boundary crosses
199 //
0c4ea33b 200 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
201 //
202 // Corrections and improvements by
203 // Andrea Dainese, Andrea.Dainese@lnl.infn.it,
204 // Andrei Gheata, Andrei.Gheata@cern.ch
205 //
6e440ee5 206
207 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0;
208 mparam[4]=0; mparam[5]=0; mparam[6]=0;
209 //
210 Double_t bparam[6]; // total parameters
211 Double_t lparam[6]; // local parameters
212
213 for (Int_t i=0;i<6;i++) bparam[i]=0;
214
215 if (!gGeoManager) {
216 printf("ERROR: no TGeo\n");
217 return 0.;
218 }
219 //
220 Double_t length;
221 Double_t dir[3];
222 length = TMath::Sqrt((end[0]-start[0])*(end[0]-start[0])+
223 (end[1]-start[1])*(end[1]-start[1])+
224 (end[2]-start[2])*(end[2]-start[2]));
225 mparam[4]=length;
226 if (length<TGeoShape::Tolerance()) return 0.0;
227 Double_t invlen = 1./length;
228 dir[0] = (end[0]-start[0])*invlen;
229 dir[1] = (end[1]-start[1])*invlen;
230 dir[2] = (end[2]-start[2])*invlen;
231
232 // Initialize start point and direction
233 TGeoNode *currentnode = 0;
234 TGeoNode *startnode = gGeoManager->InitTrack(start, dir);
235 //printf("%s length=%f\n",gGeoManager->GetPath(),length);
236 if (!startnode) {
f3b4b060 237 AliErrorClass(Form("start point out of geometry: x %f, y %f, z %f",
ff0051ed 238 start[0],start[1],start[2]));
6e440ee5 239 return 0.0;
240 }
241 TGeoMaterial *material = startnode->GetVolume()->GetMedium()->GetMaterial();
242 lparam[0] = material->GetDensity();
243 lparam[1] = material->GetRadLen();
244 lparam[2] = material->GetA();
245 lparam[3] = material->GetZ();
246 lparam[4] = length;
247 lparam[5] = lparam[3]/lparam[2];
248 if (material->IsMixture()) {
249 TGeoMixture * mixture = (TGeoMixture*)material;
250 lparam[5] =0;
251 Double_t sum =0;
252 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
253 sum += mixture->GetWmixt()[iel];
254 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
255 }
256 lparam[5]/=sum;
257 }
258
259 // Locate next boundary within length without computing safety.
260 // Propagate either with length (if no boundary found) or just cross boundary
261 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
262 Double_t step = 0.0; // Step made
263 Double_t snext = gGeoManager->GetStep();
264 // If no boundary within proposed length, return current density
265 if (!gGeoManager->IsOnBoundary()) {
266 mparam[0] = lparam[0];
267 mparam[1] = lparam[4]/lparam[1];
268 mparam[2] = lparam[2];
269 mparam[3] = lparam[3];
270 mparam[4] = lparam[4];
271 return lparam[0];
272 }
273 // Try to cross the boundary and see what is next
274 Int_t nzero = 0;
275 while (length>TGeoShape::Tolerance()) {
276 currentnode = gGeoManager->GetCurrentNode();
277 if (snext<2.*TGeoShape::Tolerance()) nzero++;
278 else nzero = 0;
279 if (nzero>3) {
280 // This means navigation has problems on one boundary
281 // Try to cross by making a small step
282 printf("ERROR: cannot cross boundary\n");
283 mparam[0] = bparam[0]/step;
284 mparam[1] = bparam[1];
285 mparam[2] = bparam[2]/step;
286 mparam[3] = bparam[3]/step;
287 mparam[5] = bparam[5]/step;
288 mparam[4] = step;
289 mparam[0] = 0.; // if crash of navigation take mean density 0
290 mparam[1] = 1000000; // and infinite rad length
291 return bparam[0]/step;
292 }
293 mparam[6]+=1.;
294 step += snext;
295 bparam[1] += snext/lparam[1];
296 bparam[2] += snext*lparam[2];
297 bparam[3] += snext*lparam[3];
298 bparam[5] += snext*lparam[5];
299 bparam[0] += snext*lparam[0];
300
301 if (snext>=length) break;
302 if (!currentnode) break;
303 length -= snext;
304 //printf("%s snext=%f length=%f\n", currentnode->GetName(),snext,length);
305 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
306 lparam[0] = material->GetDensity();
307 lparam[1] = material->GetRadLen();
308 lparam[2] = material->GetA();
309 lparam[3] = material->GetZ();
310 //printf(" %f %f %f %f\n",lparam[0],lparam[1],lparam[2],lparam[3]);
311 lparam[5] = lparam[3]/lparam[2];
312 if (material->IsMixture()) {
313 TGeoMixture * mixture = (TGeoMixture*)material;
314 lparam[5]=0;
315 Double_t sum =0;
316 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
317 sum+= mixture->GetWmixt()[iel];
318 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
319 }
320 lparam[5]/=sum;
321 }
322 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
323 snext = gGeoManager->GetStep();
324 //printf("snext %f\n",snext);
325 }
326 mparam[0] = bparam[0]/step;
327 mparam[1] = bparam[1];
328 mparam[2] = bparam[2]/step;
329 mparam[3] = bparam[3]/step;
330 mparam[5] = bparam[5]/step;
331 return bparam[0]/step;
332}
0c4ea33b 333
334
335Bool_t
336AliTracker::PropagateTrackTo(AliExternalTrackParam *track, Double_t xToGo,
337Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp){
338 //----------------------------------------------------------------
339 //
340 // Propagates the track to the plane X=xk (cm) using the magnetic field map
341 // and correcting for the crossed material.
342 //
343 // mass - mass used in propagation - used for energy loss correction
344 // maxStep - maximal step for propagation
345 //
346 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
347 //
348 //----------------------------------------------------------------
349 const Double_t kEpsilon = 0.00001;
350 Double_t xpos = track->GetX();
351 Double_t dir = (xpos<xToGo) ? 1.:-1.;
352 //
353 while ( (xToGo-xpos)*dir > kEpsilon){
354 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
355 Double_t x = xpos+step;
356 Double_t xyz0[3],xyz1[3],param[7];
357 track->GetXYZ(xyz0); //starting global position
358
359 Double_t bz=GetBz(xyz0); // getting the local Bz
360
361 if (!track->GetXYZAt(x,bz,xyz1)) return kFALSE; // no prolongation
362 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
363
364 if (TMath::Abs(track->GetSnpAt(x,bz)) >= maxSnp) return kFALSE;
365 if (!track->PropagateTo(x,bz)) return kFALSE;
366
367 MeanMaterialBudget(xyz0,xyz1,param);
368 Double_t xrho=param[0]*param[4], xx0=param[1];
369
370 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
371 if (rotateTo){
372 if (TMath::Abs(track->GetSnp()) >= maxSnp) return kFALSE;
373 track->GetXYZ(xyz0); // global position
374 Double_t alphan = TMath::ATan2(xyz0[1], xyz0[0]);
375 //
376 Double_t ca=TMath::Cos(alphan-track->GetAlpha()),
377 sa=TMath::Sin(alphan-track->GetAlpha());
378 Double_t sf=track->GetSnp(), cf=TMath::Sqrt(1.- sf*sf);
379 Double_t sinNew = sf*ca - cf*sa;
380 if (TMath::Abs(sinNew) >= maxSnp) return kFALSE;
381 if (!track->Rotate(alphan)) return kFALSE;
382 }
383 xpos = track->GetX();
384 }
385 return kTRUE;
386}
387
e23a38cb 388void AliTracker::FillResiduals(const AliExternalTrackParam *t,
389 Double_t *p, Double_t *cov,
390 UShort_t id, Bool_t updated) {
391 //
392 // This function fills the histograms of residuals
393 // The array of these histos is external for this AliTracker class.
394 // Normally, this array belong to AliGlobalQADataMaker class.
395 //
396 if (!fFillResiduals) return;
397 if (!fResiduals) return;
398
399 const Double_t *residuals=t->GetResiduals(p,cov,updated);
400 if (!residuals) return;
401
402 TH1F *h=0;
403 AliGeomManager::ELayerID layer=AliGeomManager::VolUIDToLayer(id);
57acd2d2 404 h=(TH1F*)fResiduals[fEventSpecie]->At(2*layer-2);
e23a38cb 405 h->Fill(residuals[0]);
57acd2d2 406 h=(TH1F*)fResiduals[fEventSpecie]->At(2*layer-1);
e23a38cb 407 h->Fill(residuals[1]);
a935c6c0 408
409 if (layer==5) {
49ab451d 410 if (p[1]<0) { // SSD1 absolute residuals
57acd2d2 411 ((TH1F*)fResiduals[fEventSpecie]->At(40))->Fill(t->GetY()-p[0]); //C side
412 ((TH1F*)fResiduals[fEventSpecie]->At(41))->Fill(t->GetZ()-p[1]);
49ab451d 413 } else {
57acd2d2 414 ((TH1F*)fResiduals[fEventSpecie]->At(42))->Fill(t->GetY()-p[0]); //A side
415 ((TH1F*)fResiduals[fEventSpecie]->At(43))->Fill(t->GetZ()-p[1]);
49ab451d 416 }
a935c6c0 417 }
49ab451d 418 if (layer==6) { // SSD2 absolute residuals
419 if (p[1]<0) {
57acd2d2 420 ((TH1F*)fResiduals[fEventSpecie]->At(44))->Fill(t->GetY()-p[0]); //C side
421 ((TH1F*)fResiduals[fEventSpecie]->At(45))->Fill(t->GetZ()-p[1]);
49ab451d 422 } else {
57acd2d2 423 ((TH1F*)fResiduals[fEventSpecie]->At(46))->Fill(t->GetY()-p[0]); //A side
424 ((TH1F*)fResiduals[fEventSpecie]->At(47))->Fill(t->GetZ()-p[1]);
49ab451d 425 }
a935c6c0 426 }
427
e23a38cb 428}
429
9efabefd 430void AliTracker::FillResiduals(const AliExternalTrackParam *t,
431 const AliCluster *c, Bool_t /*updated*/) {
432 //
433 // This function fills the histograms of residuals
434 // The array of these histos is external for this AliTracker class.
435 // Normally, this array belong to AliGlobalQADataMaker class.
436 //
437 // For the moment, the residuals are absolute !
438 //
439
440 if (!fFillResiduals) return;
441 if (!fResiduals) return;
442
443 UShort_t id=c->GetVolumeId();
444 const TGeoHMatrix *matrixT2L=AliGeomManager::GetTracking2LocalMatrix(id);
445
446 // Position of the cluster in the tracking c.s.
447 Double_t clsTrk[3]={c->GetX(), c->GetY(), c->GetZ()};
448 // Position of the cluster in the local module c.s.
449 Double_t clsLoc[3]={0.,0.,0.};
450 matrixT2L->LocalToMaster(clsTrk,clsLoc);
451
452
453 // Position of the intersection point in the tracking c.s.
454 Double_t trkTrk[3]={t->GetX(),t->GetY(),t->GetZ()};
455 // Position of the intersection point in the local module c.s.
456 Double_t trkLoc[3]={0.,0.,0.};
457 matrixT2L->LocalToMaster(trkTrk,trkLoc);
458
459 Double_t residuals[2]={trkLoc[0]-clsLoc[0], trkLoc[2]-clsLoc[2]};
460
461 TH1F *h=0;
462 AliGeomManager::ELayerID layer=AliGeomManager::VolUIDToLayer(id);
463 h=(TH1F*)fResiduals[fEventSpecie]->At(2*layer-2);
464 h->Fill(residuals[0]);
465 h=(TH1F*)fResiduals[fEventSpecie]->At(2*layer-1);
466 h->Fill(residuals[1]);
467
468}