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:
TFile* fFile;
vector<RooPlot*> fPlotList;
map<TGTripleHSlider*,const char*> fSliderMap;
map<TGTripleHSlider*,TGLabel*> fLabelMap;
public:
virtual ~ModelInspectorGUI();
void CloseWindow();
void DoText(const char *text);
void DoSlider();
void DoSlider(const char*);
void DoFit();
void DoExit();
void HandleButtons();
};
{
fWS = w;
fMC = mc;
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){
for(int i=0; i<numCats; ++i){
}
}
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;
GetDefaultFrameBackground(),
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:
break;
case HId2:
fHslider1->SetPointerPosition(atof(fTbh2->
GetString()));
break;
case HId3:
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());
} else {
++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();
}
}
}
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;
if(!file ){
cout <<"StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
return;
}
if(!w){
cout <<"workspace not found" << endl;
return;
}
if(!data || !mc){
cout << "data or ModelConfig was not found" <<endl;
return;
}
new ModelInspectorGUI(w,mc,data);
}