]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGLF/SPECTRA/Nuclei/B2/AliLnHistoMap.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / Nuclei / B2 / AliLnHistoMap.cxx
index 4e27e7fbdba34650777577dac495883fafe9b60e..e87599f0b4413e928826dce81e98d627cd3aa29f 100644 (file)
 #include <Riostream.h>
 #include <TString.h>
 #include <TMap.h>
+#include <TH1.h>
+#include <TAxis.h>
 #include <TH1D.h>
 #include <TH2D.h>
 #include <TObjString.h>
+#include <TMath.h>
 #include "AliLnHistoMap.h"
 
 ClassImp(AliLnHistoMap)
@@ -34,7 +37,7 @@ AliLnHistoMap::AliLnHistoMap()
 // Default constructor
 //
        fHistoMap = new TMap();
-       fHistoMap->SetOwner(kTRUE);
+       fHistoMap->SetOwner(kFALSE);
 }
 
 AliLnHistoMap::~AliLnHistoMap()
@@ -46,6 +49,7 @@ AliLnHistoMap::~AliLnHistoMap()
        
 }
 
+/*
 Int_t AliLnHistoMap::Write(const char *name, Int_t option, Int_t bsize) const
 {
 //
@@ -72,6 +76,7 @@ Int_t AliLnHistoMap::Write(const char *name, Int_t option, Int_t bsize)
 //
        return ((const AliLnHistoMap*)this)->Write(name,option,bsize);
 }
+*/
 
 TObject* AliLnHistoMap::Add(const TString& keyname, TObject* value)
 {
@@ -80,7 +85,7 @@ TObject* AliLnHistoMap::Add(const TString& keyname, TObject* value)
 //
        if(fHistoMap->Contains(keyname.Data()))
        {
-               std::cerr << "WARNING: object " << keyname << " already exists" << std::endl;
+               fHistoMap->Warning("Add", "object %s already exists", keyname.Data());
                return 0;
        }
        
@@ -90,7 +95,7 @@ TObject* AliLnHistoMap::Add(const TString& keyname, TObject* value)
        return value;
 }
 
-TH1D* AliLnHistoMap::Add(const TString& name, Int_t nbins, Double_t xmin, Double_t xmax, const TString& title, const TString& xlabel, const TString& ylabel)
+TH1D* AliLnHistoMap::Add(const TString& name, Int_t nbins, Double_t xmin, Double_t xmax, const TString& title, const TString& xlabel, const TString& ylabel, Bool_t logx)
 {
 //
 // Add a TH1D histogram to the histogram map
@@ -98,7 +103,7 @@ TH1D* AliLnHistoMap::Add(const TString& name, Int_t nbins, Double_t xmin, Double
        TH1D* value = 0;
        if(fHistoMap->Contains(name.Data()))
        {
-               std::cerr << "WARNING: histogram " << name << " already exists" << std::endl;
+               fHistoMap->Warning("Add", "histogram %s already exists", name.Data());
        }
        else
        {
@@ -107,13 +112,26 @@ TH1D* AliLnHistoMap::Add(const TString& name, Int_t nbins, Double_t xmin, Double
                value->SetXTitle(xlabel.Data());
                value->SetYTitle(ylabel.Data());
                
+               if(logx) this->SetLogXaxis(value);
+               
                fHistoMap->Add((TObject*)key, (TObject*)value);
        }
        
        return value;
 }
 
-TH2D* AliLnHistoMap::Add(const TString& name, Int_t xbins, Double_t xmin, Double_t xmax, Int_t ybins, Double_t ymin, Double_t ymax, const TString& title, const TString& xlabel, const TString& ylabel)
+TH1D* AliLnHistoMap::Add(const TString& name, Int_t nbins, Double_t* xbins, const TString& title, const TString& xlabel, const TString& ylabel)
+{
+//
+// Add a TH1D histogram with variable bin size
+//
+       TH1D* h = this->Add(name,nbins,xbins[0],xbins[nbins],title,xlabel,ylabel);
+       h->GetXaxis()->Set(nbins, xbins);
+       
+       return h;
+}
+
+TH2D* AliLnHistoMap::Add(const TString& name, Int_t xbins, Double_t xmin, Double_t xmax, Int_t ybins, Double_t ymin, Double_t ymax, const TString& title, const TString& xlabel, const TString& ylabel, Bool_t logx, Bool_t logy)
 {
 //
 // Add a TH2D histogram to the output map
@@ -121,7 +139,7 @@ TH2D* AliLnHistoMap::Add(const TString& name, Int_t xbins, Double_t xmin, Double
        TH2D* value = 0;
        if(fHistoMap->Contains(name.Data()))
        {
-               std::cerr << "WARNING: histogram " << name << " already exists" << std::endl;
+               fHistoMap->Warning("Add", "histogram %s already exists", name.Data());
        }
        else
        {
@@ -131,8 +149,97 @@ TH2D* AliLnHistoMap::Add(const TString& name, Int_t xbins, Double_t xmin, Double
                value->SetXTitle(xlabel.Data());
                value->SetYTitle(ylabel.Data());
                
+               if(logx) this->SetLogXaxis(value);
+               if(logy) this->SetLogYaxis(value);
+               
                fHistoMap->Add((TObject*)key, (TObject*)value);
        }
        
        return value;
 }
+
+TH2D* AliLnHistoMap::Add(const TString& name, Int_t nbinsx, Double_t* xbins, Int_t nbinsy, Double_t* ybins, const TString& title, const TString& xlabel, const TString& ylabel)
+{
+//
+// Add a TH2D histogram with variable bin size
+//
+       TH2D* h = this->Add(name, nbinsx, xbins[0], xbins[nbinsx], nbinsy, ybins[0], ybins[nbinsy], title, xlabel, ylabel);
+       h->GetXaxis()->Set(nbinsx, xbins);
+       h->GetYaxis()->Set(nbinsy, ybins);
+       
+       return h;
+}
+
+TH2D* AliLnHistoMap::Add(const TString& name, Int_t nbins, Double_t* xbins, Int_t ybins, Double_t ymin, Double_t ymax, const TString& title, const TString& xlabel, const TString& ylabel)
+{
+//
+// Add a TH2D histogram with variable bin size
+//
+       TH2D* h = this->Add(name, nbins, xbins[0], xbins[nbins], ybins, ymin, ymax, title, xlabel, ylabel);
+       h->GetXaxis()->Set(nbins, xbins);
+       
+       return h;
+}
+
+TH2D* AliLnHistoMap::Add(const TString& name, Int_t xbins, Double_t xmin, Double_t xmax, Int_t nbins, Double_t* ybins, const TString& title, const TString& xlabel, const TString& ylabel)
+{
+//
+// Add a TH2D histogram with variable bin size
+//
+       TH2D* h = this->Add(name, xbins, xmin, xmax, nbins, ybins[0], ybins[nbins], title, xlabel, ylabel);
+       h->GetYaxis()->Set(nbins, ybins);
+       
+       return h;
+}
+
+Bool_t AliLnHistoMap::SetLogXaxis(TH1* h)
+{
+//
+// transform linear X-axis bins to logarithmic bins
+//
+       return this->SetLogBins(h->GetXaxis());
+}
+
+Bool_t AliLnHistoMap::SetLogYaxis(TH1* h)
+{
+//
+// transform linear Y-axis bins to logarithmic bins
+//
+       return this->SetLogBins(h->GetYaxis());
+}
+
+Bool_t AliLnHistoMap::SetLogBins(TAxis* axis)
+{
+//
+// transform linear bins to logarithmic bins
+// (adapted from TPad)
+//
+       if(axis == 0) return kFALSE;
+       
+       Double_t xmin = axis->GetXmin();
+       Double_t xmax = axis->GetXmax();
+       
+       if(xmin <= 0)
+       {
+               fHistoMap->Warning("SetLogBins", "no log bins, xmin=%f is <= 0", xmin);
+               return kFALSE;
+       }
+       
+       Int_t nbins = axis->GetNbins();
+       
+       Double_t xminl = TMath::Log(xmin);
+       Double_t xmaxl = TMath::Log(xmax);
+       Double_t dx = (xmaxl-xminl)/nbins;
+       Double_t* xbins = new Double_t[nbins+1];
+       
+       xbins[0] = xmin;
+       for (Int_t i=1; i<=nbins; ++i)
+       {
+               xbins[i] = TMath::Exp(xminl+i*dx);
+       }
+       
+       axis->Set(nbins, xbins);
+       delete[] xbins;
+       
+       return kTRUE;
+}