36 class THn:
public THnBase {
39 THn& operator=(
const THn&);
42 void AllocCoordBuf()
const;
43 void InitStorage(Int_t* nbins, Int_t chunkSize);
46 THn(
const char* name,
const char* title, Int_t dim,
const Int_t* nbins,
47 const Double_t* xmin,
const Double_t* xmax);
52 static THn* CreateHn(
const char* name,
const char* title,
const TH1* h1) {
53 return (THn*) CreateHnAny(name, title, h1, kFALSE , -1);
55 static THn* CreateHn(
const char* name,
const char* title,
const THnBase* hn) {
56 return (THn*) CreateHnAny(name, title, hn, kFALSE , -1);
59 ROOT::Internal::THnBaseBinIter* CreateIter(Bool_t respectAxisRange)
const;
60 Long64_t GetNbins()
const {
return GetArray().GetNbins(); }
62 Long64_t GetBin(
const Int_t* idx)
const {
63 return GetArray().GetBin(idx);
65 Long64_t GetBin(
const Double_t* x)
const {
66 if (!fCoordBuf) AllocCoordBuf();
67 for (Int_t d = 0; d < fNdimensions; ++d) {
68 fCoordBuf[d] = GetAxis(d)->FindFixBin(x[d]);
70 return GetArray().GetBin(fCoordBuf);
72 Long64_t GetBin(
const char* name[])
const {
73 if (!fCoordBuf) AllocCoordBuf();
74 for (Int_t d = 0; d < fNdimensions; ++d) {
75 fCoordBuf[d] = GetAxis(d)->FindBin(name[d]);
77 return GetArray().GetBin(fCoordBuf);
80 Long64_t GetBin(
const Int_t* idx, Bool_t = kTRUE) {
81 return const_cast<const THn*
>(
this)->GetBin(idx);
83 Long64_t GetBin(
const Double_t* x, Bool_t = kTRUE) {
84 return const_cast<const THn*
>(
this)->GetBin(x);
86 Long64_t GetBin(
const char* name[], Bool_t = kTRUE) {
87 return const_cast<const THn*
>(
this)->GetBin(name);
90 void FillBin(Long64_t bin, Double_t w) {
93 GetArray().AddAt(bin, w);
94 if (GetCalculateErrors()) {
95 fSumw2.AddAt(bin, w * w);
100 void SetBinContent(
const Int_t* idx, Double_t v) {
103 THnBase::SetBinContent(idx, v);
105 void SetBinContent(Long64_t bin, Double_t v) {
106 GetArray().SetAsDouble(bin, v);
108 void SetBinError2(Long64_t bin, Double_t e2) {
109 if (!GetCalculateErrors()) Sumw2();
112 void AddBinContent(
const Int_t* idx, Double_t v = 1.) {
115 THnBase::AddBinContent(idx, v);
117 void AddBinContent(Long64_t bin, Double_t v = 1.) {
118 GetArray().AddAt(bin, v);
120 void AddBinError2(Long64_t bin, Double_t e2) {
121 fSumw2.At(bin) += e2;
123 Double_t GetBinContent(
const Int_t *idx)
const {
126 return THnBase::GetBinContent(idx);
128 Double_t GetBinContent(Long64_t bin, Int_t* idx = 0)
const {
131 const TNDArray& arr = GetArray();
132 Long64_t prevCellSize = arr.GetNbins();
133 for (Int_t i = 0; i < GetNdimensions(); ++i) {
134 Long64_t cellSize = arr.GetCellSize(i);
135 idx[i] = (bin % prevCellSize) / cellSize;
136 prevCellSize = cellSize;
139 return GetArray().AtAsDouble(bin);
141 Double_t GetBinError2(Long64_t linidx)
const {
142 return GetCalculateErrors() ? fSumw2.At(linidx) : GetBinContent(linidx);
145 virtual const TNDArray& GetArray()
const = 0;
146 virtual TNDArray& GetArray() = 0;
150 TH1D* Projection(Int_t xDim, Option_t* option =
"")
const {
154 return THnBase::Projection(xDim, option);
157 TH2D* Projection(Int_t yDim, Int_t xDim,
158 Option_t* option =
"")
const {
162 return THnBase::Projection(yDim, xDim, option);
165 TH3D* Projection(Int_t xDim, Int_t yDim, Int_t zDim,
166 Option_t* option =
"")
const {
170 return THnBase::Projection(xDim, yDim, zDim, option);
173 THn* Projection(Int_t ndim,
const Int_t* dim,
174 Option_t* option =
"")
const {
175 return (THn*) ProjectionND(ndim, dim, option);
178 THn* Rebin(Int_t group)
const {
179 return (THn*) RebinBase(group);
181 THn* Rebin(
const Int_t* group)
const {
182 return (THn*) RebinBase(group);
185 void Reset(Option_t* option =
"");
188 TNDArrayT<Double_t> fSumw2;
189 mutable Int_t* fCoordBuf;
227 template <
typename T>
228 class THnT:
public THn {
232 THnT(
const char* name,
const char* title,
233 Int_t dim,
const Int_t* nbins,
234 const Double_t* xmin,
const Double_t* xmax):
235 THn(name, title, dim, nbins, xmin, xmax),
236 fArray(dim, nbins, true) {}
238 const TNDArray& GetArray()
const {
return fArray; }
239 TNDArray& GetArray() {
return fArray; }
246 typedef THnT<Float_t> THnF;
247 typedef THnT<Double_t> THnD;
248 typedef THnT<Char_t> THnC;
249 typedef THnT<Short_t> THnS;
250 typedef THnT<Int_t> THnI;
251 typedef THnT<Long_t> THnL;
252 typedef THnT<Long64_t> THnL64;