Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef ATOOLS_Math_Histogram_2D_H
0002 #define ATOOLS_Math_Histogram_2D_H
0003 
0004 #include <string>
0005 
0006 
0007 namespace ATOOLS {
0008 
0009   class Histogram_2D {
0010   private :
0011     int        m_type, m_nbin, m_nbinx, m_nbiny;
0012     double     m_lowerx, m_upperx, m_lowery, m_uppery;
0013     double   * m_zvalues;
0014     double   * m_z2values;
0015     double   * m_psvalues;
0016     double   * m_tmp;
0017     double     m_fills,m_psfills;
0018     double     m_binsizex, m_binsizey, m_logbasex, m_logbasey, m_mcb;
0019     int        m_depth;
0020     bool       m_active, m_finished, m_initialized;
0021     int        m_logarithmicx, m_logarithmicy,m_fuzzyexp;
0022   public :
0023     Histogram_2D(int type,double xmin, double xmax, int nbinsx,
0024                           double ymin, double ymax, int nbinsy);
0025     Histogram_2D(const Histogram_2D *);
0026     Histogram_2D(const std::string &);
0027     ~Histogram_2D();
0028     void Reset();
0029     void Insert(double x, double y);
0030     void Insert(int ix, int iy, double weight, double n=1.);
0031     void Insert(double x, double y, double weight, double n=1.);
0032     void InsertMCB(double x, double y, double weight, double n=1.);
0033     void InsertMCBIM(double coordinatex, double coordinatey, double value);
0034     void FinishMCB();
0035     void InsertRange(double startx, double endx,
0036                      double starty, double endy, double value);
0037     void Scale(double factor);
0038     void Output();
0039     void Output(const std::string);
0040     void Finalize();
0041     void Restore();
0042     double Mean() const;
0043     inline void SetBin(int i, double entry)  { m_zvalues[i]=entry; }
0044     inline void SetBin(int ix, int iy, double entry)  { m_zvalues[iy+ix*m_nbiny+1]=entry; }
0045     inline double Bin(int i) { return m_zvalues[i]; }
0046     inline double Bin(int ix, int iy) { return m_zvalues[iy+ix*m_nbiny+1]; }
0047     double Bin(double x, double y);
0048 //     void Extrapolate(double x, double * ys,int mode); //??
0049     inline void SetFills(double fills) {  m_fills=fills; }
0050 
0051     // basic access methods
0052     int Type() { return m_type; }
0053     int Depth() { return m_depth; }
0054     int    Nbin() const { return m_nbin-2; }
0055     int    NbinX() const { return m_nbinx; }
0056     int    NbinY() const { return m_nbiny; }
0057     double Xmin() const { return m_lowerx; }
0058     double Xmax() const { return m_upperx; }
0059     double Ymin() const { return m_lowery; }
0060     double Ymax() const { return m_uppery; }
0061     double Value(int i) const { return m_zvalues[i]; }
0062     double Value(int ix, int iy) const { return m_zvalues[iy+ix*m_nbiny+1]; }
0063     double Value2(int i) const { return m_z2values[i]; }
0064     double Value2(int ix, int iy) const { return m_z2values[iy+ix*m_nbiny+1]; }
0065     double Fills() const { return m_fills; }
0066     double BinSize() const { return m_binsizex*m_binsizey; }
0067     double BinSizeX() const { return m_binsizex; }
0068     double BinSizeY() const { return m_binsizey; }
0069 
0070     double Integral() const;
0071     double Integral(int xminbin, int xmaxbin, int yminbin, int ymaxbin) const;
0072     double Integral(double xmin, double xmax, double ymin, double ymax) const;
0073     double Zmax() const;
0074     double Zmin() const;
0075     double LogCoeff() const;
0076 
0077 
0078     Histogram_2D & operator+=(const Histogram_2D & histo);
0079     void Addopt(const Histogram_2D & histo);
0080   };
0081 
0082 
0083   /*!
0084     \file
0085     \brief contains class Histogram_2D
0086   */
0087 
0088   /*!
0089     \class Histogram_2D
0090     \brief simple histogramm class
0091 
0092     This class can be used to create, file, and write out simple
0093     2D histograms. It is not yet used in the Primitive_Analysis.
0094     It can store values, and maxima. Equidistant and
0095     logarithmic bining is supported in both x and y.
0096   */
0097 
0098   /*!
0099     \fn   Histogram_2D::Histogram_2D(int type,double xmin,double xmax, int nbinsx, double ymin, double ymax, int nbinsy)
0100     \brief Constructor
0101 
0102     \param type   type of histogram (see below)
0103     \param xmin   start of histogram in x
0104     \param xmax   end of histogram in x
0105     \param nbinsy number of bins in x
0106     \param ymin   start of histogram in y
0107     \param ymax   end of histogram in y
0108     \param nbinsx number of bins in y
0109 
0110     Initialise a new Histogram_2D acording to the given parameters
0111     \verbatim
0112        type = logarithmicx*100 + logarithmicy*10 + (depth-1)
0113        (depth==1) means normal histo
0114        (depth==2) means hist with maximum store
0115     \endverbatim
0116   */
0117 
0118   /*!
0119     \fn Histogram_2D::Histogram_2D(const Histogram_2D *)
0120     \brief Copy constructor
0121   */
0122 
0123   /*!
0124     \fn Histogram_2D::Histogram_2D(const std::string&)
0125     \brief Constructor reading in values from a file
0126   */
0127 
0128   /*!
0129     \fn Histogram_2D::~Histogram_2D()
0130     \brief Destructor
0131   */
0132 
0133   /*!
0134     \fn void Histogram_2D::Reset()
0135     \brief set all bins of the histogram to zero
0136   */
0137 
0138   /*!
0139     \fn void Histogram_2D::Insert(double x, double y)
0140     \brief add one to corresponding bin
0141   */
0142 
0143   /*!
0144     \fn void  Histogram_2D::Insert(double x, double y, double weight, double n=1.0)
0145     \brief add value (and possibly the maximum) to corresponding bin
0146   */
0147 
0148   /*!
0149     \fn  void  Histogram_2D::InsertRange(double start, double end, double value)
0150     \brief fill all bin in range (bins only partly covered by range are filled coresspondingly less)
0151   */
0152 
0153   /*!
0154     \fn void  Histogram_2D::Scale(double factor)
0155     \brief multiply all bins with a given scale factor
0156   */
0157 
0158   /*!
0159     \fn void  Histogram_2D::Output()
0160     \brief print content of histogram on screen
0161   */
0162 
0163   /*!
0164     \fn  void  Histogram_2D::Output(std::string)
0165     \brief write out content of histogram in a file of given name
0166   */
0167 
0168   /*!
0169     \fn void  Histogram_2D::Finalize()
0170     \brief normalize the historam to one
0171   */
0172 
0173   /*!
0174     \fn  double Histogram_2D::Bin(int)
0175     \brief return the value array of a specified bin
0176   */
0177 
0178   /*!
0179     \fn  double Histogram_2D::Bin(double x, double y)
0180     \brief return the value array of the bin where the given x and y falls in
0181   */
0182 
0183   /*! \cond DOCUMENT_COMMENTED_OUT_FUNCTION
0184     \fn void Histogram_2D::Extrapolate(double x ,double * ys ,int mode)
0185     \brief extrapolate, returns array with value and maximum
0186 
0187       This method extrapolates an histogram in the first entry and
0188       takes the maximum of the two adjacent entries for all other entries,
0189       therefore it is suited for some kind of weighted (by the first entry)
0190       hit or miss method.
0191       The integer in the method Extrapolate labels how the histogram is treated.
0192       mode usage
0193       \verbatim
0194       0    Take only the bin in question
0195       +-1  Add all bins to the left (-) or right (+)
0196       +-2  Add all bins apart from the overflow ones to the left (-) or right (+)
0197 
0198       Tested is only mode "+1"!!!
0199       \endverbatim \endcond
0200   */
0201 
0202   /*!
0203     \fn int     Histogram_2D::Depth()
0204     \brief returns number of values per bin
0205 
0206     Depth is 1 if only the value is stored, and 2 if also a maximum is obtainable.
0207   */
0208 
0209   /*!
0210     \fn int     Histogram_2D::Nbin() const
0211     \brief  returns number of bins (not counting the overflow bins)
0212   */
0213 
0214   /*!
0215     \fn double  Histogram_2D::Xmin() const
0216     \brief  returns start of histogram
0217   */
0218 
0219   /*!
0220     \fn double  Histogram_2D::Xmax() const
0221     \brief  return end of histogram
0222   */
0223 
0224   /*!
0225     \fn double  Histogram_2D::Value(int i) const
0226     \brief  returns the value of bin with number i.
0227   */
0228 }
0229 
0230 
0231 #endif