Jpp
JNTupleToDetector.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
6 #include "JDetector/JDetector.hh"
11 #include "JIO/JFileStreamIO.hh"
12 
13 #include "Jeep/JParser.hh"
14 #include "Jeep/JMessage.hh"
15 #include "Jeep/JTimer.hh"
16 
17 
18 /**
19  * \file
20  *
21  * Program to convert ntuples to detector.
22  * \author mdejong
23  */
24 int main(int argc, char **argv)
25 {
26  using namespace std;
27 
28  string detectorFile;
29  string ntupleFile;
30  string outputFile;
31  int debug;
32 
33  try {
34 
35  JParser<> zap("Program to convert ntuples to detector.");
36 
37  zap['a'] = make_field(detectorFile);
38  zap['f'] = make_field(ntupleFile);
39  zap['o'] = make_field(outputFile) = "";
40  zap['d'] = make_field(debug) = 0;
41 
42  zap(argc, argv);
43  }
44  catch(const exception &error) {
45  FATAL(error.what() << endl);
46  }
47 
48 
49  using namespace JPP;
50 
51 
52  JDetector detector;
53 
54  try {
55  load(detectorFile, detector);
56  }
57  catch(const JException& error) {
58  FATAL(error);
59  }
60 
61 
62  const JModuleRouter router(detector);
63  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
64 
65 
66  JTimer timer("module");
67 
68  JFileStreamReader in(ntupleFile.c_str());
69 
70  for (JModuleGeometry geometry; in.load(geometry); ) {
71 
72  DEBUG(geometry << endl);
73 
74  const int id = geometry.getID();
75 
76  if (router.hasModule(id)) {
77 
78  timer.start();
79 
80  const JEulerMatrix3D R(geometry.getEulerAngle());
81 
82  JModule master = getModule(demo.get(id), id);
83 
84  master.rotate(R);
85  master.add(geometry.getPosition());
86 
87  JModule& module = detector.getModule(router.getAddress(id));
88 
89  if (module.size() == master.size()) {
90 
91  for (int pmt = 0; pmt != (int) master.size(); ++pmt) {
92  module.getPMT(pmt).setAxis(master.getPMT(pmt).getAxis());
93  }
94 
95  module.compile();
96 
97  } else {
98 
99  ERROR("Module sizes inconsistent " << module.size() << " != " << master.size() << endl);
100  }
101 
102  timer.stop();
103 
104  } else {
105 
106  ERROR("Missing module " << geometry.getID() << endl);
107  }
108  }
109 
110  in.close();
111 
112  timer.print(cout);
113 
114  if (outputFile != "") {
115 
116  if (outputFile == "%") {
117  outputFile = detectorFile;
118  }
119 
120  try {
121  store(outputFile, detector);
122  }
123  catch(const JException& error) {
124  FATAL(error);
125  }
126  }
127 }
JMessage.hh
JFileStreamIO.hh
getModule
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
Definition: JBeaconSimulator.cc:927
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
main
int main(int argc, char **argv)
Definition: JNTupleToDetector.cc:24
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
ERROR
#define ERROR(A)
Definition: JMessage.hh:66
debug
int debug
debug level
Definition: JSirene.cc:59
JDetectorAddressMapToolkit.hh
JModuleRouter.hh
JParser.hh
JDetectorToolkit.hh
JDETECTOR::store
void store(const JString &file_name, const JDetector &detector)
Store detector to output file.
Definition: JDetectorToolkit.hh:532
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JModuleGeometry.hh
JTimer.hh
JDetector.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JDETECTOR::getDetectorAddressMap
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
Definition: JDetectorAddressMapToolkit.hh:363