65enum ETestCommandIdentifiers {
75using std::map, std::vector, std::cout, std::endl;
82 TRootEmbeddedCanvas *fCanvas;
90 RooFitResult *fFitRes;
94 vector<RooPlot *> fPlotList;
95 map<TGTripleHSlider *, const char *> fSliderMap;
96 map<TGTripleHSlider *, TGLabel *> fLabelMap;
99 TGTextButton *fExitButton;
103 TGVerticalFrame *fVFrame;
105 TGHorizontalFrame *fHframe0, *fHframe1, *fHframe2;
106 TGLayoutHints *fBly, *fBfly1, *fBfly2, *fBfly3;
107 TGTripleHSlider *fHslider1;
108 TGTextBuffer *fTbh1, *fTbh2, *fTbh3;
109 TGCheckButton *fCheck1, *fCheck2;
112 ModelInspectorGUI(RooWorkspace *, ModelConfig *, RooAbsData *);
113 ~ModelInspectorGUI()
override;
116 void DoText(
const char *
text);
118 void DoSlider(
const char *);
121 void HandleButtons();
136 if (strcmp(fMC->GetPdf()->ClassName(),
"RooSimultaneous") == 0) {
137 cout <<
"Is a simultaneous PDF" << endl;
140 cout <<
" with " << channelCat->
numTypes() <<
" categories" << endl;
143 cout <<
"Is not a simultaneous PDF" << endl;
153 AddFrame(fCanvas, fLcan);
154 fPlotList.resize(numCats);
156 fCanvas->GetCanvas()->Divide(numCats);
157 for (
int i = 0; i < numCats; ++i) {
158 fCanvas->GetCanvas()->cd(i + 1)->SetBorderMode(0);
159 fCanvas->GetCanvas()->cd(i + 1)->SetGrid();
165 fCheck1 =
new TGCheckButton(fHframe0,
"&Constrained", HCId1);
169 fCheck1->SetToolTipText(
"Pointer position constrained to slider sides");
170 fCheck2->SetToolTipText(
"Pointer position relative to slider position");
172 fHframe0->Resize(200, 50);
177 fFitButton->Connect(
"Clicked()",
"ModelInspectorGUI",
this,
"DoFit()");
179 fExitButton->Connect(
"Clicked()",
"ModelInspectorGUI",
this,
"DoExit()");
181 fCheck1->Connect(
"Clicked()",
"ModelInspectorGUI",
this,
"HandleButtons()");
182 fCheck2->Connect(
"Clicked()",
"ModelInspectorGUI",
this,
"HandleButtons()");
184 fHframe2->Resize(100, 25);
194 fHframe2->AddFrame(fFitButton, fBfly2);
195 fHframe2->AddFrame(fExitButton, fBfly3);
197 AddFrame(fHframe0, fBly);
198 AddFrame(fHframe2, fBly);
203 parameters.
add(*fMC->GetParametersOfInterest());
204 parameters.
add(*fMC->GetNuisanceParameters());
210 fCan->SetContainer(fVFrame);
215 cout <<
"Adding Slider for " << param->GetName() << endl;
219 new TGLabel(hframek,
Form(
"%s = %.3f +%.3f", param->GetName(), param->getVal(), param->getError()));
221 GetDefaultFrameBackground(),
false,
false,
false,
false);
222 hsliderk->
Connect(
"PointerPositionChanged()",
"ModelInspectorGUI",
this,
"DoSlider()");
223 hsliderk->
Connect(
"PositionChanged()",
"ModelInspectorGUI",
this,
"DoSlider()");
224 hsliderk->
SetRange(param->getMin(), param->getMax());
227 fSliderList.Add(hsliderk);
228 fFrameList.Add(hframek);
230 hsliderk->
SetPosition(param->getVal() - param->getError(), param->getVal() + param->getError());
235 fVFrame->AddFrame(hframek, fBly);
236 fSliderMap[hsliderk] = param->GetName();
237 fLabelMap[hsliderk] = hlabel;
242 SetWindowName(
"RooFit/RooStats Model Inspector");
244 Resize(GetDefaultSize());
251ModelInspectorGUI::~ModelInspectorGUI()
259void ModelInspectorGUI::CloseWindow()
267void ModelInspectorGUI::DoText(
const char * )
275 case HId1: fHslider1->SetPosition(atof(fTbh1->GetString()),
static_cast<double>(fHslider1->GetMaxPosition()));
break;
276 case HId2: fHslider1->SetPointerPosition(atof(fTbh2->GetString()));
break;
277 case HId3: fHslider1->SetPosition(
static_cast<double>(fHslider1->GetMinPosition()), atof(fTbh1->GetString()));
break;
284void ModelInspectorGUI::DoFit()
286 fFitRes = fMC->GetPdf()->fitTo(*fData,
Save());
289 it = fSliderMap.begin();
290 for (; it != fSliderMap.end(); ++it) {
292 param = (
RooRealVar *)fFitRes->floatParsFinal().find(it->second);
294 it->first->SetPointerPosition(param->
getVal());
300void ModelInspectorGUI::DoSlider(
const char *
text)
302 cout <<
"." <<
text << endl;
306void ModelInspectorGUI::DoSlider()
314 if (strcmp(fMC->GetPdf()->ClassName(),
"RooSimultaneous") == 0) {
331 fPlot = ((
RooRealVar *)fMC->GetObservables()->first())->frame();
332 fData->plotOn(fPlot);
336 it = fSliderMap.begin();
337 for (; it != fSliderMap.end(); ++it) {
338 const char *
name = it->second;
339 fWS->var(
name)->setVal(it->first->GetMaxPosition());
341 fLabelMap[it->first]->SetText(
Form(
"%s = %.3f [%.3f,%.3f]", param->
GetName(), it->first->GetPointerPosition(),
342 it->first->GetMinPosition(), it->first->GetMaxPosition()));
344 normCount = fMC->GetPdf()->expectedEvents(*fMC->GetObservables());
348 it = fSliderMap.begin();
349 for (; it != fSliderMap.end(); ++it) {
350 const char *
name = it->second;
351 fWS->var(
name)->setVal(it->first->GetMinPosition());
353 normCount = fMC->GetPdf()->expectedEvents(*fMC->GetObservables());
357 it = fSliderMap.begin();
358 for (; it != fSliderMap.end(); ++it) {
359 const char *
name = it->second;
360 fWS->var(
name)->setVal(it->first->GetPointerPosition());
362 normCount = fMC->GetPdf()->expectedEvents(*fMC->GetObservables());
366 fCanvas->GetCanvas()->Modified();
367 fCanvas->GetCanvas()->Update();
375 Int_t frameIndex = 0;
376 for (
auto const&
tt : *channelCat) {
377 auto const& catName =
tt.first;
380 fCanvas->GetCanvas()->cd(frameIndex);
387 fPlot = fPlotList.at(frameIndex - 1);
390 fPlot = obs->
frame();
391 fPlotList.at(frameIndex - 1) = fPlot;
396 Cut(
Form(
"%s==%s::%s", channelCat->GetName(), channelCat->GetName(), catName.c_str())),
405 it = fSliderMap.begin();
406 for (; it != fSliderMap.end(); ++it) {
407 const char *
name = it->second;
408 fWS->var(
name)->setVal(it->first->GetMaxPosition());
410 fLabelMap[it->first]->SetText(
Form(
"%s = %.3f [%.3f,%.3f]", param->
GetName(),
411 it->first->GetPointerPosition(), it->first->GetMinPosition(),
412 it->first->GetMaxPosition()));
418 it = fSliderMap.begin();
419 for (; it != fSliderMap.end(); ++it) {
420 const char *
name = it->second;
421 fWS->var(
name)->setVal(it->first->GetMinPosition());
423 fLabelMap[it->first]->SetText(
Form(
"%s = %.3f [%.3f,%.3f]", param->
GetName(),
424 it->first->GetPointerPosition(), it->first->GetMinPosition(),
425 it->first->GetMaxPosition()));
431 it = fSliderMap.begin();
432 for (; it != fSliderMap.end(); ++it) {
433 const char *
name = it->second;
434 fWS->var(
name)->setVal(it->first->GetPointerPosition());
436 fLabelMap[it->first]->SetText(
Form(
"%s = %.3f [%.3f,%.3f]", param->
GetName(),
437 it->first->GetPointerPosition(), it->first->GetMinPosition(),
438 it->first->GetMaxPosition()));
450 Cut(
Form(
"%s==%s::%s", channelCat->GetName(), channelCat->GetName(), catName.c_str())),
456 fCanvas->GetCanvas()->Modified();
457 fCanvas->GetCanvas()->Update();
464void ModelInspectorGUI::HandleButtons()
472 case HCId1: fHslider1->SetConstrained(fCheck1->GetState());
break;
473 case HCId2: fHslider1->SetRelative(fCheck2->GetState());
break;
477void ModelInspectorGUI::DoExit()
479 printf(
"Exit application...");
483void ModelInspector(
const char *infile =
"",
const char *workspaceName =
"combined",
484 const char *modelConfigName =
"ModelConfig",
const char *dataName =
"obsData")
490 const char *filename =
"";
491 if (!strcmp(infile,
"")) {
492 filename =
"results/example_combined_GaussExample_model.root";
493 bool fileExist = !
gSystem->AccessPathName(filename);
497 cout <<
"will run standard hist2workspace example" << endl;
498 gROOT->ProcessLine(
".! prepareHistFactory .");
499 gROOT->ProcessLine(
".! hist2workspace config/example.xml");
500 cout <<
"\n\n---------------------" << endl;
501 cout <<
"Done creating example input" << endl;
502 cout <<
"---------------------\n\n" << endl;
513 cout <<
"StandardRooStatsDemoMacro: Input file " << filename <<
" is not found" << endl;
524 cout <<
"workspace not found" << endl;
537 cout <<
"data or ModelConfig was not found" << endl;
541 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.
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
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.
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)