Analysis-Utilities 26.9.9
C++/ROOT utilities for nuclear measurement data analysis
Loading...
Searching...
No Matches
InteractiveFitEditor.hpp
Go to the documentation of this file.
1#ifndef INTERACTIVEFITEDITOR_H
2#define INTERACTIVEFITEDITOR_H
3
4#include "FittingUtils.hpp"
5#include <TCanvas.h>
6#include <TGButton.h>
7#include <TGClient.h>
8#include <TGDoubleSlider.h>
9#include <TGFrame.h>
10#include <TGLabel.h>
11#include <TGNumberEntry.h>
12#include <TGSlider.h>
13#include <TGTab.h>
14#include <TGraph.h>
15#include <TLatex.h>
16#include <TMath.h>
17#include <TPad.h>
18#include <TRootEmbeddedCanvas.h>
19#include <TSystem.h>
20#include <TTimer.h>
21#include <iostream>
22
39class InteractiveFitEditor : public TGMainFrame {
40private:
41 static const Int_t kSliderRes = 10000;
42 static const Int_t kNDrawPts = 500;
43
44 static const Int_t kBtnRefit = 1000;
45 static const Int_t kBtnAccept = 1001;
46 static const Int_t kBtnCancel = 1002;
47 static const Int_t kBtnReset = 1003;
48 static const Int_t kSliderBase = 2000;
49 static const Int_t kEntryBase = 3000;
50 static const Int_t kFixBase = 4000;
51 static const Int_t kLoBoundBase = 5000;
52 static const Int_t kHiBoundBase = 6000;
53 static const Int_t kRangeSlider = 7000;
54 static const Int_t kRangeLoEntry = 7001;
55 static const Int_t kRangeHiEntry = 7002;
56
57 TH1 *hist_;
58 TF1 *fit_func_;
59 TString info_label_text_;
60 Double_t range_low_;
61 Double_t range_high_;
62 Double_t original_range_low_;
63 Double_t original_range_high_;
64 Double_t hist_x_min_;
65 Double_t hist_x_max_;
66 Int_t num_peaks_;
67 Int_t num_params_;
68
69 Double_t *original_params_;
70 Double_t *original_bounds_low_;
71 Double_t *original_bounds_high_;
72 Bool_t *original_fixed_;
73
74 Double_t *current_bounds_low_;
75 Double_t *current_bounds_high_;
76
77 TRootEmbeddedCanvas *embedded_canvas_;
78 TPad *main_pad_;
79 TPad *residual_pad_;
80
81 TGHSlider **sliders_;
82 TGNumberEntry **value_entries_;
83 TGCheckButton **fix_checks_;
84 TGNumberEntry **lo_bound_entries_;
85 TGNumberEntry **hi_bound_entries_;
86
87 TGDoubleHSlider *range_slider_;
88 TGNumberEntry *range_lo_entry_;
89 TGNumberEntry *range_hi_entry_;
90
91 TH1 *hist_draw_;
92 TGraph *comp_graphs_[3][4];
93 TF1 *bkg_draw_;
94 TGraph *res_graph_;
95 TF1 *zero_line_;
96 TF1 *plus3_line_;
97 TF1 *minus3_line_;
98 TLatex *chi2_label_;
99 Int_t n_res_points_;
100
101 Bool_t needs_redraw_;
102 Bool_t accepted_;
103 Bool_t done_;
104 Bool_t syncing_;
105 TTimer *redraw_timer_;
106
107 void BuildGUI();
108 void BuildPeakTab(TGCompositeFrame *parent, Int_t peak_idx);
109 void BuildBackgroundTab(TGCompositeFrame *parent);
110 void AddParamRow(TGCompositeFrame *parent, Int_t param_idx, const char *name);
111
112 void InitDrawing();
113 void UpdateCanvas();
114 void UpdateCompPoints();
115 void UpdateResPoints();
116
117 void SyncAllWidgets();
118 void SyncWidget(Int_t param_idx);
119
120 void OnSliderMoved(Int_t param_idx);
121 void OnEntryChanged(Int_t param_idx);
122 void OnBoundsChanged(Int_t param_idx);
123 void OnFixToggled(Int_t param_idx);
124 void OnRangeChanged();
125
126 void DoRefit();
127 void DoAccept();
128 void DoCancel();
129 void DoReset();
130
131 Int_t ValToSlider(Int_t param_idx, Double_t val);
132 Double_t SliderToVal(Int_t param_idx, Int_t pos);
133 Bool_t IsFixed(Int_t param_idx);
134 void GetDefaultBounds(Int_t param_idx, Double_t &lo, Double_t &hi);
135 Int_t BkgConstIdx() { return num_peaks_ * 10; }
136 Int_t BkgSlopeIdx() { return num_peaks_ * 10 + 1; }
137 static Int_t PeakStyle(Int_t peak_idx);
138
139public:
150 InteractiveFitEditor(const TGWindow *parent, TH1 *hist, TF1 *fit_func,
151 Double_t range_low, Double_t range_high, Int_t num_peaks,
152 const TString &info_label = "");
154 virtual ~InteractiveFitEditor();
155
163 virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
174 virtual Bool_t HandleTimer(TTimer *timer);
176 virtual void CloseWindow();
177
180 Bool_t WasAccepted() const { return accepted_; }
182 Bool_t IsDone() const { return done_; }
185 TTimer *GetRedrawTimer() { return redraw_timer_; }
188 TRootEmbeddedCanvas *GetEmbeddedCanvas() { return embedded_canvas_; }
189};
190
208Bool_t LaunchInteractiveFitEditor(TH1 *hist, TF1 *fit_func, Double_t range_low,
209 Double_t range_high, Int_t num_peaks,
210 const TString &info_label);
211
212#endif
Binned chi-squared photopeak fitting on a TF1 + Minuit2 backend.
Bool_t LaunchInteractiveFitEditor(TH1 *hist, TF1 *fit_func, Double_t range_low, Double_t range_high, Int_t num_peaks, const TString &info_label)
Open the editor and pump its event loop until the user is done.
virtual ~InteractiveFitEditor()
Destroys the widgets and drawing objects the editor created.
TRootEmbeddedCanvas * GetEmbeddedCanvas()
The canvas holding the fit and residual pads.
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
ROOT GUI message dispatch for every widget in the editor.
virtual void CloseWindow()
Window-manager close. Treated as a cancel, not an accept.
Bool_t IsDone() const
Whether the editor has finished and the loop may exit.
TTimer * GetRedrawTimer()
The coalescing redraw timer, for the driving event loop.
InteractiveFitEditor(const TGWindow *parent, TH1 *hist, TF1 *fit_func, Double_t range_low, Double_t range_high, Int_t num_peaks, const TString &info_label="")
Build the editor around an existing histogram and fit function.
virtual Bool_t HandleTimer(TTimer *timer)
Redraw tick.
Bool_t WasAccepted() const
Whether the user accepted rather than cancelled.