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>
29 #include "AliTracker.h"
30 #include "AliGeomManager.h"
31 #include "AliCluster.h"
32 #include "AliKalmanTrack.h"
34 extern TGeoManager *gGeoManager;
36 Bool_t AliTracker::fgUniformField=kTRUE;
37 Double_t AliTracker::fgBz=kAlmost0Field;
38 const AliMagF *AliTracker::fgkFieldMap=0;
39 Bool_t AliTracker::fFillResiduals=kFALSE;
40 TObjArray **AliTracker::fResiduals=NULL;
41 AliRecoParam::EventSpecie_t AliTracker::fEventSpecie=AliRecoParam::kDefault;
45 AliTracker::AliTracker():
54 //--------------------------------------------------------------------
55 // The default constructor.
56 //--------------------------------------------------------------------
57 if (!fgkFieldMap) AliWarning("Field map is not set. Call AliTracker::SetFieldMap before creating a tracker!");
60 //__________________________________________________________________________
61 AliTracker::AliTracker(const AliTracker &atr):
70 //--------------------------------------------------------------------
71 // The default constructor.
72 //--------------------------------------------------------------------
73 if (!fgkFieldMap) AliWarning("Field map is not set. Call AliTracker::SetFieldMap before creating a tracker!");
76 //__________________________________________________________________________
77 void AliTracker::SetFieldMap(const AliMagF* map, Bool_t uni) {
78 //--------------------------------------------------------------------
79 //This passes the field map to the reconstruction.
80 //--------------------------------------------------------------------
81 if (map==0) AliFatalClass("Can't access the field map !");
84 AliWarningClass("The magnetic field map has been already set !");
91 //Float_t r[3]={0.,0.,0.},b[3]; map->Field(r,b);
94 Double_t bz=-map->SolenoidField();
95 fgBz=TMath::Sign(kAlmost0Field,bz) + bz;
99 //__________________________________________________________________________
100 void AliTracker::FillClusterArray(TObjArray* /*array*/) const
102 // Publishes all pointers to clusters known to the tracker into the
103 // passed object array.
104 // The ownership is not transfered - the caller is not expected to delete
107 AliWarning("should be overriden by a sub-class.");
110 //__________________________________________________________________________
111 void AliTracker::CookLabel(AliKalmanTrack *t, Float_t wrong) const {
112 //--------------------------------------------------------------------
113 //This function "cooks" a track label. If label<0, this track is fake.
114 //--------------------------------------------------------------------
115 Int_t noc=t->GetNumberOfClusters();
117 Int_t *lb=new Int_t[noc];
118 Int_t *mx=new Int_t[noc];
119 AliCluster **clusters=new AliCluster*[noc];
122 for (i=0; i<noc; i++) {
124 Int_t index=t->GetClusterIndex(i);
125 clusters[i]=GetCluster(index);
129 for (i=0; i<noc; i++) {
130 AliCluster *c=clusters[i];
131 lab=TMath::Abs(c->GetLabel(0));
133 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
139 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
141 for (i=0; i<noc; i++) {
142 AliCluster *c=clusters[i];
143 //if (TMath::Abs(c->GetLabel(1)) == lab ||
144 // TMath::Abs(c->GetLabel(2)) == lab ) max++;
145 if (TMath::Abs(c->GetLabel(0)!=lab))
146 if (TMath::Abs(c->GetLabel(1)) == lab ||
147 TMath::Abs(c->GetLabel(2)) == lab ) max++;
150 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
151 t->SetFakeRatio((1.- Float_t(max)/noc));
159 //____________________________________________________________________________
160 void AliTracker::UseClusters(const AliKalmanTrack *t, Int_t from) const {
161 //------------------------------------------------------------------
162 //This function marks clusters associated with the track.
163 //------------------------------------------------------------------
164 Int_t noc=t->GetNumberOfClusters();
165 for (Int_t i=from; i<noc; i++) {
166 Int_t index=t->GetClusterIndex(i);
167 AliCluster *c=GetCluster(index);
172 Double_t AliTracker::GetBz(const Float_t *r) {
173 //------------------------------------------------------------------
174 // Returns Bz (kG) at the point "r" .
175 //------------------------------------------------------------------
176 Float_t b[3]; fgkFieldMap->Field(r,b);
177 Double_t bz=-Double_t(b[2]);
178 return (TMath::Sign(kAlmost0Field,bz) + bz);
182 AliTracker::MeanMaterialBudget(const Double_t *start, const Double_t *end, Double_t *mparam)
185 // Calculate mean material budget and material properties between
186 // the points "start" and "end".
188 // "mparam" - parameters used for the energy and multiple scattering
191 // mparam[0] - mean density: sum(x_i*rho_i)/sum(x_i) [g/cm3]
192 // mparam[1] - equivalent rad length fraction: sum(x_i/X0_i) [adimensional]
193 // mparam[2] - mean A: sum(x_i*A_i)/sum(x_i) [adimensional]
194 // mparam[3] - mean Z: sum(x_i*Z_i)/sum(x_i) [adimensional]
195 // mparam[4] - length: sum(x_i) [cm]
196 // mparam[5] - Z/A mean: sum(x_i*Z_i/A_i)/sum(x_i) [adimensional]
197 // mparam[6] - number of boundary crosses
199 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
201 // Corrections and improvements by
202 // Andrea Dainese, Andrea.Dainese@lnl.infn.it,
203 // Andrei Gheata, Andrei.Gheata@cern.ch
206 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0;
207 mparam[4]=0; mparam[5]=0; mparam[6]=0;
209 Double_t bparam[6]; // total parameters
210 Double_t lparam[6]; // local parameters
212 for (Int_t i=0;i<6;i++) bparam[i]=0;
215 printf("ERROR: no TGeo\n");
221 length = TMath::Sqrt((end[0]-start[0])*(end[0]-start[0])+
222 (end[1]-start[1])*(end[1]-start[1])+
223 (end[2]-start[2])*(end[2]-start[2]));
225 if (length<TGeoShape::Tolerance()) return 0.0;
226 Double_t invlen = 1./length;
227 dir[0] = (end[0]-start[0])*invlen;
228 dir[1] = (end[1]-start[1])*invlen;
229 dir[2] = (end[2]-start[2])*invlen;
231 // Initialize start point and direction
232 TGeoNode *currentnode = 0;
233 TGeoNode *startnode = gGeoManager->InitTrack(start, dir);
234 //printf("%s length=%f\n",gGeoManager->GetPath(),length);
236 AliErrorClass(Form("start point out of geometry: x %f, y %f, z %f",
237 start[0],start[1],start[2]));
240 TGeoMaterial *material = startnode->GetVolume()->GetMedium()->GetMaterial();
241 lparam[0] = material->GetDensity();
242 lparam[1] = material->GetRadLen();
243 lparam[2] = material->GetA();
244 lparam[3] = material->GetZ();
246 lparam[5] = lparam[3]/lparam[2];
247 if (material->IsMixture()) {
248 TGeoMixture * mixture = (TGeoMixture*)material;
251 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
252 sum += mixture->GetWmixt()[iel];
253 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
258 // Locate next boundary within length without computing safety.
259 // Propagate either with length (if no boundary found) or just cross boundary
260 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
261 Double_t step = 0.0; // Step made
262 Double_t snext = gGeoManager->GetStep();
263 // If no boundary within proposed length, return current density
264 if (!gGeoManager->IsOnBoundary()) {
265 mparam[0] = lparam[0];
266 mparam[1] = lparam[4]/lparam[1];
267 mparam[2] = lparam[2];
268 mparam[3] = lparam[3];
269 mparam[4] = lparam[4];
272 // Try to cross the boundary and see what is next
274 while (length>TGeoShape::Tolerance()) {
275 currentnode = gGeoManager->GetCurrentNode();
276 if (snext<2.*TGeoShape::Tolerance()) nzero++;
279 // This means navigation has problems on one boundary
280 // Try to cross by making a small step
281 printf("ERROR: cannot cross boundary\n");
282 mparam[0] = bparam[0]/step;
283 mparam[1] = bparam[1];
284 mparam[2] = bparam[2]/step;
285 mparam[3] = bparam[3]/step;
286 mparam[5] = bparam[5]/step;
288 mparam[0] = 0.; // if crash of navigation take mean density 0
289 mparam[1] = 1000000; // and infinite rad length
290 return bparam[0]/step;
294 bparam[1] += snext/lparam[1];
295 bparam[2] += snext*lparam[2];
296 bparam[3] += snext*lparam[3];
297 bparam[5] += snext*lparam[5];
298 bparam[0] += snext*lparam[0];
300 if (snext>=length) break;
301 if (!currentnode) break;
303 //printf("%s snext=%f length=%f\n", currentnode->GetName(),snext,length);
304 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
305 lparam[0] = material->GetDensity();
306 lparam[1] = material->GetRadLen();
307 lparam[2] = material->GetA();
308 lparam[3] = material->GetZ();
309 //printf(" %f %f %f %f\n",lparam[0],lparam[1],lparam[2],lparam[3]);
310 lparam[5] = lparam[3]/lparam[2];
311 if (material->IsMixture()) {
312 TGeoMixture * mixture = (TGeoMixture*)material;
315 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
316 sum+= mixture->GetWmixt()[iel];
317 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
321 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
322 snext = gGeoManager->GetStep();
323 //printf("snext %f\n",snext);
325 mparam[0] = bparam[0]/step;
326 mparam[1] = bparam[1];
327 mparam[2] = bparam[2]/step;
328 mparam[3] = bparam[3]/step;
329 mparam[5] = bparam[5]/step;
330 return bparam[0]/step;
335 AliTracker::PropagateTrackTo(AliExternalTrackParam *track, Double_t xToGo,
336 Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp){
337 //----------------------------------------------------------------
339 // Propagates the track to the plane X=xk (cm) using the magnetic field map
340 // and correcting for the crossed material.
342 // mass - mass used in propagation - used for energy loss correction
343 // maxStep - maximal step for propagation
345 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
347 //----------------------------------------------------------------
348 const Double_t kEpsilon = 0.00001;
349 Double_t xpos = track->GetX();
350 Double_t dir = (xpos<xToGo) ? 1.:-1.;
352 while ( (xToGo-xpos)*dir > kEpsilon){
353 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
354 Double_t x = xpos+step;
355 Double_t xyz0[3],xyz1[3],param[7];
356 track->GetXYZ(xyz0); //starting global position
358 Double_t bz=GetBz(xyz0); // getting the local Bz
360 if (!track->GetXYZAt(x,bz,xyz1)) return kFALSE; // no prolongation
361 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
363 if (TMath::Abs(track->GetSnpAt(x,bz)) >= maxSnp) return kFALSE;
364 if (!track->PropagateTo(x,bz)) return kFALSE;
366 MeanMaterialBudget(xyz0,xyz1,param);
367 Double_t xrho=param[0]*param[4], xx0=param[1];
369 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
371 if (TMath::Abs(track->GetSnp()) >= maxSnp) return kFALSE;
372 track->GetXYZ(xyz0); // global position
373 Double_t alphan = TMath::ATan2(xyz0[1], xyz0[0]);
375 Double_t ca=TMath::Cos(alphan-track->GetAlpha()),
376 sa=TMath::Sin(alphan-track->GetAlpha());
377 Double_t sf=track->GetSnp(), cf=TMath::Sqrt(1.- sf*sf);
378 Double_t sinNew = sf*ca - cf*sa;
379 if (TMath::Abs(sinNew) >= maxSnp) return kFALSE;
380 if (!track->Rotate(alphan)) return kFALSE;
382 xpos = track->GetX();
387 void AliTracker::FillResiduals(const AliExternalTrackParam *t,
388 Double_t *p, Double_t *cov,
389 UShort_t id, Bool_t updated) {
391 // This function fills the histograms of residuals
392 // The array of these histos is external for this AliTracker class.
393 // Normally, this array belong to AliGlobalQADataMaker class.
395 if (!fFillResiduals) return;
396 if (!fResiduals) return;
398 const Double_t *residuals=t->GetResiduals(p,cov,updated);
399 if (!residuals) return;
402 AliGeomManager::ELayerID layer=AliGeomManager::VolUIDToLayer(id);
403 h=(TH1F*)fResiduals[fEventSpecie]->At(2*layer-2);
404 h->Fill(residuals[0]);
405 h=(TH1F*)fResiduals[fEventSpecie]->At(2*layer-1);
406 h->Fill(residuals[1]);
409 if (p[1]<0) { // SSD1 absolute residuals
410 ((TH1F*)fResiduals[fEventSpecie]->At(40))->Fill(t->GetY()-p[0]); //C side
411 ((TH1F*)fResiduals[fEventSpecie]->At(41))->Fill(t->GetZ()-p[1]);
413 ((TH1F*)fResiduals[fEventSpecie]->At(42))->Fill(t->GetY()-p[0]); //A side
414 ((TH1F*)fResiduals[fEventSpecie]->At(43))->Fill(t->GetZ()-p[1]);
417 if (layer==6) { // SSD2 absolute residuals
419 ((TH1F*)fResiduals[fEventSpecie]->At(44))->Fill(t->GetY()-p[0]); //C side
420 ((TH1F*)fResiduals[fEventSpecie]->At(45))->Fill(t->GetZ()-p[1]);
422 ((TH1F*)fResiduals[fEventSpecie]->At(46))->Fill(t->GetY()-p[0]); //A side
423 ((TH1F*)fResiduals[fEventSpecie]->At(47))->Fill(t->GetZ()-p[1]);