Jpp  17.2.1-pre0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDestructDetector.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <fstream>
5 
6 #include "JDetector/JDetector.hh"
10 
11 #include "JSon/JSon.hh"
12 
13 #include "Jeep/JeepToolkit.hh"
14 #include "Jeep/JPrint.hh"
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * \file
21  *
22  * Auxiliary program to decompose detector to separate calibrations.
23  * \author mdejong
24  */
25 int main(int argc, char **argv)
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  JModuleMap data;
97 
98  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
99 
100  const JModuleAddressMap& memo = demo.get(module->getID());
101 
102  JModuleMap_t buffer(module->getID());
103 
104  for (size_t i = 0; i != module->size(); ++i) {
105  buffer[memo.getPMTPhysicalAddress(i).toString()] = (*module)[i].getID();
106  }
107 
108  data.push_back(buffer);
109  }
110 
111  js[Comment_t] = json(detector.comment);
112  js[Data_t][0][DetID_t] = json(detector.getID());
113  js[Data_t][0][DOMMap_t] = json(data);
114  js[Error_t] = json(error);
115 
116  store(setWildCard(outputFile.c_str(), MMAP), js);
117  }
118  {
119  json js;
120  JPMTCalibration data;
121 
122  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
123  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
124  data.push_back(JPMTCalibration_t(pmt->getID(), getCalibration(JCalibration(), *pmt)));
125  }
126  }
127 
128  js[Comment_t] = json(detector.comment);
129  js[Data_t][0][DetID_t] = json(detector.getID());
130  js[Data_t][0][PMTT0s_t] = json(data);
131  js[Error_t] = json(error);
132 
133  store(setWildCard(outputFile.c_str(), TCAL), js);
134  }
135  {
136  json js;
137  JModulePosition data[2];
138 
139  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
140 
141  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
142 
143  if (buffer.getFloor() == 0)
144  data[0].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
145  else
146  data[1].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
147  }
148 
149  js[Comment_t] = json(detector.comment);
150  js[Data_t][0][DetID_t] = json(detector.getID());
151  js[Data_t][0][BasePositions_t] = json(data[0]);
152  js[Data_t][0][DOMPositions_t] = json(data[1]);
153  js[Error_t] = json(error);
154 
155  store(setWildCard(outputFile.c_str(), PCAL), js);
156  }
157  {
158  json js;
159  JModuleRotation data[2];
160 
161  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
162 
163  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
164 
165  if (module->getFloor() == 0)
166  data[0].push_back(JModuleRotation_t(module->getID(), JQuaternion3D()));
167  else
168  data[1].push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module)));
169  }
170 
171  js[Comment_t] = json(detector.comment);
172  js[Data_t][0][DetID_t] = json(detector.getID());
173  js[Data_t][0][BaseRotations_t] = json(data[0]);
174  js[Data_t][0][DOMRotations_t] = json(data[1]);
175  js[Error_t] = json(error);
176 
177  store(setWildCard(outputFile.c_str(), RCAL), js);
178  }
179  {
180  json js;
181  JModuleCalibration data;
182 
183  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
184  data.push_back(JModuleCalibration_t(module->getID(), module->getT0()));
185  }
186 
187  js[Comment_t] = json(detector.comment);
188  js[Data_t][0][DetID_t] = json(detector.getID());
189  js[Data_t][0][DOMAcousticT0_t] = json(data);
190  js[Error_t] = json(error);
191 
192  store(setWildCard(outputFile.c_str(), ACAL), js);
193  }
194  {
195  json js;
196  JCompassRotation data;
197 
198  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
199  data.push_back(JCompassRotation_t(module->getID(), module->getQuaternion()));
200  }
201 
202  js[Comment_t] = json(detector.comment);
203  js[Data_t][0][DetID_t] = json(detector.getID());
204  js[Data_t][0][DOMCompassRotations_t] = json(data);
205  js[Error_t] = json(error);
206 
207  store(setWildCard(outputFile.c_str(), CCAL), js);
208  }
209  {
210  json js;
211 
212  {
213  JPMTStatus data;
214 
215  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
216  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
217  data.push_back(JPMTStatus_t(pmt->getID(), pmt->getStatus()));
218  }
219  }
220 
221  js[Data_t][0][PMTStatusInfo_t ] = json(data);
222  }
223  {
224  JModuleStatus data[2];
225 
226  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
227  if (module->getFloor() == 0)
228  data[0].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
229  else
230  data[1].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
231  }
232 
233  js[Data_t][0][BaseStatusInfo_t] = json(data[0]);
234  js[Data_t][0][DOMStatusInfo_t] = json(data[1]);
235  }
236  {
237  js[Comment_t] = json(detector.comment);
238  js[Data_t][0][DetID_t] = json(detector.getID());
239  js[Error_t] = json(error);
240  }
241 
242  store(setWildCard(outputFile.c_str(), SCAL), js);
243  }
244 
245  return 0;
246 }
static const std::string PMTStatusInfo_t
Utility class to parse command line options.
Definition: JParser.hh:1517
General exception.
Definition: JException.hh:23
static const std::string DetID_t
static const std::string RCAL
(optical|base) module orientations
int main(int argc, char *argv[])
Definition: Main.cc:15
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
Data structure for detector geometry and calibration.
Auxiliary data structure for module time calibration.
Lookup table for PMT addresses in optical module.
static const std::string Arguments_t
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:226
Auxiliary data structure for module address map.
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:1993
Auxiliary methods for handling file names, type names and environment.
static const std::string DOMRotations_t
int getID() const
Get identifier.
Definition: JObjectID.hh:50
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 struct JACOUSTICS::@4 compare
Auxiliary data structure to sort transmissions.
static const std::string Message_t
static const std::string DOMAcousticT0_t
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
General purpose messaging.
static const std::string BaseRotations_t
static const std::string Comment_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 DOMMap_t
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.
Utility class to parse command line options.
std::string toString() const
Convert PMT physical address to string.
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
const JPMTPhysicalAddress & getPMTPhysicalAddress(const int tdc) const
Get PMT physical address.
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
int debug
debug level
static const std::string BasePositions_t
static const std::string MMAP
module address map
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
Definition: JeepToolkit.hh:53