28using std::endl, std::vector;
53 if(
fNToys == 0 )
return nullptr;
59 RooCategory densityLabel(
"densityLabel",
"densityLabel" );
71 oocoutP(
nullptr,
Generation) << std::endl << std::endl <<
" GENERATING FROM nullptr DENSITY " << std::endl << std::endl;
78 RooRealVar reweight(
"reweight",
"reweight", 1.0 );
109 for(
int j=0; j < result->
numEntries(); j++ ) {
137 ooccoutE(
nullptr,
InputArguments) <<
"Cannot use multiple null densities and only ask for one weight." << std::endl;
142 ooccoutI(
nullptr,
InputArguments) <<
"No explicit null densities specified. Going to add one based on the given paramPoint and the global fPdf. ... but cannot do that inside const function." << std::endl;
149 ooccoutD(
nullptr,
InputArguments) <<
"Using given parameter point. Replaces snapshot for the only null currently defined." << std::endl;
155 vector<double> weights;
156 weights.push_back( weight );
158 vector<double> impNLLs;
160 vector<double> nullNLLs;
161 for(
unsigned int i=0; i <
fNullDensities.size(); i++ ) nullNLLs.push_back( 0.0 );
173 vector<double>& impNLLs,
181 ooccoutE(
nullptr,
InputArguments) <<
"Cannot use multiple null densities and only ask for one weight and NLL." << std::endl;
186 ooccoutI(
nullptr,
InputArguments) <<
"No explicit null densities specified. Going to add one based on the given paramPoint and the global fPdf. ... but cannot do that inside const function." << std::endl;
190 ooccoutI(
nullptr,
InputArguments) <<
"Using given parameter point. Overwrites snapshot for the only null currently defined." << std::endl;
195 vector<double> weights;
196 weights.push_back( weight );
198 vector<double> nullNLLs;
199 nullNLLs.push_back( nullNLL );
203 nullNLL = nullNLLs[0];
210 vector<double>& weights
213 ooccoutI(
nullptr,
InputArguments) <<
"weights.size() != nullDesnities.size(). You need to provide a vector with the correct size." << std::endl;
217 vector<double> impNLLs;
219 vector<double> nullNLLs;
220 for(
unsigned int i=0; i <
fNullDensities.size(); i++ ) nullNLLs.push_back( 0.0 );
234 vector<double>& weights,
235 vector<double>& impNLLVals,
236 vector<double>& nullNLLVals
249 oocoutE(
nullptr,
InputArguments) <<
"ToyMCImportanceSampler: Need to specify the null density explicitly." << std::endl;
262 oocoutE(
nullptr,
InputArguments) <<
"ToyMCImportanceSampler: Something wrong. NullNLLs must be of same size as null densities." << std::endl;
269 oocoutE(
nullptr,
InputArguments) <<
"ToyMCImportanceSampler: no importance density given or index out of range." << std::endl;
283 std::unique_ptr<RooArgSet> allVars{
fPdf->getVariables()};
284 allVars->assign(paramPoint);
303 allVars->add(*allVarsImpDens);
307 double globalWeight = 1.0;
317 RooArgSet allVarsMinusParamPoint(*allVars);
318 allVarsMinusParamPoint.
remove(paramPoint,
false,
true);
324 for(
unsigned int i=0; i < weights.size(); i++ ) weights[i] = globalWeight;
359 std::unique_ptr<RooArgSet> allParams{
fNullDensities[i]->getParameters(*data)};
373 vector<double> minNLLVals;
374 for(
unsigned int i=0; i < nullNLLVals.size(); i++ ) minNLLVals.push_back( nullNLLVals[i] );
388 fImpNLLs[i]->setData( *data,
false );
390 impNLLVals[i] =
fImpNLLs[i]->getVal();
394 for(
unsigned int j=0; j < nullNLLVals.size(); j++ ) {
395 if( impNLLVals[i] < minNLLVals[j] ) minNLLVals[j] = impNLLVals[i];
396 ooccoutD(
nullptr,
InputArguments) <<
"minNLLVals["<<j<<
"]: " << minNLLVals[j] <<
" nullNLLVals["<<j<<
"]: " << nullNLLVals[j] <<
" impNLLVals["<<i<<
"]: " << impNLLVals[i] << std::endl;
403 for(
unsigned int j=0; j < nullNLLVals.size(); j++ ) {
410 weights[j] *= exp(minNLLVals[j] - nullNLLVals[j]);
418 allVars->assign(*saveVars);
429 double impMaxMu = poi.
getVal();
437 oocoutI(
nullptr,
InputArguments) <<
"Using fitFavoredMu and error to set the number of imp points" << std::endl;
453 double impMaxMu = poi.
getVal();
456 if( impMaxMu > poiValueForBackground &&
n > 0 ) {
457 for(
int i=1; i <=
n; i++ ) {
458 poi.
setVal( poiValueForBackground + (
double)i/(
n)*(impMaxMu - poiValueForBackground) );
int Int_t
Signed integer 4 bytes (int).
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
Storage_t::size_type size() 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.
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
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.
bool setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
bool defineType(const std::string &label)
Define a state with given name.
Container class to hold unbinned data.
const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
virtual RooAbsArg * addColumn(RooAbsArg &var, bool adjustRange=true)
Add a column with the values of the given (function) argument to this dataset.
void add(const RooArgSet &row, double weight, double weightError)
Add one ore more rows of data.
double weight() const override
Return event weight of current event.
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
void AddImportanceDensity(RooAbsPdf *p, const RooArgSet *s)
For importance sampling with multiple densities/snapshots: This is used to check the current Likeliho...
std::vector< const RooArgSet * > fImportanceSnapshots
~ToyMCImportanceSampler() override
RooDataSet * GetSamplingDistributionsSingleWorker(RooArgSet ¶mPoint) override
overwrite GetSamplingDistributionsSingleWorker(paramPoint) with a version that loops over nulls and i...
RooAbsData * GenerateToyData(RooArgSet ¶mPoint, double &weight) const override
std::vector< const RooArgSet * > fNullSnapshots
void SetDensityToGenerateFromByIndex(unsigned int i, bool fromNull=false)
specifies the pdf to sample from
std::vector< RooAbsPdf * > fImportanceDensities
toysStrategies fToysStrategy
std::vector< std::unique_ptr< RooAbsReal > > fImpNLLs
!
std::vector< std::unique_ptr< RooAbsReal > > fNullNLLs
!
unsigned int fIndexGenDensity
int CreateImpDensitiesForOnePOIAdaptively(RooAbsPdf &pdf, const RooArgSet &allPOI, RooRealVar &poi, double nStdDevOverlap=0.5, double poiValueForBackground=0.0)
poi has to be fitted beforehand. This function expects this to be the muhat value.
void ClearCache() override
helper method for clearing the cache
RooArgSet fConditionalObs
set of conditional observables
std::vector< RooAbsPdf * > fNullDensities
support multiple null densities
int CreateNImpDensitiesForOnePOI(RooAbsPdf &pdf, const RooArgSet &allPOI, RooRealVar &poi, int n, double poiValueForBackground=0.0)
n is the number of importance densities
const RooArgSet * fGlobalObservables
virtual void GenerateGlobalObservables(RooAbsPdf &pdf) const
generate global observables
virtual RooDataSet * GetSamplingDistributionsSingleWorker(RooArgSet ¶mPoint)
This is the main function for serial runs.
NuisanceParametersSampler * fNuisanceParametersSampler
!
const RooArgSet * fObservables
std::unique_ptr< RooAbsData > Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooAbsData *protoData=nullptr, int forceEvents=0) const
helper for GenerateToyData
RooAbsPdf * fPdf
densities, snapshots, and test statistics to reweight to
bool fExpectedNuisancePar
whether to use expectation values for nuisance parameters (ie Asimov data set)
const RooArgSet * fNuisancePars
std::vector< TestStatistic * > fTestStatistics
Int_t fNToys
number of toys to generate
virtual void ClearCache()
helper method for clearing the cache
RooAbsPdf * fPriorNuisance
prior pdf for nuisance parameters
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
RooCmdArg WeightVar(const char *name="weight", bool reinterpretAsWeight=false)
RooCmdArg Constrain(const RooArgSet ¶ms)
RooCmdArg CloneData(bool flag)
RooCmdArg ConditionalObservables(Args_t &&... argsOrArgSet)
Create a RooCmdArg to declare conditional observables.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Namespace for the RooStats classes.
@ EXPONENTIALTOYDISTRIBUTION
Int_t CeilNint(Double_t x)
Returns the nearest integer of TMath::Ceil(x).