Jpp master_rocky-44-g75b7c4f75
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 HEADER_t = "HEADER"; //!< header in zsh format
44 const char* const IDENTIFIER_t = "IDENTIFIER"; //!< identifier in zsh format
45 const char* const VERSION_t = "VERSION"; //!< version in zsh format
46 const char* const CAN_t = "CAN"; //!< can in zsh format
47 const char* const CENTER_t = "CENTER"; //!< center in zsh format
48 const char* const SUMMARY_t = "SUMMARY"; //!< summary in zsh format
49}
50
51
52/**
53 * \file
54 *
55 * Auxiliary program to print detector file in human friendly format.
56 * \author mdejong
57 */
58int main(int argc, char **argv)
59{
60 using namespace std;
61 using namespace JPP;
62
63 string detectorFile;
64 string option;
65 double precision;
66 int debug;
67
68 try {
69
70 JParser<> zap("Auxiliary program to print detector file in human friendly format.");
71
72 zap['a'] = make_field(detectorFile);
73 zap['O'] = make_field(option) =
74
75 default_t,
76
77 pmts_t,
78 modules_t,
79 geometry_t,
80
81 comment_t,
82 header_t,
83 version_t,
84 identifier_t,
85 can_t,
86 center_t,
87 summary_t,
88
89 HEADER_t,
90 VERSION_t,
91 IDENTIFIER_t,
92 CAN_t,
93 CENTER_t,
94 SUMMARY_t;
95
96 zap['p'] = make_field(precision, "precision for match with reference module") = 1.0e-5;
97 zap['d'] = make_field(debug) = 1;
98
99 zap(argc, argv);
100 }
101 catch(const exception &error) {
102 FATAL(error.what() << endl);
103 }
104
105
107
108 try {
109 load(detectorFile, detector);
110 }
111 catch(const JException& error) {
112 FATAL(error);
113 }
114
115 if (option == default_t) {
116
117 cout << detector << endl;
118
119 } else if (option == modules_t) {
120
121 const JDetectorBuilder& demo = getDetectorBuilder(detector.getID());
122
123 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
124
125 cout << "Module";
126 cout << ' ' << noshowpos << setw(8) << right << module->getID();
127 cout << ' ' << noshowpos << setw(3) << right << module->getString();
128 cout << ' ' << noshowpos << setw(2) << right << module->getFloor();
129 cout << ' ' << FIXED(7,2) << module->getX();
130 cout << ' ' << FIXED(7,2) << module->getY();
131 cout << ' ' << FIXED(7,2) << module->getZ();
132 cout << ' ' << FIXED(8,2) << module->getT0();
133
134 if (module->getFloor() != 0) {
135 {
136 JModule buffer = demo.getModule(module->getID(), module->getLocation());
137
138 const JQuaternion3D Q = getRotation(buffer, *module);
139 const JQuaternion3D::decomposition q1(Q, JVector3Z_t);
140
141 const double phi = (JVector3Z_t.getDot(q1.twist) >= 0.0 ? +1.0 : -1.0) * q1.twist.getAngle();
142
143 cout << ' ' << FIXED(7,2) << phi;
144 }
145 {
146 const JQuaternion3D Q = module->getQuaternion();
147 const JQuaternion3D::decomposition q1(Q, JVector3Z_t);
148
149 const double phi = (JVector3Z_t.getDot(q1.twist) >= 0.0 ? +1.0 : -1.0) * q1.twist.getAngle();
150
151 cout << ' ' << FIXED(7,2) << phi;
152 }
153 {
154 JModule buffer = demo.getModule(module->getID(), module->getLocation());
155
156 const JRotation3D R = getRotation(buffer, *module);
157
158 buffer.rotate(R);
159
160 cout << ' ' << (JModule::compare(buffer, *module, precision) ? "==" : "!=")
161 << ' ' << (demo.get(module->getID()) == demo.getDefaultModuleAddressMap() ? "default" : "custom");
162 }
163 }
164
165 cout << endl;
166 }
167
168 } else if (option == pmts_t) {
169
170 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
171 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
172 cout << "PMT";
173 cout << ' ' << noshowpos << setw(8) << right << pmt->getID();
174 cout << ' ' << FIXED(7,2) << pmt->getX();
175 cout << ' ' << FIXED(7,2) << pmt->getY();
176 cout << ' ' << FIXED(7,2) << pmt->getZ();
177 cout << ' ' << FIXED(6,3) << pmt->getDX();
178 cout << ' ' << FIXED(6,3) << pmt->getDY();
179 cout << ' ' << FIXED(6,3) << pmt->getDZ();
180 cout << ' ' << FIXED(8,2) << pmt->getT0();
181 cout << ' ' << noshowpos << setw(8) << right << pmt->getStatus();
182 cout << endl;
183 }
184 }
185
186 } else if (option == geometry_t) {
187
188 cout << "Maximal distance [m] = " << FIXED(6,1) << getMaximalDistance(detector) << endl;
189 cout << "Maximal time [ns] = " << FIXED(6,1) << getMaximalTime (detector) << endl;
190
191 } else if (option == comment_t) {
192
193 cout << detector.comment << endl;
194
195 } else if (option == header_t ||
196 option == HEADER_t) {
197
198 if (option == header_t) {
199
200 cout << detector.getProperties() << endl;
201 cout << "name = " << (isARCADetector(detector) ? "ARCA" :
202 isORCADetector(detector) ? "ORCA" :
203 "unknown") << endl;
204 cout << "validity = "
205 << JDateAndTime(detector.getLowerLimit(), true).toString() << ' '
206 << JDateAndTime(detector.getUpperLimit(), true).toString() << endl;
207
208 } else {
209
210 cout << "set_variable UTM_EAST " << FIXED(12,2) << detector.getUTMEast() << ";" << endl;
211 cout << "set_variable UTM_NORTH " << FIXED(12,2) << detector.getUTMNorth() << ";" << endl;
212 cout << "set_variable UTM_Z " << FIXED(12,2) << detector.getUTMZ() << ";" << endl;
213 cout << "set_variable UTM_ZONE " << FIXED(12,2) << detector.getUTMZone() << ";" << endl;
214 cout << "set_variable UTM_WGS " << FIXED(12,2) << detector.getWGS() << ";" << endl;
215 }
216
217 } else if (option == version_t ||
218 option == VERSION_t) {
219
220 if (option == version_t) {
221
222 cout << detector.getVersion() << endl;
223
224 } else {
225
226 cout << "set_variable DETECTOR_VERSION " << detector.getVersion() << ";" << endl;
227 }
228
229 } else if (option == identifier_t ||
230 option == IDENTIFIER_t) {
231
232 if (option == identifier_t) {
233
234 cout << "Detector " << detector.getID() << endl;
235
236 } else {
237
238 cout << "set_variable DETECTOR_ID " << detector.getID() << ";" << endl;
239 }
240
241 } else if (option == can_t ||
242 option == CAN_t) {
243
244 const JCylinder3D cylinder(detector.begin(), detector.end());
245
246 const double V = (cylinder.getZmax() - cylinder.getZmin()) * PI * cylinder.getRadius() * cylinder.getRadius();
247 const double D = getMaximalDistance(detector);
248
249 if (option == can_t) {
250
251 cout << "X = " << FIXED(7,1) << cylinder.getX() << endl;
252 cout << "Y = " << FIXED(7,1) << cylinder.getY() << endl;
253 cout << "Zmin = " << FIXED(7,1) << cylinder.getZmin() << endl;
254 cout << "Zmax = " << FIXED(7,1) << cylinder.getZmax() << endl;
255 cout << "Radius = " << FIXED(7,1) << cylinder.getRadius() << endl;
256 cout << "Depth = " << FIXED(7,1) << detector.getUTMZ() << endl;
257 cout << "Volume = " << SCIENTIFIC(12,3) << V << endl;
258 cout << "Distance = " << FIXED(9,3) << D << endl;
259
260 } else {
261
262 cout << "set_variable CAN_X_M " << FIXED(7,1) << cylinder.getX() << ";" << endl;
263 cout << "set_variable CAN_Y_M " << FIXED(7,1) << cylinder.getY() << ";" << endl;
264 cout << "set_variable CAN_ZMIN_M " << FIXED(7,1) << cylinder.getZmin() << ";" << endl;
265 cout << "set_variable CAN_ZMAX_M " << FIXED(7,1) << cylinder.getZmax() << ";" << endl;
266 cout << "set_variable CAN_RADIUS_M " << FIXED(7,1) << cylinder.getRadius() << ";" << endl;
267 cout << "set_variable CAN_DEPTH_M " << FIXED(7,1) << detector.getUTMZ() << ";" << endl;
268 cout << "set_variable CAN_VOLUME_M3 " << SCIENTIFIC(12,3) << V << ";" << endl;
269 cout << "set_variable CAN_DISTANCE_M " << FIXED(9,3) << D << ";" << endl;
270 }
271
272 } else if (option == center_t ||
273 option == CENTER_t) {
274
275 const JCenter3D center(detector.begin(), detector.end());
276
277 if (option == center_t) {
278
279 cout << "center = ";
280 cout << showpos << FIXED(8,3) << center.getX() << ' ';
281 cout << showpos << FIXED(8,3) << center.getY() << ' ';
282 cout << showpos << FIXED(8,3) << center.getZ() << endl;
283
284 } else {
285
286 cout << "set_variable CENTER_X_M " << FIXED(7,1) << center.getX() << ";" << endl;
287 cout << "set_variable CENTER_Y_M " << FIXED(7,1) << center.getY() << ";" << endl;
288 cout << "set_variable CENTER_Z_M " << FIXED(7,1) << center.getZ() << ";" << endl;
289 }
290
291 } else if (option == summary_t ||
292 option == SUMMARY_t) {
293
294 const int numberOfStrings = getNumberOfStrings(detector);
295 const int numberOfFloors = getNumberOfFloors (detector);
296 const int numberOfModules = getNumberOfModules(detector);
297 const int numberOfPMTs = getNumberOfPMTs (detector);
298
299 typedef JTOOLS::JRange<int> JRange_t;
300
301 const JRange_t string(make_array(detector.begin(), detector.end(), &JModule::getString));
302 const JRange_t floor (make_array(detector.begin(), detector.end(), &JModule::getFloor));
303
304 set<int> strings;
305 set<int> modules;
306
307 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
308 strings.insert(module->getString());
309 modules.insert(module->getID());
310 }
311
312 if (option == summary_t) {
313
314 cout << "Number of strings = " << setw(4) << numberOfStrings << endl;
315 cout << "Number of floors = " << setw(4) << numberOfFloors << endl;
316 cout << "Number of modules = " << setw(4) << numberOfModules << endl;
317 cout << "Number of PMTs = " << setw(4) << numberOfPMTs << endl;
318 cout << "First string = " << setw(4) << string.first << endl;
319 cout << "Last string = " << setw(4) << string.second << endl;
320 cout << "First floor = " << setw(4) << floor .first << endl;
321 cout << "Last floor = " << setw(4) << floor .second << endl;
322
323 } else {
324
325 cout << "set_variable NUMBER_OF_STRINGS " << setw(4) << numberOfStrings << ";" << endl;
326 cout << "set_variable NUMBER_OF_FLOORS " << setw(4) << numberOfFloors << ";" << endl;
327 cout << "set_variable NUMBER_OF_MODULES " << setw(4) << numberOfModules << ";" << endl;
328 cout << "set_variable NUMBER_OF_PMTS " << setw(4) << numberOfPMTs << ";" << endl;
329 cout << "set_variable FIRST_STRING " << setw(4) << string.first << ";" << endl;
330 cout << "set_variable LAST_STRING " << setw(4) << string.second << ";" << endl;
331 cout << "set_variable FIRST_FLOOR " << setw(4) << floor .first << ";" << endl;
332 cout << "set_variable LAST_FLOOR " << setw(4) << floor .second << ";" << endl;
333 cout << "set_array STRINGS ";
334 copy(strings.begin(), strings.end(), ostream_iterator<int>(cout, " "));
335 cout << ";" << endl;
336 cout << "set_array MODULES ";
337 copy(modules.begin(), modules.end(), ostream_iterator<int>(cout, " "));
338 cout << ";" << endl;
339 }
340 }
341}
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:69
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.
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
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
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