Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooDataWeightedAverage.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 RooDataWeightedAverage.cxx
19\class RooDataWeightedAverage
20\ingroup Roofitcore
21
22Class RooDataWeightedAverage calculate a weighted
23average of a function or p.d.f given a dataset with observable
24values, i.e. DWA(f(x),D(x)) = sum_i f(x_i) where x_i is draw from
25D(i). This class is an implementation of RooAbsOptTestStatistics
26can make use of the optimization and parallelization infrastructure
27of that base class. The main use of RooDataWeightedAverage is
28to calculate curves in RooPlots that are added with ProjWData()
29plot option.
30
31**/
32
33#define __ROOFIT_SUPPRESS_ROODATAWEIGHTEDAVERAGE_DEPRECATION_WARNING
34// At least for building the implementation we have to suppress the deprecation warning
36#undef __ROOFIT_SUPPRESS_ROODATAWEIGHTEDAVERAGE_DEPRECATION_WARNING
37
38#include "Riostream.h"
39
40#include "RooAbsData.h"
41#include "RooAbsPdf.h"
42#include "RooCmdConfig.h"
43#include "RooMsgService.h"
44#include "RooAbsDataStore.h"
45
46
47
48using namespace std;
49
51;
52
53
54////////////////////////////////////////////////////////////////////////////////
55/// Constructor of data weighted average of given p.d.f over given data. If nCPU>1 the calculation is parallelized
56/// over multuple processes. If showProgress is true a progress indicator printing a single dot for each evaluation
57/// is shown. If interleave is true, the dataset split over multiple processes is done with an interleave pattern
58/// rather than a bulk-split pattern.
59
60RooDataWeightedAverage::RooDataWeightedAverage(const char *name, const char *title, RooAbsReal& pdf, RooAbsData& indata,
61 const RooArgSet& projdeps, RooAbsTestStatistic::Configuration const& cfg,
62 bool showProgress) :
63 RooAbsOptTestStatistic(name,title,pdf,indata,projdeps,cfg),
64 _showProgress(showProgress)
65{
66 if (_showProgress) {
67 coutI(Plotting) << "RooDataWeightedAverage::ctor(" << GetName() << ") constructing data weighted average of function " << pdf.GetName()
68 << " over " << indata.numEntries() << " data points of " << *(indata.get()) << " with a total weight of " << indata.sumEntries() << endl ;
69 }
70 _sumWeight = indata.sumEntries() ;
71}
72
73
74////////////////////////////////////////////////////////////////////////////////
75/// Copy constructor
76
81{
82}
83
84
85
86////////////////////////////////////////////////////////////////////////////////
87/// Destructor
88
90{
91}
92
93
94
95////////////////////////////////////////////////////////////////////////////////
96/// Return global normalization term by which raw (combined) test statistic should
97/// be defined to obtain final test statistic. For a data weighted average this
98/// the sum of all weights
99
101{
102 return _sumWeight ;
103}
104
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// Calculate the data weighted average for events [firstEVent,lastEvent] with step size stepSize
109
110double RooDataWeightedAverage::evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const
111{
112 double result(0) ;
113
114 if (setNum()==0 && _showProgress) {
115 ccoutP(Plotting) << "." ;
116 cout.flush() ;
117 }
118
119 for (auto i=firstEvent ; i<lastEvent ; i+=stepSize) {
120
121 // get the data values for this event
122 _dataClone->get(i);
123 if (_dataClone->weight()==0) continue ;
124
125 double term = _dataClone->weight() * _funcClone->getVal(_normSet);
126 result += term;
127 }
128
129 return result ;
130}
bool _showProgress
Show progress indication during evaluation if true.
double _sumWeight
Global sum of weights needed for normalization.
#define coutI(a)
#define ccoutP(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 char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
char name[80]
Definition TGX11.cxx:110
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
virtual double weight() const =0
virtual double sumEntries() const =0
Return effective number of entries in dataset, i.e., sum all weights.
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.
RooAbsOptTestStatistic is the abstract base class for test statistics objects that evaluate a functio...
RooAbsReal * _funcClone
Pointer to internal clone of input function.
RooArgSet * _normSet
Pointer to set with observables used for normalization.
RooAbsData * _dataClone
Pointer to internal clone if input data.
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
Class RooDataWeightedAverage calculate a weighted average of a function or p.d.f given a dataset with...
double globalNormalization() const override
Return global normalization term by which raw (combined) test statistic should be defined to obtain f...
~RooDataWeightedAverage() override
Destructor.
bool _showProgress
Show progress indication during evaluation if true.
double evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const override
Calculate the data weighted average for events [firstEVent,lastEvent] with step size stepSize.
RooDataWeightedAverage(const char *name, const char *title, RooAbsReal &real, RooAbsData &data, const RooArgSet &projDeps, RooAbsTestStatistic::Configuration const &cfg, bool showProgress=false)
Constructor of data weighted average of given p.d.f over given data.
double _sumWeight
Global sum of weights needed for normalization.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47