Logo ROOT  
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 to 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 <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 
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  for (const auto comp : constraintSet) {
70  if (!dynamic_cast<RooAbsPdf*>(comp)) {
71  coutE(InputArguments) << "RooConstraintSum::ctor(" << GetName() << ") ERROR: component " << comp->GetName()
72  << " is not of type RooAbsPdf" << endl ;
74  }
75  _set1.add(*comp) ;
76  }
77 
78  _paramSet.add(normSet) ;
79 }
80 
81 
82 
83 
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Copy constructor
87 
89  RooAbsReal(other, name),
90  _set1("set1",this,other._set1),
91  _paramSet("paramSet",this,other._paramSet)
92 {
93 
94 }
95 
96 
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Destructor
100 
102 {
103 
104 }
105 
106 
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Return sum of -log of constraint p.d.f.s
110 
112 {
113  Double_t sum(0);
114 
115  for (const auto comp : _set1) {
116  sum -= static_cast<RooAbsPdf*>(comp)->getLogVal(&_paramSet);
117  }
118 
119  return sum;
120 }
121 
RooErrorHandler::softAbort
static void softAbort()
Definition: RooErrorHandler.h:44
RooSetProxy::add
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...
Definition: RooSetProxy.cxx:165
RooAbsReal.h
RooMsgService.h
RooFit.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:68
RooArgSet.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooConstraintSum::~RooConstraintSum
virtual ~RooConstraintSum()
Destructor.
Definition: RooConstraintSum.cxx:101
coutE
#define coutE(a)
Definition: RooMsgService.h:33
RooConstraintSum::_paramSet
RooSetProxy _paramSet
Definition: RooConstraintSum.h:42
RooConstraintSum::_set1
RooListProxy _set1
Definition: RooConstraintSum.h:41
RooAbsReal
Definition: RooAbsReal.h:61
RooNLLVar.h
RooChi2Var.h
RooConstraintSum.h
RooConstraintSum::evaluate
Double_t evaluate() const
Return sum of -log of constraint p.d.f.s.
Definition: RooConstraintSum.cxx:111
RooAbsPdf.h
RooListProxy::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
Definition: RooListProxy.cxx:104
sum
static long int sum(long int i)
Definition: Factory.cxx:2272
RooConstraintSum::RooConstraintSum
RooConstraintSum()
Default constructor.
Definition: RooConstraintSum.cxx:53
Double_t
double Double_t
Definition: RtypesCore.h:59
name
char name[80]
Definition: TGX11.cxx:110
RooErrorHandler.h
RooAbsPdf
Definition: RooAbsPdf.h:40
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
RooConstraintSum
Definition: RooConstraintSum.h:27
Riostream.h
RooArgSet
Definition: RooArgSet.h:28