]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGHF/hfe/AliHFEtools.cxx
Merge remote-tracking branch 'origin/master' into flatdev
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliHFEtools.cxx
index dab9e9c85f205d6c13766c0b88034ce9c75c37d9..5bc40ce5b8af78f56c907154862cdb33c0bd024e 100644 (file)
 #include <TArrayD.h>
 #include <TMath.h>
 #include <TParticle.h>
+#include <TF1.h>
 #include "TH1.h"
 #include "TH1D.h"
 #include "TH2.h"
 #include "TGraph.h"
 #include "TGraphErrors.h"
+#include "TGraphAsymmErrors.h"
 #include "THnSparse.h"
 #include "TAxis.h"
 #include "TMath.h"
 #include "TString.h"
+#include "TFile.h"
+#include "TKey.h"
+#include "TROOT.h"
 
 #include "AliAODMCParticle.h"
 #include "AliAODpidUtil.h"
@@ -425,3 +430,137 @@ TH1D* AliHFEtools::GraphToHist(TGraph* g, Double_t firstBinWidth, Bool_t exchang
 
     return result;
 }
+
+//__________________________________________
+void AliHFEtools::BinParameterisation(const TF1 &fun, const TArrayD &xbins, TArrayD &bincontent){
+    //
+    // Calculate binned version of a function defined as the integral of x*f(x) in
+    // the integration range xmin,xmax, where xmin and xmax are the bin limits, divided
+    // by the binwidth. The function is important in case of steeply falling functions
+    //
+    // Parameters
+    //   fun:           the function to be binned
+    //   xbins:         the bin limits
+    //   bincontent:    the binned parameterisation
+    //
+    TString expression(Form("x*%s", fun.GetName()));
+    Double_t xmin(0), xmax(0);
+    fun.GetRange(xmin,xmax);
+    // check range
+    xmin = TMath::Min(xmin, xbins[0]);
+    xmax = TMath::Max(xmax, xbins[xbins.GetSize()-1]);
+    TF1 helper("helper",expression.Data(),xmin,xmax);   // make function x*f(x)
+    if(bincontent.GetSize() != xbins.GetSize()-1)
+        bincontent.Set(xbins.GetSize()-1); // Adapt array to number of bins
+    //Caclulate Binned
+    for(Int_t ib = 0; ib < xbins.GetSize()-1; ib++){
+        xmin = xbins[ib];
+        xmax = xbins[ib+1];
+        bincontent[ib] = (helper.Integral(xmin, xmax))/(xmax - xmin);
+    }
+}
+
+
+
+
+//_________________________________________________________________________
+//Function  AliHFEtools::GetHFEResultList() - opens file from argument and returns TList Object containing String "Results"
+//_________________________________________________________________________
+TList *AliHFEtools::GetHFEResultList(const TString str){
+
+    TFile *f = TFile::Open(str.Data());
+    if(!f || f->IsZombie()){
+        printf("Could not read file %s\n",str.Data()); 
+        return NULL ;
+    }
+    gROOT->cd();
+    TKey *k;
+    TIter next(f->GetListOfKeys());
+    while ((k = dynamic_cast<TKey *>(next()))){
+        TString s(k->GetName());
+        if(s.Contains("Results")) break;
+    }
+    if(!k){
+        printf("Output container not found\n");
+        f->Close(); delete f;
+        return NULL;
+    } 
+    TList *returnlist = dynamic_cast<TList *>(k->ReadObj());
+    f->Close(); delete f;
+    return returnlist;
+}
+
+
+//_________________________________________________________________________
+//Function  AliHFEtools::GetHFEQAList() - opens file from argument and returns TList Object containing String "QA"
+//_________________________________________________________________________
+TList *AliHFEtools::GetHFEQAList(const TString str){
+
+    TFile *f = TFile::Open(str.Data());
+    if(!f || f->IsZombie()){
+        printf("Could not read file %s\n",str.Data()); 
+        return NULL ;
+    }
+    gROOT->cd();
+    TKey *k;
+    TIter next(f->GetListOfKeys());
+    while ((k = dynamic_cast<TKey *>(next()))){
+        TString s(k->GetName());
+        if(s.Contains("QA")) break;
+    }
+    if(!k){
+        printf("Output container not found\n");
+        f->Close(); delete f;
+        return NULL;
+    } 
+    TList *returnlist = dynamic_cast<TList *>(k->ReadObj());
+    f->Close(); delete f;
+    return returnlist;
+}
+
+//__________________________________________
+void AliHFEtools::NormaliseBinWidth(TH1 *histo){
+  //
+  // Helper function to correct histograms for the bin width
+  //
+  Double_t binwidth(0.);
+  for(Int_t ipt = 1; ipt <= histo->GetNbinsX(); ipt++){
+    binwidth = histo->GetBinWidth(ipt);
+    histo->SetBinContent(ipt, histo->GetBinContent(ipt)/binwidth);
+    histo->SetBinError(ipt, histo->GetBinError(ipt)/binwidth);
+  }
+}
+
+//__________________________________________
+void AliHFEtools::NormaliseBinWdith(TGraphErrors *graph){
+  //
+  // Helper function to correct graphs with symmetric errors 
+  // for the bin width
+  //
+  Double_t binwidth(0.);
+  Double_t *ypoints = graph->GetY(),
+           *yerrors = graph->GetEY();
+  for(int ipt = 0; ipt < graph->GetN(); ipt++){
+    binwidth = 2*graph->GetEX()[ipt];
+    ypoints[ipt] /= binwidth;
+    yerrors[ipt] /= binwidth;
+  }
+}
+
+//__________________________________________
+void AliHFEtools::NormaliseBinWdithAsymm(TGraphAsymmErrors *graph){
+  //
+  // Helper function to correct graphs with asymmetric errors 
+  // for the bin width
+  //
+  Double_t binwidth(0.);
+  Double_t *ypoints = graph->GetY(),
+           *yerrorslow = graph->GetEYlow(),
+           *yerrorshigh = graph->GetEYhigh();
+  for(int ipt = 0; ipt < graph->GetN(); ipt++){
+    binwidth = graph->GetEXlow()[ipt] + graph->GetEXhigh()[ipt];
+    ypoints[ipt] /= binwidth;
+    yerrorslow[ipt] /= binwidth;
+    yerrorshigh[ipt] /= binwidth;
+  }
+}