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
22RooConstraintSum calculates 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
90
91void RooConstraintSum::computeBatch(cudaStream_t *, double *output, size_t /*size*/,
92 RooFit::Detail::DataMap const &dataMap) const
93{
94 double sum(0);
95
96 for (const auto comp : _set1) {
97 sum -= std::log(dataMap.at(comp)[0]);
98 }
99
100 output[0] = sum;
101}
102
103std::unique_ptr<RooAbsArg> RooConstraintSum::compileForNormSet(RooArgSet const & /*normSet*/, RooFit::Detail::CompileContext & ctx) const
104{
105 std::unique_ptr<RooAbsReal> newArg{static_cast<RooAbsReal*>(this->Clone())};
106
107 for (const auto server : newArg->servers()) {
108 RooArgSet nset;
109 server->getObservables(&_paramSet, nset);
110 ctx.compileServer(*server, *newArg, nset);
111 }
112
113 return newArg;
114}
115
116
117////////////////////////////////////////////////////////////////////////////////
118/// Replace the variables in this RooConstraintSum with the global observables
119/// in the dataset if they match by name. This function will do nothing if this
120/// RooConstraintSum is configured to not use the global observables stored in
121/// datasets.
122bool RooConstraintSum::setData(RooAbsData const& data, bool /*cloneData=true*/) {
123 if(_takeGlobalObservablesFromData && data.getGlobalObservables()) {
125 }
126 return true;
127}
#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:86
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:59
RooArgSet const * getGlobalObservables() const
Returns snapshot of global observables stored in this data.
Definition RooAbsData.h:301
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
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...
RooConstraintSum calculates the sum of the -(log) likelihoods of a set of RooAbsPfs that represent co...
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.
void computeBatch(cudaStream_t *, double *output, size_t size, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
RooArgSet _paramSet
Set of parameters to which constraints apply.
const bool _takeGlobalObservablesFromData
If the global observable values are taken from data.
static void softAbort()
Soft abort function that interrupts macro execution but doesn't kill ROOT.
void compileServer(RooAbsArg &server, RooAbsArg &arg, RooArgSet const &normSet)
RooSpan< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
Definition DataMap.cxx:21
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()