Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
44
45////////////////////////////////////////////////////////////////////////////////
46/// Constructor of a data weighted average function binding with
47/// variables 'vars' for function 'real' and dataset 'data' with
48/// weights.
49
51 const RooArgSet &vars, const RooArgSet* nset) :
52 RooRealBinding(real,vars,nullptr), _first(true), _real(&real), _data(&data), _nset(nset)
53{
54 // Determine if dataset contains only categories
55 bool allCat(true) ;
56 for(RooAbsArg * arg : *data.get()) {
57 if (!dynamic_cast<RooCategory*>(arg)) allCat = false ;
58 }
59
60 // Determine weights of various super categories fractions
61 if (allCat) {
62 _superCat = std::make_unique<RooSuperCategory>("superCat","superCat",*data.get()) ;
63 _catTable = std::unique_ptr<Roo1DTable>{data.table(*_superCat)};
64 }
65}
66
68
69////////////////////////////////////////////////////////////////////////////////
70/// Evaluate data-projected values of the bound real function.
71
72double RooDataProjBinding::operator()(const double xvector[]) const
73{
74 assert(isValid());
76
77 //RooAbsArg::setDirtyInhibit(true) ;
78
79 double result(0) ;
80 double wgtSum(0) ;
81
82 if (_catTable) {
83
84 // Data contains only categories, sum over weighted supercategory states
85 for (const auto& nameIdx : *_superCat) {
86 // Backprop state to data set so that _real takes appropriate value
87 _superCat->setIndex(nameIdx) ;
88
89 // Add weighted sum
90 double wgt = _catTable->get(nameIdx.first.c_str());
91 if (wgt) {
92 result += wgt * _real->getVal(_nset) ;
93 wgtSum += wgt ;
94 }
95 }
96
97 } else {
98
99 // Data contains reals, sum over all entries
100 Int_t i ;
101 Int_t nEvt = _data->numEntries() ;
102
103 // Procedure might be lengthy, give some progress indication
104 if (_first) {
105 oocoutW(_real,Eval) << "RooDataProjBinding::operator() projecting over " << nEvt << " events" << std::endl ;
106 _first = false ;
107 } else {
108 if (oodologW(_real,Eval)) {
109 ooccoutW(_real,Eval) << "." ; std::cout.flush() ;
110 }
111 }
112
113// _real->Print("v") ;
114// ((RooAbsReal*)_real)->printCompactTree() ;
115
116// RooArgSet* params = _real->getObservables(_data->get()) ;
117
118 for (i=0 ; i<nEvt ; i++) {
119 _data->get(i) ;
120
121 double wgt = _data->weight() ;
122 double ret ;
123 if (wgt) {
124 ret = _real->getVal(_nset) ;
125 result += wgt * ret ;
126// std::cout << "ret[" << i << "] = " ;
127// params->printStream(cout,RooPrintable::kName|RooPrintable::kValue,RooPrintable::kStandard) ;
128// std::cout << " = " << ret << std::endl ;
129 wgtSum += wgt ;
130 }
131 }
132 }
133
134 //RooAbsArg::setDirtyInhibit(false) ;
135
136 if (wgtSum==0) return 0 ;
137 return result / wgtSum ;
138}
#define oocoutW(o, a)
#define ooccoutW(o, a)
#define oodologW(o, a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
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
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Object to represent discrete states.
Definition RooCategory.h:28
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...