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 for (const auto comp : constraintSet) {
52 if (!dynamic_cast<RooAbsPdf*>(comp)) {
53 coutE(InputArguments) << "RooConstraintSum::ctor(" << GetName() << ") ERROR: component " << comp->GetName()
54 << " is not of type RooAbsPdf" << std::endl ;
56 }
57 _set1.add(*comp) ;
58 }
59
60 _paramSet.add(normSet) ;
61}
62
63
64////////////////////////////////////////////////////////////////////////////////
65/// Copy constructor.
66
68 RooAbsReal(other, name),
69 _set1("set1",this,other._set1),
70 _paramSet(other._paramSet),
71 _takeGlobalObservablesFromData{other._takeGlobalObservablesFromData}
72{
73}
74
75
76////////////////////////////////////////////////////////////////////////////////
77/// Return sum of -log of constraint p.d.f.s.
78
80{
81 double sum(0);
82
83 for (const auto comp : _set1) {
84 sum -= static_cast<RooAbsPdf*>(comp)->getLogVal(&_paramSet);
85 }
86
87 return sum;
88}
89
91{
92 ctx.addResult(this, ctx.buildCall("RooFit::Detail::EvaluateFuncs::constraintSumEvaluate", _set1, _set1.size()));
93}
94
95void RooConstraintSum::computeBatch(double *output, size_t /*size*/,
96 RooFit::Detail::DataMap const &dataMap) const
97{
98 double sum(0);
99
100 for (const auto comp : _set1) {
101 sum -= std::log(dataMap.at(comp)[0]);
102 }
103
104 output[0] = sum;
105}
106
107std::unique_ptr<RooAbsArg> RooConstraintSum::compileForNormSet(RooArgSet const & /*normSet*/, RooFit::Detail::CompileContext & ctx) const
108{
109 std::unique_ptr<RooAbsReal> newArg{static_cast<RooAbsReal*>(this->Clone())};
110
111 for (const auto server : newArg->servers()) {
112 RooArgSet nset;
113 server->getObservables(&_paramSet, nset);
114 ctx.compileServer(*server, *newArg, nset);
115 }
116
117 return newArg;
118}
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// Replace the variables in this RooConstraintSum with the global observables
123/// in the dataset if they match by name. This function will do nothing if this
124/// RooConstraintSum is configured to not use the global observables stored in
125/// datasets.
126bool RooConstraintSum::setData(RooAbsData const& data, bool /*cloneData=true*/) {
127 if(_takeGlobalObservablesFromData && data.getGlobalObservables()) {
129 }
130 return true;
131}
#define coutE(a)
#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:91
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
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
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
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.
static void softAbort()
Soft abort function that interrupts macro execution but doesn't kill ROOT.
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
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345
static void output()