Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JDestructDetector.cc File Reference

Auxiliary program to decompose detector to separate calibrations. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorSupportkit.hh"
#include "JSon/JSon.hh"
#include "Jeep/JeepToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to decompose detector to separate calibrations.

Author
mdejong

Definition in file JDestructDetector.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 25 of file JDestructDetector.cc.

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 {
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 {
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 {
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 {
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 {
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 {
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 {
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
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
nlohmann::json json
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
JPosition3D getPosition(const Vec &pos)
Get position.
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition JLocation.hh:247
JDetectorBuilder & getDetectorBuilder()
Get detector builder.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
std::string setWildCard(const std::string &file_name, const std::string &value)
Get file name by setting wild card to given value.
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
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.