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
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
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247 }
0248
0249
0250 #endif