Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDetector.cc
Go to the documentation of this file.
1 
2 #include <stdlib.h>
3 #include <string>
4 #include <iostream>
5 #include <sstream>
6 #include <fstream>
7 #include <deque>
8 
9 #include "JDetector/JDetector.hh"
13 #include "JDetector/JAnchor.hh"
15 #include "JSupport/JMeta.hh"
16 
17 #include "Jeep/JeepToolkit.hh"
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 namespace {
22 
23  static const char* const ARCA_t = "ARCA"; // KM3NeT/ARCA detector
24  static const char* const ORCA_t = "ORCA"; // KM3NeT/ORCA detector
25  static const char* const Antares_t = "Antares"; // Antares detector
26 }
27 
28 
29 /**
30  * \file
31  *
32  * Auxiliary program to generate detector files.
33  *
34  * The footprint of the detector can be provided through an input file (option -f).
35  *
36  * When no input file for the footprint is specified,
37  * the footprint is according the so-called WPD reference detector which is subsequently scaled
38  * according the specified line distance (JDETECTOR::JDetectorParameters::lineDistance_m).\n
39  * The specified number of lines (JDETECTOR::JDetectorParameters::numberOfLines) is then selected from
40  * this footprint according the specified detector type (JDETECTOR::JDetectorParameters::detectorType).\n
41  * The list of options includes:
42  * 1. remove outer positions (massive);
43  * 2. remove inner positions (hollow);
44  * \author mdejong
45  */
46 int main(int argc, char **argv)
47 {
48  using namespace std;
49  using namespace JPP;
50 
51  string inputFile;
52  string outputFile;
53  int detectorID;
54  string variant;
56  double Zmin_m;
57  string option;
58  int debug;
59 
60  // default values
61 
62  parameters.detectorType = 1; //
63  parameters.floorDistance_m = 0.0; // [m]
64  parameters.numberOfFloors = 18; //
65  parameters.lineDistance_m = 0.0; // [m]
66  parameters.numberOfLines = 0; //
67 
68  try {
69 
70  JParser<> zap("Auxiliary program to generate detector files.");
71 
73 
74  zap['f'] = make_field(inputFile, "anchor positions") = "";
75  zap['o'] = make_field(outputFile, "detector file");
76  zap['D'] = make_field(detectorID, "detector identifier");
77  zap['V'] = make_field(variant, "detector version") = getDetectorVersions<string>();
78  zap['@'] = make_field(helper, "detector parameters") = JPARSER::initialised();
79  zap['z'] = make_field(Zmin_m, "distance from seabed [m]") = 100.;
80  zap['O'] = make_field(option, "detector type") = ARCA_t, ORCA_t, Antares_t;
81  zap['d'] = make_field(debug) = 0;
82 
83  zap(argc, argv);
84  }
85  catch(const exception &error) {
86  FATAL(error.what() << endl);
87  }
88 
89 
90  JDetectorHeader header;
91 
92  if (option == ARCA_t)
93  header = getARCADetectorHeader();
94  else if (option == ORCA_t)
95  header = getORCADetectorHeader();
96  else if (option == Antares_t)
97  ;
98  else
99  FATAL("Invalid option " << option << endl);
100 
101 
102  JDetector detector(detectorID, variant, header);
103 
104  if (!hasDetectorAddressMap(detector.getID())) {
105  FATAL("No detector address map for detector identifier " << detector.getID() << endl);
106  }
107 
108  detector.comment.add(JMeta(argc,argv));
109 
110  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
111 
112 
113  deque<JAnchor> footprint;
114 
115  if (inputFile != "") {
116 
117  const string file_name = getFullFilename(LD_LIBRARY_PATH, inputFile);
118 
119  NOTICE("Reading file " << file_name << ".. " << flush);
120 
121  ifstream in(file_name.c_str());
122 
123  if (in) {
124 
125  for (JAnchor anchor; in >> anchor && footprint.size() < parameters.numberOfLines; ) {
126  footprint.push_back(anchor);
127  }
128 
129  in.close();
130 
131  NOTICE("OK" << endl);
132 
133  } else {
134 
135  FATAL("Error opening file " << inputFile);
136  }
137 
138  } else {
139 
140  // WPD footprint
141 
142  footprint.push_back(JAnchor( 1, 6, -7));
143  footprint.push_back(JAnchor( 2, 188, 9));
144  footprint.push_back(JAnchor( 3, 131, 153));
145  footprint.push_back(JAnchor( 4, -85, 120));
146  footprint.push_back(JAnchor( 5, -175, 39));
147  footprint.push_back(JAnchor( 6, -64, -181));
148  footprint.push_back(JAnchor( 7, 90, -178));
149  footprint.push_back(JAnchor( 8, 368, 20));
150  footprint.push_back(JAnchor( 9, 251, 159));
151  footprint.push_back(JAnchor( 10, 264, -146));
152  footprint.push_back(JAnchor( 11, 189, 293));
153  footprint.push_back(JAnchor( 12, 12, 309));
154  footprint.push_back(JAnchor( 13, -176, 338));
155  footprint.push_back(JAnchor( 14, -266, 149));
156  footprint.push_back(JAnchor( 15, -336, -1));
157  footprint.push_back(JAnchor( 16, -248, -174));
158  footprint.push_back(JAnchor( 17, -196, -348));
159  footprint.push_back(JAnchor( 18, -18, -350));
160  footprint.push_back(JAnchor( 19, 211, -339));
161  footprint.push_back(JAnchor( 20, 541, -12));
162  footprint.push_back(JAnchor( 21, 442, 183));
163  footprint.push_back(JAnchor( 22, 422, -125));
164  footprint.push_back(JAnchor( 23, 364, 287));
165  footprint.push_back(JAnchor( 24, 342, -323));
166  footprint.push_back(JAnchor( 25, 297, 499));
167  footprint.push_back(JAnchor( 26, 51, 452));
168  footprint.push_back(JAnchor( 27, -78, 488));
169  footprint.push_back(JAnchor( 28, -281, 508));
170  footprint.push_back(JAnchor( 29, -325, 304));
171  footprint.push_back(JAnchor( 30, -455, 128));
172  footprint.push_back(JAnchor( 31, -541, 15));
173  footprint.push_back(JAnchor( 32, -429, -142));
174  footprint.push_back(JAnchor( 33, -327, -316));
175  footprint.push_back(JAnchor( 34, -255, -488));
176  footprint.push_back(JAnchor( 35, -103, -508));
177  footprint.push_back(JAnchor( 36, 74, -469));
178  footprint.push_back(JAnchor( 37, 289, -452));
179  footprint.push_back(JAnchor( 38, 715, 0));
180  footprint.push_back(JAnchor( 39, 653, 154));
181  footprint.push_back(JAnchor( 40, 614, -141));
182  footprint.push_back(JAnchor( 41, 530, 269));
183  footprint.push_back(JAnchor( 42, 512, -323));
184  footprint.push_back(JAnchor( 43, 473, 472));
185  footprint.push_back(JAnchor( 44, 458, -473));
186  footprint.push_back(JAnchor( 45, 395, 632));
187  footprint.push_back(JAnchor( 46, 205, 630));
188  footprint.push_back(JAnchor( 47, 1, 667));
189  footprint.push_back(JAnchor( 48, -160, 644));
190  footprint.push_back(JAnchor( 49, -352, 639));
191  footprint.push_back(JAnchor( 50, -413, 460));
192  footprint.push_back(JAnchor( 51, -564, 286));
193  footprint.push_back(JAnchor( 52, -636, 125));
194  footprint.push_back(JAnchor( 53, -717, 23));
195  footprint.push_back(JAnchor( 54, -605, -139));
196  footprint.push_back(JAnchor( 55, -518, -279));
197  footprint.push_back(JAnchor( 56, -482, -448));
198  footprint.push_back(JAnchor( 57, -379, -595));
199  footprint.push_back(JAnchor( 58, -211, -619));
200  footprint.push_back(JAnchor( 59, 8, -652));
201  footprint.push_back(JAnchor( 60, 214, -619));
202  footprint.push_back(JAnchor( 61, 395, -617));
203  footprint.push_back(JAnchor( 62, 886, -12));
204  footprint.push_back(JAnchor( 63, 802, 155));
205  footprint.push_back(JAnchor( 64, 844, -128));
206  footprint.push_back(JAnchor( 65, 697, 285));
207  footprint.push_back(JAnchor( 66, 731, -275));
208  footprint.push_back(JAnchor( 67, 621, 450));
209  footprint.push_back(JAnchor( 68, 600, -497));
210  footprint.push_back(JAnchor( 69, 568, 593));
211  footprint.push_back(JAnchor( 70, 517, -586));
212  footprint.push_back(JAnchor( 71, 430, 776));
213  footprint.push_back(JAnchor( 72, 240, 758));
214  footprint.push_back(JAnchor( 73, 70, 783));
215  footprint.push_back(JAnchor( 74, -75, 803));
216  footprint.push_back(JAnchor( 75, -252, 809));
217  footprint.push_back(JAnchor( 76, -478, 771));
218  footprint.push_back(JAnchor( 77, -510, 590));
219  footprint.push_back(JAnchor( 78, -643, 468));
220  footprint.push_back(JAnchor( 79, -741, 284));
221  footprint.push_back(JAnchor( 80, -845, 175));
222  footprint.push_back(JAnchor( 81, -907, -6));
223  footprint.push_back(JAnchor( 82, -792, -142));
224  footprint.push_back(JAnchor( 83, -737, -340));
225  footprint.push_back(JAnchor( 84, -639, -492));
226  footprint.push_back(JAnchor( 85, -518, -596));
227  footprint.push_back(JAnchor( 86, -455, -751));
228  footprint.push_back(JAnchor( 87, -260, -814));
229  footprint.push_back(JAnchor( 88, -103, -819));
230  footprint.push_back(JAnchor( 89, 106, -764));
231  footprint.push_back(JAnchor( 90, 274, -754));
232  footprint.push_back(JAnchor( 91, 417, -762));
233  footprint.push_back(JAnchor( 92, 1094, -4));
234  footprint.push_back(JAnchor( 93, 1010, 120));
235  footprint.push_back(JAnchor( 94, 992, -171));
236  footprint.push_back(JAnchor( 95, 898, 324));
237  footprint.push_back(JAnchor( 96, 901, -298));
238  footprint.push_back(JAnchor( 97, 768, 471));
239  footprint.push_back(JAnchor( 98, 818, -477));
240  footprint.push_back(JAnchor( 99, 731, 632));
241  footprint.push_back(JAnchor(100, 713, -633));
242  footprint.push_back(JAnchor(101, 625, 772));
243  footprint.push_back(JAnchor(102, 661, -759));
244  footprint.push_back(JAnchor(103, 530, 949));
245  footprint.push_back(JAnchor(104, 345, 960));
246  footprint.push_back(JAnchor(105, 221, 931));
247  footprint.push_back(JAnchor(106, -29, 962));
248  footprint.push_back(JAnchor(107, -155, 967));
249  footprint.push_back(JAnchor(108, -382, 917));
250  footprint.push_back(JAnchor(109, -545, 965));
251  footprint.push_back(JAnchor(110, -634, 779));
252  footprint.push_back(JAnchor(111, -731, 600));
253  footprint.push_back(JAnchor(112, -852, 471));
254  footprint.push_back(JAnchor(113, -903, 322));
255  footprint.push_back(JAnchor(114, -976, 166));
256  footprint.push_back(JAnchor(115, -1100, 11));
257  footprint.push_back(JAnchor(116, -1006, -131));
258  footprint.push_back(JAnchor(117, -867, -332));
259  footprint.push_back(JAnchor(118, -800, -504));
260  footprint.push_back(JAnchor(119, -706, -593));
261  footprint.push_back(JAnchor(120, -604, -800));
262  footprint.push_back(JAnchor(121, -503, -933));
263  footprint.push_back(JAnchor(122, -318, -927));
264  footprint.push_back(JAnchor(123, -177, -926));
265  footprint.push_back(JAnchor(124, -10, -894));
266  footprint.push_back(JAnchor(125, 155, -919));
267  footprint.push_back(JAnchor(126, 381, -967));
268  footprint.push_back(JAnchor(127, 531, -900));
269  footprint.push_back(JAnchor(128, 1091, 311));
270  footprint.push_back(JAnchor(129, 1061, -285));
271  footprint.push_back(JAnchor(130, 966, 481));
272  footprint.push_back(JAnchor(131, 958, -457));
273  footprint.push_back(JAnchor(132, 905, 658));
274  footprint.push_back(JAnchor(133, 863, -630));
275  footprint.push_back(JAnchor(134, 788, 742));
276  footprint.push_back(JAnchor(135, 686, 911));
277  footprint.push_back(JAnchor(136, 277, 1113));
278  footprint.push_back(JAnchor(137, 92, 1094));
279  footprint.push_back(JAnchor(138, -84, 1127));
280  footprint.push_back(JAnchor(139, -302, 1062));
281  footprint.push_back(JAnchor(140, -732, 892));
282  footprint.push_back(JAnchor(141, -793, 761));
283  footprint.push_back(JAnchor(142, -901, 661));
284  footprint.push_back(JAnchor(143, -1012, 456));
285  footprint.push_back(JAnchor(144, -1101, 280));
286  footprint.push_back(JAnchor(145, -1077, -326));
287  footprint.push_back(JAnchor(146, -973, -457));
288  footprint.push_back(JAnchor(147, -883, -602));
289  footprint.push_back(JAnchor(148, -822, -771));
290  footprint.push_back(JAnchor(149, -689, -910));
291  footprint.push_back(JAnchor(150, -457, -1066));
292  footprint.push_back(JAnchor(151, -268, -1067));
293  footprint.push_back(JAnchor(152, -58, -1080));
294  footprint.push_back(JAnchor(153, 72, -1100));
295  footprint.push_back(JAnchor(154, 280, -1081));
296 
297  // scale positions to specified distance
298 
299  for (deque<JAnchor>::iterator i = footprint.begin(); i != footprint.end(); ++i) {
300  i->mul(parameters.lineDistance_m * 0.5 / 90.0);
301  }
302 
303  if (parameters.numberOfLines > footprint.size()) {
304  FATAL("Available footprint inconsistent with specified number of lines "
305  << parameters.numberOfLines << " > " << footprint.size() << endl);
306  }
307 
308  // select specified number of lines
309 
310  sort(footprint.begin(), footprint.end());
311 
312  if (parameters.detectorType == 2) { // hollow detector
313  while (parameters.numberOfLines < footprint.size()) {
314  footprint.pop_front();
315  }
316  } else { // massive detector
317  while (parameters.numberOfLines < footprint.size()) {
318  footprint.pop_back();
319  }
320  }
321 
322  // reset object identifiers
323 
324  for (deque<JAnchor>::iterator i = footprint.begin(); i != footprint.end(); ++i) {
325  static_cast<JObjectID&>(*i) = JObjectID(distance(footprint.begin(),i) + 1);
326  }
327  }
328 
329 
330  for (deque<JAnchor>::iterator i = footprint.begin(); i != footprint.end(); ++i) {
331  DEBUG(i->getID() << ' ' << i->getX() << ' ' << i->getY() << endl);
332  }
333 
334 
335  // build detector
336 
337  int PMT = 1;
338 
339  for (deque<JAnchor>::const_iterator anchor = footprint.begin(); anchor != footprint.end(); ++anchor) {
340 
341  {
342  const JVector3D position(anchor->getX(),
343  anchor->getY(),
344  option == ARCA_t ? ARCA_TBARZ_M :
345  option == ORCA_t ? ORCA_TBARZ_M :
346  0.0);
347 
348  const JLocation location(anchor->getID(), 0);
349 
350  const int id = demo.getModuleID(location);
351 
352  JModule module(id, location);
353 
354  module.set(position);
355 
356  module.compile();
357 
358  detector.push_back(module);
359  }
360 
361  for (unsigned int floor = 1; floor <= parameters.numberOfFloors; ++floor) {
362 
363  const JVector3D position(anchor->getX(),
364  anchor->getY(),
365  Zmin_m + (floor - 1) * parameters.floorDistance_m);
366 
367  const JLocation location(anchor->getID(), floor);
368 
369  const int id = demo.getModuleID(location);
370 
371  JModule module;
372 
373  if (option == ARCA_t || option == ORCA_t)
374  module = getModule<JKM3NeT_t> (id, location);
375  else if (option == Antares_t)
376  module = getModule<JAntares_t>(id, location);
377  else
378  FATAL("Invalid option " << option << endl);
379 
380  module.add(position);
381 
382  for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt, ++PMT) {
383  pmt->setID(PMT++);
384  //pmt->setCalibration(JCalibration((R + position.getZ())/C));
385  }
386 
387  detector.push_back(module);
388  }
389  }
390 
391  // Store detector.
392 
393  try {
394  store(outputFile, detector);
395  }
396  catch(const JException& error) {
397  FATAL(error);
398  }
399 
400  return 0;
401 }
JDetectorHeader getORCADetectorHeader()
Get detector header for ORCA.
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1517
Auxiliary class for I/O of JDetectorParameters data structure.
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
Data structure for a composite optical module.
Definition: JModule.hh:68
static const double ARCA_TBARZ_M
ORCA T-bar position relative to seabed [m].
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
static const char *const LD_LIBRARY_PATH
Nick names of environment variables.
Definition: JeepToolkit.hh:34
static const JPBS_t PMT(3, 4, 2, 3)
PBS of photo-multiplier tube (PMT)
Detector data structure.
Definition: JDetector.hh:89
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Lookup table for PMT addresses in detector.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
Data structure for parameters for detector geometry.
string outputFile
Data structure for detector geometry and calibration.
Data structure for detector header.
static const double ORCA_TBARZ_M
ORCA T-bar position relative to seabed [m].
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
Detector support kit.
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
Auxiliary methods for handling file names, type names and environment.
int getID() const
Get identifier.
Definition: JObjectID.hh:50
void compile()
Compile module data.
Definition: JModule.hh:282
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
Auxiliary class for object identification.
Definition: JObjectID.hh:22
void setID(const int id)
Set identifier.
Definition: JObjectID.hh:72
JDetectorHeader getARCADetectorHeader()
Get detector header for ARCA.
JComment & add(const std::string &comment)
Add comment.
Definition: JComment.hh:100
Data structure for anchor position on sea bed.
Definition: JAnchor.hh:24
do set_variable DETECTOR_TXT $WORKDIR detector
std::string getFullFilename(const std::string &variable, const std::string &file_name)
Get full file name (see JEEP::getPath).
Definition: JeepToolkit.hh:253
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
JModule & set(const JVector3D &pos)
Set position.
Definition: JModule.hh:408
int debug
debug level
JModule & add(const JVector3D &pos)
Add position.
Definition: JModule.hh:420
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62