1 #ifndef __JCALIBRATE_JHVGAINGRAPH__
2 #define __JCALIBRATE_JHVGAINGRAPH__
12 #include "TGraphErrors.h"
13 #include "TMultiGraph.h"
14 #include "TAttMarker.h"
22 namespace JCALIBRATE {
46 const bool logScale =
false,
47 const double base = 10.0) :
56 g0->SetLineColor (kRed);
57 g0->SetMarkerColor(kRed);
58 g0->SetMarkerStyle(kFullDotSmall);
61 g1->SetMarkerStyle(kFullDotSmall);
74 const double base = 10.0) :
77 TList* graphs =
object.GetListOfGraphs();
85 this->Add((TGraphErrors*)g0->Clone());
89 this->Add((TGraphErrors*)g1->Clone());
106 const Int_t
N = g1->GetN();
110 g1->SetPoint (N, log(fabs(HV)) / log(
base), log(gain) / log(
base));
111 g1->SetPointError(N, 0.0, gainError / log(
base) / gain);
115 g1->SetPoint (N, HV, gain);
116 g1->SetPointError(N, 0.0, gainError);
135 g1->SetPoint (i, log(fabs(HV)) / log(
base), log(gain) / log(
base));
136 g1->SetPointError(i, 0.0, gainError / log(
base) / gain);
140 g1->SetPoint (i, HV, gain);
141 g1->SetPointError(i, 0.0, gainError);
166 const bool checkHV(
const double HV1,
const double HV2)
const
168 return (fabs(HV1 - HV2) >
dHVmin);
197 if ( (g1 != NULL) && ((i >= 0 && i < g1->GetN()) &&
198 (j >= 0 && i < g1->GetN())) ) {
202 return ((g1->GetPointX(i) > g1->GetPointX(j) && g1->GetPointY(i) > g1->GetPointY(j)) ||
203 (g1->GetPointX(i) < g1->GetPointX(j) && g1->GetPointY(i) < g1->GetPointY(j)));
207 return ((g1->GetPointX(i) < g1->GetPointX(j) && g1->GetPointY(i) > g1->GetPointY(j)) ||
208 (g1->GetPointX(i) > g1->GetPointX(j) && g1->GetPointY(i) < g1->GetPointY(j)));
229 if ((i >= 0 && i < g1->GetN()) &&
230 (j >= 0 && i < g1->GetN())) {
232 double HV_i, HV_j, gain_i, gain_j;
236 HV_i = -
pow(
base, g1->GetPointX(i));
237 HV_j = -
pow(
base, g1->GetPointX(j));
238 gain_i =
pow(
base, g1->GetPointY(i));
239 gain_j =
pow(
base, g1->GetPointY(j));
243 HV_i = g1->GetPointX(i);
244 HV_j = g1->GetPointX(j);
245 gain_i = g1->GetPointY(i);
246 gain_j = g1->GetPointY(j);
269 if (g1->GetN() < 2 || !
checkGain(gainTarget)) {
273 const bool isLogLog =
loglog;
284 const double logGainTarget = log(gainTarget) / log(
base);
286 for (Int_t
k = 1;
k < g1->GetN(); ++
k) {
288 const double dlogG_i = fabs(g1->GetPointY(i) - logGainTarget);
289 const double dlogG_j = fabs(g1->GetPointY(j) - logGainTarget);
290 const double dlogG_k = fabs(g1->GetPointY(
k) - logGainTarget);
292 if (dlogG_k < dlogG_i) {
297 }
else if ((dlogG_k < dlogG_j || !
areValid(i, j)) &&
309 const double logHV0 = g1->GetPointX(i);
310 const double logHV1 = g1->GetPointX(j);
312 const double logG0 = g1->GetPointY(i);
313 const double logG1 = g1->GetPointY(j);
314 const double elogG0 = g1->GetErrorY(i);
315 const double elogG1 = g1->GetErrorY(j);
317 const double dlogG0 = logGainTarget - logG0;
318 const double dlogG1 = logGainTarget - logG1;
320 const double slope = (logG1 - logG0) / (logHV1 - logHV0);
322 const double logHVnom = dlogG0 / slope + logHV0;
323 const double elogHVnom = sqrt(dlogG1 * dlogG1 * elogG0 * elogG0 +
324 dlogG0 * dlogG0 * elogG1 * elogG1) / fabs(slope * (logG1 - logG0));
326 const double distance = fabs((logHVnom - logHV0) / (logHV0 - logHV1));
328 static const double maxDist = 2.0;
330 valid = (logHVnom > 0.0 &&
checkHV(-
pow(
base, logHVnom)) && distance < maxDist);
336 g0->SetPoint (0, logHVnom, logGainTarget);
337 g0->SetPointError(0, elogHVnom, 0.0);
358 static const double precision = 1e-3;
360 const double target = (
loglog ? log(gainTarget) / log(
base) : gainTarget);
364 if ((g0->GetN() > 0 && fabs(g0->GetPointY(0) - target < precision)) ||
interpolate(gainTarget)) {
366 return (
loglog ? -
pow(
base, g0->GetPointX(0)) : g0->GetPointX(0));
370 THROW(
JValueOutOfRange,
"JHVGainGraph::getTargetError(): No valid inter-/extrapolation candidate found for given target gain.");
384 static const double precision = 1e-3;
386 const double target = (
loglog ? log(gainTarget) / log(
base) : gainTarget);
390 if ((g0->GetN() > 0 && fabs(g0->GetPointY(0) - target) < precision) ||
interpolate(gainTarget)) {
392 return (
loglog ? g0->GetErrorX(0) *
pow(
base, g0->GetPointX(0)) * log(
base) : g0->GetErrorX(0));
396 THROW(
JValueOutOfRange,
"JHVGainGraph::getTargetError(): No valid inter-/extrapolation candidate found for given target gain.");
408 TIter next(this->GetListOfGraphs());
410 while (TGraphErrors* graph = (TGraphErrors*)next()) {
414 for (Int_t i = 0; i < graph->GetN(); ++i) {
416 Double_t absLogHV = log(fabs(graph->GetPointX(i))) / log(
base);
417 Double_t logGain = log(graph->GetPointY(i)) / log(
base);
419 Double_t absLogHVerror = graph->GetErrorX(i) / fabs(graph->GetPointX(i)) / log(
base);
420 Double_t logGainError = graph->GetErrorY(i) / fabs(graph->GetPointY(i)) / log(
base);
422 graph->SetPoint (i, absLogHV, logGain);
423 graph->SetPointError(i, absLogHVerror, logGainError);
440 TIter next(this->GetListOfGraphs());
442 while (TGraphErrors* graph = (TGraphErrors*)next()) {
446 for (Int_t i = 0; i < graph->GetN(); ++i) {
448 Double_t HV = -
pow(
base, graph->GetPointX(i));
451 Double_t HVerror = graph->GetErrorX(i) * -HV * log(
base);
452 Double_t gainError = graph->GetErrorY(i) * gain * log(
base);
454 graph->SetPoint (i, HV, gain);
455 graph->SetPointError(i, HVerror, gainError);
474 TIter next(this->GetListOfGraphs());
476 while (TGraphErrors* graph = (TGraphErrors*)next()) {
480 for (Int_t i = 0; i < graph->GetN(); ++i) {
482 Double_t absLogHV = graph->GetPointX(i) * log(this->base) / log(base);
483 Double_t logGain = graph->GetPointY(i) * log(this->base) / log(base);
485 Double_t abslogHVerror = graph->GetErrorX(i) * log(this->base) / log(base);
486 Double_t logGainError = graph->GetErrorY(i) * log(this->base) / log(base);
488 graph->SetPoint (i, absLogHV, logGain);
489 graph->SetPointError(i, abslogHVerror, logGainError);
508 TList* list = this->GetListOfGraphs();
516 g1 =
new TGraphErrors();
538 TList* list = this->GetListOfGraphs();
546 g0 =
new TGraphErrors();
568 clone->SetName(newname);
static const char * HVGAINGRAPH_RESULT
const bool checkHV(const double HV1, const double HV2) const
Checks whether two high-voltage values are different.
void unsetLogLog()
Unset log-log scale.
static void setGainRange(const JRange< double > range)
Set valid gain range.
JHVGainGraph(const char *name="HVGainGraph", const bool logScale=false, const double base=10.0)
Constructor.
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.
static const char * HVGAINGRAPH_DATA
static const double FITTOT_GAIN_MAX
Default maximal gain.
static const double FITTOT_GAIN_MIN
Default minimal gain.
then fatal No sound hydrophone file $HYDROPHONE_TXT fi JGraph f $HYDROPHONE_TXT o $HYDROPHONE_ROOT sort gr k
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
JHVGainGraph(const TMultiGraph &object, const bool logScale, const double base=10.0)
Copy constructor.
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...
void setLogBase(const double base)
Set logarithmic base for log-log scaling.
const bool checkHV(const double HV) const
Checks whether high-voltage is within range.
bool interpolate(const double gainTarget)
Inter-/Extrapolate the high-voltage value corresponding to the target gain value. ...
const bool checkGain(const double gain) const
Checks if gain is within range.
double getTargetHVError(const double gainTarget)
Get error estimate on high-voltage corresponding to given target gain value.
const bool areValid(const Int_t i, const Int_t j)
Checks whether two points are valid for inter-/extrapolation.
void SetPoint(Int_t i, Double_t HV, Double_t gain, Double_t gainError)
Set point with index i.
static void setHVRange(const JRange< double > range)
Set valid gain range.
TGraphErrors * getResult()
Get graph with the interpolation result.
Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-volt...
static JRange< double > hvRange
Allowed high-voltage range [V].
T pow(const T &x, const double y)
Power .
static void setMinHVDistance(const double minDist)
Set minimal separation distance for high-voltage.
void AddPoint(Double_t HV, Double_t gain, Double_t gainError)
Add point to diagram.
static const std::string HVGAINGRAPH_SUFFIX
JHVGainGraph * Clone(const char *newname="") const
Clone this object.
double base
Base for logarithmic scaling.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi mv $WORKDIR/fit.root $MODULE_ROOT typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
then $JPP_DIR examples JDetector JToT o $OUTPUT_FILE n N $NPE P gain
double getTargetHV(const double gainTarget)
Get high-voltage corresponding to given target gain value.
Auxiliary class to define a range between two values.
static double dHVmin
Minimal high-voltage difference between two points [V].
Exception for accessing a value in a collection that is outside of its range.
static JRange< double > gainRange
Allowed gain range.
bool loglog
Log-log scale toggle.
void setLogLog()
Set log-log scale.
then usage $script[input file[working directory[option]]] nWhere option can be N
Double_t g1(const Double_t x)
Function.