52TNamed(
name, title), fNdimensions(dim), fAxes(dim), fBrowsables(dim),
53fEntries(0), fTsumw(0), fTsumw2(-1.), fTsumwx(dim), fTsumwx2(dim),
54fIntegral(0), fIntegralStatus(kNoInt)
83 Int_t chunkSize = 1024 * 16;
85 chunkSize = ((
const THnSparse*)
this)->GetChunkSize();
87 ret->
Init(
name, title, axes, keepTargetAxis, chunkSize);
102 const TAxis* axis = 0;
105 while ((axis = (
TAxis*)iAxis())) {
116 Int_t nBins = binLast - binFirst + 1;
145 Bool_t keepTargetAxis )
const {
146 const int ndim = axes->
GetSize();
151 hist =
new TH1D(
name, title, 1, 0., 1.);
153 hist =
new TH2D(
name, title, 1, 0., 1., 1, 0., 1.);
155 hist =
new TH3D(
name, title, 1, 0., 1., 1, 0., 1., 1, 0., 1.);
157 Error(
"CreateHist",
"Cannot create histogram %s with %d dimensions!",
name, ndim);
169 Int_t nBins = binLast - binFirst + 1;
200 int ndim =
h->GetDimension();
203 int nbins[3] = {0,0,0};
204 double minRange[3] = {0.,0.,0.};
205 double maxRange[3] = {0.,0.,0.};
206 const TAxis* axis[3] = {
h->GetXaxis(),
h->GetYaxis(),
h->GetZaxis() };
207 for (
int i = 0; i < ndim; ++i) {
209 minRange[i] = axis[i]->
GetXmin();
210 maxRange[i] = axis[i]->
GetXmax();
218 const char* cname(
h->ClassName() );
219 if (cname[0] ==
'T' && cname[1] ==
'H'
220 && cname[2] >=
'1' && cname[2] <=
'3' && cname[4] == 0) {
222#define R__THNBCASE(TAG) \
224s = new _NAME2_(THnSparse,TAG)(name, title, ndim, nbins, \
225minRange, maxRange, chunkSize); \
227s = new _NAME2_(THn,TAG)(name, title, ndim, nbins, \
228minRange, maxRange); \
242 ::Warning(
"THnSparse::CreateHnAny",
"Unknown Type of Histogram");
246 for (
int i = 0; i < ndim; ++i) {
253 ::Warning(
"THnSparse::CreateHnAny",
"Unknown Type of Histogram");
272 if (sparse)
type = hn->IsA();
275 if (hn->
InheritsFrom(THnSparseD::Class())) bintype =
'D';
276 else if (hn->
InheritsFrom(THnSparseF::Class())) bintype =
'F';
277 else if (hn->
InheritsFrom(THnSparseL::Class())) bintype =
'L';
278 else if (hn->
InheritsFrom(THnSparseI::Class())) bintype =
'I';
279 else if (hn->
InheritsFrom(THnSparseS::Class())) bintype =
'S';
280 else if (hn->
InheritsFrom(THnSparseC::Class())) bintype =
'C';
282 hn->
Error(
"CreateHnAny",
"Type %s not implemented; please inform the ROOT team!",
289 if (!sparse)
type = hn->IsA();
293 else if (hn->
InheritsFrom(THnF::Class())) bintype =
'F';
294 else if (hn->
InheritsFrom(THnC::Class())) bintype =
'C';
295 else if (hn->
InheritsFrom(THnS::Class())) bintype =
'S';
296 else if (hn->
InheritsFrom(THnI::Class())) bintype =
'I';
297 else if (hn->
InheritsFrom(THnL::Class())) bintype =
'L';
299 hn->
Error(
"CreateHnAny",
"Type THnSparse with Long64_t bins is not available!");
307 hn->
Error(
"CreateHnAny",
"Unhandled type %s, not deriving from THn nor THnSparse!",
312 hn->
Error(
"CreateHnAny",
"Unhandled type %s, please inform the ROOT team!",
334 for (
int i = 0; i < nbins; ++i) {
337 if (!value && !error)
continue;
375 if (!fitOption.
Chi2) fitOption.
Like =
true;
402 const Int_t nStaticBins = 40;
403 Int_t bin[nStaticBins];
437 if (coord[i] < min || coord[i] > max)
468 if (posInsert ==
kNPOS) {
469 title +=
" projection ";
473 for (
Int_t d = ndim - 1;
d >= 0; --
d) {
476 title.
Insert(posInsert,
", ");
478 title.
Insert(posInsert,
" projection ");
491 Bool_t ignoreTargetRange = (option && (strchr(option,
'A') || strchr(option,
'a')));
492 Bool_t keepTargetAxis = ignoreTargetRange || (option && (strchr(option,
'O') || strchr(option,
'o')));
493 if (ignoreTargetRange) {
494 hadRange =
new Bool_t[ndim];
507 if (keepTargetAxis) {
521 Bool_t wantErrors = haveErrors || (option && (strchr(option,
'E') || strchr(option,
'e')));
528 while ((myLinBin = iter.
Next()) >= 0) {
536 if (binOffset > 0) --binOffset;
537 bins[
d] -= binOffset;
543 if (ndim == 1) targetLinBin = bins[0];
544 else if (ndim == 2) targetLinBin = hist->
GetBin(bins[0], bins[1]);
545 else if (ndim == 3) targetLinBin = hist->
GetBin(bins[0], bins[1], bins[2]);
618 while ((i = iter.
Next()) >= 0) {
637 Warning(
"RebinnedAdd",
"Different number of dimensions, cannot carry out operation on the histograms");
659 while ((i = iter.
Next(coord)) >= 0) {
667 x[j] =
h->GetAxis(j)->GetBinCenter(coord[j]);
729 while ((addMeObj = iter())) {
738 while ((addMeObj = iter())) {
741 Error(
"Merge",
"Object named %s is not THnBase! Skipping it.",
766 if (wantErrors)
Sumw2();
774 while ((i = iter.
Next(coord)) >= 0) {
780 if (idxh >= 0)
v2 =
h->GetBinContent(idxh);
785 if (idxh >= 0) err2 =
h->GetBinError(idxh) *
v1;
810 if (wantErrors)
Sumw2();
815 while ((i = iter.
Next(coord)) >= 0) {
860 if (wantErrors)
Sumw2();
868 while ((i = iter.
Next(coord)) >= 0) {
878 Warning(
"Divide(h)",
"Histogram h has empty bins - division by zero! Setting bin to 0.");
887 Double_t err = (err1 * err1 + err2 * err2) / (b22 * b22);
915 Error(
"Divide",
"Coefficient of dividing histogram cannot be zero");
937 while ((i = iter.
Next(coord)) >= 0) {
947 Warning(
"Divide(h1, h2)",
"Histogram h2 has empty bins - division by zero! Setting bin to 0.");
962 errSq =
TMath::Abs( ( (1. - 2.*w) * err1 * err1 + err2 * err2 ) / (
v2 *
v2) );
970 errSq =
c1 *
c2 * (err1 * err1 + err2 * err2) / (b22 * b22);
989 Warning(tag,
"Different number of dimensions, cannot carry out operation on the histograms");
994 Warning(tag,
"Different number of bins on axis %i, cannot carry out operation on the histograms", dim);
1026 if (endHistTitle >= 0) {
1028 Int_t posTitle = endHistTitle + 1;
1031 while (posTitle > 0 && posTitle < lenTitle && dim <
fNdimensions){
1034 axisTitle.
ReplaceAll(
"#semicolon", 10,
";", 1);
1038 posTitle = endTitle + 1;
1082 if (posInsert ==
kNPOS) {
1087 for (
Int_t d = ndim - 1;
d >= 0; --
d)
1089 title.
Insert(posInsert,
" rebin ");
1102 for (
Int_t i = 0; i < newbins + 1; ++i)
1105 else edges[i] = newaxis->
GetXmax();
1106 newaxis->
Set(newbins, edges);
1116 Bool_t wantErrors = haveErrors;
1123 while ((i = iter.
Next(coord)) >= 0) {
1136 h->AddBinContent(idxh,
v);
1175 Error(
"ComputeIntegral",
"The histogram must have at least one bin.");
1187 while ((i = iter.
Next(coord)) >= 0) {
1191 bool regularBin =
true;
1200 if (!regularBin)
v = 0.;
1208 Error(
"ComputeIntegral",
"No hits in regular bins (non over/underflow).");
1257 if (
v == 0. && err == 0. && options && strchr(options,
'0')) {
1270 Printf(
"Bin at (%s) = %g (+/- %g)", coord.
Data(),
v, err);
1287 if (from < 0) from = 0;
1288 if (howmany == -1) howmany =
GetNbins();
1292 if (options && (strchr(options,
'x') || strchr(options,
'X'))) {
1296 bin[dim] = from % nbins[dim];
1300 for (
Long64_t i = 0; i < howmany; ++i) {
1306 if (bin[dim] >= nbins[dim]) {
1318 for (
Long64_t i = from; i < from + howmany; ++i) {
1336 Bool_t optAxis = options && (strchr(options,
'A') || (strchr(options,
'a')));
1337 Bool_t optMem = options && (strchr(options,
'M') || (strchr(options,
'm')));
1338 Bool_t optStat = options && (strchr(options,
'S') || (strchr(options,
's')));
1339 Bool_t optContent = options && (strchr(options,
'C') || (strchr(options,
'c')));
1347 Printf(
" axis %d \"%s\": %d bins (%g..%g), %s bin sizes", dim,
1349 (axis->
GetXbins() ?
"variable" :
"fixed"));
1365 Printf(
" coordinates stored in %d chunks of %d entries\n %g of bins filled using %g of memory compared to an array",
1433fHist(hist), fAxis(axis), fProj(0)
1459 fProj = fHist->Projection(fAxis);
1461 fProj->Draw(
b ?
b->GetDrawOption() :
"");
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
void Printf(const char *fmt,...)
class describing the range in the coordinates it supports multiple range in a coordinate.
void AddRange(unsigned int icoord, double xmin, double xmax)
add a range [xmin,xmax] for the new coordinate icoord Adding a range does not delete existing one,...
virtual ~THnBaseBinIter()
Destruct a bin iterator.
TBrowser helper for THnBase.
~THnBaseBrowsable()
Destruct a THnBaseBrowsable.
THnBaseBrowsable(THnBase *hist, Int_t axis)
Construct a THnBaseBrowsable.
void Browse(TBrowser *b)
Browse an axis of a THnBase, i.e. draw its projection.
Double_t At(Int_t i) const
const Double_t * GetArray() const
Abstract array base class.
Class to manage histogram axis.
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
const TArrayD * GetXbins() const
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Int_t GetLast() const
Return last bin on the axis i.e.
const char * GetTitle() const
Returns title of object.
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Int_t GetFirst() const
Return first bin on the axis i.e.
Using a TBrowser one can browse all ROOT objects.
TClass instances represent classes, structs and namespaces in the ROOT type system.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Collection abstract base class.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Bool_t IsEmpty() const
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
static void RejectPoint(Bool_t reject=kTRUE)
Static function to set the global flag to reject points the fgRejectPoint global flag is tested by al...
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
1-D histogram with a double per channel (see TH1 documentation)}
TH1 is the base class of all histogram classes in ROOT.
virtual Double_t GetEffectiveEntries() const
Number of effective entries of the histogram.
virtual void Rebuild(Option_t *option="")
Using the current bin info, recompute the arrays for contents and errors.
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
static Int_t FitOptionsMake(Option_t *option, Foption_t &Foption)
Decode string choptin and fill fitOption structure.
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
virtual void GetBinXYZ(Int_t binglobal, Int_t &binx, Int_t &biny, Int_t &binz) const
Return binx, biny, binz corresponding to the global bin number globalbin see TH1::GetBin function abo...
virtual Int_t GetNcells() const
virtual Int_t GetBin(Int_t binx, Int_t biny=0, Int_t binz=0) const
Return Global bin number corresponding to binx,y,z.
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
virtual Double_t GetEntries() const
Return the current number of entries.
virtual void ResetStats()
Reset the statistics including the number of entries and replace with values calculated from bin cont...
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual void SetEntries(Double_t n)
2-D histogram with a double per channel (see TH1 documentation)}
3-D histogram with a double per channel (see TH1 documentation)}
Multidimensional histogram base.
void SetEntries(Double_t entries)
virtual void SetFilledBins(Long64_t)
virtual void InitStorage(Int_t *nbins, Int_t chunkSize)=0
Double_t GetBinError(const Int_t *idx) const
enum THnBase::@77 fIntegralStatus
array with bin weight sums
void SetBinError(const Int_t *idx, Double_t e)
Double_t fEntries
browser-helpers for each axis
Double_t GetSumw2() const
Bool_t IsInRange(Int_t *coord) const
Check whether bin coord is in range, as defined by TAxis::SetRange().
TFitResultPtr Fit(TF1 *f1, Option_t *option="", Option_t *goption="")
Fit a THnSparse with function f.
void AddBinContent(const Int_t *x, Double_t v=1.)
void Scale(Double_t c)
Scale contents and errors of this histogram by c: this = this * c It does not modify the histogram's ...
virtual void SetBinError2(Long64_t bin, Double_t e2)=0
TObjArray * GetListOfAxes()
TH1 * CreateHist(const char *name, const char *title, const TObjArray *axes, Bool_t keepTargetAxis) const
Create an empty histogram with name and title with a given set of axes.
Bool_t PrintBin(Long64_t idx, Int_t *coord, Option_t *options) const
Print one bin.
Double_t GetSumwx(Int_t dim) const
Bool_t CheckConsistency(const THnBase *h, const char *tag) const
Consistency check on (some of) the parameters of two histograms (for operations).
Int_t GetNdimensions() const
static THnBase * CreateHnAny(const char *name, const char *title, const TH1 *h1, Bool_t sparse, Int_t chunkSize=1024 *16)
Create a THn / THnSparse object from a histogram deriving from TH1.
void ResetBase(Option_t *option="")
Clear the histogram.
virtual Long64_t GetNbins() const =0
THnBase * RebinBase(Int_t group) const
Combine the content of "group" neighboring bins into a new bin and return the resulting THnBase.
void Browse(TBrowser *b)
Browse a THnSparse: create an entry (ROOT::THnSparseBrowsable) for each dimension.
void SetBinEdges(Int_t idim, const Double_t *bins)
Set the axis # of bins and bin limits on dimension idim.
Bool_t GetCalculateErrors() const
void AddInternal(const THnBase *h, Double_t c, Bool_t rebinned)
Add() implementation for both rebinned histograms and those with identical binning.
Double_t GetBinContent(const Int_t *idx) const
void PrintEntries(Long64_t from=0, Long64_t howmany=-1, Option_t *options=0) const
Print "howmany" entries starting at "from".
void Add(const THnBase *h, Double_t c=1.)
Add contents of h scaled by c to this histogram: this = this + c * h Note that if h has Sumw2 set,...
virtual void Reserve(Long64_t)
virtual ~THnBase()
Destruct a THnBase.
Double_t GetEntries() const
virtual Double_t GetBinError2(Long64_t linidx) const =0
virtual void Reset(Option_t *option="")=0
void SetBinContent(const Int_t *idx, Double_t v)
void Multiply(const THnBase *h)
Multiply this histogram by histogram h this = this * h Note that if h has Sumw2 set,...
void Divide(const THnBase *h)
Divide this histogram by h this = this/(h) Note that if h has Sumw2 set, Sumw2 is automatically calle...
Double_t GetSumwx2(Int_t dim) const
void Print(Option_t *option="") const
Print a THnBase.
TObject * ProjectionAny(Int_t ndim, const Int_t *dim, Bool_t wantNDim, Option_t *option="") const
Project all bins into a ndim-dimensional THn / THnSparse (whatever *this is) or if (ndim < 4 and !...
void GetRandom(Double_t *rand, Bool_t subBinRandom=kTRUE)
Generate an n-dimensional random tuple based on the histogrammed distribution.
TAxis * GetAxis(Int_t dim) const
THnBase * CloneEmpty(const char *name, const char *title, const TObjArray *axes, Bool_t keepTargetAxis) const
Create a new THnBase object that is of the same type as *this, but with dimensions and bins given by ...
Long64_t Merge(TCollection *list)
Merge this with a list of THnBase's.
virtual Long64_t GetBin(const Int_t *idx) const =0
Double_t ComputeIntegral()
Calculate the integral of the histogram.
virtual void AddBinError2(Long64_t bin, Double_t e2)=0
void RebinnedAdd(const THnBase *h, Double_t c=1.)
Add contents of h scaled by c to this histogram: this = this + c * h Note that if h has Sumw2 set,...
void SetTitle(const char *title)
Change (i.e.
void Init(const char *name, const char *title, const TObjArray *axes, Bool_t keepTargetAxis, Int_t chunkSize=1024 *16)
Initialize axes and name.
Iterator over THnBase bins.
Long64_t Next(Int_t *coord=0)
Return the next bin's index.
Bool_t HaveSkippedBin() const
Int_t GetCoord(Int_t dim) const
Efficient multidimensional histogram.
Double_t GetSparseFractionBins() const
Return the amount of filled bins over all bins.
Double_t GetSparseFractionMem() const
Return the amount of used memory over memory that would be used by a non-sparse n-dimensional histogr...
Int_t GetChunkSize() const
The TNamed class is the base class for all named ROOT classes.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Int_t GetEntriesFast() const
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
TObject * At(Int_t idx) const
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual Double_t Rndm()
Machine independent random number generator.
void ToLower()
Change string to lower-case.
TString & Insert(Ssiz_t pos, const char *s)
Ssiz_t First(char c) const
Find first occurrence of a character c.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
TString & Remove(Ssiz_t pos)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
TFitResultPtr FitObject(TH1 *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
fitting function for a TH1 (called from TH1::Fit)
Double_t Floor(Double_t x)
Double_t Sqrt(Double_t x)
Int_t CeilNint(Double_t x)
Long64_t BinarySearch(Long64_t n, const T *array, T value)