RooConstraintSum.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooConstraintSum.cxx 31654 2009-12-08 13:38:37Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 // 
00019 // BEGIN_HTML
00020 // RooConstraintSum calculates the sum of the -(log) likelihoods of
00021 // a set of RooAbsPfs that represent constraint functions. This class
00022 // is used to calculate the composite -log(L) of constraints to be
00023 // added the regular -log(L) in RooAbsPdf::fitTo() with Constrain(..)
00024 // arguments
00025 // END_HTML
00026 //
00027 
00028 
00029 #include "RooFit.h"
00030 
00031 #include "Riostream.h"
00032 #include "Riostream.h"
00033 #include <math.h>
00034 
00035 #include "RooConstraintSum.h"
00036 #include "RooAbsReal.h"
00037 #include "RooAbsPdf.h"
00038 #include "RooErrorHandler.h"
00039 #include "RooArgSet.h"
00040 #include "RooNLLVar.h"
00041 #include "RooChi2Var.h"
00042 #include "RooMsgService.h"
00043 
00044 ClassImp(RooConstraintSum)
00045 ;
00046 
00047 
00048 //_____________________________________________________________________________
00049 RooConstraintSum::RooConstraintSum()
00050 {
00051   // Default constructor
00052   _setIter1 = _set1.createIterator() ;
00053 }
00054 
00055 
00056 
00057 //_____________________________________________________________________________
00058 RooConstraintSum::RooConstraintSum(const char* name, const char* title, const RooArgSet& constraintSet, const RooArgSet& paramSet) :
00059   RooAbsReal(name, title),
00060   _set1("set1","First set of components",this),
00061   _paramSet("paramSet","Set of parameters",this)
00062 {
00063   // Constructor with set of constraint p.d.f.s. All elements in constraintSet must inherit from RooAbsPdf
00064 
00065   _setIter1 = _set1.createIterator() ;
00066 
00067   TIterator* inputIter = constraintSet.createIterator() ;
00068   RooAbsArg* comp ;
00069   while((comp = (RooAbsArg*)inputIter->Next())) {
00070     if (!dynamic_cast<RooAbsPdf*>(comp)) {
00071       coutE(InputArguments) << "RooConstraintSum::ctor(" << GetName() << ") ERROR: component " << comp->GetName() 
00072                             << " is not of type RooAbsPdf" << endl ;
00073       RooErrorHandler::softAbort() ;
00074     }
00075     _set1.add(*comp) ;
00076   }
00077 
00078   _paramSet.add(paramSet) ;
00079 
00080   delete inputIter ;
00081 }
00082 
00083 
00084 
00085 
00086 
00087 //_____________________________________________________________________________
00088 RooConstraintSum::RooConstraintSum(const RooConstraintSum& other, const char* name) :
00089   RooAbsReal(other, name), 
00090   _set1("set1",this,other._set1),
00091   _paramSet("paramSet",this,other._paramSet)
00092 {
00093   // Copy constructor
00094 
00095   _setIter1 = _set1.createIterator() ;  
00096 }
00097 
00098 
00099 
00100 //_____________________________________________________________________________
00101 RooConstraintSum::~RooConstraintSum() 
00102 {
00103   // Destructor
00104 
00105   if (_setIter1) delete _setIter1 ;
00106 }
00107 
00108 
00109 
00110 //_____________________________________________________________________________
00111 Double_t RooConstraintSum::evaluate() const 
00112 {
00113   // Return sum of -log of constraint p.d.f.s
00114 
00115   Double_t sum(0);
00116   RooAbsReal* comp ;
00117   _setIter1->Reset() ;
00118 
00119   while((comp=(RooAbsReal*)_setIter1->Next())) {
00120     sum -= ((RooAbsPdf*)comp)->getLogVal(&_paramSet) ;
00121   }
00122   
00123   return sum ;
00124 }
00125 

Generated on Tue Jul 5 15:06:20 2011 for ROOT_528-00b_version by  doxygen 1.5.1