43 class THnBase:
public TNamed {
47 TObjArray fBrowsables;
61 THnBase(
const THnBase&);
62 THnBase& operator=(
const THnBase&);
66 fNdimensions(0), fEntries(0),
67 fTsumw(0), fTsumw2(-1.), fIntegral(0), fIntegralStatus(kNoInt)
70 THnBase(
const char* name,
const char* title, Int_t dim,
71 const Int_t* nbins,
const Double_t* xmin,
const Double_t* xmax);
73 void UpdateXStat(
const Double_t *x, Double_t w = 1.) {
74 if (GetCalculateErrors()) {
75 for (Int_t d = 0; d < fNdimensions; ++d) {
76 const Double_t xd = x[d];
78 fTsumwx2[d] += w * xd * xd;
84 void FillBinBase(Double_t w) {
86 if (GetCalculateErrors()) {
90 fIntegralStatus = kInvalidInt;
93 virtual void InitStorage(Int_t* nbins, Int_t chunkSize) = 0;
94 void Init(
const char* name,
const char* title,
95 const TObjArray* axes, Bool_t keepTargetAxis,
96 Int_t chunkSize = 1024 * 16);
97 THnBase* CloneEmpty(
const char* name,
const char* title,
98 const TObjArray* axes, Bool_t keepTargetAxis)
const;
99 virtual void Reserve(Long64_t ) {}
100 virtual void SetFilledBins(Long64_t ) {};
102 Bool_t CheckConsistency(
const THnBase *h,
const char *tag)
const;
103 TH1* CreateHist(
const char* name,
const char* title,
104 const TObjArray* axes, Bool_t keepTargetAxis)
const;
105 TObject* ProjectionAny(Int_t ndim,
const Int_t* dim,
106 Bool_t wantNDim, Option_t* option =
"")
const;
107 Bool_t PrintBin(Long64_t idx, Int_t* coord, Option_t* options)
const;
108 void AddInternal(
const THnBase* h, Double_t c, Bool_t rebinned);
109 THnBase* RebinBase(Int_t group)
const;
110 THnBase* RebinBase(
const Int_t* group)
const;
111 void ResetBase(Option_t *option=
"");
113 static THnBase* CreateHnAny(
const char* name,
const char* title,
114 const TH1* h1, Bool_t sparse,
115 Int_t chunkSize = 1024 * 16);
116 static THnBase* CreateHnAny(
const char* name,
const char* title,
117 const THnBase* hn, Bool_t sparse,
118 Int_t chunkSize = 1024 * 16);
123 TObjArray* GetListOfAxes() {
return &fAxes; }
124 const TObjArray* GetListOfAxes()
const {
return &fAxes; }
125 TAxis* GetAxis(Int_t dim)
const {
return (TAxis*)fAxes[dim]; }
127 TFitResultPtr Fit(TF1 *f1 ,Option_t *option =
"", Option_t *goption =
"");
128 TList* GetListOfFunctions() {
return 0; }
130 virtual ROOT::Internal::THnBaseBinIter* CreateIter(Bool_t respectAxisRange)
const = 0;
132 virtual Long64_t GetNbins()
const = 0;
133 Double_t GetEntries()
const {
return fEntries; }
134 Double_t GetWeightSum()
const {
return fTsumw; }
135 Int_t GetNdimensions()
const {
return fNdimensions; }
136 Bool_t GetCalculateErrors()
const {
return fTsumw2 >= 0.; }
139 void CalculateErrors(Bool_t calc = kTRUE) {
144 Long64_t Fill(
const Double_t *x, Double_t w = 1.) {
146 Long64_t bin = GetBin(x, kTRUE );
150 Long64_t Fill(
const char* name[], Double_t w = 1.) {
151 Long64_t bin = GetBin(name, kTRUE );
156 virtual void FillBin(Long64_t bin, Double_t w) = 0;
158 void SetBinEdges(Int_t idim,
const Double_t* bins);
159 Bool_t IsInRange(Int_t *coord)
const;
160 Double_t GetBinError(
const Int_t *idx)
const {
return GetBinError(GetBin(idx)); }
161 Double_t GetBinError(Long64_t linidx)
const {
return TMath::Sqrt(GetBinError2(linidx)); }
162 void SetBinError(
const Int_t* idx, Double_t e) { SetBinError(GetBin(idx), e); }
163 void SetBinError(Long64_t bin, Double_t e) { SetBinError2(bin, e*e); }
164 void AddBinContent(
const Int_t* x, Double_t v = 1.) { AddBinContent(GetBin(x), v); }
165 void SetEntries(Double_t entries) { fEntries = entries; }
166 void SetTitle(
const char *title);
168 Double_t GetBinContent(
const Int_t *idx)
const {
return GetBinContent(GetBin(idx)); }
169 virtual Double_t GetBinContent(Long64_t bin, Int_t* idx = 0)
const = 0;
170 virtual Double_t GetBinError2(Long64_t linidx)
const = 0;
171 virtual Long64_t GetBin(
const Int_t* idx)
const = 0;
172 virtual Long64_t GetBin(
const Double_t* x)
const = 0;
173 virtual Long64_t GetBin(
const char* name[])
const = 0;
174 virtual Long64_t GetBin(
const Int_t* idx, Bool_t = kTRUE) = 0;
175 virtual Long64_t GetBin(
const Double_t* x, Bool_t = kTRUE) = 0;
176 virtual Long64_t GetBin(
const char* name[], Bool_t = kTRUE) = 0;
178 void SetBinContent(
const Int_t* idx, Double_t v) { SetBinContent(GetBin(idx), v); }
179 virtual void SetBinContent(Long64_t bin, Double_t v) = 0;
180 virtual void SetBinError2(Long64_t bin, Double_t e2) = 0;
181 virtual void AddBinError2(Long64_t bin, Double_t e2) = 0;
182 virtual void AddBinContent(Long64_t bin, Double_t v = 1.) = 0;
184 Double_t GetSumw()
const {
return fTsumw; }
185 Double_t GetSumw2()
const {
return fTsumw2; }
186 Double_t GetSumwx(Int_t dim)
const {
return fTsumwx[dim]; }
187 Double_t GetSumwx2(Int_t dim)
const {
return fTsumwx2[dim]; }
197 TH1D* Projection(Int_t xDim, Option_t* option =
"")
const {
198 return (TH1D*) ProjectionAny(1, &xDim,
false, option);
210 TH2D* Projection(Int_t yDim, Int_t xDim, Option_t* option =
"")
const {
211 const Int_t dim[2] = {xDim, yDim};
212 return (TH2D*) ProjectionAny(2, dim,
false, option);
223 TH3D* Projection(Int_t xDim, Int_t yDim, Int_t zDim, Option_t* option =
"")
const {
224 const Int_t dim[3] = {xDim, yDim, zDim};
225 return (TH3D*) ProjectionAny(3, dim,
false, option);
228 THnBase* ProjectionND(Int_t ndim,
const Int_t* dim,
229 Option_t* option =
"")
const {
230 return (THnBase*)ProjectionAny(ndim, dim, kTRUE , option);
233 Long64_t Merge(TCollection* list);
235 void Scale(Double_t c);
236 void Add(
const THnBase* h, Double_t c=1.);
237 void Add(
const TH1* hist, Double_t c=1.);
238 void Multiply(
const THnBase* h);
239 void Multiply(TF1* f, Double_t c = 1.);
240 void Divide(
const THnBase* h);
241 void Divide(
const THnBase* h1,
const THnBase* h2, Double_t c1 = 1., Double_t c2 = 1., Option_t* option=
"");
242 void RebinnedAdd(
const THnBase* h, Double_t c=1.);
244 virtual void Reset(Option_t* option =
"") = 0;
245 virtual void Sumw2() = 0;
247 Double_t ComputeIntegral();
248 void GetRandom(Double_t *rand, Bool_t subBinRandom = kTRUE);
250 void Print(Option_t* option =
"")
const;
251 void PrintEntries(Long64_t from = 0, Long64_t howmany = -1, Option_t* options = 0)
const;
252 void PrintBin(Int_t* coord, Option_t* options)
const {
253 PrintBin(-1, coord, options);
255 void PrintBin(Long64_t idx, Option_t* options)
const;
257 void Browse(TBrowser *b);
258 Bool_t IsFolder()
const {
return kTRUE; }
262 ClassDef(THnBase, 1);
264 friend class THnIter;
270 class THnBaseBrowsable:
public TNamed {
272 THnBaseBrowsable(THnBase* hist, Int_t axis);
274 void Browse(TBrowser *b);
275 Bool_t IsFolder()
const {
return kFALSE; }
281 ClassDef(THnBaseBrowsable, 0);
285 class THnBaseBinIter {
287 THnBaseBinIter(Bool_t respectAxisRange):
288 fRespectAxisRange(respectAxisRange), fHaveSkippedBin(kFALSE) {}
289 virtual ~THnBaseBinIter();
290 Bool_t HaveSkippedBin()
const {
return fHaveSkippedBin; }
291 Bool_t RespectsAxisRange()
const {
return fRespectAxisRange; }
293 virtual Int_t GetCoord(Int_t dim)
const = 0;
294 virtual Long64_t Next(Int_t* coord = 0) = 0;
297 Bool_t fRespectAxisRange;
298 Bool_t fHaveSkippedBin;
303 class THnIter:
public TObject {
305 THnIter(
const THnBase* hist, Bool_t respectAxisRange = kFALSE):
306 fIter(hist->CreateIter(respectAxisRange)) {}
313 Long64_t Next(Int_t* coord = 0) {
314 return fIter->Next(coord);
317 Int_t GetCoord(Int_t dim)
const {
return fIter->GetCoord(dim); }
318 Bool_t HaveSkippedBin()
const {
return fIter->HaveSkippedBin(); }
319 Bool_t RespectsAxisRange()
const {
return fIter->RespectsAxisRange(); }
322 ROOT::Internal::THnBaseBinIter* fIter;
323 ClassDef(THnIter, 0);
326 #endif // ROOT_THnBase