GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TBGSubtraction.h
Go to the documentation of this file.
1#ifndef TBGSUBTRACTION_H
2#define TBGSUBTRACTION_H
3#include "TF1.h"
4#include "TGButton.h"
5#include "TGDoubleSlider.h"
6#include "TGTripleSlider.h"
7#include "TGSlider.h"
8#include "TGToolTip.h"
9#include "TGNumberEntry.h"
10#include "TGLabel.h"
11#include "TGStatusBar.h"
12#include "TGFrame.h"
13#include "TGComboBox.h"
14#include "TRootEmbeddedCanvas.h"
15
16#include "TPeakFitter.h"
17#include "TSinglePeak.h"
18
19#include "TH1.h"
20#include "TH2.h"
21#include "GCanvas.h"
22#include "TFile.h"
23
24/** \addtogroup GUI
25 * @{
26 */
27
28/////////////////////////////////////////////////////////////////
29///
30/// \class TBGSubtraction
31///
32/// This class implements a GUI to perform projections of a 2D-Matrix
33/// with proper background subtraction.
34///
35/// There is a known issue that clicking on the close button of the
36/// window will cause a segmentation violation. If the class was
37/// created on the heap (using `new`), this will make it impossible
38/// to kill grsisort from within the terminal or sending it to the
39/// background. If the class was however created on the stack, this
40/// will simply crash grsisort. Because of this the recommended way
41/// to start it is using a line like `TBGSubtraction bg(<matrix-name>)`
42/// where bg is the variable name (can be any other valid c++ variable
43/// name), and <matrix-name> is the name of the 2D histogram (without
44/// any quotation marks).
45///
46/////////////////////////////////////////////////////////////////
47
48class TBGSubtraction : public TGMainFrame {
49 // these enums are used to communicate with ROOT classes
50 // since those classes take ints as arguments there isn't
51 // much gained by changing them to enum classes
78 enum EPeaks : std::uint8_t {
79 kGauss = 0,
82 kAB3Peak = 3
83 };
84
85 // RQ_OBJECT("TBGSubtraction")
86private:
87 TGMainFrame* fMain{nullptr};
88 TRootEmbeddedCanvas* fProjectionCanvas{nullptr};
89 TRootEmbeddedCanvas* fGateCanvas{nullptr};
90 TH2* fMatrix{nullptr};
91 TH1* fProjection{nullptr};
92 TH1* fGateHist{nullptr};
93 TH1* fBGHist1{nullptr};
94 TH1* fBGHist2{nullptr};
95 TH1* fSubtractedHist{nullptr};
96 TH1* fSubtractedBinHist{nullptr};
97 TGDoubleHSlider* fGateSlider{nullptr};
98 TGDoubleHSlider* fBGSlider1{nullptr};
99 TGDoubleHSlider* fBGSlider2{nullptr};
100 TGTripleHSlider* fPeakSlider{nullptr};
101 TGHSlider* fBinningSlider{nullptr};
102 TGNumberEntry* fBGParamEntry{nullptr};
103 TGNumberEntry* fBGEntryLow1{nullptr};
104 TGNumberEntry* fBGEntryHigh1{nullptr};
105 TGNumberEntry* fBGEntryLow2{nullptr};
106 TGNumberEntry* fBGEntryHigh2{nullptr};
107 TGNumberEntry* fGateEntryLow{nullptr};
108 TGNumberEntry* fGateEntryHigh{nullptr};
109 TGLabel* fBGParamLabel{nullptr};
110 TGLabel* fBinningLabel{nullptr};
111 TGCheckButton* fBGCheckButton1{nullptr};
112 TGCheckButton* fBGCheckButton2{nullptr};
113 TGCheckButton* fAutoUpdateCheckButton{nullptr};
114
115 TGLayoutHints* fBly{nullptr};
116 TGLayoutHints* fBly1{nullptr};
117 TGLayoutHints* fLayoutCanvases{nullptr};
118 TGLayoutHints* fLayoutParam{nullptr};
119
120 TGTextEntry* fWrite2FileName{nullptr};
121 TGTextEntry* fHistogramDescription{nullptr};
122 TGTextButton* fWrite2FileButton{nullptr};
123 TGTextButton* fPeakFitButton{nullptr};
124
125 // Status Bars
126 TGStatusBar* fProjectionStatus{nullptr};
127
128 // Frames
129 TGVerticalFrame* fGateFrame{nullptr};
130 TGVerticalFrame* fProjectionFrame{nullptr};
131 TGHorizontalFrame* fPeakFitFrame{nullptr};
132 TGHorizontalFrame* fBinningFrame{nullptr};
133 TGHorizontalFrame* fBGParamFrame{nullptr};
134 TGHorizontalFrame* fGateEntryFrame{nullptr};
135 TGHorizontalFrame* fBGEntryFrame1{nullptr};
136 TGHorizontalFrame* fBGEntryFrame2{nullptr};
137 TGHorizontalFrame* fDescriptionFrame{nullptr};
138 TGHorizontalFrame* fButtonFrame{nullptr};
139
140 // Combo box
141 TGComboBox* fAxisCombo{nullptr};
142 TGComboBox* fPeakCombo{nullptr};
143
144 // Markers
154
155 TFile* fCurrentFile{nullptr};
156
157 Int_t fGateAxis{0};
158
159 Bool_t fForceUpdate{true};
160 Double_t fPeakLowLimit{0.}; ///< lower limit for peak slider range
161 Double_t fPeakHighLimit{0.}; ///< upper limit for peak slider range
162 Double_t fPeakLowValue{0.}; ///< low range for fit
163 Double_t fPeakHighValue{0.}; ///< high range for fit
164 Double_t fPeakValue{0.}; ///< centroid for fit
165
166 TSinglePeak* fPeak{nullptr}; ///< the peak to be fit (will be a class that inherits from TSinglePeak)
167 TPeakFitter* fPeakFitter{nullptr}; ///< the peak fitter that fPeak is added to
168
169 Int_t fMaxBinning{20}; ///< maximum binning possible with binning slider (hard-coded, for now?)
170
171public:
172 explicit TBGSubtraction(TH2* mat, const char* gate_axis = "x", int maxBinning = 20);
176
179
180 void AxisComboSelected();
181 void PeakComboSelected();
182 void ClickedBGButton1();
184 // void ClickedBG2Button();
185 void DoPeakFit();
186 void DoSlider(Int_t pos = 0);
187 void DoEntry(Long_t);
189 void DoGateCanvasZoomed();
191 void UpdateBackground();
192 void UpdatePeakSliders();
193 // void DoProjection();
194 void DrawOnNewCanvas();
195 void DrawAllMarkers();
196 void DrawGateMarkers();
197 void DrawBGMarkers1();
198 void DrawBGMarkers2();
199 void DrawPeakMarkers();
200 void DrawPeak();
201 void WriteHistograms();
202 void GateStatusInfo(Int_t event, Int_t px, Int_t py, TObject* selected);
203 void ProjectionStatusInfo(Int_t event, Int_t px, Int_t py, TObject* selected);
204
205 void MakeGateHisto();
206 void MakeBGHisto1();
207 void MakeBGHisto2();
208 void DoAllGates();
209
210 void DoGateProjection();
212
213private:
214 void BuildInterface();
215 void ResetInterface();
216 void MakeConnections();
217 void Disconnect();
218 void InitializeInterface();
219 void StatusInfo(Int_t event, Int_t px, Int_t py, TObject* selected);
220 void DrawBGMarkers(TGCheckButton*& check_button, GMarker*& low_marker, GMarker*& high_marker, TGNumberEntry*& low_entry, TGNumberEntry*& high_entry, Color_t color = kBlue);
221 void UpdateGateSlider();
222 void UpdateBGSlider1();
223 void UpdateBGSlider2();
224 void UpdateBinningSlider();
225 void RebinProjection();
226
227 /// \cond CLASSIMP
228 ClassDefOverride(TBGSubtraction, 7) // NOLINT(readability-else-after-return)
229 /// \endcond
230};
231/*! @} */
232
233#endif
TH2D * mat
Definition UserFillObj.h:12
TSinglePeak * fPeak
the peak to be fit (will be a class that inherits from TSinglePeak)
TGNumberEntry * fBGEntryHigh1
TPeakFitter * fPeakFitter
the peak fitter that fPeak is added to
TGNumberEntry * fGateEntryLow
TRootEmbeddedCanvas * fProjectionCanvas
TGHorizontalFrame * fButtonFrame
TBGSubtraction(TBGSubtraction &&)=delete
TGComboBox * fPeakCombo
Double_t fPeakLowLimit
lower limit for peak slider range
TGVerticalFrame * fProjectionFrame
void DoProjectionCanvasZoomed()
TGHSlider * fBinningSlider
TGDoubleHSlider * fBGSlider2
GMarker * fLowBGMarker2
TGCheckButton * fBGCheckButton1
TGNumberEntry * fBGEntryHigh2
TGTextEntry * fWrite2FileName
GMarker * fPeakMarker
void UpdateProjectionSliders()
TGTextButton * fWrite2FileButton
TGCheckButton * fAutoUpdateCheckButton
GMarker * fHighGateMarker
void StatusInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
TGNumberEntry * fBGEntryLow2
void SetStatusFromUpdateCheckButton()
TGHorizontalFrame * fPeakFitFrame
TBGSubtraction(TH2 *mat, const char *gate_axis="x", int maxBinning=20)
TGDoubleHSlider * fBGSlider1
TGLayoutHints * fBly
TGHorizontalFrame * fBGEntryFrame1
TBGSubtraction(const TBGSubtraction &)=delete
TGHorizontalFrame * fDescriptionFrame
TGHorizontalFrame * fBinningFrame
TGStatusBar * fProjectionStatus
TGHorizontalFrame * fBGParamFrame
void DrawBGMarkers(TGCheckButton *&check_button, GMarker *&low_marker, GMarker *&high_marker, TGNumberEntry *&low_entry, TGNumberEntry *&high_entry, Color_t color=kBlue)
Int_t fMaxBinning
maximum binning possible with binning slider (hard-coded, for now?)
TGTextEntry * fHistogramDescription
TGTextButton * fPeakFitButton
TGLabel * fBinningLabel
Double_t fPeakHighLimit
upper limit for peak slider range
GMarker * fHighBGMarker2
TGDoubleHSlider * fGateSlider
TGComboBox * fAxisCombo
TGLayoutHints * fLayoutCanvases
TGLayoutHints * fLayoutParam
TGNumberEntry * fBGParamEntry
GMarker * fLowPeakMarker
void ProjectionStatusInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
void ClickedBGButton2()
TGNumberEntry * fBGEntryLow1
TBGSubtraction & operator=(const TBGSubtraction &)=delete
GMarker * fHighPeakMarker
GMarker * fHighBGMarker1
GMarker * fLowGateMarker
TGCheckButton * fBGCheckButton2
GMarker * fLowBGMarker1
Double_t fPeakValue
centroid for fit
TRootEmbeddedCanvas * fGateCanvas
Double_t fPeakHighValue
high range for fit
void DoEntry(Long_t)
TGLabel * fBGParamLabel
TGTripleHSlider * fPeakSlider
TGHorizontalFrame * fGateEntryFrame
void GateStatusInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
Double_t fPeakLowValue
low range for fit
TGNumberEntry * fGateEntryHigh
TGLayoutHints * fBly1
void DoSlider(Int_t pos=0)
TGVerticalFrame * fGateFrame
TBGSubtraction & operator=(TBGSubtraction &&)=delete
TGMainFrame * fMain
TGHorizontalFrame * fBGEntryFrame2