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