Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  const char* const geometry_t = "geometry"; //!< geometry
36 
37  const char* const IDENTIFIER_t = "IDENTIFIER"; //!< identifier in zsh format
38  const char* const VERSION_t = "VERSION"; //!< version in zsh format
39  const char* const CAN_t = "CAN"; //!< can in zsh format
40  const char* const CENTER_t = "CENTER"; //!< center in zsh format
41  const char* const SUMMARY_t = "SUMMARY"; //!< summary in zsh format
42 }
43 
44 
45 /**
46  * \file
47  *
48  * Auxiliary program to print detector file in human friendly format.
49  * \author mdejong
50  */
51 int main(int argc, char **argv)
52 {
53  using namespace std;
54 
55  string detectorFile;
56  string option;
57  int debug;
58 
59  try {
60 
61  JParser<> zap("Auxiliary program to print detector file in human friendly format.");
62 
63  zap['a'] = make_field(detectorFile);
64  zap['O'] = make_field(option) =
65  default_t,
66  header_t,
67  pmts_t,
68  modules_t,
69  version_t,
70  identifier_t,
71  can_t,
72  center_t,
73  summary_t,
74  geometry_t,
75  VERSION_t,
76  IDENTIFIER_t,
77  CAN_t,
78  CENTER_t,
79  SUMMARY_t;
80  zap['d'] = make_field(debug) = 1;
81 
82  zap(argc, argv);
83  }
84  catch(const exception &error) {
85  FATAL(error.what() << endl);
86  }
87 
88  using namespace JPP;
89 
91 
92  try {
93  load(detectorFile, detector);
94  }
95  catch(const JException& error) {
96  FATAL(error);
97  }
98 
99 
100  if (option == default_t) {
101 
102  cout << detector << endl;
103 
104  } else if (option == header_t) {
105 
106  cout << detector.getProperties() << endl;
107 
108  } else if (option == modules_t) {
109 
110  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
111 
112  double t0 = 0.0;
113 
114  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
115  t0 += pmt->getT0();
116  }
117 
118  t0 /= module->size();
119 
120  cout << "Module";
121  cout << ' ' << noshowpos << setw(8) << right << module->getID();
122  cout << ' ' << noshowpos << setw(3) << right << module->getString();
123  cout << ' ' << noshowpos << setw(2) << right << module->getFloor();
124  cout << ' ' << FIXED(7,2) << module->getX();
125  cout << ' ' << FIXED(7,2) << module->getY();
126  cout << ' ' << FIXED(7,2) << module->getZ();
127  cout << ' ' << FIXED(8,2) << t0;
128  cout << endl;
129  }
130 
131  } else if (option == pmts_t) {
132 
133  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
134  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
135 
136  cout << "PMT";
137  cout << ' ' << noshowpos << setw(8) << right << pmt->getID();
138  cout << ' ' << FIXED(7,2) << pmt->getX();
139  cout << ' ' << FIXED(7,2) << pmt->getY();
140  cout << ' ' << FIXED(7,2) << pmt->getZ();
141  cout << ' ' << FIXED(6,3) << pmt->getDX();
142  cout << ' ' << FIXED(6,3) << pmt->getDY();
143  cout << ' ' << FIXED(6,3) << pmt->getDZ();
144  cout << ' ' << FIXED(8,2) << pmt->getT0();
145  cout << ' ' << noshowpos << setw(8) << right << pmt->getStatus();
146  cout << endl;
147  }
148  }
149 
150  } else if (option == version_t ||
151  option == VERSION_t) {
152 
153  if (option == version_t) {
154 
155  cout << detector.getVersion() << endl;
156 
157  } else {
158 
159  cout << "set_variable DETECTOR_VERSION " << detector.getVersion() << ";" << endl;
160  }
161 
162  } else if (option == identifier_t ||
163  option == IDENTIFIER_t) {
164 
165  if (option == identifier_t) {
166 
167  cout << "Detector " << detector.getID() << endl;
168 
169  } else {
170 
171  cout << "set_variable DETECTOR_ID " << detector.getID() << ";" << endl;
172  }
173 
174  } else if (option == can_t ||
175  option == CAN_t) {
176 
177  const JCylinder3D cylinder(detector.begin(), detector.end());
178 
179  const double V = (cylinder.getZmax() - cylinder.getZmin()) * PI * cylinder.getRadius() * cylinder.getRadius();
180 
181  if (option == can_t) {
182 
183  cout << "X = " << FIXED(7,1) << cylinder.getX() << endl;
184  cout << "Y = " << FIXED(7,1) << cylinder.getY() << endl;
185  cout << "Zmin = " << FIXED(7,1) << cylinder.getZmin() << endl;
186  cout << "Zmax = " << FIXED(7,1) << cylinder.getZmax() << endl;
187  cout << "Radius = " << FIXED(7,1) << cylinder.getRadius() << endl;
188  cout << "Depth = " << FIXED(7,1) << detector.getUTMZ() << endl;
189  cout << "Volume = " << SCIENTIFIC(12,3) << V << endl;
190 
191  } else {
192 
193  cout << "set_variable CAN_X_M " << FIXED(7,1) << cylinder.getX() << ";" << endl;
194  cout << "set_variable CAN_Y_M " << FIXED(7,1) << cylinder.getY() << ";" << endl;
195  cout << "set_variable CAN_ZMIN_M " << FIXED(7,1) << cylinder.getZmin() << ";" << endl;
196  cout << "set_variable CAN_ZMAX_M " << FIXED(7,1) << cylinder.getZmax() << ";" << endl;
197  cout << "set_variable CAN_RADIUS_M " << FIXED(7,1) << cylinder.getRadius() << ";" << endl;
198  cout << "set_variable CAN_DEPTH_M " << FIXED(7,1) << detector.getUTMZ() << ";" << endl;
199  cout << "set_variable CAN_VOLUME_M3" << SCIENTIFIC(12,3) << V << ";" << endl;
200  }
201 
202  } else if (option == center_t || option == CENTER_t) {
203 
204  const JCenter3D center(detector.begin(), detector.end());
205 
206  if (option == center_t) {
207 
208  cout << "center = ";
209  cout << showpos << FIXED(8,3) << center.getX() << ' ';
210  cout << showpos << FIXED(8,3) << center.getY() << ' ';
211  cout << showpos << FIXED(8,3) << center.getZ() << endl;
212 
213  } else {
214 
215  cout << "set_variable CENTER_X_M " << FIXED(7,1) << center.getX() << ";" << endl;
216  cout << "set_variable CENTER_Y_M " << FIXED(7,1) << center.getY() << ";" << endl;
217  cout << "set_variable CENTER_Z_M " << FIXED(7,1) << center.getZ() << ";" << endl;
218  }
219 
220  } else if (option == summary_t ||
221  option == SUMMARY_t) {
222 
223  const int numberOfStrings = getNumberOfStrings(detector);
224  const int numberOfFloors = getNumberOfFloors (detector);
225  const int numberOfModules = getNumberOfModules(detector);
226 
228 
229  const JRange_t string(detector.begin(), detector.end(), &JModule::getString);
230  const JRange_t floor (detector.begin(), detector.end(), &JModule::getFloor);
231 
232  set<int> strings;
233 
234  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
235  strings.insert(module->getString());
236  }
237 
238  if (option == summary_t) {
239 
240  cout << "Number of strings = " << setw(4) << numberOfStrings << endl;
241  cout << "Number of floors = " << setw(4) << numberOfFloors << endl;
242  cout << "Number of modules = " << setw(4) << numberOfModules << endl;
243  cout << "First string = " << setw(4) << string.first << endl;
244  cout << "Last string = " << setw(4) << string.second << endl;
245  cout << "First floor = " << setw(4) << floor .first << endl;
246  cout << "Last floor = " << setw(4) << floor .second << endl;
247 
248  } else {
249 
250  cout << "set_variable NUMBER_OF_STRINGS " << setw(4) << numberOfStrings << ";" << endl;
251  cout << "set_variable NUMBER_OF_FLOORS " << setw(4) << numberOfFloors << ";" << endl;
252  cout << "set_variable NUMBER_OF_MODULES " << setw(4) << numberOfModules << ";" << endl;
253  cout << "set_variable FIRST_STRING " << setw(4) << string.first << ";" << endl;
254  cout << "set_variable LAST_STRING " << setw(4) << string.second << ";" << endl;
255  cout << "set_variable FIRST_FLOOR " << setw(4) << floor .first << ";" << endl;
256  cout << "set_variable LAST_FLOOR " << setw(4) << floor .second << ";" << endl;
257  cout << "set_array STRINGS ";
258  copy(strings.begin(), strings.end(), ostream_iterator<int>(cout, " "));
259  cout << endl;
260  }
261 
262  } else if (option == geometry_t) {
263 
264  cout << "Maximal distance [m] = " << FIXED(6,1) << getMaximalDistance(detector) << endl;
265  cout << "Maximal time [ns] = " << FIXED(6,1) << getMaximalTime (detector) << endl;
266  }
267 }
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
Detector data structure.
Definition: JDetector.hh:80
static const double PI
Constants.
Definition: JConstants.hh:20
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
static const JModuleCounter getNumberOfModules
Function object to count unique modules.
Data structure for detector geometry and calibration.
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
Definition: JTransitTime.sh:36
Constants.
double getMaximalDistance(const JDetector &detector)
Get maximal distance between modules in detector.
I/O formatting auxiliaries.
Cylinder object.
Definition: JCylinder3D.hh:37
Detector file.
Definition: JHead.hh:130
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
int getID() const
Get identifier.
Definition: JObjectID.hh:55
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
double getMaximalTime(const double R_Hz)
Get maximal time for given rate.
General purpose messaging.
static const JStringCounter getNumberOfStrings
Function object to count unique strings.
#define FATAL(A)
Definition: JMessage.hh:67
JRange< Double_t > JRange_t
Definition: JFitToT.hh:34
Auxiliary class to define a range between two values.
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:153
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:518
int main(int argc, char *argv[])
Definition: Main.cpp:15