Jpp  18.2.1-ARCA-DF-PATCH
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  "(optionally contains wild card \'" << FILENAME_WILD_CARD << "\')");
42  zap['p'] = make_field(precision, "precision for match with reference module") = 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  JDetector detector;
53 
54  try {
55  load(detectorFile, detector);
56  }
57  catch(const JException& error) {
58  FATAL(error);
59  }
60 
61  if (!hasDetectorAddressMap(detector.getID())) {
62  FATAL("No detector address map for detector identier " << detector.getID() << endl);
63  }
64 
65  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
66 
67 
68  // Test compatibility of modules with reference(s).
69 
70  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
71 
72  if (module->getFloor() != 0) {
73 
74  JModule buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
75 
76  const JRotation3D R = getRotation(buffer, *module);
77 
78  buffer.rotate(R);
79 
80  if (!JModule::compare(buffer, *module, precision)) {
81  FATAL("Module " << setw(10) << module->getID() << ' ' << module->getLocation() << " incompatible with reference." << endl);
82  }
83  }
84  }
85 
86 
87  const json error = { {Message_t, "" },
88  {Code_t, OK_t },
89  {Arguments_t, json::array() } };
90 
91 
92  json js;
93  size_t N = 0; // data
94 
95  js[Comment_t] = json(detector.comment);
96  js[Error_t] = json(error);
97 
98  {
100 
101  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
102  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
103  data.push_back(JPMTCalibration_t(pmt->getID(), getCalibration(JCalibration(), *pmt)));
104  }
105  }
106 
107  js[Data_t][N][DetID_t] = json(detector.getID());
108  js[Data_t][N][PMTT0s_t] = json(data);
109 
110  if (hasWildCard(outputFile)) {
111 
112  store(setWildCard(outputFile.c_str(), TCAL), js);
113 
114  js[Data_t].clear();
115 
116  } else {
117 
118  N += 1;
119  }
120  }
121  {
122  JModulePosition data[2];
123 
124  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
125 
126  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
127 
128  if (buffer.getFloor() == 0)
129  data[0].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
130  else
131  data[1].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
132  }
133 
134  js[Data_t][N][DetID_t] = json(detector.getID());
135  js[Data_t][N][BasePositions_t] = json(data[0]);
136  js[Data_t][N][DOMPositions_t] = json(data[1]);
137 
138  if (hasWildCard(outputFile)) {
139 
140  store(setWildCard(outputFile.c_str(), PCAL), js);
141 
142  js[Data_t].clear();
143 
144  } else {
145 
146  N += 1;
147  }
148  }
149  {
151 
152  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
153 
154  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
155 
156  if (module->getFloor() != 0) {
157  data.push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module)));
158  }
159  }
160 
161  js[Data_t][N][DetID_t] = json(detector.getID());
162  js[Data_t][N][DOMRotations_t] = json(data);
163 
164  if (hasWildCard(outputFile)) {
165 
166  store(setWildCard(outputFile.c_str(), RCAL), js);
167 
168  js[Data_t].clear();
169 
170  } else {
171 
172  N += 1;
173  }
174  }
175  {
176  JModuleCalibration data[2];
177 
178  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
179 
180  if (module->getFloor() == 0)
181  data[0].push_back(JModuleCalibration_t(module->getID(), module->getT0()));
182  else
183  data[1].push_back(JModuleCalibration_t(module->getID(), module->getT0()));
184  }
185 
186  js[Data_t][N][DetID_t] = json(detector.getID());
187  js[Data_t][N][BaseAcousticT0_t] = json(data[0]);
188  js[Data_t][N][DOMAcousticT0_t] = json(data[1]);
189 
190  if (hasWildCard(outputFile)) {
191 
192  store(setWildCard(outputFile.c_str(), ACAL), js);
193 
194  js[Data_t].clear();
195 
196  } else {
197 
198  N += 1;
199  }
200  }
201  {
202  JCompassRotation data[2];
203 
204  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
205  if (module->getFloor() == 0)
206  data[0].push_back(JCompassRotation_t(module->getID(), module->getQuaternion()));
207  else
208  data[1].push_back(JCompassRotation_t(module->getID(), module->getQuaternion()));
209  }
210 
211  js[Data_t][N][DetID_t] = json(detector.getID());
212  js[Data_t][N][BaseCompassRotations_t] = json(data[0]);
213  js[Data_t][N][DOMCompassRotations_t] = json(data[1]);
214 
215  if (hasWildCard(outputFile)) {
216 
217  store(setWildCard(outputFile.c_str(), CCAL), js);
218 
219  js[Data_t].clear();
220 
221  } else {
222 
223  N += 1;
224  }
225  }
226  {
227  js[Data_t][N][DetID_t] = json(detector.getID());
228 
229  {
231 
232  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
233  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
234  data.push_back(JPMTStatus_t(pmt->getID(), pmt->getStatus()));
235  }
236  }
237 
238  js[Data_t][N][PMTStatusInfo_t ] = json(data);
239  }
240  {
241  JModuleStatus data[2];
242 
243  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
244  if (module->getFloor() == 0)
245  data[0].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
246  else
247  data[1].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
248  }
249 
250  js[Data_t][N][BaseStatusInfo_t] = json(data[0]);
251  js[Data_t][N][DOMStatusInfo_t] = json(data[1]);
252  }
253 
254  if (hasWildCard(outputFile)) {
255 
256  store(setWildCard(outputFile.c_str(), SCAL), js);
257 
258  js[Data_t].clear();
259 
260  } else {
261 
262  N += 1;
263  }
264  }
265 
266 
267  if (!hasWildCard(outputFile)) {
268  store(outputFile.c_str(), js);
269  }
270 
271  return 0;
272 }
static const std::string Arguments_t
Utility class to parse command line options.
Definition: JParser.hh:1514
static const std::string DOMStatusInfo_t
static const std::string Code_t
static const std::string ACAL
acoustic time offsets (piezo sensor or hydrophone)
static const std::string CCAL
compass alignment (a.k.a. quaternion calibration)
static const std::string PMTT0s_t
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
static const std::string Error_t
std::vector< JModuleRotation_t > JModuleRotation
Module rotation.
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.
string outputFile
static const std::string BaseStatusInfo_t
std::vector< JCompassRotation_t > JCompassRotation
Compass rotation.
static const std::string TCAL
PMT time offsets.
static const std::string Comment_t
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
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 DOMPositions_t
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
static const std::string RCAL
optical module orientations
static const std::string DOMCompassRotations_t
static const std::string Message_t
#define FATAL(A)
Definition: JMessage.hh:67
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
std::vector< JModuleStatus_t > JModuleStatus
Module status.
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
static const std::string Data_t
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
static const std::string SCAL
(module|PMT) status
nlohmann::json json
std::vector< JPMTStatus_t > JPMTStatus
PMT status.
static const std::string BasePositions_t
static const std::string DOMRotations_t
static const char FILENAME_WILD_CARD
wild card character for file name substitution
Definition: JeepToolkit.hh:44
static const std::string BaseCompassRotations_t
std::vector< JModulePosition_t > JModulePosition
Module position.
do set_variable DETECTOR_TXT $WORKDIR detector
static const std::string PMTStatusInfo_t
static const std::string PCAL
(optical|base) module positions
static const std::string DetID_t
static const std::string DOMAcousticT0_t
std::vector< JPMTCalibration_t > JPMTCalibration
PMT time calibration.
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 BaseAcousticT0_t
std::vector< JModuleCalibration_t > JModuleCalibration
Module time calibration.
static const std::string OK_t
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
Definition: JeepToolkit.hh:53