]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/AliHLTTPCTrack.cxx
treatment of MC labels added
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCTrack.cxx
index 33829862123e7eb25602906b0687b642f740b6e5..d3c213fc5501dc2c3d3ad9a3b1c4cdd6ced7ca65 100644 (file)
@@ -71,7 +71,8 @@ AliHLTTPCTrack::AliHLTTPCTrack()
   fIsLocal(true),
   //  fRowRange({0,0}),
 
-  fPID(0)
+  fPID(0),
+  fId(-1)
 {
   //Constructor
   fRowRange[0]=0;
@@ -82,7 +83,7 @@ AliHLTTPCTrack::AliHLTTPCTrack()
 
   SetFirstPoint(0,0,0);
   SetLastPoint(0,0,0);
-  memset(fHitNumbers,0,159*sizeof(UInt_t));
+  memset(fHitNumbers,0,fgkHitArraySize*sizeof(UInt_t));
 }
 
 void AliHLTTPCTrack::Copy(AliHLTTPCTrack *tpt)
@@ -100,13 +101,14 @@ void AliHLTTPCTrack::Copy(AliHLTTPCTrack *tpt)
   SetPterr(tpt->GetPterr());
   SetPsierr(tpt->GetPsierr());
   SetTglerr(tpt->GetTglerr());
+  SetZ0err(tpt->GetZ0err());
+  SetY0err(tpt->GetY0err());
   SetCharge(tpt->GetCharge());
   SetHits(tpt->GetNHits(),(UInt_t *)tpt->GetHitNumbers());
-#ifdef do_mc
   SetMCid(tpt->GetMCid());
-#endif
   SetPID(tpt->GetPID());
   SetSector(tpt->GetSector());
+  SetId( tpt->GetId());
 }
 
 Int_t AliHLTTPCTrack::Compare(const AliHLTTPCTrack *track) const
@@ -133,13 +135,6 @@ Double_t AliHLTTPCTrack::GetPseudoRapidity() const
   return 0.5 * log((GetP() + GetPz()) / (GetP() - GetPz()));
 }
 
-/*
-Double_t AliHLTTPCTrack::GetEta() const
-{
-  return GetPseudoRapidity();
-}
-*/
-
 Double_t AliHLTTPCTrack::GetRapidity() const
 { 
   //get rap
@@ -621,40 +616,67 @@ int AliHLTTPCTrack::Convert2AliKalmanTrack()
   // sector A00 starts at 3 o'clock, sectors are counted counterclockwise
   // median of sector 00 is at 10 degrees, median of sector A04 at 90
   //
-  Double_t xhit;
-  Double_t charge=-1.0 * (double) GetCharge();
-  Double_t xx[5];
-  xx[1] = GetFirstPointZ();
-  xx[3] = GetTgl();
-  xx[4] = charge*(1.0/GetPt());
-
-  Double_t alpha = 0;
-  if(GetSector() == -1){
-    alpha = TMath::ATan(fabs(GetFirstPointY())/fabs(GetFirstPointX()));
-
-    if(GetFirstPointX()<0 && GetFirstPointY()>=0){
-      alpha = alpha + TMath::PiOver2();
-    }
-    else if(GetFirstPointX()<0 && GetFirstPointY()<0){
-      alpha = -TMath::Pi() + alpha;
-    }
-    else if(GetFirstPointX()>=0 && GetFirstPointY()<0){
-      alpha = -alpha;
-    }
-    xhit = GetFirstPointX()*TMath::Cos(alpha) + GetFirstPointY()*TMath::Sin(alpha);
-    xx[0] = -(GetFirstPointX()*TMath::Sin(alpha)) + GetFirstPointY()*TMath::Cos(alpha);
-    xx[2] = TMath::Sin(GetPsi()-alpha);
+
+  Double_t charge=(double) GetCharge();
+  Double_t param[5];
+  param[1] = GetFirstPointZ();
+  param[3] = GetTgl();
+  param[4] = charge*(1.0/GetPt());
+
+  Double_t alpha, phi, xl, yl;
+
+  // rotate to local coordinates if necessary
+
+  if(GetSector() == -1){ // track in global coordinates
+
+    alpha = TMath::ATan2(GetFirstPointY(),GetFirstPointX());
+    double sinAlpha = TMath::Sin(alpha);
+    double cosAlpha = TMath::Cos(alpha);   
+
+    phi = GetPsi() - alpha;
+    xl =  GetFirstPointX()*cosAlpha + GetFirstPointY()*sinAlpha;    
+    yl = -GetFirstPointX()*sinAlpha + GetFirstPointY()*cosAlpha;
+
+  } else{ // track in local coordinates
+
+    alpha = (GetSector()+0.5)*(TMath::TwoPi()/18);
+    phi = GetPsi();    
+    xl = GetFirstPointX();
+    yl = GetFirstPointY();
+
+    // normalize alpha to [-Pi,+Pi]
+
+    alpha = alpha - TMath::TwoPi() * TMath::Floor( alpha /TMath::TwoPi()+.5);
   }
-  else{
-    alpha = fmod((2*GetSector()+1)*(TMath::Pi()/18),2*TMath::Pi());
-    if      (alpha < -TMath::Pi()) alpha += 2*TMath::Pi();
-    else if (alpha >= TMath::Pi()) alpha -= 2*TMath::Pi();
+  
+  // extra rotation to keep phi in the range (-Pi/2,+Pi/2)
+  {  
+    const Double_t kMaxPhi = TMath::PiOver2() - 10./180.*TMath::Pi(); 
     
-    xhit = GetFirstPointX();
-    xx[0] = GetFirstPointY();
-    xx[2] = TMath::Sin(GetPsi());
+    // normalize phi to [-Pi,+Pi]
+    
+    phi = phi - TMath::TwoPi() * TMath::Floor( phi /TMath::TwoPi()+.5);
+    
+    if( phi >= kMaxPhi )
+      {      
+       alpha += TMath::PiOver2();
+       phi   -= TMath::PiOver2();
+       Double_t xtmp = xl;
+       xl =  yl;
+       yl = -xtmp;
+      } 
+    else if( phi <= -kMaxPhi )
+      {      
+       alpha += -TMath::PiOver2();
+       phi   -= -TMath::PiOver2();
+       Double_t xtmp = xl;
+       xl = -yl;
+       yl =  xtmp;
+      }
   }
-  
+
+  param[0] = yl;
+  param[2] = TMath::Sin(phi);
   
   //covariance matrix
   Double_t cov[15]={
@@ -675,7 +697,7 @@ int AliHLTTPCTrack::Convert2AliKalmanTrack()
   //TODO (Feb 07): make this a real warning when logging system is adapted
   //HLTWarning("track conversion to ESD format needs AliRoot version > v4-05-04");
 #else
-  Set(xhit,alpha,xx,cov);
+  Set(xl,alpha,param,cov);
   SetNumberOfClusters(nCluster);
   SetChi2(0.);
   SetFakeRatio(0.);
@@ -692,6 +714,63 @@ void AliHLTTPCTrack::SetHits(Int_t nhits,UInt_t *hits)
   if (nhits>fgkHitArraySize) {
     LOG(AliHLTTPCLog::kWarning,"AliHLTTPCTrack::SetHits","too many hits")
       << "too many hits (" << nhits << ") for hit array of size " << fgkHitArraySize << ENDLOG; 
+    SetNHits(fgkHitArraySize);
+  } else {
+    SetNHits(nhits);
   }
-  memcpy(fHitNumbers,hits,(nhits<=fgkHitArraySize?nhits:fgkHitArraySize)*sizeof(UInt_t));
+  memcpy(fHitNumbers,hits,fNHits*sizeof(UInt_t));
+}
+
+Double_t AliHLTTPCTrack::GetLengthXY() const
+{
+  //calculates the length of the arc in XY-plane. This is the length of the track in XY-plane.
+  //Using a^2 = b^2 + c^2 - 2bc * cosA for finding the angle between first and last point.
+  //Length of arc is arc = r*A. Where A is the angle between first and last point.
+
+  Double_t dx = GetLastPointX()-GetFirstPointX();
+  Double_t dy = GetLastPointY()-GetFirstPointY();
+  Double_t a = TMath::Sqrt((dx*dx)+(dy*dy)); 
+  Double_t r = GetRadius();
+  Double_t r2 = r*r;
+
+  Double_t A = TMath::ACos((r2+r2-(a*a))/(2*r2));
+
+  return r*A;
+}
+
+Double_t AliHLTTPCTrack::GetLengthTot() const
+{
+  //Calculates the length of the track in 3D
+
+
+
+
+
+  return 100.0;
+
+}
+
+int AliHLTTPCTrack::CheckConsistency()
+{
+  // Check consistency of all members
+  int iResult=0;
+  if (CheckDoubleMember(&fPterr,   0., "fPterr")<0) iResult=-EDOM;
+  if (CheckDoubleMember(&fPsierr,  0., "fPsierr")<0) iResult=-EDOM;
+  if (CheckDoubleMember(&fZ0err,   0., "fZ0err")<0) iResult=-EDOM;
+  if (CheckDoubleMember(&fY0err,   0., "fY0err")<0) iResult=-EDOM;  
+  if (CheckDoubleMember(&fTanlerr, 0., "fTanlerr")<0) iResult=-EDOM;
+  return iResult;
+}
+
+int AliHLTTPCTrack::CheckDoubleMember(double* pMember, double def, const char* name) const
+{
+  // Check consistency of a Double member
+  if (!pMember) return -EINVAL;
+  if (TMath::Abs(*pMember)>kVeryBig) {
+    LOG(AliHLTTPCLog::kWarning,"AliHLTTPCTrack","member consistency")
+      << "invalid Double number %f" << *pMember << " in member " << name << ENDLOG; 
+    *pMember=def;
+    return -EDOM;
+  }
+  return 0;
 }