RooStats Model Inspector.
Usage: The usage is the same as the StandardXxxDemo.C macros. The macro expects a root file containing a workspace with a ModelConfig and a dataset
Drag the sliders to adjust the parameters of the model. the min and max range of the sliders are used to define the upper & lower variation the pointer position of the slider is the central blue curve.
#include <map>
enum ETestCommandIdentifiers {
HId1,
HId2,
HId3,
HCId1,
HCId2,
HSId1
};
using std::map, std::vector, std::cout, std::endl;
private:
public:
~ModelInspectorGUI() override;
void DoText(
const char *
text);
void DoSlider();
void DoSlider(const char *);
void DoFit();
void DoExit();
void HandleButtons();
};
{
fWS = w;
fMC = mc;
fData = data;
if (strcmp(fMC->GetPdf()->ClassName(), "RooSimultaneous") == 0) {
cout << "Is a simultaneous PDF" << endl;
cout <<
" with " << channelCat->
numTypes() <<
" categories" << endl;
} else {
cout << "Is not a simultaneous PDF" << endl;
}
fFitRes = nullptr;
AddFrame(fCanvas, fLcan);
fPlotList.resize(numCats);
if (numCats > 1) {
fCanvas->GetCanvas()->Divide(numCats);
for (int i = 0; i < numCats; ++i) {
fCanvas->GetCanvas()->cd(i + 1)->SetBorderMode(0);
fCanvas->GetCanvas()->cd(i + 1)->SetGrid();
}
}
fCheck1->SetToolTipText("Pointer position constrained to slider sides");
fCheck2->SetToolTipText("Pointer position relative to slider position");
fHframe0->Resize(200, 50);
fFitButton->Connect("Clicked()", "ModelInspectorGUI", this, "DoFit()");
fExitButton->Connect("Clicked()", "ModelInspectorGUI", this, "DoExit()");
fCheck1->Connect("Clicked()", "ModelInspectorGUI", this, "HandleButtons()");
fCheck2->Connect("Clicked()", "ModelInspectorGUI", this, "HandleButtons()");
fHframe2->Resize(100, 25);
fHframe2->AddFrame(fFitButton, fBfly2);
fHframe2->AddFrame(fExitButton, fBfly3);
AddFrame(fHframe0, fBly);
AddFrame(fHframe2, fBly);
parameters.
add(*fMC->GetParametersOfInterest());
parameters.
add(*fMC->GetNuisanceParameters());
fCan->SetContainer(fVFrame);
cout << "Adding Slider for " << param->GetName() << endl;
new TGLabel(hframek,
Form(
"%s = %.3f +%.3f", param->GetName(), param->getVal(), param->getError()));
GetDefaultFrameBackground(), false, false, false, false);
hsliderk->
Connect(
"PointerPositionChanged()",
"ModelInspectorGUI",
this,
"DoSlider()");
hsliderk->
Connect(
"PositionChanged()",
"ModelInspectorGUI",
this,
"DoSlider()");
hsliderk->
SetRange(param->getMin(), param->getMax());
fSliderList.Add(hsliderk);
fFrameList.Add(hframek);
hsliderk->
SetPosition(param->getVal() - param->getError(), param->getVal() + param->getError());
fVFrame->AddFrame(hframek, fBly);
fSliderMap[hsliderk] = param->GetName();
fLabelMap[hsliderk] = hlabel;
}
SetWindowName("RooFit/RooStats Model Inspector");
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
DoSlider();
}
ModelInspectorGUI::~ModelInspectorGUI()
{
Cleanup();
}
void ModelInspectorGUI::CloseWindow()
{
delete this;
}
void ModelInspectorGUI::DoText(const char * )
{
switch (id) {
case HId1: fHslider1->SetPosition(atof(fTbh1->GetString()), static_cast<double>(fHslider1->GetMaxPosition())); break;
case HId2: fHslider1->SetPointerPosition(atof(fTbh2->GetString())); break;
case HId3: fHslider1->SetPosition(static_cast<double>(fHslider1->GetMinPosition()), atof(fTbh1->GetString())); break;
default: break;
}
DoSlider();
}
void ModelInspectorGUI::DoFit()
{
fFitRes = fMC->GetPdf()->fitTo(*fData,
Save());
;
it = fSliderMap.begin();
for (; it != fSliderMap.end(); ++it) {
param = (
RooRealVar *)fFitRes->floatParsFinal().find(it->second);
it->first->SetPointerPosition(param->
getVal());
}
DoSlider();
}
void ModelInspectorGUI::DoSlider(
const char *
text)
{
cout <<
"." <<
text << endl;
}
void ModelInspectorGUI::DoSlider()
{
if (strcmp(fMC->GetPdf()->ClassName(), "RooSimultaneous") == 0) {
} else {
}
if (!simPdf) {
;
delete fPlot;
fPlot = ((
RooRealVar *)fMC->GetObservables()->first())->frame();
fData->plotOn(fPlot);
double normCount;
it = fSliderMap.begin();
for (; it != fSliderMap.end(); ++it) {
const char *
name = it->second;
fWS->var(
name)->setVal(it->first->GetMaxPosition());
fLabelMap[it->first]->SetText(
Form(
"%s = %.3f [%.3f,%.3f]", param->
GetName(), it->first->GetPointerPosition(),
it->first->GetMinPosition(), it->first->GetMaxPosition()));
}
normCount = fMC->GetPdf()->expectedEvents(*fMC->GetObservables());
it = fSliderMap.begin();
for (; it != fSliderMap.end(); ++it) {
const char *
name = it->second;
fWS->var(
name)->setVal(it->first->GetMinPosition());
}
normCount = fMC->GetPdf()->expectedEvents(*fMC->GetObservables());
it = fSliderMap.begin();
for (; it != fSliderMap.end(); ++it) {
const char *
name = it->second;
fWS->var(
name)->setVal(it->first->GetPointerPosition());
}
normCount = fMC->GetPdf()->expectedEvents(*fMC->GetObservables());
fPlot->Draw();
fCanvas->GetCanvas()->Modified();
fCanvas->GetCanvas()->Update();
} else {
for (
auto const&
tt : *channelCat) {
auto const& catName =
tt.first;
++frameIndex;
fCanvas->GetCanvas()->cd(frameIndex);
fPlot = fPlotList.at(frameIndex - 1);
if (fPlot)
delete fPlot;
fPlotList.at(frameIndex - 1) = fPlot;
Cut(
Form(
"%s==%s::%s", channelCat->GetName(), channelCat->GetName(), catName.c_str())),
;
double normCount;
it = fSliderMap.begin();
for (; it != fSliderMap.end(); ++it) {
const char *
name = it->second;
fWS->var(
name)->setVal(it->first->GetMaxPosition());
fLabelMap[it->first]->SetText(
Form(
"%s = %.3f [%.3f,%.3f]", param->
GetName(),
it->first->GetPointerPosition(), it->first->GetMinPosition(),
it->first->GetMaxPosition()));
}
it = fSliderMap.begin();
for (; it != fSliderMap.end(); ++it) {
const char *
name = it->second;
fWS->var(
name)->setVal(it->first->GetMinPosition());
fLabelMap[it->first]->SetText(
Form(
"%s = %.3f [%.3f,%.3f]", param->
GetName(),
it->first->GetPointerPosition(), it->first->GetMinPosition(),
it->first->GetMaxPosition()));
}
it = fSliderMap.begin();
for (; it != fSliderMap.end(); ++it) {
const char *
name = it->second;
fWS->var(
name)->setVal(it->first->GetPointerPosition());
fLabelMap[it->first]->SetText(
Form(
"%s = %.3f [%.3f,%.3f]", param->
GetName(),
it->first->GetPointerPosition(), it->first->GetMinPosition(),
it->first->GetMaxPosition()));
}
if (!fFitRes)
else {
Cut(
Form(
"%s==%s::%s", channelCat->GetName(), channelCat->GetName(), catName.c_str())),
}
}
fCanvas->GetCanvas()->Modified();
fCanvas->GetCanvas()->Update();
}
}
void ModelInspectorGUI::HandleButtons()
{
switch (id) {
case HCId1: fHslider1->SetConstrained(fCheck1->GetState()); break;
case HCId2: fHslider1->SetRelative(fCheck2->GetState()); break;
default: break;
}
}
void ModelInspectorGUI::DoExit()
{
printf("Exit application...");
}
void ModelInspector(const char *infile = "", const char *workspaceName = "combined",
const char *modelConfigName = "ModelConfig", const char *dataName = "obsData")
{
const char *filename = "";
if (!strcmp(infile, "")) {
filename = "results/example_combined_GaussExample_model.root";
bool fileExist = !
gSystem->AccessPathName(filename);
if (!fileExist) {
cout << "will run standard hist2workspace example" << endl;
gROOT->ProcessLine(
".! prepareHistFactory .");
gROOT->ProcessLine(
".! hist2workspace config/example.xml");
cout << "\n\n---------------------" << endl;
cout << "Done creating example input" << endl;
cout << "---------------------\n\n" << endl;
}
} else
filename = infile;
if (!file) {
cout << "StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
return;
}
if (!w) {
cout << "workspace not found" << endl;
return;
}
if (!data || !mc) {
w->Print();
cout << "data or ModelConfig was not found" << endl;
return;
}
new ModelInspectorGUI(w, mc, data);
}
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
int Int_t
Signed integer 4 bytes (int).
externTApplication * gApplication
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
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.
Int_t numTypes(const char *=nullptr) const
Return number of types defined (in range named rangeName if rangeName!=nullptr).
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsArg * first() const
Abstract base class for binned and unbinned datasets.
Abstract interface for all probability density functions.
RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={}, const RooCmdArg &arg10={}) const override
Helper calling plotOn(RooPlot*, RooLinkedList&) const.
virtual double expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
RooPlot * frame(const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create a new RooPlot on the heap with a drawing frame initialized for this object,...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Object to represent discrete states.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
Plot frame and a container for graphics objects within that frame.
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
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
Persistable container for RooFit projects.
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
A frame containing two scrollbars (a horizontal and a vertical) and a viewport.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
virtual void SetRange(Float_t min, Float_t max)
virtual void SetPosition(Float_t min, Float_t max)
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
A composite frame that layout their children in horizontal way.
This class handles GUI labels.
This class describes layout hints used by the layout classes.
Defines top level windows that interact with the system Window Manager.
virtual void CloseWindow()
Close and delete main frame.
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
Yield an action as soon as it is clicked.
A TGTextEntry is a one line text input widget.
TripleSlider inherit from DoubleSlider widgets and allow easy selection of a min, max and pointer val...
virtual void SetPointerPosition(Double_t pos)
Set pointer position in scaled (real) value.
A composite frame that layout their children in vertical way.
const char * GetName() const override
Returns name of object.
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
This class creates a TGCanvas in which a TCanvas is created.
RooCmdArg Save(bool flag=true)
RooCmdArg DataError(Int_t)
RooCmdArg FillColor(TColorNumber color)
RooCmdArg LineColor(TColorNumber color)
RooCmdArg LineWidth(Width_t width)
RooCmdArg Normalization(double scaleFactor)
RooCmdArg VisualizeError(const RooDataSet ¶mData, double Z=1)
RooCmdArg MarkerSize(Size_t size)
RooCmdArg Cut(const char *cutSpec)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
RooStats::ModelConfig ModelConfig
Namespace for the RooStats classes.
void removeTopic(RooFit::MsgTopic oldTopic)