Analysis-Utilities 26.9.9
C++/ROOT utilities for nuclear measurement data analysis
Loading...
Searching...
No Matches
InteractiveRooFitEditor.hpp
Go to the documentation of this file.
1#ifndef INTERACTIVEROOFITEDITOR_H
2#define INTERACTIVEROOFITEDITOR_H
3
4#include "RooFitUtils.hpp"
5
6#include <RooAbsData.h>
7#include <RooAbsPdf.h>
8#include <RooRealVar.h>
9#include <TCanvas.h>
10#include <TGButton.h>
11#include <TGClient.h>
12#include <TGDoubleSlider.h>
13#include <TGFrame.h>
14#include <TGLabel.h>
15#include <TGNumberEntry.h>
16#include <TGSlider.h>
17#include <TGTab.h>
18#include <TGraph.h>
19#include <TH1.h>
20#include <TLatex.h>
21#include <TPad.h>
22#include <TRootEmbeddedCanvas.h>
23#include <TString.h>
24#include <TSystem.h>
25#include <TTimer.h>
26#include <vector>
27
44class InteractiveRooFitEditor : public TGMainFrame {
45private:
46 static const Int_t kSliderRes = 10000;
47 static const Int_t kNDrawPts = 500;
48
49 static const Int_t kBtnRefit = 1000;
50 static const Int_t kBtnAccept = 1001;
51 static const Int_t kBtnCancel = 1002;
52 static const Int_t kBtnReset = 1003;
53 static const Int_t kSliderBase = 2000;
54 static const Int_t kEntryBase = 3000;
55 static const Int_t kFixBase = 4000;
56 static const Int_t kLoBoundBase = 5000;
57 static const Int_t kHiBoundBase = 6000;
58 static const Int_t kRangeSlider = 7000;
59 static const Int_t kRangeLoEntry = 7001;
60 static const Int_t kRangeHiEntry = 7002;
61
62 TH1 *hist_;
63 const std::vector<Double_t> *events_;
64 Float_t display_bin_width_kev_;
65 RooAbsPdf *total_pdf_;
66 RooRealVar *x_;
67 RooAbsData *data_;
68 std::vector<RooFitPeakModel> *peaks_;
70 TString info_label_text_;
71 Double_t range_low_;
72 Double_t range_high_;
73 Double_t original_range_low_;
74 Double_t original_range_high_;
75 Double_t hist_x_min_;
76 Double_t hist_x_max_;
77 Int_t num_peaks_;
78 Int_t num_params_;
79
80 std::vector<RooRealVar *> params_;
81
82 std::vector<Double_t> original_params_;
83 std::vector<Double_t> original_bounds_low_;
84 std::vector<Double_t> original_bounds_high_;
85 std::vector<Bool_t> original_fixed_;
86 std::vector<Double_t> current_bounds_low_;
87 std::vector<Double_t> current_bounds_high_;
88
89 TRootEmbeddedCanvas *embedded_canvas_;
90 TPad *main_pad_;
91 TPad *residual_pad_;
92
93 std::vector<TGHSlider *> sliders_;
94 std::vector<TGNumberEntry *> value_entries_;
95 std::vector<TGCheckButton *> fix_checks_;
96 std::vector<TGNumberEntry *> lo_bound_entries_;
97 std::vector<TGNumberEntry *> hi_bound_entries_;
98
99 TGDoubleHSlider *range_slider_;
100 TGNumberEntry *range_lo_entry_;
101 TGNumberEntry *range_hi_entry_;
102
103 TH1 *hist_draw_;
104 TGraph *total_graph_;
105 TGraph *bkg_graph_;
106 TGraph *comp_graphs_[3][4];
107 TGraph *res_graph_;
108 TF1 *zero_line_;
109 TF1 *plus3_line_;
110 TF1 *minus3_line_;
111 TLatex *chi2_label_;
112 Int_t n_res_points_;
113
114 Bool_t needs_redraw_;
115 Bool_t accepted_;
116 Bool_t done_;
117 Bool_t syncing_;
118 TTimer *redraw_timer_;
119
120 void BuildGUI();
121 void BuildPeakTab(TGCompositeFrame *parent, Int_t peak_idx);
122 void BuildBackgroundTab(TGCompositeFrame *parent);
123 void AddParamRow(TGCompositeFrame *parent, Int_t param_idx, const char *name);
124
125 void InitDrawing();
126 void UpdateCanvas();
127 void UpdateAllGraphs();
128 void UpdateResPoints();
129
130 void SyncAllWidgets();
131 void SyncWidget(Int_t param_idx);
132
133 void OnSliderMoved(Int_t param_idx);
134 void OnEntryChanged(Int_t param_idx);
135 void OnBoundsChanged(Int_t param_idx);
136 void OnFixToggled(Int_t param_idx);
137 void OnRangeChanged();
138
139 void DoRefit();
140 void DoAccept();
141 void DoCancel();
142 void DoReset();
143
144 Int_t ValToSlider(Int_t param_idx, Double_t val);
145 Double_t SliderToVal(Int_t param_idx, Int_t pos);
146 Bool_t IsFixed(Int_t param_idx);
147 void GetDefaultBounds(Int_t param_idx, Double_t &lo, Double_t &hi);
148 Int_t BkgConstIdx() { return num_peaks_ * 10; }
149 Int_t BkgSlopeIdx() { return num_peaks_ * 10 + 1; }
150 static Int_t PeakStyle(Int_t peak_idx);
151
152 Double_t EvalPdfDensity(RooAbsPdf *pdf, Double_t xv);
153 Double_t ComponentExpected(RooAbsPdf *pdf, Double_t yield, Double_t xv);
154
155public:
177 InteractiveRooFitEditor(const TGWindow *parent, TH1 *hist,
178 const std::vector<Double_t> *events,
179 Float_t display_bin_width_kev, RooAbsPdf *total_pdf,
180 RooRealVar *x, RooAbsData *data,
181 std::vector<RooFitPeakModel> *peaks,
182 RooFitBackgroundModel *bkg, Double_t range_low,
183 Double_t range_high, const TString &info_label = "");
185 virtual ~InteractiveRooFitEditor();
186
194 virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
205 virtual Bool_t HandleTimer(TTimer *timer);
207 virtual void CloseWindow();
208
211 Bool_t WasAccepted() const { return accepted_; }
213 Bool_t IsDone() const { return done_; }
216 TTimer *GetRedrawTimer() { return redraw_timer_; }
219 TRootEmbeddedCanvas *GetEmbeddedCanvas() { return embedded_canvas_; }
220};
221
244 TH1 *hist, const std::vector<Double_t> *events,
245 Float_t display_bin_width_kev, RooAbsPdf *total_pdf, RooRealVar *x,
246 RooAbsData *data, std::vector<RooFitPeakModel> *peaks,
247 RooFitBackgroundModel *bkg, Double_t range_low, Double_t range_high,
248 const TString &info_label);
249
250#endif
Bool_t LaunchInteractiveRooFitEditor(TH1 *hist, const std::vector< Double_t > *events, Float_t display_bin_width_kev, RooAbsPdf *total_pdf, RooRealVar *x, RooAbsData *data, std::vector< RooFitPeakModel > *peaks, RooFitBackgroundModel *bkg, Double_t range_low, Double_t range_high, const TString &info_label)
Open the RooFit editor and pump its event loop until the user is done.
TRootEmbeddedCanvas * GetEmbeddedCanvas()
The canvas holding the fit and residual pads.
InteractiveRooFitEditor(const TGWindow *parent, TH1 *hist, const std::vector< Double_t > *events, Float_t display_bin_width_kev, RooAbsPdf *total_pdf, RooRealVar *x, RooAbsData *data, std::vector< RooFitPeakModel > *peaks, RooFitBackgroundModel *bkg, Double_t range_low, Double_t range_high, const TString &info_label="")
Build the editor around a converged RooFit model.
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
ROOT GUI message dispatch for every widget in the editor.
TTimer * GetRedrawTimer()
The coalescing redraw timer, for the driving event loop.
Bool_t WasAccepted() const
Whether the user accepted rather than cancelled.
virtual void CloseWindow()
Window-manager close. Treated as a cancel, not an accept.
virtual ~InteractiveRooFitEditor()
Destroys the widgets and drawing objects the editor created.
virtual Bool_t HandleTimer(TTimer *timer)
Redraw tick.
Bool_t IsDone() const
Whether the editor has finished and the loop may exit.
The RooFit objects making up one channel's background.