Jpp  17.2.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[Comment_t] = json(detector.comment);
105  js[Data_t][0][DetID_t] = json(detector.getID());
106  js[Data_t][0][PMTT0s_t] = json(data);
107  js[Error_t] = json(error);
108 
109  store(setWildCard(outputFile.c_str(), TCAL), js);
110  }
111  {
112  json js;
113  JModulePosition data[2];
114 
115  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
116 
117  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
118 
119  if (buffer.getFloor() == 0)
120  data[0].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
121  else
122  data[1].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
123  }
124 
125  js[Comment_t] = json(detector.comment);
126  js[Data_t][0][DetID_t] = json(detector.getID());
127  js[Data_t][0][BasePositions_t] = json(data[0]);
128  js[Data_t][0][DOMPositions_t] = json(data[1]);
129  js[Error_t] = json(error);
130 
131  store(setWildCard(outputFile.c_str(), PCAL), js);
132  }
133  {
134  json js;
135  JModuleRotation data[2];
136 
137  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
138 
139  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
140 
141  if (module->getFloor() == 0)
142  data[0].push_back(JModuleRotation_t(module->getID(), JQuaternion3D()));
143  else
144  data[1].push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module)));
145  }
146 
147  js[Comment_t] = json(detector.comment);
148  js[Data_t][0][DetID_t] = json(detector.getID());
149  js[Data_t][0][BaseRotations_t] = json(data[0]);
150  js[Data_t][0][DOMRotations_t] = json(data[1]);
151  js[Error_t] = json(error);
152 
153  store(setWildCard(outputFile.c_str(), RCAL), js);
154  }
155  {
156  json js;
157  JModuleCalibration data;
158 
159  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
160  data.push_back(JModuleCalibration_t(module->getID(), module->getT0()));
161  }
162 
163  js[Comment_t] = json(detector.comment);
164  js[Data_t][0][DetID_t] = json(detector.getID());
165  js[Data_t][0][DOMAcousticT0_t] = json(data);
166  js[Error_t] = json(error);
167 
168  store(setWildCard(outputFile.c_str(), ACAL), js);
169  }
170  {
171  json js;
172  JCompassRotation data;
173 
174  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
175  data.push_back(JCompassRotation_t(module->getID(), module->getQuaternion()));
176  }
177 
178  js[Comment_t] = json(detector.comment);
179  js[Data_t][0][DetID_t] = json(detector.getID());
180  js[Data_t][0][DOMCompassRotations_t] = json(data);
181  js[Error_t] = json(error);
182 
183  store(setWildCard(outputFile.c_str(), CCAL), js);
184  }
185  {
186  json js;
187 
188  {
189  JPMTStatus data;
190 
191  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
192  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
193  data.push_back(JPMTStatus_t(pmt->getID(), pmt->getStatus()));
194  }
195  }
196 
197  js[Data_t][0][PMTStatusInfo_t ] = json(data);
198  }
199  {
200  JModuleStatus data[2];
201 
202  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
203  if (module->getFloor() == 0)
204  data[0].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
205  else
206  data[1].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
207  }
208 
209  js[Data_t][0][BaseStatusInfo_t] = json(data[0]);
210  js[Data_t][0][DOMStatusInfo_t] = json(data[1]);
211  }
212  {
213  js[Comment_t] = json(detector.comment);
214  js[Data_t][0][DetID_t] = json(detector.getID());
215  js[Error_t] = json(error);
216  }
217 
218  store(setWildCard(outputFile.c_str(), SCAL), js);
219  }
220 
221  return 0;
222 }
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 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:226
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
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 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
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 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
int debug
debug level
static const std::string BasePositions_t
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
Definition: JeepToolkit.hh:53