Analysis-Utilities 26.9.9
C++/ROOT utilities for nuclear measurement data analysis
Loading...
Searching...
No Matches
InteractiveSimultaneousFitEditor.hpp
Go to the documentation of this file.
1#ifndef INTERACTIVESIMULTANEOUSFITEDITOR_H
2#define INTERACTIVESIMULTANEOUSFITEDITOR_H
3
4#include "RooFitUtils.hpp"
5
6#include <RooAbsData.h>
7#include <RooAbsPdf.h>
8#include <RooRealVar.h>
9#include <RooSimultaneous.h>
10#include <TCanvas.h>
11#include <TGButton.h>
12#include <TGClient.h>
13#include <TGDoubleSlider.h>
14#include <TGFrame.h>
15#include <TGLabel.h>
16#include <TGNumberEntry.h>
17#include <TGSlider.h>
18#include <TGTab.h>
19#include <TGraph.h>
20#include <TH1.h>
21#include <TLatex.h>
22#include <TPad.h>
23#include <TRootEmbeddedCanvas.h>
24#include <TString.h>
25#include <TSystem.h>
26#include <TTimer.h>
27#include <map>
28#include <vector>
29
41 TString name;
42 TH1 *hist;
45 const std::vector<Double_t> *events;
47 RooAbsPdf *pdf;
48 RooAbsData *data;
49 std::vector<RooFitPeakModel> *peaks;
51 Int_t num_peaks;
52
58 std::vector<RooRealVar *> params;
59 std::vector<Double_t> original_params;
60 std::vector<Double_t> original_bounds_low;
61 std::vector<Double_t> original_bounds_high;
62 std::vector<Bool_t> original_fixed;
63 std::vector<Double_t> current_bounds_low;
64 std::vector<Double_t> current_bounds_high;
66
70
71 std::vector<TGHSlider *> sliders;
72 std::vector<TGNumberEntry *> value_entries;
73 std::vector<TGCheckButton *> fix_checks;
74 std::vector<TGNumberEntry *> lo_bound_entries;
75 std::vector<TGNumberEntry *> hi_bound_entries;
76
77 TRootEmbeddedCanvas *embedded_canvas;
78 TPad *main_pad;
81 TGraph *total_graph;
82 TGraph *bkg_graph;
83 TGraph *comp_graphs[3][4];
84 TGraph *res_graph;
88 TLatex *chi2_label;
91};
92
109class InteractiveSimultaneousFitEditor : public TGMainFrame {
110private:
111 static const Int_t kSliderRes = 10000;
112 static const Int_t kNDrawPts = 500;
113
114 static const Int_t kBtnRefit = 1000;
115 static const Int_t kBtnAccept = 1001;
116 static const Int_t kBtnCancel = 1002;
117 static const Int_t kBtnReset = 1003;
118
119 static const Int_t kRangeSlider = 7000;
120 static const Int_t kRangeLoEntry = 7001;
121 static const Int_t kRangeHiEntry = 7002;
122
123 static const Int_t kSliderStride = 100;
124 static const Int_t kSliderBase = 10000;
125 static const Int_t kEntryBase = 20000;
126 static const Int_t kFixBase = 30000;
127 static const Int_t kLoBoundBase = 40000;
128 static const Int_t kHiBoundBase = 50000;
129
130 RooSimultaneous *sim_pdf_;
131 RooAbsData *combined_data_;
132 RooRealVar *x_;
133 std::vector<SimEditorChannelView> channels_;
134 TString info_label_text_;
135 Double_t range_low_;
136 Double_t range_high_;
137 Double_t original_range_low_;
138 Double_t original_range_high_;
139 Double_t hist_x_min_;
140 Double_t hist_x_max_;
141
142 TGDoubleHSlider *range_slider_;
143 TGNumberEntry *range_lo_entry_;
144 TGNumberEntry *range_hi_entry_;
145
146 Bool_t needs_redraw_;
147 Bool_t accepted_;
148 Bool_t done_;
149 Bool_t syncing_;
150 Bool_t fit_debug_;
151 TTimer *redraw_timer_;
152
153 Int_t ChannelIndexFromWidgetId(Int_t base, Int_t parm1, Int_t &local_idx);
154
155 void BuildGUI();
156 void BuildChannelTab(TGCompositeFrame *parent, Int_t ch_idx);
157 void BuildPeakSubTab(TGCompositeFrame *parent, Int_t ch_idx, Int_t peak_idx);
158 void BuildBackgroundSubTab(TGCompositeFrame *parent, Int_t ch_idx);
159 void AddParamRow(TGCompositeFrame *parent, Int_t ch_idx, Int_t param_idx,
160 const char *name);
161
162 void InitDrawing();
163 void InitChannelDrawing(SimEditorChannelView &cv);
164 void UpdateCanvases();
165 void UpdateChannelGraphs(SimEditorChannelView &cv);
166 void UpdateChannelResiduals(SimEditorChannelView &cv);
167 void UpdateChannelChi2(SimEditorChannelView &cv);
168
169 void SyncAllWidgets();
170 void SyncChannelWidget(Int_t ch_idx, Int_t param_idx);
171
172 void OnSliderMoved(Int_t ch_idx, Int_t param_idx);
173 void OnEntryChanged(Int_t ch_idx, Int_t param_idx);
174 void OnBoundsChanged(Int_t ch_idx, Int_t param_idx);
175 void OnFixToggled(Int_t ch_idx, Int_t param_idx);
176 void OnRangeChanged();
177
178 void DoRefit();
179 void DoAccept();
180 void DoCancel();
181 void DoReset();
182
183 // Re-tie each channel's linear-background slope lower bound to the current
184 // shared fit range so 1+slope*x stays positive across the whole window.
185 void ApplyBackgroundSlopeBounds();
186
187 // Debug aid: scan each channel's components for a non-finite normalization
188 // integral or a non-finite raw value across the range, to name the pdf
189 // behind an invalid NLL. Only called when fit_debug_ is set.
190 void DiagnoseInvalidComponents();
191
192 Int_t ValToSlider(Int_t ch_idx, Int_t param_idx, Double_t val);
193 Double_t SliderToVal(Int_t ch_idx, Int_t param_idx, Int_t pos);
194 Bool_t IsFixed(Int_t ch_idx, Int_t param_idx);
195 void GetDefaultBounds(Int_t ch_idx, Int_t param_idx, Double_t &lo,
196 Double_t &hi);
197 Int_t BkgConstIdx(Int_t ch_idx) { return channels_[ch_idx].num_peaks * 10; }
198 Int_t BkgSlopeIdx(Int_t ch_idx) {
199 return channels_[ch_idx].num_peaks * 10 + 1;
200 }
201 static Int_t PeakStyle(Int_t peak_idx);
202
203public:
220 const TGWindow *parent, RooSimultaneous *sim_pdf,
221 RooAbsData *combined_data, RooRealVar *x,
222 const std::vector<SimEditorChannelView> &channel_views,
223 Double_t range_low, Double_t range_high, const TString &info_label = "",
224 Bool_t fit_debug = kFALSE);
227
235 virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
246 virtual Bool_t HandleTimer(TTimer *timer);
248 virtual void CloseWindow();
249
252 Bool_t WasAccepted() const { return accepted_; }
254 Bool_t IsDone() const { return done_; }
257 TTimer *GetRedrawTimer() { return redraw_timer_; }
260 std::vector<SimEditorChannelView> *GetChannels() { return &channels_; }
261};
262
282 RooSimultaneous *sim_pdf, RooAbsData *combined_data, RooRealVar *x,
283 std::vector<SimEditorChannelView> &channel_views, Double_t range_low,
284 Double_t range_high, const TString &info_label, Bool_t fit_debug = kFALSE);
285
286#endif
Bool_t LaunchInteractiveSimultaneousFitEditor(RooSimultaneous *sim_pdf, RooAbsData *combined_data, RooRealVar *x, std::vector< SimEditorChannelView > &channel_views, Double_t range_low, Double_t range_high, const TString &info_label, Bool_t fit_debug=kFALSE)
Open the simultaneous editor and pump its event loop.
virtual void CloseWindow()
Window-manager close. Treated as a cancel, not an accept.
Bool_t WasAccepted() const
Whether the user accepted rather than cancelled.
std::vector< SimEditorChannelView > * GetChannels()
The per-channel views, carrying the edited parameters.
virtual Bool_t HandleTimer(TTimer *timer)
Redraw tick.
TTimer * GetRedrawTimer()
The coalescing redraw timer, for the driving event loop.
InteractiveSimultaneousFitEditor(const TGWindow *parent, RooSimultaneous *sim_pdf, RooAbsData *combined_data, RooRealVar *x, const std::vector< SimEditorChannelView > &channel_views, Double_t range_low, Double_t range_high, const TString &info_label="", Bool_t fit_debug=kFALSE)
Build the editor around a converged simultaneous model.
virtual ~InteractiveSimultaneousFitEditor()
Destroys the widgets and drawing objects the editor created.
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
ROOT GUI message dispatch for every widget in the editor.
Bool_t IsDone() const
Whether the editor has finished and the loop may exit.
The RooFit objects making up one channel's background.
Everything the simultaneous editor needs to show one channel.
std::vector< Double_t > original_bounds_high
std::vector< TGNumberEntry * > lo_bound_entries
std::vector< TGCheckButton * > fix_checks
Float_t display_bin_width_kev
Display bin width.
const std::vector< Double_t > * events
Event-level values behind hist, so the display can be rebinned live as the fit range changes.
RooAbsData * data
This channel's unbinned dataset.
RooFitBackgroundModel * bkg
Background model.
std::vector< Double_t > current_bounds_low
std::vector< Double_t > original_bounds_low
std::vector< Double_t > current_bounds_high
std::vector< TGNumberEntry * > hi_bound_entries
TH1 * hist
Display histogram for this channel.
std::vector< TGNumberEntry * > value_entries
RooAbsPdf * pdf
This channel's summed model.
std::vector< RooRealVar * > params
Int_t num_peaks
Peaks in this channel.
std::vector< RooFitPeakModel > * peaks
Per-peak parameter models.
TString name
Channel name, shown on the tab.