File indexing completed on 2025-12-16 10:31:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TH1
0013 #define ROOT_TH1
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "TAxis.h"
0025
0026 #include "TAttLine.h"
0027
0028 #include "TAttFill.h"
0029
0030 #include "TAttMarker.h"
0031
0032 #include "TArrayC.h"
0033 #include "TArrayS.h"
0034 #include "TArrayI.h"
0035 #include "TArrayL64.h"
0036 #include "TArrayF.h"
0037 #include "TArrayD.h"
0038 #include "TDirectory.h"
0039 #include "Foption.h"
0040
0041 #include "TVectorFfwd.h"
0042 #include "TVectorDfwd.h"
0043
0044 #include "TFitResultPtr.h"
0045
0046 #include <algorithm>
0047 #include <cfloat>
0048 #include <string>
0049 #include <stdexcept>
0050 #include <type_traits>
0051 #include <array>
0052 #include <numeric>
0053
0054 class TF1;
0055 class TH1D;
0056 class TBrowser;
0057 class TDirectory;
0058 class TList;
0059 class TCollection;
0060 class TVirtualFFT;
0061 class TVirtualHistPainter;
0062 class TRandom;
0063
0064 namespace ROOT::Internal {
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074 template <typename T>
0075 T Slice(const T &histo, std::vector<Int_t> &args)
0076 {
0077 static_assert(std::is_pointer_v<decltype(histo.fArray)>,
0078 "The type of the histogram to slice must expose the internal array data.");
0079
0080 TDirectory::TContext _{nullptr};
0081 T slicedHisto = histo;
0082
0083 using ValueType = std::remove_pointer_t<decltype(slicedHisto.fArray)>;
0084 slicedHisto.template SliceHistoInPlace<ValueType>(args, slicedHisto.fArray, slicedHisto.fN);
0085 return slicedHisto;
0086 }
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 template <typename T>
0098 void SetSliceContent(T &histo, const std::vector<Double_t> &input,
0099 const std::vector<std::pair<Int_t, Int_t>> &sliceEdges)
0100 {
0101 static_assert(std::is_pointer_v<decltype(histo.fArray)>,
0102 "The type of the histogram to slice must expose the internal array data.");
0103
0104 using ValueType = std::remove_pointer_t<decltype(histo.fArray)>;
0105 histo.template SetSliceContent<ValueType>(input, sliceEdges, histo.fArray);
0106 }
0107 }
0108
0109 class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
0110
0111 public:
0112
0113
0114 enum EBinErrorOpt {
0115 kNormal = 0,
0116 kPoisson = 1 ,
0117 kPoisson2 = 2
0118 };
0119
0120
0121 enum {
0122 kNoAxis = 0,
0123 kXaxis = BIT(0),
0124 kYaxis = BIT(1),
0125 kZaxis = BIT(2),
0126 kAllAxes = kXaxis | kYaxis | kZaxis
0127 };
0128
0129
0130 enum EStatOverflows {
0131 kIgnore = 0,
0132 kConsider = 1,
0133 kNeutral = 2,
0134 };
0135
0136
0137
0138 enum EInconsistencyBits {
0139 kFullyConsistent = 0,
0140 kDifferentLabels = BIT(0),
0141 kDifferentBinLimits = BIT(1),
0142 kDifferentAxisLimits = BIT(2),
0143 kDifferentNumberOfBins = BIT(3),
0144 kDifferentDimensions = BIT(4)
0145 };
0146
0147 friend class TH1Merger;
0148
0149 protected:
0150 Int_t fNcells;
0151 TAxis fXaxis;
0152 TAxis fYaxis;
0153 TAxis fZaxis;
0154 Short_t fBarOffset;
0155 Short_t fBarWidth;
0156 Double_t fEntries;
0157 Double_t fTsumw;
0158 Double_t fTsumw2;
0159 Double_t fTsumwx;
0160 Double_t fTsumwx2;
0161 Double_t fMaximum;
0162 Double_t fMinimum;
0163 Double_t fNormFactor;
0164 TArrayD fContour;
0165 TArrayD fSumw2;
0166 TString fOption;
0167 TList *fFunctions;
0168 Int_t fBufferSize;
0169 Double_t *fBuffer;
0170 TDirectory *fDirectory;
0171 Int_t fDimension;
0172 Double_t *fIntegral;
0173 TVirtualHistPainter *fPainter;
0174 EBinErrorOpt fBinStatErrOpt;
0175 EStatOverflows fStatOverflows;
0176 static Int_t fgBufferSize;
0177 static Bool_t fgAddDirectory;
0178 static Bool_t fgStatOverflows;
0179 static Bool_t fgDefaultSumw2;
0180
0181 public:
0182 static Int_t FitOptionsMake(Option_t *option, Foption_t &Foption);
0183
0184 private:
0185 void Build();
0186
0187 TH1(const TH1&) = delete;
0188 TH1& operator=(const TH1&) = delete;
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205 template <typename ValueType>
0206 void SliceHistoInPlace(std::vector<Int_t> &args, ValueType *&dataArray, Int_t &fN)
0207 {
0208 constexpr Int_t kMaxDim = 3;
0209 Int_t ndim = args.size() / 2;
0210 if (ndim != fDimension) {
0211 throw std::invalid_argument(
0212 Form("Number of dimensions in slice (%d) does not match histogram dimension (%d).", ndim, fDimension));
0213 }
0214
0215
0216 std::array<Int_t, kMaxDim> nBins{}, totalBins{};
0217 std::array<std::vector<Double_t>, kMaxDim> edges;
0218 for (decltype(ndim) d = 0; d < ndim; ++d) {
0219 const auto &axis = (d == 0 ? fXaxis : d == 1 ? fYaxis : fZaxis);
0220 auto start = std::max(1, args[d * 2]);
0221 auto end = std::min(axis.GetNbins() + 1, args[d * 2 + 1]);
0222 nBins[d] = end - start;
0223 totalBins[d] = axis.GetNbins() + 2;
0224 args[2 * d] = start;
0225 args[2 * d + 1] = end;
0226
0227 for (int b = start; b <= end; ++b)
0228 edges[d].push_back(axis.GetBinLowEdge(b));
0229 edges[d].push_back(axis.GetBinUpEdge(end));
0230 }
0231
0232
0233 size_t rowSz = nBins[0] + 2;
0234 size_t planeSz = rowSz * (ndim > 1 ? nBins[1] + 2 : 1);
0235 size_t newSize = planeSz * (ndim > 2 ? nBins[2] + 2 : 1);
0236
0237
0238 auto *newArr = new ValueType[newSize]();
0239
0240 auto rowIncr = 1 + (ndim > 1 ? (rowSz - 1) : 0);
0241 ValueType under = 0, over = 0;
0242 Bool_t firstUnder = false;
0243 Int_t lastOverIdx = 0;
0244
0245
0246 size_t dstIdx = 1 + (ndim > 1 ? rowSz : 0) + (ndim > 2 ? planeSz : 0);
0247 for (auto z = (ndim > 2 ? args[4] : 0); z < (ndim > 2 ? args[5] : 1); ++z) {
0248 for (auto y = (ndim > 1 ? args[2] : 0); y < (ndim > 1 ? args[3] : 1); ++y) {
0249 size_t rowStart = z * totalBins[1] * totalBins[0] + y * totalBins[0] + args[0];
0250 std::copy_n(dataArray + rowStart, nBins[0], newArr + dstIdx);
0251 if (!firstUnder) {
0252 under = std::accumulate(dataArray, dataArray + rowStart, ValueType{});
0253 firstUnder = true;
0254 } else {
0255 under += std::accumulate(dataArray + rowStart - args[0], dataArray + rowStart, ValueType{});
0256 }
0257 lastOverIdx = rowStart - args[0] + totalBins[0];
0258 over += std::accumulate(dataArray + rowStart + nBins[0], dataArray + lastOverIdx, ValueType{});
0259 dstIdx += rowIncr;
0260 }
0261 if (ndim > 2) {
0262 dstIdx += 2 * rowIncr;
0263 }
0264 }
0265
0266
0267 over += std::accumulate(dataArray + lastOverIdx, dataArray + fN, ValueType{});
0268 newArr[0] = under;
0269 newArr[newSize - 1] = over;
0270
0271
0272 delete[] dataArray;
0273 dataArray = newArr;
0274
0275
0276 switch (ndim) {
0277 case 1: this->SetBins(nBins[0], edges[0].data()); break;
0278 case 2: this->SetBins(nBins[0], edges[0].data(), nBins[1], edges[1].data()); break;
0279 case 3: this->SetBins(nBins[0], edges[0].data(), nBins[1], edges[1].data(), nBins[2], edges[2].data()); break;
0280 }
0281
0282
0283 ResetStats();
0284 }
0285
0286 template <typename T>
0287 friend T ROOT::Internal::Slice(const T &histo, std::vector<Int_t> &args);
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300 template <typename ValueType>
0301 void SetSliceContent(const std::vector<Double_t> &values, const std::vector<std::pair<Int_t, Int_t>> &sliceEdges,
0302 ValueType *dataArray)
0303 {
0304 const Int_t ndim = sliceEdges.size();
0305 if (ndim != fDimension) {
0306 throw std::invalid_argument(Form(
0307 "Number of edges in the specified slice (%d) does not match histogram dimension (%d).", ndim, fDimension));
0308 }
0309
0310
0311 auto getSliceIndices = [](const std::vector<std::pair<Int_t, Int_t>> &edges) -> std::vector<std::vector<Int_t>> {
0312 const auto dim = edges.size();
0313 if (dim == 0) {
0314 return {};
0315 }
0316
0317 std::vector<std::vector<Int_t>> slices(dim);
0318 for (size_t d = 0; d < dim; ++d) {
0319 for (auto val = edges[d].first; val < edges[d].second; ++val) {
0320 slices[d].push_back(val);
0321 }
0322 }
0323
0324 size_t totalCombinations = 1;
0325 for (const auto &slice : slices) {
0326 totalCombinations *= slice.size();
0327 }
0328
0329 std::vector<std::vector<Int_t>> result(totalCombinations, std::vector<Int_t>(3, 0));
0330 for (size_t d = 0; d < slices.size(); ++d) {
0331 size_t repeat = 1;
0332 for (size_t i = d + 1; i < slices.size(); ++i) {
0333 repeat *= slices[i].size();
0334 }
0335
0336 size_t index = 0;
0337 for (size_t i = 0; i < totalCombinations; ++i) {
0338 result[i][d] = slices[d][(index / repeat) % slices[d].size()];
0339 ++index;
0340 }
0341 }
0342
0343 return result;
0344 };
0345
0346 auto sliceIndices = getSliceIndices(sliceEdges);
0347
0348 if (values.size() != sliceIndices.size()) {
0349 throw std::invalid_argument("Number of provided values does not match number of bins to set.");
0350 }
0351
0352 for (size_t i = 0; i < sliceIndices.size(); ++i) {
0353 auto globalBin = this->GetBin(sliceIndices[i][0], sliceIndices[i][1], sliceIndices[i][2]);
0354
0355
0356 dataArray[globalBin] = values[i];
0357 }
0358
0359
0360 ResetStats();
0361 }
0362
0363 template <typename T>
0364 friend void ROOT::Internal::SetSliceContent(T &histo, const std::vector<Double_t> &input,
0365 const std::vector<std::pair<Int_t, Int_t>> &sliceEdges);
0366
0367 protected:
0368 TH1();
0369 TH1(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup);
0370 TH1(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins);
0371 TH1(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins);
0372
0373 Int_t AxisChoice(Option_t *axis) const;
0374 virtual Int_t BufferFill(Double_t x, Double_t w);
0375 virtual Bool_t FindNewAxisLimits(const TAxis* axis, const Double_t point, Double_t& newMin, Double_t &newMax);
0376 TString ProvideSaveName(Option_t *option, Bool_t testfdir = kFALSE);
0377 virtual void SavePrimitiveHelp(std::ostream &out, const char *hname, Option_t *option = "");
0378 static Bool_t RecomputeAxisLimits(TAxis& destAxis, const TAxis& anAxis);
0379 static Bool_t SameLimitsAndNBins(const TAxis& axis1, const TAxis& axis2);
0380 Bool_t IsEmpty() const;
0381 UInt_t GetAxisLabelStatus() const;
0382
0383 inline static Double_t AutoP2GetPower2(Double_t x, Bool_t next = kTRUE);
0384 inline static Int_t AutoP2GetBins(Int_t n);
0385 virtual Int_t AutoP2FindLimits(Double_t min, Double_t max);
0386
0387 virtual Double_t DoIntegral(Int_t ix1, Int_t ix2, Int_t iy1, Int_t iy2, Int_t iz1, Int_t iz2, Double_t & err,
0388 Option_t * opt, Bool_t doerr = kFALSE) const;
0389
0390 virtual void DoFillN(Int_t ntimes, const Double_t *x, const Double_t *w, Int_t stride=1);
0391 Bool_t GetStatOverflowsBehaviour() const { return EStatOverflows::kNeutral == fStatOverflows ? fgStatOverflows : EStatOverflows::kConsider == fStatOverflows; }
0392
0393 static bool CheckAxisLimits(const TAxis* a1, const TAxis* a2);
0394 static bool CheckBinLimits(const TAxis* a1, const TAxis* a2);
0395 static bool CheckBinLabels(const TAxis* a1, const TAxis* a2);
0396 static bool CheckEqualAxes(const TAxis* a1, const TAxis* a2);
0397 static bool CheckConsistentSubAxes(const TAxis *a1, Int_t firstBin1, Int_t lastBin1, const TAxis *a2, Int_t firstBin2=0, Int_t lastBin2=0);
0398 int LoggedInconsistency(const char* name, const TH1* h1, const TH1* h2, bool useMerge=false) const;
0399
0400 public:
0401
0402 enum EStatusBits {
0403 kNoStats = BIT(9),
0404 kUserContour = BIT(10),
0405
0406 kLogX = BIT(15),
0407 kIsZoomed = BIT(16),
0408 kNoTitle = BIT(17),
0409 kIsAverage = BIT(18),
0410 kIsNotW = BIT(19),
0411
0412 kAutoBinPTwo = BIT(20),
0413 kIsHighlight = BIT(21)
0414 };
0415
0416
0417
0418
0419
0420
0421 enum {
0422 kNstat = 13
0423 };
0424
0425
0426 ~TH1() override;
0427
0428 virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="");
0429 virtual Bool_t Add(const TH1 *h1, Double_t c1=1);
0430 virtual Bool_t Add(const TH1 *h, const TH1 *h2, Double_t c1=1, Double_t c2=1);
0431
0432
0433 virtual void AddBinContent(Int_t bin) = 0;
0434
0435
0436 virtual void AddBinContent(Int_t bin, Double_t w) = 0;
0437 static void AddDirectory(Bool_t add=kTRUE);
0438 static Bool_t AddDirectoryStatus();
0439 void Browse(TBrowser *b) override;
0440 virtual Bool_t CanExtendAllAxes() const;
0441 virtual Double_t Chi2Test(const TH1* h2, Option_t *option = "UU", Double_t *res = nullptr) const;
0442 virtual Double_t Chi2TestX(const TH1* h2, Double_t &chi2, Int_t &ndf, Int_t &igood,Option_t *option = "UU", Double_t *res = nullptr) const;
0443 virtual Double_t Chisquare(TF1 * f1, Option_t *option = "") const;
0444 static Int_t CheckConsistency(const TH1* h1, const TH1* h2);
0445 virtual void ClearUnderflowAndOverflow();
0446 virtual Double_t ComputeIntegral(Bool_t onlyPositive = false, Option_t *option = "");
0447 TObject* Clone(const char *newname = "") const override;
0448 void Copy(TObject &hnew) const override;
0449 virtual void DirectoryAutoAdd(TDirectory *);
0450 Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
0451 virtual Bool_t Divide(TF1 *f1, Double_t c1=1);
0452 virtual Bool_t Divide(const TH1 *h1);
0453 virtual Bool_t Divide(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1, Option_t *option="");
0454 void Draw(Option_t *option = "") override;
0455 virtual TH1 *DrawCopy(Option_t *option="", const char * name_postfix = "_copy") const;
0456 virtual TH1 *DrawNormalized(Option_t *option="", Double_t norm=1) const;
0457 virtual void DrawPanel();
0458 virtual Int_t BufferEmpty(Int_t action=0);
0459 virtual void Eval(TF1 *f1, Option_t *option="");
0460 void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
0461 virtual void ExtendAxis(Double_t x, TAxis *axis);
0462 virtual TH1 *FFT(TH1* h_output, Option_t *option);
0463 virtual Int_t Fill(Double_t x);
0464 virtual Int_t Fill(Double_t x, Double_t w);
0465 virtual Int_t Fill(const char *name, Double_t w);
0466 virtual void FillN(Int_t ntimes, const Double_t *x, const Double_t *w, Int_t stride=1);
0467 virtual void FillN(Int_t, const Double_t *, const Double_t *, const Double_t *, Int_t) {}
0468 virtual void FillRandom(TF1 *f1, Int_t ntimes=5000, TRandom * rng = nullptr);
0469 void FillRandom(const char *fname, Int_t ntimes=5000, TRandom * rng = nullptr);
0470 virtual void FillRandom(TH1 *h, Int_t ntimes=5000, TRandom * rng = nullptr);
0471 virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0);
0472 virtual Int_t FindFixBin(Double_t x, Double_t y=0, Double_t z=0) const;
0473 virtual Int_t FindFirstBinAbove(Double_t threshold=0, Int_t axis=1, Int_t firstBin=1, Int_t lastBin=-1) const;
0474 virtual Int_t FindLastBinAbove (Double_t threshold=0, Int_t axis=1, Int_t firstBin=1, Int_t lastBin=-1) const;
0475 TObject *FindObject(const char *name) const override;
0476 TObject *FindObject(const TObject *obj) const override;
0477 virtual TFitResultPtr Fit(const char *formula ,Option_t *option="" ,Option_t *goption="", Double_t xmin=0, Double_t xmax=0);
0478 virtual TFitResultPtr Fit(TF1 *f1 ,Option_t *option="" ,Option_t *goption="", Double_t xmin=0, Double_t xmax=0);
0479 virtual void FitPanel();
0480 TH1 *GetAsymmetry(TH1* h2, Double_t c2=1, Double_t dc2=0);
0481 Int_t GetBufferLength() const {return fBuffer ? (Int_t)fBuffer[0] : 0;}
0482 Int_t GetBufferSize () const {return fBufferSize;}
0483 const Double_t *GetBuffer() const {return fBuffer;}
0484 static Int_t GetDefaultBufferSize();
0485 virtual Double_t *GetIntegral();
0486 TH1 *GetCumulative(Bool_t forward = kTRUE, const char* suffix = "_cumulative") const;
0487
0488 TList *GetListOfFunctions() const { return fFunctions; }
0489
0490 virtual Int_t GetNdivisions(Option_t *axis="X") const;
0491 virtual Color_t GetAxisColor(Option_t *axis="X") const;
0492 virtual Color_t GetLabelColor(Option_t *axis="X") const;
0493 virtual Style_t GetLabelFont(Option_t *axis="X") const;
0494 virtual Float_t GetLabelOffset(Option_t *axis="X") const;
0495 virtual Float_t GetLabelSize(Option_t *axis="X") const;
0496 virtual Style_t GetTitleFont(Option_t *axis="X") const;
0497 virtual Float_t GetTitleOffset(Option_t *axis="X") const;
0498 virtual Float_t GetTitleSize(Option_t *axis="X") const;
0499 virtual Float_t GetTickLength(Option_t *axis="X") const;
0500 virtual Float_t GetBarOffset() const {return Float_t(0.001*Float_t(fBarOffset));}
0501 virtual Float_t GetBarWidth() const {return Float_t(0.001*Float_t(fBarWidth));}
0502 virtual Int_t GetContour(Double_t *levels = nullptr);
0503 virtual Double_t GetContourLevel(Int_t level) const;
0504 virtual Double_t GetContourLevelPad(Int_t level) const;
0505
0506 virtual Int_t GetBin(Int_t binx, Int_t biny=0, Int_t binz=0) const;
0507 virtual void GetBinXYZ(Int_t binglobal, Int_t &binx, Int_t &biny, Int_t &binz) const;
0508 virtual Double_t GetBinCenter(Int_t bin) const;
0509 virtual Double_t GetBinContent(Int_t bin) const;
0510 virtual Double_t GetBinContent(Int_t bin, Int_t) const { return GetBinContent(bin); }
0511 virtual Double_t GetBinContent(Int_t bin, Int_t, Int_t) const { return GetBinContent(bin); }
0512 virtual Double_t GetBinError(Int_t bin) const;
0513 virtual Double_t GetBinError(Int_t binx, Int_t biny) const { return GetBinError(GetBin(binx, biny)); }
0514 virtual Double_t GetBinError(Int_t binx, Int_t biny, Int_t binz) const { return GetBinError(GetBin(binx, biny, binz)); }
0515 virtual Double_t GetBinErrorLow(Int_t bin) const;
0516 virtual Double_t GetBinErrorUp(Int_t bin) const;
0517 virtual EBinErrorOpt GetBinErrorOption() const { return fBinStatErrOpt; }
0518 virtual Double_t GetBinLowEdge(Int_t bin) const;
0519 virtual Double_t GetBinWidth(Int_t bin) const;
0520 virtual Double_t GetBinWithContent(Double_t c, Int_t &binx, Int_t firstx = 0, Int_t lastx = 0,Double_t maxdiff = 0) const;
0521 virtual void GetCenter(Double_t *center) const;
0522 static Bool_t GetDefaultSumw2();
0523 TDirectory *GetDirectory() const {return fDirectory;}
0524 virtual Double_t GetEntries() const;
0525 virtual Double_t GetEffectiveEntries() const;
0526 virtual TF1 *GetFunction(const char *name) const;
0527 virtual Int_t GetDimension() const { return fDimension; }
0528 virtual Double_t GetKurtosis(Int_t axis=1) const;
0529 virtual void GetLowEdge(Double_t *edge) const;
0530 virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const;
0531 virtual Int_t GetMaximumBin() const;
0532 virtual Int_t GetMaximumBin(Int_t &locmax, Int_t &locmay, Int_t &locmaz) const;
0533 virtual Double_t GetMaximumStored() const {return fMaximum;}
0534 virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const;
0535 virtual Int_t GetMinimumBin() const;
0536 virtual Int_t GetMinimumBin(Int_t &locmix, Int_t &locmiy, Int_t &locmiz) const;
0537 virtual Double_t GetMinimumStored() const {return fMinimum;}
0538 virtual void GetMinimumAndMaximum(Double_t& min, Double_t& max) const;
0539 virtual Double_t GetMean(Int_t axis=1) const;
0540 virtual Double_t GetMeanError(Int_t axis=1) const;
0541 virtual Int_t GetNbinsX() const {return fXaxis.GetNbins();}
0542 virtual Int_t GetNbinsY() const {return fYaxis.GetNbins();}
0543 virtual Int_t GetNbinsZ() const {return fZaxis.GetNbins();}
0544 virtual Int_t GetNcells() const {return fNcells; }
0545 virtual Double_t GetNormFactor() const {return fNormFactor;}
0546 char *GetObjectInfo(Int_t px, Int_t py) const override;
0547 Option_t *GetOption() const override { return fOption.Data(); }
0548
0549 TVirtualHistPainter *GetPainter(Option_t *option="");
0550
0551 virtual Int_t GetQuantiles(Int_t n, Double_t *xp, const Double_t *p = nullptr);
0552 virtual Double_t GetRandom(TRandom *rng = nullptr, Option_t *option = "") const;
0553 virtual void GetStats(Double_t *stats) const;
0554 virtual Double_t GetStdDev(Int_t axis=1) const;
0555 virtual Double_t GetStdDevError(Int_t axis=1) const;
0556 Double_t GetSumOfAllWeights(const bool includeOverflow) const;
0557
0558
0559 virtual Double_t GetSumOfWeights() const { return GetSumOfAllWeights(false); }
0560 virtual TArrayD *GetSumw2() {return &fSumw2;}
0561 virtual const TArrayD *GetSumw2() const {return &fSumw2;}
0562 virtual Int_t GetSumw2N() const {return fSumw2.fN;}
0563
0564
0565
0566 Double_t GetRMS(Int_t axis=1) const { return GetStdDev(axis); }
0567 Double_t GetRMSError(Int_t axis=1) const { return GetStdDevError(axis); }
0568
0569 virtual Double_t GetSkewness(Int_t axis=1) const;
0570 EStatOverflows GetStatOverflows() const { return fStatOverflows; }
0571 TAxis* GetXaxis() { return &fXaxis; }
0572 TAxis* GetYaxis() { return &fYaxis; }
0573 TAxis* GetZaxis() { return &fZaxis; }
0574 const TAxis* GetXaxis() const { return &fXaxis; }
0575 const TAxis* GetYaxis() const { return &fYaxis; }
0576 const TAxis* GetZaxis() const { return &fZaxis; }
0577 virtual Double_t Integral(Option_t *option="") const;
0578 virtual Double_t Integral(Int_t binx1, Int_t binx2, Option_t *option="") const;
0579 virtual Double_t IntegralAndError(Int_t binx1, Int_t binx2, Double_t & err, Option_t *option="") const;
0580 virtual Double_t Interpolate(Double_t x) const;
0581 virtual Double_t Interpolate(Double_t x, Double_t y) const;
0582 virtual Double_t Interpolate(Double_t x, Double_t y, Double_t z) const;
0583 Bool_t IsBinOverflow(Int_t bin, Int_t axis = 0) const;
0584 Bool_t IsBinUnderflow(Int_t bin, Int_t axis = 0) const;
0585 virtual Bool_t IsHighlight() const { return TestBit(kIsHighlight); }
0586 virtual Double_t AndersonDarlingTest(const TH1 *h2, Option_t *option="") const;
0587 virtual Double_t AndersonDarlingTest(const TH1 *h2, Double_t &advalue) const;
0588 virtual Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const;
0589 virtual void LabelsDeflate(Option_t *axis="X");
0590 virtual void LabelsInflate(Option_t *axis="X");
0591 virtual void LabelsOption(Option_t *option="h", Option_t *axis="X");
0592 virtual Long64_t Merge(TCollection *list) { return Merge(list,""); }
0593 Long64_t Merge(TCollection *list, Option_t * option);
0594 virtual Bool_t Multiply(TF1 *f1, Double_t c1=1);
0595 virtual Bool_t Multiply(const TH1 *h1);
0596 virtual Bool_t Multiply(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1, Option_t *option="");
0597 virtual void Normalize(Option_t *option="");
0598 void Paint(Option_t *option = "") override;
0599 void Print(Option_t *option = "") const override;
0600 virtual void PutStats(Double_t *stats);
0601 virtual TH1 *Rebin(Int_t ngroup = 2, const char *newname = "", const Double_t *xbins = nullptr);
0602 virtual TH1 *RebinX(Int_t ngroup = 2, const char *newname = "") { return Rebin(ngroup,newname, (Double_t*) nullptr); }
0603 virtual void Rebuild(Option_t *option = "");
0604 void RecursiveRemove(TObject *obj) override;
0605 virtual void Reset(Option_t *option = "");
0606 virtual void ResetStats();
0607 void SaveAs(const char *filename = "hist", Option_t *option = "") const override;
0608 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0609 virtual void Scale(Double_t c1=1, Option_t *option="");
0610 virtual void SetAxisColor(Color_t color=1, Option_t *axis="X");
0611 virtual void SetAxisRange(Double_t xmin, Double_t xmax, Option_t *axis="X");
0612 virtual void SetBarOffset(Float_t offset=0.25) {fBarOffset = Short_t(1000*offset);}
0613 virtual void SetBarWidth(Float_t width=0.5) {fBarWidth = Short_t(1000*width);}
0614 virtual void SetBinContent(Int_t bin, Double_t content);
0615 virtual void SetBinContent(Int_t bin, Int_t, Double_t content) { SetBinContent(bin, content); }
0616 virtual void SetBinContent(Int_t bin, Int_t, Int_t, Double_t content) { SetBinContent(bin, content); }
0617 virtual void SetBinError(Int_t bin, Double_t error);
0618 virtual void SetBinError(Int_t binx, Int_t biny, Double_t error);
0619 virtual void SetBinError(Int_t binx, Int_t biny, Int_t binz, Double_t error);
0620 virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax);
0621 virtual void SetBins(Int_t nx, const Double_t *xBins);
0622 virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax, Int_t ny, Double_t ymin, Double_t ymax);
0623 virtual void SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t *yBins);
0624 virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax, Int_t ny, Double_t ymin, Double_t ymax,
0625 Int_t nz, Double_t zmin, Double_t zmax);
0626 virtual void SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t * yBins, Int_t nz,
0627 const Double_t *zBins);
0628 virtual void SetBinsLength(Int_t = -1) { }
0629 virtual void SetBinErrorOption(EBinErrorOpt type) { fBinStatErrOpt = type; }
0630 virtual void SetBuffer(Int_t bufsize, Option_t *option="");
0631 virtual UInt_t SetCanExtend(UInt_t extendBitMask);
0632 virtual void SetContent(const Double_t *content);
0633 virtual void SetContour(Int_t nlevels, const Double_t *levels = nullptr);
0634 virtual void SetContourLevel(Int_t level, Double_t value);
0635 virtual void SetColors(Color_t linecolor = -1, Color_t markercolor = -1, Color_t fillcolor = -1);
0636 static void SetDefaultBufferSize(Int_t bufsize=1000);
0637 static void SetDefaultSumw2(Bool_t sumw2=kTRUE);
0638 virtual void SetDirectory(TDirectory *dir);
0639 virtual void SetEntries(Double_t n) { fEntries = n; }
0640 virtual void SetError(const Double_t *error);
0641 virtual void SetHighlight(Bool_t set = kTRUE);
0642 virtual void SetLabelColor(Color_t color=1, Option_t *axis="X");
0643 virtual void SetLabelFont(Style_t font=62, Option_t *axis="X");
0644 virtual void SetLabelOffset(Float_t offset=0.005, Option_t *axis="X");
0645 virtual void SetLabelSize(Float_t size=0.02, Option_t *axis="X");
0646
0647
0648
0649
0650
0651
0652 virtual void SetMaximum(Double_t maximum = -1111) { fMaximum = maximum; }
0653 virtual void SetMinimum(Double_t minimum = -1111) { fMinimum = minimum; }
0654
0655 void SetName(const char *name) override;
0656 void SetNameTitle(const char *name, const char *title) override;
0657 virtual void SetNdivisions(Int_t n=510, Option_t *axis="X");
0658 virtual void SetNormFactor(Double_t factor=1) {fNormFactor = factor;}
0659 virtual void SetStats(Bool_t stats=kTRUE);
0660 virtual void SetOption(Option_t *option=" ") {fOption = option;}
0661 virtual void SetTickLength(Float_t length=0.02, Option_t *axis="X");
0662 virtual void SetTitleFont(Style_t font=62, Option_t *axis="X");
0663 virtual void SetTitleOffset(Float_t offset=1, Option_t *axis="X");
0664 virtual void SetTitleSize(Float_t size=0.02, Option_t *axis="X");
0665 void SetStatOverflows(EStatOverflows statOverflows) { fStatOverflows = statOverflows; }
0666 void SetTitle(const char *title) override;
0667 virtual void SetXTitle(const char *title) {fXaxis.SetTitle(title);}
0668 virtual void SetYTitle(const char *title) {fYaxis.SetTitle(title);}
0669 virtual void SetZTitle(const char *title) {fZaxis.SetTitle(title);}
0670 virtual TH1 *ShowBackground(Int_t niter=20, Option_t *option="same");
0671 virtual Int_t ShowPeaks(Double_t sigma=2, Option_t *option="", Double_t threshold=0.05);
0672 virtual void Smooth(Int_t ntimes=1, Option_t *option="");
0673 static void SmoothArray(Int_t NN, Double_t *XX, Int_t ntimes=1);
0674 static void StatOverflows(Bool_t flag=kTRUE);
0675 virtual void Sumw2(Bool_t flag = kTRUE);
0676 void UseCurrentStyle() override;
0677 static TH1 *TransformHisto(TVirtualFFT *fft, TH1* h_output, Option_t *option);
0678
0679 static void SavePrimitiveFunctions(std::ostream &out, const char *varname, TList *lst);
0680
0681
0682 virtual Double_t GetCellContent(Int_t binx, Int_t biny) const
0683 { Obsolete("GetCellContent", "v6-00", "v6-04"); return GetBinContent(GetBin(binx, biny)); }
0684 virtual Double_t GetCellError(Int_t binx, Int_t biny) const
0685 { Obsolete("GetCellError", "v6-00", "v6-04"); return GetBinError(binx, biny); }
0686 virtual void RebinAxis(Double_t x, TAxis *axis)
0687 { Obsolete("RebinAxis", "v6-00", "v6-04"); ExtendAxis(x, axis); }
0688 virtual void SetCellContent(Int_t binx, Int_t biny, Double_t content)
0689 { Obsolete("SetCellContent", "v6-00", "v6-04"); SetBinContent(GetBin(binx, biny), content); }
0690 virtual void SetCellError(Int_t binx, Int_t biny, Double_t content)
0691 { Obsolete("SetCellError", "v6-00", "v6-04"); SetBinError(binx, biny, content); }
0692
0693 ClassDefOverride(TH1,8)
0694
0695 protected:
0696
0697
0698
0699 virtual Double_t RetrieveBinContent(Int_t bin) const = 0;
0700
0701
0702
0703 virtual void UpdateBinContent(Int_t bin, Double_t content) = 0;
0704
0705 virtual Double_t GetBinErrorSqUnchecked(Int_t bin) const { return fSumw2.fN ? fSumw2.fArray[bin] : RetrieveBinContent(bin); }
0706 };
0707
0708 namespace cling {
0709 std::string printValue(TH1 *val);
0710 }
0711
0712
0713
0714 class TH1C : public TH1, public TArrayC {
0715
0716 public:
0717 TH1C();
0718 TH1C(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup);
0719 TH1C(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins);
0720 TH1C(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins);
0721 TH1C(const TH1C &h1c);
0722 TH1C& operator=(const TH1C &h1);
0723 ~TH1C() override;
0724
0725 void AddBinContent(Int_t bin) override;
0726 void AddBinContent(Int_t bin, Double_t w) override;
0727 void Copy(TObject &hnew) const override;
0728 void Reset(Option_t *option="") override;
0729 void SetBinsLength(Int_t n=-1) override;
0730
0731 ClassDefOverride(TH1C,3)
0732
0733 friend TH1C operator*(Double_t c1, const TH1C &h1);
0734 friend TH1C operator*(const TH1C &h1, Double_t c1);
0735 friend TH1C operator+(const TH1C &h1, const TH1C &h2);
0736 friend TH1C operator-(const TH1C &h1, const TH1C &h2);
0737 friend TH1C operator*(const TH1C &h1, const TH1C &h2);
0738 friend TH1C operator/(const TH1C &h1, const TH1C &h2);
0739
0740 protected:
0741 Double_t RetrieveBinContent(Int_t bin) const override { return Double_t (fArray[bin]); }
0742 void UpdateBinContent(Int_t bin, Double_t content) override { fArray[bin] = Char_t (content); }
0743 };
0744
0745 TH1C operator*(Double_t c1, const TH1C &h1);
0746 inline
0747 TH1C operator*(const TH1C &h1, Double_t c1) {return operator*(c1,h1);}
0748 TH1C operator+(const TH1C &h1, const TH1C &h2);
0749 TH1C operator-(const TH1C &h1, const TH1C &h2);
0750 TH1C operator*(const TH1C &h1, const TH1C &h2);
0751 TH1C operator/(const TH1C &h1, const TH1C &h2);
0752
0753
0754
0755 class TH1S : public TH1, public TArrayS {
0756
0757 public:
0758 TH1S();
0759 TH1S(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup);
0760 TH1S(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins);
0761 TH1S(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins);
0762 TH1S(const TH1S &h1s);
0763 TH1S& operator=(const TH1S &h1);
0764 ~TH1S() override;
0765
0766 void AddBinContent(Int_t bin) override;
0767 void AddBinContent(Int_t bin, Double_t w) override;
0768 void Copy(TObject &hnew) const override;
0769 void Reset(Option_t *option="") override;
0770 void SetBinsLength(Int_t n=-1) override;
0771
0772 ClassDefOverride(TH1S,3)
0773
0774 friend TH1S operator*(Double_t c1, const TH1S &h1);
0775 friend TH1S operator*(const TH1S &h1, Double_t c1);
0776 friend TH1S operator+(const TH1S &h1, const TH1S &h2);
0777 friend TH1S operator-(const TH1S &h1, const TH1S &h2);
0778 friend TH1S operator*(const TH1S &h1, const TH1S &h2);
0779 friend TH1S operator/(const TH1S &h1, const TH1S &h2);
0780
0781 protected:
0782 Double_t RetrieveBinContent(Int_t bin) const override { return Double_t (fArray[bin]); }
0783 void UpdateBinContent(Int_t bin, Double_t content) override { fArray[bin] = Short_t (content); }
0784 };
0785
0786 TH1S operator*(Double_t c1, const TH1S &h1);
0787 inline
0788 TH1S operator*(const TH1S &h1, Double_t c1) {return operator*(c1,h1);}
0789 TH1S operator+(const TH1S &h1, const TH1S &h2);
0790 TH1S operator-(const TH1S &h1, const TH1S &h2);
0791 TH1S operator*(const TH1S &h1, const TH1S &h2);
0792 TH1S operator/(const TH1S &h1, const TH1S &h2);
0793
0794
0795
0796 class TH1I: public TH1, public TArrayI {
0797
0798 public:
0799 TH1I();
0800 TH1I(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup);
0801 TH1I(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins);
0802 TH1I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins);
0803 TH1I(const TH1I &h1i);
0804 TH1I& operator=(const TH1I &h1);
0805 ~TH1I() override;
0806
0807 void AddBinContent(Int_t bin) override;
0808 void AddBinContent(Int_t bin, Double_t w) override;
0809 void Copy(TObject &hnew) const override;
0810 void Reset(Option_t *option="") override;
0811 void SetBinsLength(Int_t n=-1) override;
0812
0813 ClassDefOverride(TH1I,3)
0814
0815 friend TH1I operator*(Double_t c1, const TH1I &h1);
0816 friend TH1I operator*(const TH1I &h1, Double_t c1);
0817 friend TH1I operator+(const TH1I &h1, const TH1I &h2);
0818 friend TH1I operator-(const TH1I &h1, const TH1I &h2);
0819 friend TH1I operator*(const TH1I &h1, const TH1I &h2);
0820 friend TH1I operator/(const TH1I &h1, const TH1I &h2);
0821
0822 protected:
0823 Double_t RetrieveBinContent(Int_t bin) const override { return Double_t (fArray[bin]); }
0824 void UpdateBinContent(Int_t bin, Double_t content) override { fArray[bin] = Int_t (content); }
0825 };
0826
0827 TH1I operator*(Double_t c1, const TH1I &h1);
0828 inline
0829 TH1I operator*(const TH1I &h1, Double_t c1) {return operator*(c1,h1);}
0830 TH1I operator+(const TH1I &h1, const TH1I &h2);
0831 TH1I operator-(const TH1I &h1, const TH1I &h2);
0832 TH1I operator*(const TH1I &h1, const TH1I &h2);
0833 TH1I operator/(const TH1I &h1, const TH1I &h2);
0834
0835
0836
0837 class TH1L: public TH1, public TArrayL64 {
0838
0839 public:
0840 TH1L();
0841 TH1L(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup);
0842 TH1L(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins);
0843 TH1L(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins);
0844 TH1L(const TH1L &h1l);
0845 TH1L& operator=(const TH1L &h1);
0846 ~TH1L() override;
0847
0848 void AddBinContent(Int_t bin) override;
0849 void AddBinContent(Int_t bin, Double_t w) override;
0850 void Copy(TObject &hnew) const override;
0851 void Reset(Option_t *option="") override;
0852 void SetBinsLength(Int_t n=-1) override;
0853
0854 ClassDefOverride(TH1L,0)
0855
0856 friend TH1L operator*(Double_t c1, const TH1L &h1);
0857 friend TH1L operator*(const TH1L &h1, Double_t c1);
0858 friend TH1L operator+(const TH1L &h1, const TH1L &h2);
0859 friend TH1L operator-(const TH1L &h1, const TH1L &h2);
0860 friend TH1L operator*(const TH1L &h1, const TH1L &h2);
0861 friend TH1L operator/(const TH1L &h1, const TH1L &h2);
0862
0863 protected:
0864 Double_t RetrieveBinContent(Int_t bin) const override { return Double_t (fArray[bin]); }
0865 void UpdateBinContent(Int_t bin, Double_t content) override { fArray[bin] = Long64_t (content); }
0866 };
0867
0868 TH1L operator*(Double_t c1, const TH1L &h1);
0869 inline
0870 TH1L operator*(const TH1L &h1, Double_t c1) {return operator*(c1,h1);}
0871 TH1L operator+(const TH1L &h1, const TH1L &h2);
0872 TH1L operator-(const TH1L &h1, const TH1L &h2);
0873 TH1L operator*(const TH1L &h1, const TH1L &h2);
0874 TH1L operator/(const TH1L &h1, const TH1L &h2);
0875
0876
0877
0878 class TH1F : public TH1, public TArrayF {
0879
0880 public:
0881 TH1F();
0882 TH1F(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup);
0883 TH1F(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins);
0884 TH1F(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins);
0885 explicit TH1F(const TVectorF &v);
0886 TH1F(const TH1F &h1f);
0887 TH1F& operator=(const TH1F &h1);
0888 ~TH1F() override;
0889
0890
0891
0892 void AddBinContent(Int_t bin) override {++fArray[bin];}
0893
0894
0895
0896 void AddBinContent(Int_t bin, Double_t w) override
0897 { fArray[bin] += Float_t (w); }
0898 void Copy(TObject &hnew) const override;
0899 void Reset(Option_t *option = "") override;
0900 void SetBinsLength(Int_t n=-1) override;
0901
0902 ClassDefOverride(TH1F,3)
0903
0904 friend TH1F operator*(Double_t c1, const TH1F &h1);
0905 friend TH1F operator*(const TH1F &h1, Double_t c1);
0906 friend TH1F operator+(const TH1F &h1, const TH1F &h2);
0907 friend TH1F operator-(const TH1F &h1, const TH1F &h2);
0908 friend TH1F operator*(const TH1F &h1, const TH1F &h2);
0909 friend TH1F operator/(const TH1F &h1, const TH1F &h2);
0910
0911 protected:
0912 Double_t RetrieveBinContent(Int_t bin) const override { return Double_t (fArray[bin]); }
0913 void UpdateBinContent(Int_t bin, Double_t content) override { fArray[bin] = Float_t (content); }
0914 };
0915
0916 TH1F operator*(Double_t c1, const TH1F &h1);
0917 inline
0918 TH1F operator*(const TH1F &h1, Double_t c1) {return operator*(c1,h1);}
0919 TH1F operator+(const TH1F &h1, const TH1F &h2);
0920 TH1F operator-(const TH1F &h1, const TH1F &h2);
0921 TH1F operator*(const TH1F &h1, const TH1F &h2);
0922 TH1F operator/(const TH1F &h1, const TH1F &h2);
0923
0924
0925
0926 class TH1D : public TH1, public TArrayD {
0927
0928 public:
0929 TH1D();
0930 TH1D(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup);
0931 TH1D(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins);
0932 TH1D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins);
0933 explicit TH1D(const TVectorD &v);
0934 TH1D(const TH1D &h1d);
0935 TH1D& operator=(const TH1D &h1);
0936 ~TH1D() override;
0937
0938
0939
0940 void AddBinContent(Int_t bin) override {++fArray[bin];}
0941
0942
0943 void AddBinContent(Int_t bin, Double_t w) override
0944 {fArray[bin] += Double_t (w);}
0945 void Copy(TObject &hnew) const override;
0946 void Reset(Option_t *option = "") override;
0947 void SetBinsLength(Int_t n=-1) override;
0948
0949 ClassDefOverride(TH1D,3)
0950
0951 friend TH1D operator*(Double_t c1, const TH1D &h1);
0952 friend TH1D operator*(const TH1D &h1, Double_t c1);
0953 friend TH1D operator+(const TH1D &h1, const TH1D &h2);
0954 friend TH1D operator-(const TH1D &h1, const TH1D &h2);
0955 friend TH1D operator*(const TH1D &h1, const TH1D &h2);
0956 friend TH1D operator/(const TH1D &h1, const TH1D &h2);
0957
0958 protected:
0959 Double_t RetrieveBinContent(Int_t bin) const override { return fArray[bin]; }
0960 void UpdateBinContent(Int_t bin, Double_t content) override { fArray[bin] = content; }
0961 };
0962
0963 TH1D operator*(Double_t c1, const TH1D &h1);
0964 inline
0965 TH1D operator*(const TH1D &h1, Double_t c1) {return operator*(c1,h1);}
0966 TH1D operator+(const TH1D &h1, const TH1D &h2);
0967 TH1D operator-(const TH1D &h1, const TH1D &h2);
0968 TH1D operator*(const TH1D &h1, const TH1D &h2);
0969 TH1D operator/(const TH1D &h1, const TH1D &h2);
0970
0971 extern TH1 *R__H(Int_t hid);
0972 extern TH1 *R__H(const char *hname);
0973
0974 #endif