GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TEnergyCal.cxx
Go to the documentation of this file.
1#include "TEnergyCal.h"
2
4{
5 // Default Constructor
7}
8
10{
11 // Sets the default titles of the TGraph in the TEnergyCal
12 SetTitle("Energy Calibration");
13 GetYaxis()->SetTitle("Accepted Energy (keV)");
14 GetXaxis()->SetTitle("Measured Centroid");
15 GetYaxis()->CenterTitle();
16 GetXaxis()->CenterTitle();
17}
18
19std::vector<Double_t> TEnergyCal::GetParameters() const
20{
21 // WILL NEED TO CHANGE THIS APPROPRIATELY
22 Int_t nParams = GetFunction("energy")->GetNpar();
23 std::vector<Double_t> paramList(nParams);
24
25 for(int i = 0; i < nParams; i++) {
26 paramList[i] = GetParameter(i);
27 }
28
29 return paramList;
30}
31
32Double_t TEnergyCal::GetParameter(size_t parameter) const
33{
34 // WILL NEED TO CHANGE THIS APPROPRIATELY
35 return GetFunction("gain")->GetParameter(parameter); // Root does all of the checking for us.
36}
37
38void TEnergyCal::SetNucleus(TNucleus* nuc, Option_t* opt)
39{
40 // Sets the nucleus of the TEnergyCal. This function sets the data points
41 // of the TEnergyCal automatically with the provided nucleus
42 TString optstr = opt;
43 optstr.ToUpper();
44 if((GetNucleus() == nullptr) || optstr.Contains("F")) {
45 TGraphErrors::Clear();
47 for(int i = 0; i < GetNucleus()->NTransitions(); i++) {
48 TGraphErrors::SetPoint(i, 0.0, GetNucleus()->GetTransition(i)->GetEnergy());
49 TGraphErrors::SetPointError(i, 0.0, GetNucleus()->GetTransition(i)->GetEnergyUncertainty());
50 }
51 } else if(GetNucleus() != nullptr) {
52 std::cout << "Nucleus already exists. Use \"F\" option to overwrite" << std::endl;
53 }
54
56 // Sort();
57}
58
59void TEnergyCal::AddPoint(Double_t measured, Double_t accepted, Double_t measuredUncertainty,
60 Double_t acceptedUncertainty)
61{
62 // Add a point to the TEnergyCal. The points are sorted by increasing measured centroid.
63 Int_t point = GetN();
64 TGraphErrors::SetPoint(point, measured, accepted);
65 TGraphErrors::SetPointError(point, measuredUncertainty, acceptedUncertainty);
66 // Sort();
67}
68
69Bool_t TEnergyCal::SetPoint(Int_t idx, Double_t measured)
70{
71 // Sets the data point at index idx.
72 if(GetNucleus() == nullptr) {
73 std::cout << "No nucleus set yet..." << std::endl;
74 return false;
75 }
76
77 Double_t x = 0.;
78 Double_t y = 0.;
79 Double_t dx = 0.;
80 Double_t dy = 0.;
81 GetPoint(idx, x, y);
82 dx = GetErrorX(idx);
83 dy = GetErrorY(idx);
84 TGraphErrors::SetPoint(idx, measured, y);
85 TGraphErrors::SetPointError(idx, dx, dy);
86
87 return true;
88}
89
90Bool_t TEnergyCal::SetPoint(Int_t idx, TPeak* peak)
91{
92 // Sets the data point at index idx using the centroid, and sigma of a fitted TPeak.
93 if(peak == nullptr) {
94 std::cout << "No Peak, pointer is null" << std::endl;
95 return false;
96 }
97 Double_t centroid = peak->GetCentroid();
98 Double_t dCentroid = peak->GetCentroidErr();
99
100 SetPoint(idx, centroid);
101 return SetPointError(idx, dCentroid);
102}
103
104Bool_t TEnergyCal::SetPointError(Int_t idx, Double_t measuredUncertainty)
105{
106 // Sets the measured Error of the data point at index idx.
107 if(GetNucleus() == nullptr) {
108 std::cout << "No nucleus set yet..." << std::endl;
109 return false;
110 }
111
112 TGraphErrors::SetPointError(idx, measuredUncertainty, GetErrorX(idx));
113 // Sort();
114
115 return true;
116}
117
119{
120 // Write the energy calibration information to the current TChannel.
121 if(GetChannel() == nullptr) {
122 Error("WriteToChannel", "No Channel Set");
123 return;
124 }
126 std::cout << "Writing to channel " << GetChannel()->GetNumber() << std::endl;
127 std::cout << "p0 = " << GetParameter(0) << " \t p1 = " << GetParameter(1) << std::endl;
128 // Set the energy parameters based on the fitted calibration.
129 GetChannel()->AddENGCoefficient(static_cast<Float_t>(GetParameter(0)));
130 GetChannel()->AddENGCoefficient(static_cast<Float_t>(GetParameter(1)));
131}
132
133void TEnergyCal::Print(Option_t*) const
134{
135 // Print the TEnergyCal information
136 TCal::Print();
137 TGraphErrors::Print();
138}
139
140void TEnergyCal::Clear(Option_t*)
141{
142 // Clear the TEnergyCal and reset the default titles.
143 TCal::Clear();
145}
void Print(Option_t *opt="") const override
Definition TCal.cxx:145
void Clear(Option_t *opt="") override
Definition TCal.cxx:137
virtual void SetNucleus(TNucleus *nuc, Option_t *opt="")
Definition TCal.cxx:24
TChannel * GetChannel() const
Definition TCal.cxx:121
virtual TNucleus * GetNucleus() const
Definition TCal.h:76
void DestroyENGCal()
Definition TChannel.cxx:554
int GetNumber() const
Definition TChannel.h:169
void AddENGCoefficient(Float_t temp, size_t range=0)
Definition TChannel.h:204
Double_t GetParameter(size_t parameter) const override
void SetNucleus(TNucleus *nuc, Option_t *opt="") override
std::vector< Double_t > GetParameters() const override
void AddPoint(Double_t measured, Double_t accepted, Double_t measuredUncertainty=0.0, Double_t acceptedUncertainty=0.0)
void WriteToChannel() const override
void SetDefaultTitles()
Definition TEnergyCal.cxx:9
void Print(Option_t *opt="") const override
void Clear(Option_t *opt="") override
Bool_t SetPointError(Int_t idx, Double_t measuredUncertainty)
Bool_t SetPoint(Int_t idx, Double_t measured)
Int_t NTransitions() const
Definition TNucleus.h:76
Definition TPeak.h:28
Double_t GetCentroidErr() const
Definition TPeak.h:52
Double_t GetCentroid() const
Definition TPeak.h:51