00001 #ifndef __BCMODELGRAPHFITTER__H 00002 #define __BCMODELGRAPHFITTER__H 00003 00004 /*! 00005 * \class BCGraphFitter 00006 * \brief A class for fitting graphs with functions 00007 * \author Daniel Kollar 00008 * \author Kevin Kröninger 00009 * \version 1.0 00010 * \date 2008 00011 * \detail This class allows fitting of a TGraphErrors using 00012 * a TF1 function. It doeasn't take the x uncertainties into account. 00013 * For that look at BCGraphXFitter (not yet implemented). 00014 */ 00015 00016 /* 00017 * Copyright (C) 2008, Daniel Kollar and Kevin Kroeninger. 00018 * All rights reserved. 00019 * 00020 * For the licensing terms see doc/COPYING. 00021 */ 00022 00023 // --------------------------------------------------------- 00024 00025 #include <vector> 00026 00027 #include <BAT/BCModel.h> 00028 00029 class TGraphErrors; 00030 class TF1; 00031 00032 // --------------------------------------------------------- 00033 00034 class BCGraphFitter : public BCModel 00035 { 00036 public: 00037 00038 /** \name Constructors and destructors */ 00039 /* @{ */ 00040 00041 /** 00042 * Default constructor */ 00043 BCGraphFitter(); 00044 00045 /** 00046 * Constructor 00047 * @param graph pointer to TGraphErrors 00048 * @param func pointer to TF1 */ 00049 BCGraphFitter(TGraphErrors * graph, TF1 * func); 00050 00051 /** 00052 * The default destructor. */ 00053 ~BCGraphFitter(); 00054 00055 /* @} */ 00056 00057 /** \name Member functions (get) */ 00058 /* @{ */ 00059 00060 /** 00061 * @return pointer to TGraphErrors */ 00062 TGraphErrors * GetGraph() 00063 { return fGraph; }; 00064 00065 /** 00066 * @return pointer to TF1 */ 00067 TF1 * GetFitFunction() 00068 { return fFitFunction; }; 00069 00070 /** 00071 * @return pointer to the error band */ 00072 TGraph * GetErrorBand() 00073 { return fErrorBand; }; 00074 00075 /** 00076 * @return pointer to a graph for the fit function */ 00077 TGraph * GetGraphFitFunction() 00078 { return fGraphFitFunction; }; 00079 00080 /* @} */ 00081 00082 /** \name Member functions (set) */ 00083 /* @{ */ 00084 00085 /** 00086 * @param graph pointer to TGraphErrors object */ 00087 int SetGraph(TGraphErrors * graph); 00088 00089 /** 00090 * @param func pointer to TF1 object */ 00091 int SetFitFunction(TF1 * func); 00092 00093 /* @} */ 00094 /** \name Member functions (miscellaneous methods) */ 00095 /* @{ */ 00096 00097 /** 00098 * The log of the prior probability. It is set to be flat in all parameters. 00099 * @param parameters vector containing the parameter values */ 00100 // double LogAPrioriProbability(std::vector <double> parameters); 00101 00102 /** 00103 * The log of the conditional probability. 00104 * @param parameters vector containing the parameter values */ 00105 double LogLikelihood(std::vector <double> parameters); 00106 00107 /** 00108 * Returns the value of the 1D fit function for a given set of parameters 00109 * at a given x. 00110 * @param x point to calculate the function value at 00111 * @param parameters parameters of the function */ 00112 double FitFunction(std::vector <double> x, std::vector <double> parameters); 00113 00114 /** 00115 * Performs the fit. The graph and the function has to beset beforehand. 00116 * @return An error code. */ 00117 int Fit(); 00118 00119 /** 00120 * Performs the fit of the graph with the function. 00121 * @param graph pointer to TGraphErrors object 00122 * @param func pointer to TF1 object 00123 * @return An error code. */ 00124 int Fit(TGraphErrors * graph, TF1 * func); 00125 00126 /** 00127 * Draw the fit in the current pad. */ 00128 void DrawFit(const char * options = "", bool flaglegend = false); 00129 00130 virtual double CDF(const std::vector<double>& parameters, int index, bool lower=false); 00131 00132 /* @} */ 00133 00134 private: 00135 00136 /** 00137 * The graph containing the data. */ 00138 TGraphErrors * fGraph; 00139 00140 /** 00141 * The fit function */ 00142 TF1 * fFitFunction; 00143 00144 /** 00145 * Pointer to the error band (for legend) */ 00146 TGraph * fErrorBand; 00147 00148 /** 00149 * Pointer to a graph for displaying the fit function */ 00150 TGraph * fGraphFitFunction; 00151 00152 }; 00153 00154 // --------------------------------------------------------- 00155 00156 #endif