Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDetectorCalibration.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JDETECTORCALIBRATION__
2 #define __JDETECTOR__JDETECTORCALIBRATION__
3 
4 #include <string>
5 #include <vector>
6 
7 #include "JDB/JUPI_t.hh"
8 #include "JSon/JSon.hh"
9 #include "JLang/JObjectID.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JDETECTOR {}
20 namespace JPP { using namespace JDETECTOR; }
21 
22 /**
23  * Auxiliary classes and methods for detector calibration.
24  */
25 namespace JDETECTOR {
26 
27  using JSON::json;
28  using JLANG::JObjectID;
29  using JDATABASE::JUPI_t;
30  using JDATABASE::JPBS_t;
33 
34  /**
35  * Detector calibration key words for JSON I/O.
36  */
37 
38  // Meta data
39  static const std::string User_t = "User";
40  static const std::string Location_t = "Location";
41  static const std::string StartTime_t = "StartTime";
42  static const std::string EndTime_t = "EndTime";
43  static const std::string Comment_t = "Comment";
44  static const std::string UUID_t = "UUID";
45 
46  // Type specifiers
47  static const std::string Type_t = "Type";
48  static const std::string Parameters_t = "Parameters";
49  static const std::string Tests_t = "Tests";
50  static const std::string Data_t = "Data";
51  static const std::string RunNumber_t = "RUN_NUMBER";
52  static const std::string Name_t = "Name";
53  static const std::string Unit_t = "Unit";
54  static const std::string Values_t = "Values";
55 
56  // Calibration types
57  static const std::string PMTT0s_t = "PMTT0s";
58  static const std::string PMTSupplyVoltage_t = "PMT_Supply_Voltage";
59  static const std::string PMTThreshold_t = "PMT_Threshold";
60  static const std::string PMTGain_t = "PMT_Gain";
61  static const std::string DOMPositions_t = "DOMPositions";
62  static const std::string DOMRotations_t = "DOMRotations";
63 
64  // Prefixes
65  static const std::string Test_t = "Test";
66  static const std::string Target_t = "Target";
67  static const std::string Outcome_t = "Outcome";
68 
69  // Identifiers
70  static const std::string UPI_t = "UPI";
71  static const std::string PBS_t = "PBS";
72  static const std::string Variant_t = "Variant";
73  static const std::string PMTSerial_t = "PMTSerial";
74  static const std::string DOMSerial_t = "DOMSerial";
75  static const std::string DOMId_t = "DOMId";
76 
77  // Variable names
78  static const std::string T0_t = "T0";
79  static const std::string PX_t = "PX";
80  static const std::string PY_t = "PY";
81  static const std::string PZ_t = "PZ";
82  static const std::string Q0_t = "Q0";
83  static const std::string QX_t = "QX";
84  static const std::string QY_t = "QY";
85  static const std::string QZ_t = "QZ";
86 
87  // Units
88  static const std::string Unitless_t = "-";
89  static const std::string Volt_t = "V";
90 
91  // Status
92  static const std::string Result_t = "Result";
93  static const std::string OK_t = "OK";
94  static const std::string Failed_t = "FAILED";
95 
96 
97  /**
98  * Check validity of JSon data.
99  *
100  * \param js JSon data
101  * \return true if valid; else false
102  */
103  inline bool is_valid(const json& js)
104  {
105  return js.contains(Result_t) && js[Result_t] == OK_t;
106  }
107 
108 
109  /**
110  * Cast single value to array of strings, conform the DB-format.
111  *
112  * \param value value
113  * \return std::vector containing value casted to string
114  */
115  template <class T>
117  {
118  using namespace std;
119 
120  return vector<string>{ to_string(value) };
121  }
122 
123 
124  /**
125  * Retrieve value from json array of strings.
126  *
127  * \param string_value_array array of string-casted values
128  * \return double-casted value
129  */
130  inline double retrieve_value(std::vector<std::string> string_value_array)
131  {
132  return std::stod(string_value_array[0]);
133  }
134 
135 
136  /**
137  * Auxiliary data structure for PMT time calibration.
138  */
140  public JObjectID,
141  public JCalibration
142  {
143  /**
144  * Default constructor.
145  */
147  {}
148 
149 
150  /**
151  * Constructor.
152  *
153  * \param id PMT identifier
154  * \param calibration PMT time calibration
155  */
157  const JCalibration& calibration) :
158  JObjectID (id),
159  JCalibration(calibration)
160  {}
161  };
162 
163 
164  /**
165  * Convert PMT time calibration to JSon.
166  *
167  * \param js json
168  * \param object PMT time calibration
169  */
170  inline void to_json(json& js, const JPMTCalibration_t& object)
171  {
172  js = json{ { PMTSerial_t, object.getID() },
173  { T0_t, object.getT0() } };
174  }
175 
176 
177  /**
178  * Convert JSon to PMT time calibration.
179  *
180  * \param js json
181  * \param object PMT time calibration
182  */
183  inline void from_json(const json& js, JPMTCalibration_t& object)
184  {
185  object.setID(js.at(PMTSerial_t).get<int>());
186 
187  object.setT0(js.at(T0_t).get<double>());
188  }
189 
190 
191  /**
192  * Data structure for PMT high-voltage calibration.
193  */
195  public JUPI_t
196  {
197  /**
198  * Default constructor.
199  */
201  {}
202 
203 
204  /**
205  * Constructor.
206  *
207  * \param upi %UPI
208  * \param result result
209  * \param hv HV
210  */
212  const std::string& result,
213  const double hv) :
214  JUPI_t (upi),
215  result (result),
216  supplyVoltage(hv)
217  {}
218 
219  std::string result;
221  };
222 
223 
224  /**
225  * Convert PMT high-voltage calibration to JSon.
226  *
227  * \param js json
228  * \param object PMT high-voltage calibration
229  */
230  inline void to_json(json& js, const JHVCalibration_t& object)
231  {
232  std::ostringstream os;
233 
234  os << object.getUPI();
235 
236  js[UPI_t] = os.str();
237  js[Test_t + Result_t] = object.result;
239  { Unit_t, Volt_t },
240  { Values_t, get_string_array(object.supplyVoltage) } };
241  }
242 
243 
244  /**
245  * Convert JSon to PMT high-voltage calibration.
246  *
247  * \param js json
248  * \param object PMT high-voltage calibration
249  */
250  inline void from_json(const json& js, JHVCalibration_t& object)
251  {
252  using namespace std;
253 
254  stringstream is(js.at(UPI_t).get<string>());
255 
256  is >> static_cast<JUPI_t&>(object);
257 
258  object.result = js.at(Test_t + Result_t).get<string>();
259  object.supplyVoltage = retrieve_value(js.at(Test_t + Parameters_t)[0].at(Values_t).get<vector<string>>());
260  }
261 
262 
263  /**
264  * Data structure for PMT threshold calibration.
265  */
267  public JUPI_t
268  {
269  /**
270  * Default constructor.
271  */
273  {}
274 
275  /**
276  * Constructor.
277  *
278  * \param upi %UPI
279  * \param result result
280  * \param threshold threshold
281  * \param runNumbers run numbers
282  */
284  const std::string& result,
285  const double threshold,
286  const std::vector<std::string>& runNumbers = std::vector<std::string>{}) :
287  JUPI_t (upi),
288  result (result),
289  threshold (threshold),
290  runNumberList(runNumbers)
291  {}
292  std::string result;
293  double threshold;
295  };
296 
297 
298  /**
299  * Convert PMT threshold calibration to JSon.
300  *
301  * \param js json
302  * \param object PMT threshold calibration
303  */
304  inline void to_json(json& js, const JTHCalibration_t& object)
305  {
306  std::ostringstream os;
307 
308  os << object.getUPI();
309 
310  js[UPI_t] = os.str();
311  js[Test_t + Result_t] = object.result;
312  js[Test_t + Parameters_t][0] = json{ { Name_t, PMTThreshold_t },
313  { Unit_t, Unitless_t },
314  { Values_t, get_string_array(object.threshold) } };
315  js[Test_t + Parameters_t][2] = json{ { Name_t, RunNumber_t },
316  { Unit_t, Unitless_t },
317  { Values_t, object.runNumberList } };
318  }
319 
320 
321  /**
322  * Convert JSon to PMT threshold calibration.
323  *
324  * \param js json
325  * \param object PMT threshold calibration
326  */
327  inline void from_json(const json& js, JTHCalibration_t& object)
328  {
329  using namespace std;
330 
331  stringstream is(js.at(UPI_t).get<string>());
332 
333  is >> static_cast<JUPI_t&>(object);
334 
335  object.result = js.at(Test_t + Result_t).get<string>();
336  object.threshold = retrieve_value(js.at(Test_t + Parameters_t)[0].at(Values_t).get<vector<string>>());
337  object.runNumberList = js.at(Test_t + Parameters_t)[2].at(Values_t).get<vector<string>>();
338  }
339 
340 
341  /**
342  * Auxiliary data structure for module position.
343  */
345  public JObjectID,
346  public JPosition3D
347  {
348  /**
349  * Default constructor.
350  */
352  {}
353 
354 
355  /**
356  * Constructor.
357  *
358  * \param id module identifier
359  * \param position module position
360  */
362  const JPosition3D& position) :
363  JObjectID (id),
364  JPosition3D(position)
365  {}
366  };
367 
368 
369  /**
370  * Convert module position to JSon.
371  *
372  * \param js json
373  * \param object module position
374  */
375  inline void to_json(json& js, const JModulePosition_t& object)
376  {
377  js = json{ { DOMId_t, object.getID() },
378  { PX_t, object.getX() },
379  { PY_t, object.getY() },
380  { PZ_t, object.getZ() } };
381  }
382 
383 
384  /**
385  * Convert JSon to module position.
386  *
387  * \param js json
388  * \param object module position
389  */
390  inline void from_json(const json& js, JModulePosition_t& object)
391  {
392  object.setID(js.at(DOMId_t).get<int>());
393 
394  object.setPosition(JPosition3D(js.at(PX_t).get<double>(),
395  js.at(PY_t).get<double>(),
396  js.at(PZ_t).get<double>()));
397  }
398 
399  /**
400  * Auxiliary data structure for module rotation.
401  */
403  public JObjectID,
404  public JQuaternion3D
405  {
406  /**
407  * Default constructor.
408  */
410  {}
411 
412 
413  /**
414  * Constructor.
415  *
416  * \param id module identifier
417  * \param rotation module rotation
418  */
420  const JQuaternion3D& rotation) :
421  JObjectID (id),
422  JQuaternion3D(rotation)
423  {}
424  };
425 
426 
427  /**
428  * Convert module rotation to JSon.
429  *
430  * \param js json
431  * \param object module rotation
432  */
433  inline void to_json(json& js, const JModuleRotation_t& object)
434  {
435  js = json{ { DOMId_t, object.getID() },
436  { Q0_t, object.getA() },
437  { QX_t, object.getB() },
438  { QY_t, object.getC() },
439  { QZ_t, object.getD() } };
440  }
441 
442 
443  /**
444  * Convert JSon to module rotation.
445  *
446  * \param js json
447  * \param object module rotation
448  */
449  inline void from_json(const json& js, JModuleRotation_t& object)
450  {
451  object.setID(js.at(DOMId_t).get<int>());
452 
453  object.setQuaternion(JQuaternion3D(js.at(Q0_t).get<double>(),
454  js.at(QX_t).get<double>(),
455  js.at(QY_t).get<double>(),
456  js.at(QZ_t).get<double>()));
457  }
458 
459  typedef std::vector<JHVCalibration_t> JHVCalibration; //!< PMT high voltage calibration
460  typedef std::vector<JTHCalibration_t> JTHCalibration; //!< PMT threshold calibration
461  typedef std::vector<JPMTCalibration_t> JPMTCalibration; //!< PMT time calibration
462  typedef std::vector<JModulePosition_t> JModulePosition; //!< Module position
463  typedef std::vector<JModuleRotation_t> JModuleRotation; //!< Module rotation
464 }
465 
466 #endif
static const std::string DOMSerial_t
static const std::string UUID_t
static const std::string PMTGain_t
void to_json(json &js, const JPMTCalibration_t &object)
Convert PMT time calibration to JSon.
static const std::string PZ_t
static const std::string Name_t
static const std::string PMTSupplyVoltage_t
static const std::string Q0_t
JPMTCalibration_t()
Default constructor.
Time calibration (including definition of sign of time offset).
JHVCalibration_t(const JUPI_t &upi, const std::string &result, const double hv)
Constructor.
static const std::string Unit_t
static const std::string Failed_t
static const std::string UPI_t
static const std::string Tests_t
static const std::string DOMPositions_t
static const std::string OK_t
JModuleRotation_t(const JObjectID &id, const JQuaternion3D &rotation)
Constructor.
static const std::string DOMId_t
JHVCalibration_t()
Default constructor.
std::vector< JModuleRotation_t > JModuleRotation
Module rotation.
static const std::string QZ_t
static const std::string Variant_t
static const std::string PX_t
static const std::string Location_t
Universal product identifier (UPI).
Definition: JUPI_t.hh:29
Data structure for time calibration.
double retrieve_value(std::vector< std::string > string_value_array)
Retrieve value from json array of strings.
JPMTCalibration_t(const JObjectID &id, const JCalibration &calibration)
Constructor.
is
Definition: JDAQCHSM.chsm:167
static const std::string Target_t
std::vector< std::string > runNumberList
static const std::string Result_t
static const std::string Outcome_t
static const std::string Volt_t
void from_json(const json &js, JPMTCalibration_t &object)
Convert JSon to PMT time calibration.
static const std::string T0_t
std::vector< JHVCalibration_t > JHVCalibration
PMT high voltage calibration.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
static const std::string DOMRotations_t
bool is_valid(const json &js)
Check validity of JSon data.
static const std::string PMTThreshold_t
static const std::string Test_t
static const std::string PMTSerial_t
static const std::string RunNumber_t
JModulePosition_t(const JObjectID &id, const JPosition3D &position)
Constructor.
static const std::string Comment_t
Data structure for unit quaternion in three dimensions.
static const std::string Values_t
JTHCalibration_t()
Default constructor.
static const std::string PY_t
static const std::string EndTime_t
JModulePosition_t()
Default constructor.
static const std::string PBS_t
Auxiliary class for object identification.
Definition: JObjectID.hh:22
std::vector< JTHCalibration_t > JTHCalibration
PMT threshold calibration.
Data structure for PMT high-voltage calibration.
nlohmann::json json
static const std::string Type_t
std::string to_string(const T &value)
Convert value to string.
static const std::string StartTime_t
Auxiliary data structure for module rotation.
JModuleRotation_t()
Default constructor.
Product breakdown structure (PBS).
Definition: JPBS_t.hh:25
static const std::string User_t
Detector calibration key words for JSON I/O.
Auxiliary data structure for module position.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
static const std::string PMTT0s_t
std::vector< JModulePosition_t > JModulePosition
Module position.
JTHCalibration_t(const JUPI_t &upi, const std::string &result, const double threshold, const std::vector< std::string > &runNumbers=std::vector< std::string >{})
Constructor.
static const std::string Parameters_t
static const std::string Data_t
Auxiliary data structure for PMT time calibration.
static const std::string QY_t
static const std::string Unitless_t
std::vector< JPMTCalibration_t > JPMTCalibration
PMT time calibration.
Data structure for PMT threshold calibration.
std::vector< std::string > get_string_array(T value)
Cast single value to array of strings, conform the DB-format.
static const std::string QX_t