// RooConstraintSum calculates the sum of the -(log) likelihoods of
// a set of RooAbsPfs that represent constraint functions. This class
// is used to calculate the composite -log(L) of constraints to be
// added the regular -log(L) in RooAbsPdf::fitTo() with Constrain(..)
// arguments
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "Riostream.h"
#include <math.h>
#include "RooConstraintSum.h"
#include "RooAbsReal.h"
#include "RooAbsPdf.h"
#include "RooErrorHandler.h"
#include "RooArgSet.h"
#include "RooNLLVar.h"
#include "RooChi2Var.h"
#include "RooMsgService.h"
ClassImp(RooConstraintSum)
;
RooConstraintSum::RooConstraintSum()
{
_setIter1 = _set1.createIterator() ;
}
RooConstraintSum::RooConstraintSum(const char* name, const char* title, const RooArgSet& constraintSet, const RooArgSet& paramSet) :
RooAbsReal(name, title),
_set1("set1","First set of components",this),
_paramSet("paramSet","Set of parameters",this)
{
_setIter1 = _set1.createIterator() ;
TIterator* inputIter = constraintSet.createIterator() ;
RooAbsArg* comp ;
while((comp = (RooAbsArg*)inputIter->Next())) {
if (!dynamic_cast<RooAbsPdf*>(comp)) {
coutE(InputArguments) << "RooConstraintSum::ctor(" << GetName() << ") ERROR: component " << comp->GetName()
<< " is not of type RooAbsPdf" << endl ;
RooErrorHandler::softAbort() ;
}
_set1.add(*comp) ;
}
_paramSet.add(paramSet) ;
delete inputIter ;
}
RooConstraintSum::RooConstraintSum(const RooConstraintSum& other, const char* name) :
RooAbsReal(other, name),
_set1("set1",this,other._set1),
_paramSet("paramSet",this,other._paramSet)
{
_setIter1 = _set1.createIterator() ;
}
RooConstraintSum::~RooConstraintSum()
{
if (_setIter1) delete _setIter1 ;
}
Double_t RooConstraintSum::evaluate() const
{
Double_t sum(0);
RooAbsReal* comp ;
RooFIter setIter1 = _set1.fwdIterator() ;
while((comp=(RooAbsReal*)setIter1.next())) {
sum -= ((RooAbsPdf*)comp)->getLogVal(&_paramSet) ;
}
return sum ;
}