]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/flow/AliFMDFlowBessel.cxx
Creating the TOFQA.root file before the QA histograms and the calibration tree (Chiara)
[u/mrichter/AliRoot.git] / FMD / flow / AliFMDFlowBessel.cxx
index 89488ba30e6a3ee3652d82ab9bf7cacc53ff9784..5e7566ff49a3e26064cd3f511b13244bf072a029 100644 (file)
@@ -48,8 +48,8 @@ namespace
     Double_t f1 = Envj(n1, a0) - mp;
     Int_t    nn = 0;
     for (UInt_t i = 0; i < 20; i++) { 
-      nn = n1 - (n1 - n0) / (1. - f0 / f1);
-      if (fabs(nn - n1) < 1) break;
+      nn = Int_t(n1 - (n1 - n0) / (1. - f0 / f1));
+      if (fabs(Double_t(nn - n1)) < 1) break;
       n0 = n1;
       f0 = f1;
       n1 = nn;
@@ -193,7 +193,7 @@ AliFMDFlowBessel::Ihalf(Int_t n, Double_t x, Double_t* bi, Double_t* di)
   // Double_t tdi[p*n/2+2];
   
   // Calculate I(-1/2) for n>0 or I(1/2) for n<0 
-  Double_t bim = sqrt(2) * (*c)(x) / sqrt(M_PI * x);
+  Double_t bim = sqrt(Double_t(2)) * (*c)(x) / sqrt(M_PI * x);
 
   // We calculate one more than n, that is we calculate 
   //   I(1/2), I(3/2),...,I(n/2+1) 
@@ -285,6 +285,25 @@ AliFMDFlowBessel::Iwhole(UInt_t in, Double_t x, Double_t* bi, Double_t* di)
   return mn;
 }
 
+//____________________________________________________________________
+namespace 
+{
+  Double_t* EnsureSize(Double_t*& a, UInt_t& old, const UInt_t size)
+  {
+    if (a && old < size) { 
+      // Will delete, and reallocate. 
+      if (old != 1) delete [] a;
+      a = 0;
+    }
+    if (!a && size > 0) {
+      // const UInt_t n = (size <= 1 ? 2 : size);
+      a              = new Double_t[size];
+      old            = size; // n;
+    }
+    return a;
+  }
+}
+      
 //____________________________________________________________________
 UInt_t 
 AliFMDFlowBessel::Inu(Double_t n1, Double_t n2, Double_t x, 
@@ -296,6 +315,10 @@ AliFMDFlowBessel::Inu(Double_t n1, Double_t n2, Double_t x,
   UInt_t  in1 = UInt_t(fabs(n1));
   UInt_t  in2 = UInt_t(fabs(n2));
   UInt_t  nt  = UInt_t(n2 - n1 + 1);
+  static Double_t* tbi = 0;
+  static Double_t* tdi = 0;
+  static UInt_t    tn  = 0;
+
   if (Int_t(2 * fabs(n1)) % 2 == 1) { // Half-integer argument 
     if (Int_t(2 * fabs(n2)) % 2 != 1) { 
       std::cout << "If n1 is half-integer (" << n1 << ") then n2 "
@@ -310,20 +333,12 @@ AliFMDFlowBessel::Inu(Double_t n1, Double_t n2, Double_t x,
     Int_t l2    = (s1 > 0 ? in1 : 0);
 
     // Temporary buffers - only grows in size. 
-    static Double_t* tbi = 0;
-    static Double_t* tdi = 0;
-    static UInt_t    tn  = 0;
-    if (!tbi || tn < nt+1) { 
-      if (tbi) delete [] tbi;
-      if (tdi) delete [] tdi;
-      tn  = nt+1;
-      tbi = new Double_t[tn];
-      tdi = new Double_t[tn];
-    }
+    tbi = EnsureSize(tbi, tn, nt+1);
+    tdi = EnsureSize(tdi, tn, nt+1);
     // Double_t tbi[nt+1], tdi[nt+1];
 
     if (s1 < 0) { 
-      Ihalf(2 * n1, x, tbi, tdi);
+      Ihalf(Int_t(2 * n1), x, tbi, tdi);
       for (Int_t i = 0; i < l1 && i < Int_t(nt); i++) { 
        bi[i] = tbi[i];
        di[i] = tdi[i];
@@ -331,7 +346,7 @@ AliFMDFlowBessel::Inu(Double_t n1, Double_t n2, Double_t x,
     }
     if (s2 > 0) { 
       // std::cout << "Evaluating Ihalf(" << 2 * n2 << "," << x << ",...)";
-      Ihalf(2 * n2, x, tbi, tdi);
+      Ihalf(Int_t(2 * n2), x, tbi, tdi);
       for (Int_t i = l1; i <= 2 * Int_t(in2) && i < Int_t(nt); i++) { 
        UInt_t j = i + l2 - l1;
        bi[i] = tbi[j];
@@ -348,24 +363,18 @@ AliFMDFlowBessel::Inu(Double_t n1, Double_t n2, Double_t x,
   }
 
   UInt_t  n   = UInt_t(in1 > in2 ? in1 : in2);
-  static Double_t* tbi = 0;
-  static Double_t* tdi = 0;
-  static UInt_t    tn  = 0;
-  if (!tbi || tn < n+1) { 
-    if (tbi) delete [] tbi;
-    if (tdi) delete [] tdi;
-    tn  = n+1;
-    tbi = new Double_t[tn];
-    tdi = new Double_t[tn];
-  }
+  // Temporary buffers - only grows in size. 
+  tbi = EnsureSize(tbi, tn, n+1);
+  tdi = EnsureSize(tdi, tn, n+1);
   // Double_t  tbi[n+1];
   // Double_t  tdi[n+1];
+
   UInt_t  r   = Iwhole(n, x, tbi, tdi);
   if (r < n) 
     std::cerr << "Only got " << r << "/" << n << " values" 
              << std::endl;
   for (UInt_t i = 0; i < nt; i++) { 
-    UInt_t j = (i + n1 < 0 ? -n1-i : n1+i);
+    UInt_t j = UInt_t(i + n1 < 0 ? -n1-i : n1+i);
     bi[i]    = tbi[j];
     di[i]    = tdi[j];
   }