48class ETestCommandIdentifiers(Enum):
57ETestCmdId = ETestCommandIdentifiers
60class ModelInspectorGUI(ROOT.TGMainFrame):
112 def CloseWindow(self):
122 te = ROOT.BindObject(self.gTQSender, ROOT.TGTextEntry)
124 if Id == ETestCmdId.HId1.value:
125 fHslider1.SetPosition(atof(self.fTbh1.GetString()), self.fHslider1.GetMaxPosition())
126 elif Id == ETestCmdId.HId2.value:
127 fHslider1.SetPointerPosition(atof(self.fTbh2.GetString()))
128 elif Id == ETestCmdId.HId3.value:
129 fHslider1.SetPosition(self.fHslider1.GetMinPosition(), atof(self.fTbh1.GetString()))
135 self.fFitRes = self.fMC.GetPdf().fitTo(self.fData, Save=
True)
137 for it
in self.fSliderMap:
138 param = self.fWS.var(it.second)
139 param = self.fFitRes.floatParsFinal().find(it.second.Data())
140 it.first.SetPosition(param.getVal() - param.getError(), param.getVal() + param.getError())
141 it.first.SetPointerPosition(param.getVal())
157 simPdf = ROOT.nullptr
159 if str(self.fMC.GetPdf().ClassName()) ==
"RooSimultaneous":
160 simPdf = self.fMC.GetPdf()
161 channelCat = simPdf.indexCat()
162 numCats = channelCat.numTypes()
174 it = ROOT.map(TGTripleHSlider, char).iterator
181 self.fPlot = (self.fMC.GetObservables().first()).frame()
182 self.fData.plotOn(self.fPlot)
187 for it
in self.fSliderMap:
189 self.fWS.var(name).setVal(it.first.GetMaxPosition())
190 param = self.fWS.var(name)
191 self.fLabelMap[it.first].SetText(
193 "{:s} = {:.3}f [{:.3}f,{:.3}f]".
format(
195 it.first.GetPointerPosition(),
196 it.first.GetMinPosition(),
197 it.first.GetMaxPosition(),
202 normCount = self.fMC.GetPdf().expectedEvents(self.fMC.GetObservables())
203 self.fMC.GetPdf().plotOn(
204 self.fPlot, ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent), LineColor=
"r"
209 for it
in self.fSliderMap:
211 self.fWS.var(name).setVal(it.first.GetMinPosition())
213 normCount = self.fMC.GetPdf().expectedEvents(self.fMC.GetObservables())
214 self.fMC.GetPdf().plotOn(
215 self.fPlot, ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent), LineColor=
"g"
220 for it
in self.fSliderMap:
222 self.fWS.var(name).setVal(it.first.GetPointerPosition())
224 normCount = self.fMC.GetPdf().expectedEvents(self.fMC.GetObservables())
225 self.fMC.GetPdf().plotOn(
226 self.fPlot, ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent), LineColor=
"b"
230 self.fCanvas.GetCanvas().Modified()
231 self.fCanvas.GetCanvas().Update()
237 channelCat = simPdf.indexCat()
241 gchannelCat = channelCat
242 for tt
in channelCat:
246 self.fCanvas.GetCanvas().cd(frameIndex)
249 pdftmp = simPdf.getPdf(str(catName))
250 obstmp = pdftmp.getObservables(self.fMC.GetObservables())
251 global ggpdftmp, gobstmp
258 gframeIndex = frameIndex
260 gfPlotList = self.fPlotList
261 self.fPlot = self.fPlotList[frameIndex - 1]
264 self.fPlot = obs.frame()
266 self.fPlotList[frameIndex - 1] = self.fPlot
269 msglevel = ROOT.RooMsgService.instance().globalKillBelow()
270 ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.WARNING)
275 Cut=ROOT.Form(
"{:s}=={:s}::{:s}".
format(channelCat.GetName(), channelCat.GetName(), str(catName))),
282 ROOT.RooMsgService.instance().setGlobalKillBelow(msglevel)
288 for it
in self.fSliderMap:
290 self.fWS.var(name).setVal(it.first.GetMaxPosition())
291 param = self.fWS.var(name)
292 self.fLabelMap[it.first].SetText(
294 "{:s} = {:.3f} [{:.3f},{:.3f}]".
format(
296 it.first.GetPointerPosition(),
297 it.first.GetMinPosition(),
298 it.first.GetMaxPosition(),
303 normCount = pdftmp.expectedEvents(obstmp)
307 ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent),
314 for it
in self.fSliderMap:
316 self.fWS.var(name).setVal(it.first.GetMinPosition())
317 param = self.fWS.var(name)
318 self.fLabelMap[it.first].SetText(
320 "{:s} = {:.3f} [{:.3f},{:.3f}]".
format(
322 it.first.GetPointerPosition(),
323 it.first.GetMinPosition(),
324 it.first.GetMaxPosition(),
330 normCount = pdftmp.expectedEvents(obstmp)
333 ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent),
340 for it
in self.fSliderMap:
342 self.fWS.var(name).setVal(it.first.GetPointerPosition())
343 param = self.fWS.var(name)
344 self.fLabelMap[it.first].SetText(
346 "{:s} = {:.3f} [{:.3f},{:.3f}]".
format(
348 it.first.GetPointerPosition(),
349 it.first.GetMinPosition(),
350 it.first.GetMaxPosition(),
356 normCount = pdftmp.expectedEvents(obstmp)
360 gnormCount = normCount
365 ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent),
373 ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent),
374 ROOT.RooFit.VisualizeError(self.fFitRes, self.fMC.GetNuisanceParameters()),
379 ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent),
383 msglevel = ROOT.RooMsgService.instance().globalKillBelow()
384 ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.WARNING)
389 "{:s}=={:s}::{:s}".
format(channelCat.GetName(), channelCat.GetName(), str(catName))
394 ROOT.RooMsgService.instance().setGlobalKillBelow(msglevel)
398 self.fCanvas.GetCanvas().Modified()
399 self.fCanvas.GetCanvas().Update()
405 def HandleButtons(self):
414 btn = ROOT.BindObject(self.gTQSender, ROOT.TGTextButton)
417 case ETestCmdId.HCId1.value:
418 self.fHslider1.SetConstrained(self.fCheck1.GetState())
420 case ETestCmdId.HCId2.value:
421 self.fHslider1.SetRelative(self.fCheck2.GetState())
428 print(
"Exit application...")
429 self.gApplication.Terminate(0)
434 def __init__(self, w, mc, data):
441 self.fCanvas = ROOT.TRootEmbeddedCanvas()
442 self.fLcan = ROOT.TGLayoutHints()
443 self.fFitFcn = ROOT.TF1()
444 self.fPlot = ROOT.RooPlot()
445 self.fFile = ROOT.TFile()
446 self.fFitRes = ROOT.RooFitResult()
448 self.fSliderList = ROOT.TList()
449 self.fFrameList = ROOT.TList()
450 self.fPlotList = ROOT.std.vector(
"RooPlot *")()
451 self.fSliderMap = ROOT.std.map(
"TGTripleHSlider *",
" TString ")()
454 self.fLabelMap = ROOT.std.map(
"TGTripleHSlider*",
"TGLabel *")()
456 self.fFitButton = ROOT.TGButton()
457 self.fExitButton = ROOT.TGTextButton()
460 self.fCan = ROOT.TGCanvas()
461 self.fVFrame = ROOT.TGVerticalFrame()
463 self.fHframe0 = self.fHframe1 = self.fHframe2 = ROOT.TGHorizontalFrame()
464 self.fBly = self.fBfly1 = self.fBfly2 = self.fBfly3 = ROOT.TGLayoutHints()
465 self.fHslider1 = ROOT.TGTripleHSlider()
466 self.fTbh1 = self.fTbh2 = self.fTbh3 = ROOT.TGTextBuffer()
467 self.fCheck1 = self.fCheck2 = ROOT.TGCheckButton()
475 super().__init__(ROOT.gClient.GetRoot(), 500, 500)
476 self.gTQSender = ROOT.gTQSender
477 self.gApplication = ROOT.gApplication
479 ROOT.RooMsgService.instance().getStream(1).removeTopic(ROOT.RooFit.NumIntegration)
481 simPdf = ROOT.nullptr
484 if self.fMC.GetPdf().ClassName() ==
"RooSimultaneous":
485 print(f
"Is a simultaneous PDF")
486 simPdf = self.fMC.GetPdf()
487 channelCat = simPdf.indexCat()
488 print(f
" with {channelCat.numTypes()} categories")
489 numCats = channelCat.numTypes()
491 print(f
"Is not a simultaneous PDF")
493 self.fFitRes = ROOT.nullptr
494 self.SetCleanup(ROOT.kDeepCleanup)
498 self.fCanvas = ROOT.TRootEmbeddedCanvas(
"Canvas", self, 600, 400)
499 self.fLcan = ROOT.TGLayoutHints(ROOT.kLHintsExpandX | ROOT.kLHintsExpandY, 10, 10, 10, 10)
500 self.AddFrame(self.fCanvas, self.fLcan)
501 self.fPlotList.resize(numCats)
504 self.fCanvas.GetCanvas().Divide(numCats)
505 for i
in range(numCats):
506 self.fCanvas.GetCanvas().cd(i + 1).SetBorderMode(0)
507 self.fCanvas.GetCanvas().cd(i + 1).SetGrid()
510 self.fHframe0 = ROOT.TGHorizontalFrame(self, 0, 0, 0)
512 self.fCheck1 = ROOT.TGCheckButton(self.fHframe0,
"&Constrained", ETestCmdId.HCId1.value)
513 self.fCheck2 = ROOT.TGCheckButton(self.fHframe0,
"&Relative", ETestCmdId.HCId2.value)
514 self.fCheck1.SetState(ROOT.kButtonUp)
515 self.fCheck2.SetState(ROOT.kButtonUp)
516 self.fCheck1.SetToolTipText(
"Pointer position constrained to slider sides")
517 self.fCheck2.SetToolTipText(
"Pointer position relative to slider position")
519 self.fHframe0.Resize(200, 50)
521 self.fHframe2 = ROOT.TGHorizontalFrame(self, 0, 0, 0)
523 dp_DoFit = ROOT.TPyDispatcher(self.DoFit)
524 self.fFitButton = ROOT.TGTextButton(self.fHframe2,
"&Fit")
525 self.fFitButton.SetFont(
"Helvetica")
526 self.fFitButton.Connect(
"Clicked()",
"TPyDispatcher", dp_DoFit,
"Dispatch()")
528 dp_DoExit = ROOT.TPyDispatcher(self.DoExit)
529 self.fExitButton = ROOT.TGTextButton(self.fHframe2,
"&Exit")
530 self.fExitButton.SetFont(
"Helvetica")
533 self.fExitButton.SetCommand(
'TPython::Exec( "raise SystemExit" )')
539 dp_HandleButtons = ROOT.TPyDispatcher(self.HandleButtons)
540 self.fCheck1.Connect(
"Clicked()",
"TPyDispatcher", dp_HandleButtons,
"Dispatch()")
541 self.fCheck2.Connect(
"Clicked()",
"TPyDispatcher", dp_HandleButtons,
"Dispatch()")
543 self.fHframe2.Resize(100, 25)
546 self.fBly = ROOT.TGLayoutHints(ROOT.kLHintsTop | ROOT.kLHintsExpandX, 5, 5, 5, 5)
549 self.fBfly1 = ROOT.TGLayoutHints(ROOT.kLHintsTop | ROOT.kLHintsCenterX, 5, 5, 5, 5)
550 self.fBfly2 = ROOT.TGLayoutHints(ROOT.kLHintsTop | ROOT.kLHintsLeft, 5, 5, 5, 5)
551 self.fBfly3 = ROOT.TGLayoutHints(ROOT.kLHintsTop | ROOT.kLHintsRight, 5, 5, 5, 5)
553 self.fHframe2.AddFrame(self.fFitButton, self.fBfly2)
554 self.fHframe2.AddFrame(self.fExitButton, self.fBfly3)
556 self.AddFrame(self.fHframe0, self.fBly)
557 self.AddFrame(self.fHframe2, self.fBly)
561 parameters = ROOT.RooArgSet()
562 parameters.add(self.fMC.GetParametersOfInterest())
563 parameters.add(self.fMC.GetNuisanceParameters())
567 self.fCan = ROOT.TGCanvas(self, 100, 100, ROOT.kFixedSize)
568 self.AddFrame(self.fCan, ROOT.TGLayoutHints(ROOT.kLHintsExpandY | ROOT.kLHintsExpandX))
569 self.fVFrame = ROOT.TGVerticalFrame(self.fCan.GetViewPort(), 10, 10)
570 self.fCan.SetContainer(self.fVFrame)
575 for param
in parameters:
576 print(f
"Adding Slider for ", param.GetName())
577 hframek = ROOT.TGHorizontalFrame(self.fVFrame, 0, 0, 0)
579 hlabel = ROOT.TGLabel(
580 hframek, ROOT.Form(
"{:s} = {:.3f} +{:.3f}".
format(param.GetName(), param.getVal(), param.getError()))
583 hsliderk = ROOT.TGTripleHSlider(
586 ROOT.kDoubleScaleBoth,
587 ETestCmdId.HSId1.value,
588 ROOT.kHorizontalFrame,
589 ROOT.TGFrame.GetDefaultFrameBackground(),
596 dp_DoSlider = ROOT.TPyDispatcher(self.DoSlider)
597 hsliderk.Connect(
"PointerPositionChanged()",
"TPyDispatcher", dp_DoSlider,
"Dispatch()")
598 hsliderk.Connect(
"PositionChanged()",
"TPyDispatcher", dp_DoSlider,
"Dispatch()")
599 hsliderk.SetRange(param.getMin(), param.getMax())
601 hframek.Resize(200, 25)
602 self.fSliderList.
Add(hsliderk)
603 self.fFrameList.
Add(hframek)
605 hsliderk.SetPosition(param.getVal() - param.getError(), param.getVal() + param.getError())
606 hsliderk.SetPointerPosition(param.getVal())
608 hframek.AddFrame(hlabel, self.fBly)
609 hframek.AddFrame(hsliderk, self.fBly)
610 self.fVFrame.AddFrame(hframek, self.fBly)
611 self.fSliderMap[hsliderk] = param.GetName()
612 self.fLabelMap[hsliderk] = hlabel
616 self.SetWindowName(
"RooFit/RooStats Model Inspector")
618 self.Resize(self.GetDefaultSize())
625def ModelInspector(infile="", workspaceName="combined", modelConfigName="ModelConfig", dataName="obsData"):
633 filename =
"results/example_combined_GaussExample_model.root"
634 fileExist =
not ROOT.gSystem.AccessPathName(filename)
638 print(f
"will run standard hist2workspace example")
639 ROOT.gROOT.ProcessLine(
".! prepareHistFactory .")
640 ROOT.gROOT.ProcessLine(
".! hist2workspace config/example.xml")
641 print(f
"\n\n---------------------")
642 print(f
"Done creating example input")
643 print(f
"---------------------\n\n")
650 Declare = ROOT.gInterpreter.Declare
652 """using namespace std;
653 using namespace RooFit;
654 using namespace RooStats;
660 Declare(f
'TFile *file = TFile::Open("{filename}");')
666 except ReferenceError:
667 print(
"file wasn't load properly and is a nullptr")
668 print(f
"\nInput file {filename} was not found")
676 ProcessLine = ROOT.gInterpreter.ProcessLine
677 ProcessLine(f
'RooWorkspace *w = (RooWorkspace *)file->Get("{workspaceName}");')
681 except ReferenceError:
682 print(f
"Workspace:{workspaceName} wasn't load properly and is a nullptr")
687 ProcessLine(f
'ModelConfig *mc = (ModelConfig *)w->obj("{modelConfigName}");')
692 ProcessLine(f
'RooAbsData *DATA = w->data("{dataName}");')
698 print(
"name", mc.GetPdf())
701 except ReferenceError:
702 print(f
"ModelConfig:{modelConfigName} wasn't load properly and is a nullptr")
706 except ReferenceError:
707 print(f
"data:{dataName} wasn't load properly and is a nullptr")
710 print(
"running ModelInspectorGUI...")
711 ModelInspectorGUI(w, mc, data)
714ModelInspector(infile=
"", workspaceName=
"combined", modelConfigName=
"ModelConfig", dataName=
"obsData")
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.