Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JTuneHV.cc File Reference

Program for inter-/extrapolation of nominal high-voltage settings. More...

#include <map>
#include <fstream>
#include "JSystem/JDate.hh"
#include "JLang/JUUID.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JTools/JRange.hh"
#include "JSupport/JMeta.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JDB/JUPI.hh"
#include "JDB/JUPI_t.hh"
#include "JCalibrate/JFitToT.hh"
#include "JCalibrate/JHVGainGraph.hh"
#include "JROOT/JManager.hh"
#include "JSon/JSon.hh"
#include "TFile.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program for inter-/extrapolation of nominal high-voltage settings.

Author
acreusot, mdejong and bjung

Definition in file JTuneHV.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

< Minimal HV step [V]

< Allowed HV range [V]

< Allowed gain fit-range

< Target nominal gain value

Definition at line 113 of file JTuneHV.cc.

114 {
115  using namespace std;
116  using namespace JPP;
117 
118  string inputFile;
119  string detectorFile;
120  string outputFile;
121  string UPIFile;
122 
123  string login;
124  string locationID;
125  string testType;
126  int elapsedTime = 0;
127 
128  double HVstepMin = 2 * 3.14; //!< Minimal HV step [V]
129  JRange<double> HVrange(-1500 + 1e-2,
130  -80 - 1e-2); //!< Allowed HV range [V]
131  JRange<double> gainRange(FITTOT_GAIN_MIN + 1e-2,
132  FITTOT_GAIN_MAX - 1e-2); //!< Allowed gain fit-range
133  double gainTarget = NOMINAL_GAIN; //!< Target nominal gain value
134  bool loglog = true;
135  double base = 10.0;
136 
137  int debug;
138 
139 
140  try {
141 
142  JProperties properties;
143 
144  properties.insert(gmake_property(login));
145  properties.insert(gmake_property(locationID));
146  properties.insert(gmake_property(testType));
147  properties.insert(gmake_property(elapsedTime));
148 
149  JProperties settings;
150 
151  settings.insert(gmake_property(HVstepMin));
152  settings.insert(gmake_property(HVrange));
153  settings.insert(gmake_property(gainRange));
154  settings.insert(gmake_property(gainTarget));
155  settings.insert(gmake_property(loglog));
156  settings.insert(gmake_property(base));
157 
158  JParser<> zap("Example program to find optimal HV-settings.");
159 
160  zap['f'] = make_field(inputFile, "input file (ROOT format)");
161  zap['o'] = make_field(outputFile, "output file (json format)");
162  zap['a'] = make_field(detectorFile, "detector file");
163  zap['b'] = make_field(UPIFile, "PMT UPI ASCII table");
164  zap['#'] = make_field(properties, "database information") = JPARSER::initialised();
165  zap['@'] = make_field(settings, "interpolation settings") = JPARSER::initialised();
166  zap['d'] = make_field(debug, "debug") = 1;
167 
168  zap(argc, argv);
169  }
170  catch(const exception &error) {
171  FATAL(error.what() << endl);
172  }
173 
174  if (login.empty() || locationID.empty()) {
175 
176  FATAL("Missing user information (please specify via -#login and -#locationID");
177 
178  } else if (testType.empty()) {
179 
180  FATAL("Missing database test type (please specify via -#testType)");
181  }
182 
183 
184  const JUUID& UUID = JUUID::rndm();
185 
186  JDateAndTimeFormat format = ISO8601;
187  JDateAndTime timer;
188 
189  timer->tm_sec -= elapsedTime;
190 
192 
193  try {
194  load(detectorFile, detector);
195  }
196  catch (const exception& error) {
197  FATAL(error.what() << endl);
198  }
199 
200  JModuleRouter router(detector);
201 
202  JUPITable fetchUPI(UPIFile.c_str());
203 
204 
205  // Read input
206 
207  TFile input(inputFile.c_str(), "READ");
208 
209  JManager<string, TMultiGraph> manager(new TMultiGraph(), "%.HVxG");
210 
211  input >> manager;
212 
213 
214  // Find optimal HV corresponding to a nominal gain of 1.0
215  // via linear interpolation in log-log scale
216 
217  JHVCalibration HVcalibrations;
218 
219  JHVGainGraph::setMinHVDistance(HVstepMin);
220  JHVGainGraph::setHVRange (HVrange);
221  JHVGainGraph::setGainRange (gainRange);
222 
223  NOTICE("Searching optimal high-voltage settings..." << endl <<
224  LEFT(30) << "UPI" << CENTER(35) << "(identifer / location)" << RIGHT(35) << "Inter-/Extrapolated high-voltage [-]" << endl);
225 
226  for (JManager<string, TMultiGraph>::iterator it = manager.begin(); it != manager.end(); ++it) {
227 
228  const string& name = it->first;
229  JHVGainGraph data(*it->second, loglog, base);
230 
231  // Retrieve upi, location and serialID
232 
233  const int seppos = name.find('.');
234  const int moduleID = stoi(name.substr(0, seppos));
235  const int tdc = stoi(name.substr(seppos + 1, seppos + 3));
236 
237  const JModule& module = router.getModule(moduleID);
238  const JPMT& pmt = router.getPMT(JPMTIdentifier(moduleID, tdc));
239 
240  const JUPI_t& pmtUPI = fetchUPI(PBS::PMT, pmt.getID());
241  const string location = MAKE_STRING(right << FILL(4,'0') << module.getLocation().getString() << '.' <<
242  right << FILL(2,'0') << module.getLocation().getFloor() << '.' <<
243  right << FILL(2,'0') << tdc);
244 
245  NOTICE(LEFT(30) << pmtUPI << "(a.k.a. " << name << " / " << location << "): ");
246 
247  if (data.interpolate(gainTarget)) {
248 
249  const double result = data.getTargetHV (gainTarget);
250  const double error = data.getTargetHVError(gainTarget);
251 
252  NOTICE(right << FIXED(20,2) << result << " +/- " << FIXED(4,2) << error << endl);
253 
254  HVcalibrations.push_back(JHVCalibration_t(pmtUPI, OK_t, result));
255 
256  } else {
257 
258  WARNING("Could not find high-voltage corresponding to target gain; Setting zero." << endl);
259 
260  HVcalibrations.push_back(JHVCalibration_t(pmtUPI, Failed_t, 0.0));
261  }
262  }
263 
264 
265  // Write json output
266 
267  json js;
268 
269  js[UUID_t] = MAKE_STRING(UUID);
270  js[User_t] = login;
271  js[Location_t] = locationID;
272  js[Test_t + Type_t] = testType;
273  js[StartTime_t] = timer.toString(format);
274  js[EndTime_t] = timer().toString(format);
275  js[Tests_t] = json(HVcalibrations);
276 
277  ofstream ofs(outputFile.c_str());
278 
279  ofs << setw(2) << setprecision(8);
280  ofs << js;
281 
282  ofs.close();
283 }
Utility class to parse command line options.
Definition: JParser.hh:1500
static const std::string UUID_t
#define WARNING(A)
Definition: JMessage.hh:65
Data structure for a composite optical module.
Definition: JModule.hh:57
static const std::string Failed_t
#define gmake_property(A)
macro to convert (template) parameter to JPropertiesElement object
static const std::string Tests_t
static const JPBS_t PMT(3, 4, 2, 3)
PBS of photo-multiplier tube (PMT)
static const std::string OK_t
static const double FITTOT_GAIN_MAX
Default maximal gain.
Definition: JFitToT.hh:44
Detector data structure.
Definition: JDetector.hh:80
static const double FITTOT_GAIN_MIN
Default minimal gain.
Definition: JFitToT.hh:43
Router for direct addressing of module data in detector data structure.
Utility class to parse parameter values.
Definition: JProperties.hh:496
static const std::string Location_t
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
JDateAndTimeFormat
Date and time formats.
Universal product identifier (UPI).
Definition: JUPI_t.hh:29
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:445
string outputFile
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
Auxiliary data structure for alignment of data.
Definition: JManip.hh:365
Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-volt...
Definition: JHVGainGraph.hh:35
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Detector file.
Definition: JHead.hh:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
return result
Definition: JPolint.hh:727
int getID() const
Get identifier.
Definition: JObjectID.hh:50
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:47
#define NOTICE(A)
Definition: JMessage.hh:64
static const std::string Test_t
ISO-8601 standard.
int debug
debug level
Definition: JSirene.cc:63
const double NOMINAL_GAIN
Specification for normalized gain corresponding to a one photo-electron pulse.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:327
#define FATAL(A)
Definition: JMessage.hh:67
then echo n User name
Definition: JCookie.sh:45
static const std::string EndTime_t
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Auxililary class to get date and time.
Simple wrapper for UUID.
Definition: JUUID.hh:22
Data structure for PMT high-voltage calibration.
nlohmann::json json
static const std::string Type_t
static const std::string StartTime_t
static const std::string User_t
Detector calibration key words for JSON I/O.
do set_variable DETECTOR_TXT $WORKDIR detector