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