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