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 
163  } else {
164 
165  cout << "set_variable UTM_EAST " << FIXED(12,2) << detector.getUTMEast() << ";" << endl;
166  cout << "set_variable UTM_NORTH " << FIXED(12,2) << detector.getUTMNorth() << ";" << endl;
167  cout << "set_variable UTM_Z " << FIXED(12,2) << detector.getUTMZ() << ";" << endl;
168  cout << "set_variable UTM_ZONE " << FIXED(12,2) << detector.getUTMZone() << ";" << endl;
169  cout << "set_variable UTM_WGS " << FIXED(12,2) << detector.getWGS() << ";" << endl;
170  }
171 
172  } else if (option == version_t ||
173  option == VERSION_t) {
174 
175  if (option == version_t) {
176 
177  cout << detector.getVersion() << endl;
178 
179  } else {
180 
181  cout << "set_variable DETECTOR_VERSION " << detector.getVersion() << ";" << endl;
182  }
183 
184  } else if (option == identifier_t ||
185  option == IDENTIFIER_t) {
186 
187  if (option == identifier_t) {
188 
189  cout << "Detector " << detector.getID() << endl;
190 
191  } else {
192 
193  cout << "set_variable DETECTOR_ID " << detector.getID() << ";" << endl;
194  }
195 
196  } else if (option == can_t ||
197  option == CAN_t) {
198 
199  const JCylinder3D cylinder(detector.begin(), detector.end());
200 
201  const double V = (cylinder.getZmax() - cylinder.getZmin()) * PI * cylinder.getRadius() * cylinder.getRadius();
202 
203  if (option == can_t) {
204 
205  cout << "X = " << FIXED(7,1) << cylinder.getX() << endl;
206  cout << "Y = " << FIXED(7,1) << cylinder.getY() << endl;
207  cout << "Zmin = " << FIXED(7,1) << cylinder.getZmin() << endl;
208  cout << "Zmax = " << FIXED(7,1) << cylinder.getZmax() << endl;
209  cout << "Radius = " << FIXED(7,1) << cylinder.getRadius() << endl;
210  cout << "Depth = " << FIXED(7,1) << detector.getUTMZ() << endl;
211  cout << "Volume = " << SCIENTIFIC(12,3) << V << endl;
212 
213  } else {
214 
215  cout << "set_variable CAN_X_M " << FIXED(7,1) << cylinder.getX() << ";" << endl;
216  cout << "set_variable CAN_Y_M " << FIXED(7,1) << cylinder.getY() << ";" << endl;
217  cout << "set_variable CAN_ZMIN_M " << FIXED(7,1) << cylinder.getZmin() << ";" << endl;
218  cout << "set_variable CAN_ZMAX_M " << FIXED(7,1) << cylinder.getZmax() << ";" << endl;
219  cout << "set_variable CAN_RADIUS_M " << FIXED(7,1) << cylinder.getRadius() << ";" << endl;
220  cout << "set_variable CAN_DEPTH_M " << FIXED(7,1) << detector.getUTMZ() << ";" << endl;
221  cout << "set_variable CAN_VOLUME_M3" << SCIENTIFIC(12,3) << V << ";" << endl;
222  }
223 
224  } else if (option == center_t ||
225  option == CENTER_t) {
226 
227  const JCenter3D center(detector.begin(), detector.end());
228 
229  if (option == center_t) {
230 
231  cout << "center = ";
232  cout << showpos << FIXED(8,3) << center.getX() << ' ';
233  cout << showpos << FIXED(8,3) << center.getY() << ' ';
234  cout << showpos << FIXED(8,3) << center.getZ() << endl;
235 
236  } else {
237 
238  cout << "set_variable CENTER_X_M " << FIXED(7,1) << center.getX() << ";" << endl;
239  cout << "set_variable CENTER_Y_M " << FIXED(7,1) << center.getY() << ";" << endl;
240  cout << "set_variable CENTER_Z_M " << FIXED(7,1) << center.getZ() << ";" << endl;
241  }
242 
243  } else if (option == summary_t ||
244  option == SUMMARY_t) {
245 
246  const int numberOfStrings = getNumberOfStrings(detector);
247  const int numberOfFloors = getNumberOfFloors (detector);
248  const int numberOfModules = getNumberOfModules(detector);
249 
250  typedef JTOOLS::JRange<int> JRange_t;
251 
252  const JRange_t string(make_array(detector.begin(), detector.end(), &JModule::getString));
253  const JRange_t floor (make_array(detector.begin(), detector.end(), &JModule::getFloor));
254 
255  set<int> strings;
256 
257  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
258  strings.insert(module->getString());
259  }
260 
261  if (option == summary_t) {
262 
263  cout << "Number of strings = " << setw(4) << numberOfStrings << endl;
264  cout << "Number of floors = " << setw(4) << numberOfFloors << endl;
265  cout << "Number of modules = " << setw(4) << numberOfModules << endl;
266  cout << "First string = " << setw(4) << string.first << endl;
267  cout << "Last string = " << setw(4) << string.second << endl;
268  cout << "First floor = " << setw(4) << floor .first << endl;
269  cout << "Last floor = " << setw(4) << floor .second << endl;
270 
271  } else {
272 
273  cout << "set_variable NUMBER_OF_STRINGS " << setw(4) << numberOfStrings << ";" << endl;
274  cout << "set_variable NUMBER_OF_FLOORS " << setw(4) << numberOfFloors << ";" << endl;
275  cout << "set_variable NUMBER_OF_MODULES " << setw(4) << numberOfModules << ";" << endl;
276  cout << "set_variable FIRST_STRING " << setw(4) << string.first << ";" << endl;
277  cout << "set_variable LAST_STRING " << setw(4) << string.second << ";" << endl;
278  cout << "set_variable FIRST_FLOOR " << setw(4) << floor .first << ";" << endl;
279  cout << "set_variable LAST_FLOOR " << setw(4) << floor .second << ";" << endl;
280  cout << "set_array STRINGS ";
281  copy(strings.begin(), strings.end(), ostream_iterator<int>(cout, " "));
282  cout << endl;
283  }
284  }
285 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
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:37
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