Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
22Calculates the sum of the -(log) likelihoods of
23a set of RooAbsPfs that represent constraint functions. This class
24is used to calculate the composite -log(L) of constraints to be
25added to the regular -log(L) in RooAbsPdf::fitTo() with Constrain(..)
26arguments.
27**/
28
29
30#include "RooConstraintSum.h"
31#include "RooAbsData.h"
32#include "RooAbsReal.h"
33#include "RooAbsPdf.h"
34#include "RooErrorHandler.h"
35#include "RooArgSet.h"
36#include "RooMsgService.h"
37#include "RooHelpers.h"
39
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// Constructor with set of constraint p.d.f.s. All elements in constraintSet must inherit from RooAbsPdf.
45
46RooConstraintSum::RooConstraintSum(const char* name, const char* title, const RooArgSet& constraintSet, const RooArgSet& normSet, bool takeGlobalObservablesFromData) :
47 RooAbsReal(name, title),
48 _set1("set1","First set of components",this),
49 _takeGlobalObservablesFromData{takeGlobalObservablesFromData}
50{
51 _set1.addTyped<RooAbsPdf>(constraintSet);
52 _paramSet.add(normSet) ;
53}
54
55
56////////////////////////////////////////////////////////////////////////////////
57/// Copy constructor.
58
60 RooAbsReal(other, name),
61 _set1("set1",this,other._set1),
62 _paramSet(other._paramSet),
64{
65}
66
67
68////////////////////////////////////////////////////////////////////////////////
69/// Return sum of -log of constraint p.d.f.s.
70
72{
73 double sum(0);
74
75 for (const auto comp : _set1) {
76 sum -= static_cast<RooAbsPdf*>(comp)->getLogVal(&_paramSet);
77 }
78
79 return sum;
80}
81
83{
84 ctx.addResult(this, ctx.buildCall("RooFit::Detail::MathFuncs::constraintSum", _set1, _set1.size()));
85}
86
88{
89 double sum(0);
90
91 for (const auto comp : _set1) {
92 sum -= std::log(ctx.at(comp)[0]);
93 }
94
95 ctx.output()[0] = sum;
96}
97
98std::unique_ptr<RooAbsArg> RooConstraintSum::compileForNormSet(RooArgSet const & /*normSet*/, RooFit::Detail::CompileContext & ctx) const
99{
100 std::unique_ptr<RooAbsReal> newArg{static_cast<RooAbsReal*>(this->Clone())};
101
102 for (const auto server : newArg->servers()) {
103 RooArgSet nset;
104 server->getObservables(&_paramSet, nset);
105 ctx.compileServer(*server, *newArg, nset);
106 }
107
108 return newArg;
109}
110
111
112////////////////////////////////////////////////////////////////////////////////
113/// Replace the variables in this RooConstraintSum with the global observables
114/// in the dataset if they match by name. This function will do nothing if this
115/// RooConstraintSum is configured to not use the global observables stored in
116/// datasets.
117bool RooConstraintSum::setData(RooAbsData const& data, bool /*cloneData=true*/) {
118 if(_takeGlobalObservablesFromData && data.getGlobalObservables()) {
120 }
121 return true;
122}
const bool _takeGlobalObservablesFromData
If the global observable values are taken from data.
RooSetProxy _paramSet
Parameters of the test statistic (=parameters of the input function)
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
char name[80]
Definition TGX11.cxx:110
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition RooAbsArg.h:89
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
bool addTyped(const RooAbsCollection &list, bool silent=false)
Adds elements of a given RooAbsCollection to the container if they match the specified type.
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
RooArgSet const * getGlobalObservables() const
Returns snapshot of global observables stored in this data.
Definition RooAbsData.h:288
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Calculates the sum of the -(log) likelihoods of a set of RooAbsPfs that represent constraint function...
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
bool setData(RooAbsData const &data, bool cloneData=true)
Replace the variables in this RooConstraintSum with the global observables in the dataset if they mat...
void translate(RooFit::Detail::CodeSquashContext &ctx) const override
This function defines a translation for each RooAbsReal based object that can be used to express the ...
RooListProxy _set1
Set of constraint terms.
double evaluate() const override
Return sum of -log of constraint p.d.f.s.
RooArgSet _paramSet
Set of parameters to which constraints apply.
const bool _takeGlobalObservablesFromData
If the global observable values are taken from data.
A class to maintain the context for squashing of RooFit models into code.
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
void addResult(RooAbsArg const *key, std::string const &value)
A function to save an expression that includes/depends on the result of the input node.
void compileServer(RooAbsArg &server, RooAbsArg &arg, RooArgSet const &normSet)
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345