104 for (
auto *myarg2 : static_range_cast<RooRealVar *>(*
fParams)) {
105 myarg2->setBins(nBins);
118 "Adjusted number of toys to number of bins of nuisance parameters: " <<
fNToys << endl;
150 : fSamplingDistName(
"SD"),
153 fAdaptiveLowLimit(-
RooNumber::infinity()),
154 fAdaptiveHighLimit(
RooNumber::infinity())
163 : fSamplingDistName(ts.GetVarName().Data()),
166 fAdaptiveLowLimit(-
RooNumber::infinity()),
167 fAdaptiveHighLimit(
RooNumber::infinity())
189 bool goodConfig =
true;
207 if (!allTS)
return nullptr;
215 std::unique_ptr<RooArgSet> allVars;
216 std::unique_ptr<RooArgSet> saveAll;
221 saveAll = std::make_unique<RooArgSet>();
222 allVars->snapshot(*saveAll);
238 allVars->assign(*saveAll);
248 oocoutW(
nullptr,
InputArguments) <<
"Multiple test statistics defined, but only one distribution will be returned." << endl;
255 if(
r ==
nullptr ||
r->numEntries() == 0) {
276 <<
"Bad COnfiguration in ToyMCSampler "
285 <<
"Adaptive sampling in ToyMCSampler is not supported for parallel runs."
296 toymcstudy.SetParamPoint(paramPointIn);
330 <<
"Bad COnfiguration in ToyMCSampler "
337 std::unique_ptr<RooArgSet> paramPoint{paramPointIn.
snapshot()};
339 std::unique_ptr<RooArgSet> saveAll{allVars->snapshot()};
346 double toysInTails = 0.0;
353 if ( i% 500 == 0 && i>0 ) {
362 double valueFirst = -999.0;
366 allVars->assign(*saveAll);
368 std::unique_ptr<RooAbsData> toydata{
GenerateToyData(*paramPoint, weight)};
371 if (std::none_of(toySet->
begin(), toySet->
end(),
372 [](
const RooAbsArg *arg) { return dynamic_cast<const RooAbsCategory *>(arg) != nullptr; })) {
374 <<
"ToyMCSampler: Generated toy data didn't contain a category variable, although"
375 " a simultaneous PDF is in use. To generate events for a simultaneous PDF, all components need to be"
376 " extended. Otherwise, the number of events to generate per component cannot be determined."
387 valueFirst = firstTS->getVal();
390 if(valueFirst != valueFirst) {
391 oocoutW(
nullptr,
Generation) <<
"skip: " << valueFirst <<
", " << weight << endl;
399 if(weight >= 0.) toysInTails += weight;
400 else toysInTails += 1.;
405 allVars->assign(*saveAll);
440 for (
int i=0; i < nCat; ++i){
441 channelCat.setIndex(i);
447 _obsList.emplace_back(std::move(globtmp));
453 for (
unsigned int i = 0; i <
_pdfList.size(); ++i) {
466 allVars->assign(*values);
487 allVars->assign(paramPoint);
494 oocoutI(
nullptr,
InputArguments) <<
"Cannot use multigen when nuisance parameters vary for every toy" << endl;
506 std::unique_ptr<RooArgSet> saveVars{allVars->snapshot()};
517 RooArgSet allVarsMinusParamPoint(*allVars);
518 allVarsMinusParamPoint.
remove(paramPoint,
false,
true);
532 allVars->assign(*saveVars);
551 std::unique_ptr<RooAbsData>
data;
552 int events = forceEvents;
583 <<
"ToyMCSampler: Error : pdf is not extended and number of events per toy is zero"
626 last->
Add(newSamples);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Common abstract base class for objects that represent a value and a "shape" in RooFit.
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
RooFit::OwningPtr< RooArgSet > getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expression tree)
Int_t numTypes(const char *=nullptr) const
Return number of types defined (in range named rangeName if rangeName!=nullptr)
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
Storage_t const & get() const
Const access to the underlying stl container.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
Storage_t::size_type size() const
RooAbsArg * first() const
TIterator end() and range-based for loops.")
Abstract base class for binned and unbinned datasets.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract interface for all probability density functions.
virtual double expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
GenSpec * prepareMultiGen(const RooArgSet &whatVars, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={})
Prepare GenSpec configuration object for efficient generation of multiple datasets from identical spe...
RooFit::OwningPtr< RooDataSet > generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={})
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
virtual RooFit::OwningPtr< RooDataSet > generateSimGlobal(const RooArgSet &whatVars, Int_t nEvents)
Special generator interface for generation of 'global observables' – for RooStats tools.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Object to represent discrete states.
Container class to hold unbinned data.
bool merge(RooDataSet *data1, RooDataSet *data2=nullptr, RooDataSet *data3=nullptr, RooDataSet *data4=nullptr, RooDataSet *data5=nullptr, RooDataSet *data6=nullptr)
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
Provides numeric constants used in RooFit.
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Variable that can be changed from the outside.
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooAbsPdf * getPdf(RooStringView catName) const
Return the p.d.f associated with the given index category name.
const RooAbsCategoryLValue & indexCat() const
This class is designed to aid in the construction of RooDataSets and RooArgSets, particularly those n...
void AppendArgSet(const RooAbsCollection *aset, TString prefix="")
For each variable in aset, prepend prefix to its name and add to the internal store.
RooDataSet * GetAsDataSet(TString name, TString title)
Returns all detailed output as a dataset.
const RooArgList * GetAsArgList() const
void CommitSet(double weight=1.0)
Commit to the result RooDataSet.
RooWorkspace & GetWorkspace(void) const
returns fWorkspace
Int_t GetNExperiments(void) const
return fNExperiments
const char * GetHost(void) const
returns fHost
bool GetShowGui(void) const
return fShowGui
This class simply holds a sampling distribution of some test statistic.
void Add(const SamplingDistribution *other)
merge two sampling distributions
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
ToyMCSampler is an implementation of the TestStatSampler interface.
const RooArgSet * fGlobalObservables
std::string fSamplingDistName
name of the model
virtual void GenerateGlobalObservables(RooAbsPdf &pdf) const
generate global observables
virtual RooDataSet * GetSamplingDistributionsSingleWorker(RooArgSet ¶mPoint)
This is the main function for serial runs.
std::unique_ptr< const RooArgSet > fParametersForTestStat
virtual SamplingDistribution * AppendSamplingDistribution(RooArgSet &allParameters, SamplingDistribution *last, Int_t additionalMC)
Extended interface to append to sampling distribution more samples.
NuisanceParametersSampler * fNuisanceParametersSampler
!
std::unique_ptr< RooAbsPdf::GenSpec > _gs4
! GenSpec #4
const RooArgSet * fObservables
double fAdaptiveHighLimit
double fToysInTails
minimum no of toys in tails for adaptive sampling (taking weights into account, therefore double) Def...
virtual RooArgList * EvaluateAllTestStatistics(RooAbsData &data, const RooArgSet &poi)
Evaluate all test statistics, returning result and any detailed output.
RooAbsPdf * fPdf
densities, snapshots, and test statistics to reweight to
SamplingDistribution * GetSamplingDistribution(RooArgSet ¶mPoint) override
main interface
std::unique_ptr< RooAbsPdf::GenSpec > _gs1
! GenSpec #1
virtual RooDataSet * GetSamplingDistributions(RooArgSet ¶mPoint)
Use for serial and parallel runs.
virtual void AddTestStatistic(TestStatistic *t=nullptr)
The pdf can be nullptr in which case the density from SetPdf() is used.
virtual RooAbsData * GenerateToyData(RooArgSet ¶mPoint, RooAbsPdf &pdf) const
generates toy data without weight
bool fExpectedNuisancePar
whether to use expectation values for nuisance parameters (ie Asimov data set)
bool fUseMultiGen
Use PrepareMultiGen?
std::unique_ptr< RooAbsPdf::GenSpec > _gs2
! GenSpec #2
const RooArgSet * fNuisancePars
std::unique_ptr< RooAbsPdf::GenSpec > _gs3
! GenSpec #3
std::vector< TestStatistic * > fTestStatistics
Int_t fNEvents
number of events per toy (may be ignored depending on settings)
ToyMCSampler()
Proof constructor. Do not use.
std::unique_ptr< RooArgSet > _allVars
!
std::unique_ptr< RooAbsData > Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet *protoData=nullptr, int forceEvents=0) const
helper for GenerateToyData
static void SetAlwaysUseMultiGen(bool flag)
std::vector< RooAbsPdf * > _pdfList
! We don't own those objects
Int_t fNToys
number of toys to generate
virtual void ClearCache()
helper method for clearing the cache
bool CheckConfig(void)
Checks for sufficient information to do a GetSamplingDistribution(...).
ProofConfig * fProofConfig
!
std::vector< std::unique_ptr< RooArgSet > > _obsList
!
static bool fgAlwaysUseMultiGen
Use PrepareMultiGen always.
double fMaxToys
maximum no of toys (taking weights into account, therefore double)
const RooDataSet * fProtoData
in dev
TString fGenerateBinnedTag
std::vector< std::unique_ptr< RooAbsPdf::GenSpec > > _gsList
!
RooAbsPdf * fPriorNuisance
prior pdf for nuisance parameters
ToyMCStudy is an implementation of RooAbsStudy for toy Monte Carlo sampling.
void SetToyMCSampler(ToyMCSampler &t)
Utility class to manage studies that consist of repeated applications of generate-and-fit operations ...
void runProof(Int_t nExperiments, const char *proofHost="", bool showGui=true)
Open PROOF-Lite session.
Persistable container for RooFit projects.
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
RooCmdArg Extended(bool flag=true)
RooCmdArg ProtoData(const RooDataSet &protoData, bool randomizeOrder=false, bool resample=false)
RooCmdArg AutoBinned(bool flag=true)
RooCmdArg NumEvents(Int_t numEvents)
RooCmdArg GenBinned(const char *tag)
RooCmdArg ExpectedData(bool flag=true)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Namespace for the RooStats classes.
void removeTopic(RooFit::MsgTopic oldTopic)