Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/// Default constructor
64
66 _func(0), _data(0), _projDeps(0), _splitRange(0), _simCount(0),
67 _verbose(kFALSE), _init(kFALSE), _gofOpMode(Slave), _nEvents(0), _setNum(0),
68 _numSets(0), _extSet(0), _nGof(0), _gofArray(0), _nCPU(1), _mpfeArray(0),
69 _mpinterl(RooFit::BulkPartition), _doOffset(kFALSE), _offset(0),
70 _offsetCarry(0), _evalCarry(0)
71{
72}
73
74
75
76////////////////////////////////////////////////////////////////////////////////
77/// Create a test statistic from the given function and the data.
78/// \param[in] name Name of the test statistic
79/// \param[in] title Title (for plotting)
80/// \param[in] real Function to be used for tests
81/// \param[in] data Data to fit function to
82/// \param[in] projDeps A set of projected observables
83/// \param[in] rangeName Fit data only in range with given name
84/// \param[in] addCoefRangeName If not null, all RooAddPdf components of `real` will be instructed to fix their fraction definitions to the given named range.
85/// \param[in] nCPU If larger than one, the test statistic calculation will be parallelized over multiple processes.
86/// By default the data is split with 'bulk' partitioning (each process calculates a contigious block of fraction 1/nCPU
87/// of the data). For binned data this approach may be suboptimal as the number of bins with >0 entries
88/// in each processing block many vary greatly thereby distributing the workload rather unevenly.
89/// \param[in] interleave is set to true, the interleave partitioning strategy is used where each partition
90/// i takes all bins for which (ibin % ncpu == i) which is more likely to result in an even workload.
91/// \param[in] verbose Be more verbose.
92/// \param[in] splitCutRange If true, a different rangeName constructed as rangeName_{catName} will be used
93/// as range definition for each index state of a RooSimultaneous. This means that a different range can be defined
94/// for each category such as
95/// ```
96/// myVariable.setRange("range_pi0", 135, 210);
97/// myVariable.setRange("range_gamma", 50, 210);
98/// ```
99/// if the categories are called "pi0" and "gamma".
100
101RooAbsTestStatistic::RooAbsTestStatistic(const char *name, const char *title, RooAbsReal& real, RooAbsData& data,
102 const RooArgSet& projDeps, const char* rangeName, const char* addCoefRangeName,
103 Int_t nCPU, RooFit::MPSplit interleave, Bool_t verbose, Bool_t splitCutRange) :
104 RooAbsReal(name,title),
105 _paramSet("paramSet","Set of parameters",this),
106 _func(&real),
107 _data(&data),
108 _projDeps((RooArgSet*)projDeps.Clone()),
109 _rangeName(rangeName?rangeName:""),
110 _addCoefRangeName(addCoefRangeName?addCoefRangeName:""),
111 _splitRange(splitCutRange),
112 _simCount(1),
113 _verbose(verbose),
114 _nGof(0),
115 _gofArray(0),
116 _nCPU(nCPU),
117 _mpfeArray(0),
118 _mpinterl(interleave),
119 _doOffset(kFALSE),
120 _offset(0),
121 _offsetCarry(0),
122 _evalCarry(0)
123{
124 // Register all parameters as servers
125 RooArgSet* params = real.getParameters(&data) ;
126 _paramSet.add(*params) ;
127 delete params ;
128
129 if (_nCPU>1 || _nCPU==-1) {
130
131 if (_nCPU==-1) {
132 _nCPU=1 ;
133 }
134
136
137 } else {
138
139 // Determine if RooAbsReal is a RooSimultaneous
140 Bool_t simMode = dynamic_cast<RooSimultaneous*>(&real)?kTRUE:kFALSE ;
141
142 if (simMode) {
144 } else {
145 _gofOpMode = Slave ;
146 }
147 }
148
149 _setNum = 0 ;
150 _extSet = 0 ;
151 _numSets = 1 ;
152 _init = kFALSE ;
153 _nEvents = data.numEntries() ;
154}
155
156
157
158////////////////////////////////////////////////////////////////////////////////
159/// Copy constructor
160
162 RooAbsReal(other,name),
163 _paramSet("paramSet","Set of parameters",this),
164 _func(other._func),
165 _data(other._data),
166 _projDeps((RooArgSet*)other._projDeps->Clone()),
167 _rangeName(other._rangeName),
168 _addCoefRangeName(other._addCoefRangeName),
169 _splitRange(other._splitRange),
170 _simCount(1),
171 _verbose(other._verbose),
172 _nGof(0),
173 _gofArray(0),
174 _gofSplitMode(other._gofSplitMode),
175 _nCPU(other._nCPU),
176 _mpfeArray(0),
177 _mpinterl(other._mpinterl),
178 _doOffset(other._doOffset),
179 _offset(other._offset),
180 _offsetCarry(other._offsetCarry),
181 _evalCarry(other._evalCarry)
182{
183 // Our parameters are those of original
184 _paramSet.add(other._paramSet) ;
185
186 if (_nCPU>1 || _nCPU==-1) {
187
188 if (_nCPU==-1) {
189 _nCPU=1 ;
190 }
191
193
194 } else {
195
196 // Determine if RooAbsReal is a RooSimultaneous
197 Bool_t simMode = dynamic_cast<RooSimultaneous*>(_func)?kTRUE:kFALSE ;
198
199 if (simMode) {
201 } else {
202 _gofOpMode = Slave ;
203 }
204 }
205
206 _setNum = 0 ;
207 _extSet = 0 ;
208 _numSets = 1 ;
209 _init = kFALSE ;
211
212
213}
214
215
216
217////////////////////////////////////////////////////////////////////////////////
218/// Destructor
219
221{
222 if (MPMaster == _gofOpMode && _init) {
223 for (Int_t i = 0; i < _nCPU; ++i) delete _mpfeArray[i];
224 delete[] _mpfeArray ;
225 }
226
227 if (SimMaster == _gofOpMode && _init) {
228 for (Int_t i = 0; i < _nGof; ++i) delete _gofArray[i];
229 delete[] _gofArray ;
230 }
231
232 delete _projDeps ;
233
234}
235
236
237
238////////////////////////////////////////////////////////////////////////////////
239/// Calculate and return value of test statistic. If the test statistic
240/// is calculated from a RooSimultaneous, the test statistic calculation
241/// is performed separately on each simultaneous p.d.f component and associated
242/// data, and then combined. If the test statistic calculation is parallelized,
243/// partitions are calculated in nCPU processes and combined a posteriori.
244
246{
247 // One-time Initialization
248 if (!_init) {
249 const_cast<RooAbsTestStatistic*>(this)->initialize() ;
250 }
251
252 if (SimMaster == _gofOpMode) {
253 // Evaluate array of owned GOF objects
254 Double_t ret = 0.;
255
258 } else {
259 Double_t sum = 0., carry = 0.;
260 for (Int_t i = 0 ; i < _nGof; ++i) {
262 Double_t y = _gofArray[i]->getValV();
263 carry += _gofArray[i]->getCarry();
264 y -= carry;
265 const Double_t t = sum + y;
266 carry = (t - sum) - y;
267 sum = t;
268 }
269 }
270 ret = sum ;
271 _evalCarry = carry;
272 }
273
274 // Only apply global normalization if SimMaster doesn't have MP master
275 if (numSets()==1) {
276 const Double_t norm = globalNormalization();
277 ret /= norm;
278 _evalCarry /= norm;
279 }
280
281 return ret ;
282
283 } else if (MPMaster == _gofOpMode) {
284
285 // Start calculations in parallel
286 for (Int_t i = 0; i < _nCPU; ++i) _mpfeArray[i]->calculate();
287
288
289 Double_t sum(0), carry = 0.;
290 for (Int_t i = 0; i < _nCPU; ++i) {
292 carry += _mpfeArray[i]->getCarry();
293 y -= carry;
294 const Double_t t = sum + y;
295 carry = (t - sum) - y;
296 sum = t;
297 }
298
299 Double_t ret = sum ;
300 _evalCarry = carry;
301 return ret ;
302
303 } else {
304
305 // Evaluate as straight FUNC
306 Int_t nFirst(0), nLast(_nEvents), nStep(1) ;
307
308 switch (_mpinterl) {
310 nFirst = _nEvents * _setNum / _numSets ;
311 nLast = _nEvents * (_setNum+1) / _numSets ;
312 nStep = 1 ;
313 break;
314
316 nFirst = _setNum ;
317 nLast = _nEvents ;
318 nStep = _numSets ;
319 break ;
320
322 nFirst = 0 ;
323 nLast = _nEvents ;
324 nStep = 1 ;
325 break ;
326
327 case RooFit::Hybrid:
328 throw std::logic_error("this should never happen");
329 break ;
330 }
331
332 Double_t ret = evaluatePartition(nFirst,nLast,nStep);
333
334 if (numSets()==1) {
335 const Double_t norm = globalNormalization();
336 ret /= norm;
337 _evalCarry /= norm;
338 }
339
340 return ret ;
341
342 }
343}
344
345
346
347////////////////////////////////////////////////////////////////////////////////
348/// One-time initialization of the test statistic. Setup
349/// infrastructure for simultaneous p.d.f processing and/or
350/// parallelized processing if requested
351
353{
354 if (_init) return kFALSE;
355
356 if (MPMaster == _gofOpMode) {
358 } else if (SimMaster == _gofOpMode) {
360 }
361 _init = kTRUE;
362 return kFALSE;
363}
364
365
366
367////////////////////////////////////////////////////////////////////////////////
368/// Forward server redirect calls to component test statistics
369
370Bool_t RooAbsTestStatistic::redirectServersHook(const RooAbsCollection& newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t)
371{
372 if (SimMaster == _gofOpMode && _gofArray) {
373 // Forward to slaves
374 for (Int_t i = 0; i < _nGof; ++i) {
375 if (_gofArray[i]) {
376 _gofArray[i]->recursiveRedirectServers(newServerList,mustReplaceAll,nameChange);
377 }
378 }
379 } else if (MPMaster == _gofOpMode&& _mpfeArray) {
380 // Forward to slaves
381 for (Int_t i = 0; i < _nCPU; ++i) {
382 if (_mpfeArray[i]) {
383 _mpfeArray[i]->recursiveRedirectServers(newServerList,mustReplaceAll,nameChange);
384// cout << "redirecting servers on " << _mpfeArray[i]->GetName() << endl;
385 }
386 }
387 }
388 return kFALSE;
389}
390
391
392
393////////////////////////////////////////////////////////////////////////////////
394/// Add extra information on component test statistics when printing
395/// itself as part of a tree structure
396
398{
399 if (SimMaster == _gofOpMode) {
400 // Forward to slaves
401 os << indent << "RooAbsTestStatistic begin GOF contents" << endl ;
402 for (Int_t i = 0; i < _nGof; ++i) {
403 if (_gofArray[i]) {
404 TString indent2(indent);
405 indent2 += Form("[%d] ",i);
406 _gofArray[i]->printCompactTreeHook(os,indent2);
407 }
408 }
409 os << indent << "RooAbsTestStatistic end GOF contents" << endl;
410 } else if (MPMaster == _gofOpMode) {
411 // WVE implement this
412 }
413}
414
415
416
417////////////////////////////////////////////////////////////////////////////////
418/// Forward constant term optimization management calls to component
419/// test statistics
420
422{
423 initialize();
424 if (SimMaster == _gofOpMode) {
425 // Forward to slaves
426 for (Int_t i = 0; i < _nGof; ++i) {
427 // In SimComponents Splitting strategy only constOptimize the terms that are actually used
429 if ( (i % _numSets == _setNum) || (effSplit != RooFit::SimComponents) ) {
430 if (_gofArray[i]) _gofArray[i]->constOptimizeTestStatistic(opcode,doAlsoTrackingOpt);
431 }
432 }
433 } else if (MPMaster == _gofOpMode) {
434 for (Int_t i = 0; i < _nCPU; ++i) {
435 _mpfeArray[i]->constOptimizeTestStatistic(opcode,doAlsoTrackingOpt);
436 }
437 }
438}
439
440
441
442////////////////////////////////////////////////////////////////////////////////
443/// Set MultiProcessor set number identification of this instance
444
446{
447 _setNum = inSetNum; _numSets = inNumSets;
449
450 if (SimMaster == _gofOpMode) {
451 // Forward to slaves
452 initialize();
453 for (Int_t i = 0; i < _nGof; ++i) {
454 if (_gofArray[i]) _gofArray[i]->setMPSet(inSetNum,inNumSets);
455 }
456 }
457}
458
459
460
461////////////////////////////////////////////////////////////////////////////////
462/// Initialize multi-processor calculation mode. Create component test statistics in separate
463/// processed that are connected to this process through a RooAbsRealMPFE front-end class.
464
465void RooAbsTestStatistic::initMPMode(RooAbsReal* real, RooAbsData* data, const RooArgSet* projDeps, const char* rangeName, const char* addCoefRangeName)
466{
468
469 // Create proto-goodness-of-fit
470 RooAbsTestStatistic* gof = create(GetName(),GetTitle(),*real,*data,*projDeps,rangeName,addCoefRangeName,1,_mpinterl,_verbose,_splitRange);
472
473 for (Int_t i = 0; i < _nCPU; ++i) {
474 gof->setMPSet(i,_nCPU);
475 gof->SetName(Form("%s_GOF%d",GetName(),i));
476 gof->SetTitle(Form("%s_GOF%d",GetTitle(),i));
477
478 ccoutD(Eval) << "RooAbsTestStatistic::initMPMode: starting remote server process #" << i << endl;
479 _mpfeArray[i] = new RooRealMPFE(Form("%s_%lx_MPFE%d",GetName(),(ULong_t)this,i),Form("%s_%lx_MPFE%d",GetTitle(),(ULong_t)this,i),*gof,false);
480 //_mpfeArray[i]->setVerbose(kTRUE,kTRUE);
482 if (i > 0) {
484 }
485 }
487 coutI(Eval) << "RooAbsTestStatistic::initMPMode: started " << _nCPU << " remote server process." << endl;
488 //cout << "initMPMode --- done" << endl ;
489 return ;
490}
491
492
493
494////////////////////////////////////////////////////////////////////////////////
495/// Initialize simultaneous p.d.f processing mode. Strip simultaneous
496/// p.d.f into individual components, split dataset in subset
497/// matching each component and create component test statistics for
498/// each of them.
499
501 const RooArgSet* projDeps, const char* rangeName, const char* addCoefRangeName)
502{
503
504 RooAbsCategoryLValue& simCat = const_cast<RooAbsCategoryLValue&>(simpdf->indexCat());
505
506 TString simCatName(simCat.GetName());
507 TList* dsetList = const_cast<RooAbsData*>(data)->split(simCat,processEmptyDataSets());
508 if (!dsetList) {
509 coutE(Fitting) << "RooAbsTestStatistic::initSimMode(" << GetName() << ") ERROR: index category of simultaneous pdf is missing in dataset, aborting" << endl;
510 throw std::runtime_error("RooAbsTestStatistic::initSimMode() ERROR, index category of simultaneous pdf is missing in dataset, aborting");
511 }
512
513 // Count number of used states
514 Int_t n = 0;
515 _nGof = 0;
516
517 for (const auto& catState : simCat) {
518 // Retrieve the PDF for this simCat state
519 RooAbsPdf* pdf = simpdf->getPdf(catState.first.c_str());
520 RooAbsData* dset = (RooAbsData*) dsetList->FindObject(catState.first.c_str());
521
522 if (pdf && dset && (0. != dset->sumEntries() || processEmptyDataSets())) {
523 ++_nGof;
524 }
525 }
526
527 // Allocate arrays
529 _gofSplitMode.resize(_nGof);
530
531 // Create array of regular fit contexts, containing subset of data and single fitCat PDF
532 for (const auto& catState : simCat) {
533 const std::string& catName = catState.first;
534 // Retrieve the PDF for this simCat state
535 RooAbsPdf* pdf = simpdf->getPdf(catName.c_str());
536 RooAbsData* dset = (RooAbsData*) dsetList->FindObject(catName.c_str());
537
538 if (pdf && dset && (0. != dset->sumEntries() || processEmptyDataSets())) {
539 ccoutI(Fitting) << "RooAbsTestStatistic::initSimMode: creating slave calculator #" << n << " for state " << catName
540 << " (" << dset->numEntries() << " dataset entries)" << endl;
541
542
543 // *** START HERE
544 // WVE HACK determine if we have a RooRealSumPdf and then treat it like a binned likelihood
545 RooAbsPdf* binnedPdf = 0 ;
546 Bool_t binnedL = kFALSE ;
547 if (pdf->getAttribute("BinnedLikelihood") && pdf->IsA()->InheritsFrom(RooRealSumPdf::Class())) {
548 // Simplest case: top-level of component is a RRSP
549 binnedPdf = pdf ;
550 binnedL = kTRUE ;
551 } else if (pdf->IsA()->InheritsFrom(RooProdPdf::Class())) {
552 // Default case: top-level pdf is a product of RRSP and other pdfs
553 RooFIter iter = ((RooProdPdf*)pdf)->pdfList().fwdIterator() ;
554 RooAbsArg* component ;
555 while ((component = iter.next())) {
556 if (component->getAttribute("BinnedLikelihood") && component->IsA()->InheritsFrom(RooRealSumPdf::Class())) {
557 binnedPdf = (RooAbsPdf*) component ;
558 binnedL = kTRUE ;
559 }
560 if (component->getAttribute("MAIN_MEASUREMENT")) {
561 // not really a binned pdf, but this prevents a (potentially) long list of subsidiary measurements to be passed to the slave calculator
562 binnedPdf = (RooAbsPdf*) component ;
563 }
564 }
565 }
566 // WVE END HACK
567 // Below here directly pass binnedPdf instead of PROD(binnedPdf,constraints) as constraints are evaluated elsewhere anyway
568 // and omitting them reduces model complexity and associated handling/cloning times
569 if (_splitRange && rangeName) {
570 _gofArray[n] = create(catName.c_str(), catName.c_str(),(binnedPdf?*binnedPdf:*pdf),*dset,*projDeps,
571 Form("%s_%s",rangeName,catName.c_str()),addCoefRangeName,_nCPU*(_mpinterl?-1:1),_mpinterl,_verbose,_splitRange,binnedL);
572 } else {
573 _gofArray[n] = create(catName.c_str(),catName.c_str(),(binnedPdf?*binnedPdf:*pdf),*dset,*projDeps,
574 rangeName,addCoefRangeName,_nCPU,_mpinterl,_verbose,_splitRange,binnedL);
575 }
577 // *** END HERE
578
579 // Fill per-component split mode with Bulk Partition for now so that Auto will map to bulk-splitting of all components
581 if (dset->numEntries()<10) {
582 //cout << "RAT::initSim("<< GetName() << ") MP mode is auto, setting split mode for component "<< n << " to SimComponents"<< endl ;
585 } else {
586 //cout << "RAT::initSim("<< GetName() << ") MP mode is auto, setting split mode for component "<< n << " to BulkPartition"<< endl ;
589 }
590 }
591
592 // Servers may have been redirected between instantiation and (deferred) initialization
593
594 RooArgSet *actualParams = binnedPdf ? binnedPdf->getParameters(dset) : pdf->getParameters(dset);
595 RooArgSet* selTargetParams = (RooArgSet*) _paramSet.selectCommon(*actualParams);
596
597 _gofArray[n]->recursiveRedirectServers(*selTargetParams);
598
599 delete selTargetParams;
600 delete actualParams;
601
602 ++n;
603
604 } else {
605 if ((!dset || (0. != dset->sumEntries() && !processEmptyDataSets())) && pdf) {
606 if (_verbose) {
607 ccoutD(Fitting) << "RooAbsTestStatistic::initSimMode: state " << catName
608 << " has no data entries, no slave calculator created" << endl;
609 }
610 }
611 }
612 }
613 coutI(Fitting) << "RooAbsTestStatistic::initSimMode: created " << n << " slave calculators." << endl;
614
615 dsetList->Delete(); // delete the content.
616 delete dsetList;
617}
618
619
620////////////////////////////////////////////////////////////////////////////////
621/// Change dataset that is used to given one. If cloneData is kTRUE, a clone of
622/// in the input dataset is made. If the test statistic was constructed with
623/// a range specification on the data, the cloneData argument is ignored and
624/// the data is always cloned.
626{
627 // Trigger refresh of likelihood offsets
628 if (isOffsetting()) {
631 }
632
633 switch(operMode()) {
634 case Slave:
635 // Delegate to implementation
636 return setDataSlave(indata, cloneData);
637 case SimMaster:
638 // Forward to slaves
639 // cout << "RATS::setData(" << GetName() << ") SimMaster, calling setDataSlave() on slave nodes" << endl;
640 if (indata.canSplitFast()) {
641 for (Int_t i = 0; i < _nGof; ++i) {
642 RooAbsData* compData = indata.getSimData(_gofArray[i]->GetName());
643 _gofArray[i]->setDataSlave(*compData, cloneData);
644 }
645 } else if (0 == indata.numEntries()) {
646 // For an unsplit empty dataset, simply assign empty dataset to each component
647 for (Int_t i = 0; i < _nGof; ++i) {
648 _gofArray[i]->setDataSlave(indata, cloneData);
649 }
650 } else {
651 const RooAbsCategoryLValue& indexCat = static_cast<RooSimultaneous*>(_func)->indexCat();
652 TList* dlist = indata.split(indexCat, kTRUE);
653 if (!dlist) {
654 coutF(DataHandling) << "Tried to split '" << indata.GetName() << "' into categories of '" << indexCat.GetName()
655 << "', but splitting failed. Input data:" << std::endl;
656 indata.Print("V");
657 throw std::runtime_error("Error when setting up test statistic: dataset couldn't be split into categories.");
658 }
659
660 for (Int_t i = 0; i < _nGof; ++i) {
661 RooAbsData* compData = (RooAbsData*) dlist->FindObject(_gofArray[i]->GetName());
662 // cout << "component data for index " << _gofArray[i]->GetName() << " is " << compData << endl;
663 if (compData) {
664 _gofArray[i]->setDataSlave(*compData,kFALSE,kTRUE);
665 } else {
666 coutE(DataHandling) << "RooAbsTestStatistic::setData(" << GetName() << ") ERROR: Cannot find component data for state " << _gofArray[i]->GetName() << endl;
667 }
668 }
669 }
670 break;
671 case MPMaster:
672 // Not supported
673 coutF(DataHandling) << "RooAbsTestStatistic::setData(" << GetName() << ") FATAL: setData() is not supported in multi-processor mode" << endl;
674 throw std::runtime_error("RooAbsTestStatistic::setData is not supported in MPMaster mode");
675 break;
676 }
677
678 return kTRUE;
679}
680
681
682
684{
685 // Apply internal value offsetting to control numeric precision
686 if (!_init) {
687 const_cast<RooAbsTestStatistic*>(this)->initialize() ;
688 }
689
690 switch(operMode()) {
691 case Slave:
692 _doOffset = flag ;
693 // Clear offset if feature is disabled to that it is recalculated next time it is enabled
694 if (!_doOffset) {
695 _offset = 0 ;
696 _offsetCarry = 0;
697 }
698 setValueDirty() ;
699 break ;
700 case SimMaster:
701 _doOffset = flag;
702 for (Int_t i = 0; i < _nGof; ++i) {
703 _gofArray[i]->enableOffsetting(flag);
704 }
705 break ;
706 case MPMaster:
707 _doOffset = flag;
708 for (Int_t i = 0; i < _nCPU; ++i) {
710 }
711 break;
712 }
713}
714
715
717{ return _evalCarry; }
#define coutI(a)
#define coutF(a)
#define coutE(a)
#define ccoutI(a)
#define ccoutD(a)
const Bool_t kFALSE
Definition RtypesCore.h:92
unsigned long ULong_t
Definition RtypesCore.h:55
const Bool_t kTRUE
Definition RtypesCore.h:91
#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:72
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:508
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
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...
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.
void SetName(const char *name)
Set the name of the TNamed.
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.
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
Storage_t::size_type size() const
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:49
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:193
RooAbsData * getSimData(const char *idxstate)
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Bool_t canSplitFast() const
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:61
virtual Double_t getValV(const RooArgSet *normalisationSet=nullptr) const
Return value of object.
RooAbsTestStatistic is the abstract base class for all test statistics.
virtual Bool_t processEmptyDataSets() const
Int_t _nGof
Number of designated set to calculated extended term.
GOFOpMode operMode() const
void initSimMode(RooSimultaneous *pdf, RooAbsData *data, const RooArgSet *projDeps, const char *rangeName, const char *addCoefRangeName)
Initialize simultaneous p.d.f processing mode.
Int_t _nCPU
GOF MP Split mode specified by component (when Auto is active)
virtual RooAbsTestStatistic * create(const char *name, const char *title, RooAbsReal &real, RooAbsData &data, const RooArgSet &projDeps, const char *rangeName=0, const char *addCoefRangeName=0, Int_t nCPU=1, RooFit::MPSplit interleave=RooFit::BulkPartition, Bool_t verbose=kTRUE, Bool_t splitCutRange=kFALSE, Bool_t binnedL=kFALSE)=0
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
RooAbsTestStatistic()
Default constructor.
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
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
avoids loss of precision
void initMPMode(RooAbsReal *real, RooAbsData *data, const RooArgSet *projDeps, const char *rangeName, const char *addCoefRangeName)
Initialize multi-processor calculation mode.
std::vector< RooFit::MPSplit > _gofSplitMode
Array of sub-contexts representing part of the combined test statistic.
Double_t _offsetCarry
Offset.
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:29
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:37
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
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
@ SimComponents
@ BulkPartition
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345