Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAbsTestStatistic.h
Go to the documentation of this file.
1/// \cond ROOFIT_INTERNAL
2
3/*
4 * Project: RooFit
5 *
6 * Copyright (c) 2024, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#ifndef ROO_ABS_TEST_STATISTIC
14#define ROO_ABS_TEST_STATISTIC
15
16#include "RooAbsReal.h"
17#include "RooSetProxy.h"
18#include "RooRealProxy.h"
19#include "TStopwatch.h"
20#include "Math/Util.h"
21
22#include <string>
23#include <vector>
24
25class RooArgSet ;
26class RooAbsData ;
27class RooAbsReal ;
28class RooSimultaneous ;
29class RooRealMPFE ;
30
32typedef RooAbsData* pRooAbsData ;
33typedef RooRealMPFE* pRooRealMPFE ;
34
35class RooAbsTestStatistic : public RooAbsReal {
36 friend class RooRealMPFE;
37public:
38
39 struct Configuration {
40 /// Stores the configuration parameters for RooAbsTestStatistic.
41 std::string rangeName;
42 std::string addCoefRangeName;
43 int nCPU = 1;
45 bool verbose = true;
46 bool splitCutRange = false;
47 bool cloneInputData = true;
48 double integrateOverBinsPrecision = -1.;
49 bool binnedL = false;
51 };
52
53 // Constructors, assignment etc
54 RooAbsTestStatistic(const char *name, const char *title, RooAbsReal& real, RooAbsData& data,
55 const RooArgSet& projDeps, Configuration const& cfg);
56 RooAbsTestStatistic(const RooAbsTestStatistic& other, const char* name=nullptr);
57 ~RooAbsTestStatistic() override;
58 virtual RooAbsTestStatistic* create(const char *name, const char *title, RooAbsReal& real, RooAbsData& data,
59 const RooArgSet& projDeps, Configuration const& cfg) = 0;
60
61 void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt=true) override ;
62
63 virtual double combinedValue(RooAbsReal** gofArray, Int_t nVal) const = 0 ;
64 virtual double globalNormalization() const {
65 // Default value of global normalization factor is 1.0
66 return 1.0 ;
67 }
68
69 bool setData(RooAbsData& data, bool cloneData=true) override ;
70
71 void enableOffsetting(bool flag) override ;
72 bool isOffsetting() const override { return _doOffset ; }
73 double offset() const override { return _offset.Sum() ; }
74 virtual double offsetCarry() const { return _offset.Carry(); }
75
77 GOFOpMode operMode() const {
78 // Return test statistic operation mode of this instance (SimMaster, MPMaster or Slave)
79 return _gofOpMode ;
80 }
81
82protected:
83
84 void printCompactTreeHook(std::ostream& os, const char* indent="") override ;
85
86 bool redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override ;
87 double evaluate() const override ;
88
89 virtual double evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const = 0 ;
90 virtual double getCarry() const;
91
92 // Overridden in cache-optimized test statistic
93 virtual void runRecalculateCache(std::size_t /*firstEvent*/, std::size_t /*lastEvent*/, std::size_t /*stepSize*/) const {}
94
96 void setSimCount(Int_t simCount) {
97 // Store total number of components p.d.f. of a RooSimultaneous in this component test statistic
99 }
100
101 void setEventCount(Int_t nEvents) {
102 // Store total number of events in this component test statistic
103 _nEvents = nEvents ;
104 }
105
106 Int_t numSets() const {
107 // Return total number of sets for parallel calculation
108 return _numSets ;
109 }
110 Int_t setNum() const {
111 // Return parallel calculation set number for this instance
112 return _setNum ;
113 }
114
115 RooSetProxy _paramSet ; ///< Parameters of the test statistic (=parameters of the input function)
116
117
118 // Original arguments
119 RooAbsReal* _func = nullptr; ///< Pointer to original input function
120 RooAbsData* _data = nullptr; ///< Pointer to original input dataset
121 const RooArgSet* _projDeps = nullptr; ///< Pointer to set with projected observables
122 std::string _rangeName ; ///< Name of range in which to calculate test statistic
123 std::string _addCoefRangeName ; ///< Name of reference to be used for RooAddPdf components
124 bool _splitRange = false; ///< Split rangeName in RooSimultaneous index labels if true
125 Int_t _simCount = 1; ///< Total number of component p.d.f.s in RooSimultaneous (if any)
126 bool _verbose = false; ///< Verbose messaging if true
127
128 virtual bool setDataSlave(RooAbsData& /*data*/, bool /*cloneData*/=true, bool /*ownNewDataAnyway*/=false) { return true ; }
129
130 //private:
131
132
133 virtual bool processEmptyDataSets() const { return true ; }
134
135 bool initialize() ;
136 void initSimMode(RooSimultaneous* pdf, RooAbsData* data, const RooArgSet* projDeps, std::string const& rangeName, std::string const& addCoefRangeName) ;
137 void initMPMode(RooAbsReal* real, RooAbsData* data, const RooArgSet* projDeps, std::string const& rangeName, std::string const& addCoefRangeName) ;
138
139 mutable bool _init = false; ///<! Is object initialized
140 GOFOpMode _gofOpMode = Slave; ///< Operation mode of test statistic instance
141
142 Int_t _nEvents = 0; ///< Total number of events in test statistic calculation
143 Int_t _setNum = 0; ///< Partition number of this instance in parallel calculation mode
144 Int_t _numSets = 1; ///< Total number of partitions in parallel calculation mode
145 Int_t _extSet = 0; ///<! Number of designated set to calculated extended term
146
147 // Simultaneous mode data
148 std::vector<std::unique_ptr<RooAbsTestStatistic>> _gofArray; ///<! Array of sub-contexts representing part of the combined test statistic
149
150 // Parallel mode data
151 Int_t _nCPU = 1; ///< Number of processors to use in parallel calculation mode
152 pRooRealMPFE* _mpfeArray = nullptr; ///<! Array of parallel execution frond ends
153
154 RooFit::MPSplit _mpinterl = RooFit::BulkPartition; ///< Use interleaving strategy rather than N-wise split for partitioning of dataset for multiprocessor-split
155 bool _doOffset = false; ///< Apply interval value offset to control numeric precision?
156 const bool _takeGlobalObservablesFromData = false; ///< If the global observable values are taken from data
157 mutable ROOT::Math::KahanSum<double> _offset {0.0}; ///<! Offset as KahanSum to avoid loss of precision
158 mutable double _evalCarry = 0.0; ///<! carry of Kahan sum in evaluatePartition
159};
160
161#endif
162
163/// \endcond
int Int_t
Definition RtypesCore.h:45
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
char name[80]
Definition TGX11.cxx:110
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:136
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
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
@ BulkPartition
void evaluate(typename Architecture_t::Tensor_t &A, EActivationFunction f)
Apply the given activation function to each value in the given tensor A.
Definition Functions.h:98
void initialize(typename Architecture_t::Matrix_t &A, EInitialization m)
Definition Functions.h:282