]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVE/EveDet/AliEveMUONTrack.cxx
Coverity
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveMUONTrack.cxx
index 9c2db9bf17effab68fab840211e58807a175971c..ef0c2f2a703adb4b60c6532f5495e64e93d6ade3 100644 (file)
@@ -12,7 +12,6 @@
 #include <EveBase/AliEveEventManager.h>
 
 #include <AliMagF.h>
-#include <AliMagFMaps.h>
 #include <AliLog.h>
 #include <AliESDMuonTrack.h>
 #include <AliESDEvent.h>
 #include <AliMUONTrackParam.h>
 #include <AliMUONConstants.h>
 #include <AliMUONESDInterface.h>
+#include <AliMUONVCluster.h>
 
 #include <TClonesArray.h>
-#include <TStyle.h>
-#include <TROOT.h>
+#include <TGeoGlobalMagField.h>
 #include <TParticle.h>
 #include <TParticlePDG.h>
+#include <TROOT.h>
+#include <TStyle.h>
 
 #include <Riostream.h>
 
@@ -44,7 +45,6 @@
 
 ClassImp(AliEveMUONTrack)
 
-AliMagF* AliEveMUONTrack::fgFieldMap = 0;
 
 //______________________________________________________________________________
 AliEveMUONTrack::AliEveMUONTrack(TEveRecTrack* t, TEveTrackPropagator* rs) :
@@ -61,9 +61,6 @@ AliEveMUONTrack::AliEveMUONTrack(TEveRecTrack* t, TEveTrackPropagator* rs) :
   //
   // constructor
   //
-
-  if (fgFieldMap == 0)
-    fgFieldMap = AliEveEventManager::AssertMagField();
 }
 
 //______________________________________________________________________________
@@ -471,69 +468,62 @@ void AliEveMUONTrack::MakeMUONTrack(AliMUONTrack *mtrack)
   // builds the track with dipole field
   //
 
-  if (!fIsRefTrack) {
-    fIsMUONTrack = kTRUE;
-    fTrack    = mtrack;
-  }
-
-  if (fIsRefTrack) {
-    fTrack = new AliMUONTrack(*mtrack);
+  if (!fIsESDTrack) {
+    if (!fIsRefTrack) {
+      fIsMUONTrack = kTRUE;
+      fTrack = mtrack;
+    } else {
+      fTrack = new AliMUONTrack(*mtrack);
+    }
   }
 
   Double_t xv, yv;
   Float_t ax, bx, ay, by;
   Float_t xr[28], yr[28], zr[28];
   Float_t xrc[28], yrc[28], zrc[28];
+  Int_t chr[28];
   char form[1000];
 
   TMatrixD smatrix(2,2);
   TMatrixD sums(2,1);
   TMatrixD res(2,1);
 
-  Float_t xRec, xRec0;
-  Float_t yRec, yRec0;
-  Float_t zRec, zRec0;
-
   // middle z between the two detector planes of the trigger chambers
   Float_t zg[4] = { -1603.5, -1620.5, -1703.5, -1720.5 };
 
   Float_t pt    = 0.0;
-  Float_t pv[3] = { 0.0 };
+  Float_t pv[3] = {0., 0., 0.};
 
   if (fIsMUONTrack) {
     if (mtrack->GetMatchTrigger()) {
-      sprintf(form,"AliEveMUONTrack %2d (MT)", fLabel);
+      sprintf(form,"MUONTrack %2d (MT)", fLabel);
     } else {
-      sprintf(form,"AliEveMUONTrack %2d     ", fLabel);
+      sprintf(form,"MUONTrack %2d     ", fLabel);
     }
     SetName(form);
     SetLineStyle(1);
   }
 
-  AliMUONTrackParam *trackParam = mtrack->GetTrackParamAtVertex();
-  xRec0  = trackParam->GetNonBendingCoor();
-  yRec0  = trackParam->GetBendingCoor();
-  zRec0  = trackParam->GetZ();
-
-  if (fIsMUONTrack) {
-    SetPoint(fCount,xRec0,yRec0,zRec0);
+  AliMUONTrackParam *trackParam = 0x0;
+  if (fIsMUONTrack || fIsESDTrack) {
+    trackParam = mtrack->GetTrackParamAtVertex();
+    SetPoint(fCount,trackParam->GetNonBendingCoor(),trackParam->GetBendingCoor(),trackParam->GetZ());
     fCount++;
   }
 
-  for (Int_t i = 0; i < 28; i++) xr[i]=yr[i]=zr[i]=0.0;
-
+  for (Int_t i = 0; i < 28; i++) {
+    xr[i]=yr[i]=zr[i]=0.0;
+    chr[i]=-1;
+  }
+  
   Int_t nTrackHits = mtrack->GetNClusters();
-
-  Bool_t hitChamber[14] = {kFALSE};
-  Int_t iCha;
   TClonesArray* trackParamAtCluster = mtrack->GetTrackParamAtCluster();
-
   for (Int_t iHit = 0; iHit < nTrackHits; iHit++){
 
     trackParam = (AliMUONTrackParam*) trackParamAtCluster->At(iHit);
 
     if (iHit == 0) {
-      if (IsMUONTrack()) {
+      if (IsMUONTrack() || IsESDTrack()) {
        pt = TMath::Sqrt(trackParam->Px()*trackParam->Px()+trackParam->Py()*trackParam->Py());
        SetLineColor(ColorIndex(pt));
       }
@@ -543,141 +533,25 @@ void AliEveMUONTrack::MakeMUONTrack(AliMUONTrack *mtrack)
       fP.Set(pv);
     }
 
-    xRec  = trackParam->GetNonBendingCoor();
-    yRec  = trackParam->GetBendingCoor();
-    zRec  = trackParam->GetZ();
-
-    iCha = AliMUONConstants::ChamberNumber(zRec);
+    xr[iHit] = trackParam->GetNonBendingCoor();
+    yr[iHit] = trackParam->GetBendingCoor();
+    zr[iHit] = trackParam->GetZ();
+    chr[iHit] = trackParam->GetClusterPtr()->GetChamberId();
 
-    xr[iHit] = xRec;
-    yr[iHit] = yRec;
-    zr[iHit] = zRec;
-
-    hitChamber[iCha] = kTRUE;
-
-  }
-
-  Int_t crntCha, lastHitSt12, firstHitSt3, lastHitSt3, firstHitSt45;
-
-  if (fIsMUONTrack) nTrackHits = 10;
-
-  lastHitSt12  = -1;
-  firstHitSt3  = -1;
-  lastHitSt3   = -1;
-  firstHitSt45 = -1;
-  for (Int_t iHit = 0; iHit < nTrackHits; iHit++) {
-    crntCha = AliMUONConstants::ChamberNumber(zr[iHit]);
-    if (hitChamber[crntCha] && crntCha >= 0 && crntCha <= 3) {
-      lastHitSt12 = iHit;
-    }
-    if (hitChamber[crntCha] && crntCha >= 4 && crntCha <= 5) {
-      if (firstHitSt3 == -1) firstHitSt3 = iHit;
-      lastHitSt3 = iHit;
-    }
-    if (hitChamber[crntCha] && crntCha >= 6 && crntCha <= 9) {
-      if (firstHitSt45 == -1) firstHitSt45 = iHit;
-    }
   }
-
-  if (lastHitSt12 >= 0) {
-    for (Int_t iHit = 0; iHit <= lastHitSt12; iHit++) {
-      SetPoint(fCount,xr[iHit],yr[iHit],zr[iHit]);
-      fCount++;
-    }
-    if (firstHitSt3 >= 0) {
-      Propagate(xr,yr,zr,lastHitSt12,firstHitSt3);
-      SetPoint(fCount,xr[firstHitSt3],yr[firstHitSt3],zr[firstHitSt3]);
-      fCount++;
-      if (lastHitSt3 >= 0) {
-       SetPoint(fCount,xr[lastHitSt3],yr[lastHitSt3],zr[lastHitSt3]);
-       fCount++;
-       if (firstHitSt45 >= 0) {
-         Propagate(xr,yr,zr,lastHitSt3,firstHitSt45);
-         for (Int_t iHit = firstHitSt45; iHit < nTrackHits; iHit++) {
-           SetPoint(fCount,xr[iHit],yr[iHit],zr[iHit]);
-           fCount++;
-         }
-       } else {
-         Propagate(xr,yr,zr,lastHitSt3,9999);
-       }
-      } else if (firstHitSt45 >= 0) {
-       Propagate(xr,yr,zr,firstHitSt3,firstHitSt45);
-       for (Int_t iHit = firstHitSt45; iHit < nTrackHits; iHit++) {
-         SetPoint(fCount,xr[iHit],yr[iHit],zr[iHit]);
-         fCount++;
-       }
-      } else {
-       Propagate(xr,yr,zr,firstHitSt3,9999);
-      }
-    } else if (lastHitSt3 >= 0) {
-      Propagate(xr,yr,zr,lastHitSt12,lastHitSt3);
-      SetPoint(fCount,xr[lastHitSt3],yr[lastHitSt3],zr[lastHitSt3]);
-      fCount++;
-      if (firstHitSt45 >= 0) {
-       Propagate(xr,yr,zr,lastHitSt3,firstHitSt45);
-       for (Int_t iHit = firstHitSt45; iHit < nTrackHits; iHit++) {
-         SetPoint(fCount,xr[iHit],yr[iHit],zr[iHit]);
-         fCount++;
-       }
-      } else {
-       Propagate(xr,yr,zr,lastHitSt3,9999);
-      }
-    } else if (firstHitSt45 >= 0){
-      Propagate(xr,yr,zr,lastHitSt12,firstHitSt45);
-      for (Int_t iHit = firstHitSt45; iHit < nTrackHits; iHit++) {
-       SetPoint(fCount,xr[iHit],yr[iHit],zr[iHit]);
-       fCount++;
-      }
-    } else {
-      Propagate(xr,yr,zr,lastHitSt12,9999);
-    }
-  } else if (firstHitSt3 >= 0) {
-    SetPoint(fCount,xr[firstHitSt3],yr[firstHitSt3],zr[firstHitSt3]);
-    fCount++;
-    if (lastHitSt3 >= 0) {
-      SetPoint(fCount,xr[lastHitSt3],yr[lastHitSt3],zr[lastHitSt3]);
-      fCount++;
-      if (firstHitSt45) {
-       Propagate(xr,yr,zr,lastHitSt3,firstHitSt45);
-       for (Int_t iHit = firstHitSt45; iHit < nTrackHits; iHit++) {
-         SetPoint(fCount,xr[iHit],yr[iHit],zr[iHit]);
-         fCount++;
-       }
-      } else {
-       Propagate(xr,yr,zr,lastHitSt3,9999);
-      }
-    } else if (firstHitSt45 >= 0) {
-      Propagate(xr,yr,zr,firstHitSt3,firstHitSt45);
-      for (Int_t iHit = firstHitSt45; iHit < nTrackHits; iHit++) {
-       SetPoint(fCount,xr[iHit],yr[iHit],zr[iHit]);
-       fCount++;
-      }
-    } else {
-      Propagate(xr,yr,zr,firstHitSt3,9999);
-    }
-  } else if (lastHitSt3 >= 0) {
-    SetPoint(fCount,xr[lastHitSt3],yr[lastHitSt3],zr[lastHitSt3]);
+  
+  SetPoint(fCount,xr[0],yr[0],zr[0]);
+  fCount++;
+  for (Int_t iHit = 1; iHit < nTrackHits; iHit++) {
+    if (chr[iHit] > 3 && chr[iHit-1] < 6) Propagate(xr,yr,zr,iHit-1,iHit);
+    SetPoint(fCount,xr[iHit],yr[iHit],zr[iHit]);
     fCount++;
-    if (firstHitSt45 >= 0) {
-      Propagate(xr,yr,zr,lastHitSt3,firstHitSt45);
-      for (Int_t iHit = firstHitSt45; iHit < nTrackHits; iHit++) {
-       SetPoint(fCount,xr[iHit],yr[iHit],zr[iHit]);
-       fCount++;
-      }
-    } else {
-      Propagate(xr,yr,zr,lastHitSt3,9999);
-    }
-  } else {
-    for (Int_t iHit = 0; iHit < nTrackHits; iHit++) {
-      SetPoint(fCount,xr[iHit],yr[iHit],zr[iHit]);
-      fCount++;
-    }
   }
-
-  if (!fIsMUONTrack) return;
+  
+  if (!fIsMUONTrack && !fIsESDTrack) return;
 
   Int_t nrc = 0;
-  if (mtrack->GetMatchTrigger() && 1) {
+  if (mtrack->GetMatchTrigger()) {
 
     for (Int_t i = 0; i < nTrackHits; i++) {
       if (TMath::Abs(zr[i]) > 1000.0) {
@@ -769,7 +643,7 @@ void AliEveMUONTrack::MakeMUONTriggerTrack(AliMUONTriggerTrack *mtrack)
 
   char form[1000];
 
-  sprintf(form,"MUONTriggerTrack %2d",mtrack->GetLoTrgNum());
+  snprintf(form,1000,"MUONTriggerTrack %2d",mtrack->GetLoTrgNum());
   SetName(form);
   SetLineStyle(1);
 
@@ -784,53 +658,27 @@ void AliEveMUONTrack::MakeESDTrack(AliESDMuonTrack *mtrack)
 
   fIsESDTrack = kTRUE;
 
-  fTrack = new AliMUONTrack();
-  AliMUONTrackParam trackParam;
-  AliMUONESDInterface::GetParamAtVertex(*mtrack, trackParam);
-  fTrack->SetTrackParamAtVertex(&trackParam);
-  fTrack->SetMatchTrigger(mtrack->GetMatchTrigger());
-
   char form[1000];
-  sprintf(form,"ESDTrack %2d ", fLabel);
+  if (mtrack->GetMatchTrigger()) {
+    sprintf(form,"ESDTrack %2d (MT)", fLabel);
+  } else {
+    sprintf(form,"ESDTrack %2d     ", fLabel);
+  }
   SetName(form);
   SetLineStyle(3);
   SetLineColor(0);
 
-  Double_t vect[7], vout[7];
-  Double_t step = 1.0;
-
-  Int_t charge = (Int_t)TMath::Sign(1.0,trackParam.GetInverseBendingMomentum());
-  Float_t pv[3];
-  pv[0] = trackParam.Px();
-  pv[1] = trackParam.Py();
-  pv[2] = trackParam.Pz();
-  fP.Set(pv);
-
-  vect[0] = trackParam.GetNonBendingCoor();
-  vect[1] = trackParam.GetBendingCoor();
-  vect[2] = trackParam.GetZ();
-  vect[3] = trackParam.Px()/trackParam.P();
-  vect[4] = trackParam.Py()/trackParam.P();
-  vect[5] = trackParam.Pz()/trackParam.P();
-  vect[6] = trackParam.P();
+  fTrack = new AliMUONTrack();
 
-  //cout << "vertex " << vect[0] << "   " << vect[1] << "   " << vect[2] << "   " << endl;
-
-  Double_t zMax = -1750.0;
-  Double_t rMax =   350.0;
-  Double_t r    =     0.0;
-
-  Int_t nSteps = 0;
-  while ((vect[2] > zMax) && (nSteps < 10000) && (r < rMax)) {
-    nSteps++;
-    OneStepRungekutta(charge, step, vect, vout);
-    SetPoint(fCount,vout[0],vout[1],vout[2]);
-    fCount++;
-    for (Int_t i = 0; i < 7; i++) {
-      vect[i] = vout[i];
-    }
-    r = TMath::Sqrt(vect[0]*vect[0]+vect[1]*vect[1]);
-  }
+  // create a simple track from the ESD track
+  AliMUONESDInterface::ESDToMUON(*mtrack,*fTrack);
+  
+  // reset track parameters at vertex to the ones at DCA
+  AliMUONTrackParam paramAtDCA;
+  AliMUONESDInterface::GetParamAtDCA(*mtrack, paramAtDCA);
+  fTrack->SetTrackParamAtVertex(&paramAtDCA);
+  
+  MakeMUONTrack(fTrack);
 
 }
 
@@ -930,23 +778,23 @@ void AliEveMUONTrack::Propagate(Float_t *xr, Float_t *yr, Float_t *zr, Int_t i1,
 
   trackParamAtCluster = fTrack->GetTrackParamAtCluster();
 
-  if (IsMUONTrack()) {
+  if (IsMUONTrack() || IsESDTrack()) {
     trackParam = (AliMUONTrackParam*)trackParamAtCluster->At(i1);
-    charge = (Int_t)TMath::Sign(1.0,trackParam->GetInverseBendingMomentum());
+    charge = (Int_t)trackParam->GetCharge();
   }
   if (IsRefTrack()) {
     trackParam = fTrack->GetTrackParamAtVertex();
-    charge = (Int_t)TMath::Sign(1.0,trackParam->GetInverseBendingMomentum());
+    charge = (Int_t)trackParam->GetCharge();
     trackParam = (AliMUONTrackParam*)trackParamAtCluster->At(i1);
   }
 
   vect[0] = xr[i1];
   vect[1] = yr[i1];
   vect[2] = zr[i1];
-  vect[3] = trackParam->Px()/trackParam->P();
-  vect[4] = trackParam->Py()/trackParam->P();
-  vect[5] = trackParam->Pz()/trackParam->P();
   vect[6] = trackParam->P();
+  vect[3] = trackParam->Px()/vect[6];
+  vect[4] = trackParam->Py()/vect[6];
+  vect[5] = trackParam->Pz()/vect[6];
 
   Int_t nSteps = 0;
   while ((vect[2] > zMax) && (nSteps < 10000)) {
@@ -961,37 +809,6 @@ void AliEveMUONTrack::Propagate(Float_t *xr, Float_t *yr, Float_t *zr, Int_t i1,
 
 }
 
-//______________________________________________________________________________
-void AliEveMUONTrack::GetField(Double_t *position, Double_t *field)
-{
-  //
-  // returns field components at position, for a give field map
-  //
-
-  /// interface for arguments in double precision (Why ? ChF)
-  Float_t x[3], b[3];
-
-  x[0] = position[0]; x[1] = position[1]; x[2] = position[2];
-
-  if (fgFieldMap) {
-    fgFieldMap->Field(x,b);
-  }
-  else {
-    AliWarning("No field map");
-    field[0] = field[1] = field[2] = 0.0;
-    return;
-  }
-
-  // force components
-  //b[1] = 0.0;
-  //b[2] = 0.0;
-
-  field[0] = b[0]; field[1] = b[1]; field[2] = b[2];
-
-  return;
-
-}
-
 //______________________________________________________________________________
 void AliEveMUONTrack::OneStepRungekutta(Double_t charge, Double_t step,
                                  Double_t* vect, Double_t* vout)
@@ -1070,8 +887,7 @@ void AliEveMUONTrack::OneStepRungekutta(Double_t charge, Double_t step,
       rest  = step - tl;
       if (TMath::Abs(h) > TMath::Abs(rest)) h = rest;
       //cmodif: call gufld(vout,f) changed into:
-
-      GetField(vout,f);
+      TGeoGlobalMagField::Instance()->Field(vout,f);
 
       // *
       // *             start of integration
@@ -1115,7 +931,7 @@ void AliEveMUONTrack::OneStepRungekutta(Double_t charge, Double_t step,
       xyzt[2] = zt;
 
       //cmodif: call gufld(xyzt,f) changed into:
-      GetField(xyzt,f);
+      TGeoGlobalMagField::Instance()->Field(xyzt,f);
 
       at     = a + secxs[0];
       bt     = b + secys[0];
@@ -1152,7 +968,7 @@ void AliEveMUONTrack::OneStepRungekutta(Double_t charge, Double_t step,
       xyzt[2] = zt;
 
       //cmodif: call gufld(xyzt,f) changed into:
-      GetField(xyzt,f);
+      TGeoGlobalMagField::Instance()->Field(xyzt,f);
 
       z      = z + (c + (seczs[0] + seczs[1] + seczs[2]) * kthird) * h;
       y      = y + (b + (secys[0] + secys[1] + secys[2]) * kthird) * h;
@@ -1245,7 +1061,7 @@ Int_t AliEveMUONTrack::ColorIndex(Float_t val)
   //
 
   Float_t threshold =  0.0;
-  Float_t maxVal    =  2.0;
+  Float_t maxVal    = 10.0;
 
   Float_t div  = TMath::Max(1, (Int_t)(maxVal - threshold));
   Int_t   nCol = gStyle->GetNumberOfColors();
@@ -1254,3 +1070,32 @@ Int_t AliEveMUONTrack::ColorIndex(Float_t val)
   return gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin));
 
 }
+
+//==============================================================================
+// Temporary AliEveMUONTrackList
+//==============================================================================
+
+//______________________________________________________________________________
+void AliEveMUONTrackList::HackMomentumLimits(Bool_t recurse)
+{
+  // Find momentum limits from included tracks.
+
+  fLimPt = fLimP = 0;
+
+  for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
+  {
+    TEveTrack* track = dynamic_cast<TEveTrack*>(*i);
+    if (track)
+    {
+      fLimPt = TMath::Max(fLimPt, track->GetMomentum().Perp());
+      fLimP  = TMath::Max(fLimP,  track->GetMomentum().Mag());
+    }
+    if (recurse)
+      FindMomentumLimits(*i, recurse);
+  }
+
+  fLimPt = RoundMomentumLimit(fLimPt);
+  fLimP  = RoundMomentumLimit(fLimP);
+  if (fMaxPt == 0) fMaxPt = fLimPt;
+  if (fMaxP  == 0) fMaxP  = fLimP;
+}