CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

LikelihoodFunctional.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: LikelihoodFunctional.cc,v 1.4 2003/10/10 17:40:39 garren Exp $
00003 #include "CLHEP/GenericFunctions/LikelihoodFunctional.hh"
00004 #include "CLHEP/GenericFunctions/Argument.hh"
00005 #include "CLHEP/GenericFunctions/AbsFunction.hh"
00006 #include <iostream>
00007 #include <sstream>
00008 #include <stdexcept>
00009 #include <cmath>      // for log()
00010 
00011 namespace Genfun {
00012 LikelihoodFunctional::LikelihoodFunctional(const ArgumentList & aList):
00013 _aList(aList)
00014 {}
00015 
00016 LikelihoodFunctional::~LikelihoodFunctional() {
00017 }
00018 
00019 double LikelihoodFunctional::operator [] (const AbsFunction & function) const {
00020   double logLikelihood(0);
00021   for (unsigned int i=0; i<_aList.size();i++) {
00022     Argument a = _aList[i];
00023     double f = function(a);
00024     if (f<=0.0) {
00025       std::ostringstream stream;
00026       stream <<  "Negative likelihood arg[" << i << "]=" << a;
00027       throw std::runtime_error(stream.str());
00028     }
00029     logLikelihood -= log(f);
00030   }
00031   return 2.0*logLikelihood;
00032 }
00033 } // namespace Genfun

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7