Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
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. More...
 
void AddPoint (Double_t HV, Double_t gain, Double_t gainError)
 Add point to diagram. More...
 
void SetPoint (Int_t i, Double_t HV, Double_t gain, Double_t gainError)
 Set point with index i. More...
 
const bool checkHV (const double HV) const
 Checks whether high-voltage is within range. More...
 
const bool checkHV (const double HV1, const double HV2) const
 Checks whether two high-voltage values are different. More...
 
const bool checkGain (const double gain) const
 Checks if gain is within range. More...
 
const bool areIncreasing (const Int_t i, const Int_t j)
 Checks whether the gains of two points are strictly increasing as function of their absolute high-voltage. More...
 
const bool areValid (const Int_t i, const Int_t j)
 Checks whether two points are valid for inter-/extrapolation. More...
 
bool interpolate (const double gainTarget)
 Inter-/Extrapolate the high-voltage value corresponding to the target gain value. More...
 
double getTargetHV (const double gainTarget)
 Get high-voltage corresponding to given target gain value. More...
 
double getTargetHVError (const double gainTarget)
 Get error estimate on high-voltage corresponding to given target gain value. More...
 
TGraphErrors * getData ()
 Get graph with the input data for the interpolation. More...
 
TGraphErrors * getResult ()
 Get graph with the interpolation result. More...
 

Static Public Member Functions

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

Private Attributes

TMultiGraph * data
 HV-versus-gain data. More...
 

Static Private Attributes

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

Detailed Description

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

Definition at line 35 of file JHVInterpolator.hh.

Constructor & Destructor Documentation

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

Constructor.

Parameters
objectTMultiGraph object

Definition at line 42 of file JHVInterpolator.hh.

42  :
43  data(&object)
44  {}
TMultiGraph * data
HV-versus-gain data.

Member Function Documentation

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 54 of file JHVInterpolator.hh.

55  {
56  TGraphErrors* g1 = getData();
57 
58  const Int_t N = g1->GetN();
59 
60  g1->SetPoint (N, fabs(HV), gain);
61  g1->SetPointError(N, 0.0, gainError);
62  }
TGraphErrors * getData()
Get graph with the input data for the interpolation.
then $JPP_DIR examples JDetector JToT o $OUTPUT_FILE n N $NPE P gain
Definition: JToT.sh:45
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:35
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
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 73 of file JHVInterpolator.hh.

74  {
75  TGraphErrors* g1 = getData();
76 
77  g1->SetPoint (i, fabs(HV), gain);
78  g1->SetPointError(i, 0.0, gainError);
79  }
TGraphErrors * getData()
Get graph with the input data for the interpolation.
then $JPP_DIR examples JDetector JToT o $OUTPUT_FILE n N $NPE P gain
Definition: JToT.sh:45
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
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 88 of file JHVInterpolator.hh.

89  {
90  return (HV > hvRange.getLowerLimit() &&
91  HV < hvRange.getUpperLimit());
92  }
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
static JRange< double > hvRange
Allowed high-voltage range [V].
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
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 102 of file JHVInterpolator.hh.

103  {
104  return (fabs(HV1 - HV2) > dHVmin);
105  }
static double dHVmin
Minimal high-voltage difference between two points [V].
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 114 of file JHVInterpolator.hh.

115  {
116  return (gain > gainRange.getLowerLimit() &&
118  }
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
static JRange< double > gainRange
Allowed gain range.
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
then $JPP_DIR examples JDetector JToT o $OUTPUT_FILE n N $NPE P gain
Definition: JToT.sh:45
const bool JCALIBRATE::JHVInterpolator::areIncreasing ( const Int_t  i,
const Int_t  j 
)
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 129 of file JHVInterpolator.hh.

130  {
131  TGraphErrors* g1 = getData();
132 
133  if ((i >= 0 && i < g1->GetN()) &&
134  (j >= 0 && i < g1->GetN())) {
135 
136  return ((g1->GetPointX(i) > g1->GetPointX(j) && g1->GetPointY(i) > g1->GetPointY(j)) ||
137  (g1->GetPointX(i) < g1->GetPointX(j) && g1->GetPointY(i) < g1->GetPointY(j)));
138 
139  } else {
140 
141  return false;
142  }
143  }
TGraphErrors * getData()
Get graph with the input data for the interpolation.
int j
Definition: JPolint.hh:666
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
const bool JCALIBRATE::JHVInterpolator::areValid ( const Int_t  i,
const Int_t  j 
)
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 153 of file JHVInterpolator.hh.

154  {
155  TGraphErrors* g1 = getData();
156 
157  if ((i >= 0 && i < g1->GetN()) &&
158  (j >= 0 && i < g1->GetN())) {
159 
160  const double HV_i = -fabs(g1->GetPointX(i));
161  const double HV_j = -fabs(g1->GetPointX(j));
162  const double gain_i = g1->GetPointY(i);
163  const double gain_j = g1->GetPointY(j);
164 
165  return (areIncreasing( i, j) && checkHV(HV_i) && checkGain(gain_i) &&
166  checkHV (HV_i, HV_j) && checkHV(HV_j) && checkGain(gain_j));
167 
168  } else {
169 
170  return false;
171  }
172  }
TGraphErrors * getData()
Get graph with the input data for the interpolation.
const bool checkHV(const double HV) const
Checks whether high-voltage is within range.
const bool checkGain(const double gain) const
Checks if gain is within range.
const bool areIncreasing(const Int_t i, const Int_t j)
Checks whether the gains of two points are strictly increasing as function of their absolute high-vol...
int j
Definition: JPolint.hh:666
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
bool JCALIBRATE::JHVInterpolator::interpolate ( 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 181 of file JHVInterpolator.hh.

182  {
183  TGraphErrors* g1 = getData();
184 
185  if (g1->GetN() < 2 || !checkGain(gainTarget)) {
186  return false;
187  }
188 
189  // Search for valid inter-/extrapolation points
190 
191  Int_t i = 0;
192  Int_t j = 1;
193 
194  for (Int_t k = 1; k < g1->GetN(); ++k) {
195 
196  const double dGain_i = fabs(g1->GetPointY(i) - gainTarget);
197  const double dGain_j = fabs(g1->GetPointY(j) - gainTarget);
198  const double dGain_k = fabs(g1->GetPointY(k) - gainTarget);
199 
200  if (dGain_k < dGain_i) {
201 
202  j = (areValid(i, k) ? i : j);
203  i = k;
204 
205  } else if ((dGain_k < dGain_j || !areValid(i, j)) &&
206  areValid(i, k)) {
207  j = k;
208  }
209  }
210 
211  // Inter-/Extrapolate high-voltage corresponding to given gain
212 
213  if (areValid(i, j)) {
214 
215  const double logHV0 = log(fabs(g1->GetPointX(i)));
216  const double logHV1 = log(fabs(g1->GetPointX(j)));
217 
218  const double logG0 = log(g1->GetPointY(i));
219  const double logG1 = log(g1->GetPointY(j));
220  const double elogG0 = g1->GetErrorY(i) / g1->GetPointY(i);
221  const double elogG1 = g1->GetErrorY(j) / g1->GetPointY(j);
222 
223  const double dlogG0 = log(gainTarget) - logG0;
224  const double dlogG1 = log(gainTarget) - logG1;
225 
226  const double slope = (logG1 - logG0) / (logHV1 - logHV0);
227 
228  const double HVnom = exp(dlogG0 / slope + logHV0);
229  const double eHVnom = HVnom * sqrt(dlogG1 * dlogG1 * elogG0 * elogG0 +
230  dlogG0 * dlogG0 * elogG1 * elogG1) / fabs(slope * (logG1 - logG0));
231 
232  const double distance = fabs((log(HVnom) - logHV0) / (logHV0 - logHV1));
233  static const double maxDist = 2.0;
234 
235  if (checkHV(-HVnom) && distance < maxDist) {
236 
237  TGraphErrors* g0 = getResult();
238 
239  g0->SetPoint (0, HVnom, gainTarget);
240  g0->SetPointError(0, eHVnom, 0.0);
241 
242  return true;
243  }
244  }
245 
246  return false;
247  }
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
TGraphErrors * getResult()
Get graph with the interpolation result.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
TGraphErrors * getData()
Get graph with the input data for the interpolation.
const bool areValid(const Int_t i, const Int_t j)
Checks whether two points are valid for inter-/extrapolation.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable STRING $argv[2] set_array QUANTILES set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))" set_variable MODULE `getModule -a $DETECTOR -L "$STRING 0"` typeset -Z 4 STRING JOpera1D -f hydrophone.root
const bool checkHV(const double HV) const
Checks whether high-voltage is within range.
const bool checkGain(const double gain) const
Checks if gain is within range.
int j
Definition: JPolint.hh:666
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
double JCALIBRATE::JHVInterpolator::getTargetHV ( const double  gainTarget)
inline

Get high-voltage corresponding to given target gain value.

Parameters
gainTargettarget gain value for inter-/extrapolation
Returns
inter-/extrapolated high-voltage
corresponding to target gain value [V]

Definition at line 257 of file JHVInterpolator.hh.

258  {
259  static const double precision = 1e-3;
260 
261  TGraphErrors* g0 = getResult();
262 
263  if ((g0->GetN() > 0 && fabs(g0->GetPointY(0) - gainTarget) < precision) || interpolate(gainTarget)) {
264 
265  return g0->GetPointX(0);
266 
267  } else {
268 
269  THROW(JValueOutOfRange, "JHVInterpolator::getTargetError(): No valid inter-/extrapolation candidate found for given target gain of " << gainTarget << '.');
270  }
271  }
TGraphErrors * getResult()
Get graph with the interpolation result.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
bool interpolate(const double gainTarget)
Inter-/Extrapolate the high-voltage value corresponding to the target gain value. ...
double JCALIBRATE::JHVInterpolator::getTargetHVError ( const double  gainTarget)
inline

Get error estimate on high-voltage corresponding to given target gain value.

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

Definition at line 281 of file JHVInterpolator.hh.

282  {
283  static const double precision = 1e-3;
284 
285  TGraphErrors* g0 = getResult();
286 
287  if ((g0->GetN() > 0 && fabs(g0->GetPointY(0) - gainTarget) < precision) || interpolate(gainTarget)) {
288 
289  return g0->GetErrorX(0);
290 
291  } else {
292 
293  THROW(JValueOutOfRange, "JHVInterpolator::getTargetError(): No valid inter-/extrapolation candidate found for given target gain of " << gainTarget << '.');
294  }
295  }
TGraphErrors * getResult()
Get graph with the interpolation result.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
bool interpolate(const double gainTarget)
Inter-/Extrapolate the high-voltage value corresponding to the target gain value. ...
TGraphErrors* JCALIBRATE::JHVInterpolator::getData ( )
inline

Get graph with the input data for the interpolation.

Returns
pointer to graph with input data

Definition at line 303 of file JHVInterpolator.hh.

304  {
305  TGraphErrors* g1;
306 
307  TList* list = data->GetListOfGraphs();
308 
309  if (list != NULL && list->FindObject(HVINTERPOLATOR_DATA) != NULL) {
310 
311  g1 = (TGraphErrors*)list->FindObject(HVINTERPOLATOR_DATA);
312 
313  } else {
314 
315  g1 = new TGraphErrors();
316 
317  g1->SetName(HVINTERPOLATOR_DATA);
318 
319  g1->SetMarkerStyle(kFullDotSmall);
320 
321  g1->Set(0);
322 
323  data->Add(g1);
324  }
325 
326  return g1;
327  }
TMultiGraph * data
HV-versus-gain data.
static const char * HVINTERPOLATOR_DATA
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
TGraphErrors* JCALIBRATE::JHVInterpolator::getResult ( )
inline

Get graph with the interpolation result.

Returns
pointer to graph with the interpolation result

Definition at line 335 of file JHVInterpolator.hh.

336  {
337  TGraphErrors* g0;
338 
339  TList* list = data->GetListOfGraphs();
340 
341  if (list != NULL && list->FindObject(HVINTERPOLATOR_RESULT) != NULL) {
342 
343  g0 = (TGraphErrors*)list->FindObject(HVINTERPOLATOR_RESULT);
344 
345  } else {
346 
347  g0 = new TGraphErrors();
348 
349  g0->SetName(HVINTERPOLATOR_RESULT);
350 
351  g0->SetLineColor (kRed);
352  g0->SetMarkerColor(kRed);
353  g0->SetMarkerStyle(kFullDotSmall);
354 
355  g0->Set(0);
356 
357  data->Add(g0);
358  }
359 
360  return g0;
361  }
static const char * HVINTERPOLATOR_RESULT
TMultiGraph * data
HV-versus-gain data.
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 369 of file JHVInterpolator.hh.

370  {
371  dHVmin = minDist;
372  }
static double dHVmin
Minimal high-voltage difference between two points [V].
static void JCALIBRATE::JHVInterpolator::setHVRange ( const JRange< double >  range)
inlinestatic

Set valid gain range.

Parameters
rangevalid high-voltage range [V]

Definition at line 380 of file JHVInterpolator.hh.

381  {
382  hvRange = range;
383  }
static JRange< double > hvRange
Allowed high-voltage range [V].
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
static void JCALIBRATE::JHVInterpolator::setGainRange ( const JRange< double >  range)
inlinestatic

Set valid gain range.

Parameters
rangevalid gain range

Definition at line 391 of file JHVInterpolator.hh.

392  {
393  gainRange = range;
394  }
static JRange< double > gainRange
Allowed gain range.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $

Member Data Documentation

TMultiGraph* JCALIBRATE::JHVInterpolator::data
private

HV-versus-gain data.

Definition at line 399 of file JHVInterpolator.hh.

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

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

Default values.

Definition at line 401 of file JHVInterpolator.hh.

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

Allowed high-voltage range [V].

Definition at line 402 of file JHVInterpolator.hh.

JRange< double > JCALIBRATE::JHVInterpolator::gainRange
staticprivate
Initial value:
= JRange<double>(FITTOT_GAIN_MIN,

Allowed gain range.

Definition at line 403 of file JHVInterpolator.hh.


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