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