]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliTracker.cxx
Removal of printf and cout messages (Per Thomas)
[u/mrichter/AliRoot.git] / STEER / AliTracker.cxx
index f91dbce051cff8a6406ff072b4d8e98d8d7d45a3..f9bbbb708516d6721d887279799babeb516b8af6 100644 (file)
 //-------------------------------------------------------------------------
 #include <TClass.h>
 #include <TMath.h>
+#include <TH1F.h>
 #include <TGeoManager.h>
 
 #include "AliMagF.h"
 #include "AliTracker.h"
+#include "AliGeomManager.h"
 #include "AliCluster.h"
 #include "AliKalmanTrack.h"
 
@@ -34,6 +36,8 @@ extern TGeoManager *gGeoManager;
 Bool_t AliTracker::fgUniformField=kTRUE;
 Double_t AliTracker::fgBz=kAlmost0Field;
 const AliMagF *AliTracker::fgkFieldMap=0;
+Bool_t AliTracker::fFillResiduals=kFALSE;
+TObjArray *AliTracker::fResiduals=0;
 
 ClassImp(AliTracker)
 
@@ -97,6 +101,7 @@ void AliTracker::CookLabel(AliKalmanTrack *t, Float_t wrong) const {
   //This function "cooks" a track label. If label<0, this track is fake.
   //--------------------------------------------------------------------
   Int_t noc=t->GetNumberOfClusters();
+  if (noc<1) return;
   Int_t *lb=new Int_t[noc];
   Int_t *mx=new Int_t[noc];
   AliCluster **clusters=new AliCluster*[noc];
@@ -179,6 +184,12 @@ AliTracker::MeanMaterialBudget(Double_t *start,Double_t *end,Double_t *mparam)
   // mparam[5] - Z/A mean: sum(x_i*Z_i/A_i)/sum(x_i) [adimensional]
   // mparam[6] - number of boundary crosses
   //
+  //  Origin:  Marian Ivanov, Marian.Ivanov@cern.ch
+  //
+  //  Corrections and improvements by
+  //        Andrea Dainese, Andrea.Dainese@lnl.infn.it,
+  //        Andrei Gheata,  Andrei.Gheata@cern.ch
+  //
 
   mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0;
   mparam[4]=0; mparam[5]=0; mparam[6]=0;
@@ -210,7 +221,8 @@ AliTracker::MeanMaterialBudget(Double_t *start,Double_t *end,Double_t *mparam)
   TGeoNode *startnode = gGeoManager->InitTrack(start, dir);
   //printf("%s length=%f\n",gGeoManager->GetPath(),length);
   if (!startnode) {
-    printf("ERROR: start point out of geometry\n");
+    AliErrorClass(Form("start point out of geometry: x %f, y %f, z %f",
+                 start[0],start[1],start[2]));
     return 0.0;
   }
   TGeoMaterial *material = startnode->GetVolume()->GetMedium()->GetMaterial();
@@ -305,3 +317,80 @@ AliTracker::MeanMaterialBudget(Double_t *start,Double_t *end,Double_t *mparam)
   mparam[5] = bparam[5]/step;
   return bparam[0]/step;
 }
+
+
+Bool_t 
+AliTracker::PropagateTrackTo(AliExternalTrackParam *track, Double_t xToGo, 
+Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp){
+  //----------------------------------------------------------------
+  //
+  // Propagates the track to the plane X=xk (cm) using the magnetic field map 
+  // and correcting for the crossed material.
+  //
+  // mass     - mass used in propagation - used for energy loss correction
+  // maxStep  - maximal step for propagation
+  //
+  //  Origin: Marian Ivanov,  Marian.Ivanov@cern.ch
+  //
+  //----------------------------------------------------------------
+  const Double_t kEpsilon = 0.00001;
+  Double_t xpos     = track->GetX();
+  Double_t dir      = (xpos<xToGo) ? 1.:-1.;
+  //
+  while ( (xToGo-xpos)*dir > kEpsilon){
+    Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
+    Double_t x    = xpos+step;
+    Double_t xyz0[3],xyz1[3],param[7];
+    track->GetXYZ(xyz0);   //starting global position
+
+    Double_t bz=GetBz(xyz0); // getting the local Bz
+
+    if (!track->GetXYZAt(x,bz,xyz1)) return kFALSE;   // no prolongation
+    xyz1[2]+=kEpsilon; // waiting for bug correction in geo
+
+    if (TMath::Abs(track->GetSnpAt(x,bz)) >= maxSnp) return kFALSE;
+    if (!track->PropagateTo(x,bz))  return kFALSE;
+
+    MeanMaterialBudget(xyz0,xyz1,param);       
+    Double_t xrho=param[0]*param[4], xx0=param[1];
+
+    if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
+    if (rotateTo){
+      if (TMath::Abs(track->GetSnp()) >= maxSnp) return kFALSE;
+      track->GetXYZ(xyz0);   // global position
+      Double_t alphan = TMath::ATan2(xyz0[1], xyz0[0]); 
+      //
+      Double_t ca=TMath::Cos(alphan-track->GetAlpha()), 
+               sa=TMath::Sin(alphan-track->GetAlpha());
+      Double_t sf=track->GetSnp(), cf=TMath::Sqrt(1.- sf*sf);
+      Double_t sinNew =  sf*ca - cf*sa;
+      if (TMath::Abs(sinNew) >= maxSnp) return kFALSE;
+      if (!track->Rotate(alphan)) return kFALSE;
+    }
+    xpos = track->GetX();
+  }
+  return kTRUE;
+}
+
+void AliTracker::FillResiduals(const AliExternalTrackParam *t,
+                             Double_t *p, Double_t *cov, 
+                              UShort_t id, Bool_t updated) {
+  //
+  // This function fills the histograms of residuals 
+  // The array of these histos is external for this AliTracker class.
+  // Normally, this array belong to AliGlobalQADataMaker class.  
+  // 
+  if (!fFillResiduals) return; 
+  if (!fResiduals) return; 
+
+  const Double_t *residuals=t->GetResiduals(p,cov,updated);
+  if (!residuals) return;
+
+  TH1F *h=0;
+  AliGeomManager::ELayerID layer=AliGeomManager::VolUIDToLayer(id);
+  h=(TH1F*)fResiduals->At(2*layer-2);
+  h->Fill(residuals[0]);
+  h=(TH1F*)fResiduals->At(2*layer-1);
+  h->Fill(residuals[1]);
+}
+