Cache the InversePitch instead of computing it each time.
[u/mrichter/AliRoot.git] / MUON / AliMUONMathieson.cxx
index 3e4a5726489e14c33c37cb168b76b0308a19d390..862b1f9894aa6bf972ffd80bf1edb53eee87349f 100644 (file)
 
 /* $Id$ */
 
-#include <TMath.h>
-#include <TRandom.h>
-
 #include "AliMUONMathieson.h"
-#include "AliSegmentation.h"
+
+#include "AliLog.h"
 #include "AliMUONGeometrySegmentation.h"
 
+#include <TClass.h>
+#include <TMath.h>
+#include <TRandom.h>
 
 ClassImp(AliMUONMathieson)
        
@@ -33,7 +34,8 @@ ClassImp(AliMUONMathieson)
     fSqrtKy3(0.),
     fKy2(0.),
     fKy4(0.),
-    fPitch(0.)
+    fPitch(0.),
+    fInversePitch(0.)
 {
 // Default constructor
 
@@ -64,58 +66,60 @@ void AliMUONMathieson::SetSqrtKy3AndDeriveKy2Ky4(Float_t SqrtKy3)
   Float_t cy1 = fKy2 * fSqrtKy3 / 4. / TMath::ATan(Double_t(fSqrtKy3));
   fKy4 = cy1 / fKy2 / fSqrtKy3;
 }
-// -------------------------------------------
-Float_t AliMUONMathieson::IntXY(AliSegmentation * segmentation)
-{
-// Calculate charge on current pad according to Mathieson distribution
-// 
-    const Float_t kInversePitch = 1/fPitch;      
-//
-//  Integration limits defined by segmentation model
-//  
-    Float_t xi1, xi2, yi1, yi2;
-    segmentation->IntegrationLimits(xi1,xi2,yi1,yi2);
-    xi1=xi1*kInversePitch;
-    xi2=xi2*kInversePitch;
-    yi1=yi1*kInversePitch;
-    yi2=yi2*kInversePitch;
-//
-// The Mathieson function 
-    Double_t ux1=fSqrtKx3*TMath::TanH(fKx2*xi1);
-    Double_t ux2=fSqrtKx3*TMath::TanH(fKx2*xi2);
 
-    Double_t uy1=fSqrtKy3*TMath::TanH(fKy2*yi1);
-    Double_t uy2=fSqrtKy3*TMath::TanH(fKy2*yi2);
-
-    
-    return Float_t(4.*fKx4*(TMath::ATan(ux2)-TMath::ATan(ux1))*
-                     fKy4*(TMath::ATan(uy2)-TMath::ATan(uy1)));
+//_____________________________________________________________________________
+Float_t
+AliMUONMathieson::IntXY(Float_t xi1, Float_t yi1, Float_t xi2, Float_t yi2) const
+{
+  //
+  // Integrate the Mathieson over x and y
+  //
+  xi1 *= fInversePitch;
+  xi2 *= fInversePitch;
+  yi1 *= fInversePitch;
+  yi2 *= fInversePitch;
+  //
+  // The Mathieson function 
+  Double_t ux1=fSqrtKx3*TMath::TanH(fKx2*xi1);
+  Double_t ux2=fSqrtKx3*TMath::TanH(fKx2*xi2);
+  
+  Double_t uy1=fSqrtKy3*TMath::TanH(fKy2*yi1);
+  Double_t uy2=fSqrtKy3*TMath::TanH(fKy2*yi2);
+  
+  
+  return Float_t(4.*fKx4*(TMath::ATan(ux2)-TMath::ATan(ux1))*
+                 fKy4*(TMath::ATan(uy2)-TMath::ATan(uy1)));
 }
+
 // -------------------------------------------
 Float_t AliMUONMathieson::IntXY(Int_t idDE, AliMUONGeometrySegmentation* segmentation)
 {
 // Calculate charge on current pad according to Mathieson distribution
 // using Detection elt
-   
-    const Float_t kInversePitch = 1./fPitch;
 //
 //  Integration limits defined by segmentation model
 //  
     Float_t xi1, xi2, yi1, yi2;
     segmentation->IntegrationLimits(idDE, xi1,xi2,yi1,yi2);
-    xi1=xi1*kInversePitch;
-    xi2=xi2*kInversePitch;
-    yi1=yi1*kInversePitch;
-    yi2=yi2*kInversePitch;
-//
-// The Mathieson function 
-    Double_t ux1=fSqrtKx3*TMath::TanH(fKx2*xi1);
-    Double_t ux2=fSqrtKx3*TMath::TanH(fKx2*xi2);
-
-    Double_t uy1=fSqrtKy3*TMath::TanH(fKy2*yi1);
-    Double_t uy2=fSqrtKy3*TMath::TanH(fKy2*yi2);
+    return IntXY(xi1,yi1,xi2,yi2);
+}
 
-    
-    return Float_t(4.*fKx4*(TMath::ATan(ux2)-TMath::ATan(ux1))*
-                     fKy4*(TMath::ATan(uy2)-TMath::ATan(uy1)));
+//______________________________________________________________________________
+void 
+AliMUONMathieson::SetPitch(Float_t p1)
+{
+  //
+  // Defines the pitch, and store its inverse, which is what is used in fact.
+  //
+  fPitch = p1;
+  if ( fPitch )
+  {
+    fInversePitch = 1/fPitch;
+  }
+  else
+  {
+    AliError(Form("Invalid pitch %e",p1));
+    fInversePitch = 0.0;
+  }
 }
+