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),
63 _takeGlobalObservablesFromData{other._takeGlobalObservablesFromData}
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 double sum(0);
85
86 for (const auto comp : _set1) {
87 sum -= std::log(ctx.at(comp)[0]);
88 }
89
90 ctx.output()[0] = sum;
91}
92
93std::unique_ptr<RooAbsArg> RooConstraintSum::compileForNormSet(RooArgSet const & /*normSet*/, RooFit::Detail::CompileContext & ctx) const
94{
95 std::unique_ptr<RooAbsReal> newArg{static_cast<RooAbsReal*>(this->Clone())};
96
97 for (const auto server : newArg->servers()) {
98 RooArgSet nset;
99 server->getObservables(&_paramSet, nset);
100 ctx.compileServer(*server, *newArg, nset);
101 }
102
103 return newArg;
104}
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// Replace the variables in this RooConstraintSum with the global observables
109/// in the dataset if they match by name. This function will do nothing if this
110/// RooConstraintSum is configured to not use the global observables stored in
111/// datasets.
112bool RooConstraintSum::setData(RooAbsData const& data, bool /*cloneData=true*/) {
113 if(_takeGlobalObservablesFromData && data.getGlobalObservables()) {
115 }
116 return true;
117}
#define ClassImp(name)
Definition Rtypes.h:382
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.
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:290
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:24
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...
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 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