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