ROOT  6.06/09
Reference Guide
RooConstraintSum.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 //////////////////////////////////////////////////////////////////////////////
18 //
19 // BEGIN_HTML
20 // RooConstraintSum calculates the sum of the -(log) likelihoods of
21 // a set of RooAbsPfs that represent constraint functions. This class
22 // is used to calculate the composite -log(L) of constraints to be
23 // added the regular -log(L) in RooAbsPdf::fitTo() with Constrain(..)
24 // arguments
25 // END_HTML
26 //
27 
28 
29 #include "RooFit.h"
30 
31 #include "Riostream.h"
32 #include "Riostream.h"
33 #include <math.h>
34 
35 #include "RooConstraintSum.h"
36 #include "RooAbsReal.h"
37 #include "RooAbsPdf.h"
38 #include "RooErrorHandler.h"
39 #include "RooArgSet.h"
40 #include "RooNLLVar.h"
41 #include "RooChi2Var.h"
42 #include "RooMsgService.h"
43 
44 using namespace std;
45 
47 ;
48 
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Default constructor
52 
54 {
55  _setIter1 = _set1.createIterator() ;
56 }
57 
58 
59 
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Constructor with set of constraint p.d.f.s. All elements in constraintSet must inherit from RooAbsPdf
63 
64 RooConstraintSum::RooConstraintSum(const char* name, const char* title, const RooArgSet& constraintSet, const RooArgSet& normSet) :
65  RooAbsReal(name, title),
66  _set1("set1","First set of components",this),
67  _paramSet("paramSet","Set of parameters",this)
68 {
69 
71 
72  TIterator* inputIter = constraintSet.createIterator() ;
73  RooAbsArg* comp ;
74  while((comp = (RooAbsArg*)inputIter->Next())) {
75  if (!dynamic_cast<RooAbsPdf*>(comp)) {
76  coutE(InputArguments) << "RooConstraintSum::ctor(" << GetName() << ") ERROR: component " << comp->GetName()
77  << " is not of type RooAbsPdf" << endl ;
79  }
80  _set1.add(*comp) ;
81  }
82 
83  _paramSet.add(normSet) ;
84 
85  delete inputIter ;
86 }
87 
88 
89 
90 
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Copy constructor
94 
96  RooAbsReal(other, name),
97  _set1("set1",this,other._set1),
98  _paramSet("paramSet",this,other._paramSet)
99 {
101 }
102 
103 
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Destructor
107 
109 {
110  if (_setIter1) delete _setIter1 ;
111 }
112 
113 
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// Return sum of -log of constraint p.d.f.s
117 
119 {
120  Double_t sum(0);
121  RooAbsReal* comp ;
122  RooFIter setIter1 = _set1.fwdIterator() ;
123 
124  while((comp=(RooAbsReal*)setIter1.next())) {
125  sum -= ((RooAbsPdf*)comp)->getLogVal(&_paramSet) ;
126  }
127 
128  return sum ;
129 }
130 
#define coutE(a)
Definition: RooMsgService.h:35
static void softAbort()
RooFIter fwdIterator() const
Double_t evaluate() const
do not persist
STL namespace.
RooConstraintSum()
Default constructor.
TIterator * _setIter1
Iterator abstract base class.
Definition: TIterator.h:32
ClassImp(RooConstraintSum)
TIterator * createIterator(Bool_t dir=kIterForward) const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
virtual ~RooConstraintSum()
Destructor.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
RooAbsArg * next()
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
#define name(a, b)
Definition: linkTestLib0.cpp:5
RooListProxy _set1
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
virtual TObject * Next()=0
RooSetProxy _paramSet
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...