Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAbsTestStatistic.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 *
4 * Copyright (c) 2024, CERN
5 *
6 * Redistribution and use in source and binary forms,
7 * with or without modification, are permitted according to the terms
8 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
9 */
10
11#ifndef ROO_ABS_TEST_STATISTIC
12#define ROO_ABS_TEST_STATISTIC
13
14#include "RooAbsReal.h"
15#include "RooSetProxy.h"
16#include "RooRealProxy.h"
17#include "TStopwatch.h"
18#include "Math/Util.h"
19
20#include <string>
21#include <vector>
22
23class RooArgSet ;
24class RooAbsData ;
25class RooAbsReal ;
26class RooSimultaneous ;
27class RooRealMPFE ;
28
32
34 friend class RooRealMPFE;
35public:
36
38 /// Stores the configuration parameters for RooAbsTestStatistic.
39 std::string rangeName;
40 std::string addCoefRangeName;
41 int nCPU = 1;
43 bool verbose = true;
44 bool splitCutRange = false;
45 bool cloneInputData = true;
47 bool binnedL = false;
49 };
50
51 // Constructors, assignment etc
52 RooAbsTestStatistic(const char *name, const char *title, RooAbsReal& real, RooAbsData& data,
53 const RooArgSet& projDeps, Configuration const& cfg);
54 RooAbsTestStatistic(const RooAbsTestStatistic& other, const char* name=nullptr);
55 ~RooAbsTestStatistic() override;
56 virtual RooAbsTestStatistic* create(const char *name, const char *title, RooAbsReal& real, RooAbsData& data,
57 const RooArgSet& projDeps, Configuration const& cfg) = 0;
58
59 void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt=true) override ;
60
61 virtual double combinedValue(RooAbsReal** gofArray, Int_t nVal) const = 0 ;
62 virtual double globalNormalization() const {
63 // Default value of global normalization factor is 1.0
64 return 1.0 ;
65 }
66
67 bool setData(RooAbsData& data, bool cloneData=true) override ;
68
69 void enableOffsetting(bool flag) override ;
70 bool isOffsetting() const override { return _doOffset ; }
71 double offset() const override { return _offset.Sum() ; }
72 virtual double offsetCarry() const { return _offset.Carry(); }
73
76 // Return test statistic operation mode of this instance (SimMaster, MPMaster or Slave)
77 return _gofOpMode ;
78 }
79
80protected:
81
82 void printCompactTreeHook(std::ostream& os, const char* indent="") override ;
83
84 bool redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override ;
85 double evaluate() const override ;
86
87 virtual double evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const = 0 ;
88 virtual double getCarry() const;
89
90 // Overridden in cache-optimized test statistic
91 virtual void runRecalculateCache(std::size_t /*firstEvent*/, std::size_t /*lastEvent*/, std::size_t /*stepSize*/) const {}
92
94 void setSimCount(Int_t simCount) {
95 // Store total number of components p.d.f. of a RooSimultaneous in this component test statistic
96 _simCount = simCount ;
97 }
98
99 void setEventCount(Int_t nEvents) {
100 // Store total number of events in this component test statistic
101 _nEvents = nEvents ;
102 }
103
104 Int_t numSets() const {
105 // Return total number of sets for parallel calculation
106 return _numSets ;
107 }
108 Int_t setNum() const {
109 // Return parallel calculation set number for this instance
110 return _setNum ;
111 }
112
113 RooSetProxy _paramSet ; ///< Parameters of the test statistic (=parameters of the input function)
114
115
116 // Original arguments
117 RooAbsReal* _func = nullptr; ///< Pointer to original input function
118 RooAbsData* _data = nullptr; ///< Pointer to original input dataset
119 const RooArgSet* _projDeps = nullptr; ///< Pointer to set with projected observables
120 std::string _rangeName ; ///< Name of range in which to calculate test statistic
121 std::string _addCoefRangeName ; ///< Name of reference to be used for RooAddPdf components
122 bool _splitRange = false; ///< Split rangeName in RooSimultaneous index labels if true
123 Int_t _simCount = 1; ///< Total number of component p.d.f.s in RooSimultaneous (if any)
124 bool _verbose = false; ///< Verbose messaging if true
125
126 virtual bool setDataSlave(RooAbsData& /*data*/, bool /*cloneData*/=true, bool /*ownNewDataAnyway*/=false) { return true ; }
127
128 //private:
129
130
131 virtual bool processEmptyDataSets() const { return true ; }
132
133 bool initialize() ;
134 void initSimMode(RooSimultaneous* pdf, RooAbsData* data, const RooArgSet* projDeps, std::string const& rangeName, std::string const& addCoefRangeName) ;
135 void initMPMode(RooAbsReal* real, RooAbsData* data, const RooArgSet* projDeps, std::string const& rangeName, std::string const& addCoefRangeName) ;
136
137 mutable bool _init = false; ///<! Is object initialized
138 GOFOpMode _gofOpMode = Slave; ///< Operation mode of test statistic instance
139
140 Int_t _nEvents = 0; ///< Total number of events in test statistic calculation
141 Int_t _setNum = 0; ///< Partition number of this instance in parallel calculation mode
142 Int_t _numSets = 1; ///< Total number of partitions in parallel calculation mode
143 Int_t _extSet = 0; ///<! Number of designated set to calculated extended term
144
145 // Simultaneous mode data
146 std::vector<std::unique_ptr<RooAbsTestStatistic>> _gofArray; ///<! Array of sub-contexts representing part of the combined test statistic
147
148 // Parallel mode data
149 Int_t _nCPU = 1; ///< Number of processors to use in parallel calculation mode
150 pRooRealMPFE* _mpfeArray = nullptr; ///<! Array of parallel execution frond ends
151
152 RooFit::MPSplit _mpinterl = RooFit::BulkPartition; ///< Use interleaving strategy rather than N-wise split for partitioning of dataset for multiprocessor-split
153 bool _doOffset = false; ///< Apply interval value offset to control numeric precision?
154 const bool _takeGlobalObservablesFromData = false; ///< If the global observable values are taken from data
155 mutable ROOT::Math::KahanSum<double> _offset {0.0}; ///<! Offset as KahanSum to avoid loss of precision
156 mutable double _evalCarry = 0.0; ///<! carry of Kahan sum in evaluatePartition
157};
158
159#endif
RooAbsData * pRooAbsData
RooRealMPFE * pRooRealMPFE
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
char name[80]
Definition TGX11.cxx:110
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:122
T Sum() const
Definition Util.h:240
T Carry() const
Definition Util.h:250
Abstract container object that can hold multiple RooAbsArg objects.
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
Abstract base class for all test statistics.
Int_t _setNum
Partition number of this instance in parallel calculation mode.
virtual RooAbsTestStatistic * create(const char *name, const char *title, RooAbsReal &real, RooAbsData &data, const RooArgSet &projDeps, Configuration const &cfg)=0
virtual bool processEmptyDataSets() const
double _evalCarry
! carry of Kahan sum in evaluatePartition
std::string _addCoefRangeName
Name of reference to be used for RooAddPdf components.
Int_t _nEvents
Total number of events in test statistic calculation.
GOFOpMode operMode() const
Int_t _nCPU
Number of processors to use in parallel calculation mode.
RooSetProxy _paramSet
Parameters of the test statistic (=parameters of the input function)
virtual double globalNormalization() const
RooAbsReal * _func
Pointer to original input function.
bool setData(RooAbsData &data, bool cloneData=true) override
Change dataset that is used to given one.
void printCompactTreeHook(std::ostream &os, const char *indent="") override
Add extra information on component test statistics when printing itself as part of a tree structure.
Int_t _numSets
Total number of partitions in parallel calculation mode.
RooFit::MPSplit _mpinterl
Use interleaving strategy rather than N-wise split for partitioning of dataset for multiprocessor-spl...
bool isOffsetting() const override
double evaluate() const override
Calculate and return value of test statistic.
GOFOpMode _gofOpMode
Operation mode of test statistic instance.
virtual bool setDataSlave(RooAbsData &, bool=true, bool=false)
void initMPMode(RooAbsReal *real, RooAbsData *data, const RooArgSet *projDeps, std::string const &rangeName, std::string const &addCoefRangeName)
Initialize multi-processor calculation mode.
std::string _rangeName
Name of range in which to calculate test statistic.
void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt=true) override
Forward constant term optimization management calls to component test statistics.
bool _init
! Is object initialized
Int_t _simCount
Total number of component p.d.f.s in RooSimultaneous (if any)
ROOT::Math::KahanSum< double > _offset
! Offset as KahanSum to avoid loss of precision
virtual void runRecalculateCache(std::size_t, std::size_t, std::size_t) const
void setSimCount(Int_t simCount)
Int_t _extSet
! Number of designated set to calculated extended term
void setEventCount(Int_t nEvents)
double offset() const override
std::vector< std::unique_ptr< RooAbsTestStatistic > > _gofArray
! Array of sub-contexts representing part of the combined test statistic
bool initialize()
One-time initialization of the test statistic.
virtual double offsetCarry() const
const RooArgSet * _projDeps
Pointer to set with projected observables.
void initSimMode(RooSimultaneous *pdf, RooAbsData *data, const RooArgSet *projDeps, std::string const &rangeName, std::string const &addCoefRangeName)
Initialize simultaneous p.d.f processing mode.
~RooAbsTestStatistic() override
Destructor.
virtual double getCarry() const
bool _verbose
Verbose messaging if true.
void enableOffsetting(bool flag) override
virtual double evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const =0
bool _splitRange
Split rangeName in RooSimultaneous index labels if true.
virtual double combinedValue(RooAbsReal **gofArray, Int_t nVal) const =0
pRooRealMPFE * _mpfeArray
! Array of parallel execution frond ends
bool _doOffset
Apply interval value offset to control numeric precision?
RooAbsData * _data
Pointer to original input dataset.
const bool _takeGlobalObservablesFromData
If the global observable values are taken from data.
void setMPSet(Int_t setNum, Int_t numSets)
Set MultiProcessor set number identification of this instance.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override
Forward server redirect calls to component test statistics.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Multi-processor front-end for parallel calculation of RooAbsReal objects.
Definition RooRealMPFE.h:29
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
@ BulkPartition
std::string rangeName
Stores the configuration parameters for RooAbsTestStatistic.