99 myarg2->setBins(nBins);
112 "Adjusted number of toys to number of bins of nuisance parameters: " <<
fNToys << std::endl;
169 bool goodConfig =
true;
187 if (!allTS)
return nullptr;
195 std::unique_ptr<RooArgSet> allVars;
196 std::unique_ptr<RooArgSet> saveAll;
198 allVars = std::unique_ptr<RooArgSet>{
fPdf->getVariables()};
201 saveAll = std::make_unique<RooArgSet>();
202 allVars->snapshot(*saveAll);
218 allVars->assign(*saveAll);
228 oocoutW(
nullptr,
InputArguments) <<
"Multiple test statistics defined, but only one distribution will be returned." << std::endl;
235 if(
r ==
nullptr ||
r->numEntries() == 0) {
236 oocoutW(
nullptr,
Generation) <<
"no sampling distribution generated" << std::endl;
265 <<
"Bad COnfiguration in ToyMCSampler "
272 std::unique_ptr<RooArgSet> paramPoint{paramPointIn.
snapshot()};
273 std::unique_ptr<RooArgSet> allVars{
fPdf->getVariables()};
274 std::unique_ptr<RooArgSet> saveAll{allVars->snapshot()};
281 double toysInTails = 0.0;
288 if ( i% 500 == 0 && i>0 ) {
297 double valueFirst = -999.0;
301 allVars->assign(*saveAll);
303 std::unique_ptr<RooAbsData> toydata{
GenerateToyData(*paramPoint, weight)};
305 const RooArgSet* toySet = toydata->get();
306 if (std::none_of(toySet->
begin(), toySet->
end(),
307 [](
const RooAbsArg *arg) { return dynamic_cast<const RooAbsCategory *>(arg) != nullptr; })) {
309 <<
"ToyMCSampler: Generated toy data didn't contain a category variable, although"
310 " a simultaneous PDF is in use. To generate events for a simultaneous PDF, all components need to be"
311 " extended. Otherwise, the number of events to generate per component cannot be determined."
322 valueFirst = firstTS->getVal();
325 if(valueFirst != valueFirst) {
326 oocoutW(
nullptr,
Generation) <<
"skip: " << valueFirst <<
", " << weight << std::endl;
334 if(weight >= 0.) toysInTails += weight;
335 else toysInTails += 1.;
340 allVars->assign(*saveAll);
375 for (
int i=0; i < nCat; ++i){
376 channelCat.setIndex(i);
382 _obsList.emplace_back(std::move(globtmp));
388 for (
unsigned int i = 0; i <
_pdfList.size(); ++i) {
401 allVars->assign(*values);
421 std::unique_ptr<RooArgSet> allVars{
fPdf->getVariables()};
422 allVars->assign(paramPoint);
429 oocoutI(
nullptr,
InputArguments) <<
"Cannot use multigen when nuisance parameters vary for every toy" << std::endl;
441 std::unique_ptr<RooArgSet> saveVars{allVars->snapshot()};
452 RooArgSet allVarsMinusParamPoint(*allVars);
453 allVarsMinusParamPoint.
remove(paramPoint,
false,
true);
467 allVars->assign(*saveVars);
486 std::unique_ptr<RooAbsData> data;
487 int events = forceEvents;
495 std::stringstream ss;
496 ss <<
"ToyMCSampler: Error : pdf is not extended and number of events per toy is zero";
498 throw std::runtime_error(ss.str());
507 data = std::unique_ptr<RooDataSet>{pdf.
generate(*
_gs2)};
514 data = std::unique_ptr<RooDataSet>{pdf.
generate(*
_gs1)};
525 if(protoData) data = std::unique_ptr<RooDataSet>{pdf.
generate(observables, events,
AllBinned(),
ProtoData(*protoData,
true,
true))};
526 else data = std::unique_ptr<RooDataSet>{pdf.
generate(observables, events,
AllBinned())};
531 data = std::unique_ptr<RooDataSet>{pdf.
generate(*
_gs3)};
538 data = std::unique_ptr<RooDataSet>{pdf.
generate(*
_gs4)};
562 last->
Add(newSamples);
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
int Int_t
Signed integer 4 bytes (int).
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.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
const_iterator end() const
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
const_iterator begin() const
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.
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
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.
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...
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.
const RooAbsData * fProtoData
in dev
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
std::unique_ptr< RooAbsData > Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooAbsData *protoData=nullptr, int forceEvents=0) const
helper for GenerateToyData
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.
ToyMCSampler(TestStatistic &ts, Int_t ntoys)
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)
double fAdaptiveLowLimit
tails
std::unique_ptr< RooArgSet > _allVars
!
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(...).
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)
TString fGenerateBinnedTag
std::vector< std::unique_ptr< RooAbsPdf::GenSpec > > _gsList
!
RooAbsPdf * fPriorNuisance
prior pdf for nuisance parameters
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 AutoBinned(bool flag=true)
RooCmdArg NumEvents(Int_t numEvents)
RooCmdArg GenBinned(const char *tag)
RooCmdArg ProtoData(const RooAbsData &protoData, bool randomizeOrder=false, bool resample=false)
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)