51 TNamed(name, title), fNdimensions(dim), fAxes(dim), fBrowsables(dim),
52 fEntries(0), fTsumw(0), fTsumw2(-1.), fTsumwx(dim), fTsumwx2(dim),
53 fIntegral(0), fIntegralStatus(kNoInt)
56 TAxis* axis =
new TAxis(nbins[i], xmin ? xmin[i] : 0., xmax ? xmax[i] : 1.);
82 Int_t chunkSize = 1024 * 16;
84 chunkSize = ((
const THnSparse*)
this)->GetChunkSize();
86 ret->
Init(name, title, axes, keepTargetAxis, chunkSize);
101 const TAxis* axis = 0;
104 while ((axis = (
TAxis*)iAxis())) {
115 Int_t nBins = binLast - binFirst + 1;
144 Bool_t keepTargetAxis )
const {
145 const int ndim = axes->
GetSize();
150 hist =
new TH1D(name, title, 1, 0., 1.);
152 hist =
new TH2D(name, title, 1, 0., 1., 1, 0., 1.);
154 hist =
new TH3D(name, title, 1, 0., 1., 1, 0., 1., 1, 0., 1.);
156 Error(
"CreateHist",
"Cannot create histogram %s with %d dimensions!", name, ndim);
161 for (
Int_t d = 0; d < ndim; ++d) {
166 if (binFirst == 0) binFirst = 1;
168 Int_t nBins = binLast - binFirst + 1;
202 int nbins[3] = {0,0,0};
206 for (
int i = 0; i < ndim; ++i) {
208 minRange[i] = axis[i]->
GetXmin();
209 maxRange[i] = axis[i]->
GetXmax();
218 if (cname[0] ==
'T' && cname[1] ==
'H'
219 && cname[2] >=
'1' && cname[2] <=
'3' && cname[4] == 0) {
221 #define R__THNBCASE(TAG) \
223 s = new _NAME2_(THnSparse,TAG)(name, title, ndim, nbins, \
224 minRange, maxRange, chunkSize); \
226 s = new _NAME2_(THn,TAG)(name, title, ndim, nbins, \
227 minRange, maxRange); \
241 ::Warning(
"THnSparse::CreateHnAny",
"Unknown Type of Histogram");
245 for (
int i = 0; i < ndim; ++i) {
252 ::Warning(
"THnSparse::CreateHnAny",
"Unknown Type of Histogram");
271 if (sparse) type = hn->IsA();
281 hn->
Error(
"CreateHnAny",
"Type %s not implemented; please inform the ROOT team!",
288 if (!sparse) type = hn->IsA();
298 hn->
Error(
"CreateHnAny",
"Type THnSparse with Long64_t bins is not available!");
306 hn->
Error(
"CreateHnAny",
"Unhandled type %s, not deriving from THn nor THnSparse!",
311 hn->
Error(
"CreateHnAny",
"Unhandled type %s, please inform the ROOT team!",
333 for (
int i = 0; i <
nbins; ++i) {
336 if (!value && !error)
continue;
374 if (!fitOption.
Chi2) fitOption.
Like =
true;
401 const Int_t nStaticBins = 40;
402 Int_t bin[nStaticBins];
436 if (coord[i] < min || coord[i] > max)
459 for (
Int_t d = 0; d < ndim; ++d) {
466 if (posInsert ==
kNPOS) {
467 title +=
" projection ";
468 for (
Int_t d = 0; d < ndim; ++d)
471 for (
Int_t d = ndim - 1; d >= 0; --d) {
474 title.
Insert(posInsert,
", ");
476 title.
Insert(posInsert,
" projection ");
480 for (
Int_t d = 0; d < ndim; ++d) {
489 Bool_t ignoreTargetRange = (option && (strchr(option,
'A') || strchr(option,
'a')));
490 Bool_t keepTargetAxis = ignoreTargetRange || (option && (strchr(option,
'O') || strchr(option,
'o')));
491 if (ignoreTargetRange) {
492 hadRange =
new Bool_t[ndim];
493 for (
Int_t d = 0; d < ndim; ++d){
501 ret = hn =
CloneEmpty(name, title, &newaxes, keepTargetAxis);
503 ret = hist =
CreateHist(name, title, &newaxes, keepTargetAxis);
505 if (keepTargetAxis) {
508 for (
Int_t d = 0; d < ndim; ++d) {
519 Bool_t wantErrors = haveErrors || (option && (strchr(option,
'E') || strchr(option,
'e')));
526 while ((myLinBin = iter.
Next()) >= 0) {
529 for (
Int_t d = 0; d < ndim; ++d) {
534 if (binOffset > 0) --binOffset;
535 bins[d] -= binOffset;
541 if (ndim == 1) targetLinBin = bins[0];
542 else if (ndim == 2) targetLinBin = hist->
GetBin(bins[0], bins[1]);
543 else if (ndim == 3) targetLinBin = hist->
GetBin(bins[0], bins[1], bins[2]);
594 for (
Int_t d = 0; d < ndim; ++d)
616 while ((i = iter.
Next()) >= 0) {
635 Warning(
"RebinnedAdd",
"Different number of dimensions, cannot carry out operation on the histograms");
657 while ((i = iter.
Next(coord)) >= 0) {
727 while ((addMeObj =
iter())) {
736 while ((addMeObj =
iter())) {
739 Error(
"Merge",
"Object named %s is not THnBase! Skipping it.",
764 if (wantErrors)
Sumw2();
772 while ((i = iter.
Next(coord)) >= 0) {
808 if (wantErrors)
Sumw2();
813 while ((i = iter.
Next(coord)) >= 0) {
858 if (wantErrors)
Sumw2();
866 while ((i = iter.
Next(coord)) >= 0) {
876 Warning(
"Divide(h)",
"Histogram h has empty bins - division by zero! Setting bin to 0.");
885 Double_t err = (err1 * err1 + err2 * err2) / (b22 * b22);
913 Error(
"Divide",
"Coefficient of dividing histogram cannot be zero");
935 while ((i = iter.
Next(coord)) >= 0) {
945 Warning(
"Divide(h1, h2)",
"Histogram h2 has empty bins - division by zero! Setting bin to 0.");
960 errSq =
TMath::Abs( ( (1. - 2.*w) * err1 * err1 + err2 * err2 ) / (v2 * v2) );
968 errSq = c1 * c2 * (err1 * err1 + err2 * err2) / (b22 * b22);
987 Warning(tag,
"Different number of dimensions, cannot carry out operation on the histograms");
992 Warning(tag,
"Different number of bins on axis %i, cannot carry out operation on the histograms", dim);
1024 if (endHistTitle >= 0) {
1026 Int_t posTitle = endHistTitle + 1;
1029 while (posTitle > 0 && posTitle < lenTitle && dim <
fNdimensions){
1032 axisTitle.
ReplaceAll(
"#semicolon", 10,
";", 1);
1036 posTitle = endTitle + 1;
1074 for (
Int_t d = 0; d < ndim; ++d)
1075 name +=
Form(
"_%d", group[d]);
1080 if (posInsert ==
kNPOS) {
1082 for (
Int_t d = 0; d < ndim; ++d)
1083 title +=
Form(
"{%d}", group[d]);
1085 for (
Int_t d = ndim - 1; d >= 0; --d)
1086 title.
Insert(posInsert,
Form(
"{%d}", group[d]));
1087 title.
Insert(posInsert,
" rebin ");
1092 for (
Int_t d = 0; d < ndim; ++d) {
1096 Int_t newbins = (newaxis->
GetNbins() + group[d] - 1) / group[d];
1100 for (
Int_t i = 0; i < newbins + 1; ++i)
1101 if (group[d] * i <= newaxis->
GetNbins())
1102 edges[i] = newaxis->
GetXbins()->
At(group[d] * i);
1103 else edges[i] = newaxis->
GetXmax();
1104 newaxis->
Set(newbins, edges);
1114 Bool_t wantErrors = haveErrors;
1121 while ((i = iter.
Next(coord)) >= 0) {
1123 for (
Int_t d = 0; d < ndim; ++d) {
1173 Error(
"ComputeIntegral",
"The histogram must have at least one bin.");
1185 while ((i = iter.
Next(coord)) >= 0) {
1189 bool regularBin =
true;
1198 if (!regularBin) v = 0.;
1206 Error(
"ComputeIntegral",
"No hits in regular bins (non over/underflow).");
1255 if (v == 0. && err == 0. && options && strchr(options,
'0')) {
1268 Printf(
"Bin at (%s) = %g (+/- %g)", coord.
Data(),
v, err);
1285 if (from < 0) from = 0;
1286 if (howmany == -1) howmany =
GetNbins();
1290 if (options && (strchr(options,
'x') || strchr(options,
'X'))) {
1294 bin[dim] = from % nbins[dim];
1298 for (
Long64_t i = 0; i < howmany; ++i) {
1304 if (bin[dim] >= nbins[dim]) {
1316 for (
Long64_t i = from; i < from + howmany; ++i) {
1334 Bool_t optAxis = options && (strchr(options,
'A') || (strchr(options,
'a')));
1335 Bool_t optMem = options && (strchr(options,
'M') || (strchr(options,
'm')));
1336 Bool_t optStat = options && (strchr(options,
'S') || (strchr(options,
's')));
1337 Bool_t optContent = options && (strchr(options,
'C') || (strchr(options,
'c')));
1345 Printf(
" axis %d \"%s\": %d bins (%g..%g), %s bin sizes", dim,
1347 (axis->
GetXbins() ?
"variable" :
"fixed"));
1363 Printf(
" coordinates stored in %d chunks of %d entries\n %g of bins filled using %g of memory compared to an array",
1431 fHist(hist), fAxis(axis), fProj(0)
1457 fProj = fHist->Projection(fAxis);
Abstract array base class.
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
Double_t ComputeIntegral()
Calculate the integral of the histogram.
Int_t GetFirst() const
Return first bin on the axis i.e.
Double_t GetBinContent(const Int_t *idx) const
Double_t At(Int_t i) const
virtual const char * GetTitle() const
Returns title of object.
Bool_t GetCalculateErrors() const
virtual void Reset(Option_t *option="")=0
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
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 Floor(Double_t x)
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
void SetEntries(Double_t entries)
Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
TFitResultPtr Fit(TF1 *f1, Option_t *option="", Option_t *goption="")
Fit a THnSparse with function f.
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
virtual Long64_t GetNbins() const =0
void Multiply(const THnBase *h)
Multiply this histogram by histogram h this = this * h Note that if h has Sumw2 set, Sumw2 is automatically called for this if not already set.
TString & ReplaceAll(const TString &s1, const TString &s2)
virtual Int_t GetDimension() const
virtual void SetName(const char *name)
Change (i.e.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Int_t GetChunkSize() const
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
void Scale(Double_t c)
Scale contents and errors of this histogram by c: this = this * c It does not modify the histogram's ...
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 GetRandom(Double_t *rand, Bool_t subBinRandom=kTRUE)
Generate an n-dimensional random tuple based on the histogrammed distribution.
void ToLower()
Change string to lower-case.
Double_t GetSumwx2(Int_t dim) const
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
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.
Int_t GetEntriesFast() const
const TKDTreeBinning * bins
virtual void SetNameTitle(const char *name, const char *title)
Change (i.e. set) all the TNamed parameters (name and title).
TString & Insert(Ssiz_t pos, const char *s)
void AddBinContent(const Int_t *x, Double_t v=1.)
void Print(Option_t *option="") const
Print a THnBase.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
const char * Data() const
Double_t fEntries
browser-helpers for each axis
THnBaseBrowsable(THnBase *hist, Int_t axis)
Construct a THnBaseBrowsable.
TBrowser helper for THnBase.
Int_t GetNdimensions() const
static Int_t FitOptionsMake(Option_t *option, Foption_t &Foption)
flag to call TH1::Sumw2 automatically at histogram creation time
Efficient multidimensional histogram.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
The TNamed class is the base class for all named ROOT classes.
virtual Bool_t IsEmpty() const
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
virtual void Reserve(Long64_t)
Double_t GetSparseFractionBins() const
Return the amount of filled bins over all bins.
std::map< std::string, std::string >::const_iterator iter
enum THnBase::@95 fIntegralStatus
array with bin weight sums
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.
void SetBinContent(const Int_t *idx, Double_t v)
Bool_t IsInRange(Int_t *coord) const
Check whether bin coord is in range, as defined by TAxis::SetRange().
std::vector< std::vector< double > > Data
virtual ~THnBaseBinIter()
Destruct a bin iterator.
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 ...
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 !wan...
void Browse(TBrowser *b)
Browse an axis of a THnBase, i.e. draw its projection.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
virtual void ResetStats()
Reset the statistics including the number of entries and replace with values calculates from bin cont...
virtual void SetBinError(Int_t bin, Double_t error)
see convention for numbering bins in TH1::GetBin
virtual Double_t GetBinError2(Long64_t linidx) const =0
THnBase * RebinBase(Int_t group) const
Combine the content of "group" neighboring bins into a new bin and return the resulting THnBase...
virtual Double_t GetEffectiveEntries() const
number of effective entries of the histogram, neff = (Sum of weights )^2 / (Sum of weight^2 ) In case...
Using a TBrowser one can browse all ROOT objects.
void AddInternal(const THnBase *h, Double_t c, Bool_t rebinned)
Add() implementation for both rebinned histograms and those with identical binning.
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis from bin first to last.
virtual void InitStorage(Int_t *nbins, Int_t chunkSize)=0
Double_t GetEntries() const
virtual void SetFilledBins(Long64_t)
Double_t GetBinError(const Int_t *idx) const
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Class to manage histogram axis.
Long64_t Next(Int_t *coord=0)
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual Long64_t GetBin(const Int_t *idx) const =0
void Init(const char *name, const char *title, const TObjArray *axes, Bool_t keepTargetAxis, Int_t chunkSize=1024 *16)
Initialize axes and name.
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
Collection abstract base class.
virtual ~THnBase()
Destruct a THnBase.
Double_t GetSumwx(Int_t dim) const
Bool_t TestBit(UInt_t f) const
char * Form(const char *fmt,...)
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...
virtual const char * GetName() const
Returns name of object.
The ROOT global object gROOT contains a list of all defined classes.
const char * GetTitle() const
Returns title of object.
TAxis * GetAxis(Int_t dim) const
void SetBinEdges(Int_t idim, const Double_t *bins)
Set the axis # of bins and bin limits on dimension idim.
R__EXTERN TRandom * gRandom
virtual void Rebuild(Option_t *option="")
Using the current bin info, recompute the arrays for contents and errors.
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
const Double_t * GetArray() const
TString & Remove(Ssiz_t pos)
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...
Double_t GetSumw2() const
void SetBinError(const Int_t *idx, Double_t e)
virtual Int_t GetSize() const
virtual void SetBinError2(Long64_t bin, Double_t e2)=0
class describing the range in the coordinates it supports multiple range in a coordinate.
Bool_t CheckConsistency(const THnBase *h, const char *tag) const
Consistency check on (some of) the parameters of two histograms (for operations). ...
virtual const char * GetName() const
Returns name of object.
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...
Long64_t Merge(TCollection *list)
Merge this with a list of THnBase's.
~THnBaseBrowsable()
Destruct a THnBaseBrowsable.
virtual void AddBinError2(Long64_t bin, Double_t e2)=0
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.
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Int_t GetLast() const
Return last bin on the axis i.e.
void Browse(TBrowser *b)
Browse a THnSparse: create an entry (ROOT::THnSparseBrowsable) for each dimension.
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Mother of all ROOT objects.
Double_t GetSparseFractionMem() const
Return the amount of used memory over memory that would be used by a non-sparse n-dimensional histogr...
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Iterator over THnBase bins.
TObjArray * GetListOfAxes()
virtual void SetEntries(Double_t n)
Multidimensional histogram base.
const TArrayD * GetXbins() 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)
Bool_t PrintBin(Long64_t idx, Int_t *coord, Option_t *options) const
Print one bin.
Double_t Sqrt(Double_t x)
TObject * At(Int_t idx) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual Bool_t IsInside(const Double_t *x) const
return kTRUE if the point is inside the function range
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0)
Evaluate function with given coordinates and parameters.
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
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
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...
Int_t CeilNint(Double_t x)
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Ssiz_t First(char c) const
Find first occurrence of a character c.
void ResetBase(Option_t *option="")
Clear the histogram.
void SetTitle(const char *title)
Change (i.e.
void PrintEntries(Long64_t from=0, Long64_t howmany=-1, Option_t *options=0) const
Print "howmany" entries starting at "from".
Int_t GetCoord(Int_t dim) const
Bool_t HaveSkippedBin() const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.