Jpp 19.3.0
the software that should make you happy
Loading...
Searching...
No Matches
JPrintDetector.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <set>
5#include <iterator>
6
11#include "JDetector/JModule.hh"
12
13#include "JMath/JConstants.hh"
14#include "JTools/JRange.hh"
19
20#include "Jeep/JPrint.hh"
21#include "Jeep/JParser.hh"
22#include "Jeep/JMessage.hh"
23
24
25namespace {
26 /**
27 * Print options.
28 */
29 const char* const default_t = "default"; //!< as-is
30
31 const char* const modules_t = "modules"; //!< modules
32 const char* const pmts_t = "pmts"; //!< PMTs
33 const char* const geometry_t = "geometry"; //!< geometry
34
35 const char* const comment_t = "comment"; //!< comment
36 const char* const header_t = "header"; //!< header
37 const char* const identifier_t = "identifier"; //!< identifier
38 const char* const version_t = "version"; //!< version
39 const char* const can_t = "can"; //!< can
40 const char* const center_t = "center"; //!< center
41 const char* const summary_t = "summary"; //!< summary
42
43 const char* const GEOMETRY_t = "GEOMETRY"; //!< geometry in zsh format
44 const char* const HEADER_t = "HEADER"; //!< header in zsh format
45 const char* const IDENTIFIER_t = "IDENTIFIER"; //!< identifier in zsh format
46 const char* const VERSION_t = "VERSION"; //!< version in zsh format
47 const char* const CAN_t = "CAN"; //!< can in zsh format
48 const char* const CENTER_t = "CENTER"; //!< center in zsh format
49 const char* const SUMMARY_t = "SUMMARY"; //!< summary in zsh format
50
51 /**
52 * Get zsh array name for given string.
53 *
54 * \param id string number
55 * \return zsh array name
56 */
57 inline std::string getString(const int id)
58 {
59 return MAKE_STRING("STRING_" << FILL(4,'0') << id);
60 }
61}
62
63
64/**
65 * \file
66 *
67 * Auxiliary program to print detector file in human friendly format.
68 * \author mdejong
69 */
70int main(int argc, char **argv)
71{
72 using namespace std;
73 using namespace JPP;
74
75 string detectorFile;
76 string option;
77 double precision;
78 int debug;
79
80 try {
81
82 JParser<> zap("Auxiliary program to print detector file in human friendly format.");
83
84 zap['a'] = make_field(detectorFile);
85 zap['O'] = make_field(option) =
86
87 default_t,
88
89 pmts_t,
90 modules_t,
91 geometry_t,
92
93 comment_t,
94 header_t,
95 version_t,
96 identifier_t,
97 can_t,
98 center_t,
99 summary_t,
100
101 GEOMETRY_t,
102 HEADER_t,
103 VERSION_t,
104 IDENTIFIER_t,
105 CAN_t,
106 CENTER_t,
107 SUMMARY_t;
108
109 zap['p'] = make_field(precision, "precision for match with reference module") = 1.0e-5;
110 zap['d'] = make_field(debug) = 1;
111
112 zap(argc, argv);
113 }
114 catch(const exception &error) {
115 FATAL(error.what() << endl);
116 }
117
118
120
121 try {
122 load(detectorFile, detector);
123 }
124 catch(const JException& error) {
125 FATAL(error);
126 }
127
128 if (option == default_t) {
129
130 cout << detector << endl;
131
132 } else if (option == modules_t) {
133
134 const JDetectorBuilder& demo = getDetectorBuilder(detector.getID());
135
136 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
137
138 cout << "Module";
139 cout << ' ' << noshowpos << setw(8) << right << module->getID();
140 cout << ' ' << noshowpos << setw(3) << right << module->getString();
141 cout << ' ' << noshowpos << setw(2) << right << module->getFloor();
142 cout << ' ' << FIXED(7,2) << module->getX();
143 cout << ' ' << FIXED(7,2) << module->getY();
144 cout << ' ' << FIXED(7,2) << module->getZ();
145 cout << ' ' << FIXED(8,2) << module->getT0();
146
147 if (module->getFloor() != 0) {
148 {
149 JModule buffer = demo.getModule(module->getID(), module->getLocation());
150
151 const JQuaternion3D Q = getRotation(buffer, *module);
152 const JQuaternion3D::decomposition q1(Q, JVector3Z_t);
153
154 const double phi = (JVector3Z_t.getDot(q1.twist) >= 0.0 ? +1.0 : -1.0) * q1.twist.getAngle();
155
156 cout << ' ' << FIXED(7,2) << phi;
157 }
158 {
159 const JQuaternion3D Q = module->getQuaternion();
160 const JQuaternion3D::decomposition q1(Q, JVector3Z_t);
161
162 const double phi = (JVector3Z_t.getDot(q1.twist) >= 0.0 ? +1.0 : -1.0) * q1.twist.getAngle();
163
164 cout << ' ' << FIXED(7,2) << phi;
165 }
166 {
167 JModule buffer = demo.getModule(module->getID(), module->getLocation());
168
169 const JRotation3D R = getRotation(buffer, *module);
170
171 buffer.rotate(R);
172
173 cout << ' ' << (JModule::compare(buffer, *module, precision) ? "==" : "!=")
174 << ' ' << (demo.get(module->getID()) == demo.getDefaultModuleAddressMap() ? "default" : "custom");
175 }
176 }
177
178 cout << endl;
179 }
180
181 } else if (option == pmts_t) {
182
183 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
184 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
185 cout << "PMT";
186 cout << ' ' << noshowpos << setw(8) << right << pmt->getID();
187 cout << ' ' << FIXED(7,2) << pmt->getX();
188 cout << ' ' << FIXED(7,2) << pmt->getY();
189 cout << ' ' << FIXED(7,2) << pmt->getZ();
190 cout << ' ' << FIXED(6,3) << pmt->getDX();
191 cout << ' ' << FIXED(6,3) << pmt->getDY();
192 cout << ' ' << FIXED(6,3) << pmt->getDZ();
193 cout << ' ' << FIXED(8,2) << pmt->getT0();
194 cout << ' ' << noshowpos << setw(8) << right << pmt->getStatus();
195 cout << endl;
196 }
197 }
198
199 } else if (option == geometry_t ||
200 option == GEOMETRY_t) {
201
202 if (option == geometry_t) {
203
204 cout << "Maximal distance [m] = " << FIXED(6,1) << getMaximalDistance(detector) << endl;
205 cout << "Minimal distance [m] = " << FIXED(6,1) << getMinimalDistance(detector) << endl;
206 cout << "Maximal time [ns] = " << FIXED(6,1) << getMaximalTime (detector) << endl;
207
208 } else {
209
210 cout << "set_variable MAXIMAL_DISTANCE_M " << FIXED(6,1) << getMaximalDistance(detector) << ";" << endl;
211 cout << "set_variable MINIMAL_DISTANCE_M " << FIXED(6,1) << getMinimalDistance(detector) << ";" << endl;
212 }
213
214 } else if (option == comment_t) {
215
216 cout << detector.comment << endl;
217
218 } else if (option == header_t ||
219 option == HEADER_t) {
220
221 if (option == header_t) {
222
223 cout << detector.getProperties() << endl;
224 cout << "name = " << (isARCADetector(detector) ? "ARCA" :
225 isORCADetector(detector) ? "ORCA" :
226 "unknown") << endl;
227 cout << "validity = "
228 << JDateAndTime(detector.getLowerLimit(), true).toString() << ' '
229 << JDateAndTime(detector.getUpperLimit(), true).toString() << endl;
230
231 } else {
232
233 cout << "set_variable UTM_EAST " << FIXED(12,2) << detector.getUTMEast() << ";" << endl;
234 cout << "set_variable UTM_NORTH " << FIXED(12,2) << detector.getUTMNorth() << ";" << endl;
235 cout << "set_variable UTM_Z " << FIXED(12,2) << detector.getUTMZ() << ";" << endl;
236 cout << "set_variable UTM_ZONE " << FIXED(12,2) << detector.getUTMZone() << ";" << endl;
237 cout << "set_variable UTM_WGS " << FIXED(12,2) << detector.getWGS() << ";" << endl;
238 }
239
240 } else if (option == version_t ||
241 option == VERSION_t) {
242
243 if (option == version_t) {
244
245 cout << detector.getVersion() << endl;
246
247 } else {
248
249 cout << "set_variable DETECTOR_VERSION " << detector.getVersion() << ";" << endl;
250 }
251
252 } else if (option == identifier_t ||
253 option == IDENTIFIER_t) {
254
255 if (option == identifier_t) {
256
257 cout << "Detector " << detector.getID() << endl;
258
259 } else {
260
261 cout << "set_variable DETECTOR_ID " << detector.getID() << ";" << endl;
262 }
263
264 } else if (option == can_t ||
265 option == CAN_t) {
266
267 const JCylinder3D cylinder(detector.begin(), detector.end());
268
269 const double V = (cylinder.getZmax() - cylinder.getZmin()) * PI * cylinder.getRadius() * cylinder.getRadius();
270 const double D = getMaximalDistance(detector);
271
272 if (option == can_t) {
273
274 cout << "X = " << FIXED(7,1) << cylinder.getX() << endl;
275 cout << "Y = " << FIXED(7,1) << cylinder.getY() << endl;
276 cout << "Zmin = " << FIXED(7,1) << cylinder.getZmin() << endl;
277 cout << "Zmax = " << FIXED(7,1) << cylinder.getZmax() << endl;
278 cout << "Radius = " << FIXED(7,1) << cylinder.getRadius() << endl;
279 cout << "Depth = " << FIXED(7,1) << detector.getUTMZ() << endl;
280 cout << "Volume = " << SCIENTIFIC(12,3) << V << endl;
281 cout << "Distance = " << FIXED(9,3) << D << endl;
282
283 } else {
284
285 cout << "set_variable CAN_X_M " << FIXED(7,1) << cylinder.getX() << ";" << endl;
286 cout << "set_variable CAN_Y_M " << FIXED(7,1) << cylinder.getY() << ";" << endl;
287 cout << "set_variable CAN_ZMIN_M " << FIXED(7,1) << cylinder.getZmin() << ";" << endl;
288 cout << "set_variable CAN_ZMAX_M " << FIXED(7,1) << cylinder.getZmax() << ";" << endl;
289 cout << "set_variable CAN_RADIUS_M " << FIXED(7,1) << cylinder.getRadius() << ";" << endl;
290 cout << "set_variable CAN_DEPTH_M " << FIXED(7,1) << detector.getUTMZ() << ";" << endl;
291 cout << "set_variable CAN_VOLUME_M3 " << SCIENTIFIC(12,3) << V << ";" << endl;
292 cout << "set_variable CAN_DISTANCE_M " << FIXED(9,3) << D << ";" << endl;
293 }
294
295 } else if (option == center_t ||
296 option == CENTER_t) {
297
298 const JCenter3D center(detector.begin(), detector.end());
299
300 if (option == center_t) {
301
302 cout << "center = ";
303 cout << showpos << FIXED(8,3) << center.getX() << ' ';
304 cout << showpos << FIXED(8,3) << center.getY() << ' ';
305 cout << showpos << FIXED(8,3) << center.getZ() << endl;
306
307 } else {
308
309 cout << "set_variable CENTER_X_M " << FIXED(7,1) << center.getX() << ";" << endl;
310 cout << "set_variable CENTER_Y_M " << FIXED(7,1) << center.getY() << ";" << endl;
311 cout << "set_variable CENTER_Z_M " << FIXED(7,1) << center.getZ() << ";" << endl;
312 }
313
314 } else if (option == summary_t ||
315 option == SUMMARY_t) {
316
317 const int numberOfStrings = getNumberOfStrings(detector);
318 const int numberOfFloors = getNumberOfFloors (detector);
319 const int numberOfModules = getNumberOfModules(detector);
320 const int numberOfPMTs = getNumberOfPMTs (detector);
321
322 typedef JTOOLS::JRange<int> JRange_t;
323
324 const JRange_t string_t(make_array(detector.begin(), detector.end(), &JModule::getString));
325 const JRange_t floor_t (make_array(detector.begin(), detector.end(), &JModule::getFloor));
326
327 set<int> strings;
328 set<int> modules;
329
330 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
331 strings.insert(module->getString());
332 modules.insert(module->getID());
333 }
334
335 if (option == summary_t) {
336
337 cout << "Number of strings = " << setw(4) << numberOfStrings << endl;
338 cout << "Number of floors = " << setw(4) << numberOfFloors << endl;
339 cout << "Number of modules = " << setw(4) << numberOfModules << endl;
340 cout << "Number of PMTs = " << setw(4) << numberOfPMTs << endl;
341 cout << "First string = " << setw(4) << string_t.first << endl;
342 cout << "Last string = " << setw(4) << string_t.second << endl;
343 cout << "First floor = " << setw(4) << floor_t .first << endl;
344 cout << "Last floor = " << setw(4) << floor_t .second << endl;
345
346 } else {
347
348 cout << "let \"NUMBER_OF_STRINGS = " << setw(5) << numberOfStrings << "\";" << endl;
349 cout << "let \"NUMBER_OF_FLOORS = " << setw(5) << numberOfFloors << "\";" << endl;
350 cout << "let \"NUMBER_OF_MODULES = " << setw(5) << numberOfModules << "\";" << endl;
351 cout << "let \"NUMBER_OF_PMTS = " << setw(5) << numberOfPMTs << "\";" << endl;
352 cout << "let \"FIRST_STRING = " << setw(5) << string_t.first << "\";" << endl;
353 cout << "let \"LAST_STRING = " << setw(5) << string_t.second << "\";" << endl;
354 cout << "let \"FIRST_FLOOR = " << setw(5) << floor_t .first << "\";" << endl;
355 cout << "let \"LAST_FLOOR = " << setw(5) << floor_t .second << "\";" << endl;
356 cout << "STRINGS=(";
357 copy(strings.begin(), strings.end(), ostream_iterator<int>(cout, " "));
358 cout << ");" << endl;
359 cout << "MODULES=(";
360 copy(modules.begin(), modules.end(), ostream_iterator<int>(cout, " "));
361 cout << ");" << endl;
362
363 // detector map
364
365 for (const auto i : strings) {
366 cout << "typeset -A " << getString(i) << ";" << endl;
367 }
368 for (const auto& i : detector) {
369 cout << getString(i.getString()) << "[" << i.getFloor() << "]=" << i.getID() << ";" << endl;
370 }
371 }
372 }
373}
Date and time functions.
Detector support kit.
Data structure for detector geometry and calibration.
Mathematical constants.
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Data structure for optical module.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
I/O formatting auxiliaries.
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
Auxiliary class to define a range between two values.
const JModuleAddressMap & get(const int id) const
Get module address map.
virtual const JModuleAddressMap & getDefaultModuleAddressMap() const =0
Get default module address map.
Detector data structure.
Definition JDetector.hh:96
Data structure for a composite optical module.
Definition JModule.hh:75
void rotate(const JRotation3D &R)
Rotate module.
Definition JModule.hh:314
double getRadius() const
Get radius.
Definition JCircle2D.hh:144
double getY() const
Get y position.
Definition JVector2D.hh:74
double getX() const
Get x position.
Definition JVector2D.hh:63
double getZmin() const
Get minimal z position.
double getZmax() const
Get maximal z position.
Data structure for unit quaternion in three dimensions.
double getAngle() const
Get rotation angle.
double getY() const
Get y position.
Definition JVector3D.hh:104
double getZ() const
Get z position.
Definition JVector3D.hh:115
double getX() const
Get x position.
Definition JVector3D.hh:94
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
Range of values.
Definition JRange.hh:42
JMODEL::JString getString(const JFit &fit)
Get model parameters of string.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for sequence of same character.
Definition JManip.hh:330
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Auxiliary interface for building detector.
const JModule & getModule(const int id=-1, const JLocation &location=JLocation()) const
Get module.
Auxiliary data structure for decomposition of quaternion in twist and swing quaternions.
JQuaternion3D twist
rotation around parallel axis
Auxiliary class for date and time.
std::string toString() const
Get ASCII formatted date and time.
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488