Jpp  master_rocky
the software that should make you happy
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 }
Time calibration (including definition of sign of time offset).
int main(int argc, char **argv)
Dynamic ROOT object management.
General purpose messaging.
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
I/O formatting auxiliaries.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
Definition: JProperties.hh:501
Auxiliary class to handle file name, ROOT directory and object name.
TString getObjectName() const
Get object name.
const std::string & getFilename() const
Get file name.
Utility class to parse command line options.
Definition: JParser.hh:1698
static const double FITTOT_GAIN_MAX
Default maximal gain.
Definition: JFitToT.hh:45
static const double FITTOT_GAIN_MIN
Default minimal gain.
Definition: JFitToT.hh:44
const double NOMINAL_GAIN
Specification for normalized gain corresponding to a one photo-electron pulse.
@ RIGHT
Definition: JTwosome.hh:18
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
Definition: JSTDTypes.hh:14
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:330
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Type definition of range.
Definition: JHead.hh:43
Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-volt...
double getHVError() const
Get error estimate on interpolated high-voltage.
double getHV() const
Get interpolated high-voltage.
bool interpolateHV(const double gainTarget)
Inter-/Extrapolate the high-voltage value corresponding to the target gain value.
void AddPoint(Double_t HV, Double_t gain, Double_t gainError)
Add point to diagram.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72