Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JHVInterpolator.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <vector>
4 #include <istream>
5 
6 #include "Jeep/JPrint.hh"
7 #include "Jeep/JParser.hh"
8 #include "Jeep/JMessage.hh"
9 
10 #include "JROOT/JManager.hh"
11 #include "JGizmo/JRootObjectID.hh"
12 
14 
15 #include "JCalibrate/JFitToT.hh"
17 
18 
19 /**
20  * \file
21  *
22  * Example program to interpolate input high-voltage-gain data.
23  * \author bjjung
24  */
25 int main(int argc, char **argv)
26 {
27  using namespace std;
28  using namespace JPP;
29 
31 
32  typedef map<double, pair<double, double>> map_t;
33  typedef JRange<double> JRange_t;
34 
35  map_t input;
36  JRootObjectID output;
37 
38  double minDistanceHV = 2 * 3.14;
39  JRange_t rangeHV = JRange_t(-1500 + 1e-2,
40  -80 - 1e-2);
41  JRange_t rangeGain = JRange_t(FITTOT_GAIN_MIN + 1e-2,
42  FITTOT_GAIN_MAX - 1e-2);
43  double targetGain = NOMINAL_GAIN;
44 
45  int debug;
46 
47  try {
48 
49  JParser<> zap("Example program to interpolate high-voltage versus gain ASCII data.");
50 
51  JProperties properties;
52 
53  properties.insert(gmake_property(minDistanceHV));
54  properties.insert(gmake_property(rangeHV));
55  properties.insert(gmake_property(rangeGain));
56  properties.insert(gmake_property(targetGain));
57 
58  zap['f'] = make_field(input);
59  zap['o'] = make_field(output) = JPARSER::initialised();
60  zap['@'] = make_field(properties) = JPARSER::initialised();
61  zap['d'] = make_field(debug) = 2;
62 
63  zap(argc, argv);
64  }
65  catch (const exception& error) {
66  FATAL(error.what() << endl);
67  }
68 
69  JHVInterpolator::setMinHVDistance(minDistanceHV);
70  JHVInterpolator::setHVRange (rangeHV);
71  JHVInterpolator::setGainRange (rangeGain);
72 
73  TMultiGraph graph (output.getObjectName(), NULL);
74  JHVInterpolator interpolator(graph);
75 
76  NOTICE(RIGHT(35) << "High-Voltage [V]" << RIGHT(31) << "gain [-]" << endl);
77 
78  for (map_t::const_iterator i = input.cbegin(); i != input.cend(); ++i) {
79 
80  const double HV = i->first;
81  const double gain = i->second.first;
82  const double gainError = i->second.second;
83 
84  NOTICE(FIXED(35,2) << HV << FIXED(22,2) << gain << " +/- " << FIXED(3,2) << gainError << endl);
85 
86  interpolator.AddPoint(HV, gain, gainError);
87  }
88 
89  NOTICE(FILL(100,'-') << " Interpolated high-voltage" << setfill(' ') << endl);
90 
91  try {
92 
93  const double targetHV = interpolator.getTargetHV (targetGain);
94  const double targetHVError = interpolator.getTargetHVError(targetGain);
95 
96  NOTICE(FIXED(35,2) << right << -targetHV << " +/- " <<
97  FIXED(8, 2) << left << targetHVError <<
98  FIXED(9, 2) << right << targetGain << endl);
99  }
100  catch (const exception& error) {
101  FATAL(error.what() << endl);
102  }
103 
104  TFile file(output.getFilename().c_str(), "RECREATE");
105 
106  graph.Write();
107  file.Close();
108 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
Time calibration (including definition of sign of time offset).
#define gmake_property(A)
macro to convert (template) parameter to JPropertiesElement object
static const double FITTOT_GAIN_MAX
Default maximal gain.
Definition: JFitToT.hh:44
static const double FITTOT_GAIN_MIN
Default minimal gain.
Definition: JFitToT.hh:43
Utility class to parse parameter values.
Definition: JProperties.hh:496
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
then usage $script< string identifier >< detectorfile > input file(toashort file)+" "\nNote that the input files and toashort files should be one-to-one related." fi if (( $
Dynamic ROOT object management.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
I/O formatting auxiliaries.
Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-volt...
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
const double NOMINAL_GAIN
Specification for normalized gain corresponding to a one photo-electron pulse.
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
then $JPP_DIR examples JDetector JToT o $OUTPUT_FILE n N $NPE P gain
Definition: JToT.sh:45
Utility class to parse command line options.