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>
27 #include <TGeoMatrix.h>
30 #include "AliTracker.h"
31 #include "AliGeomManager.h"
32 #include "AliCluster.h"
33 #include "AliKalmanTrack.h"
35 extern TGeoManager *gGeoManager;
37 Bool_t AliTracker::fgUniformField=kTRUE;
38 Double_t AliTracker::fgBz=kAlmost0Field;
39 const AliMagF *AliTracker::fgkFieldMap=0;
40 Bool_t AliTracker::fFillResiduals=kFALSE;
41 TObjArray **AliTracker::fResiduals=NULL;
42 AliRecoParam::EventSpecie_t AliTracker::fEventSpecie=AliRecoParam::kDefault;
46 AliTracker::AliTracker():
55 //--------------------------------------------------------------------
56 // The default constructor.
57 //--------------------------------------------------------------------
58 if (!fgkFieldMap) AliWarning("Field map is not set. Call AliTracker::SetFieldMap before creating a tracker!");
61 //__________________________________________________________________________
62 AliTracker::AliTracker(const AliTracker &atr):
71 //--------------------------------------------------------------------
72 // The default constructor.
73 //--------------------------------------------------------------------
74 if (!fgkFieldMap) AliWarning("Field map is not set. Call AliTracker::SetFieldMap before creating a tracker!");
77 //__________________________________________________________________________
78 void 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 !");
85 AliWarningClass("The magnetic field map has been already set !");
92 //Float_t r[3]={0.,0.,0.},b[3]; map->Field(r,b);
95 Double_t bz=-map->SolenoidField();
96 fgBz=TMath::Sign(kAlmost0Field,bz) + bz;
100 //__________________________________________________________________________
101 void AliTracker::FillClusterArray(TObjArray* /*array*/) const
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
108 AliWarning("should be overriden by a sub-class.");
111 //__________________________________________________________________________
112 void 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();
118 Int_t *lb=new Int_t[noc];
119 Int_t *mx=new Int_t[noc];
120 AliCluster **clusters=new AliCluster*[noc];
123 for (i=0; i<noc; i++) {
125 Int_t index=t->GetClusterIndex(i);
126 clusters[i]=GetCluster(index);
130 for (i=0; i<noc; i++) {
131 AliCluster *c=clusters[i];
132 lab=TMath::Abs(c->GetLabel(0));
134 for (j=0; j<noc; j++) if (lb[j]==lab || mx[j]==0) break;
140 for (i=0; i<noc; i++) if (mx[i]>max) {max=mx[i]; lab=lb[i];}
142 for (i=0; i<noc; i++) {
143 AliCluster *c=clusters[i];
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++;
151 if ((1.- Float_t(max)/noc) > wrong) lab=-lab;
152 t->SetFakeRatio((1.- Float_t(max)/noc));
160 //____________________________________________________________________________
161 void 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);
173 Double_t AliTracker::GetBz(const Float_t *r) {
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);
183 AliTracker::MeanMaterialBudget(const Double_t *start, const Double_t *end, Double_t *mparam)
186 // Calculate mean material budget and material properties between
187 // the points "start" and "end".
189 // "mparam" - parameters used for the energy and multiple scattering
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
200 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
202 // Corrections and improvements by
203 // Andrea Dainese, Andrea.Dainese@lnl.infn.it,
204 // Andrei Gheata, Andrei.Gheata@cern.ch
207 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0;
208 mparam[4]=0; mparam[5]=0; mparam[6]=0;
210 Double_t bparam[6]; // total parameters
211 Double_t lparam[6]; // local parameters
213 for (Int_t i=0;i<6;i++) bparam[i]=0;
216 printf("ERROR: no TGeo\n");
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]));
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;
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);
237 AliErrorClass(Form("start point out of geometry: x %f, y %f, z %f",
238 start[0],start[1],start[2]));
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();
247 lparam[5] = lparam[3]/lparam[2];
248 if (material->IsMixture()) {
249 TGeoMixture * mixture = (TGeoMixture*)material;
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];
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];
273 // Try to cross the boundary and see what is next
275 while (length>TGeoShape::Tolerance()) {
276 currentnode = gGeoManager->GetCurrentNode();
277 if (snext<2.*TGeoShape::Tolerance()) nzero++;
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;
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;
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];
301 if (snext>=length) break;
302 if (!currentnode) break;
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;
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];
322 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
323 snext = gGeoManager->GetStep();
324 //printf("snext %f\n",snext);
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;
336 AliTracker::PropagateTrackTo(AliExternalTrackParam *track, Double_t xToGo,
337 Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp){
338 //----------------------------------------------------------------
340 // Propagates the track to the plane X=xk (cm) using the magnetic field map
341 // and correcting for the crossed material.
343 // mass - mass used in propagation - used for energy loss correction
344 // maxStep - maximal step for propagation
346 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
348 //----------------------------------------------------------------
349 const Double_t kEpsilon = 0.00001;
350 Double_t xpos = track->GetX();
351 Double_t dir = (xpos<xToGo) ? 1.:-1.;
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
359 Double_t bz=GetBz(xyz0); // getting the local Bz
361 if (!track->GetXYZAt(x,bz,xyz1)) return kFALSE; // no prolongation
362 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
364 if (TMath::Abs(track->GetSnpAt(x,bz)) >= maxSnp) return kFALSE;
365 if (!track->PropagateTo(x,bz)) return kFALSE;
367 MeanMaterialBudget(xyz0,xyz1,param);
368 Double_t xrho=param[0]*param[4], xx0=param[1];
370 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
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]);
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;
383 xpos = track->GetX();
388 void AliTracker::FillResiduals(const AliExternalTrackParam *t,
389 Double_t *p, Double_t *cov,
390 UShort_t id, Bool_t updated) {
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.
396 if (!fFillResiduals) return;
397 if (!fResiduals) return;
399 const Double_t *residuals=t->GetResiduals(p,cov,updated);
400 if (!residuals) return;
403 AliGeomManager::ELayerID layer=AliGeomManager::VolUIDToLayer(id);
404 h=(TH1F*)fResiduals[fEventSpecie]->At(2*layer-2);
405 h->Fill(residuals[0]);
406 h=(TH1F*)fResiduals[fEventSpecie]->At(2*layer-1);
407 h->Fill(residuals[1]);
410 if (p[1]<0) { // SSD1 absolute residuals
411 ((TH1F*)fResiduals[fEventSpecie]->At(40))->Fill(t->GetY()-p[0]); //C side
412 ((TH1F*)fResiduals[fEventSpecie]->At(41))->Fill(t->GetZ()-p[1]);
414 ((TH1F*)fResiduals[fEventSpecie]->At(42))->Fill(t->GetY()-p[0]); //A side
415 ((TH1F*)fResiduals[fEventSpecie]->At(43))->Fill(t->GetZ()-p[1]);
418 if (layer==6) { // SSD2 absolute residuals
420 ((TH1F*)fResiduals[fEventSpecie]->At(44))->Fill(t->GetY()-p[0]); //C side
421 ((TH1F*)fResiduals[fEventSpecie]->At(45))->Fill(t->GetZ()-p[1]);
423 ((TH1F*)fResiduals[fEventSpecie]->At(46))->Fill(t->GetY()-p[0]); //A side
424 ((TH1F*)fResiduals[fEventSpecie]->At(47))->Fill(t->GetZ()-p[1]);
430 void AliTracker::FillResiduals(const AliExternalTrackParam *t,
431 const AliCluster *c, Bool_t /*updated*/) {
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.
437 // For the moment, the residuals are absolute !
440 if (!fFillResiduals) return;
441 if (!fResiduals) return;
443 UShort_t id=c->GetVolumeId();
444 const TGeoHMatrix *matrixT2L=AliGeomManager::GetTracking2LocalMatrix(id);
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);
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);
459 Double_t residuals[2]={trkLoc[0]-clsLoc[0], trkLoc[2]-clsLoc[2]};
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]);