Logo ROOT  
Reference Guide
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 
22 Class RooDataWeightedAverage calculate a weighted
23 average of a function or p.d.f given a dataset with observable
24 values, i.e. DWA(f(x),D(x)) = sum_i f(x_i) where x_i is draw from
25 D(i). This class is an implementation of RooAbsOptTestStatistics
26 can make use of the optimization and parallization infrastructure
27 of that base class. The main use of RooDataWeightedAverage is
28 to calculate curves in RooPlots that are added with ProjWData()
29 plot option.
30 
31 **/
32 
33 #include "RooFit.h"
34 #include "Riostream.h"
35 
36 #include "RooDataWeightedAverage.h"
37 #include "RooAbsData.h"
38 #include "RooAbsPdf.h"
39 #include "RooCmdConfig.h"
40 #include "RooMsgService.h"
41 #include "RooAbsDataStore.h"
42 
43 
44 
45 using namespace std;
46 
48 ;
49 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Constructor of data weighted average of given p.d.f over given data. If nCPU>1 the calculation is parallelized
53 /// over multuple processes. If showProgress is true a progress indicator printing a single dot for each evaluation
54 /// is shown. If interleave is true, the dataset split over multiple processes is done with an interleave pattern
55 /// rather than a bulk-split pattern.
56 
57 RooDataWeightedAverage::RooDataWeightedAverage(const char *name, const char *title, RooAbsReal& pdf, RooAbsData& indata,
58  const RooArgSet& projdeps, RooAbsTestStatistic::Configuration const& cfg,
59  bool showProgress) :
60  RooAbsOptTestStatistic(name,title,pdf,indata,projdeps,cfg),
61  _showProgress(showProgress)
62 {
63  if (_showProgress) {
64  coutI(Plotting) << "RooDataWeightedAverage::ctor(" << GetName() << ") constructing data weighted average of function " << pdf.GetName()
65  << " over " << indata.numEntries() << " data points of " << *(indata.get()) << " with a total weight of " << indata.sumEntries() << endl ;
66  }
67  _sumWeight = indata.sumEntries() ;
68 }
69 
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Copy constructor
73 
76  _sumWeight(other._sumWeight),
77  _showProgress(other._showProgress)
78 {
79 }
80 
81 
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Destructor
85 
87 {
88 }
89 
90 
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Return global normalization term by which raw (combined) test statistic should
94 /// be defined to obtain final test statistic. For a data weighted avarage this
95 /// the the sum of all weights
96 
98 {
99  return _sumWeight ;
100 }
101 
102 
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Calculate the data weighted average for events [firstEVent,lastEvent] with step size stepSize
106 
107 Double_t RooDataWeightedAverage::evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const
108 {
109  Double_t result(0) ;
110 
111  _dataClone->store()->recalculateCache( _projDeps, firstEvent, lastEvent, stepSize,kFALSE) ;
112 
113  if (setNum()==0 && _showProgress) {
114  ccoutP(Plotting) << "." ;
115  cout.flush() ;
116  }
117 
118  for (auto i=firstEvent ; i<lastEvent ; i+=stepSize) {
119 
120  // get the data values for this event
121  _dataClone->get(i);
122  if (_dataClone->weight()==0) continue ;
123 
125  result += term;
126  }
127 
128  return result ;
129 }
130 
131 
132 
RooDataWeightedAverage::~RooDataWeightedAverage
virtual ~RooDataWeightedAverage()
Destructor.
Definition: RooDataWeightedAverage.cxx:86
RooCmdConfig.h
RooMsgService.h
RooAbsData
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:49
RooFit.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooAbsOptTestStatistic::_funcClone
RooAbsReal * _funcClone
Definition: RooAbsOptTestStatistic.h:81
RooAbsData::weight
virtual Double_t weight() const =0
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooAbsData::store
RooAbsDataStore * store()
Definition: RooAbsData.h:68
coutI
#define coutI(a)
Definition: RooMsgService.h:30
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
RooAbsOptTestStatistic::_dataClone
RooAbsData * _dataClone
Definition: RooAbsOptTestStatistic.h:80
RooDataWeightedAverage.h
RooAbsData::sumEntries
virtual Double_t sumEntries() const =0
Return effective number of entries in dataset, i.e., sum all weights.
RooDataWeightedAverage
Class RooDataWeightedAverage calculate a weighted average of a function or p.d.f given a dataset with...
Definition: RooDataWeightedAverage.h:22
RooAbsPdf.h
RooAbsOptTestStatistic::_projDeps
RooArgSet * _projDeps
Definition: RooAbsOptTestStatistic.h:82
RooAbsDataStore::recalculateCache
virtual void recalculateCache(const RooArgSet *, Int_t, Int_t, Int_t, Bool_t)
Definition: RooAbsDataStore.h:111
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
RooAbsData::get
virtual const RooArgSet * get() const
Definition: RooAbsData.h:92
RooFit::Plotting
@ Plotting
Definition: RooGlobalFunc.h:60
RooAbsTestStatistic::setNum
Int_t setNum() const
Definition: RooAbsTestStatistic.h:105
ccoutP
#define ccoutP(a)
Definition: RooMsgService.h:39
RooDataWeightedAverage::_showProgress
Bool_t _showProgress
Definition: RooDataWeightedAverage.h:51
RooAbsTestStatistic::Configuration
Definition: RooAbsTestStatistic.h:43
RooAbsData::numEntries
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Definition: RooAbsData.cxx:304
RooDataWeightedAverage::evaluatePartition
virtual Double_t evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const
Calculate the data weighted average for events [firstEVent,lastEvent] with step size stepSize.
Definition: RooDataWeightedAverage.cxx:107
RooAbsDataStore.h
RooDataWeightedAverage::_sumWeight
Double_t _sumWeight
Definition: RooDataWeightedAverage.h:50
RooAbsData.h
Double_t
double Double_t
Definition: RtypesCore.h:59
RooDataWeightedAverage::RooDataWeightedAverage
RooDataWeightedAverage()
Definition: RooDataWeightedAverage.h:26
RooDataWeightedAverage::globalNormalization
virtual Double_t globalNormalization() const
Return global normalization term by which raw (combined) test statistic should be defined to obtain f...
Definition: RooDataWeightedAverage.cxx:97
RooAbsOptTestStatistic
RooAbsOptTestStatistic is the abstract base class for test statistics objects that evaluate a functio...
Definition: RooAbsOptTestStatistic.h:28
name
char name[80]
Definition: TGX11.cxx:110
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
RooAbsOptTestStatistic::_normSet
RooArgSet * _normSet
Definition: RooAbsOptTestStatistic.h:78
Riostream.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:33