]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDESDRevertexer.cxx
Fix for Coverity warning 16208
[u/mrichter/AliRoot.git] / FMD / AliFMDESDRevertexer.cxx
index 1c2a497d0f551e8010051217d397a45e65d5555a..9174e73e28416df43f17ada7ed57f3b56c13a635 100644 (file)
@@ -1,19 +1,37 @@
 #include <AliFMDESDRevertexer.h>
 #include <AliFMDGeometry.h>
 #include <AliESDFMD.h>
+#include <TMath.h>
+#include <AliLog.h>
+
+ClassImp(AliFMDESDRevertexer)
+#if 0 // for emacs 
+;
+#endif
 
 //____________________________________________________________________
 AliFMDESDRevertexer::AliFMDESDRevertexer()
 {
   AliFMDGeometry* geom = AliFMDGeometry::Instance();
   geom->Init();
-  geom->InitTransforms();
+  geom->InitTransformations();
 }
 
 //____________________________________________________________________
 Bool_t
-AliFMDESDRevertexer::Revertex(AliESDFMD* fmdEsd, Double_t vz)
+AliFMDESDRevertexer::Revertex(AliESDFMD* fmdEsd, Double_t vz) const
 {
+  // Recalculate the various quantities based on updated 
+  // primary vertex position. 
+  // 
+  // Parameters: 
+  //    fmdEsd    FMD ESD object 
+  //    vz        New vertex location (along the z-axis)
+  //
+  // Return:
+  //    true on success, false if there was an error during the 
+  //    recalculations.   Please inspect log output for details. 
+  // 
   if (!fmdEsd) return kFALSE;
   
   Bool_t ret = kTRUE;
@@ -24,31 +42,36 @@ AliFMDESDRevertexer::Revertex(AliESDFMD* fmdEsd, Double_t vz)
       UShort_t nsec = (ir == 0 ?  20 :  40);
       UShort_t nstr = (ir == 0 ? 512 : 256);
       for (UShort_t str = 0; str < nstr; str++) { 
-       Double_t phi, r, theta, oldTheta;
+       Double_t phi, r, theta;
        Double_t eta      = AliESDFMD::kInvalidEta;
-       Double_t oldEta   = fmdEsd->Eta(det, rng, sec, str);
+       Double_t oldEta   = fmdEsd->Eta(det, rng, 0, str);
+       // if (oldEta == AliESDFMD::kInvalidEta) continue;
+
        Double_t oldTheta = Eta2Theta(oldEta);
        Bool_t   ret1     = PhysicalCoordinates(det, rng, 0, str, vz, 
-                                               eta, phi, r, theta));
-       fmdEsd->SetEta(det, rng, sec, str, eta);
+                                               eta, phi, r, theta);
+       fmdEsd->SetEta(det, rng, 0, str, eta);
 
        if (!ret1) {
          // If the was an error, then there's no reason to go on with
          // this strip-ring.  Note, that the eta is correctly set to
          // AliESDFMD::kInvalidMult. 
          AliWarning(Form("Failed to calculate eta, phi for "
-                         "FMD%d%c[%02d,%03d] with v_z=%9.4f" 
+                         "FMD%d%c[%02d,%03d] with v_z=%9.4f",
                          det, rng, 0, str, vz));
          ret = kFALSE;
          continue;
        }
-       
+
        Double_t corr = TMath::Abs(TMath::Cos(theta));
-       if (fmdEsd->IsAngleCorrected()) 
-         corr /= TMath::Abs(TMath::Cos(oldTheta));
-       for (UShort_t sec = 0; sec < nsec; sec++) { 
-         Double_t mult = fmdEsd->Multiplicity(det, rng, sec, str);
-         fmdEsd->SetMultiplicity(det, rng, sec, str, corr * mult);
+       if (fmdEsd->IsAngleCorrected()) {
+         if (oldEta != AliESDFMD::kInvalidMult)
+           corr /= TMath::Abs(TMath::Cos(oldTheta));
+         for (UShort_t sec = 0; sec < nsec; sec++) { 
+           Double_t mult = fmdEsd->Multiplicity(det, rng, sec, str);
+           if (mult == AliESDFMD::kInvalidMult) continue;
+           fmdEsd->SetMultiplicity(det, rng, sec, str, corr * mult);
+         }
        }
       }
     }
@@ -61,6 +84,7 @@ AliFMDESDRevertexer::Revertex(AliESDFMD* fmdEsd, Double_t vz)
 Double_t
 AliFMDESDRevertexer::Eta2Theta(Double_t eta) const
 {
+  if (eta == AliESDFMD::kInvalidEta) return 0;
   return 2 * TMath::ATan(TMath::Exp(-eta));
 }
 
@@ -84,17 +108,7 @@ AliFMDESDRevertexer::PhysicalCoordinates(UShort_t  det,
   Double_t x=0, y=0, z=0;
   geom->Detector2XYZ(det, rng, sec, str, x, y, z);
 
-  // Check that the conversion succeeded
-  if (x == 0 && y == 0 && z == 0) return kFALSE;
-  
-  // Correct for vertex offset. 
-  z     += vz;
-  phi   =  TMath::ATan2(y, x);
-  r     =  TMath::Sqrt(y * y + x * x);
-  theta =  TMath::ATan2(r, z);
-  eta   = -TMath::Log(TMath::Tan(theta / 2));
-
-  return kTRUE;
+  return AliFMDGeometry::XYZ2REtaPhiTheta(x, y, z-vz, r, eta, phi, theta);
 }