Jpp  16.0.0-rc.2
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 
12 #include "JGizmo/JRootObjectID.hh"
13 
14 #include "JSupport/JMeta.hh"
15 
17 
18 #include "JCalibrate/JFitToT.hh"
20 
21 
22 /**
23  * \file
24  *
25  * Example program to interpolate input high-voltage-gain data.
26  * \author bjjung
27  */
28 int main(int argc, char **argv)
29 {
30  using namespace std;
31  using namespace JPP;
32 
34 
35  typedef map<double, pair<double, double>> map_t;
36  typedef JRange<double> JRange_t;
37 
38  map_t input;
39  JRootObjectID output;
40 
41  double minDistanceHV = 2 * 3.14;
42  JRange_t rangeHV = JRange_t(-1500 + 1e-2,
43  -80 - 1e-2);
44  JRange_t rangeGain = JRange_t(FITTOT_GAIN_MIN + 1e-2,
45  FITTOT_GAIN_MAX - 1e-2);
46  double targetGain = NOMINAL_GAIN;
47 
48  int debug;
49 
50  try {
51 
52  JParser<> zap("Example program to interpolate high-voltage versus gain ASCII data.");
53 
54  JProperties properties;
55 
56  properties.insert(gmake_property(minDistanceHV));
57  properties.insert(gmake_property(rangeHV));
58  properties.insert(gmake_property(rangeGain));
59  properties.insert(gmake_property(targetGain));
60 
61  zap['f'] = make_field(input);
62  zap['o'] = make_field(output) = JPARSER::initialised();
63  zap['@'] = make_field(properties) = JPARSER::initialised();
64  zap['d'] = make_field(debug) = 2;
65 
66  zap(argc, argv);
67  }
68  catch (const exception& error) {
69  FATAL(error.what() << endl);
70  }
71 
72  JHVInterpolator::setMinHVDistance(minDistanceHV);
73  JHVInterpolator::setHVRange (rangeHV);
74  JHVInterpolator::setGainRange (rangeGain);
75 
76  TMultiGraph graph (output.getObjectName(), NULL);
77  JHVInterpolator interpolator(graph);
78 
79  NOTICE(RIGHT(35) << "High-Voltage [V]" << RIGHT(31) << "gain [-]" << endl);
80 
81  for (map_t::const_iterator i = input.cbegin(); i != input.cend(); ++i) {
82 
83  const double HV = i->first;
84  const double gain = i->second.first;
85  const double gainError = i->second.second;
86 
87  NOTICE(FIXED(35,2) << HV << FIXED(22,2) << gain << " +/- " << FIXED(3,2) << gainError << endl);
88 
89  interpolator.AddPoint(HV, gain, gainError);
90  }
91 
92  TFile file(output.getFilename().c_str(), "RECREATE");
93 
94  putObject(file, JMeta(argc, argv));
95 
96  graph.Write();
97 
98  file.Close();
99 
100  NOTICE(FILL(100,'-') << " Interpolated high-voltage" << setfill(' ') << endl);
101 
102  try {
103 
104  interpolator.interpolateHV(targetGain);
105 
106  const double targetHV = interpolator.getHV ();
107  const double targetHVError = interpolator.getHVError();
108 
109  NOTICE(FIXED(35,2) << right << -targetHV << " +/- " <<
110  FIXED(8, 2) << left << targetHVError <<
111  FIXED(9, 2) << right << targetGain << endl);
112  }
113  catch (const exception& error) {
114  FATAL(error.what() << endl);
115  }
116 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
then set_variable PMT_FILE set_variable DAQ_FILE set_variable OUTPUT_FILE set_variable DETECTOR else fatal Wrong number of arguments fi set_variable RUNBYRUN file
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
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
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
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:47
Utility class to parse command line options.