Jpp
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 
7 #include "JDetector/JDetector.hh"
9 
10 #include "JTools/JConstants.hh"
11 #include "JTools/JRange.hh"
14 
15 #include "Jeep/JPrint.hh"
16 #include "Jeep/JParser.hh"
17 #include "Jeep/JMessage.hh"
18 
19 
20 namespace {
21  /**
22  * Print options.
23  */
24  const char* const default_t = "default"; //!< as-is
25 
26  const char* const header_t = "header"; //!< header only
27  const char* const modules_t = "modules"; //!< modules
28  const char* const pmts_t = "pmts"; //!< PMTs
29 
30  const char* const identifier_t = "identifier"; //!< identifier
31  const char* const version_t = "version"; //!< version
32  const char* const can_t = "can"; //!< can
33  const char* const center_t = "center"; //!< center
34  const char* const summary_t = "summary"; //!< summary
35 
36  const char* const IDENTIFIER_t = "IDENTIFIER"; //!< identifier in zsh format
37  const char* const VERSION_t = "VERSION"; //!< version in zsh format
38  const char* const CAN_t = "CAN"; //!< can in zsh format
39  const char* const CENTER_t = "CENTER"; //!< center in zsh format
40  const char* const SUMMARY_t = "SUMMARY"; //!< summary in zsh format
41 }
42 
43 
44 /**
45  * \file
46  *
47  * Auxiliary program to print detector file in human friendly format.
48  * \author mdejong
49  */
50 int main(int argc, char **argv)
51 {
52  using namespace std;
53 
54  string detectorFile;
55  string option;
56  int debug;
57 
58  try {
59 
60  JParser<> zap("Auxiliary program to print detector file in human friendly format.");
61 
62  zap['a'] = make_field(detectorFile);
63  zap['O'] = make_field(option) =
64  default_t,
65  header_t,
66  pmts_t,
67  modules_t,
68  version_t,
69  identifier_t,
70  can_t,
71  center_t,
72  summary_t,
73  VERSION_t,
74  IDENTIFIER_t,
75  CAN_t,
76  CENTER_t,
77  SUMMARY_t;
78  zap['d'] = make_field(debug) = 1;
79 
80  zap(argc, argv);
81  }
82  catch(const exception &error) {
83  FATAL(error.what() << endl);
84  }
85 
86  using namespace JPP;
87 
89 
90  try {
91  load(detectorFile, detector);
92  }
93  catch(const JException& error) {
94  FATAL(error);
95  }
96 
97 
98  if (option == default_t) {
99 
100  cout << detector << endl;
101 
102  } else if (option == header_t) {
103 
104  cout << detector.getProperties() << endl;
105 
106  } else if (option == modules_t) {
107 
108  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
109 
110  double t0 = 0.0;
111 
112  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
113  t0 += pmt->getT0();
114  }
115 
116  t0 /= module->size();
117 
118  cout << "Module";
119  cout << ' ' << noshowpos << setw(8) << right << module->getID();
120  cout << ' ' << noshowpos << setw(3) << right << module->getString();
121  cout << ' ' << noshowpos << setw(2) << right << module->getFloor();
122  cout << ' ' << FIXED(7,2) << module->getX();
123  cout << ' ' << FIXED(7,2) << module->getY();
124  cout << ' ' << FIXED(7,2) << module->getZ();
125  cout << ' ' << FIXED(8,2) << t0;
126  cout << endl;
127  }
128 
129  } else if (option == pmts_t) {
130 
131  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
132  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
133 
134  cout << "PMT";
135  cout << ' ' << noshowpos << setw(8) << right << pmt->getID();
136  cout << ' ' << FIXED(7,2) << pmt->getX();
137  cout << ' ' << FIXED(7,2) << pmt->getY();
138  cout << ' ' << FIXED(7,2) << pmt->getZ();
139  cout << ' ' << FIXED(6,3) << pmt->getDX();
140  cout << ' ' << FIXED(6,3) << pmt->getDY();
141  cout << ' ' << FIXED(6,3) << pmt->getDZ();
142  cout << ' ' << FIXED(8,2) << pmt->getT0();
143  cout << ' ' << noshowpos << setw(8) << right << pmt->getStatus();
144  cout << endl;
145  }
146  }
147 
148  } else if (option == version_t ||
149  option == VERSION_t) {
150 
151  if (option == version_t) {
152 
153  cout << detector.getVersion() << endl;
154 
155  } else {
156 
157  cout << "set_variable DETECTOR_VERSION " << detector.getVersion() << ";" << endl;
158  }
159 
160  } else if (option == identifier_t ||
161  option == IDENTIFIER_t) {
162 
163  if (option == identifier_t) {
164 
165  cout << "Detector " << detector.getID() << endl;
166 
167  } else {
168 
169  cout << "set_variable DETECTOR_ID " << detector.getID() << ";" << endl;
170  }
171 
172  } else if (option == can_t ||
173  option == CAN_t) {
174 
175  const JCylinder3D cylinder(detector.begin(), detector.end());
176 
177  const double V = (cylinder.getZmax() - cylinder.getZmin()) * PI * cylinder.getRadius() * cylinder.getRadius();
178 
179  if (option == can_t) {
180 
181  cout << "X = " << FIXED(7,1) << cylinder.getX() << endl;
182  cout << "Y = " << FIXED(7,1) << cylinder.getY() << endl;
183  cout << "Zmin = " << FIXED(7,1) << cylinder.getZmin() << endl;
184  cout << "Zmax = " << FIXED(7,1) << cylinder.getZmax() << endl;
185  cout << "Radius = " << FIXED(7,1) << cylinder.getRadius() << endl;
186  cout << "Depth = " << FIXED(7,1) << detector.getUTMZ() << endl;
187  cout << "Volume = " << SCIENTIFIC(12,3) << V << endl;
188 
189  } else {
190 
191  cout << "set_variable CAN_X_M " << FIXED(7,1) << cylinder.getX() << ";" << endl;
192  cout << "set_variable CAN_Y_M " << FIXED(7,1) << cylinder.getY() << ";" << endl;
193  cout << "set_variable CAN_ZMIN_M " << FIXED(7,1) << cylinder.getZmin() << ";" << endl;
194  cout << "set_variable CAN_ZMAX_M " << FIXED(7,1) << cylinder.getZmax() << ";" << endl;
195  cout << "set_variable CAN_RADIUS_M " << FIXED(7,1) << cylinder.getRadius() << ";" << endl;
196  cout << "set_variable CAN_DEPTH_M " << FIXED(7,1) << detector.getUTMZ() << ";" << endl;
197  cout << "set_variable CAN_VOLUME_M3" << SCIENTIFIC(12,3) << V << ";" << endl;
198  }
199 
200  } else if (option == center_t || option == CENTER_t) {
201 
202  const JCenter3D center(detector.begin(), detector.end());
203 
204  if (option == center_t) {
205 
206  cout << "center = ";
207  cout << showpos << FIXED(8,3) << center.getX() << ' ';
208  cout << showpos << FIXED(8,3) << center.getY() << ' ';
209  cout << showpos << FIXED(8,3) << center.getZ() << endl;
210 
211  } else {
212 
213  cout << "set_variable CENTER_X_M " << FIXED(7,1) << center.getX() << ";" << endl;
214  cout << "set_variable CENTER_Y_M " << FIXED(7,1) << center.getY() << ";" << endl;
215  cout << "set_variable CENTER_Z_M " << FIXED(7,1) << center.getZ() << ";" << endl;
216  }
217 
218  } else if (option == summary_t ||
219  option == SUMMARY_t) {
220 
221  const int numberOfStrings = getNumberOfStrings(detector);
222  const int numberOfFloors = getNumberOfFloors (detector);
223  const int numberOfModules = getNumberOfModules(detector);
224 
225  typedef JTOOLS::JRange<int> JRange_t;
226 
227  const JRange_t string(detector.begin(), detector.end(), &JModule::getString);
228  const JRange_t floor (detector.begin(), detector.end(), &JModule::getFloor);
229 
230  set<int> strings;
231 
232  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
233  strings.insert(module->getString());
234  }
235 
236  if (option == summary_t) {
237 
238  cout << "Number of strings = " << setw(4) << numberOfStrings << endl;
239  cout << "Number of floors = " << setw(4) << numberOfFloors << endl;
240  cout << "Number of modules = " << setw(4) << numberOfModules << endl;
241  cout << "First string = " << setw(4) << string.first << endl;
242  cout << "Last string = " << setw(4) << string.second << endl;
243  cout << "First floor = " << setw(4) << floor .first << endl;
244  cout << "Last floor = " << setw(4) << floor .second << endl;
245 
246  } else {
247 
248  cout << "set_variable NUMBER_OF_STRINGS " << setw(4) << numberOfStrings << ";" << endl;
249  cout << "set_variable NUMBER_OF_FLOORS " << setw(4) << numberOfFloors << ";" << endl;
250  cout << "set_variable NUMBER_OF_MODULES " << setw(4) << numberOfModules << ";" << endl;
251  cout << "set_variable FIRST_STRING " << setw(4) << string.first << ";" << endl;
252  cout << "set_variable LAST_STRING " << setw(4) << string.second << ";" << endl;
253  cout << "set_variable FIRST_FLOOR " << setw(4) << floor .first << ";" << endl;
254  cout << "set_variable LAST_FLOOR " << setw(4) << floor .second << ";" << endl;
255  cout << "set_array STRINGS ";
256  copy(strings.begin(), strings.end(), ostream_iterator<int>(cout, " "));
257  cout << endl;
258  }
259  }
260 }
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
JGEOMETRY3D::JCenter3D
Center.
Definition: JGeometry3DToolkit.hh:29
JMessage.hh
JPrint.hh
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:476
JTOOLS::JRange< int >
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JDETECTOR::getNumberOfStrings
int getNumberOfStrings(const JDetector &detector)
Get number of strings.
Definition: JDetectorToolkit.hh:398
JAANET::copy
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:152
JDETECTOR::getNumberOfFloors
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
Definition: JDetectorToolkit.hh:434
std::set< int >
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JGEOMETRY3D::JCylinder3D
Cylinder object.
Definition: JCylinder3D.hh:37
JRange.hh
debug
int debug
debug level
Definition: JSirene.cc:59
JDETECTOR::getNumberOfModules
int getNumberOfModules(const JDetector &detector)
Get number of modules.
Definition: JDetectorToolkit.hh:452
JConstants.hh
main
int main(int argc, char **argv)
Definition: JPrintDetector.cc:50
SCIENTIFIC
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:518
JParser.hh
JDetectorToolkit.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JAANET::detector
Detector file.
Definition: JHead.hh:130
std
Definition: jaanetDictionary.h:36
JCylinder3D.hh
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
JDetector.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
JLANG::JException
General exception.
Definition: JException.hh:23
JGeometry3DToolkit.hh