Logo ROOT  
Reference Guide
RooAbsTestStatistic.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 RooAbsTestStatistic.cxx
19\class RooAbsTestStatistic
20\ingroup Roofitcore
21
22RooAbsTestStatistic is the abstract base class for all test
23statistics. Test statistics that evaluate the PDF at each data
24point should inherit from the RooAbsOptTestStatistic class which
25implements several generic optimizations that can be done for such
26quantities.
27
28This test statistic base class organizes calculation of test
29statistic values for RooSimultaneous PDF as a combination of test
30statistic values for the PDF components of the simultaneous PDF and
31organizes multi-processor parallel calculation of test statistic
32values. For the latter, the test statistic value is calculated in
33partitions in parallel executing processes and a posteriori
34combined in the main thread.
35**/
36
37#include "RooAbsTestStatistic.h"
38
39#include "RooAbsPdf.h"
40#include "RooSimultaneous.h"
41#include "RooAbsData.h"
42#include "RooArgSet.h"
43#include "RooRealVar.h"
44#include "RooNLLVar.h"
45#include "RooRealMPFE.h"
46#include "RooErrorHandler.h"
47#include "RooMsgService.h"
48#include "RooProdPdf.h"
49#include "RooRealSumPdf.h"
51
52#include "TTimeStamp.h"
53#include "TClass.h"
54#include <string>
55#include <stdexcept>
56
57using namespace std;
58
60
61
62////////////////////////////////////////////////////////////////////////////////
63/// Create a test statistic from the given function and the data.
64/// \param[in] name Name of the test statistic
65/// \param[in] title Title (for plotting)
66/// \param[in] real Function to be used for tests
67/// \param[in] data Data to fit function to
68/// \param[in] projDeps A set of projected observables
69/// \param[in] cfg statistic configuration object
70///
71/// cfg contains:
72/// - rangeName Fit data only in range with given name
73/// - addCoefRangeName If not null, all RooAddPdf components of `real` will be instructed to fix their fraction definitions to the given named range.
74/// - nCPU If larger than one, the test statistic calculation will be parallelized over multiple processes.
75/// By default the data is split with 'bulk' partitioning (each process calculates a contigious block of fraction 1/nCPU
76/// of the data). For binned data this approach may be suboptimal as the number of bins with >0 entries
77/// in each processing block many vary greatly thereby distributing the workload rather unevenly.
78/// - interleave is set to true, the interleave partitioning strategy is used where each partition
79/// i takes all bins for which (ibin % ncpu == i) which is more likely to result in an even workload.
80/// - verbose Be more verbose.
81/// - splitCutRange If true, a different rangeName constructed as rangeName_{catName} will be used
82/// as range definition for each index state of a RooSimultaneous. This means that a different range can be defined
83/// for each category such as
84/// ```
85/// myVariable.setRange("range_pi0", 135, 210);
86/// myVariable.setRange("range_gamma", 50, 210);
87/// ```
88/// if the categories are called "pi0" and "gamma".
89
91 const RooArgSet& projDeps, RooAbsTestStatistic::Configuration const& cfg) :
92 RooAbsReal(name,title),
93 _paramSet("paramSet","Set of parameters",this),
94 _func(&real),
95 _data(&data),
96 _projDeps((RooArgSet*)projDeps.Clone()),
97 _rangeName(cfg.rangeName),
98 _addCoefRangeName(cfg.addCoefRangeName),
99 _splitRange(cfg.splitCutRange),
100 _verbose(cfg.verbose),
101 // Determine if RooAbsReal is a RooSimultaneous
102 _gofOpMode{(cfg.nCPU>1 || cfg.nCPU==-1) ? MPMaster : (dynamic_cast<RooSimultaneous*>(_func) ? SimMaster : Slave)},
103 _nEvents{data.numEntries()},
104 _nCPU(cfg.nCPU != -1 ? cfg.nCPU : 1),
105 _mpinterl(cfg.interleave),
106 _takeGlobalObservablesFromData{cfg.takeGlobalObservablesFromData}
107{
108 // Register all parameters as servers
109 _paramSet.add(*std::unique_ptr<RooArgSet>{real.getParameters(&data)});
110
111 if (cfg.rangeName.find(',') != std::string::npos) {
112 auto errorMsg = std::string("Ranges ") + cfg.rangeName
113 + " were passed to the RooAbsTestStatistic with name \"" + name + "\", "
114 + "but it doesn't support multiple comma-separated fit ranges!\n" +
115 + "Instead, one should combine multiple RooAbsTestStatistic objects "
116 + "(see RooAbsPdf::createNLL for an example with RooNLLVar).";
117 coutE(InputArguments) << errorMsg << std::endl;
118 throw std::invalid_argument(errorMsg);
119 }
120}
121
122
123
124////////////////////////////////////////////////////////////////////////////////
125/// Copy constructor
126
128 RooAbsReal(other,name),
129 _paramSet("paramSet","Set of parameters",this),
130 _func(other._func),
131 _data(other._data),
132 _projDeps((RooArgSet*)other._projDeps->Clone()),
133 _rangeName(other._rangeName),
134 _addCoefRangeName(other._addCoefRangeName),
135 _splitRange(other._splitRange),
136 _verbose(other._verbose),
137 // Determine if RooAbsReal is a RooSimultaneous
138 _gofOpMode{(other._nCPU>1 || other._nCPU==-1) ? MPMaster : (dynamic_cast<RooSimultaneous*>(_func) ? SimMaster : Slave)},
139 _nEvents{_data->numEntries()},
140 _gofSplitMode(other._gofSplitMode),
141 _nCPU(other._nCPU != -1 ? other._nCPU : 1),
142 _mpinterl(other._mpinterl),
143 _doOffset(other._doOffset),
144 _takeGlobalObservablesFromData{other._takeGlobalObservablesFromData},
145 _offset(other._offset),
146 _evalCarry(other._evalCarry)
147{
148 // Our parameters are those of original
149 _paramSet.add(other._paramSet) ;
150}
151
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Destructor
156
158{
159 if (MPMaster == _gofOpMode && _init) {
160 for (Int_t i = 0; i < _nCPU; ++i) delete _mpfeArray[i];
161 delete[] _mpfeArray ;
162 }
163
164 if (SimMaster == _gofOpMode && _init) {
165 for (Int_t i = 0; i < _nGof; ++i) delete _gofArray[i];
166 delete[] _gofArray ;
167 }
168
169 delete _projDeps ;
170
171}
172
173
174
175////////////////////////////////////////////////////////////////////////////////
176/// Calculate and return value of test statistic. If the test statistic
177/// is calculated from a RooSimultaneous, the test statistic calculation
178/// is performed separately on each simultaneous p.d.f component and associated
179/// data, and then combined. If the test statistic calculation is parallelized,
180/// partitions are calculated in nCPU processes and combined a posteriori.
181
183{
184 // One-time Initialization
185 if (!_init) {
186 const_cast<RooAbsTestStatistic*>(this)->initialize() ;
187 }
188
189 if (SimMaster == _gofOpMode) {
190 // Evaluate array of owned GOF objects
191 double ret = 0.;
192
195 } else {
196 double sum = 0., carry = 0.;
197 for (Int_t i = 0 ; i < _nGof; ++i) {
199 double y = _gofArray[i]->getValV();
200 carry += _gofArray[i]->getCarry();
201 y -= carry;
202 const double t = sum + y;
203 carry = (t - sum) - y;
204 sum = t;
205 }
206 }
207 ret = sum ;
208 _evalCarry = carry;
209 }
210
211 // Only apply global normalization if SimMaster doesn't have MP master
212 if (numSets()==1) {
213 const double norm = globalNormalization();
214 ret /= norm;
215 _evalCarry /= norm;
216 }
217
218 return ret ;
219
220 } else if (MPMaster == _gofOpMode) {
221
222 // Start calculations in parallel
223 for (Int_t i = 0; i < _nCPU; ++i) _mpfeArray[i]->calculate();
224
225
226 double sum(0), carry = 0.;
227 for (Int_t i = 0; i < _nCPU; ++i) {
228 double y = _mpfeArray[i]->getValV();
229 carry += _mpfeArray[i]->getCarry();
230 y -= carry;
231 const double t = sum + y;
232 carry = (t - sum) - y;
233 sum = t;
234 }
235
236 double ret = sum ;
237 _evalCarry = carry;
238
239 const double norm = globalNormalization();
240 ret /= norm;
241 _evalCarry /= norm;
242
243 return ret ;
244
245 } else {
246
247 // Evaluate as straight FUNC
248 Int_t nFirst(0), nLast(_nEvents), nStep(1) ;
249
250 switch (_mpinterl) {
252 nFirst = _nEvents * _setNum / _numSets ;
253 nLast = _nEvents * (_setNum+1) / _numSets ;
254 nStep = 1 ;
255 break;
256
258 nFirst = _setNum ;
259 nLast = _nEvents ;
260 nStep = _numSets ;
261 break ;
262
264 nFirst = 0 ;
265 nLast = _nEvents ;
266 nStep = 1 ;
267 break ;
268
269 case RooFit::Hybrid:
270 throw std::logic_error("this should never happen");
271 break ;
272 }
273
274 double ret = evaluatePartition(nFirst,nLast,nStep);
275
276 if (numSets()==1) {
277 const double norm = globalNormalization();
278 ret /= norm;
279 _evalCarry /= norm;
280 }
281
282 return ret ;
283
284 }
285}
286
287
288
289////////////////////////////////////////////////////////////////////////////////
290/// One-time initialization of the test statistic. Setup
291/// infrastructure for simultaneous p.d.f processing and/or
292/// parallelized processing if requested
293
295{
296 if (_init) return false;
297
298 if (MPMaster == _gofOpMode) {
300 } else if (SimMaster == _gofOpMode) {
302 }
303 _init = true;
304 return false;
305}
306
307
308
309////////////////////////////////////////////////////////////////////////////////
310/// Forward server redirect calls to component test statistics
311
312bool RooAbsTestStatistic::redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool)
313{
314 if (SimMaster == _gofOpMode && _gofArray) {
315 // Forward to slaves
316 for (Int_t i = 0; i < _nGof; ++i) {
317 if (_gofArray[i]) {
318 _gofArray[i]->recursiveRedirectServers(newServerList,mustReplaceAll,nameChange);
319 }
320 }
321 } else if (MPMaster == _gofOpMode&& _mpfeArray) {
322 // Forward to slaves
323 for (Int_t i = 0; i < _nCPU; ++i) {
324 if (_mpfeArray[i]) {
325 _mpfeArray[i]->recursiveRedirectServers(newServerList,mustReplaceAll,nameChange);
326// cout << "redirecting servers on " << _mpfeArray[i]->GetName() << endl;
327 }
328 }
329 }
330 return false;
331}
332
333
334
335////////////////////////////////////////////////////////////////////////////////
336/// Add extra information on component test statistics when printing
337/// itself as part of a tree structure
338
340{
341 if (SimMaster == _gofOpMode) {
342 // Forward to slaves
343 os << indent << "RooAbsTestStatistic begin GOF contents" << endl ;
344 for (Int_t i = 0; i < _nGof; ++i) {
345 if (_gofArray[i]) {
346 TString indent2(indent);
347 indent2 += Form("[%d] ",i);
348 _gofArray[i]->printCompactTreeHook(os,indent2);
349 }
350 }
351 os << indent << "RooAbsTestStatistic end GOF contents" << endl;
352 } else if (MPMaster == _gofOpMode) {
353 // WVE implement this
354 }
355}
356
357
358
359////////////////////////////////////////////////////////////////////////////////
360/// Forward constant term optimization management calls to component
361/// test statistics
362
364{
365 initialize();
366 if (SimMaster == _gofOpMode) {
367 // Forward to slaves
368 for (Int_t i = 0; i < _nGof; ++i) {
369 // In SimComponents Splitting strategy only constOptimize the terms that are actually used
371 if ( (i % _numSets == _setNum) || (effSplit != RooFit::SimComponents) ) {
372 if (_gofArray[i]) _gofArray[i]->constOptimizeTestStatistic(opcode,doAlsoTrackingOpt);
373 }
374 }
375 } else if (MPMaster == _gofOpMode) {
376 for (Int_t i = 0; i < _nCPU; ++i) {
377 _mpfeArray[i]->constOptimizeTestStatistic(opcode,doAlsoTrackingOpt);
378 }
379 }
380}
381
382
383
384////////////////////////////////////////////////////////////////////////////////
385/// Set MultiProcessor set number identification of this instance
386
388{
389 _setNum = inSetNum; _numSets = inNumSets;
391
392 if (SimMaster == _gofOpMode) {
393 // Forward to slaves
394 initialize();
395 for (Int_t i = 0; i < _nGof; ++i) {
396 if (_gofArray[i]) _gofArray[i]->setMPSet(inSetNum,inNumSets);
397 }
398 }
399}
400
401
402
403////////////////////////////////////////////////////////////////////////////////
404/// Initialize multi-processor calculation mode. Create component test statistics in separate
405/// processed that are connected to this process through a RooAbsRealMPFE front-end class.
406
407void RooAbsTestStatistic::initMPMode(RooAbsReal* real, RooAbsData* data, const RooArgSet* projDeps, std::string const& rangeName, std::string const& addCoefRangeName)
408{
410
411 // Create proto-goodness-of-fit
412 Configuration cfg;
413 cfg.rangeName = rangeName;
414 cfg.addCoefRangeName = addCoefRangeName;
415 cfg.nCPU = 1;
416 cfg.interleave = _mpinterl;
417 cfg.verbose = _verbose;
420 // This configuration parameter is stored in the RooAbsOptTestStatistic.
421 // It would have been cleaner to move the member variable into RooAbsTestStatistic,
422 // but to avoid incrementing the class version we do the dynamic_cast trick.
423 if(auto thisAsRooAbsOptTestStatistic = dynamic_cast<RooAbsOptTestStatistic const*>(this)) {
424 cfg.integrateOverBinsPrecision = thisAsRooAbsOptTestStatistic->_integrateBinsPrecision;
425 }
426 RooAbsTestStatistic* gof = create(GetName(),GetTitle(),*real,*data,*projDeps,cfg);
428
429 for (Int_t i = 0; i < _nCPU; ++i) {
430 gof->setMPSet(i,_nCPU);
431 gof->SetName(Form("%s_GOF%d",GetName(),i));
432 gof->SetTitle(Form("%s_GOF%d",GetTitle(),i));
433
434 ccoutD(Eval) << "RooAbsTestStatistic::initMPMode: starting remote server process #" << i << endl;
435 _mpfeArray[i] = new RooRealMPFE(Form("%s_%zx_MPFE%d",GetName(),(size_t)this,i),Form("%s_%zx_MPFE%d",GetTitle(),(size_t)this,i),*gof,false);
436 //_mpfeArray[i]->setVerbose(true,true);
438 if (i > 0) {
440 }
441 }
443 coutI(Eval) << "RooAbsTestStatistic::initMPMode: started " << _nCPU << " remote server process." << endl;
444 //cout << "initMPMode --- done" << endl ;
445 return ;
446}
447
448
449
450////////////////////////////////////////////////////////////////////////////////
451/// Initialize simultaneous p.d.f processing mode. Strip simultaneous
452/// p.d.f into individual components, split dataset in subset
453/// matching each component and create component test statistics for
454/// each of them.
455
457 const RooArgSet* projDeps,
458 std::string const& rangeName, std::string const& addCoefRangeName)
459{
460
461 RooAbsCategoryLValue& simCat = const_cast<RooAbsCategoryLValue&>(simpdf->indexCat());
462
463 TString simCatName(simCat.GetName());
464 TList* dsetList = const_cast<RooAbsData*>(data)->split(*simpdf,processEmptyDataSets());
465 if (!dsetList) {
466 coutE(Fitting) << "RooAbsTestStatistic::initSimMode(" << GetName() << ") ERROR: index category of simultaneous pdf is missing in dataset, aborting" << endl;
467 throw std::runtime_error("RooAbsTestStatistic::initSimMode() ERROR, index category of simultaneous pdf is missing in dataset, aborting");
468 }
469
470 // Count number of used states
471 Int_t n = 0;
472 _nGof = 0;
473
474 for (const auto& catState : simCat) {
475 // Retrieve the PDF for this simCat state
476 RooAbsPdf* pdf = simpdf->getPdf(catState.first.c_str());
477 RooAbsData* dset = (RooAbsData*) dsetList->FindObject(catState.first.c_str());
478
479 if (pdf && dset && (0. != dset->sumEntries() || processEmptyDataSets())) {
480 ++_nGof;
481 }
482 }
483
484 // Allocate arrays
486 _gofSplitMode.resize(_nGof);
487
488 // Create array of regular fit contexts, containing subset of data and single fitCat PDF
489 for (const auto& catState : simCat) {
490 const std::string& catName = catState.first;
491 // Retrieve the PDF for this simCat state
492 RooAbsPdf* pdf = simpdf->getPdf(catName.c_str());
493 RooAbsData* dset = (RooAbsData*) dsetList->FindObject(catName.c_str());
494
495 if (pdf && dset && (0. != dset->sumEntries() || processEmptyDataSets())) {
496 ccoutI(Fitting) << "RooAbsTestStatistic::initSimMode: creating slave calculator #" << n << " for state " << catName
497 << " (" << dset->numEntries() << " dataset entries)" << endl;
498
499
500 // *** START HERE
501 // WVE HACK determine if we have a RooRealSumPdf and then treat it like a binned likelihood
502 RooAbsPdf* binnedPdf = 0 ;
503 bool binnedL = false ;
504 if (pdf->getAttribute("BinnedLikelihood") && pdf->IsA()->InheritsFrom(RooRealSumPdf::Class())) {
505 // Simplest case: top-level of component is a RRSP
506 binnedPdf = pdf ;
507 binnedL = true ;
508 } else if (pdf->IsA()->InheritsFrom(RooProdPdf::Class())) {
509 // Default case: top-level pdf is a product of RRSP and other pdfs
510 RooFIter iter = ((RooProdPdf*)pdf)->pdfList().fwdIterator() ;
511 RooAbsArg* component ;
512 while ((component = iter.next())) {
513 if (component->getAttribute("BinnedLikelihood") && component->IsA()->InheritsFrom(RooRealSumPdf::Class())) {
514 binnedPdf = (RooAbsPdf*) component ;
515 binnedL = true ;
516 }
517 if (component->getAttribute("MAIN_MEASUREMENT")) {
518 // not really a binned pdf, but this prevents a (potentially) long list of subsidiary measurements to be passed to the slave calculator
519 binnedPdf = (RooAbsPdf*) component ;
520 }
521 }
522 }
523 // WVE END HACK
524 // Below here directly pass binnedPdf instead of PROD(binnedPdf,constraints) as constraints are evaluated elsewhere anyway
525 // and omitting them reduces model complexity and associated handling/cloning times
526 Configuration cfg;
527 cfg.addCoefRangeName = addCoefRangeName;
528 cfg.interleave = _mpinterl;
529 cfg.verbose = _verbose;
531 cfg.binnedL = binnedL;
533 // This configuration parameter is stored in the RooAbsOptTestStatistic.
534 // It would have been cleaner to move the member variable into RooAbsTestStatistic,
535 // but to avoid incrementing the class version we do the dynamic_cast trick.
536 if(auto thisAsRooAbsOptTestStatistic = dynamic_cast<RooAbsOptTestStatistic const*>(this)) {
537 cfg.integrateOverBinsPrecision = thisAsRooAbsOptTestStatistic->_integrateBinsPrecision;
538 }
539 if (_splitRange && !rangeName.empty()) {
540 cfg.rangeName = rangeName + "_" + catName;
541 cfg.nCPU = _nCPU*(_mpinterl?-1:1);
542 } else {
543 cfg.rangeName = rangeName;
544 cfg.nCPU = _nCPU;
545 }
546 _gofArray[n] = create(catName.c_str(),catName.c_str(),(binnedPdf?*binnedPdf:*pdf),*dset,*projDeps,cfg);
548 // *** END HERE
549
550 // Fill per-component split mode with Bulk Partition for now so that Auto will map to bulk-splitting of all components
552 if (dset->numEntries()<10) {
553 //cout << "RAT::initSim("<< GetName() << ") MP mode is auto, setting split mode for component "<< n << " to SimComponents"<< endl ;
556 } else {
557 //cout << "RAT::initSim("<< GetName() << ") MP mode is auto, setting split mode for component "<< n << " to BulkPartition"<< endl ;
560 }
561 }
562
563 // Servers may have been redirected between instantiation and (deferred) initialization
564
565 RooArgSet *actualParams = binnedPdf ? binnedPdf->getParameters(dset) : pdf->getParameters(dset);
566 RooArgSet* selTargetParams = (RooArgSet*) _paramSet.selectCommon(*actualParams);
567
568 _gofArray[n]->recursiveRedirectServers(*selTargetParams);
569
570 delete selTargetParams;
571 delete actualParams;
572
573 ++n;
574
575 } else {
576 if ((!dset || (0. != dset->sumEntries() && !processEmptyDataSets())) && pdf) {
577 if (_verbose) {
578 ccoutD(Fitting) << "RooAbsTestStatistic::initSimMode: state " << catName
579 << " has no data entries, no slave calculator created" << endl;
580 }
581 }
582 }
583 }
584 coutI(Fitting) << "RooAbsTestStatistic::initSimMode: created " << n << " slave calculators." << endl;
585
586 dsetList->Delete(); // delete the content.
587 delete dsetList;
588}
589
590
591////////////////////////////////////////////////////////////////////////////////
592/// Change dataset that is used to given one. If cloneData is true, a clone of
593/// in the input dataset is made. If the test statistic was constructed with
594/// a range specification on the data, the cloneData argument is ignored and
595/// the data is always cloned.
596bool RooAbsTestStatistic::setData(RooAbsData& indata, bool cloneData)
597{
598 // Trigger refresh of likelihood offsets
599 if (isOffsetting()) {
600 enableOffsetting(false);
601 enableOffsetting(true);
602 }
603
604 switch(operMode()) {
605 case Slave:
606 // Delegate to implementation
607 return setDataSlave(indata, cloneData);
608 case SimMaster:
609 // Forward to slaves
610 if (indata.canSplitFast()) {
611 for (int i = 0; i < _nGof; ++i) {
612 RooAbsData* compData = indata.getSimData(_gofArray[i]->GetName());
613 _gofArray[i]->setDataSlave(*compData, cloneData);
614 }
615 } else if (0 == indata.numEntries()) {
616 // For an unsplit empty dataset, simply assign empty dataset to each component
617 for (int i = 0; i < _nGof; ++i) {
618 _gofArray[i]->setDataSlave(indata, cloneData);
619 }
620 } else {
621 const RooAbsCategoryLValue& indexCat = static_cast<RooSimultaneous*>(_func)->indexCat();
622 std::unique_ptr<TList> dlist{indata.split(indexCat, true)};
623 if (!dlist) {
624 coutF(DataHandling) << "Tried to split '" << indata.GetName() << "' into categories of '" << indexCat.GetName()
625 << "', but splitting failed. Input data:" << std::endl;
626 indata.Print("V");
627 throw std::runtime_error("Error when setting up test statistic: dataset couldn't be split into categories.");
628 }
629
630 for (int i = 0; i < _nGof; ++i) {
631 if (auto compData = static_cast<RooAbsData*>(dlist->FindObject(_gofArray[i]->GetName()))) {
632 _gofArray[i]->setDataSlave(*compData,false,true);
633 } else {
634 coutE(DataHandling) << "RooAbsTestStatistic::setData(" << GetName() << ") ERROR: Cannot find component data for state " << _gofArray[i]->GetName() << endl;
635 }
636 }
637 }
638 break;
639 case MPMaster:
640 // Not supported
641 coutF(DataHandling) << "RooAbsTestStatistic::setData(" << GetName() << ") FATAL: setData() is not supported in multi-processor mode" << endl;
642 throw std::runtime_error("RooAbsTestStatistic::setData is not supported in MPMaster mode");
643 break;
644 }
645
646 return true;
647}
648
649
650
652{
653 // Apply internal value offsetting to control numeric precision
654 if (!_init) {
655 const_cast<RooAbsTestStatistic*>(this)->initialize() ;
656 }
657
658 switch(operMode()) {
659 case Slave:
660 _doOffset = flag ;
661 // Clear offset if feature is disabled to that it is recalculated next time it is enabled
662 if (!_doOffset) {
663 _offset = 0 ;
664 }
665 setValueDirty() ;
666 break ;
667 case SimMaster:
668 _doOffset = flag;
669 for (Int_t i = 0; i < _nGof; ++i) {
670 _gofArray[i]->enableOffsetting(flag);
671 }
672 break ;
673 case MPMaster:
674 _doOffset = flag;
675 for (Int_t i = 0; i < _nCPU; ++i) {
677 }
678 break;
679 }
680}
681
682
684{ return _evalCarry; }
#define coutI(a)
Definition: RooMsgService.h:34
#define coutF(a)
Definition: RooMsgService.h:38
#define coutE(a)
Definition: RooMsgService.h:37
#define ccoutI(a)
Definition: RooMsgService.h:42
#define ccoutD(a)
Definition: RooMsgService.h:41
#define ClassImp(name)
Definition: Rtypes.h:375
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
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2447
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
Definition: RooAbsArg.cxx:1191
void SetName(const char *name) override
Set the name of the TNamed.
Definition: RooAbsArg.cxx:2311
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2189
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:508
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:301
RooArgSet * getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Definition: RooAbsArg.cxx:565
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:62
virtual double sumEntries() const =0
Return effective number of entries in dataset, i.e., sum all weights.
bool canSplitFast() const
RooAbsData * getSimData(const char *idxstate)
void Print(Option_t *options=0) const override
Print TNamed name and title.
Definition: RooAbsData.h:239
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Definition: RooAbsData.cxx:379
virtual TList * split(const RooAbsCategory &splitCat, bool createEmptyDataSets=false) const
Split dataset into subsets based on states of given splitCat in this dataset.
RooAbsOptTestStatistic is the abstract base class for test statistics objects that evaluate a functio...
TClass * IsA() const override
Definition: RooAbsPdf.h:400
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:64
virtual double getValV(const RooArgSet *normalisationSet=nullptr) const
Return value of object.
Definition: RooAbsReal.cxx:275
RooAbsTestStatistic is the 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
Int_t _nGof
Number of sub-contexts.
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 partioning of dataset for multiprocessor-split...
pRooAbsTestStatistic * _gofArray
! Array of sub-contexts representing part of the combined test statistic
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
ROOT::Math::KahanSum< double > _offset
! Offset as KahanSum to avoid loss of precision
void setSimCount(Int_t simCount)
Int_t _extSet
! Number of designated set to calculated extended term
bool initialize()
One-time initialization of the test statistic.
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?
std::vector< RooFit::MPSplit > _gofSplitMode
! GOF MP Split mode specified by component (when Auto is active)
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:57
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
RooAbsArg * next()
Return next element or nullptr if at end.
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:33
static TClass * Class()
RooRealMPFE is the multi-processor front-end for parallel calculation of RooAbsReal objects.
Definition: RooRealMPFE.h:30
void initialize()
Initialize the remote process and message passing pipes between current process and remote process.
void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTracking=true) override
Intercept call to optimize constant term in test statistics and forward it to object on server side.
double getValV(const RooArgSet *nset=0) const override
If value needs recalculation and calculation has not beed started with a call to calculate() start it...
virtual double getCarry() const
void enableOffsetting(bool flag) override
Control verbose messaging related to inter process communication on both client and server side.
void followAsSlave(RooRealMPFE &master)
Definition: RooRealMPFE.h:48
static TClass * Class()
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
const RooAbsCategoryLValue & indexCat() const
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4862
A doubly linked list.
Definition: TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition: TList.cxx:578
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
TClass * IsA() const override
Definition: TNamed.h:58
Basic string class.
Definition: TString.h:136
Double_t y[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
@ SimComponents
Definition: RooGlobalFunc.h:66
@ Interleave
Definition: RooGlobalFunc.h:66
@ BulkPartition
Definition: RooGlobalFunc.h:66
@ DataHandling
Definition: RooGlobalFunc.h:65
@ InputArguments
Definition: RooGlobalFunc.h:64
std::string rangeName
Stores the configuration parameters for RooAbsTestStatistic.
static uint64_t sum(uint64_t i)
Definition: Factory.cxx:2345