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
};
private:
ModelConfig *fMC;
vector<RooPlot *> fPlotList;
map<TGTripleHSlider *, const char *> fSliderMap;
map<TGTripleHSlider *, TGLabel *> fLabelMap;
public:
virtual ~ModelInspectorGUI();
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 = 0;
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;
hsliderk->
Connect(
"PointerPositionChanged()",
"ModelInspectorGUI",
this,
"DoSlider()");
hsliderk->
Connect(
"PositionChanged()",
"ModelInspectorGUI",
this,
"DoSlider()");
fSliderList.Add(hsliderk);
fFrameList.Add(hframek);
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()), fHslider1->GetMaxPosition()); break;
case HId2: fHslider1->SetPointerPosition(atof(fTbh2->GetString())); break;
case HId3: fHslider1->SetPosition(fHslider1->GetMinPosition(), atof(fTbh1->GetString())); break;
default: break;
}
DoSlider();
}
void ModelInspectorGUI::DoFit()
{
fFitRes = fMC->GetPdf()->fitTo(*fData,
Save());
map<TGTripleHSlider *, const char *>::iterator it;
;
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) {
map<TGTripleHSlider *, const char *>::iterator it;
;
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 {
++frameIndex;
fCanvas->GetCanvas()->cd(frameIndex);
fPlot = fPlotList.at(frameIndex - 1);
if (fPlot)
delete fPlot;
fPlotList.at(frameIndex - 1) = fPlot;
map<TGTripleHSlider *, const char *>::iterator it;
;
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 {
}
fPlot->Draw();
}
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";
if (!fileExist) {
#ifdef _WIN32
cout << "HistFactory file cannot be generated on Windows - exit" << endl;
return;
#endif
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;
cout << "StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
return;
}
if (!w) {
cout << "workspace not found" << endl;
return;
}
ModelConfig *mc = (ModelConfig *)w->
obj(modelConfigName);
if (!data || !mc) {
cout << "data or ModelConfig was not found" << endl;
return;
}
new ModelInspectorGUI(w, mc, data);
}
#define ClassDef(name, id)
R__EXTERN TApplication * gApplication
R__EXTERN void * gTQSender
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Return the observables of this pdf given a set of observables.
TIterator * typeIterator() const
Return iterator over all defined states.
Int_t numTypes(const char *=0) const
RooAbsArg * first() const
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
RooAbsData is the common abstract base class for binned and unbinned datasets.
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events from this p.d.f for use in extended likelihood calculations.
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none(), const RooCmdArg &arg9=RooCmdArg::none(), const RooCmdArg &arg10=RooCmdArg::none()) const
Helper calling plotOn(RooPlot*, RooLinkedList&) const.
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
RooPlot * frame(const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create a new RooPlot on the heap with a drawing frame initialized for this object,...
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg(), const RooCmdArg &arg10=RooCmdArg()) const
Plot (project) PDF on specified frame.
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
RooCategory represents a fundamental (non-derived) discrete value object.
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
A RooPlot is a plot frame and a container for graphics objects within that frame.
RooRealVar represents a fundamental (non-derived) real valued object.
Double_t getError() const
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
const RooAbsCategoryLValue & indexCat() const
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
The RooWorkspace is a persistable container for RooFit projects.
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
void Print(Option_t *opts=0) const
Print contents of the workspace.
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
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)
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
virtual void CloseWindow()
Close and delete main frame.
virtual void SetPointerPosition(Float_t pos)
Set pointer position in scaled (real) value.
Iterator abstract base class.
virtual TObject * Next()=0
virtual const char * GetName() const
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.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Template specialisation used in RooAbsArg:
RooCmdArg VisualizeError(const RooDataSet ¶mData, Double_t Z=1)
RooCmdArg FillColor(Color_t color)
RooCmdArg LineWidth(Width_t width)
RooCmdArg Save(Bool_t flag=kTRUE)
RooCmdArg MarkerSize(Size_t size)
RooCmdArg Cut(const char *cutSpec)
RooCmdArg DataError(Int_t)
RooCmdArg LineColor(Color_t color)
RooCmdArg Normalization(Double_t scaleFactor)
Namespace for the RooStats classes.
void removeTopic(RooFit::MsgTopic oldTopic)