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