coverity fix
[u/mrichter/AliRoot.git] / TPC / AliTPCPRF2D.cxx
index 7ec8a35..4f8d636 100644 (file)
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-
-#include "TMath.h"
-#include "AliTPCPRF2D.h"
-#include "TF2.h"
 #include <Riostream.h>
+#include <TCanvas.h>
+#include <TClass.h>
+#include <TF2.h>
+#include <TH1.h> 
+#include <TMath.h>
+#include <TPad.h>
+#include <TPaveText.h>
+#include <TStyle.h>
+#include <TText.h>
 #include <string.h>
-#include "TCanvas.h"
-#include "TPad.h"
-#include "TStyle.h"
-#include "TH1.h" 
-#include "AliH2F.h"
 
+#include "AliH2F.h"
+#include "AliTPCPRF2D.h"
 
-#include "TPaveText.h"
-#include "TText.h"
 
 extern TStyle * gStyle;
 
@@ -52,7 +52,7 @@ const Double_t AliTPCPRF2D::fgkSQRT12=3.464101;
 const Int_t   AliTPCPRF2D::fgkNPRF = 100;
 
 
-static Double_t funGauss2D(Double_t *x, Double_t * par)
+static Double_t FunGauss2D(const Double_t *const x, const Double_t *const par)
 { 
 //Gauss function  -needde by the generic function object 
   return ( TMath::Exp(-(x[0]*x[0])/(2*par[0]*par[0]))*
@@ -60,14 +60,14 @@ static Double_t funGauss2D(Double_t *x, Double_t * par)
 
 }
 
-static Double_t funCosh2D(Double_t *x, Double_t * par)
+static Double_t FunCosh2D(const Double_t *const x, const Double_t *const par)
 {
  //Cosh function  -needde by the generic function object 
   return ( 1/(TMath::CosH(3.14159*x[0]/(2*par[0]))*
           TMath::CosH(3.14159*x[1]/(2*par[1]))));
 }    
 
-static Double_t funGati2D(Double_t *x, Double_t * par)
+static Double_t FunGati2D(const Double_t *const x, const Double_t *const par)
 {
   //Gati function  -needde by the generic function object 
   Float_t k3=par[1];
@@ -96,23 +96,50 @@ static Double_t funGati2D(Double_t *x, Double_t * par)
 ClassImp(AliTPCPRF2D)
 
 AliTPCPRF2D::AliTPCPRF2D()
+            :TObject(),
+             fcharge(0),
+             fY1(0.),
+             fY2(0.),
+             fNYdiv(0),
+             fNChargeArray(0),
+             fChargeArray(0),
+             fHeightFull(0.),
+             fHeightS(0.),
+             fShiftY(0.),
+             fWidth(0.),
+             fK(0.),
+             fNPRF(0),
+             fNdiv(5),
+             fDStep(0.),
+             fKNorm(1.),
+             fInteg(0.),
+             fGRF(0),
+             fK3X(0.),
+             fK3Y(0.),
+             fPadDistance(0.),
+             fOrigSigmaX(0.),
+             fOrigSigmaY(0.),
+             fChargeAngle(0.),
+             fPadAngle(0.),
+             fSigmaX(0.),
+             fSigmaY(0.),
+             fMeanX(0.),
+             fMeanY(0.),
+             fInterX(0),
+             fInterY(0),
+             fCurrentY(0.),
+             fDYtoWire(0.),
+             fDStepM1(0.)             
 {
   //default constructor for response function object
-  fcharge = 0;
-  fNChargeArray = 0;
-  fChargeArray = 0;
+
   fNPRF =fgkNPRF ;
-  fSigmaX = 0;
-  fSigmaY = 0;
+  for(Int_t i=0;i<5;i++){
+        funParam[i]=0.;
+        fType[i]=0;
+  }
+  
 
-  fGRF = 0;
-  fKNorm = 1;
-  fOrigSigmaY=0;
-  fOrigSigmaX=0;
-  fNdiv = 5;
-  //set daault angels
-  fChargeAngle = 0;
-  fPadAngle = 0;
   //chewron default values   
   SetPad(0.8,0.8);
   SetChevron(0.2,0.0,1.0);
@@ -177,42 +204,39 @@ Float_t AliTPCPRF2D::GetPRF(Float_t xin, Float_t yin)
     fcharge   = &(fChargeArray[i*fNPRF]);
     return GetPRFActiv(xin);
   }
-  else{
-    //make interpolation from more fore lines
-    Int_t i= Int_t(y);
-    Float_t res;
-    if ((i<0) || (i>=fNYdiv) ) return 0;
-    Float_t z0=0;
-    Float_t z1=0;
-    Float_t z2=0;
-    Float_t z3=0;
-    if (i>0) {
-      fcharge =&(fChargeArray[(i-1)*fNPRF]);
-      z0 = GetPRFActiv(xin);
-    }
-    fcharge =&(fChargeArray[i*fNPRF]);
-    z1=GetPRFActiv(xin);
-    if ((i+1)<fNYdiv){
-      fcharge =&(fChargeArray[(i+1)*fNPRF]);
-      z2 = GetPRFActiv(xin);
-    }
-    if ((i+2)<fNYdiv){
-      fcharge =&(fChargeArray[(i+2)*fNPRF]);
-      z3 = GetPRFActiv(xin);
-    }
-    Float_t a,b,c,d,k,l;
-    a=z1;
-    b=(z2-z0)/2.;
-    k=z2-a-b;
-    l=(z3-z1)/2.-b;
-    d=l-2*k;
-    c=k-d;
-    Float_t dy=y-Float_t(i);
-
-    res = a+b*dy+c*dy*dy+d*dy*dy*dy;  
-    return res;            
-  }        
-  return 0.;
+  //make interpolation from more fore lines
+  Int_t i= Int_t(y);
+  Float_t res;
+  if ((i<0) || (i>=fNYdiv) ) return 0;
+  Float_t z0=0;
+  Float_t z1=0;
+  Float_t z2=0;
+  Float_t z3=0;
+  if (i>0) {
+    fcharge =&(fChargeArray[(i-1)*fNPRF]);
+    z0 = GetPRFActiv(xin);
+  }
+  fcharge =&(fChargeArray[i*fNPRF]);
+  z1=GetPRFActiv(xin);
+  if ((i+1)<fNYdiv){
+    fcharge =&(fChargeArray[(i+1)*fNPRF]);
+    z2 = GetPRFActiv(xin);
+  }
+  if ((i+2)<fNYdiv){
+    fcharge =&(fChargeArray[(i+2)*fNPRF]);
+    z3 = GetPRFActiv(xin);
+  }
+  Float_t a,b,c,d,k,l;
+  a=z1;
+  b=(z2-z0)/2.;
+  k=z2-a-b;
+  l=(z3-z1)/2.-b;
+  d=l-2*k;
+  c=k-d;
+  Float_t dy=y-Float_t(i);
+  
+  res = a+b*dy+c*dy*dy+d*dy*dy*dy;  
+  return res;            
 } 
 
 
@@ -250,7 +274,7 @@ Float_t  AliTPCPRF2D::GetGRF(Float_t xin, Float_t yin)
 }
 
    
-void AliTPCPRF2D::SetParam( TF2 * GRF,  Float_t kNorm, 
+void AliTPCPRF2D::SetParam( TF2 *const GRF,  Float_t kNorm, 
                       Float_t sigmaX, Float_t sigmaY)
 {
   //adjust parameters of the original charge distribution
@@ -258,7 +282,8 @@ void AliTPCPRF2D::SetParam( TF2 * GRF,  Float_t kNorm,
    if (fGRF !=0 ) fGRF->Delete();
    fGRF = GRF;
    fKNorm = kNorm;
-   sprintf(fType,"User");
+   //sprintf(fType,"User");
+   snprintf(fType,5,"User");
    if (sigmaX ==0) sigmaX=(fWidth*(1+TMath::Abs(fK)))/fgkSQRT12;
    if (sigmaY ==0) sigmaY=(fWidth*(1+TMath::Abs(fK)))/fgkSQRT12;
    fOrigSigmaX=sigmaX; 
@@ -288,9 +313,10 @@ void AliTPCPRF2D::SetGauss(Float_t sigmaX, Float_t sigmaY,
   fKNorm = kNorm;
   fOrigSigmaX=sigmaX;
   fOrigSigmaY=sigmaY;
-  sprintf(fType,"Gauss");
+  //sprintf(fType,"Gauss");
+  snprintf(fType,5,"Gauss");
   if (fGRF !=0 ) fGRF->Delete();
-  fGRF = new TF2("fun",funGauss2D,-5.,5.,-5.,5.,4);
+  fGRF = new TF2("FunGauss2D",FunGauss2D,-5.,5.,-5.,5.,4);
   
   funParam[0]=sigmaX;
   funParam[1]=sigmaY;  
@@ -321,9 +347,10 @@ void AliTPCPRF2D::SetCosh(Float_t sigmaX, Float_t sigmaY,
   fKNorm = kNorm;
   fOrigSigmaX=sigmaX;
   fOrigSigmaY=sigmaY; 
-  sprintf(fType,"Cosh");
+  //  sprintf(fType,"Cosh");
+  snprintf(fType,5,"Cosh");
   if (fGRF !=0 ) fGRF->Delete();
-  fGRF = new TF2("fun",        funCosh2D,-5.,5.,-5.,5.,4);   
+  fGRF = new TF2("FunCosh2D",  FunCosh2D,-5.,5.,-5.,5.,4);   
   funParam[0]=sigmaX;
   funParam[1]=sigmaY;
   funParam[2]=fK;  
@@ -352,9 +379,10 @@ void AliTPCPRF2D::SetGati(Float_t K3X, Float_t K3Y,
   fK3X=K3X;
   fK3Y=K3Y;
   fPadDistance=padDistance;  
-  sprintf(fType,"Gati");
+  //sprintf(fType,"Gati");
+  snprintf(fType,5,"Gati");
   if (fGRF !=0 ) fGRF->Delete();
-  fGRF = new TF2("fun",        funGati2D,-5.,5.,-5.,5.,5);  
+  fGRF = new TF2("FunGati2D",  FunGati2D,-5.,5.,-5.,5.,5);  
  
   funParam[0]=padDistance;
   funParam[1]=K3X;
@@ -645,30 +673,30 @@ void AliTPCPRF2D::UpdateSigma()
 }
 
 
-void AliTPCPRF2D::Streamer(TBuffer &R__b)
+void AliTPCPRF2D::Streamer(TBuffer &xRuub)
 {
    // Stream an object of class AliTPCPRF2D
 
-   if (R__b.IsReading()) {
-      UInt_t R__s, R__c;
-      Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
-      AliTPCPRF2D::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
+   if (xRuub.IsReading()) {
+      UInt_t xRuus, xRuuc;
+      Version_t xRuuv = xRuub.ReadVersion(&xRuus, &xRuuc);
+      AliTPCPRF2D::Class()->ReadBuffer(xRuub, this, xRuuv, xRuus, xRuuc);
       //read functions
       if (strncmp(fType,"User",3)!=0){
        delete fGRF;  
         if (strncmp(fType,"Gauss",3)==0) 
-         fGRF = new TF2("fun",funGauss2D,-5.,5.,-5.,5.,4);
+         fGRF = new TF2("FunGauss2D",FunGauss2D,-5.,5.,-5.,5.,4);
         if (strncmp(fType,"Cosh",3)==0) 
-         fGRF = new TF2("fun",funCosh2D,-5.,5.,-5.,5.,4);
+         fGRF = new TF2("FunCosh2D",FunCosh2D,-5.,5.,-5.,5.,4);
         if (strncmp(fType,"Gati",3)==0) 
-         fGRF = new TF2("fun",funGati2D,-5.,5.,-5.,5.,5);      
+         fGRF = new TF2("FunGati2D",FunGati2D,-5.,5.,-5.,5.,5);      
         if (fGRF!=0) fGRF->SetParameters(funParam);
       }
       //calculate conversion coefitient to convert position to virtual wire
       fDYtoWire=Float_t(fNYdiv-1)/(fY2-fY1);
       fDStepM1=1/fDStep;
    } else {
-      AliTPCPRF2D::Class()->WriteBuffer(R__b,this);
+      AliTPCPRF2D::Class()->WriteBuffer(xRuub,this);
    }
 }
 
@@ -679,7 +707,8 @@ TH1F *  AliTPCPRF2D::GenerDrawXHisto(Float_t x1, Float_t x2,Float_t y)
   //  at position y 
   char s[100]; 
   const Int_t kn=200;
-  sprintf(s,"Pad Response Function");  
+  //sprintf(s,"Pad Response Function"); 
+  snprintf(s,100,"Pad Response Function");  
   TH1F * hPRFc = new TH1F("hPRFc",s,kn+1,x1,x2);
   Float_t x=x1;
   Float_t y1;
@@ -700,7 +729,8 @@ AliH2F * AliTPCPRF2D::GenerDrawHisto(Float_t x1, Float_t x2, Float_t y1, Float_t
   //gener two dimensional histogram with PRF
   //
   char s[100];
-  sprintf(s,"Pad Response Function");  
+  //sprintf(s,"Pad Response Function"); 
+  snprintf(s,100,"Pad Response Function");  
   AliH2F * hPRFc = new AliH2F("hPRFc",s,Nx,x1,x2,Ny,y1,y2);
   Float_t dx=(x2-x1)/Float_t(Nx);
   Float_t dy=(y2-y1)/Float_t(Ny) ;
@@ -728,7 +758,8 @@ AliH2F * AliTPCPRF2D::GenerDrawDistHisto(Float_t x1, Float_t x2, Float_t y1, Flo
   const Float_t kminth=0.00001;
   if (thr<kminth) thr=kminth;
   char s[100]; 
-  sprintf(s,"COG distortion of PRF (threshold=%2.2f)",thr);  
+  //sprintf(s,"COG distortion of PRF (threshold=%2.2f)",thr); 
+  snprintf(s,100,"COG distortion of PRF (threshold=%2.2f)",thr); 
   AliH2F * hPRFDist = new AliH2F("hDistortion",s,Nx,x1,x2,Ny,y1,y2);
   Float_t dx=(x2-x1)/Float_t(Nx);
   Float_t dy=(y2-y1)/Float_t(Ny) ;
@@ -797,9 +828,11 @@ void AliTPCPRF2D::DrawX(Float_t x1 ,Float_t x2,Float_t y1,Float_t y2, Int_t N)
     else y = y1+i*(y2-y1)/Float_t(N-1);
     pad2->cd(i+1);
     TH1F * hPRFc =GenerDrawXHisto(x1, x2,y);
-    sprintf(ch,"PRF at wire position: %2.3f",y);
+    //sprintf(ch,"PRF at wire position: %2.3f",y);
+    snprintf(ch,40,"PRF at wire position: %2.3f",y);
     hPRFc->SetTitle(ch);  
-    sprintf(ch,"PRF %d",i);
+    //sprintf(ch,"PRF %d",i);
+    snprintf(ch,15,"PRF %d",i);
     hPRFc->SetName(ch);  
      hPRFc->Fit("gaus");
   }
@@ -870,55 +903,74 @@ void AliTPCPRF2D::DrawComment(TPaveText *comment)
   //draw comments to picture
   TText * title = comment->AddText("Pad Response Function  parameters:");
   title->SetTextSize(0.03);
-  sprintf(s,"Height of pad:  %2.2f cm",fHeightFull);
+  //sprintf(s,"Height of pad:  %2.2f cm",fHeightFull);
+  snprintf(s,100,"Height of pad:  %2.2f cm",fHeightFull);
   comment->AddText(s);
-  sprintf(s,"Width pad:  %2.2f cm",fWidth);
+  //sprintf(s,"Width pad:  %2.2f cm",fWidth);
+  snprintf(s,100,"Width pad:  %2.2f cm",fWidth);
   comment->AddText(s);
-  sprintf(s,"Pad Angle:  %2.2f ",fPadAngle);
+  //sprintf(s,"Pad Angle:  %2.2f ",fPadAngle);
+  snprintf(s,100,"Pad Angle:  %2.2f ",fPadAngle);
   comment->AddText(s);
   
   if (TMath::Abs(fK)>0.0001){
-    sprintf(s,"Height of one chevron unit h:  %2.2f cm",2*fHeightS);
+    //sprintf(s,"Height of one chevron unit h:  %2.2f cm",2*fHeightS);
+    snprintf(s,100,"Height of one chevron unit h:  %2.2f cm",2*fHeightS);
     comment->AddText(s);
-    sprintf(s,"Overlap factor:  %2.2f",fK);
+    //sprintf(s,"Overlap factor:  %2.2f",fK);
+    snprintf(s,100,"Overlap factor:  %2.2f",fK);
     comment->AddText(s); 
   }
 
   if (strncmp(fType,"User",3)==0){
-    sprintf(s,"Charge distribution - user defined function  %s ",fGRF->GetTitle());
+    //sprintf(s,"Charge distribution - user defined function  %s ",fGRF->GetTitle());
+    snprintf(s,100,"Charge distribution - user defined function  %s ",fGRF->GetTitle());
     comment->AddText(s);  
-    sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    //sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    snprintf(s,100,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);  
     comment->AddText(s);  
-    sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    //sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    snprintf(s,100,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
     comment->AddText(s); 
   }
   if (strncmp(fType,"Gauss",3)==0){
-    sprintf(s,"Gauss charge distribution");
+    //sprintf(s,"Gauss charge distribution");
+    snprintf(s,100,"Gauss charge distribution");
     comment->AddText(s);  
-    sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    //sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    snprintf(s,100,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
     comment->AddText(s);  
-    sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    //sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    snprintf(s,100,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
     comment->AddText(s); 
   }
   if (strncmp(fType,"Gati",3)==0){
-    sprintf(s,"Gati charge distribution");
+    //sprintf(s,"Gati charge distribution");
+    snprintf(s,100,"Gati charge distribution");
     comment->AddText(s);  
-    sprintf(s,"K3X of Gati : %2.2f ",fK3X);
+    //sprintf(s,"K3X of Gati : %2.2f ",fK3X);
+    snprintf(s,100,"K3X of Gati : %2.2f ",fK3X);
     comment->AddText(s);  
-    sprintf(s,"K3Y of Gati: %2.2f ",fK3Y);
+    //sprintf(s,"K3Y of Gati: %2.2f ",fK3Y);
+    snprintf(s,100,"K3Y of Gati: %2.2f ",fK3Y);
     comment->AddText(s); 
-    sprintf(s,"Wire to Pad Distance: %2.2f ",fPadDistance);
+    //sprintf(s,"Wire to Pad Distance: %2.2f ",fPadDistance);
+    snprintf(s,100,"Wire to Pad Distance: %2.2f ",fPadDistance);
     comment->AddText(s); 
   }
   if (strncmp(fType,"Cosh",3)==0){
-    sprintf(s,"Cosh charge distribution");
+    //sprintf(s,"Cosh charge distribution");
+    snprintf(s,100,"Cosh charge distribution");
     comment->AddText(s);  
-    sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    //sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    snprintf(s,100,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
     comment->AddText(s);  
-    sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    //sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    snprintf(s,100,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
     comment->AddText(s); 
   }
-  sprintf(s,"Normalisation: %2.2f ",fKNorm);
+  //sprintf(s,"Normalisation: %2.2f ",fKNorm);
+  snprintf(s,100,"Normalisation: %2.2f ",fKNorm);
   comment->AddText(s);    
 }