GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TEfficiencyCalibrator.h
Go to the documentation of this file.
1#ifndef TEFFICIENCYCALIBRATOR_H
2#define TEFFICIENCYCALIBRATOR_H
3
4#if __cplusplus >= 201703L
5
6#include <cstdarg>
7#include <vector>
8#include <string>
9
10#include "TFile.h"
11#include "TPad.h"
12#include "TLegend.h"
13#include "TGFrame.h"
14#include "TGTab.h"
15#include "TGStatusBar.h"
16#include "TGButtonGroup.h"
17#include "TGButton.h"
18#include "TGNumberEntry.h"
19#include "TGLabel.h"
20#include "TGProgressBar.h"
21#include "TGComboBox.h"
22#include "TRootEmbeddedCanvas.h"
23#include "TH1.h"
24#include "TH2.h"
25
26#include "Globals.h"
27#include "TNucleus.h"
28#include "TPeakFitter.h"
29#include "TSinglePeak.h"
30#include "TCalibrationGraph.h"
31
32/** \addtogroup Calibration
33 * @{
34 */
35
36class TEfficiencyCalibrator;
37class TEfficiencyDatatypeTab;
38
39class TEfficiencyTab {
40 /////////////////////////////////////////////////////////////////
41 ///
42 /// \class TEfficiencyTab
43 ///
44 /// This class is the innermost tab with one type of data for one
45 /// source. It automatically calculates the summing in and summing
46 /// out for all peaks defined in the TNucleus object provided to it
47 /// (if it can fit them in the singles spectrum with a large enough
48 /// area). Parameters for it are the range of the fits, the minimum
49 /// threshold for the area to be acceptablem, and the background
50 /// parameter.
51 ///
52 /////////////////////////////////////////////////////////////////
53public:
54 enum EPeakType : std::uint8_t { kRWPeak = 0,
55 kABPeak = 1,
56 kAB3Peak = 2,
57 kGauss = 3 };
58
59 TEfficiencyTab(TEfficiencyDatatypeTab* parent, TNucleus* nucleus, std::tuple<TH1*, TH1*, TH2*> hists, TGCompositeFrame* frame);
60 TEfficiencyTab(const TEfficiencyTab&) = default;
61 TEfficiencyTab(TEfficiencyTab&&) noexcept = default;
62 TEfficiencyTab& operator=(const TEfficiencyTab&) = default;
63 TEfficiencyTab& operator=(TEfficiencyTab&&) noexcept = default;
64 ~TEfficiencyTab() = default;
65
66 void FindPeaks();
67 TSinglePeak* NewPeak(const double& energy);
68 TSinglePeak* NewPeak(TSinglePeak* peak);
69 void Redraw();
70 void MakeConnections();
71 void Disconnect();
72 void Status(Int_t event, Int_t px, Int_t py, TObject* selected);
73
74 // getters
75 std::vector<std::tuple<TTransition*, double, double, double, double, double, double, double, double>> Peaks() const { return fPeaks; }
76 const char* GetName() const { return fNucleus->GetName(); }
77
78private:
79 void BuildInterface();
80
81 // graphic elements
82 TGCompositeFrame* fFrame{nullptr};
83 TGHorizontalFrame* fTopFrame{nullptr};
84 TRootEmbeddedCanvas* fProjectionCanvas{nullptr};
85 TGStatusBar* fStatusBar{nullptr};
86
87 // storage elements
88 TNucleus* fNucleus; ///< the source nucleus
89 TEfficiencyDatatypeTab* fParent; ///< the parent of this tab
90 TH1* fSingles{nullptr}; ///< the singles histogram we're using
91 TH1* fSummingOut{nullptr}; ///< the (mixed) matrix we're using for summing out
92 TH2* fSummingIn{nullptr}; ///< the sum matrix we're using for summing in
93 TPeakFitter fPeakFitter;
94 TPeakFitter fSummingOutPeakFitter;
95 std::vector<TH1*> fSummingInProj;
96 std::vector<TH1*> fSummingInProjBg;
97 std::vector<std::tuple<TTransition*, double, double, double, double, double, double, double, double>> fPeaks;
98 std::vector<TObject*> fFitFunctions; ///< vector with all fits of the singles histogram
99 std::vector<TObject*> fRemovedFitFunctions; ///< vector with all removed fits of the singles histogram
100};
101
102class TEfficiencyDatatypeTab {
103 /////////////////////////////////////////////////////////////////
104 ///
105 /// \class TEfficiencyDatatypeTab
106 ///
107 /// This class is the outer tab with all the sources data for one
108 /// data type (single/addback, suppressed/unsuppressed). It creates
109 /// the tabs for each source and has some navigational buttons.
110 ///
111 /////////////////////////////////////////////////////////////////
112public:
113 enum EEntry : std::uint8_t { kRangeEntry,
114 kThresholdEntry,
115 kBgParamEntry,
116 kCalibrationUncertaintyEntry,
117 kPeakTypeBox,
118 kDegreeEntry,
119 kPlotEfficiencyCheck,
120 kPlotUncorrEfficiencyCheck,
121 kPlotPeakAreaCheck,
122 kPlotSummingInCheck,
123 kPlotSummingOutCheck };
124
125 TEfficiencyDatatypeTab(TEfficiencyCalibrator* parent, std::vector<TNucleus*> nucleus, std::vector<std::tuple<TH1*, TH1*, TH2*>> hists, TGCompositeFrame* frame, const std::string& dataType, TGHProgressBar* progressBar);
126 TEfficiencyDatatypeTab(const TEfficiencyDatatypeTab&) = default;
127 TEfficiencyDatatypeTab(TEfficiencyDatatypeTab&&) noexcept = default;
128 TEfficiencyDatatypeTab& operator=(const TEfficiencyDatatypeTab&) = default;
129 TEfficiencyDatatypeTab& operator=(TEfficiencyDatatypeTab&&) noexcept = default;
130 ~TEfficiencyDatatypeTab();
131
132 void CreateTabs();
133 void MakeConnections();
134 void Disconnect();
135
136 void Status(Int_t event, Int_t px, Int_t py, TObject* selected);
137 void DrawGraph();
138 void UpdateEfficiencyGraph();
139 void UpdatePeakType();
140 void FitEfficiency();
141 void FittingControl(Int_t id);
142
143 int Degree();
144
145 TCalibrationGraphSet* EfficiencyGraph() { return fEfficiencyGraph; }
146
147 static double EfficiencyDebertin(double* x, double* par);
148 static double EfficiencyRadware(double* x, double* par);
149 static double EfficiencyPolynomial(double* x, double* par);
150
151private:
152 void ReadValues();
153
154 // graphic elements
155 TGCompositeFrame* fFrame{nullptr};
156 TGVerticalFrame* fLeftFrame{nullptr}; ///< Left frame for the source tabs
157 TGTab* fDataTab{nullptr}; ///< tab for channels
158 std::vector<TEfficiencyTab*> fEfficiencyTab;
159 TGGroupFrame* fFittingParameterFrame{nullptr};
160 TGLabel* fRangeLabel{nullptr};
161 TGNumberEntry* fRangeEntry{nullptr};
162 TGLabel* fBgParamLabel{nullptr};
163 TGNumberEntry* fBgParamEntry{nullptr};
164 TGLabel* fThresholdLabel{nullptr};
165 TGNumberEntry* fThresholdEntry{nullptr};
166 TGComboBox* fPeakTypeBox{nullptr};
167 TGHButtonGroup* fFittingControlGroup{nullptr};
168 TGTextButton* fRefitButton{nullptr};
169 TGTextButton* fRefitAllButton{nullptr};
170 TGVerticalFrame* fRightFrame{nullptr}; ///< Right frame for the efficiency data and fit
171 TRootEmbeddedCanvas* fEfficiencyCanvas{nullptr};
172 TLegend* fLegend{nullptr};
173 TGStatusBar* fStatusBar{nullptr};
174 TGGroupFrame* fGraphParameterFrame{nullptr};
175 TGLabel* fDegreeLabel{nullptr};
176 TGNumberEntry* fDegreeEntry{nullptr};
177 TGLabel* fCalibrationUncertaintyLabel{nullptr};
178 TGNumberEntry* fCalibrationUncertaintyEntry{nullptr};
179 TGGroupFrame* fPlotOptionFrame{nullptr};
180 TGCheckButton* fPlotEfficiencyCheck{nullptr};
181 TGCheckButton* fPlotUncorrEfficiencyCheck{nullptr};
182 TGCheckButton* fPlotPeakAreaCheck{nullptr};
183 TGCheckButton* fPlotSummingInCheck{nullptr};
184 TGCheckButton* fPlotSummingOutCheck{nullptr};
185 TGTextButton* fRecalculateButton{nullptr};
186
187 // storage elements
188 std::vector<TNucleus*> fNucleus; ///< the source nuclei
189 TEfficiencyCalibrator* fParent; ///< the parent of this tab
190 std::string fDataType; ///< data type of this tab
191 TCalibrationGraphSet* fEfficiencyGraph{nullptr}; ///< the combined efficiency graph from all sources
192 TCalibrationGraphSet* fUncorrEfficiencyGraph{nullptr}; ///< the combined uncorrected efficiency graph from all sources
193 TCalibrationGraphSet* fPeakAreaGraph{nullptr}; ///< the combined peak area graph from all sources
194 TCalibrationGraphSet* fSummingInGraph{nullptr}; ///< the combined summing in correction graph from all sources
195 TCalibrationGraphSet* fSummingOutGraph{nullptr}; ///< the combined summing out correction graph from all sources
196 TF1* fEfficiency{nullptr}; ///< fit of efficiency
197 TDirectory* fMainDirectory{nullptr}; ///< main directory (should be the file we're writing to)
198 TDirectory* fSubDirectory{nullptr}; ///< subdirectory this tab writes the graphs to
199};
200
201class TEfficiencyCalibrator : public TGMainFrame {
202 /////////////////////////////////////////////////////////////////
203 ///
204 /// \class TEfficiencyCalibrator
205 ///
206 /// This is a class that determines the efficiency from source
207 /// data.
208 /// It expects a list of files with a 1D singles histogram and
209 /// 2D histograms of energy vs. (suppressed) energy and
210 /// energy vs. sum of energies. In case of suppressed data only the
211 /// x-axis of the former 2D histogram should use suppressed data,
212 /// the y-axis needs to be unsuppressed data!
213 /// These kinds of files are created by the SummingCorrectionsHelper.cxx
214 /// in the examples folder.
215 /// If the file name contains a source isotope at the beginning of
216 /// the name, the source selection will be automatic, otherwise
217 /// a window will pop up with the option to select the isotope for
218 /// each file.
219 ///
220 /// The efficiency curves can be:
221 /// e(E) = ln E + (ln E)/E + (ln E)^2/E + (ln E)^3/E + (ln E)^4/E,
222 /// or the radware form
223 /// ln(e(E)) = ((a1 + a2 x + a3 x^2)^-a7 + (a4 + a5 y + a6 y^2)^-a7)^-1/a7
224 /// with x = ln(E/100), y = ln(E/1000)
225 /// or a polynomial ln(e(E)) = sum i 0->8 a_i (ln(E))^i (Ryan's & Andrew's PhD theses)
226 ///
227 /////////////////////////////////////////////////////////////////
228
229public:
230 enum ESources : std::uint8_t { k22Na,
231 k56Co,
232 k60Co,
233 k133Ba,
234 k152Eu,
235 k241Am };
236 enum EEntry : std::uint16_t { kStartButton = 0,
237 kSourceBox = 100,
238 kSigmaEntry = 200,
239 kThresholdEntry = 300 };
240
241 explicit TEfficiencyCalibrator(int n...);
242 TEfficiencyCalibrator(const TEfficiencyCalibrator&) = delete;
243 TEfficiencyCalibrator(TEfficiencyCalibrator&&) noexcept = delete;
244 TEfficiencyCalibrator& operator=(const TEfficiencyCalibrator&) = delete;
245 TEfficiencyCalibrator& operator=(TEfficiencyCalibrator&&) noexcept = delete;
246 ~TEfficiencyCalibrator();
247
248 void SetSource(Int_t windowId, Int_t entryId);
249 void Start();
250
251 void LineHeight(const unsigned int& val)
252 {
253 fLineHeight = val;
254 Resize(GetSize());
255 }
256
257 using TGWindow::HandleTimer;
258 void HandleTimer();
259 void SecondWindow();
260
261 static void Range(const double& val) { fRange = val; }
262 static void Threshold(const double& val) { fThreshold = val; }
263 static void BgParam(const int& val) { fBgParam = val; }
264 static void PeakType(const TEfficiencyTab::EPeakType& val) { fPeakType = val; }
265 static void Degree(const int& val) { fDegree = val; }
266 static void CalibrationUncertainty(const double& val) { fCalibrationUncertainty = val; }
267 static void ShowRemovedFits(const bool& val) { fShowRemovedFits = val; }
268
269 static double Range() { return fRange; }
270 static double Threshold() { return fThreshold; }
271 static int BgParam() { return fBgParam; }
272 static TEfficiencyTab::EPeakType PeakType() { return fPeakType; }
273 static int Degree() { return fDegree; }
274 static double CalibrationUncertainty() { return fCalibrationUncertainty; }
275 static bool ShowRemovedFits() { return fShowRemovedFits; }
276
277 static int LineHeight() { return fLineHeight; }
278 static int WindowWidth() { return fWindowWidth; }
279
280 static EVerbosity VerboseLevel() { return fVerboseLevel; }
281 static void VerboseLevel(EVerbosity val) { fVerboseLevel = val; }
282
283 std::vector<TCalibrationGraphSet*> EfficiencyGraphs() { return fEfficiencyGraph; }
284 size_t NumberOfEfficiencyGraphs() { return fEfficiencyGraph.size(); }
285 TCalibrationGraphSet* EfficiencyGraph(size_t i) { return fEfficiencyGraph.at(i); }
286
287private:
288 void DeleteElement(TGFrame* element);
289 void BuildFirstInterface();
290 void MakeFirstConnections();
291 void DisconnectFirst();
292 void DeleteFirst();
293 void BuildSecondInterface();
294 void MakeSecondConnections();
295 void DisconnectSecond();
296
297 static EVerbosity fVerboseLevel; ///< Changes verbosity from 0 (quiet) to 4 (very verbose)
298 static double fRange;
299 static double fThreshold;
300 static int fBgParam; ///< the bg parameter used to determine the background in the gamma spectra
301 static TEfficiencyTab::EPeakType fPeakType; ///< peak type used for fitting
302 static int fDegree; ///< degree of fit function (0 = debertin form, 1 = radware form, everything else polynomial ln(e(E)) = sum i 0->8 a_i (ln(E))^i (Ryan's & Andrew's PhD theses)
303 static double fCalibrationUncertainty; ///< calibration uncertainty (peaks are rejected if the centroid and energy difference is larger than centroid and energy uncertainties plus this)
304 static bool fShowRemovedFits; ///< flag to toggle whether removed fits are shown on the plot or not
305 std::vector<TFile*> fFiles;
306 std::vector<TNucleus*> fSources;
307 std::vector<std::string> fDataType; ///< type of each data set
308 std::vector<std::vector<std::tuple<TH1*, TH1*, TH2*>>> fHistograms; ///< for each type of data (suppressed, addback) in the file a vector with three histograms for each source
309 std::vector<TEfficiencyDatatypeTab*> fEfficiencyDatatypeTab;
310 std::vector<TCalibrationGraphSet*> fEfficiencyGraph;
311 TFile* fOutput{nullptr};
312
313 TGTextButton* fEmitter{nullptr};
314
315 static unsigned int fLineHeight; ///< Height of text boxes and progress bar
316 static unsigned int fWindowWidth; ///< Width of window
317
318 // graphic elements
319 std::vector<TGLabel*> fSourceLabel;
320 std::vector<TGComboBox*> fSourceBox;
321 TGTab* fDatatypeTab{nullptr};
322 TGHProgressBar* fProgressBar{nullptr};
323 TGTextButton* fStartButton{nullptr};
324
325 /// \cond CLASSIMP
326 ClassDefOverride(TEfficiencyCalibrator, 1) // NOLINT(readability-else-after-return)
327 /// \endcond
328};
329/*! @} */
330#endif
331#endif
EVerbosity
Definition Globals.h:143