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 "Math/Util.h"
20
21#include <string>
22#include <vector>
23
24class RooArgSet ;
25class RooAbsData ;
26class RooAbsReal ;
27class RooSimultaneous ;
28class RooRealMPFE ;
29
31typedef RooAbsData* pRooAbsData ;
32typedef RooRealMPFE* pRooRealMPFE ;
33
34class RooAbsTestStatistic : public RooAbsReal {
35 friend class RooRealMPFE;
36public:
37
38 struct Configuration {
39 /// Stores the configuration parameters for RooAbsTestStatistic.
40 std::string rangeName;
41 std::string addCoefRangeName;
42 int nCPU = 1;
44 bool verbose = true;
45 bool splitCutRange = false;
46 bool cloneInputData = true;
47 double integrateOverBinsPrecision = -1.;
48 bool binnedL = false;
50 };
51
52 // Constructors, assignment etc
53 RooAbsTestStatistic(const char *name, const char *title, RooAbsReal& real, RooAbsData& data,
54 const RooArgSet& projDeps, Configuration const& cfg);
55 RooAbsTestStatistic(const RooAbsTestStatistic& other, const char* name=nullptr);
56 ~RooAbsTestStatistic() override;
57 virtual RooAbsTestStatistic* create(const char *name, const char *title, RooAbsReal& real, RooAbsData& data,
58 const RooArgSet& projDeps, Configuration const& cfg) = 0;
59
60 void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt=true) override ;
61
62 virtual double combinedValue(RooAbsReal** gofArray, Int_t nVal) const = 0 ;
63 virtual double globalNormalization() const {
64 // Default value of global normalization factor is 1.0
65 return 1.0 ;
66 }
67
68 bool setData(RooAbsData& data, bool cloneData=true) override ;
69
70 void enableOffsetting(bool flag) override ;
71 bool isOffsetting() const override { return _doOffset ; }
72 double offset() const override { return _offset.Sum() ; }
73 virtual double offsetCarry() const { return _offset.Carry(); }
74
76 GOFOpMode operMode() const {
77 // Return test statistic operation mode of this instance (SimMaster, MPMaster or Slave)
78 return _gofOpMode ;
79 }
80
81protected:
82
83 void printCompactTreeHook(std::ostream& os, const char* indent="") override ;
84
85 bool redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override ;
86 double evaluate() const override ;
87
88 virtual double evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const = 0 ;
89 virtual double getCarry() const;
90
91 // Overridden in cache-optimized test statistic
92 virtual void runRecalculateCache(std::size_t /*firstEvent*/, std::size_t /*lastEvent*/, std::size_t /*stepSize*/) const {}
93
95 void setSimCount(Int_t simCount) {
96 // Store total number of components p.d.f. of a RooSimultaneous in this component test statistic
98 }
99
100 void setEventCount(Int_t nEvents) {
101 // Store total number of events in this component test statistic
102 _nEvents = nEvents ;
103 }
104
105 Int_t numSets() const {
106 // Return total number of sets for parallel calculation
107 return _numSets ;
108 }
109 Int_t setNum() const {
110 // Return parallel calculation set number for this instance
111 return _setNum ;
112 }
113
114 RooSetProxy _paramSet ; ///< Parameters of the test statistic (=parameters of the input function)
115
116
117 // Original arguments
118 RooAbsReal* _func = nullptr; ///< Pointer to original input function
119 RooAbsData* _data = nullptr; ///< Pointer to original input dataset
120 const RooArgSet* _projDeps = nullptr; ///< Pointer to set with projected observables
121 std::string _rangeName ; ///< Name of range in which to calculate test statistic
122 std::string _addCoefRangeName ; ///< Name of reference to be used for RooAddPdf components
123 bool _splitRange = false; ///< Split rangeName in RooSimultaneous index labels if true
124 Int_t _simCount = 1; ///< Total number of component p.d.f.s in RooSimultaneous (if any)
125 bool _verbose = false; ///< Verbose messaging if true
126
127 virtual bool setDataSlave(RooAbsData& /*data*/, bool /*cloneData*/=true, bool /*ownNewDataAnyway*/=false) { return true ; }
128
129 //private:
130
131
132 virtual bool processEmptyDataSets() const { return true ; }
133
134 bool initialize() ;
135 void initSimMode(RooSimultaneous* pdf, RooAbsData* data, const RooArgSet* projDeps, std::string const& rangeName, std::string const& addCoefRangeName) ;
136 void initMPMode(RooAbsReal* real, RooAbsData* data, const RooArgSet* projDeps, std::string const& rangeName, std::string const& addCoefRangeName) ;
137
138 mutable bool _init = false; ///<! Is object initialized
139 GOFOpMode _gofOpMode = Slave; ///< Operation mode of test statistic instance
140
141 Int_t _nEvents = 0; ///< Total number of events in test statistic calculation
142 Int_t _setNum = 0; ///< Partition number of this instance in parallel calculation mode
143 Int_t _numSets = 1; ///< Total number of partitions in parallel calculation mode
144 Int_t _extSet = 0; ///<! Number of designated set to calculated extended term
145
146 // Simultaneous mode data
147 std::vector<std::unique_ptr<RooAbsTestStatistic>> _gofArray; ///<! Array of sub-contexts representing part of the combined test statistic
148
149 // Parallel mode data
150 Int_t _nCPU = 1; ///< Number of processors to use in parallel calculation mode
151 pRooRealMPFE* _mpfeArray = nullptr; ///<! Array of parallel execution frond ends
152
153 RooFit::MPSplit _mpinterl = RooFit::BulkPartition; ///< Use interleaving strategy rather than N-wise split for partitioning of dataset for multiprocessor-split
154 bool _doOffset = false; ///< Apply interval value offset to control numeric precision?
155 const bool _takeGlobalObservablesFromData = false; ///< If the global observable values are taken from data
156 mutable ROOT::Math::KahanSum<double> _offset {0.0}; ///<! Offset as KahanSum to avoid loss of precision
157 mutable double _evalCarry = 0.0; ///<! carry of Kahan sum in evaluatePartition
158};
159
160#endif
161
162/// \endcond
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
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:137
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:63
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