Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/RooHist.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooHist.h,v 1.22 2007/05/11 09:11:30 verkerke Exp $
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 #ifndef ROO_HIST
0017 #define ROO_HIST
0018 
0019 #include "TGraphAsymmErrors.h"
0020 #include "RooPlotable.h"
0021 #include "RooAbsData.h"
0022 
0023 class RooAbsRealLValue;
0024 class RooCurve;
0025 class RooFitResult;
0026 
0027 class TH1;
0028 
0029 class RooHist : public TGraphAsymmErrors, public RooPlotable {
0030 public:
0031   RooHist() {}
0032   RooHist(double nominalBinWidth, double nSigma= 1, double xErrorFrac=1.0, double scaleFactor=1.0);
0033   RooHist(const TH1 &data, double nominalBinWidth= 0, double nSigma= 1, RooAbsData::ErrorType=RooAbsData::Poisson,
0034      double xErrorFrac=1.0, bool correctForBinWidth=true, double scaleFactor=1.);
0035   RooHist(const TH1 &data1, const TH1 &data2, double nominalBinWidth= 0, double nSigma= 1, RooAbsData::ErrorType=RooAbsData::Poisson,
0036      double xErrorFrac=1.0, bool efficiency=false, double scaleFactor=1.0);
0037   RooHist(const RooHist& hist1, const RooHist& hist2, double wgt1=1.0, double wgt2=1.0,
0038      RooAbsData::ErrorType etype=RooAbsData::Poisson, double xErrorFrac=1.0) ;
0039   RooHist(const RooAbsReal &f, RooAbsRealLValue &x, double xErrorFrac=1.0, double scaleFactor=1.0, const RooArgSet *normVars = nullptr, const RooFitResult* fr = nullptr);
0040 
0041   // add a datapoint for a bin with n entries, using a Poisson error
0042   void addBin(Axis_t binCenter, double n, double binWidth= 0, double xErrorFrac=1.0, double scaleFactor=1.0);
0043   // add a datapoint for a bin with n entries, using a given error
0044   void addBinWithError(Axis_t binCenter, double n, double elow, double ehigh, double binWidth= 0,
0045              double xErrorFrac=1.0, bool correctForBinWidth=true, double scaleFactor=1.0);
0046   // add a datapoint for a bin with n entries, using a given x and y error
0047   void addBinWithXYError(Axis_t binCenter, double n, double exlow, double exhigh, double eylow, double eyhigh,
0048                          double scaleFactor=1.0);
0049   // add a datapoint for the asymmetry (n1-n2)/(n1+n2), using a binomial error
0050   void addAsymmetryBin(Axis_t binCenter, Int_t n1, Int_t n2, double binWidth= 0, double xErrorFrac=1.0, double scaleFactor=1.0);
0051   // add a datapoint for the asymmetry (n1-n2)/(n1+n2), using sum-of-weights error
0052   void addAsymmetryBinWithError(Axis_t binCenter, double n1, double n2, double en1, double en2, double binWidth= 0, double xErrorFrac=1.0, double scaleFactor=1.0);
0053 
0054   // add a datapoint for the efficiency (n1)/(n1+n2), using a binomial error
0055   void addEfficiencyBin(Axis_t binCenter, Int_t n1, Int_t n2, double binWidth= 0, double xErrorFrac=1.0, double scaleFactor=1.0);
0056   // add a datapoint for the efficiency (n1)/(n1+n2), using a sum-of-weights error
0057   void addEfficiencyBinWithError(Axis_t binCenter, double n1, double n2, double en1, double en2, double binWidth= 0, double xErrorFrac=1.0, double scaleFactor=1.0);
0058 
0059   void printName(std::ostream& os) const override ;
0060   void printTitle(std::ostream& os) const override ;
0061   void printClassName(std::ostream& os) const override ;
0062   void printMultiline(std::ostream& os, Int_t content, bool verbose=false, TString indent= "") const override;
0063 
0064   inline void Print(Option_t *options= nullptr) const override {
0065     // Printing interface
0066     printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
0067   }
0068 
0069   double getFitRangeNEvt() const override;
0070   double getFitRangeNEvt(double xlo, double xhi) const override ;
0071   /// Return (average) bin width of this RooHist.
0072   double getFitRangeBinW() const override { return _nominalBinWidth ; }
0073   inline double getNominalBinWidth() const { return _nominalBinWidth; }
0074   inline void setRawEntries(double n) { _rawEntries = n ; }
0075 
0076   bool hasIdenticalBinning(const RooHist& other) const ;
0077 
0078   RooHist* makeResidHist(const RooCurve& curve,bool normalize=false, bool useAverage=false) const;
0079   RooHist* makePullHist(const RooCurve& curve, bool useAverage=false) const
0080     {return makeResidHist(curve,true,useAverage); }
0081 
0082   bool isIdentical(const RooHist& other, double tol=1e-6, bool verbose=true) const ;
0083 
0084 
0085 protected:
0086   void initialize();
0087   Int_t roundBin(double y);
0088 
0089   friend class RooPlot;
0090 
0091   void fillResidHist(RooHist & residHist, const RooCurve& curve,bool normalize=false, bool useAverage=false) const;
0092   std::unique_ptr<RooHist> createEmptyResidHist(const RooCurve& curve, bool normalize=false) const;
0093 
0094 private:
0095 
0096   void addPoint(Axis_t binCenter, double y, double yscale, double exlow, double exhigh, double eylow, double eyhigh);
0097 
0098   double _nominalBinWidth = 1.0; ///< Average bin width
0099   double _nSigma = 1.0;          ///< Number of 'sigmas' error bars represent
0100   double _entries = 0.0;         ///< Number of entries in histogram
0101   double _rawEntries = 0.0;      ///< Number of entries in source dataset
0102 
0103   std::vector<double> _originalWeights; ///< The original bin weights that were passed to the `RooHist::addBin` functions before scaling and bin width correction
0104 
0105   ClassDefOverride(RooHist,2) // 1-dimensional histogram with error bars
0106 };
0107 
0108 #endif