Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooDataProjBinding.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 RooDataProjBinding.cxx
19\class RooDataProjBinding
20\ingroup Roofitcore
21
22adaptor that projects a real function via summation of states
23provided in a dataset. The real function must be attached to the
24dataset before creating this binding object.
25
26If the dataset only contains category variables, the summation is optimized
27performing a weighted sum over the states of a RooSuperCategory that is
28constructed from all the categories in the dataset
29
30**/
31
32#include "RooDataProjBinding.h"
33#include "RooAbsReal.h"
34#include "RooAbsData.h"
35#include "Roo1DTable.h"
36#include "RooSuperCategory.h"
37#include "RooCategory.h"
38#include "RooAbsPdf.h"
39#include "RooMsgService.h"
40
41#include <iostream>
42#include <cassert>
43
44using namespace std;
45
47
48////////////////////////////////////////////////////////////////////////////////
49/// Constructor of a data weighted average function binding with
50/// variables 'vars' for function 'real' and dataset 'data' with
51/// weights.
52
54 const RooArgSet &vars, const RooArgSet* nset) :
55 RooRealBinding(real,vars,nullptr), _first(true), _real(&real), _data(&data), _nset(nset)
56{
57 // Determine if dataset contains only categories
58 bool allCat(true) ;
59 for(RooAbsArg * arg : *data.get()) {
60 if (!dynamic_cast<RooCategory*>(arg)) allCat = false ;
61 }
62
63 // Determine weights of various super categories fractions
64 if (allCat) {
65 _superCat = std::make_unique<RooSuperCategory>("superCat","superCat",*data.get()) ;
66 _catTable = std::unique_ptr<Roo1DTable>{data.table(*_superCat)};
67 }
68}
69
71
72////////////////////////////////////////////////////////////////////////////////
73/// Evaluate data-projected values of the bound real function.
74
75double RooDataProjBinding::operator()(const double xvector[]) const
76{
77 assert(isValid());
78 loadValues(xvector);
79
80 //RooAbsArg::setDirtyInhibit(true) ;
81
82 double result(0) ;
83 double wgtSum(0) ;
84
85 if (_catTable) {
86
87 // Data contains only categories, sum over weighted supercategory states
88 for (const auto& nameIdx : *_superCat) {
89 // Backprop state to data set so that _real takes appropriate value
90 _superCat->setIndex(nameIdx) ;
91
92 // Add weighted sum
93 double wgt = _catTable->get(nameIdx.first.c_str());
94 if (wgt) {
95 result += wgt * _real->getVal(_nset) ;
96 wgtSum += wgt ;
97 }
98 }
99
100 } else {
101
102 // Data contains reals, sum over all entries
103 Int_t i ;
104 Int_t nEvt = _data->numEntries() ;
105
106 // Procedure might be lengthy, give some progress indication
107 if (_first) {
108 oocoutW(_real,Eval) << "RooDataProjBinding::operator() projecting over " << nEvt << " events" << endl ;
109 _first = false ;
110 } else {
111 if (oodologW(_real,Eval)) {
112 ooccoutW(_real,Eval) << "." ; cout.flush() ;
113 }
114 }
115
116// _real->Print("v") ;
117// ((RooAbsReal*)_real)->printCompactTree() ;
118
119// RooArgSet* params = _real->getObservables(_data->get()) ;
120
121 for (i=0 ; i<nEvt ; i++) {
122 _data->get(i) ;
123
124 double wgt = _data->weight() ;
125 double ret ;
126 if (wgt) {
127 ret = _real->getVal(_nset) ;
128 result += wgt * ret ;
129// cout << "ret[" << i << "] = " ;
130// params->printStream(cout,RooPrintable::kName|RooPrintable::kValue,RooPrintable::kStandard) ;
131// cout << " = " << ret << endl ;
132 wgtSum += wgt ;
133 }
134 }
135 }
136
137 //RooAbsArg::setDirtyInhibit(false) ;
138
139 if (wgtSum==0) return 0 ;
140 return result / wgtSum ;
141}
RooAbsData * _data
Pointer to original input dataset.
#define oocoutW(o, a)
#define ooccoutW(o, a)
#define oodologW(o, a)
bool _first
!
Definition RooNLLVar.h:46
#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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
virtual double weight() const =0
virtual const RooArgSet * get() const
Definition RooAbsData.h:101
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
bool isValid() const
Definition RooAbsFunc.h:37
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Object to represent discrete states.
Definition RooCategory.h:28
adaptor that projects a real function via summation of states provided in a dataset.
std::unique_ptr< Roo1DTable > _catTable
Supercategory table generated from _data.
const RooArgSet * _nset
Normalization set for real function.
bool _first
Bit indicating if operator() has been called yet.
const RooAbsReal * _real
Real function to be projected.
RooDataProjBinding(const RooAbsReal &real, const RooAbsData &data, const RooArgSet &vars, const RooArgSet *normSet=nullptr)
Constructor of a data weighted average function binding with variables 'vars' for function 'real' and...
~RooDataProjBinding() override
std::unique_ptr< RooSuperCategory > _superCat
Supercategory constructed from _data's category variables.
const RooAbsData * _data
Dataset used for projection.
double operator()(const double xvector[]) const override
Evaluate data-projected values of the bound real function.
Lightweight interface adaptor that binds a RooAbsReal object to a subset of its servers and present i...
void loadValues(const double xvector[]) const
Load the vector of variable values into the RooRealVars associated as variables with the bound RooAbs...