1 #ifndef __JCALIBRATE_JHVINTERPOLATOR__
2 #define __JCALIBRATE_JHVINTERPOLATOR__
12 #include "TGraphErrors.h"
13 #include "TMultiGraph.h"
14 #include "TAttMarker.h"
47 TGraphErrors* g0 =
new TGraphErrors();
50 g0->SetLineColor (kRed);
51 g0->SetMarkerColor(kRed);
52 g0->SetMarkerStyle(kFullDotSmall);
57 TGraphErrors*
g1 =
new TGraphErrors();
60 g1->SetMarkerStyle(kFullDotSmall);
74 void AddPoint(Double_t HV, Double_t gain, Double_t gainError)
78 const Int_t N =
g1->GetN();
80 g1->SetPoint (N, fabs(HV), gain);
81 g1->SetPointError(N, 0.0, gainError);
93 void SetPoint(Int_t i, Double_t HV, Double_t gain, Double_t gainError)
97 g1->SetPoint (i, fabs(HV), gain);
98 g1->SetPointError(i, 0.0, gainError);
122 const bool checkHV(
const double HV1,
const double HV2)
const
124 return (fabs(HV1 - HV2) >
dHVmin);
153 if ((i >= 0 && i < g1->GetN()) &&
154 (
j >= 0 && i < g1->GetN())) {
156 return ((
g1->GetPointX(i) >
g1->GetPointX(
j) &&
g1->GetPointY(i) >
g1->GetPointY(
j)) ||
157 (
g1->GetPointX(i) <
g1->GetPointX(
j) &&
g1->GetPointY(i) <
g1->GetPointY(
j)));
177 if ((i >= 0 && i < g1->GetN()) &&
178 (
j >= 0 && j < g1->GetN())) {
180 const double HV_i = -fabs(
g1->GetPointX(i));
181 const double HV_j = -fabs(
g1->GetPointX(
j));
182 const double gain_i =
g1->GetPointY(i);
183 const double gain_j =
g1->GetPointY(
j);
214 for (Int_t k = 2; k <
g1->GetN(); ++k) {
216 const double dGain_i = fabs(
g1->GetPointY(i) - gainTarget);
217 const double dGain_j = fabs(
g1->GetPointY(
j) - gainTarget);
218 const double dGain_k = fabs(
g1->GetPointY(k) - gainTarget);
220 if (dGain_k < dGain_j) {
233 const double logHV0 = log(fabs(
g1->GetPointX(i)));
234 const double logHV1 = log(fabs(
g1->GetPointX(
j)));
236 const double logG0 = log(
g1->GetPointY(i));
237 const double logG1 = log(
g1->GetPointY(
j));
238 const double elogG0 =
g1->GetErrorY(i) /
g1->GetPointY(i);
239 const double elogG1 =
g1->GetErrorY(
j) /
g1->GetPointY(
j);
241 const double dlogG0 = log(gainTarget) - logG0;
242 const double dlogG1 = log(gainTarget) - logG1;
244 const double slope = (logG1 - logG0) / (logHV1 - logHV0);
246 const double HVnom = exp(dlogG0 / slope + logHV0);
247 const double eHVnom = HVnom * sqrt(dlogG1 * dlogG1 * elogG0 * elogG0 +
248 dlogG0 * dlogG0 * elogG1 * elogG1) / fabs(slope * (logG1 - logG0));
250 const double distance = fabs((log(HVnom) - logHV0) / (logHV0 - logHV1));
251 static const double maxDist = 2.0;
257 g0->SetPoint (0, HVnom, gainTarget);
258 g0->SetPointError(0, eHVnom, 0.0);
278 if (g0->GetN() > 0) {
280 return g0->GetPointX(0);
284 THROW(
JNoValue,
"JHVInterpolator::getHV(): Missing HV inter-/extrapolation point. Please call JHVInterpolator::interpolateHV() first.");
299 if (g0->GetN() > 0) {
301 return g0->GetErrorX(0);
305 THROW(
JNoValue,
"JHVInterpolator::getHVError(): Missing HV inter-/extrpolation point. Please call JHVInterpolator::interpolateHV() first.");
317 TList* list =
data->GetListOfGraphs();
323 }
else if (list == NULL) {
341 TList* list =
data->GetListOfGraphs();
347 }
else if (list == NULL) {
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Double_t g1(const Double_t x)
Function.
Auxiliary class to define a range between two values.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Exception for missing value.
Exception for null pointer operation.
Exception for accessing a value in a collection that is outside of its range.
Auxiliary classes and methods for PMT calibration.
static const std::string HVINTERPOLATOR_SUFFIX
static const char * HVINTERPOLATOR_RESULT
static const double FITTOT_GAIN_MAX
Default maximal gain.
static const double FITTOT_GAIN_MIN
Default minimal gain.
static const char * HVINTERPOLATOR_DATA
Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-volt...
double getHVError() const
Get error estimate on interpolated high-voltage.
const bool areValid(const Int_t i, const Int_t j) const
Checks whether two points are valid for inter-/extrapolation.
double getHV() const
Get interpolated high-voltage.
static void setHVRange(const JRange< double > range)
Set valid gain range.
static void setMinHVDistance(const double minDist)
Set minimal separation distance for high-voltage.
static JRange< double > gainRange
Allowed gain range.
const bool checkHV(const double HV1, const double HV2) const
Checks whether two high-voltage values are different.
const bool checkGain(const double gain) const
Checks if gain is within range.
TMultiGraph * data
HV-versus-gain data.
static void setGainRange(const JRange< double > range)
Set valid gain range.
JHVInterpolator(TMultiGraph &object)
Constructor.
bool interpolateHV(const double gainTarget)
Inter-/Extrapolate the high-voltage value corresponding to the target gain value.
void SetPoint(Int_t i, Double_t HV, Double_t gain, Double_t gainError)
Set point with index i.
const bool areIncreasing(const Int_t i, const Int_t j) const
Checks whether the gains of two points are strictly increasing as function of their absolute high-vol...
TGraphErrors * getResult() const
Get graph with the interpolation result.
static JRange< double > hvRange
Allowed high-voltage range [V].
static double dHVmin
Minimal high-voltage difference between two points [V].
TGraphErrors * getData() const
Get graph with the input data for the interpolation.
void AddPoint(Double_t HV, Double_t gain, Double_t gainError)
Add point to diagram.
const bool checkHV(const double HV) const
Checks whether high-voltage is within range.