Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
examples/JCalibrate/JHVGainGraph.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 
46  bool loglog = true;
47  double base = 10.0;
48 
49  int debug;
50 
51  try {
52 
53  JParser<> zap("Example program to interpolate high-voltage versus gain ASCII data.");
54 
55  JProperties properties;
56 
57  properties.insert(gmake_property(minDistanceHV));
58  properties.insert(gmake_property(rangeHV));
59  properties.insert(gmake_property(rangeGain));
60  properties.insert(gmake_property(targetGain));
61  properties.insert(gmake_property(loglog));
62  properties.insert(gmake_property(base));
63 
64  zap['f'] = make_field(input);
65  zap['o'] = make_field(output) = JPARSER::initialised();
66  zap['@'] = make_field(properties) = JPARSER::initialised();
67  zap['d'] = make_field(debug) = 2;
68 
69  zap(argc, argv);
70  }
71  catch (const exception& error) {
72  FATAL(error.what() << endl);
73  }
74 
75  JHVGainGraph::setMinHVDistance(minDistanceHV);
76  JHVGainGraph::setHVRange (rangeHV);
77  JHVGainGraph::setGainRange (rangeGain);
78 
79  JHVGainGraph graph(output.getObjectName(), loglog, base);
80 
81  NOTICE(RIGHT(35) << "High-Voltage [V]" << RIGHT(31) << "gain [-]" << endl);
82 
83  for (map_t::const_iterator i = input.cbegin(); i != input.cend(); ++i) {
84 
85  const double HV = i->first;
86  const double gain = i->second.first;
87  const double gainError = i->second.second;
88 
89  NOTICE(FIXED(35,2) << HV << FIXED(22,2) << gain << " +/- " << FIXED(3,2) << gainError << endl);
90 
91  graph.AddPoint(HV, gain, gainError);
92  }
93 
94  NOTICE(FILL(100,'-') << " Interpolated high-voltage" << setfill(' ') << endl);
95 
96  try {
97 
98  const double targetHV = graph.getTargetHV (targetGain);
99  const double targetHVError = graph.getTargetHVError(targetGain);
100 
101  NOTICE(FIXED(35,2) << right << targetHV << " +/- " <<
102  FIXED(8, 2) << left << targetHVError <<
103  FIXED(9, 2) << right << targetGain << endl);
104  }
105  catch (const exception& error) {
106  FATAL(error.what() << endl);
107  }
108 
109  TFile file(output.getFilename().c_str(), "RECREATE");
110 
111  graph.Write();
112  file.Close();
113 }
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
Dynamic ROOT object management.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:445
Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-volt...
Definition: JHVGainGraph.hh:35
I/O formatting auxiliaries.
#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:327
#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.