]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - CORRFW/AliCFDataGrid.cxx
Fixing the AddTask
[u/mrichter/AliRoot.git] / CORRFW / AliCFDataGrid.cxx
index d307e173bfde612550112082078887b086c1023e..30a9f5122d156f070c009f2f7bd541b9fe50d86c 100644 (file)
  **************************************************************************/
 //--------------------------------------------------------------------//
 //                                                                    //
-// AliCFDataGrid Class                                        //
+// AliCFDataGrid Class                                                //
 // Class to handle observed data and correct them                     // 
 //                                                                    //
 // -- Author : S.Arcelli                                              //
 //                                                                    //
-//                                                                    //
+// substantially modified by r. vernet                                //
 //                                                                    //
 //--------------------------------------------------------------------//
 //
@@ -34,31 +34,18 @@ ClassImp(AliCFDataGrid)
 
 //____________________________________________________________________
 AliCFDataGrid::AliCFDataGrid() : 
-  AliCFGrid(),
-  fSelData(-1),
-  fContainer(0x0)
-{
-  //
-  // default constructor
-  //
-  SumW2(); //errors saved
-}
-
-//____________________________________________________________________
-AliCFDataGrid::AliCFDataGrid(const Char_t* name,const Char_t* title) : 
-  AliCFGrid(name,title),
+  AliCFGridSparse(),
   fSelData(-1),
   fContainer(0x0)
 {
   //
   // default constructor
   //
-  SumW2(); //errors saved
 }
 
 //____________________________________________________________________
-AliCFDataGrid::AliCFDataGrid(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn, const Double_t *binLimitsIn) :  
-  AliCFGrid(name,title,nVarIn,nBinIn,binLimitsIn),
+AliCFDataGrid::AliCFDataGrid(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn) :
+  AliCFGridSparse(name,title,nVarIn,nBinIn),
   fSelData(-1),
   fContainer(0x0)
 {
@@ -67,22 +54,27 @@ AliCFDataGrid::AliCFDataGrid(const Char_t* name, const Char_t* title, const Int_
   //
   SumW2();// errors saved
 }
+
 //____________________________________________________________________
-AliCFDataGrid::AliCFDataGrid(const Char_t* name, const Char_t* title, const AliCFContainer &c) :  
-  AliCFGrid(name,title,c.GetNVar(),c.GetNBins(),c.GetBinLimits()),
-  fSelData(-1),
-  fContainer(0x0)
+AliCFDataGrid::AliCFDataGrid(const Char_t* name, const Char_t* title, const AliCFContainer &c, Int_t step) :  
+  AliCFGridSparse(name,title),
+  fSelData(step),
+  fContainer(&c)
 {
   //
   // main constructor
+  // assign directly the selection step
   //
-  SumW2();
-   //assign the container;
-  fContainer=&c;
 
+  //simply clones the container's data at specified step
+  fData = (THnSparse*) fContainer->GetGrid(fSelData)->GetGrid()->Clone();
+  SumW2();
+  AliInfo(Form("retrieving measured data from Container %s at selection step %i.",fContainer->GetName(),fSelData));
 }
+
 //____________________________________________________________________
-AliCFDataGrid::AliCFDataGrid(const AliCFDataGrid& data) :   AliCFGrid(),
+AliCFDataGrid::AliCFDataGrid(const AliCFDataGrid& data) : 
+  AliCFGridSparse(data),
   fSelData(-1),
   fContainer(0x0)
 {
@@ -99,36 +91,17 @@ AliCFDataGrid::~AliCFDataGrid()
   // destructor
   //
 }
+
 //____________________________________________________________________
 AliCFDataGrid &AliCFDataGrid::operator=(const AliCFDataGrid &c)
 {
   //
   // assigment operator
   //
-  if (this != &c)
-    ((AliCFDataGrid &) c).Copy(*this);
+  if (this != &c) c.Copy(*this);
   return *this;
 } 
-//____________________________________________________________________
 
-void AliCFDataGrid::SetMeasured(Int_t istep)
-{
-  //
-  // Deposit observed data over the grid
-  //
-  Int_t nEmptyBins=0;
-  fSelData=istep;
-  //Initially, set the corrected data to the measured data
-  for(Int_t i=0;i<fNDim;i++){
-    Float_t meas=fContainer->GetGrid(fSelData)->GetElement(i);
-    Float_t dmeas=fContainer->GetGrid(fSelData)->GetElementError(i);
-    SetElement(i,meas);
-    SetElementError(i,dmeas);
-    if(meas <=0)nEmptyBins++;
-  }
-  fNentriesTot=fNDim;
-  AliInfo(Form("retrieving measured data from Container %s at selection step %i: %i empty bins were found.",fContainer->GetName(),fSelData,nEmptyBins));
-} 
 //____________________________________________________________________
 void AliCFDataGrid::ApplyEffCorrection(const AliCFEffGrid &c)
 {
@@ -136,39 +109,12 @@ void AliCFDataGrid::ApplyEffCorrection(const AliCFEffGrid &c)
   //
   // Apply the efficiency correction
   //
-  if(c.GetNVar()!=fNVar){
+  if (c.GetNVar()!=GetNVar()) {
     AliInfo("Different number of variables, cannot apply correction");
     return;
   }
-  if(c.GetNDim()!=fNDim){
-    AliInfo("Different number of dimension, cannot apply correction");
-    return;
-  }
-
-  //Get the data
-  Int_t ncorr=0;    
-  Int_t nnocorr=0;    
-  Float_t eff,deff,unc,dunc,corr,dcorr;
-  //Apply the correction
-  for(Int_t i=0;i<fNDim;i++){
-    eff =c.GetElement(i);    
-    deff =c.GetElementError(i);    
-    unc =GetElement(i);    
-    dunc =GetElementError(i);    
-    if(eff>0 && unc>0){      
-      ncorr++;
-      corr=unc/eff;
-      dcorr=TMath::Sqrt(dunc*dunc/unc/unc+deff*deff/eff/eff)*corr;
-      SetElement(i,corr);
-      SetElementError(i,dcorr);
-    } else{
-      if(unc>0)nnocorr++;
-      SetElement(i,0);
-      SetElementError(i,0);
-    }
-  }
-  AliInfo(Form("correction applied for %i cells in correction matrix of Container %s, having entries in Data Container %s.",ncorr,c.GetName(),GetName()));
-  AliInfo(Form("No correction applied for %i empty bins in correction matrix of Container %s, having entries in Data Container %s. Their content in the corrected data container was set to zero",nnocorr,c.GetName(),GetName()));
+  Divide(&c);
+  AliInfo(Form("correction applied on data grid %s with efficiency %s.",GetName(),c.GetName()));
 }
 //____________________________________________________________________
 void AliCFDataGrid::ApplyBGCorrection(const AliCFDataGrid &c)
@@ -177,40 +123,20 @@ void AliCFDataGrid::ApplyBGCorrection(const AliCFDataGrid &c)
   //
   // Apply correction for background
   //
-  if(c.GetNVar()!=fNVar){
+  if (c.GetNVar()!=GetNVar()) {
     AliInfo("Different number of variables, cannot apply correction");
     return;
   }
-  if(c.GetNDim()!=fNDim){
-    AliInfo("Different number of dimension, cannot apply correction");
-    return;
-  }
-
-  //Get the data
-  Float_t bkg,dbkg,unc,dunc,corr,dcorr;
-
-  //Apply the correction
-
-  for(Int_t i=0;i<fNDim;i++){
-    bkg =c.GetElement(i);    
-    dbkg =c.GetElementError(i);    
-    unc =GetElement(i);    
-    dunc =GetElementError(i);    
-    corr=unc-bkg;
-    dcorr=TMath::Sqrt(unc+bkg); //stat err only...
-    SetElement(i,corr);
-    SetElementError(i,dcorr);
-      
-  }
+  Add(&c,-1);
+  AliInfo(Form("background %s subtracted from data %s.",c.GetName(),GetName()));
 }
+
 //____________________________________________________________________
-void AliCFDataGrid::Copy(TObject& eff) const
+void AliCFDataGrid::Copy(TObject& c) const
 {
   // copy function
-
-  Copy(eff);
-  AliCFDataGrid& target = (AliCFDataGrid &) eff;
+  Copy(c);
+  AliCFDataGrid& target = (AliCFDataGrid &) c;
   target.fContainer=fContainer;
   target.fSelData=fSelData;
-
 }