Skip to content

Commit fbb3468

Browse files
committed
allowing control of binned data via protodataset in hypotest calculator
1 parent 0ee05c5 commit fbb3468

File tree

8 files changed

+17
-11
lines changed

8 files changed

+17
-11
lines changed

roofit/roofitcore/inc/RooGlobalFunc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ RooCmdArg Conditional(const RooArgSet& pdfSet, const RooArgSet& depSet, bool dep
358358
* @{
359359
*/
360360
// RooAbsPdf::generate arguments
361-
RooCmdArg ProtoData(const RooDataSet& protoData, bool randomizeOrder=false, bool resample=false) ;
361+
RooCmdArg ProtoData(const RooAbsData& protoData, bool randomizeOrder=false, bool resample=false) ;
362362
RooCmdArg NumEvents(Int_t numEvents) ;
363363
RooCmdArg NumEvents(double numEvents) ;
364364
RooCmdArg AutoBinned(bool flag=true) ;

roofit/roofitcore/src/RooAbsPdf.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ RooAbsGenContext* RooAbsPdf::autoGenContext(const RooArgSet &vars, const RooData
11911191
/// as binned generation is always executed at the top-level node for a regular
11921192
/// PDF, so for those it only mattes that the top-level node is tagged.
11931193
///
1194-
/// <tr><td> ProtoData(const RooDataSet& data, bool randOrder)
1194+
/// <tr><td> ProtoData(const RooAbsData& data, bool randOrder)
11951195
/// <td> Use specified dataset as prototype dataset. If randOrder in ProtoData() is set to true,
11961196
/// the order of the events in the dataset will be read in a random order if the requested
11971197
/// number of events to be generated does not match the number of events in the prototype dataset.

roofit/roofitcore/src/RooBinnedGenContext.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ RooBinnedGenContext::RooBinnedGenContext(const RooAbsPdf &model, const RooArgSet
6060
if (prototype)
6161
{
6262
RooArgSet coefNSet(vars) ;
63-
coefNSet.add(*prototype->get()) ;
63+
coefNSet.add(*prototype->get(),true) ;
6464
_pdf->fixAddCoefNormalization(coefNSet) ;
6565
}
6666

roofit/roofitcore/src/RooGenContext.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ RooGenContext::RooGenContext(const RooAbsPdf &model, const RooArgSet &vars,
8787
// Optionally fix RooAddPdf normalizations
8888
if (prototype&&_pdfClone->dependsOn(*prototype->get())) {
8989
RooArgSet fullNormSet(vars) ;
90-
fullNormSet.add(*prototype->get()) ;
90+
fullNormSet.add(*prototype->get(),true) ;
9191
_pdfClone->fixAddCoefNormalization(fullNormSet) ;
9292
}
9393

roofit/roofitcore/src/RooGlobalFunc.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, bool dep
798798
};
799799

800800
// RooAbsPdf::generate arguments
801-
RooCmdArg ProtoData(const RooDataSet &protoData, bool randomizeOrder, bool resample)
801+
RooCmdArg ProtoData(const RooAbsData &protoData, bool randomizeOrder, bool resample)
802802
{
803803
return RooCmdArg("PrototypeData", randomizeOrder, resample, 0, 0, nullptr, nullptr, &protoData, nullptr);
804804
}

roofit/roostats/inc/RooStats/ToyMCSampler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ class ToyMCSampler: public TestStatSampler {
229229
fAdaptiveLowLimit = low_threshold;
230230
}
231231

232-
void SetProtoData(const RooDataSet* d) { fProtoData = d; }
232+
void SetProtoData(const RooAbsData* d) { fProtoData = d; }
233233

234234
protected:
235235

236236
const RooArgList* EvaluateAllTestStatistics(RooAbsData& data, const RooArgSet& poi, DetailedOutputAggregator& detOutAgg);
237237

238238
/// helper for GenerateToyData
239-
std::unique_ptr<RooAbsData> Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet *protoData=nullptr, int forceEvents=0) const;
239+
std::unique_ptr<RooAbsData> Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooAbsData *protoData=nullptr, int forceEvents=0) const;
240240

241241
/// helper method for clearing the cache
242242
virtual void ClearCache();
@@ -272,7 +272,7 @@ class ToyMCSampler: public TestStatSampler {
272272
double fAdaptiveLowLimit;
273273
double fAdaptiveHighLimit;
274274

275-
const RooDataSet *fProtoData = nullptr; ///< in dev
275+
const RooAbsData *fProtoData = nullptr; ///< in dev
276276

277277
mutable NuisanceParametersSampler *fNuisanceParametersSampler = nullptr; ///<!
278278

roofit/roostats/src/HypoTestCalculatorGeneric.cxx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ HypoTestCalculatorGeneric::HypoTestCalculatorGeneric(
6363
*altModel.GetPdf(),
6464
altModel.GetSnapshot());
6565

66-
fDefaultSampler = new ToyMCSampler(*fDefaultTestStat, 1000);
67-
fTestStatSampler = fDefaultSampler;
66+
auto toymcs = new ToyMCSampler(*fDefaultTestStat, 1000);
67+
// --- Ensure the ToyMCSampler generates toys with the same structure as the observed data
68+
toymcs->SetProtoData(&data);
69+
const bool dataIsBinned = dynamic_cast<const RooDataHist*>(fData) != nullptr;
70+
toymcs->SetGenerateBinned(dataIsBinned); // if observed is RooDataHist -> generate RooDataHist toys
71+
72+
fDefaultSampler = toymcs;
73+
fTestStatSampler = toymcs;
6874
}
6975

7076

roofit/roostats/src/ToyMCSampler.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ RooAbsData* ToyMCSampler::GenerateToyData(RooArgSet& paramPoint, double& weight,
476476
/// or whether it should use the expected number of events. It also takes
477477
/// into account the option to generate a binned data set (*i.e.* RooDataHist).
478478

479-
std::unique_ptr<RooAbsData> ToyMCSampler::Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet* protoData, int forceEvents) const {
479+
std::unique_ptr<RooAbsData> ToyMCSampler::Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooAbsData* protoData, int forceEvents) const {
480480

481481
if(fProtoData) {
482482
protoData = fProtoData;

0 commit comments

Comments
 (0)