]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/src/AliL3Fitter.cxx
Make AliTRDgeometryFull default
[u/mrichter/AliRoot.git] / HLT / src / AliL3Fitter.cxx
index 6f33c606fcc2ef02390246a109876bdc0bf158f8..8aa6da8cfa5102e89cbf8bc04f4000d2d27e5f25 100644 (file)
@@ -1,35 +1,61 @@
-//$Id$
+// @(#) $Id$
 
 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
-//*-- Copyright &copy ASV 
+//*-- Copyright &copy ALICE HLT Group 
 
+#include "AliL3StandardIncludes.h"
 #include <math.h>
 
-#include "AliL3Defs.h"
 #include "AliL3Logging.h"
 #include "AliL3Fitter.h"
 #include "AliL3Vertex.h"
 #include "AliL3Track.h"
 #include "AliL3SpacePointData.h"
 #include "AliL3MemHandler.h"
+#include "AliL3Transform.h"
+#include "AliLevel3.h"
 
+/** \class AliL3Fitter
+<pre>
 //_____________________________________________________________
 // AliL3Fitter
 //
 // Fit class HLT
+</pre>
+*/
 
 ClassImp(AliL3Fitter)
 
-AliL3Fitter::AliL3Fitter(AliL3Vertex *vertex)
+
+AliL3Fitter::AliL3Fitter()
+{
+  fTrack=0;
+  fVertex=0;
+  memset(fClusters,0,36*6*sizeof(AliL3SpacePointData*));
+}
+
+AliL3Fitter::AliL3Fitter(AliL3Vertex *vertex,Bool_t vertexconstraint)
 {
   //constructor
   fTrack=0;
   fVertex = vertex;
-  BFACT = 0.0029980;
-  fVertexConstraint=kTRUE;
+  fVertexConstraint=vertexconstraint;
+  memset(fClusters,0,36*6*sizeof(AliL3SpacePointData*));
+}
+
+AliL3Fitter::~AliL3Fitter()
+{
+  for(Int_t i=0; i<36; i++)
+    {
+      for(Int_t j=0; j<6; j++)
+       {
+         if(fClusters[i][j])
+           delete fClusters[i][j];
+       }
+    }
 }
 
-void AliL3Fitter::LoadClusters(Char_t *path)
+void AliL3Fitter::LoadClusters(Char_t *path,Int_t event,Bool_t sp)
 {
   Char_t fname[256];
   AliL3MemHandler *clusterfile[36][6];
@@ -37,8 +63,16 @@ void AliL3Fitter::LoadClusters(Char_t *path)
     {
       for(Int_t p=0; p<6; p++)
        {
+         Int_t patch;
+         if(sp==kTRUE)
+           patch=-1;
+         else
+           patch=p;
+         if(fClusters[s][p])
+           delete fClusters[s][p];
+         fClusters[s][p] = 0;
          clusterfile[s][p] = new AliL3MemHandler();
-         sprintf(fname,"%spoints_%d_%d.raw",path,s,p);
+         sprintf(fname,"%s/points_%d_%d_%d.raw",path,event,s,patch);
          if(!clusterfile[s][p]->SetBinaryInput(fname))
            {
              delete clusterfile[s][p];
@@ -48,10 +82,58 @@ void AliL3Fitter::LoadClusters(Char_t *path)
          fClusters[s][p] = (AliL3SpacePointData*)clusterfile[s][p]->Allocate();
          clusterfile[s][p]->Binary2Memory(fNcl[s][p],fClusters[s][p]);
          clusterfile[s][p]->CloseBinaryInput();
+         if(sp==kTRUE)
+           break;
        }
     }
 }
 
+void AliL3Fitter::SortTrackClusters(AliL3Track *track)
+{
+  //Sort the internal cluster list in each track with respect to row numbering.
+  //This may be necessary when no conventional track follower has been
+  //applied, in which the cluster list has been maintained in a more
+  //arbitrary fashion.
+
+  Int_t nhits = track->GetNHits();
+  Int_t *ids = (Int_t*)track->GetHitNumbers();
+  Int_t *origids = new Int_t[nhits];
+  Int_t *mk = new Int_t[nhits];
+  Int_t k;
+
+  for(k=0; k<nhits; k++) {origids[k] = ids[k]; mk[k] = -1;}
+  
+  Int_t slice,patch,id,padrow,maxrow,maxk;
+  UInt_t pos;
+  for(Int_t j=0; j<nhits; j++)
+    {
+      maxrow=-1;
+      maxk=200;
+      for(k=0; k<nhits; k++)
+       {
+         id=ids[k];
+         if(id < 0) continue;
+         slice = (id>>25) & 0x7f;
+         patch = (id>>22) & 0x7;
+         pos = id&0x3fffff;          
+         AliL3SpacePointData *points = fClusters[slice][patch];
+         padrow = points[pos].fPadRow;
+         if(padrow > maxrow)
+           {
+             maxrow = padrow;
+             maxk=k;
+           }
+       }
+      mk[j]=maxk;
+      ids[maxk]=-1;
+    }
+    
+  for(k=0; k<nhits; k++)
+    ids[k] = origids[mk[k]];
+  delete [] origids;
+  delete [] mk;
+}
+
 Int_t AliL3Fitter::FitHelix(AliL3Track *track)
 {
   fTrack = track;
@@ -88,7 +170,6 @@ Int_t AliL3Fitter::FitCircle()
   
   //
   //     Loop over hits calculating average
-  
   Double_t fXYWeight[(fTrack->GetNHits())];
   UInt_t *hitnum = fTrack->GetHitNumbers();
   for(Int_t i=0; i<fTrack->GetNHits(); i++)
@@ -97,13 +178,11 @@ Int_t AliL3Fitter::FitCircle()
       Int_t slice = (id>>25) & 0x7f;
       Int_t patch = (id>>22) & 0x7;
       UInt_t pos = id&0x3fffff;
-      
       AliL3SpacePointData *points = fClusters[slice][patch];
-      fXYWeight[i] = 1./ (Double_t)(points[pos].fXYErr*points[pos].fXYErr + points[pos].fXYErr*points[pos].fXYErr);
+      fXYWeight[i] = 1./ (Double_t)(points[pos].fSigmaY2 + points[pos].fSigmaY2);
       wsum += fXYWeight[i];
       xav += fXYWeight[i]*points[pos].fX;
       yav += fXYWeight[i]*points[pos].fY;
-      
     }
   if (fVertexConstraint == kTRUE)
     {    
@@ -121,7 +200,7 @@ Int_t AliL3Fitter::FitCircle()
   Double_t xyav  = 0.0 ; 
   Double_t yyav  = 0.0 ;
   Double_t xi, yi ;
-
+  
   for(Int_t i=0; i<fTrack->GetNHits(); i++)
     { 
       UInt_t id = hitnum[i];
@@ -129,6 +208,7 @@ Int_t AliL3Fitter::FitCircle()
       Int_t patch = (id>>22) & 0x7;
       UInt_t pos = id&0x3fffff;
       AliL3SpacePointData *points = fClusters[slice][patch];
+
       xi = points[pos].fX -xav;
       yi        = points[pos].fY - yav ;
       xxav     += xi * xi * fXYWeight[i];
@@ -313,13 +393,13 @@ Int_t AliL3Fitter::FitCircle()
      if (fabs(dlamda)<   dlamax) break ;
   }
 
-  Double_t chi2 = (Double_t)(chiscl * lamda) ;
+  //Double_t chi2 = (Double_t)(chiscl * lamda) ;
  
   //fTrack->SetChiSq1(chi2);
   // Double_t dchisq = chiscl * dlamda ;            
-//
-//-->  NOW CALCULATE THE MATRIX ELEMENTS FOR ALPHA, BETA & KAPPA
-//
+  //
+  //-->  NOW CALCULATE THE MATRIX ELEMENTS FOR ALPHA, BETA & KAPPA
+  //
   Double_t h11   = xxav  -     lamda ;
   Double_t h14   = xrrav ;
   Double_t h22   = yyav  -     lamda ; 
@@ -371,47 +451,30 @@ Int_t AliL3Fitter::FitCircle()
 
   fTrack->SetCharge(q);
   
-//
-//    Get other track parameters
-//
-  Double_t x0, y0,phi0,r0,psi,pt ;
-  if ( fVertexConstraint == kTRUE)
-    {
-      //flag = 1 ; // primary track flag
-      x0   = fVertex->GetX() ;
-      y0   = fVertex->GetY() ;
-      phi0 = fVertex->GetPhi() ;
-      r0   = fVertex->GetR() ;
-      fTrack->SetPhi0(phi0);
-      fTrack->SetR0(r0);
-    } 
-  else 
-    {
-      Int_t lastid=fTrack->GetNHits()-1;
-      UInt_t id = hitnum[lastid];
-      Int_t slice = (id>>25) & 0x7f;
-      Int_t patch = (id>>22) & 0x7;
-      UInt_t pos = id&0x3fffff;
-      AliL3SpacePointData *points = fClusters[slice][patch];
-      
-      //flag =  0 ; // primary track flag
-      x0   =  points[pos].fX;
-      y0   =  points[pos].fY;
-      phi0 =  atan2(points[pos].fY,points[pos].fX);
-      if ( phi0 < 0 ) phi0 += 2*Pi;
-      r0   =  sqrt ( points[pos].fX * points[pos].fX + points[pos].fY*points[pos].fY);
-      fTrack->SetPhi0(phi0);
-      fTrack->SetR0(r0);
-    }
-  //
+  //Set the first point on the track to the space point coordinates of the innermost track
+  //This will be updated to lie on the fit later on (AliL3Track::UpdateToFirstPoint).
+  Double_t x0,y0,psi,pt ;
+  Int_t lastid=fTrack->GetNHits()-1;
+  UInt_t id = hitnum[lastid];
+  Int_t slice = (id>>25) & 0x7f;
+  Int_t patch = (id>>22) & 0x7;
+  UInt_t pos = id&0x3fffff;
+  AliL3SpacePointData *points = fClusters[slice][patch];
+  x0   =  points[pos].fX;
+  y0   =  points[pos].fY;
+  fTrack->SetFirstPoint(x0,y0,0); //Z-value is set in FitLine
+  
+  //Set the remaining fit parameters
   psi  = (Double_t)atan2(bcent-y0,acent-x0) ;
-  psi  = psi + q * 0.5F * Pi ;
-  if ( psi < 0 ) psi = psi + 2*Pi;
+  psi  = psi + q * 0.5F * AliL3Transform::Pi() ;
+  if ( psi < 0 ) psi = psi + 2*AliL3Transform::Pi();
   
-  pt   = (Double_t)(BFACT * BField * radius ) ;
+  pt   = (Double_t)(AliL3Transform::GetBFact() * AliL3Transform::GetBField() * radius ) ;
   fTrack->SetPsi(psi);
   fTrack->SetPt(pt);
-  fTrack->SetFirstPoint(x0,y0,0);
+  fTrack->SetRadius(radius);
+  fTrack->SetCenterX(acent);
+  fTrack->SetCenterY(bcent);
   //
 //    Get errors from fast fit
 //
@@ -438,14 +501,15 @@ Int_t AliL3Fitter::FitLine ( )
   //find sum , sums ,sumz, sumss 
   // 
   Double_t dx, dy ;
-  Double_t radius = (Double_t)(fTrack->GetPt() / ( BFACT * BField ) ) ;
+  Double_t radius = (Double_t)(fTrack->GetPt() / ( AliL3Transform::GetBFact() * AliL3Transform::GetBField() ) ) ;
 
   //TObjArray *hits = fTrack->GetHits();
   //Int_t num_of_hits = fTrack->GetNumberOfPoints();
 
   Double_t fS[(fTrack->GetNHits())];
+  Double_t *fZWeight = new Double_t[fTrack->GetNHits()];
   UInt_t *hitnum = fTrack->GetHitNumbers();
-  if (fVertexConstraint==kTRUE)
+  if (0)//fVertexConstraint==kTRUE)
     {
       UInt_t id = hitnum[0];
       Int_t slice = (id>>25) & 0x7f;
@@ -454,7 +518,7 @@ Int_t AliL3Fitter::FitLine ( )
       AliL3SpacePointData *points = fClusters[slice][patch];
       
       dx = points[pos].fX - fVertex->GetX();
-      dy = points[pos].fY - fVertex->GetY() ;
+      dy = points[pos].fY - fVertex->GetY();
     }
   else 
     {
@@ -470,9 +534,8 @@ Int_t AliL3Fitter::FitLine ( )
       AliL3SpacePointData *pointsl = fClusters[slice][patch];
       dx = pointsf[posf].fX - pointsl[posl].fX;
       dy = pointsf[posf].fY - pointsl[posl].fY;
-      
     }
-  
+
   Double_t localPsi = 0.5F * sqrt ( dx*dx + dy*dy ) / radius ;
   Double_t total_s ;
   
@@ -482,7 +545,7 @@ Int_t AliL3Fitter::FitLine ( )
     } 
   else 
     { 
-      total_s = 2.0 * radius * Pi ;
+      total_s = 2.0 * radius * AliL3Transform::Pi() ;
     } 
   
   Double_t dpsi,s;
@@ -495,6 +558,7 @@ Int_t AliL3Fitter::FitLine ( )
       UInt_t pos = id&0x3fffff;
       AliL3SpacePointData *points = fClusters[slice][patch];
       
+      fZWeight[i] = 1./(Double_t)(points[pos].fSigmaZ2);
       if(i>0)
        {
          id = hitnum[i-1];
@@ -505,6 +569,8 @@ Int_t AliL3Fitter::FitLine ( )
          dx = points[pos].fX -lastpoints[lastpos].fX;
          dy = points[pos].fY -lastpoints[lastpos].fY;
          dpsi = 0.5 * (Double_t)sqrt ( dx*dx + dy*dy ) / radius ;
+         if(fabs(dpsi) > 1)
+           return 1;
          fTrack->SetPsierr(dpsi);
          s = fS[i-1] - 2.0 * radius * (Double_t)asin ( dpsi ) ;
          fS[i]=s;
@@ -512,11 +578,11 @@ Int_t AliL3Fitter::FitLine ( )
       else
        fS[i]=total_s;
       
-      sum += 1/(points[pos].fZErr*points[pos].fZErr);
-      ss  += 1/(points[pos].fZErr*points[pos].fZErr) * fS[i];
-      sz  += 1/(points[pos].fZErr*points[pos].fZErr)*points[pos].fZ;
-      sss += 1/(points[pos].fZErr*points[pos].fZErr)* fS[i] * fS[i];
-      ssz += 1/(points[pos].fZErr*points[pos].fZErr) * fS[i] * points[pos].fZ;
+      sum += fZWeight[i];
+      ss  += fZWeight[i] * fS[i];
+      sz  += fZWeight[i] * points[pos].fZ;
+      sss += fZWeight[i] * fS[i] * fS[i];
+      ssz += fZWeight[i] * fS[i] * points[pos].fZ;
       
     }
   
@@ -551,7 +617,7 @@ Int_t AliL3Fitter::FitLine ( )
       UInt_t pos = id&0x3fffff;
       AliL3SpacePointData *points = fClusters[slice][patch];
       r1   = points[pos].fZ - tanl * fS[i] - z0 ;
-      chi2 += (Double_t) ( (Double_t)(1/(points[pos].fZErr*points[pos].fZErr)) * (r1 * r1) );
+      chi2 += (Double_t) ( (Double_t)(fZWeight[i]) * (r1 * r1) );
     }
   
   //fTrack->SetChiSq2(chi2);
@@ -567,6 +633,6 @@ Int_t AliL3Fitter::FitLine ( )
   
   fTrack->SetTglerr(dtanl);
   fTrack->SetZ0err(dz0);
-  
+  delete [] fZWeight;
   return 0 ;
 }