Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JCALIBRATE::JHVInterpolator Struct Reference

Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-voltage. More...

#include <JHVInterpolator.hh>

Public Member Functions

 JHVInterpolator (TMultiGraph &object)
 Constructor.
 
void AddPoint (Double_t HV, Double_t gain, Double_t gainError)
 Add point to diagram.
 
void SetPoint (Int_t i, Double_t HV, Double_t gain, Double_t gainError)
 Set point with index i.
 
const bool checkHV (const double HV) const
 Checks whether high-voltage is within 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.
 
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-voltage.
 
const bool areValid (const Int_t i, const Int_t j) const
 Checks whether two points are valid for inter-/extrapolation.
 
bool interpolateHV (const double gainTarget)
 Inter-/Extrapolate the high-voltage value corresponding to the target gain value.
 
double getHV () const
 Get interpolated high-voltage.
 
double getHVError () const
 Get error estimate on interpolated high-voltage.
 
TGraphErrors * getData () const
 Get graph with the input data for the interpolation.
 
TGraphErrors * getResult () const
 Get graph with the interpolation result.
 

Static Public Member Functions

static void setMinHVDistance (const double minDist)
 Set minimal separation distance for high-voltage.
 
static void setHVRange (const JRange< double > range)
 Set valid gain range.
 
static void setGainRange (const JRange< double > range)
 Set valid gain range.
 

Private Attributes

TMultiGraph * data
 HV-versus-gain data.
 

Static Private Attributes

static double dHVmin = 2 * 3.14
 Minimal high-voltage difference between two points [V].
 
static JRange< double > hvRange = JRange<double>(-1500, -80)
 Allowed high-voltage range [V].
 
static JRange< double > gainRange
 Allowed gain range.
 

Detailed Description

Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-voltage.

Definition at line 37 of file JHVInterpolator.hh.

Constructor & Destructor Documentation

◆ JHVInterpolator()

JCALIBRATE::JHVInterpolator::JHVInterpolator ( TMultiGraph & object)
inline

Constructor.

Parameters
objectTMultiGraph object

Definition at line 44 of file JHVInterpolator.hh.

44 :
45 data(&object)
46 {
47 TGraphErrors* g0 = new TGraphErrors();
48
49 g0->SetName(HVINTERPOLATOR_RESULT);
50 g0->SetLineColor (kRed);
51 g0->SetMarkerColor(kRed);
52 g0->SetMarkerStyle(kFullDotSmall);
53 g0->Set(0);
54
55 data->Add(g0);
56
57 TGraphErrors* g1 = new TGraphErrors();
58
59 g1->SetName(HVINTERPOLATOR_DATA);
60 g1->SetMarkerStyle(kFullDotSmall);
61 g1->Set(0);
62
63 data->Add(g1);
64 }
Double_t g1(const Double_t x)
Function.
Definition JQuantiles.cc:25
static const char * HVINTERPOLATOR_RESULT
static const char * HVINTERPOLATOR_DATA
TMultiGraph * data
HV-versus-gain data.

Member Function Documentation

◆ AddPoint()

void JCALIBRATE::JHVInterpolator::AddPoint ( Double_t HV,
Double_t gain,
Double_t gainError )
inline

Add point to diagram.

Parameters
HVhigh-voltage [V]
gaingain value
gainErrorerror on gain value

Definition at line 74 of file JHVInterpolator.hh.

75 {
76 TGraphErrors* g1 = getData();
77
78 const Int_t N = g1->GetN();
79
80 g1->SetPoint (N, fabs(HV), gain);
81 g1->SetPointError(N, 0.0, gainError);
82 }
TGraphErrors * getData() const
Get graph with the input data for the interpolation.

◆ SetPoint()

void JCALIBRATE::JHVInterpolator::SetPoint ( Int_t i,
Double_t HV,
Double_t gain,
Double_t gainError )
inline

Set point with index i.

Parameters
iindex of point
HVhigh-voltage [V]
gaingain value
gainErrorerror on gain value

Definition at line 93 of file JHVInterpolator.hh.

94 {
95 TGraphErrors* g1 = getData();
96
97 g1->SetPoint (i, fabs(HV), gain);
98 g1->SetPointError(i, 0.0, gainError);
99 }

◆ checkHV() [1/2]

const bool JCALIBRATE::JHVInterpolator::checkHV ( const double HV) const
inline

Checks whether high-voltage is within range.

Parameters
HVhigh-voltage [V]
Returns
true if high-voltage is within range; else false

Definition at line 108 of file JHVInterpolator.hh.

109 {
110 return (HV > hvRange.getLowerLimit() &&
111 HV < hvRange.getUpperLimit());
112 }
static JRange< double > hvRange
Allowed high-voltage range [V].

◆ checkHV() [2/2]

const bool JCALIBRATE::JHVInterpolator::checkHV ( const double HV1,
const double HV2 ) const
inline

Checks whether two high-voltage values are different.

Parameters
HV1first high-voltage [V]
HV2second high-voltage [V]
Returns
true if absolute difference is greater than minimal required difference; else false

Definition at line 122 of file JHVInterpolator.hh.

123 {
124 return (fabs(HV1 - HV2) > dHVmin);
125 }
static double dHVmin
Minimal high-voltage difference between two points [V].

◆ checkGain()

const bool JCALIBRATE::JHVInterpolator::checkGain ( const double gain) const
inline

Checks if gain is within range.

Parameters
gaingain value
Returns
true if gain within allowed range; else false

Definition at line 134 of file JHVInterpolator.hh.

135 {
136 return (gain > gainRange.getLowerLimit() &&
137 gain < gainRange.getUpperLimit());
138 }
static JRange< double > gainRange
Allowed gain range.

◆ areIncreasing()

const bool JCALIBRATE::JHVInterpolator::areIncreasing ( const Int_t i,
const Int_t j ) const
inline

Checks whether the gains of two points are strictly increasing as function of their absolute high-voltage.

Parameters
iindex of first point
jindex of second point
Returns
true if gains of given points are strictly increasing
as function of the absolute high-voltage; else false

Definition at line 149 of file JHVInterpolator.hh.

150 {
151 TGraphErrors* g1 = getData();
152
153 if ((i >= 0 && i < g1->GetN()) &&
154 (j >= 0 && i < g1->GetN())) {
155
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)));
158
159 } else {
160
161 return false;
162 }
163 }

◆ areValid()

const bool JCALIBRATE::JHVInterpolator::areValid ( const Int_t i,
const Int_t j ) const
inline

Checks whether two points are valid for inter-/extrapolation.

Parameters
iindex of first point
jindex of second point
Returns
true if valid for inter-/extrapolation; else false

Definition at line 173 of file JHVInterpolator.hh.

174 {
175 TGraphErrors* g1 = getData();
176
177 if ((i >= 0 && i < g1->GetN()) &&
178 (j >= 0 && j < g1->GetN())) {
179
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);
184
185 return (areIncreasing( i, j) && checkHV(HV_i) && checkGain(gain_i) &&
186 checkHV (HV_i, HV_j) && checkHV(HV_j) && checkGain(gain_j));
187
188 } else {
189
190 return false;
191 }
192 }
const bool checkGain(const double gain) const
Checks if gain is within range.
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...
const bool checkHV(const double HV) const
Checks whether high-voltage is within range.

◆ interpolateHV()

bool JCALIBRATE::JHVInterpolator::interpolateHV ( const double gainTarget)
inline

Inter-/Extrapolate the high-voltage value corresponding to the target gain value.

Parameters
gainTargettarget gain value for inter-/extrapolation
Returns
true if inter-/extrapolation successful; else false

Definition at line 201 of file JHVInterpolator.hh.

202 {
203 TGraphErrors* g1 = getData();
204
205 if (g1->GetN() < 2 || !checkGain(gainTarget)) {
206 return false;
207 }
208
209 // Search for valid inter-/extrapolation points
210
211 Int_t i = 0;
212 Int_t j = 1;
213
214 for (Int_t k = 2; k < g1->GetN(); ++k) {
215
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);
219
220 if (dGain_k < dGain_j) {
221 i = (areValid(j,k) ? j : i);
222 j = k;
223 } else if ((dGain_k < dGain_i || !areValid(i,j)) && areValid(j,k)) {
224 i = j;
225 j = k;
226 }
227 }
228
229 // Inter-/Extrapolate high-voltage corresponding to given gain
230
231 if (areValid(i, j)) {
232
233 const double logHV0 = log(fabs(g1->GetPointX(i)));
234 const double logHV1 = log(fabs(g1->GetPointX(j)));
235
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);
240
241 const double dlogG0 = log(gainTarget) - logG0;
242 const double dlogG1 = log(gainTarget) - logG1;
243
244 const double slope = (logG1 - logG0) / (logHV1 - logHV0);
245
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));
249
250 const double distance = fabs((log(HVnom) - logHV0) / (logHV0 - logHV1));
251 static const double maxDist = 2.0;
252
253 if (checkHV(-HVnom) && distance < maxDist) {
254
255 TGraphErrors* g0 = getResult();
256
257 g0->SetPoint (0, HVnom, gainTarget);
258 g0->SetPointError(0, eHVnom, 0.0);
259
260 return true;
261 }
262 }
263
264 return false;
265 }
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
int j
Definition JPolint.hh:801
const bool areValid(const Int_t i, const Int_t j) const
Checks whether two points are valid for inter-/extrapolation.
TGraphErrors * getResult() const
Get graph with the interpolation result.

◆ getHV()

double JCALIBRATE::JHVInterpolator::getHV ( ) const
inline

Get interpolated high-voltage.

Returns
inter-/extrapolated high-voltage
corresponding to target gain value [V]

Definition at line 274 of file JHVInterpolator.hh.

275 {
276 TGraphErrors* g0 = getResult();
277
278 if (g0->GetN() > 0) {
279
280 return g0->GetPointX(0);
281
282 } else {
283
284 THROW(JNoValue, "JHVInterpolator::getHV(): Missing HV inter-/extrapolation point. Please call JHVInterpolator::interpolateHV() first.");
285 }
286 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.

◆ getHVError()

double JCALIBRATE::JHVInterpolator::getHVError ( ) const
inline

Get error estimate on interpolated high-voltage.

Returns
error on inter-/extrapolated high-voltage
corresponding to the target gain value [V]

Definition at line 295 of file JHVInterpolator.hh.

296 {
297 TGraphErrors* g0 = getResult();
298
299 if (g0->GetN() > 0) {
300
301 return g0->GetErrorX(0);
302
303 } else {
304
305 THROW(JNoValue, "JHVInterpolator::getHVError(): Missing HV inter-/extrpolation point. Please call JHVInterpolator::interpolateHV() first.");
306 }
307 }

◆ getData()

TGraphErrors * JCALIBRATE::JHVInterpolator::getData ( ) const
inline

Get graph with the input data for the interpolation.

Returns
pointer to graph with input data

Definition at line 315 of file JHVInterpolator.hh.

316 {
317 TList* list = data->GetListOfGraphs();
318
319 if (list != NULL && list->FindObject(HVINTERPOLATOR_DATA) != NULL) {
320
321 return (TGraphErrors*)list->FindObject(HVINTERPOLATOR_DATA);
322
323 } else if (list == NULL) {
324
325 THROW(JNullPointerException, "JHVInterpolator()::getData(): Emtpy list of graphs.");
326
327 } else {
328
329 THROW(JNullPointerException, "JHVInterpolator()::getData(): No " << HVINTERPOLATOR_DATA << " graph.");
330 }
331 }

◆ getResult()

TGraphErrors * JCALIBRATE::JHVInterpolator::getResult ( ) const
inline

Get graph with the interpolation result.

Returns
pointer to graph with the interpolation result

Definition at line 339 of file JHVInterpolator.hh.

340 {
341 TList* list = data->GetListOfGraphs();
342
343 if (list != NULL && list->FindObject(HVINTERPOLATOR_RESULT) != NULL) {
344
345 return (TGraphErrors*)list->FindObject(HVINTERPOLATOR_RESULT);
346
347 } else if (list == NULL) {
348
349 THROW(JNullPointerException, "JHVInterpolator::getResult(): Empty list of graphs.");
350
351 } else {
352
353 THROW(JNullPointerException, "JHVInterpolator::getResult(): No " << HVINTERPOLATOR_RESULT << " graph.");
354 }
355 }

◆ setMinHVDistance()

static void JCALIBRATE::JHVInterpolator::setMinHVDistance ( const double minDist)
inlinestatic

Set minimal separation distance for high-voltage.

Parameters
minDistminimal separation distance for high-voltage

Definition at line 363 of file JHVInterpolator.hh.

364 {
365 dHVmin = minDist;
366 }

◆ setHVRange()

static void JCALIBRATE::JHVInterpolator::setHVRange ( const JRange< double > range)
inlinestatic

Set valid gain range.

Parameters
rangevalid high-voltage range [V]

Definition at line 374 of file JHVInterpolator.hh.

375 {
376 hvRange = range;
377 }

◆ setGainRange()

static void JCALIBRATE::JHVInterpolator::setGainRange ( const JRange< double > range)
inlinestatic

Set valid gain range.

Parameters
rangevalid gain range

Definition at line 385 of file JHVInterpolator.hh.

386 {
387 gainRange = range;
388 }

Member Data Documentation

◆ data

TMultiGraph* JCALIBRATE::JHVInterpolator::data
private

HV-versus-gain data.

Definition at line 393 of file JHVInterpolator.hh.

◆ dHVmin

double JCALIBRATE::JHVInterpolator::dHVmin = 2 * 3.14
staticprivate

Minimal high-voltage difference between two points [V].

Default values.

Definition at line 395 of file JHVInterpolator.hh.

◆ hvRange

JRange< double > JCALIBRATE::JHVInterpolator::hvRange = JRange<double>(-1500, -80)
staticprivate

Allowed high-voltage range [V].

Definition at line 396 of file JHVInterpolator.hh.

◆ gainRange

JRange< double > JCALIBRATE::JHVInterpolator::gainRange
staticprivate
Initial value:
= JRange<double>(FITTOT_GAIN_MIN,
static const double FITTOT_GAIN_MAX
Default maximal gain.
Definition JFitToT.hh:45
static const double FITTOT_GAIN_MIN
Default minimal gain.
Definition JFitToT.hh:44

Allowed gain range.

Definition at line 397 of file JHVInterpolator.hh.


The documentation for this struct was generated from the following file: