00001 #ifndef __BCH1D__H 00002 #define __BCH1D__H 00003 00004 /*! 00005 * \class BCH1D 00006 * \brief A class for handling 1D distributions. 00007 * \author Daniel Kollar 00008 * \author Kevin Kröninger 00009 * \version 1.0 00010 * \date 08.2008 00011 * \detail This class contains a TH1D histogram and some additional 00012 * functions. It is used for marginalized distributions. 00013 */ 00014 00015 /* 00016 * Copyright (C) 2008-2010, Daniel Kollar and Kevin Kroeninger. 00017 * All rights reserved. 00018 * 00019 * For the licensing terms see doc/COPYING. 00020 */ 00021 00022 // --------------------------------------------------------- 00023 00024 #include <vector> 00025 00026 #include <TH1.h> 00027 00028 // --------------------------------------------------------- 00029 00030 class BCH1D 00031 { 00032 public: 00033 00034 /** \name Constructors and destructors */ 00035 /* @{ */ 00036 00037 /** 00038 * The default constructor. */ 00039 BCH1D(); 00040 00041 /** 00042 * The default constructor. */ 00043 BCH1D(TH1D * hist) 00044 { fHistogram = hist; }; 00045 00046 /** 00047 * The default destructor. */ 00048 ~BCH1D(); 00049 00050 /* @} */ 00051 00052 /** \name Member functions (get) */ 00053 /* @{ */ 00054 00055 /** 00056 * @return The one-dimensional histogram. */ 00057 TH1D * GetHistogram() 00058 { return fHistogram; }; 00059 00060 /** 00061 * @return The mean of the distribution. */ 00062 double GetMean() 00063 { return fHistogram -> GetMean(); }; 00064 00065 /** 00066 * @return The mode of the distribution. */ 00067 double GetMode(); 00068 00069 /** 00070 * @return The median of the distribution. */ 00071 double GetMedian() 00072 { return this -> GetQuantile(0.5); }; 00073 00074 /** 00075 * Returns the quantile of the distribution. 00076 * @param probability The probability. 00077 * @return The quantile of the distribution for the probability. 00078 * @see GetLimit(double probability) */ 00079 double GetQuantile(double probablity); 00080 00081 /** 00082 * Return the quantily of the distribution 00083 * @param probability The probability. 00084 * @return The quantile of the distribution for the probability. 00085 * @see GetQuantile(double probablity) */ 00086 double GetLimit(double probability) 00087 { return this -> GetQuantile(probability); }; 00088 00089 /** 00090 * @return The RMS of the distribution. */ 00091 double GetRMS() 00092 { return fHistogram -> GetRMS(); }; 00093 00094 /** 00095 * Returns the integral of distribution the between two values. 00096 * @param valuemin The value from which the intergration is done. 00097 * @param valuemax The value up to which the intergration is done. 00098 * @return The integral. */ 00099 double GetIntegral(double valuemin, double valuemax); 00100 00101 /** 00102 * Returns the p-value. 00103 * Returns the integral from 0 to the probability. 00104 * @param probability Upper limit of integration. 00105 * @return The p-value. */ 00106 double GetPValue(double probability); 00107 00108 /* @} */ 00109 00110 /** \name Member functions (set) */ 00111 /* @{ */ 00112 00113 /** 00114 * Sets the histogram. */ 00115 void SetHistogram(TH1D * hist) 00116 { fHistogram = hist; }; 00117 00118 /** 00119 * Set default probability limits. Allowed values are between 68% 00120 * and 100%. The default value is 95%. */ 00121 void SetDefaultCLLimit(double limit); 00122 00123 /** 00124 * Set global mode */ 00125 void SetGlobalMode(double mode) 00126 { fMode=mode; fModeFlag=1; }; 00127 00128 /* @} */ 00129 00130 /** \name Member functions (miscellaneous methods) */ 00131 /* @{ */ 00132 00133 /** 00134 * Print distribution into a PostScript file. 00135 * @param filename Output filename 00136 * @param ww canvas size in pixels along X 00137 * @param ww canvas size in pixels along Y 00138 * If ww and wh are set to 0, default ROOT canvas size is used. 00139 * For explanation of parameters options and ovalue look at BCH1D::Draw() 00140 * method. */ 00141 void Print(const char * filename, int options=0, double ovalue=0., int ww=0, int wh=0); 00142 00143 /** 00144 * Draw distribution into the active canvas. 00145 * @param options Drawing options: \n 0 = band mode [default], \n 00146 * 1 = draw vertical line, \n 00147 * 2 = band mode with minimal interval 00148 * @param ovalue Option specific value. For option 0, if ovalue is nonzero 00149 * a limit is to be drawn rather than central band with ovalue being the 00150 * per cent value of the limit. If negative, limit is drawn from minimum, 00151 * if positive limit is drawn from maximum. Allowed values are 00152 * 68 < |limit| < 100. If mode is outside the band, the limit is 00153 * drawn automatically. The default limit can be changed by 00154 * BCH1D::SetDefaultCLLimit(int limit). \n 00155 * For option 1 the ovalue defines 00156 * where the line is drawn. \n 00157 * For option 2 the ovalue sets the content of 00158 * the minimal interval in per cent. If omitted a 68% minimal interval 00159 * will be drawn. */ 00160 void Draw(int options=0, double ovalue=0.); 00161 00162 /** 00163 * Draw distribution with band between min and max and with marker at the mode. 00164 * Write the location of the mode with uncertainties. If limit is specified, 00165 * draw CL limit. Allowed values are 68 < |limit| < 100. */ 00166 void DrawShadedLimits(double mode, double min, double max, double limit=0); 00167 00168 /** 00169 * Draw distribution with bands so that the total shaded area is the 00170 * smallest possible containing and integral of "prob". Draw the location 00171 * of the mean and median if requested (default). */ 00172 void DrawSmallest(double mode, double prob, bool drawmean=true); 00173 00174 /** 00175 * Include a legend for the symbols of mean, mode, median and 00176 * confidence band used in 1D marginalized posterior distributions. 00177 * @param text the text used to name the legend entry for the confidence band 00178 */ 00179 void DrawLegend(const char* text); 00180 00181 /** 00182 * Calculate the minimal interval of the distribution containing a given content. 00183 * @param min calculated minimum of the interval 00184 * @param max calculated maximum of the interval 00185 * @param content content of the interval [default is .68] 00186 * @return the content of the histogram between min and max */ 00187 double GetSmallestInterval(double & min, double & max, double content=.68); 00188 00189 TH1D * GetSmallestIntervalHistogram(double level); 00190 00191 std::vector <double> GetSmallestIntervals(double content = 0.68); 00192 00193 /** 00194 * Calculate integral of the distribution between min and max. 00195 * @param min lower boundary of the integrated interval 00196 * @param max upper boundary of the integrated interval 00197 * @return integral calculated as sum of BinContent*BinWidth */ 00198 double IntegralWidth(double min, double max); 00199 00200 /** 00201 * Get histogram with bins outside min, max band being zero. The 00202 * new histogram can have 2 more bins than the original one as the 00203 * bins where min and max fall into will be split in two (except for the 00204 * case when min and/or max are equal to some of the original bin 00205 * boundaries. 00206 * @param min lower boundary of the non-zero interval 00207 * @param max upper boundary of the non-zero interval 00208 * @return new histogram which is nonzero only between min and max */ 00209 TH1D * GetSubHisto(double min, double max, const char * name); 00210 00211 /* @} */ 00212 00213 private: 00214 00215 /** 00216 * The 1D histogram */ 00217 TH1D * fHistogram; 00218 00219 /** 00220 * Default confidence level limit */ 00221 double fDefaultCLLimit; 00222 00223 /** 00224 * Global mode */ 00225 double fMode; 00226 00227 /** 00228 * "Is there a global mode?" flag */ 00229 int fModeFlag; 00230 00231 }; 00232 00233 // --------------------------------------------------------- 00234 00235 #endif