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::EvaluateFuncs::constraintSumEvaluate", _set1, _set1.size()));
85}
86
87void RooConstraintSum::computeBatch(double *output, size_t /*size*/,
88 RooFit::Detail::DataMap const &dataMap) const
89{
90 double sum(0);
91
92 for (const auto comp : _set1) {
93 sum -= std::log(dataMap.at(comp)[0]);
94 }
95
96 output[0] = sum;
97}
98
99std::unique_ptr<RooAbsArg> RooConstraintSum::compileForNormSet(RooArgSet const & /*normSet*/, RooFit::Detail::CompileContext & ctx) const
100{
101 std::unique_ptr<RooAbsReal> newArg{static_cast<RooAbsReal*>(this->Clone())};
102
103 for (const auto server : newArg->servers()) {
104 RooArgSet nset;
105 server->getObservables(&_paramSet, nset);
106 ctx.compileServer(*server, *newArg, nset);
107 }
108
109 return newArg;
110}
111
112
113////////////////////////////////////////////////////////////////////////////////
114/// Replace the variables in this RooConstraintSum with the global observables
115/// in the dataset if they match by name. This function will do nothing if this
116/// RooConstraintSum is configured to not use the global observables stored in
117/// datasets.
118bool RooConstraintSum::setData(RooAbsData const& data, bool /*cloneData=true*/) {
119 if(_takeGlobalObservablesFromData && data.getGlobalObservables()) {
121 }
122 return true;
123}
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...
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.
void computeBatch(double *output, size_t size, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
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)
Definition DataMap.cxx:22
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345
static void output()