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