Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JDestructDetector.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <fstream>
5
10
11#include "JSon/JSon.hh"
12
13#include "Jeep/JeepToolkit.hh"
14#include "Jeep/JPrint.hh"
15#include "Jeep/JParser.hh"
16#include "Jeep/JMessage.hh"
17
18
19/**
20 * \file
21 *
22 * Auxiliary program to decompose detector to separate calibrations.
23 * \author mdejong
24 */
25int main(int argc, char **argv)
26{
27 using namespace std;
28 using namespace JPP;
29
30 string detectorFile;
31 string outputFile;
32 double precision;
33 int debug;
34
35 try {
36
37 JParser<> zap("Auxiliary program to decompose detector to separate calibrations.");
38
39 zap['a'] = make_field(detectorFile, "detector file");
40 zap['o'] = make_field(outputFile, "detector calibrations file in JSON format "\
41 "(optionally contains wild card \'" << FILENAME_WILDCARD << "\')");
42 zap['p'] = make_field(precision, "precision for match with reference module") = 1.0e-5;
43 zap['d'] = make_field(debug) = 1;
44
45 zap(argc, argv);
46 }
47 catch(const exception &error) {
48 FATAL(error.what() << endl);
49 }
50
51
53
54 try {
55 load(detectorFile, detector);
56 }
57 catch(const JException& error) {
58 FATAL(error);
59 }
60
61 if (!hasDetectorAddressMap(detector.getID())) {
62 FATAL("No detector address map for detector identier " << detector.getID() << endl);
63 }
64
65 const JDetectorBuilder& demo = getDetectorBuilder(detector.getID());
66
67
68 // Test compatibility of modules with reference(s).
69
70 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
71
72 if (module->getFloor() != 0) {
73
74 JModule buffer = demo.getModule(module->getID(), module->getLocation());
75
76 const JRotation3D R = getRotation(buffer, *module);
77
78 buffer.rotate(R);
79
80 if (!JModule::compare(buffer, *module, precision)) {
81 FATAL("Module " << setw(10) << module->getID() << " at location " << getLabel(module->getLocation()) << " incompatible with " << (demo.get(module->getID()) == demo.getDefaultModuleAddressMap() ? "default" : "custom") << " reference." << endl);
82 }
83 }
84 }
85
86
87 const json error = { {Message_t, "" },
88 {Code_t, OK_t },
89 {Arguments_t, json::array() } };
90
91
92 json js;
93 size_t N = 0; // data
94
95 js[Comment_t] = json(detector.comment);
96 js[Error_t] = json(error);
97
98 {
99 JPMTCalibration data;
100
101 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
102 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
103 data.push_back(JPMTCalibration_t(pmt->getID(), getCalibration(JCalibration(), *pmt)));
104 }
105 }
106
107 js[Data_t][N][DetID_t] = json(detector.getID());
108 js[Data_t][N][PMTT0s_t] = json(data);
109
110 if (hasWildCard(outputFile)) {
111
112 store(setWildCard(outputFile.c_str(), TCAL), js);
113
114 js[Data_t].clear();
115
116 } else {
117
118 N += 1;
119 }
120 }
121 {
122 JModulePosition data[2];
123
124 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
125
126 const JModule& buffer = demo.getModule(module->getID(), module->getLocation());
127
128 if (buffer.getFloor() == 0)
129 data[0].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
130 else
131 data[1].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
132 }
133
134 js[Data_t][N][DetID_t] = json(detector.getID());
135 js[Data_t][N][BasePositions_t] = json(data[0]);
136 js[Data_t][N][DOMPositions_t] = json(data[1]);
137
138 if (hasWildCard(outputFile)) {
139
140 store(setWildCard(outputFile.c_str(), PCAL), js);
141
142 js[Data_t].clear();
143
144 } else {
145
146 N += 1;
147 }
148 }
149 {
150 JModuleRotation data;
151
152 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
153
154 const JModule& buffer = demo.getModule(module->getID(), module->getLocation());
155
156 if (module->getFloor() != 0) {
157 data.push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module)));
158 }
159 }
160
161 js[Data_t][N][DetID_t] = json(detector.getID());
162 js[Data_t][N][DOMRotations_t] = json(data);
163
164 if (hasWildCard(outputFile)) {
165
166 store(setWildCard(outputFile.c_str(), RCAL), js);
167
168 js[Data_t].clear();
169
170 } else {
171
172 N += 1;
173 }
174 }
175 {
176 JModuleCalibration data[2];
177
178 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
179
180 if (module->getFloor() == 0)
181 data[0].push_back(JModuleCalibration_t(module->getID(), module->getT0()));
182 else
183 data[1].push_back(JModuleCalibration_t(module->getID(), module->getT0()));
184 }
185
186 js[Data_t][N][DetID_t] = json(detector.getID());
187 js[Data_t][N][BaseAcousticT0_t] = json(data[0]);
188 js[Data_t][N][DOMAcousticT0_t] = json(data[1]);
189
190 if (hasWildCard(outputFile)) {
191
192 store(setWildCard(outputFile.c_str(), ACAL), js);
193
194 js[Data_t].clear();
195
196 } else {
197
198 N += 1;
199 }
200 }
201 {
202 JCompassRotation data[2];
203
204 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
205 if (module->getFloor() == 0)
206 data[0].push_back(JCompassRotation_t(module->getID(), module->getQuaternion()));
207 else
208 data[1].push_back(JCompassRotation_t(module->getID(), module->getQuaternion()));
209 }
210
211 js[Data_t][N][DetID_t] = json(detector.getID());
212 js[Data_t][N][BaseCompassRotations_t] = json(data[0]);
213 js[Data_t][N][DOMCompassRotations_t] = json(data[1]);
214
215 if (hasWildCard(outputFile)) {
216
217 store(setWildCard(outputFile.c_str(), CCAL), js);
218
219 js[Data_t].clear();
220
221 } else {
222
223 N += 1;
224 }
225 }
226 {
227 js[Data_t][N][DetID_t] = json(detector.getID());
228
229 {
230 JPMTStatus data;
231
232 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
233 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
234 data.push_back(JPMTStatus_t(pmt->getID(), pmt->getStatus()));
235 }
236 }
237
238 js[Data_t][N][PMTStatusInfo_t ] = json(data);
239 }
240 {
241 JModuleStatus data[2];
242
243 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
244 if (module->getFloor() == 0)
245 data[0].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
246 else
247 data[1].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
248 }
249
250 js[Data_t][N][BaseStatusInfo_t] = json(data[0]);
251 js[Data_t][N][DOMStatusInfo_t] = json(data[1]);
252 }
253
254 if (hasWildCard(outputFile)) {
255
256 store(setWildCard(outputFile.c_str(), SCAL), js);
257
258 js[Data_t].clear();
259
260 } else {
261
262 N += 1;
263 }
264 }
265
266
267 if (!hasWildCard(outputFile)) {
268 store(outputFile.c_str(), js);
269 }
270
271 return 0;
272}
string outputFile
int main(int argc, char **argv)
Detector support kit.
Data structure for detector geometry and calibration.
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
nlohmann::json json
Auxiliary methods for handling file names, type names and environment.
Data structure for time calibration.
const JModuleAddressMap & get(const int id) const
Get module address map.
virtual const JModuleAddressMap & getDefaultModuleAddressMap() const =0
Get default module address map.
Detector data structure.
Definition JDetector.hh:96
int getFloor() const
Get floor number.
Definition JLocation.hh:146
Data structure for a composite optical module.
Definition JModule.hh:75
void rotate(const JRotation3D &R)
Rotate module.
Definition JModule.hh:314
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Detector file.
Definition JHead.hh:227
Auxiliary data structure for compass rotation.
Auxiliary interface for building detector.
const JModule & getModule(const int id=-1, const JLocation &location=JLocation()) const
Get module.
Auxiliary data structure for module time calibration.
Auxiliary data structure for module position.
Auxiliary data structure for module rotation.
Auxiliary data structure for module status.
Auxiliary data structure for PMT time calibration.
Auxiliary data structure for PMT status.