Jpp  15.0.1
the software that should make you happy
 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 "JMath/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 modules_t = "modules"; //!< modules
27  const char* const pmts_t = "pmts"; //!< PMTs
28  const char* const geometry_t = "geometry"; //!< geometry
29 
30  const char* const comment_t = "comment"; //!< comment
31  const char* const header_t = "header"; //!< header
32  const char* const identifier_t = "identifier"; //!< identifier
33  const char* const version_t = "version"; //!< version
34  const char* const can_t = "can"; //!< can
35  const char* const center_t = "center"; //!< center
36  const char* const summary_t = "summary"; //!< summary
37 
38  const char* const HEADER_t = "HEADER"; //!< header in zsh format
39  const char* const IDENTIFIER_t = "IDENTIFIER"; //!< identifier in zsh format
40  const char* const VERSION_t = "VERSION"; //!< version in zsh format
41  const char* const CAN_t = "CAN"; //!< can in zsh format
42  const char* const CENTER_t = "CENTER"; //!< center in zsh format
43  const char* const SUMMARY_t = "SUMMARY"; //!< summary in zsh format
44 }
45 
46 
47 /**
48  * \file
49  *
50  * Auxiliary program to print detector file in human friendly format.
51  * \author mdejong
52  */
53 int main(int argc, char **argv)
54 {
55  using namespace std;
56 
57  string detectorFile;
58  string option;
59  int debug;
60 
61  try {
62 
63  JParser<> zap("Auxiliary program to print detector file in human friendly format.");
64 
65  zap['a'] = make_field(detectorFile);
66  zap['O'] = make_field(option) =
67 
68  default_t,
69 
70  pmts_t,
71  modules_t,
72  geometry_t,
73 
74  comment_t,
75  header_t,
76  version_t,
77  identifier_t,
78  can_t,
79  center_t,
80  summary_t,
81 
82  HEADER_t,
83  VERSION_t,
84  IDENTIFIER_t,
85  CAN_t,
86  CENTER_t,
87  SUMMARY_t;
88 
89  zap['d'] = make_field(debug) = 1;
90 
91  zap(argc, argv);
92  }
93  catch(const exception &error) {
94  FATAL(error.what() << endl);
95  }
96 
97  using namespace JPP;
98 
100 
101  try {
102  load(detectorFile, detector);
103  }
104  catch(const JException& error) {
105  FATAL(error);
106  }
107 
108 
109  if (option == default_t) {
110 
111  cout << detector << endl;
112 
113  } else if (option == modules_t) {
114 
115  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
116 
117  cout << "Module";
118  cout << ' ' << noshowpos << setw(8) << right << module->getID();
119  cout << ' ' << noshowpos << setw(3) << right << module->getString();
120  cout << ' ' << noshowpos << setw(2) << right << module->getFloor();
121  cout << ' ' << FIXED(7,2) << module->getX();
122  cout << ' ' << FIXED(7,2) << module->getY();
123  cout << ' ' << FIXED(7,2) << module->getZ();
124  cout << ' ' << FIXED(8,2) << module->getT0();
125  cout << endl;
126  }
127 
128  } else if (option == pmts_t) {
129 
130  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
131  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
132 
133  cout << "PMT";
134  cout << ' ' << noshowpos << setw(8) << right << pmt->getID();
135  cout << ' ' << FIXED(7,2) << pmt->getX();
136  cout << ' ' << FIXED(7,2) << pmt->getY();
137  cout << ' ' << FIXED(7,2) << pmt->getZ();
138  cout << ' ' << FIXED(6,3) << pmt->getDX();
139  cout << ' ' << FIXED(6,3) << pmt->getDY();
140  cout << ' ' << FIXED(6,3) << pmt->getDZ();
141  cout << ' ' << FIXED(8,2) << pmt->getT0();
142  cout << ' ' << noshowpos << setw(8) << right << pmt->getStatus();
143  cout << endl;
144  }
145  }
146 
147  } else if (option == geometry_t) {
148 
149  cout << "Maximal distance [m] = " << FIXED(6,1) << getMaximalDistance(detector) << endl;
150  cout << "Maximal time [ns] = " << FIXED(6,1) << getMaximalTime (detector) << endl;
151 
152  } else if (option == comment_t) {
153 
154  cout << detector.comment << endl;
155 
156  } else if (option == header_t ||
157  option == HEADER_t) {
158 
159  if (option == header_t) {
160 
161  cout << detector.getProperties() << endl;
162  cout << "name = " << (isARCADetector(detector) ? "ARCA" :
163  isORCADetector(detector) ? "ORCA" :
164  "unknown") << endl;
165 
166  } else {
167 
168  cout << "set_variable UTM_EAST " << FIXED(12,2) << detector.getUTMEast() << ";" << endl;
169  cout << "set_variable UTM_NORTH " << FIXED(12,2) << detector.getUTMNorth() << ";" << endl;
170  cout << "set_variable UTM_Z " << FIXED(12,2) << detector.getUTMZ() << ";" << endl;
171  cout << "set_variable UTM_ZONE " << FIXED(12,2) << detector.getUTMZone() << ";" << endl;
172  cout << "set_variable UTM_WGS " << FIXED(12,2) << detector.getWGS() << ";" << endl;
173  }
174 
175  } else if (option == version_t ||
176  option == VERSION_t) {
177 
178  if (option == version_t) {
179 
180  cout << detector.getVersion() << endl;
181 
182  } else {
183 
184  cout << "set_variable DETECTOR_VERSION " << detector.getVersion() << ";" << endl;
185  }
186 
187  } else if (option == identifier_t ||
188  option == IDENTIFIER_t) {
189 
190  if (option == identifier_t) {
191 
192  cout << "Detector " << detector.getID() << endl;
193 
194  } else {
195 
196  cout << "set_variable DETECTOR_ID " << detector.getID() << ";" << endl;
197  }
198 
199  } else if (option == can_t ||
200  option == CAN_t) {
201 
202  const JCylinder3D cylinder(detector.begin(), detector.end());
203 
204  const double V = (cylinder.getZmax() - cylinder.getZmin()) * PI * cylinder.getRadius() * cylinder.getRadius();
205 
206  if (option == can_t) {
207 
208  cout << "X = " << FIXED(7,1) << cylinder.getX() << endl;
209  cout << "Y = " << FIXED(7,1) << cylinder.getY() << endl;
210  cout << "Zmin = " << FIXED(7,1) << cylinder.getZmin() << endl;
211  cout << "Zmax = " << FIXED(7,1) << cylinder.getZmax() << endl;
212  cout << "Radius = " << FIXED(7,1) << cylinder.getRadius() << endl;
213  cout << "Depth = " << FIXED(7,1) << detector.getUTMZ() << endl;
214  cout << "Volume = " << SCIENTIFIC(12,3) << V << endl;
215 
216  } else {
217 
218  cout << "set_variable CAN_X_M " << FIXED(7,1) << cylinder.getX() << ";" << endl;
219  cout << "set_variable CAN_Y_M " << FIXED(7,1) << cylinder.getY() << ";" << endl;
220  cout << "set_variable CAN_ZMIN_M " << FIXED(7,1) << cylinder.getZmin() << ";" << endl;
221  cout << "set_variable CAN_ZMAX_M " << FIXED(7,1) << cylinder.getZmax() << ";" << endl;
222  cout << "set_variable CAN_RADIUS_M " << FIXED(7,1) << cylinder.getRadius() << ";" << endl;
223  cout << "set_variable CAN_DEPTH_M " << FIXED(7,1) << detector.getUTMZ() << ";" << endl;
224  cout << "set_variable CAN_VOLUME_M3" << SCIENTIFIC(12,3) << V << ";" << endl;
225  }
226 
227  } else if (option == center_t ||
228  option == CENTER_t) {
229 
230  const JCenter3D center(detector.begin(), detector.end());
231 
232  if (option == center_t) {
233 
234  cout << "center = ";
235  cout << showpos << FIXED(8,3) << center.getX() << ' ';
236  cout << showpos << FIXED(8,3) << center.getY() << ' ';
237  cout << showpos << FIXED(8,3) << center.getZ() << endl;
238 
239  } else {
240 
241  cout << "set_variable CENTER_X_M " << FIXED(7,1) << center.getX() << ";" << endl;
242  cout << "set_variable CENTER_Y_M " << FIXED(7,1) << center.getY() << ";" << endl;
243  cout << "set_variable CENTER_Z_M " << FIXED(7,1) << center.getZ() << ";" << endl;
244  }
245 
246  } else if (option == summary_t ||
247  option == SUMMARY_t) {
248 
249  const int numberOfStrings = getNumberOfStrings(detector);
250  const int numberOfFloors = getNumberOfFloors (detector);
251  const int numberOfModules = getNumberOfModules(detector);
252  const int numberOfPMTs = getNumberOfPMTs (detector);
253 
254  typedef JTOOLS::JRange<int> JRange_t;
255 
256  const JRange_t string(make_array(detector.begin(), detector.end(), &JModule::getString));
257  const JRange_t floor (make_array(detector.begin(), detector.end(), &JModule::getFloor));
258 
260 
261  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
262  strings.insert(module->getString());
263  }
264 
265  if (option == summary_t) {
266 
267  cout << "Number of strings = " << setw(4) << numberOfStrings << endl;
268  cout << "Number of floors = " << setw(4) << numberOfFloors << endl;
269  cout << "Number of modules = " << setw(4) << numberOfModules << endl;
270  cout << "Number of PMTs = " << setw(4) << numberOfPMTs << endl;
271  cout << "First string = " << setw(4) << string.first << endl;
272  cout << "Last string = " << setw(4) << string.second << endl;
273  cout << "First floor = " << setw(4) << floor .first << endl;
274  cout << "Last floor = " << setw(4) << floor .second << endl;
275 
276  } else {
277 
278  cout << "set_variable NUMBER_OF_STRINGS " << setw(4) << numberOfStrings << ";" << endl;
279  cout << "set_variable NUMBER_OF_FLOORS " << setw(4) << numberOfFloors << ";" << endl;
280  cout << "set_variable NUMBER_OF_MODULES " << setw(4) << numberOfModules << ";" << endl;
281  cout << "set_variable NUMBER_OF_PMTS " << setw(4) << numberOfPMTs << ";" << endl;
282  cout << "set_variable FIRST_STRING " << setw(4) << string.first << ";" << endl;
283  cout << "set_variable LAST_STRING " << setw(4) << string.second << ";" << endl;
284  cout << "set_variable FIRST_FLOOR " << setw(4) << floor .first << ";" << endl;
285  cout << "set_variable LAST_FLOOR " << setw(4) << floor .second << ";" << endl;
286  cout << "set_array STRINGS ";
287  copy(strings.begin(), strings.end(), ostream_iterator<int>(cout, " "));
288  cout << endl;
289  }
290  }
291 }
bool isORCADetector(const JDetectorHeader &header)
Check if given detector header is compatible with that of ORCA.
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
bool isARCADetector(const JDetectorHeader &header)
Check if given detector header is compatible with tat of ARCA.
Detector data structure.
Definition: JDetector.hh:89
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
static const JModuleCounter getNumberOfModules
Function object to count unique modules.
Data structure for detector geometry and calibration.
double getMaximalDistance(const JDetector &detector)
Get maximal distance between modules in detector.
I/O formatting auxiliaries.
Cylinder object.
Definition: JCylinder3D.hh:39
Detector file.
Definition: JHead.hh:196
Mathematical constants.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
then usage $script< detector specific acoustics-fit script >< option > nAuxiliary script to make scan of pre stretching of detector strings(see JEditDetector)." "\nPossible options
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
static const double PI
Mathematical constants.
int debug
debug level
Definition: JSirene.cc:63
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
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
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:139
do set_variable DETECTOR_TXT $WORKDIR detector
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484