]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTracker.cxx
Possibility to store the track parameters reconstructed with TPC only (Marian)
[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>
6e440ee5 25#include <TGeoManager.h>
be9c5115 26
7b5ef2e6 27#include "AliMagF.h"
be9c5115 28#include "AliTracker.h"
c84a5e9e 29#include "AliCluster.h"
7d0f8548 30#include "AliKalmanTrack.h"
41377c29 31
6e440ee5 32extern TGeoManager *gGeoManager;
33
7d0f8548 34Bool_t AliTracker::fgUniformField=kTRUE;
7b5ef2e6 35Double_t AliTracker::fgBz=kAlmost0Field;
3b242889 36const AliMagF *AliTracker::fgkFieldMap=0;
37
be9c5115 38ClassImp(AliTracker)
39
3b242889 40AliTracker::AliTracker():
fe12e09c 41 TObject(),
3b242889 42 fX(0),
43 fY(0),
44 fZ(0),
45 fSigmaX(0.005),
46 fSigmaY(0.005),
47 fSigmaZ(0.010)
48{
49 //--------------------------------------------------------------------
50 // The default constructor.
51 //--------------------------------------------------------------------
c9b9861a 52 if (!fgkFieldMap) AliWarning("Field map is not set. Call AliTracker::SetFieldMap before creating a tracker!");
3b242889 53}
54
fe12e09c 55//__________________________________________________________________________
56AliTracker::AliTracker(const AliTracker &atr):
57 TObject(atr),
58 fX(atr.fX),
59 fY(atr.fY),
60 fZ(atr.fZ),
61 fSigmaX(atr.fSigmaX),
62 fSigmaY(atr.fSigmaY),
63 fSigmaZ(atr.fSigmaZ)
64{
65 //--------------------------------------------------------------------
66 // The default constructor.
67 //--------------------------------------------------------------------
68 if (!fgkFieldMap) AliWarning("Field map is not set. Call AliTracker::SetFieldMap before creating a tracker!");
69}
70
71//__________________________________________________________________________
7d0f8548 72void 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 !");
77
729c2fa2 78 if (fgkFieldMap) {
79 AliWarningClass("The magnetic field map has been already set !");
80 return;
81 }
82
7d0f8548 83 fgUniformField=uni;
84 fgkFieldMap=map;
85
86 //Float_t r[3]={0.,0.,0.},b[3]; map->Field(r,b);
7ebb06c3 87 //Double_t bz=-b[2];
7d0f8548 88
7ebb06c3 89 Double_t bz=-map->SolenoidField();
7b5ef2e6 90 fgBz=TMath::Sign(kAlmost0Field,bz) + bz;
7d0f8548 91
92}
93
be9c5115 94//__________________________________________________________________________
95void 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];
103
104 Int_t i;
105 for (i=0; i<noc; i++) {
106 lb[i]=mx[i]=0;
107 Int_t index=t->GetClusterIndex(i);
108 clusters[i]=GetCluster(index);
109 }
110
111 Int_t lab=123456789;
112 for (i=0; i<noc; i++) {
113 AliCluster *c=clusters[i];
114 lab=TMath::Abs(c->GetLabel(0));
115 Int_t j;
116 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
117 lb[j]=lab;
118 (mx[j])++;
119 }
120
121 Int_t max=0;
122 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
123
124 for (i=0; i<noc; i++) {
125 AliCluster *c=clusters[i];
babd135a 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++;
be9c5115 131 }
132
133 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
babd135a 134 t->SetFakeRatio((1.- Float_t(max)/noc));
be9c5115 135 t->SetLabel(lab);
136
137 delete[] lb;
138 delete[] mx;
139 delete[] clusters;
140}
141
142//____________________________________________________________________________
143void 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);
151 c->Use();
152 }
153}
7b5ef2e6 154
155Double_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);
162}
6e440ee5 163
164Double_t
165AliTracker::MeanMaterialBudget(Double_t *start,Double_t *end,Double_t *mparam)
166{
167 //
168 // Calculate mean material budget and material properties between
169 // the points "start" and "end".
170 //
171 // "mparam" - parameters used for the energy and multiple scattering
172 // corrections:
173 //
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
181 //
182
183 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0;
184 mparam[4]=0; mparam[5]=0; mparam[6]=0;
185 //
186 Double_t bparam[6]; // total parameters
187 Double_t lparam[6]; // local parameters
188
189 for (Int_t i=0;i<6;i++) bparam[i]=0;
190
191 if (!gGeoManager) {
192 printf("ERROR: no TGeo\n");
193 return 0.;
194 }
195 //
196 Double_t length;
197 Double_t dir[3];
198 length = TMath::Sqrt((end[0]-start[0])*(end[0]-start[0])+
199 (end[1]-start[1])*(end[1]-start[1])+
200 (end[2]-start[2])*(end[2]-start[2]));
201 mparam[4]=length;
202 if (length<TGeoShape::Tolerance()) return 0.0;
203 Double_t invlen = 1./length;
204 dir[0] = (end[0]-start[0])*invlen;
205 dir[1] = (end[1]-start[1])*invlen;
206 dir[2] = (end[2]-start[2])*invlen;
207
208 // Initialize start point and direction
209 TGeoNode *currentnode = 0;
210 TGeoNode *startnode = gGeoManager->InitTrack(start, dir);
211 //printf("%s length=%f\n",gGeoManager->GetPath(),length);
212 if (!startnode) {
213 printf("ERROR: start point out of geometry\n");
214 return 0.0;
215 }
216 TGeoMaterial *material = startnode->GetVolume()->GetMedium()->GetMaterial();
217 lparam[0] = material->GetDensity();
218 lparam[1] = material->GetRadLen();
219 lparam[2] = material->GetA();
220 lparam[3] = material->GetZ();
221 lparam[4] = length;
222 lparam[5] = lparam[3]/lparam[2];
223 if (material->IsMixture()) {
224 TGeoMixture * mixture = (TGeoMixture*)material;
225 lparam[5] =0;
226 Double_t sum =0;
227 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
228 sum += mixture->GetWmixt()[iel];
229 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
230 }
231 lparam[5]/=sum;
232 }
233
234 // Locate next boundary within length without computing safety.
235 // Propagate either with length (if no boundary found) or just cross boundary
236 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
237 Double_t step = 0.0; // Step made
238 Double_t snext = gGeoManager->GetStep();
239 // If no boundary within proposed length, return current density
240 if (!gGeoManager->IsOnBoundary()) {
241 mparam[0] = lparam[0];
242 mparam[1] = lparam[4]/lparam[1];
243 mparam[2] = lparam[2];
244 mparam[3] = lparam[3];
245 mparam[4] = lparam[4];
246 return lparam[0];
247 }
248 // Try to cross the boundary and see what is next
249 Int_t nzero = 0;
250 while (length>TGeoShape::Tolerance()) {
251 currentnode = gGeoManager->GetCurrentNode();
252 if (snext<2.*TGeoShape::Tolerance()) nzero++;
253 else nzero = 0;
254 if (nzero>3) {
255 // This means navigation has problems on one boundary
256 // Try to cross by making a small step
257 printf("ERROR: cannot cross boundary\n");
258 mparam[0] = bparam[0]/step;
259 mparam[1] = bparam[1];
260 mparam[2] = bparam[2]/step;
261 mparam[3] = bparam[3]/step;
262 mparam[5] = bparam[5]/step;
263 mparam[4] = step;
264 mparam[0] = 0.; // if crash of navigation take mean density 0
265 mparam[1] = 1000000; // and infinite rad length
266 return bparam[0]/step;
267 }
268 mparam[6]+=1.;
269 step += snext;
270 bparam[1] += snext/lparam[1];
271 bparam[2] += snext*lparam[2];
272 bparam[3] += snext*lparam[3];
273 bparam[5] += snext*lparam[5];
274 bparam[0] += snext*lparam[0];
275
276 if (snext>=length) break;
277 if (!currentnode) break;
278 length -= snext;
279 //printf("%s snext=%f length=%f\n", currentnode->GetName(),snext,length);
280 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
281 lparam[0] = material->GetDensity();
282 lparam[1] = material->GetRadLen();
283 lparam[2] = material->GetA();
284 lparam[3] = material->GetZ();
285 //printf(" %f %f %f %f\n",lparam[0],lparam[1],lparam[2],lparam[3]);
286 lparam[5] = lparam[3]/lparam[2];
287 if (material->IsMixture()) {
288 TGeoMixture * mixture = (TGeoMixture*)material;
289 lparam[5]=0;
290 Double_t sum =0;
291 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
292 sum+= mixture->GetWmixt()[iel];
293 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
294 }
295 lparam[5]/=sum;
296 }
297 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
298 snext = gGeoManager->GetStep();
299 //printf("snext %f\n",snext);
300 }
301 mparam[0] = bparam[0]/step;
302 mparam[1] = bparam[1];
303 mparam[2] = bparam[2]/step;
304 mparam[3] = bparam[3]/step;
305 mparam[5] = bparam[5]/step;
306 return bparam[0]/step;
307}