00001 #ifndef CMTERREST_H_ 00002 #define CMTERREST_H_ 00003 #include <boost/function.hpp> 00004 #include <vector> 00005 00006 /** \addtogroup statistics Statistical methods */ 00007 /* @{ */ 00008 00009 //! This class is used as a base for stochastic error estimation 00010 /*! This base class is used for stochastic error estimation with Bootstrap, Jacknife or 00011 * similar methods. It takes a template parameter, the type of the function object 00012 * that generates individual samples for the analysis. The only requirement is, that 00013 * operator() returns a value that is convertible to a double. 00014 */ 00015 template <class SampleGenerator> 00016 class StatErrEst 00017 { 00018 private: 00019 //! We store the sample generator in a private variable 00020 SampleGenerator Generator; 00021 //! Make the desired number of samples using the Generator function object 00022 void MakeSamples() 00023 { 00024 Samples.reserve(nrealizations); 00025 std::generate_n(back_inserter(Samples),nrealizations,Generator); 00026 } 00027 //! This is the only virtual function, it is overwritten by the derived class to implement the error calculation method 00028 virtual void CalcErrors_Imp(double &m, double &v) = 0; 00029 protected: 00030 //! How many samples are requested 00031 int nrealizations; 00032 //! the vector that holds the generated samples 00033 std::vector<double> Samples; 00034 public: 00035 //! public access function to generated samples 00036 std::vector<double> &GetSamples(){return Samples;} 00037 //! The main function, calculates the error, by generating samples and calling the derived function 00038 void CalcErrors(double &m, double &v) 00039 { 00040 MakeSamples(); 00041 CalcErrors_Imp(m,v); 00042 } 00043 //! The constructor takes two parameters, the desired number of samples and the function object to generate them 00044 StatErrEst(const int nsamples, SampleGenerator TheGenerator): 00045 Generator(TheGenerator),nrealizations(nsamples){}; 00046 virtual ~StatErrEst(){}; 00047 }; 00048 /* @} */ 00049 #endif /*CMTERREST_H_*/
1.5.5