1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 // class for handling histograms
17 // author: Eulogio Serradilla <eulogio.serradilla@cern.ch>
19 #include <Riostream.h>
26 #include <TObjString.h>
28 #include "AliLnHistoMap.h"
30 ClassImp(AliLnHistoMap)
32 AliLnHistoMap::AliLnHistoMap()
37 // Default constructor
39 fHistoMap = new TMap();
40 fHistoMap->SetOwner(kTRUE);
43 AliLnHistoMap::~AliLnHistoMap()
52 Int_t AliLnHistoMap::Write(const char *name, Int_t option, Int_t bsize) const
55 // write only the histograms
60 TIter hIter(fHistoMap);
61 while( (key = (TObjString*)hIter.Next()) )
63 if(fHistoMap->GetValue(key)->InheritsFrom("TH1"))
65 nbytes += ((TH1*)fHistoMap->GetValue(key))->Write(name,option,bsize);
72 Int_t AliLnHistoMap::Write(const char *name, Int_t option, Int_t bsize)
74 // write only the histograms
76 return ((const AliLnHistoMap*)this)->Write(name,option,bsize);
79 TObject* AliLnHistoMap::Add(const TString& keyname, TObject* value)
82 // Add a TObject to the histogram map
84 if(fHistoMap->Contains(keyname.Data()))
86 fHistoMap->Warning("Add", "object %s already exists", keyname.Data());
90 TObjString* key = new TObjString(keyname.Data());
92 fHistoMap->Add((TObject*)key, value);
96 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)
99 // Add a TH1D histogram to the histogram map
102 if(fHistoMap->Contains(name.Data()))
104 fHistoMap->Warning("Add", "histogram %s already exists", name.Data());
108 TObjString* key = new TObjString(name.Data());
109 value = new TH1D(name.Data(),title.Data(),nbins,xmin,xmax);
110 value->SetXTitle(xlabel.Data());
111 value->SetYTitle(ylabel.Data());
113 if(logx) this->SetLogXaxis(value);
115 fHistoMap->Add((TObject*)key, (TObject*)value);
121 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)
124 // Add a TH2D histogram to the output map
127 if(fHistoMap->Contains(name.Data()))
129 fHistoMap->Warning("Add", "histogram %s already exists", name.Data());
133 TObjString* key = new TObjString(name.Data());
135 value = new TH2D(name.Data(),title.Data(),xbins,xmin,xmax,ybins,ymin,ymax);
136 value->SetXTitle(xlabel.Data());
137 value->SetYTitle(ylabel.Data());
139 if(logx) this->SetLogXaxis(value);
140 if(logy) this->SetLogYaxis(value);
142 fHistoMap->Add((TObject*)key, (TObject*)value);
148 Bool_t AliLnHistoMap::SetLogXaxis(TH1* h)
151 // transform linear X-axis bins to logarithmic bins
153 return this->SetLogBins(h->GetXaxis());
156 Bool_t AliLnHistoMap::SetLogYaxis(TH1* h)
159 // transform linear Y-axis bins to logarithmic bins
161 return this->SetLogBins(h->GetYaxis());
164 Bool_t AliLnHistoMap::SetLogBins(TAxis* axis)
167 // transform linear bins to logarithmic bins
168 // (adapted from TPad)
170 if(axis == 0) return kFALSE;
172 Double_t xmin = axis->GetXmin();
173 Double_t xmax = axis->GetXmax();
177 fHistoMap->Warning("SetLogBins", "no log bins, xmin=%f is <= 0", xmin);
181 Int_t nbins = axis->GetNbins();
183 Double_t xminl = TMath::Log(xmin);
184 Double_t xmaxl = TMath::Log(xmax);
185 Double_t dx = (xmaxl-xminl)/nbins;
186 Double_t* xbins = new Double_t[nbins+1];
189 for (Int_t i=1; i<=nbins; ++i)
191 xbins[i] = TMath::Exp(xminl+i*dx);
194 axis->Set(nbins, xbins);