Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:09:49

0001 #ifndef ATOOLS_Math_Histogram_H
0002 #define ATOOLS_Math_Histogram_H
0003 
0004 #include <string>
0005 
0006 
0007 namespace ATOOLS {
0008 
0009   class Histogram {
0010   private :
0011     int        m_type, m_nbin;
0012     double     m_lower, m_upper;
0013     double   * m_yvalues, * m_y2values;
0014     double   * m_psvalues, * m_ps2values;
0015     double  ** m_mvalues, * m_ysums;
0016     double   * m_tmp;
0017     double     m_fills,m_psfills;
0018     double     m_mfills,m_mpsfills;
0019     double     m_binsize, m_logbase,m_mcb;
0020     int        m_depth;
0021     bool       m_active, m_finished, m_initialized;
0022     int        m_logarithmic,m_fuzzyexp;
0023     std::string m_name;
0024     void MPIInit();
0025   public :
0026     Histogram(int type,double xmin, double xmax, int nbins,
0027           const std::string &name="");
0028     Histogram(const Histogram *);
0029     Histogram(const std::string &,const int=0, std::string content="");
0030     ~Histogram();
0031     void MPISync();
0032     void Reset();
0033     void CopyFrom(const Histogram *histo);
0034     void Insert(double x);
0035     void Insert(int i, double weight, double n=1.0);
0036     void Insert(double x, double weight, double n=1.0);
0037     void InsertMCB(double x, double weight, double =1.);
0038     void InsertMCBIM(double coordinate,double value);
0039     void FinishMCB();
0040     void InsertRange(double start, double end, double value);
0041     void Scale(double factor);
0042     void ScaleHistogramWidth(double factor, int mode=0);
0043     void Output();
0044     void Output(const std::string);
0045     void Finalize();
0046     void Restore();
0047     double GeneratePoint(const double &rn);
0048     double Average() const;
0049     double Mean() const;
0050     double LowEdge(int i) const;
0051     double HighEdge(int i) const;
0052     void SetBin(int i, double y)  { m_yvalues[i]=y; }
0053     void SetBin2(int i, double y2)  { m_y2values[i]=y2; }
0054     void SetBinPS(int i, double ps)  { m_psvalues[i]=ps; }
0055     void SetBinPS2(int i, double ps)  { m_ps2values[i]=ps; }
0056     double Bin(int i) const;
0057     double Bin2(int i) const;
0058     double Bin(double x) const;
0059     double BinOrInterpolate(int i) const;
0060     double BinOrInterpolate(double x) const;
0061     void Extrapolate(double x, double * ys,int mode);
0062     inline void SetFills(double fills) {  m_fills=fills; }
0063 
0064     // basic access methods
0065     int Type() { return m_type; }
0066     int Depth() { return m_depth; }
0067     int    Nbin() const { return m_nbin-2; }
0068     double Xmin() const { return m_lower; }
0069     double Xmax() const { return m_upper; }
0070     double Value(int i) const { return m_yvalues[i]; }
0071     double Value2(int i) const { return m_y2values[i]; }
0072     double Fills() const { return m_fills; }
0073     double BinSize() const { return m_binsize; }
0074 
0075     double Integral() const;
0076     double Ymax() const;
0077     double Ymin() const;
0078     double LogCoeff() const;
0079 
0080 
0081     Histogram & operator+=(const Histogram & histo);
0082     Histogram & operator=(const Histogram & histo);
0083     void Addopt(const Histogram & histo);
0084     void AddGeometric(const Histogram & histo);
0085     void BinMin(const Histogram & histo);
0086     void BinMax(const Histogram & histo);
0087     int CheckStatistics(const Histogram & histo,double& avgs,double& maxs);
0088 
0089     inline const std::string &Name() const { return m_name; }
0090   };
0091 
0092 
0093   /*! 
0094     \file 
0095     \brief contains class Histogram
0096   */
0097 
0098   /*!
0099     \class Histogram
0100     \brief simple histogramm class
0101     
0102     This class can be used to create, file, and write out simple
0103     histograms. It is used in the Primitive_Analysis.
0104     It can store values, and maxima. Equidistant and
0105     logarithmic bining is supported.
0106   */
0107 
0108   /*!
0109     \fn   Histogram::Histogram(int type,double xmin,double xmax, int nbins, const std::string &name="")
0110     \brief Constructor
0111 
0112     \param type   type of histogram (see below)
0113     \param xmin   start of histogram
0114     \param xmax   end of histogram
0115     \param nbins  number of bins
0116     \param name   the name to give the histogram
0117 
0118     Initialise a new Histogram acording to the given parameters
0119     \verbatim
0120        type = logarithmic*10 + (depth-1)  
0121        (depth==1) means normal histo 
0122        (depth==2) means hist with maximum store
0123     \endverbatim
0124   */
0125 
0126   /*!
0127     \fn Histogram::Histogram(const Histogram *)
0128     \brief Copy constructor
0129   */
0130 
0131   /*!
0132     \fn Histogram::Histogram(const std::string & pID,const int mode=0, std::string content="")
0133     \brief Constructor reading in values from a file or from string content
0134            if provided.
0135   */    
0136 
0137   /*!
0138     \fn Histogram::~Histogram()
0139     \brief Destructor
0140   */
0141 
0142   /*!
0143     \fn void Histogram::Reset()
0144     \brief set all bins of the histogram to zero
0145   */
0146   
0147   /*! 
0148     \fn void Histogram::Insert(double x)
0149     \brief add one to corresponding bin
0150   */
0151     
0152   /*!
0153     \fn void  Histogram::Insert(double x, double weight, double n=1.0)
0154     \brief add value (and possibly the maximum) to corresponding bin
0155   */
0156     
0157   /*!
0158     \fn  void  Histogram::InsertRange(double start, double end, double value)
0159     \brief fill all bin in range (bins only partly covered by range are filled coresspondingly less)
0160   */
0161     
0162   /*!
0163     \fn void  Histogram::Scale(double factor)
0164     \brief multiply all bins with a given scale factor
0165   */
0166 
0167   /*!
0168     \fn void  Histogram::ScaleHistogramWidth(double factor, int mode=0)
0169     \brief multiply binsize and Xmax with factor ("stretch" the histogram)
0170     \param factor Factor by which to scale the bin width.
0171     \param mode bin height rescaling:
0172       - 0: rescale bin height with factor (don't change integral over bins)
0173       - 1: don't rescale bin height
0174   */
0175 
0176     
0177   /*!
0178     \fn void  Histogram::Output()
0179     \brief print content of histogram on screen
0180   */
0181     
0182   /*!
0183     \fn  void  Histogram::Output(std::string)
0184     \brief write out content of histogram in a file of given name
0185   */
0186     
0187   /*!
0188     \fn void  Histogram::Finalize()
0189     \brief normalize the historam to one
0190   */
0191     
0192   /*!
0193     \fn  double Histogram::Bin(int i) const
0194     \brief return the value array of a specified bin
0195   */
0196     
0197   /*!
0198     \fn  double Histogram::Bin(double x) const
0199     \brief return the value array of the bin where the given x falls in
0200   */
0201     
0202   /*!
0203     \fn void Histogram::Extrapolate(double x ,double * ys ,int mode)
0204     \brief extrapolate, returns array with value and maximum
0205 
0206       This method extrapolates an histogram in the first entry and
0207       takes the maximum of the two adjacent entries for all other entries,
0208       therefore it is suited for some kind of weighted (by the first entry)
0209       hit or miss method.
0210       The integer in the method Extrapolate labels how the histogram is treated.
0211       mode usage
0212       \verbatim
0213       0    Take only the bin in question
0214       +-1  Add all bins to the left (-) or right (+)
0215       +-2  Add all bins apart from the overflow ones to the left (-) or right (+)
0216 
0217       Tested is only mode "+1"!!!
0218       \endverbatim
0219   */
0220     
0221   /*!
0222     \fn int     Histogram::Depth() 
0223     \brief returns number of values per bin
0224 
0225     Depth is 1 if only the value is stored, and 2 if also a maximum is obtainable.
0226   */
0227       
0228   /*!
0229     \fn int     Histogram::Nbin() const
0230     \brief  returns number of bins (not counting the overflow bins)
0231   */
0232       
0233   /*!
0234     \fn double  Histogram::Xmin() const 
0235     \brief  returns start of histogram
0236   */
0237       
0238   /*!
0239     \fn double  Histogram::Xmax() const 
0240     \brief  return end of histogram
0241   */
0242       
0243   /*!
0244     \fn double  Histogram::Value(int i) const
0245     \brief  returns the value of bin with number i.
0246   */
0247 }
0248 
0249 
0250 #endif