GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TSourceCalibration.h
Go to the documentation of this file.
1#ifndef TSOURCECALIBRATION_H
2#define TSOURCECALIBRATION_H
3
4#include <cstdarg>
5#include <iostream>
6#include <vector>
7#include <string>
8#include <thread>
9#include <mutex>
10
11#include "TFile.h"
12#include "TCanvas.h"
13#include "TPad.h"
14#include "TLegend.h"
15#include "TGFrame.h"
16#include "TGTab.h"
17#include "TGFSComboBox.h"
18#include "TGStatusBar.h"
19#include "TGButtonGroup.h"
20#include "TGButton.h"
21#include "TGNumberEntry.h"
22#include "TGLabel.h"
23#include "TGProgressBar.h"
24#include "TRootEmbeddedCanvas.h"
25#include "TH2.h"
26#include "TPaveText.h"
27#include "RVersion.h"
28
29#include "GPeak.h"
30#include "TSinglePeak.h"
31#include "TNucleus.h"
32#include "TCalibrationGraph.h"
33#include "GH1D.h"
34#include "Globals.h"
35#include "TRedirect.h"
36
37class TSourceTab;
38
39std::map<GPeak*, std::tuple<double, double, double, double>> Match(std::vector<GPeak*> peaks, std::vector<std::tuple<double, double, double, double>> sources, TSourceTab* sourceTab);
40std::map<GPeak*, std::tuple<double, double, double, double>> SmartMatch(std::vector<GPeak*> peaks, std::vector<std::tuple<double, double, double, double>> sources, TSourceTab* sourceTab);
41
42double Polynomial(double* x, double* par);
43
44bool FilledBin(TH2* matrix, const int& bin);
45
47
48class TChannelTab;
49
51public:
52 TSourceTab(TChannelTab* parent, TGCompositeFrame* frame, GH1D* projection, const double& sigma, const double& threshold, const double& peakRatio, std::vector<std::tuple<double, double, double, double>> sourceEnergy);
53 TSourceTab(const TSourceTab& rhs);
54 TSourceTab(TSourceTab&&) noexcept = default;
55 TSourceTab& operator=(const TSourceTab&) = default;
56 TSourceTab& operator=(TSourceTab&&) noexcept = default;
57 ~TSourceTab();
58
59 void MakeConnections();
60 void Disconnect();
61
62 void ProjectionStatus(Event_t* event);
63 void ProjectionStatus(Int_t event, Int_t px, Int_t py, TObject* selected);
64
65 void Add(std::map<GPeak*, std::tuple<double, double, double, double>> map);
66 void FindPeaks(const double& sigma, const double& threshold, const double& peakRatio, const bool& force = false, const bool& fast = true);
67
68 void SourceEnergy(std::vector<std::tuple<double, double, double, double>> val) { fSourceEnergy = std::move(val); }
69
70 void Status(const char* status, int position);
71
72 TGraphErrors* Data() const { return fData; }
73 TGraphErrors* Fwhm() const { return fFwhm; }
74 TRootEmbeddedCanvas* ProjectionCanvas() const { return fProjectionCanvas; }
75
76 void RemovePoint(Int_t px, Int_t py);
77 void RemoveResidualPoint(Int_t px, Int_t py);
78
79 void PrintLayout() const;
80
81private:
82 void BuildInterface();
83 void UpdateRegions();
84
85 // parent
87
88 // graphic elements
89 TGCompositeFrame* fSourceFrame{nullptr};
90 TRootEmbeddedCanvas* fProjectionCanvas{nullptr};
91 TGStatusBar* fSourceStatusBar{nullptr};
92
93 // storage elements
94 GH1D* fProjection{nullptr};
95 TGraphErrors* fData{nullptr};
96 TGraphErrors* fFwhm{nullptr};
97 double fSigma{2.};
98 double fThreshold{0.05};
99 double fPeakRatio{2.};
100 std::vector<GPeak*> fPeaks;
101 std::vector<std::tuple<double, double, double, double>> fSourceEnergy;
102 std::vector<std::pair<double, double>> fRegions;
103};
104
106public:
107 TChannelTab(TSourceCalibration* parent, std::vector<TNucleus*> nuclei, std::vector<GH1D*> projections, std::string name, TGCompositeFrame* frame, double sigma, double threshold, int degree, std::vector<std::vector<std::tuple<double, double, double, double>>> sourceEnergies, TGHProgressBar* progressBar);
108 TChannelTab(const TChannelTab&) = default;
109 TChannelTab(TChannelTab&&) noexcept = default;
110 TChannelTab& operator=(const TChannelTab&) = default;
111 TChannelTab& operator=(TChannelTab&&) noexcept = default;
112 ~TChannelTab();
113
114 void CreateSourceTab(size_t source);
115
116 void MakeConnections();
117 void Disconnect();
118
119 void CalibrationStatus(Int_t event, Int_t px, Int_t py, TObject* selected);
120 void SelectCanvas(Event_t* event);
121
122 void UpdateData();
123 void UpdateFwhm();
124 void UpdateChannel();
125 void SelectedTab(Int_t id);
126 void Write(TFile* output);
127 void Calibrate();
128 void Calibrate(const int& degree, const bool& force = false);
129 void FindPeaks(const double& sigma, const double& threshold, const double& peakRatio, const bool& force = false, const bool& fast = true);
130 TGTab* SourceTab() const { return fSourceTab; }
131 TGraphErrors* Data(int channelId) const { return fSources[channelId]->Data(); }
132 size_t NumberOfSources() const { return fSources.size(); }
133 std::string Name() const { return fName; }
134 int ActiveSourceTab() const { return fActiveSourceTab; }
136
137 static void ZoomX();
138 static void ZoomY();
139
140 void PrintLayout() const;
141
142private:
143 // graphic elements
144 TGCompositeFrame* fChannelFrame{nullptr}; ///< main frame of this tab
145 TGTab* fSourceTab{nullptr}; ///< tab for sources
146 std::vector<TSourceTab*> fSources; ///< tabs for all sources
147 TGTab* fCanvasTab{nullptr}; ///< tab for canvases (calibration with residuals, and FWHM)
148 TGCompositeFrame* fCalibrationFrame{nullptr}; ///< frame of tab with calibration
149 TRootEmbeddedCanvas* fCalibrationCanvas{nullptr};
150 TPad* fResidualPad{nullptr};
151 TPad* fCalibrationPad{nullptr};
152 TGStatusBar* fChannelStatusBar{nullptr};
153 TLegend* fLegend{nullptr};
154 TPaveText* fChi2Label{nullptr};
155 TGCompositeFrame* fFwhmFrame{nullptr}; ///< frame of tab with fwhm
156 TRootEmbeddedCanvas* fFwhmCanvas{nullptr};
157 TGHProgressBar* fProgressBar{nullptr};
158
159 // storage elements
160 TSourceCalibration* fParent; ///< the parent of this tab
161 std::vector<TNucleus*> fNuclei; ///< the source nucleus
162 std::vector<GH1D*> fProjections; ///< vector of all projections
163 std::string fName; ///< name of this tab
164 double fSigma{2.}; ///< the sigma used in the peak finder
165 double fThreshold{0.05}; ///< the threshold (relative to the largest peak) used in the peak finder
166 int fDegree{1}; ///< degree of polynomial function used to calibrate
167 std::vector<std::vector<std::tuple<double, double, double, double>>> fSourceEnergies; ///< vector with source energies and uncertainties
168 TCalibrationGraphSet* fData{nullptr}; ///< combined data from all sources
169 TCalibrationGraphSet* fFwhm{nullptr}; ///< combined fwhm from all sources
170 int fActiveSourceTab{0}; ///< id of the currently active source tab
171};
172
173class TSourceCalibration : public TGMainFrame {
174public:
175 TSourceCalibration(double sigma, double threshold, int degree, double peakRatio, int count...);
178 TSourceCalibration& operator=(const TSourceCalibration&) = delete;
179 TSourceCalibration& operator=(TSourceCalibration&&) noexcept = delete;
181
182 void SetSource(Int_t windowId, Int_t entryId);
183 void Start();
184
185 void LineHeight(const unsigned int& val)
186 {
187 fLineHeight = val;
188 Resize(GetSize());
189 }
190
191 void Navigate(Int_t id);
192 void Calibrate();
193 void FindPeaks();
194 void FindPeaksFast();
195 void SelectedTab(Int_t id);
196
197 void NavigateFinal(Int_t id);
198 void FitFinal(const int& channelId);
199 void SelectedFinalTab(Int_t id);
200 void SelectedFinalMainTab(Int_t id);
201 void UpdateChannel(const int& channelId);
202 void WriteCalibration();
203
204 double Sigma() { return fSigmaEntry->GetNumber(); }
205 double Threshold() { return fThresholdEntry->GetNumber(); }
206 int Degree()
207 {
208 if(fDegreeEntry != nullptr) { fDefaultDegree = static_cast<int>(fDegreeEntry->GetNumber()); }
209 return fDefaultDegree;
210 }
211 double PeakRatio()
212 {
213 if(fPeakRatioEntry != nullptr) { fDefaultPeakRatio = fPeakRatioEntry->GetNumber(); }
214 return fDefaultPeakRatio;
215 }
216 bool WriteNonlinearities() { return fWriteNonlinearities->IsDown(); }
217 std::vector<std::tuple<double, double, double, double>> SourceEnergy(const size_t& i) { return fSourceEnergy.at(i); }
218 void CalibrationStatus(Int_t event, Int_t px, Int_t py, TObject* selected);
219
220 using TGWindow::HandleTimer;
221 void HandleTimer();
222 void SecondWindow();
224
225 static void PanelWidth(int val) { fPanelWidth = val; }
226 static void PanelHeight(int val) { fPanelHeight = val; }
227 static void StatusbarHeight(int val) { fStatusbarHeight = val; }
228
229 static int PanelWidth() { return fPanelWidth; }
230 static int PanelHeight() { return fPanelHeight; }
231 static int StatusbarHeight() { return fStatusbarHeight; }
232
233 // no getters for these as they are only used in this class
234 static void ParameterHeight(int val) { fParameterHeight = val; }
235 static void SourceboxWidth(int val) { fSourceboxWidth = val; }
236 static void DigitWidth(int val) { fDigitWidth = val; }
237
238 static void VerboseLevel(EVerbosity val) { fVerboseLevel = val; }
240
241 static void LogFile(std::string val) { fLogFile = std::move(val); }
242 static std::string LogFile() { return fLogFile; }
243
244 static void MaxIterations(int val) { fMaxIterations = val; }
245 static int MaxIterations() { return fMaxIterations; }
246
247 static void ZoomX();
248
249 void PrintLayout() const;
250
251private:
271
272 void BuildFirstInterface();
274 void DisconnectFirst();
275 void DeleteFirst();
278 void AcceptChannel(const int& channelId = -1);
279 void DisconnectSecond();
283 void AcceptFinalChannel(const int& channelId = -1);
285 void DeleteElement(TGFrame* element);
286
287 //TGHorizontalFrame* fTopFrame{nullptr};
288 TGHorizontalFrame* fBottomFrame{nullptr};
289 TGVerticalFrame* fLeftFrame{nullptr};
290 TGVerticalFrame* fRightFrame{nullptr};
291 TGTextButton* fStartButton{nullptr};
292 TGTab* fTab{nullptr};
293 std::vector<TChannelTab*> fChannelTab;
294
295 TGTextButton* fEmitter{nullptr};
296 TGHButtonGroup* fNavigationGroup{nullptr};
297 TGTextButton* fPreviousButton{nullptr};
298 TGTextButton* fCalibrateButton{nullptr};
299 TGTextButton* fFindPeaksButton{nullptr};
300 TGTextButton* fFindPeaksFastButton{nullptr};
301 TGTextButton* fDiscardButton{nullptr};
302 TGTextButton* fAcceptButton{nullptr};
303 TGTextButton* fAcceptAllButton{nullptr};
304 TGTextButton* fNextButton{nullptr};
305 TGGroupFrame* fParameterFrame{nullptr};
306 TGLabel* fSigmaLabel{nullptr};
307 TGNumberEntry* fSigmaEntry{nullptr};
308 TGLabel* fThresholdLabel{nullptr};
309 TGNumberEntry* fThresholdEntry{nullptr};
310 TGLabel* fDegreeLabel{nullptr};
311 TGNumberEntry* fDegreeEntry{nullptr};
312 TGLabel* fPeakRatioLabel{nullptr};
313 TGNumberEntry* fPeakRatioEntry{nullptr};
314 TGCheckButton* fWriteNonlinearities{nullptr};
315 TGHProgressBar* fProgressBar{nullptr};
316
317 std::vector<TGLabel*> fMatrixNames;
318 std::vector<TGComboBox*> fSourceBox;
319 std::vector<TNucleus*> fSource;
320 std::vector<std::vector<std::tuple<double, double, double, double>>> fSourceEnergy; ///< vector to hold source energy, energy uncertainty, intensity, and intensity uncertainty
321 std::vector<int> fActiveBins;
322 std::vector<int> fActualChannelId;
323 std::vector<const char*> fChannelLabel;
324
325 std::vector<TH2*> fMatrices;
326 int fNofBins{0}; ///< Number of filled bins in first matrix
327
328 static std::string fLogFile; ///< name of log file, if empty no log file is written
329
330 // graphic settings
331 unsigned int fLineHeight{20}; ///< Height of text boxes and progress bar
332 static int fPanelWidth; ///< Width of one panel
333 static int fPanelHeight; ///< Height of one panel
334 static int fStatusbarHeight; ///< Height of status bar (also extra height needed for tabs)
335 static int fParameterHeight; ///< Height of the frame for the parameters
336 static int fSourceboxWidth; ///< Width of the box to select which source each histogram is from
337 static int fDigitWidth; ///< Number of digits used for parameter entries (if they are floating point)
338
339 int fWaitMs{100}; ///< How many milliseconds we wait before we process the navigation input (to avoid double triggers?)
340
341 int fOldErrorLevel; ///< Used to store old value of gErrorIgnoreLevel (set to kError for the scope of the class)
342
343 double fDefaultSigma{2.}; ///< The default sigma used for the peak finding algorithm, can be changed later.
344 double fDefaultThreshold{0.05}; ///< The default threshold used for the peak finding algorithm, can be changed later. Co-56 source needs a much lower threshold, 0.01 or 0.02, but that makes it much slower too.
345 int fDefaultDegree{1}; ///< The default degree of the polynomial used for calibrating, can be changed later.
346 double fDefaultPeakRatio{2.}; ///< The default ratio between found peaks and peaks in the source (per region).
347 static int fMaxIterations; ///< Maximum iterations over combinations in Match and SmartMatch
348
349 TFile* fOutput{nullptr};
350
351 static EVerbosity fVerboseLevel; ///< Changes verbosity from 0 (quiet) to 4 (very verbose)
352
353 /// \cond CLASSIMP
354 ClassDefOverride(TSourceCalibration, 1) // NOLINT(readability-else-after-return)
355 /// \endcond
356};
357
358#endif
EVerbosity
Definition Globals.h:143
bool FilledBin(TH2 *matrix, const int &bin)
std::map< GPeak *, std::tuple< double, double, double, double > > Match(std::vector< GPeak * > peaks, std::vector< std::tuple< double, double, double, double > > sources, TSourceTab *sourceTab)
double Polynomial(double *x, double *par)
std::map< GPeak *, std::tuple< double, double, double, double > > SmartMatch(std::vector< GPeak * > peaks, std::vector< std::tuple< double, double, double, double > > sources, TSourceTab *sourceTab)
Definition GH1D.h:17
Definition GPeak.h:11
std::vector< GH1D * > fProjections
vector of all projections
double fThreshold
the threshold (relative to the largest peak) used in the peak finder
void PrintLayout() const
TGCompositeFrame * fChannelFrame
main frame of this tab
std::vector< TSourceTab * > fSources
tabs for all sources
TCalibrationGraphSet * fFwhm
combined fwhm from all sources
TGraphErrors * Data(int channelId) const
TChannelTab(TSourceCalibration *parent, std::vector< TNucleus * > nuclei, std::vector< GH1D * > projections, std::string name, TGCompositeFrame *frame, double sigma, double threshold, int degree, std::vector< std::vector< std::tuple< double, double, double, double > > > sourceEnergies, TGHProgressBar *progressBar)
TPaveText * fChi2Label
TGTab * fSourceTab
tab for sources
void SelectCanvas(Event_t *event)
void Write(TFile *output)
void CalibrationStatus(Int_t event, Int_t px, Int_t py, TObject *selected)
TSourceTab * SelectedSourceTab() const
static void ZoomY()
TGCompositeFrame * fCalibrationFrame
frame of tab with calibration
TSourceCalibration * fParent
the parent of this tab
std::vector< std::vector< std::tuple< double, double, double, double > > > fSourceEnergies
vector with source energies and uncertainties
int ActiveSourceTab() const
std::string Name() const
void CreateSourceTab(size_t source)
TGCompositeFrame * fFwhmFrame
frame of tab with fwhm
TRootEmbeddedCanvas * fFwhmCanvas
int fActiveSourceTab
id of the currently active source tab
std::string fName
name of this tab
void FindPeaks(const double &sigma, const double &threshold, const double &peakRatio, const bool &force=false, const bool &fast=true)
int fDegree
degree of polynomial function used to calibrate
static void ZoomX()
std::vector< TNucleus * > fNuclei
the source nucleus
void SelectedTab(Int_t id)
TGStatusBar * fChannelStatusBar
size_t NumberOfSources() const
TGTab * SourceTab() const
TGTab * fCanvasTab
tab for canvases (calibration with residuals, and FWHM)
TChannelTab(const TChannelTab &)=default
double fSigma
the sigma used in the peak finder
TChannelTab(TChannelTab &&) noexcept=default
TGHProgressBar * fProgressBar
TRootEmbeddedCanvas * fCalibrationCanvas
TCalibrationGraphSet * fData
combined data from all sources
unsigned int fLineHeight
Height of text boxes and progress bar.
int fWaitMs
How many milliseconds we wait before we process the navigation input (to avoid double triggers?...
TGTextButton * fPreviousButton
static std::string LogFile()
static int fStatusbarHeight
Height of status bar (also extra height needed for tabs)
TGVerticalFrame * fRightFrame
static std::string fLogFile
name of log file, if empty no log file is written
TGNumberEntry * fPeakRatioEntry
static void SourceboxWidth(int val)
TGCheckButton * fWriteNonlinearities
int fDefaultDegree
The default degree of the polynomial used for calibrating, can be changed later.
void NavigateFinal(Int_t id)
static EVerbosity VerboseLevel()
static void ZoomX()
TGGroupFrame * fParameterFrame
std::vector< TGLabel * > fMatrixNames
static void VerboseLevel(EVerbosity val)
TGTextButton * fCalibrateButton
TGTextButton * fAcceptAllButton
void AcceptChannel(const int &channelId=-1)
TGNumberEntry * fSigmaEntry
static void ParameterHeight(int val)
std::vector< std::tuple< double, double, double, double > > SourceEnergy(const size_t &i)
double fDefaultSigma
The default sigma used for the peak finding algorithm, can be changed later.
static int fMaxIterations
Maximum iterations over combinations in Match and SmartMatch.
TGTextButton * fFindPeaksFastButton
static void MaxIterations(int val)
double fDefaultPeakRatio
The default ratio between found peaks and peaks in the source (per region).
TGHProgressBar * fProgressBar
TSourceCalibration(const TSourceCalibration &)=delete
TGHButtonGroup * fNavigationGroup
TGNumberEntry * fThresholdEntry
void SetSource(Int_t windowId, Int_t entryId)
TGTextButton * fFindPeaksButton
void SelectedFinalMainTab(Int_t id)
void SelectedFinalTab(Int_t id)
std::vector< int > fActiveBins
TGTextButton * fDiscardButton
std::vector< TNucleus * > fSource
void CalibrationStatus(Int_t event, Int_t px, Int_t py, TObject *selected)
std::vector< const char * > fChannelLabel
std::vector< TChannelTab * > fChannelTab
static void LogFile(std::string val)
TGTextButton * fAcceptButton
TSourceCalibration(double sigma, double threshold, int degree, double peakRatio, int count...)
static int fPanelWidth
Width of one panel.
void BuildThirdInterface()
void UpdateChannel(const int &channelId)
static int fPanelHeight
Height of one panel.
void AcceptFinalChannel(const int &channelId=-1)
TSourceCalibration(TSourceCalibration &&) noexcept=delete
std::vector< TH2 * > fMatrices
void LineHeight(const unsigned int &val)
int fOldErrorLevel
Used to store old value of gErrorIgnoreLevel (set to kError for the scope of the class)
static int fDigitWidth
Number of digits used for parameter entries (if they are floating point)
std::vector< TGComboBox * > fSourceBox
std::vector< int > fActualChannelId
int fNofBins
Number of filled bins in first matrix.
void FitFinal(const int &channelId)
TGNumberEntry * fDegreeEntry
void DeleteElement(TGFrame *element)
static int fParameterHeight
Height of the frame for the parameters.
static void PanelWidth(int val)
std::vector< std::vector< std::tuple< double, double, double, double > > > fSourceEnergy
vector to hold source energy, energy uncertainty, intensity, and intensity uncertainty
static void StatusbarHeight(int val)
static int fSourceboxWidth
Width of the box to select which source each histogram is from.
TGTextButton * fStartButton
double fDefaultThreshold
The default threshold used for the peak finding algorithm, can be changed later. Co-56 source needs a...
void MakeThirdConnections()
TGTextButton * fNextButton
TGVerticalFrame * fLeftFrame
static void DigitWidth(int val)
static EVerbosity fVerboseLevel
Changes verbosity from 0 (quiet) to 4 (very verbose)
TGHorizontalFrame * fBottomFrame
static void PanelHeight(int val)
void RemovePoint(Int_t px, Int_t py)
void SourceEnergy(std::vector< std::tuple< double, double, double, double > > val)
TSourceTab(TSourceTab &&) noexcept=default
std::vector< GPeak * > fPeaks
void Status(const char *status, int position)
TGraphErrors * fFwhm
TGraphErrors * Fwhm() const
TRootEmbeddedCanvas * fProjectionCanvas
TSourceTab(TChannelTab *parent, TGCompositeFrame *frame, GH1D *projection, const double &sigma, const double &threshold, const double &peakRatio, std::vector< std::tuple< double, double, double, double > > sourceEnergy)
void FindPeaks(const double &sigma, const double &threshold, const double &peakRatio, const bool &force=false, const bool &fast=true)
std::vector< std::pair< double, double > > fRegions
void Add(std::map< GPeak *, std::tuple< double, double, double, double > > map)
void ProjectionStatus(Event_t *event)
TGCompositeFrame * fSourceFrame
TRootEmbeddedCanvas * ProjectionCanvas() const
TGraphErrors * Data() const
TChannelTab * fParent
TGraphErrors * fData
void RemoveResidualPoint(Int_t px, Int_t py)
std::vector< std::tuple< double, double, double, double > > fSourceEnergy
void PrintLayout() const
TGStatusBar * fSourceStatusBar