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