Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JMergeDetector.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4
10
11#include "JLang/JEquation_t.hh"
12
13#include "JSupport/JMeta.hh"
14
15#include "Jeep/JParser.hh"
16#include "Jeep/JMessage.hh"
17
18namespace {
19
20 using namespace JPP;
21
22 /**
23 * List of valid keys.
24 */
25 static const std::set<std::string> keys = { TCAL, PCAL, RCAL, ACAL, CCAL, SCAL };
26}
27
28
29/**
30 * \file
31 *
32 * Auxiliary program to merge detector files.
33 *
34 * \author mdejong
35 */
36int main(int argc, char **argv)
37{
38 using namespace std;
39 using namespace JPP;
40
41 vector<string> detectorFile;
43 string outputFile;
44 int debug;
45
46 try {
47
48 JParser<> zap("Auxiliary program to merge detector files.");
49
50 zap['a'] = make_field(detectorFile);
51 zap['o'] = make_field(outputFile);
52 zap['@'] = make_field(calset, "import calibration sets \"<key> = <file name>[; <key> = <file name>]\"" << endl
53 << "possible keys: " << JEEPZ() << keys) = JPARSER::initialised();
54 zap['d'] = make_field(debug) = 1;
55
56 zap(argc, argv);
57 }
58 catch(const exception &error) {
59 FATAL(error.what() << endl);
60 }
61
62
64
65 for (vector<JEquation_t>::const_iterator i = calset.begin(); i != calset.end(); ++i) {
66
67 if (keys.count(i->getKey()) == 0)
68 FATAL("Invalid calibration set \"" << i->getKey() << "\"" << endl);
69 else
70 calibration[i->getKey()] = trim(i->getValue());
71 }
72
73
75
76 for (vector<string>::const_iterator i = detectorFile.begin(); i != detectorFile.end(); ++i) {
77
78 JDetector buffer;
79
80 try {
81 load(*i, buffer);
82 }
83 catch(const JException& error) {
84 FATAL(error);
85 }
86
87 if (detector.empty())
88 detector = buffer;
89 else
90 copy(buffer.begin(), buffer.end(), back_inserter(detector));
91 }
92
93
94 if (calibration.count(TCAL)) {
95
96 JDetector buffer;
97
98 try {
99 load(calibration[TCAL], buffer);
100 }
101 catch(const JException& error) {
102 FATAL(error);
103 }
104
105 JPMTRouter router(detector);
106
107 for (const auto& module : buffer) {
108 for (const auto& pmt : module) {
109 if (router.hasPMT(pmt.getID()))
110 detector.getPMT(router.getAddress(pmt.getID())).setCalibration(pmt.getCalibration());
111 else
112 FATAL("Missing PMT " << pmt.getID() << endl);
113 }
114 }
115 }
116
117
118 if (calibration.count(PCAL)) {
119
120 JDetector buffer;
121
122 try {
123 load(calibration[PCAL], buffer);
124 }
125 catch(const JException& error) {
126 FATAL(error);
127 }
128
129 JModuleRouter router(detector);
130
131 for (const auto& module : buffer) {
132 if (router.hasModule(module.getID())) {
133
134 if (module.getFloor() != 0)
135 detector.getModule(router.getAddress(module.getID())).set(module.getCenter());
136 else
137 detector.getModule(router.getAddress(module.getID())).set(module.getPosition());
138
139 } else
140 FATAL("Missing module " << module.getID() << endl);
141 }
142 }
143
144
145 if (calibration.count(RCAL)) {
146
147 JDetector buffer;
148
149 try {
150 load(calibration[RCAL], buffer);
151 }
152 catch(const JException& error) {
153 FATAL(error);
154 }
155
156 JModuleRouter router(detector);
157
158 for (const auto& module : buffer) {
159 if (router.hasModule(module.getID())) {
160
161 if (module.getFloor() != 0) {
162
163 JModule& object = detector.getModule(router.getAddress(module.getID()));
164
165 const JRotation3D R = getRotation(object, module);
166 const JPosition3D center = object.getCenter();
167
168 object.sub(center);
169 object.rotate(R);
170 object.add(center);
171 }
172
173 } else
174 FATAL("Missing module " << module.getID() << endl);
175 }
176 }
177
178
179 if (calibration.count(ACAL)) {
180
181 JDetector buffer;
182
183 try {
184 load(calibration[ACAL], buffer);
185 }
186 catch(const JException& error) {
187 FATAL(error);
188 }
189
190 JModuleRouter router(detector);
191
192 for (const auto& module : buffer) {
193 if (router.hasModule(module.getID())) {
194
195 detector.getModule(router.getAddress(module.getID())).setT0(module.getT0());
196
197 } else
198 FATAL("Missing module " << module.getID() << endl);
199 }
200 }
201
202
203 if (calibration.count(CCAL)) {
204
205 JDetector buffer;
206
207 try {
208 load(calibration[CCAL], buffer);
209 }
210 catch(const JException& error) {
211 FATAL(error);
212 }
213
214 JModuleRouter router(detector);
215
216 for (const auto& module : buffer) {
217 if (router.hasModule(module.getID())) {
218
219 detector.getModule(router.getAddress(module.getID())).setQuaternion(module.getQuaternion());
220
221 } else
222 FATAL("Missing module " << module.getID() << endl);
223 }
224 }
225
226
227 if (calibration.count(SCAL)) {
228
229 JDetector buffer;
230
231 try {
232 load(calibration[SCAL], buffer);
233 }
234 catch(const JException& error) {
235 FATAL(error);
236 }
237 {
238 JModuleRouter router(detector);
239
240 for (const auto& module : buffer) {
241 if (router.hasModule(module.getID()))
242 detector.getModule(router.getAddress(module.getID())).setStatus(module.getStatus());
243 else
244 FATAL("Missing module " << module.getID() << endl);
245 }
246 }
247 {
248 JPMTRouter router(detector);
249
250 for (const auto& module : buffer) {
251 for (const auto& pmt : module) {
252 if (router.hasPMT(pmt.getID()))
253 detector.getPMT(router.getAddress(pmt.getID())).setStatus(pmt.getStatus());
254 else
255 FATAL("Missing PMT " << pmt.getID() << endl);
256 }
257 }
258 }
259 }
260
261
262 detector.comment.add(JMeta(argc,argv));
263
264 try {
266 }
267 catch(const JException& error) {
268 FATAL(error);
269 }
270}
string outputFile
Data structure for detector geometry and calibration.
int main(int argc, char **argv)
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
ROOT I/O of application specific meta data.
Direct access to module in detector data structure.
Direct access to PMT in detector data structure.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
bool hasModule(const JObjectID &id) const
Has module.
const JModuleAddress & getAddress(const JObjectID &id) const
Get address of module.
Data structure for a composite optical module.
Definition JModule.hh:75
Router for direct addressing of PMT data in detector data structure.
Definition JPMTRouter.hh:37
bool hasPMT(const JObjectID &id) const
Has PMT.
const JPMTAddress & getAddress(const JObjectID &id) const
Get address of PMT.
Definition JPMTRouter.hh:80
Data structure for position in three dimensions.
JVector3D & add(const JVector3D &vector)
Add vector.
Definition JVector3D.hh:142
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition JVector3D.hh:158
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
std::string trim(const std::string &buffer)
Trim string.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static const std::string TCAL
PMT time offsets.
static const std::string PCAL
(optical|base) module positions
static const std::string SCAL
(module|PMT) status
static const std::string RCAL
optical module orientations
static const std::string ACAL
acoustic time offsets (piezo sensor or hydrophone)
static const std::string CCAL
compass alignment (a.k.a. quaternion calibration)
Calibration.
Definition JHead.hh:330
Detector file.
Definition JHead.hh:227
Auxiliary data structure for streaming of STL containers.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72