Logo ROOT   6.18/05
Reference Guide
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 "RooFit.h"
33#include "Riostream.h"
34
35#include "RooDataProjBinding.h"
36#include "RooAbsReal.h"
37#include "RooAbsData.h"
38#include "Roo1DTable.h"
39#include "RooSuperCategory.h"
40#include "RooCategory.h"
41#include "RooAbsPdf.h"
42#include "RooMsgService.h"
43
44#include <assert.h>
45
46
47
48using namespace std;
49
51;
52
53
54////////////////////////////////////////////////////////////////////////////////
55/// Constructor of a data weighted average function binding with
56/// variables 'vars' for function 'real' and dataset 'data' with
57/// weights.
58
60 const RooArgSet &vars, const RooArgSet* nset) :
61 RooRealBinding(real,vars,0), _first(kTRUE), _real(&real), _data(&data), _nset(nset),
62 _superCat(0), _catTable(0)
63{
64 // Determine if dataset contains only categories
65 TIterator* iter = data.get()->createIterator() ;
66 Bool_t allCat(kTRUE) ;
67 RooAbsArg* arg ;
68 while((arg=(RooAbsArg*)iter->Next())) {
69 if (!dynamic_cast<RooCategory*>(arg)) allCat = kFALSE ;
70 }
71 delete iter ;
72
73 // Determine weights of various super categories fractions
74 if (allCat) {
75 _superCat = new RooSuperCategory("superCat","superCat",*data.get()) ;
76 _catTable = data.table(*_superCat) ;
77 }
78}
79
80
81
82////////////////////////////////////////////////////////////////////////////////
83/// Destructor, delete owned objects
84
86{
87 if (_superCat) delete _superCat ;
88 if (_catTable) delete _catTable ;
89}
90
91
92
93////////////////////////////////////////////////////////////////////////////////
94/// Evaluate data-projected values of the bound real function.
95
97{
98 assert(isValid());
99 loadValues(xvector);
100
101 //RooAbsArg::setDirtyInhibit(kTRUE) ;
102
103 Double_t result(0) ;
104 Double_t wgtSum(0) ;
105
106 if (_catTable) {
107
108 // Data contains only categories, sum over weighted supercategory states
109 TIterator* iter = _superCat->typeIterator() ;
111 while((type=(RooCatType*)iter->Next())) {
112 // Backprop state to data set so that _real takes appropriate value
113 _superCat->setIndex(type->getVal()) ;
114
115 // Add weighted sum
116 Double_t wgt = _catTable->get(type->GetName()) ;
117 if (wgt) {
118 result += wgt * _real->getVal(_nset) ;
119 wgtSum += wgt ;
120 }
121 }
122 delete iter ;
123
124 } else {
125
126 // Data contains reals, sum over all entries
127 Int_t i ;
128 Int_t nEvt = _data->numEntries() ;
129
130 // Procedure might be lengthy, give some progress indication
131 if (_first) {
132 oocoutW(_real,Eval) << "RooDataProjBinding::operator() projecting over " << nEvt << " events" << endl ;
133 _first = kFALSE ;
134 } else {
135 if (oodologW(_real,Eval)) {
136 ooccoutW(_real,Eval) << "." ; cout.flush() ;
137 }
138 }
139
140// _real->Print("v") ;
141// ((RooAbsReal*)_real)->printCompactTree() ;
142
143// RooArgSet* params = _real->getObservables(_data->get()) ;
144
145 for (i=0 ; i<nEvt ; i++) {
146 _data->get(i) ;
147
148 Double_t wgt = _data->weight() ;
149 Double_t ret ;
150 if (wgt) {
151 ret = _real->getVal(_nset) ;
152 result += wgt * ret ;
153// cout << "ret[" << i << "] = " ;
154// params->printStream(cout,RooPrintable::kName|RooPrintable::kValue,RooPrintable::kStandard) ;
155// cout << " = " << ret << endl ;
156 wgtSum += wgt ;
157 }
158 }
159 }
160
161 //RooAbsArg::setDirtyInhibit(kFALSE) ;
162
163 if (wgtSum==0) return 0 ;
164 return result / wgtSum ;
165}
#define oocoutW(o, a)
Definition: RooMsgService.h:46
#define ooccoutW(o, a)
Definition: RooMsgService.h:53
#define oodologW(o, a)
Definition: RooMsgService.h:73
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
int type
Definition: TGX11.cxx:120
Double_t get(const char *label, Bool_t silent=kFALSE) const
Return the table entry named 'label'.
Definition: Roo1DTable.cxx:244
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:70
TIterator * typeIterator() const
Return iterator over all defined states.
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
virtual const RooArgSet * get() const
Definition: RooAbsData.h:80
virtual Roo1DTable * table(const RooArgSet &catSet, const char *cuts="", const char *opts="") const
Construct table for product of categories in catSet.
Definition: RooAbsData.cxx:754
virtual Double_t weight() const =0
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:306
Bool_t isValid() const
Definition: RooAbsFunc.h:33
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:81
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
Definition: RooCatType.h:22
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:24
adaptor that projects a real function via summation of states provided in a dataset.
virtual ~RooDataProjBinding()
Destructor, delete owned objects.
RooDataProjBinding(const RooAbsReal &real, const RooAbsData &data, const RooArgSet &vars, const RooArgSet *normSet=0)
Constructor of a data weighted average function binding with variables 'vars' for function 'real' and...
const RooArgSet * _nset
const RooAbsReal * _real
RooSuperCategory * _superCat
const RooAbsData * _data
virtual Double_t operator()(const Double_t xvector[]) const
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_t xvector[]) const
Load the vector of variable values into the RooRealVars associated as variables with the bound RooAbs...
RooSuperCategory can join several RooAbsCategoryLValue objects into a single category.
virtual Bool_t setIndex(Int_t index, Bool_t printError=kTRUE)
Set the value of the super category by specifying the state index code by setting the states of the c...
Iterator abstract base class.
Definition: TIterator.h:30
virtual TObject * Next()=0