Logo ROOT   6.08/07
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 \file RooConstraintSum.cxx
19 \class RooConstraintSum
20 \ingroup Roofitcore
21 
22 RooConstraintSum calculates the sum of the -(log) likelihoods of
23 a set of RooAbsPfs that represent constraint functions. This class
24 is used to calculate the composite -log(L) of constraints to be
25 added the regular -log(L) in RooAbsPdf::fitTo() with Constrain(..)
26 arguments
27 **/
28 
29 
30 #include "RooFit.h"
31 
32 #include "Riostream.h"
33 #include "Riostream.h"
34 #include <math.h>
35 
36 #include "RooConstraintSum.h"
37 #include "RooAbsReal.h"
38 #include "RooAbsPdf.h"
39 #include "RooErrorHandler.h"
40 #include "RooArgSet.h"
41 #include "RooNLLVar.h"
42 #include "RooChi2Var.h"
43 #include "RooMsgService.h"
44 
45 using namespace std;
46 
48 ;
49 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Default constructor
53 
55 {
56  _setIter1 = _set1.createIterator() ;
57 }
58 
59 
60 
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Constructor with set of constraint p.d.f.s. All elements in constraintSet must inherit from RooAbsPdf
64 
65 RooConstraintSum::RooConstraintSum(const char* name, const char* title, const RooArgSet& constraintSet, const RooArgSet& normSet) :
66  RooAbsReal(name, title),
67  _set1("set1","First set of components",this),
68  _paramSet("paramSet","Set of parameters",this)
69 {
70 
72 
73  TIterator* inputIter = constraintSet.createIterator() ;
74  RooAbsArg* comp ;
75  while((comp = (RooAbsArg*)inputIter->Next())) {
76  if (!dynamic_cast<RooAbsPdf*>(comp)) {
77  coutE(InputArguments) << "RooConstraintSum::ctor(" << GetName() << ") ERROR: component " << comp->GetName()
78  << " is not of type RooAbsPdf" << endl ;
80  }
81  _set1.add(*comp) ;
82  }
83 
84  _paramSet.add(normSet) ;
85 
86  delete inputIter ;
87 }
88 
89 
90 
91 
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Copy constructor
95 
97  RooAbsReal(other, name),
98  _set1("set1",this,other._set1),
99  _paramSet("paramSet",this,other._paramSet)
100 {
102 }
103 
104 
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Destructor
108 
110 {
111  if (_setIter1) delete _setIter1 ;
112 }
113 
114 
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Return sum of -log of constraint p.d.f.s
118 
120 {
121  Double_t sum(0);
122  RooAbsReal* comp ;
123  RooFIter setIter1 = _set1.fwdIterator() ;
124 
125  while((comp=(RooAbsReal*)setIter1.next())) {
126  sum -= ((RooAbsPdf*)comp)->getLogVal(&_paramSet) ;
127  }
128 
129  return sum ;
130 }
131 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TIterator * createIterator(Bool_t dir=kIterForward) const
static long int sum(long int i)
Definition: Factory.cxx:1786
#define coutE(a)
Definition: RooMsgService.h:35
static void softAbort()
STL namespace.
RooConstraintSum()
Default constructor.
TIterator * _setIter1
Iterator abstract base class.
Definition: TIterator.h:32
RooConstraintSum calculates the sum of the -(log) likelihoods of a set of RooAbsPfs that represent co...
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
virtual ~RooConstraintSum()
Destructor.
RooAbsArg * next()
#define ClassImp(name)
Definition: Rtypes.h:279
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
RooFIter fwdIterator() const
Double_t evaluate() const
do not persist
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
char name[80]
Definition: TGX11.cxx:109
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts &#39;var&#39; into set and registers &#39;var&#39; as server to owner with...