Go to the documentation of this file.00001 #ifndef PhysicsTools_Utilities_CombinedChiSquaredLikelihood_h
00002 #define PhysicsTools_Utilities_CombinedChiSquaredLikelihood_h
00003 #include "PhysicsTools/Utilities/interface/RootMinuitResultPrinter.h"
00004 #include "PhysicsTools/Utilities/interface/RootMinuitFuncEvaluator.h"
00005
00006 namespace fit {
00007 template<typename ChiSquared, typename Likelihood>
00008 class CombinedChiSquaredLikelihood {
00009 public:
00010 CombinedChiSquaredLikelihood() { }
00011 CombinedChiSquaredLikelihood(const ChiSquared & chi2, const Likelihood & like) :
00012 chi2_(chi2), like_(like) { }
00013
00014 double operator()() const {
00015 return - 2 * like_() + chi2_();
00016 }
00017 ChiSquared & chi2() { return chi2_; }
00018 const ChiSquared & chi2() const { return chi2_; }
00019 Likelihood & like() { return like_; }
00020 const Likelihood & like() const { return like_; }
00021 size_t numberOfBins() const {
00022 return chi2_.numberOfBins();
00023 }
00024 private:
00025 ChiSquared chi2_;
00026 Likelihood like_;
00027 };
00028
00029 template<typename ChiSquared, typename Likelihood>
00030 struct RootMinuitResultPrinter<CombinedChiSquaredLikelihood<ChiSquared, Likelihood> > {
00031 static void print(double amin, unsigned int numberOfFreeParameters, const CombinedChiSquaredLikelihood<ChiSquared, Likelihood> & f) {
00032 unsigned int ndof = f.numberOfBins() - numberOfFreeParameters;
00033 std::cout << "-2 log(maximum-likelihood) = " << amin << ", n.d.o.f = " << ndof
00034 << ", free parameters = " << numberOfFreeParameters
00035 << std::endl;
00036 std::cout << "chi-2 contibution: " << f.chi2()() << "(n. bins: " << f.chi2().numberOfBins() << ")" << std::endl
00037 << "likelihood contriution: " << -2.*f.like()() << std::endl;
00038 }
00039 };
00040
00041 }
00042
00043 #endif