Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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 "JMath/JConstants.hh"
#include "JTools/JRange.hh"
#include "JGeometry3D/JGeometry3DToolkit.hh"
#include "JGeometry3D/JCylinder3D.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

int main ( int  argc,
char **  argv 
)

Definition at line 53 of file JPrintDetector.cc.

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 
253  typedef JTOOLS::JRange<int> JRange_t;
254 
255  const JRange_t string(make_array(detector.begin(), detector.end(), &JModule::getString));
256  const JRange_t floor (make_array(detector.begin(), detector.end(), &JModule::getFloor));
257 
258  set<int> strings;
259 
260  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
261  strings.insert(module->getString());
262  }
263 
264  if (option == summary_t) {
265 
266  cout << "Number of strings = " << setw(4) << numberOfStrings << endl;
267  cout << "Number of floors = " << setw(4) << numberOfFloors << endl;
268  cout << "Number of modules = " << setw(4) << numberOfModules << endl;
269  cout << "First string = " << setw(4) << string.first << endl;
270  cout << "Last string = " << setw(4) << string.second << endl;
271  cout << "First floor = " << setw(4) << floor .first << endl;
272  cout << "Last floor = " << setw(4) << floor .second << endl;
273 
274  } else {
275 
276  cout << "set_variable NUMBER_OF_STRINGS " << setw(4) << numberOfStrings << ";" << endl;
277  cout << "set_variable NUMBER_OF_FLOORS " << setw(4) << numberOfFloors << ";" << endl;
278  cout << "set_variable NUMBER_OF_MODULES " << setw(4) << numberOfModules << ";" << endl;
279  cout << "set_variable FIRST_STRING " << setw(4) << string.first << ";" << endl;
280  cout << "set_variable LAST_STRING " << setw(4) << string.second << ";" << endl;
281  cout << "set_variable FIRST_FLOOR " << setw(4) << floor .first << ";" << endl;
282  cout << "set_variable LAST_FLOOR " << setw(4) << floor .second << ";" << endl;
283  cout << "set_array STRINGS ";
284  copy(strings.begin(), strings.end(), ostream_iterator<int>(cout, " "));
285  cout << endl;
286  }
287  }
288 }
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
bool isARCADetector(const JDetectorHeader &header)
Check if given detector header is compatible with tat of ARCA.
Detector data structure.
Definition: JDetector.hh:80
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
static const JModuleCounter getNumberOfModules
Function object to count unique modules.
double getMaximalDistance(const JDetector &detector)
Get maximal distance between modules in detector.
Cylinder object.
Definition: JCylinder3D.hh:39
Detector file.
Definition: JHead.hh:196
#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
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.
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.
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