Jpp  17.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JDestructDetector.cc File Reference

Auxiliary program to decompose detector to separate calibrations. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorAddressMapToolkit.hh"
#include "JSon/JSon.hh"
#include "Jeep/JeepToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to decompose detector to separate calibrations.

Author
mdejong

Definition in file JDestructDetector.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file JDestructDetector.cc.

26 {
27  using namespace std;
28  using namespace JPP;
29 
30  string detectorFile;
31  string outputFile;
32  double precision;
33  int debug;
34 
35  try {
36 
37  JParser<> zap("Auxiliary program to decompose detector to separate calibrations.");
38 
39  zap['a'] = make_field(detectorFile, "detector file");
40  zap['o'] = make_field(outputFile, "detector calibrations file in JSON format "\
41  "(should contain wild card \'" << FILENAME_WILD_CARD << "\')");
42  zap['p'] = make_field(precision) = 1.0e-5;
43  zap['d'] = make_field(debug) = 1;
44 
45  zap(argc, argv);
46  }
47  catch(const exception &error) {
48  FATAL(error.what() << endl);
49  }
50 
51 
52  if (!hasWildCard(outputFile)) {
53  FATAL("No wild card \'" << FILENAME_WILD_CARD << "\' in " << outputFile);
54  }
55 
57 
58  try {
59  load(detectorFile, detector);
60  }
61  catch(const JException& error) {
62  FATAL(error);
63  }
64 
65  if (!hasDetectorAddressMap(detector.getID())) {
66  FATAL("No detector address map for detector identier " << detector.getID() << endl);
67  }
68 
69  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
70 
71 
72  // Test compatibility of modules with reference(s).
73 
74  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
75 
76  if (module->getFloor() != 0) {
77 
78  JModule buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
79 
80  const JRotation3D R = getRotation(buffer, *module);
81 
82  buffer.rotate(R);
83 
84  if (!JModule::compare(buffer, *module, precision)) {
85  FATAL("Module " << setw(10) << module->getID() << ' ' << module->getLocation() << " incompatible with reference." << endl);
86  }
87  }
88  }
89 
90  const json error = { {Message_t, "" },
91  {Code_t, OK_t },
92  {Arguments_t, json::array() } };
93 
94  {
95  json js;
96  JPMTCalibration data;
97 
98  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
99  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
100  data.push_back(JPMTCalibration_t(pmt->getID(), getCalibration(JCalibration(), *pmt)));
101  }
102  }
103 
104  js[Data_t][0][DetID_t] = json(detector.getID());
105  js[Data_t][0][PMTT0s_t] = json(data);
106  js[Error_t] = json(error);
107 
108  store(setWildCard(outputFile.c_str(), TCAL), js);
109  }
110  {
111  json js;
112  JModulePosition data[2];
113 
114  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
115 
116  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
117 
118  if (buffer.getFloor() == 0)
119  data[0].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
120  else
121  data[1].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
122  }
123 
124  js[Data_t][0][DetID_t] = json(detector.getID());
125  js[Data_t][0][BasePositions_t] = json(data[0]);
126  js[Data_t][0][DOMPositions_t] = json(data[1]);
127  js[Error_t] = json(error);
128 
129  store(setWildCard(outputFile.c_str(), PCAL), js);
130  }
131  {
132  json js;
133  JModuleRotation data[2];
134 
135  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
136 
137  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
138 
139  if (module->getFloor() == 0)
140  data[0].push_back(JModuleRotation_t(module->getID(), JQuaternion3D()));
141  else
142  data[1].push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module)));
143  }
144 
145  js[Data_t][0][DetID_t] = json(detector.getID());
146  js[Data_t][0][BaseRotations_t] = json(data[0]);
147  js[Data_t][0][DOMRotations_t] = json(data[1]);
148  js[Error_t] = json(error);
149 
150  store(setWildCard(outputFile.c_str(), RCAL), js);
151  }
152  {
153  json js;
154  JModuleCalibration data;
155 
156  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
157  data.push_back(JModuleCalibration_t(module->getID(), module->getT0()));
158  }
159 
160  js[Data_t][0][DetID_t] = json(detector.getID());
161  js[Data_t][0][DOMAcousticT0_t] = json(data);
162  js[Error_t] = json(error);
163 
164  store(setWildCard(outputFile.c_str(), ACAL), js);
165  }
166  {
167  json js;
168  JCompassRotation data;
169 
170  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
171  data.push_back(JCompassRotation_t(module->getID(), module->getQuaternion()));
172  }
173 
174  js[Data_t][0][DetID_t] = json(detector.getID());
175  js[Data_t][0][DOMCompassRotations_t] = json(data);
176  js[Error_t] = json(error);
177 
178  store(setWildCard(outputFile.c_str(), CCAL), js);
179  }
180  {
181  json js;
182 
183  {
184  JPMTStatus data;
185 
186  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
187  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
188  data.push_back(JPMTStatus_t(pmt->getID(), pmt->getStatus()));
189  }
190  }
191 
192  js[Data_t][0][PMTStatusInfo_t ] = json(data);
193  }
194  {
195  JModuleStatus data[2];
196 
197  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
198  if (module->getFloor() == 0)
199  data[0].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
200  else
201  data[1].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
202  }
203 
204  js[Data_t][0][BaseStatusInfo_t] = json(data[0]);
205  js[Data_t][0][DOMStatusInfo_t] = json(data[1]);
206  }
207  {
208  js[Data_t][0][DetID_t] = json(detector.getID());
209  js[Error_t] = json(error);
210  }
211 
212  store(setWildCard(outputFile.c_str(), SCAL), js);
213  }
214 }
static const std::string PMTStatusInfo_t
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
static const std::string DetID_t
static const std::string RCAL
(optical|base) module orientations
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
Data structure for a composite optical module.
Definition: JModule.hh:68
static const std::string DOMPositions_t
static const std::string OK_t
Detector data structure.
Definition: JDetector.hh:89
Rotation matrix.
Definition: JRotation3D.hh:111
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
static const std::string TCAL
PMT time offsets.
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
Lookup table for PMT addresses in detector.
static const std::string CCAL
compass alignment (a.k.a. quaternion calibration)
Data structure for time calibration.
string outputFile
Auxiliary data structure for module time calibration.
static const std::string Arguments_t
Detector file.
Definition: JHead.hh:224
Auxiliary data structure for compass rotation.
static const std::string SCAL
PMT status.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
static const std::string DOMRotations_t
static const std::string PCAL
(optical|base) module positions
static const std::string ACAL
acoustic time offsets (piezo sensor or hydrophone)
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
JPosition3D getPosition(const Vec &pos)
Get position.
static const std::string Code_t
static const std::string Message_t
static const std::string DOMAcousticT0_t
int debug
debug level
Definition: JSirene.cc:66
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:315
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
static const std::string BaseRotations_t
#define FATAL(A)
Definition: JMessage.hh:67
Data structure for unit quaternion in three dimensions.
std::string setWildCard(const std::string &file_name, const std::string &value)
Get file name by setting wild card to given value.
Definition: JeepToolkit.hh:66
static const std::string DOMCompassRotations_t
Auxiliary data structure for PMT status.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
nlohmann::json json
Auxiliary data structure for module rotation.
static const char FILENAME_WILD_CARD
wild card character for file name substitution
Definition: JeepToolkit.hh:44
Auxiliary data structure for module position.
static const std::string DOMStatusInfo_t
static const std::string PMTT0s_t
static const std::string Error_t
do set_variable DETECTOR_TXT $WORKDIR detector
static const std::string Data_t
Auxiliary data structure for PMT time calibration.
Auxiliary data structure for module status.
static const std::string BaseStatusInfo_t
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
static const std::string BasePositions_t
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
Definition: JeepToolkit.hh:53