Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:24:27

0001 // -*- C++ -*-
0002 //
0003 // Distribution.hpp is a part of myStatistics
0004 // Copyright (C) 2012-2019 Simon Platzer, The Herwig Collaboration
0005 //
0006 // myStatistics is licenced under version 3 of the GPL, see COPYING for details.
0007 //
0008 #ifndef MYSTATISTICS_Distribution_hpp_included
0009 #define MYSTATISTICS_Distribution_hpp_included
0010 
0011 #include "Histogram.h"
0012 
0013 #include <iostream>
0014 
0015 namespace Statistics {
0016 
0017   /**
0018    * \brief A (one dimensional) distribution
0019    * \author Simon Platzer
0020    */
0021   class Distribution {
0022 
0023   public:
0024 
0025     /**
0026      * A bin in a distribution
0027      */
0028     struct DistributionBin {
0029 
0030       /**
0031        * Default constructor
0032        */
0033       DistributionBin();
0034 
0035       /**
0036        * Construct from a histogram bin, given a number of attempted
0037        * points
0038        */
0039       DistributionBin(const Bin& bin,
0040               double nPoints);
0041 
0042       /**
0043        * Add two distributionBins
0044        */
0045       DistributionBin& operator+=(const DistributionBin& other);
0046 
0047       /**
0048        * Subtract two distributionBins
0049        */
0050       DistributionBin& operator-=(const DistributionBin& other);
0051 
0052       /**
0053        * Multiply two distributionBins
0054        */
0055       DistributionBin& operator*=(const DistributionBin& other);
0056 
0057       /**
0058        * Divide two distributionBins
0059        */
0060       DistributionBin& operator/=(const DistributionBin& other);
0061 
0062       /**
0063        * Fill distribution data from an XML element
0064        */
0065       void fromXML(const XML::Element&);
0066 
0067       /**
0068        * Return an XML element for the data of this distribution
0069        */
0070       XML::Element toXML() const;
0071 
0072       /**
0073        * The bin boundaries
0074        */
0075       std::pair<double,double> boundaries;
0076 
0077       /**
0078        * The bin value
0079        */
0080       double value;
0081 
0082       /**
0083        * The bin error squared
0084        */
0085       double errorSquared;
0086 
0087     };
0088 
0089   public:
0090 
0091     /**
0092      * Default constructor
0093      */
0094     Distribution();
0095 
0096     /**
0097      * Construct from a histogram
0098      */
0099     explicit Distribution(const Histogram& histo,
0100               double nPoints);
0101 
0102     /**
0103      * Destructor
0104      */
0105     virtual ~Distribution();
0106 
0107   public:
0108 
0109     /**
0110      * Return the name of the distribution
0111      */
0112     const std::string& name() const { return theName; }
0113 
0114     /**
0115      * Return the bins in the distribution
0116      */
0117     const std::vector<DistributionBin>& bins() const { return theBins; }
0118 
0119   public:
0120 
0121     /**
0122      * Return true, if this distribution is compatible with another one.
0123      */
0124     bool isCompatible(const Distribution& other) const;
0125 
0126     /**
0127      * Add two distributions
0128      */
0129     Distribution& operator+=(const Distribution& other);
0130 
0131     /**
0132      * Subtract two distributions
0133      */
0134     Distribution& operator-=(const Distribution& other);
0135 
0136     /**
0137      * Multiply two distributions
0138      */
0139     Distribution& operator*=(const Distribution& other);
0140 
0141     /**
0142      * Divide two distributions
0143      */
0144     Distribution& operator/=(const Distribution& other);
0145 
0146   public:
0147 
0148     /**
0149      * Fill distribution data from an XML element
0150      */
0151     void fromXML(const XML::Element&);
0152 
0153     /**
0154      * Return an XML element for the data of this distribution
0155      */
0156     XML::Element toXML() const;
0157 
0158   public:
0159 
0160     /**
0161      * Write out data ready for make-plots, given an analysis name and
0162      * plot options
0163      */
0164     void toMakePlots(const std::string& analysis,
0165              const std::string& options = "") const;
0166 
0167     /**
0168      * Write out data ready for make-plots, given an analysis name and
0169      * plot options
0170      */
0171     void toMakePlots(const std::string& analysis,
0172              const Distribution& lower,
0173              const Distribution& upper,
0174              const std::string& options = "") const;
0175 
0176     /**
0177      * Write out data ready for make-plots, given an analysis name and
0178      * plot options
0179      */
0180     void appendToMakePlots(std::ostream& os,
0181                const std::string& analysis,
0182                const std::string& options = "") const;
0183 
0184     /**
0185      * Write out data ready for make-plots, given an analysis name and
0186      * plot options
0187      */
0188     void appendToMakePlots(std::ostream& os,
0189                const std::string& analysis,
0190                const Distribution& lower,
0191                const Distribution& upper,
0192                const std::string& options = "") const;
0193 
0194   private:
0195 
0196     /**
0197      * The name of the distribution
0198      */
0199     std::string theName;
0200 
0201     /**
0202      * The bins in the distribution
0203      */
0204     std::vector<DistributionBin> theBins;
0205 
0206   };
0207 
0208 }
0209 
0210 #endif // MYSTATISTICS_Distribution_hpp_included