Jpp 20.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JPrintDetector.cc File Reference

Auxiliary program to print detector file in human friendly format. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <set>
#include <iterator>
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorAddressMap.hh"
#include "JDetector/JDetectorSupportkit.hh"
#include "JDetector/JModule.hh"
#include "JMath/JConstants.hh"
#include "JTools/JRange.hh"
#include "JSystem/JDateAndTime.hh"
#include "JGeometry3D/JGeometry3DToolkit.hh"
#include "JGeometry3D/JCylinder3D.hh"
#include "JGeometry3D/JQuaternion3D.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 print detector file in human friendly format.

Author
mdejong

Definition in file JPrintDetector.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 70 of file JPrintDetector.cc.

71{
72 using namespace std;
73 using namespace JPP;
74
75 string detectorFile;
76 set<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, "possible options "
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) = JPARSER::initialised();
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.count(default_t)) {
129
130 cout << detector << endl;
131
132 }
133
134 if (option.count(modules_t)) {
135
136 const JDetectorBuilder& demo = getDetectorBuilder(detector.getID());
137
138 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
139
140 cout << "Module";
141 cout << ' ' << noshowpos << setw(8) << right << module->getID();
142 cout << ' ' << noshowpos << setw(3) << right << module->getString();
143 cout << ' ' << noshowpos << setw(2) << right << module->getFloor();
144 cout << ' ' << FIXED(7,2) << module->getX();
145 cout << ' ' << FIXED(7,2) << module->getY();
146 cout << ' ' << FIXED(7,2) << module->getZ();
147 cout << ' ' << FIXED(8,2) << module->getT0();
148
149 if (module->getFloor() != 0) {
150 {
151 JModule buffer = demo.getModule(module->getID(), module->getLocation());
152
153 const JQuaternion3D Q = getRotation(buffer, *module);
154 const JQuaternion3D::decomposition q1(Q, JVector3Z_t);
155
156 const double phi = (JVector3Z_t.getDot(q1.twist) >= 0.0 ? +1.0 : -1.0) * q1.twist.getAngle();
157
158 cout << ' ' << FIXED(7,2) << phi;
159 }
160 {
161 const JQuaternion3D Q = module->getQuaternion();
162 const JQuaternion3D::decomposition q1(Q, JVector3Z_t);
163
164 const double phi = (JVector3Z_t.getDot(q1.twist) >= 0.0 ? +1.0 : -1.0) * q1.twist.getAngle();
165
166 cout << ' ' << FIXED(7,2) << phi;
167 }
168 {
169 JModule buffer = demo.getModule(module->getID(), module->getLocation());
170
171 const JRotation3D R = getRotation(buffer, *module);
172
173 buffer.rotate(R);
174
175 cout << ' ' << (JModule::compare(buffer, *module, precision) ? "==" : "!=")
176 << ' ' << (demo.get(module->getID()) == demo.getDefaultModuleAddressMap() ? "default" : "custom");
177 }
178 }
179
180 cout << endl;
181 }
182
183 }
184
185 if (option.count(pmts_t)) {
186
188
189 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
190
191 const JModuleAddressMap& memo = demo.get(module->getID());
192
193 for (size_t i = 0; i != module->size(); ++i) {
194
195 const JPMT& pmt = module->getPMT(i);
196 const JPMTPhysicalAddress& address = memo.getPMTPhysicalAddress(i);
197
198 cout << "PMT[" << FILL(2,'0') << i << FILL() << "]";
199 cout << ' ' << address;
200 cout << ' ' << noshowpos << setw(8) << right << pmt.getID();
201 cout << ' ' << FIXED(7,2) << pmt.getX();
202 cout << ' ' << FIXED(7,2) << pmt.getY();
203 cout << ' ' << FIXED(7,2) << pmt.getZ();
204 cout << ' ' << FIXED(6,3) << pmt.getDX();
205 cout << ' ' << FIXED(6,3) << pmt.getDY();
206 cout << ' ' << FIXED(6,3) << pmt.getDZ();
207 cout << ' ' << FIXED(8,2) << pmt.getT0();
208 cout << ' ' << noshowpos << setw(8) << right << pmt.getStatus();
209 cout << endl;
210 }
211 }
212
213 }
214
215 if (option.count(geometry_t) ||
216 option.count(GEOMETRY_t)) {
217
218 if (option.count(geometry_t)) {
219
220 cout << "Maximal distance [m] = " << FIXED(6,1) << getMaximalDistance(detector) << endl;
221 cout << "Minimal distance [m] = " << FIXED(6,1) << getMinimalDistance(detector) << endl;
222 cout << "Maximal time [ns] = " << FIXED(6,1) << getMaximalTime (detector) << endl;
223
224 } else {
225
226 cout << "set_variable MAXIMAL_DISTANCE_M " << FIXED(6,1) << getMaximalDistance(detector) << ";" << endl;
227 cout << "set_variable MINIMAL_DISTANCE_M " << FIXED(6,1) << getMinimalDistance(detector) << ";" << endl;
228 }
229
230 }
231
232 if (option.count(comment_t)) {
233
234 cout << detector.comment << endl;
235
236 }
237
238 if (option.count(header_t) ||
239 option.count(HEADER_t)) {
240
241 if (option.count(header_t)) {
242
243 cout << detector.getProperties() << endl;
244 cout << "name = " << (isARCADetector(detector) ? "ARCA" :
245 isORCADetector(detector) ? "ORCA" :
246 "unknown") << endl;
247 cout << "validity = "
248 << JDateAndTime(detector.getLowerLimit(), true).toString() << ' '
249 << JDateAndTime(detector.getUpperLimit(), true).toString() << endl;
250
251 } else {
252
253 cout << "set_variable UTM_EAST " << FIXED(12,2) << detector.getUTMEast() << ";" << endl;
254 cout << "set_variable UTM_NORTH " << FIXED(12,2) << detector.getUTMNorth() << ";" << endl;
255 cout << "set_variable UTM_Z " << FIXED(12,2) << detector.getUTMZ() << ";" << endl;
256 cout << "set_variable UTM_ZONE " << FIXED(12,2) << detector.getUTMZone() << ";" << endl;
257 cout << "set_variable UTM_WGS " << FIXED(12,2) << detector.getWGS() << ";" << endl;
258 }
259
260 }
261
262 if (option.count(version_t) ||
263 option.count(VERSION_t)) {
264
265 if (option.count(version_t)) {
266
267 cout << detector.getVersion() << endl;
268
269 } else {
270
271 cout << "set_variable DETECTOR_VERSION " << detector.getVersion() << ";" << endl;
272 }
273
274 }
275
276 if (option.count(identifier_t) ||
277 option.count(IDENTIFIER_t)) {
278
279 if (option.count(identifier_t)) {
280
281 cout << "Detector " << detector.getID() << endl;
282
283 } else {
284
285 cout << "set_variable DETECTOR_ID " << detector.getID() << ";" << endl;
286 }
287
288 }
289
290 if (option.count(can_t) ||
291 option.count(CAN_t)) {
292
293 const JCylinder3D cylinder(detector.begin(), detector.end());
294
295 const double V = (cylinder.getZmax() - cylinder.getZmin()) * PI * cylinder.getRadius() * cylinder.getRadius();
296 const double D = getMaximalDistance(detector);
297
298 if (option.count(can_t)) {
299
300 cout << "X = " << FIXED(7,1) << cylinder.getX() << endl;
301 cout << "Y = " << FIXED(7,1) << cylinder.getY() << endl;
302 cout << "Zmin = " << FIXED(7,1) << cylinder.getZmin() << endl;
303 cout << "Zmax = " << FIXED(7,1) << cylinder.getZmax() << endl;
304 cout << "Radius = " << FIXED(7,1) << cylinder.getRadius() << endl;
305 cout << "Depth = " << FIXED(7,1) << detector.getUTMZ() << endl;
306 cout << "Volume = " << SCIENTIFIC(12,3) << V << endl;
307 cout << "Distance = " << FIXED(9,3) << D << endl;
308
309 } else {
310
311 cout << "set_variable CAN_X_M " << FIXED(7,1) << cylinder.getX() << ";" << endl;
312 cout << "set_variable CAN_Y_M " << FIXED(7,1) << cylinder.getY() << ";" << endl;
313 cout << "set_variable CAN_ZMIN_M " << FIXED(7,1) << cylinder.getZmin() << ";" << endl;
314 cout << "set_variable CAN_ZMAX_M " << FIXED(7,1) << cylinder.getZmax() << ";" << endl;
315 cout << "set_variable CAN_RADIUS_M " << FIXED(7,1) << cylinder.getRadius() << ";" << endl;
316 cout << "set_variable CAN_DEPTH_M " << FIXED(7,1) << detector.getUTMZ() << ";" << endl;
317 cout << "set_variable CAN_VOLUME_M3 " << SCIENTIFIC(12,3) << V << ";" << endl;
318 cout << "set_variable CAN_DISTANCE_M " << FIXED(9,3) << D << ";" << endl;
319 }
320
321 }
322
323 if (option.count(center_t) ||
324 option.count(CENTER_t)) {
325
326 const JCenter3D center(detector.begin(), detector.end());
327
328 if (option.count(center_t)) {
329
330 cout << "center = ";
331 cout << showpos << FIXED(8,3) << center.getX() << ' ';
332 cout << showpos << FIXED(8,3) << center.getY() << ' ';
333 cout << showpos << FIXED(8,3) << center.getZ() << endl;
334
335 } else {
336
337 cout << "set_variable CENTER_X_M " << FIXED(7,1) << center.getX() << ";" << endl;
338 cout << "set_variable CENTER_Y_M " << FIXED(7,1) << center.getY() << ";" << endl;
339 cout << "set_variable CENTER_Z_M " << FIXED(7,1) << center.getZ() << ";" << endl;
340 }
341
342 }
343
344 if (option.count(summary_t) ||
345 option.count(SUMMARY_t)) {
346
347 const int numberOfStrings = getNumberOfStrings(detector);
348 const int numberOfFloors = getNumberOfFloors (detector);
349 const int numberOfModules = getNumberOfModules(detector);
350 const int numberOfPMTs = getNumberOfPMTs (detector);
351
352 typedef JTOOLS::JRange<int> JRange_t;
353
354 const JRange_t string_t(make_array(detector.begin(), detector.end(), &JModule::getString));
355 const JRange_t floor_t (make_array(detector.begin(), detector.end(), &JModule::getFloor));
356
357 set<int> strings;
358 set<int> modules;
359
360 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
361 strings.insert(module->getString());
362 modules.insert(module->getID());
363 }
364
365 if (option.count(summary_t)) {
366
367 cout << "Number of strings = " << setw(4) << numberOfStrings << endl;
368 cout << "Number of floors = " << setw(4) << numberOfFloors << endl;
369 cout << "Number of modules = " << setw(4) << numberOfModules << endl;
370 cout << "Number of PMTs = " << setw(4) << numberOfPMTs << endl;
371 cout << "First string = " << setw(4) << string_t.first << endl;
372 cout << "Last string = " << setw(4) << string_t.second << endl;
373 cout << "First floor = " << setw(4) << floor_t .first << endl;
374 cout << "Last floor = " << setw(4) << floor_t .second << endl;
375
376 } else {
377
378 cout << "let \"NUMBER_OF_STRINGS = " << setw(5) << numberOfStrings << "\";" << endl;
379 cout << "let \"NUMBER_OF_FLOORS = " << setw(5) << numberOfFloors << "\";" << endl;
380 cout << "let \"NUMBER_OF_MODULES = " << setw(5) << numberOfModules << "\";" << endl;
381 cout << "let \"NUMBER_OF_PMTS = " << setw(5) << numberOfPMTs << "\";" << endl;
382 cout << "let \"FIRST_STRING = " << setw(5) << string_t.first << "\";" << endl;
383 cout << "let \"LAST_STRING = " << setw(5) << string_t.second << "\";" << endl;
384 cout << "let \"FIRST_FLOOR = " << setw(5) << floor_t .first << "\";" << endl;
385 cout << "let \"LAST_FLOOR = " << setw(5) << floor_t .second << "\";" << endl;
386 cout << "STRINGS=(";
387 copy(strings.begin(), strings.end(), ostream_iterator<int>(cout, " "));
388 cout << ");" << endl;
389 cout << "MODULES=(";
390 copy(modules.begin(), modules.end(), ostream_iterator<int>(cout, " "));
391 cout << ");" << endl;
392
393 // detector map
394
395 for (const auto i : strings) {
396 cout << "typeset -A " << getString(i) << ";" << endl;
397 }
398 for (const auto& i : detector) {
399 cout << getString(i.getString()) << "[" << i.getFloor() << "]=" << i.getID() << ";" << endl;
400 }
401 }
402 }
403}
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
double getT0() const
Get time offset.
Lookup table for PMT addresses in detector.
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
Lookup table for PMT addresses in optical module.
const JPMTPhysicalAddress & getPMTPhysicalAddress(const int tdc) const
Get PMT physical address.
Data structure for a composite optical module.
Definition JModule.hh:76
void rotate(const JRotation3D &R)
Rotate module.
Definition JModule.hh:315
Data structure for PMT physical address.
Data structure for PMT geometry, calibration and status.
Definition JPMT.hh:49
Data structure for unit quaternion in three dimensions.
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
double getDY() const
Get y direction.
Definition JVersor3D.hh:106
double getDX() const
Get x direction.
Definition JVersor3D.hh:95
double getDZ() const
Get z direction.
Definition JVersor3D.hh:117
General exception.
Definition JException.hh:24
int getID() const
Get identifier.
Definition JObjectID.hh:50
Utility class to parse command line options.
Definition JParser.hh:1698
Range of values.
Definition JRange.hh:42
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
JMODEL::JString getString(const JFit &fit)
Get model parameters of string.
const char *const string_t
routing by string
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
JDetectorBuilder & getDetectorBuilder()
Get detector builder.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
bool isORCADetector(const JDetectorHeader &header)
Check if given detector header is compatible with that of ORCA.
bool isARCADetector(const JDetectorHeader &header)
Check if given detector header is compatible with tat of ARCA.
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
int getNumberOfModules(const JDetector &detector, const bool option=false)
Get number of modules.
double getMinimalDistance(const JDetector &detector)
Get minimal distance between modules in detector.
double getMaximalDistance(const JDetector &detector, const bool option=false)
Get maximal distance between modules in detector.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getMaximalTime(const double R_Hz)
Get maximal time for given rate.
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.
status_type getStatus(const JType< status_type > &type) const
Get status.
Definition JStatus.hh:60
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
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