Jpp
JDestructDetector.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <fstream>
5 
6 #include "JDetector/JDetector.hh"
10 
11 #include "Jeep/JeepToolkit.hh"
12 #include "Jeep/JPrint.hh"
13 #include "Jeep/JParser.hh"
14 #include "Jeep/JMessage.hh"
15 
16 
17 /**
18  * \file
19  *
20  * Auxiliary program to decompose detector to separate calibrations.
21  * \author mdejong
22  */
23 int main(int argc, char **argv)
24 {
25  using namespace std;
26  using namespace JPP;
27 
28  string detectorFile;
29  string outputFile;
30  double precision;
31  int debug;
32 
33  try {
34 
35  JParser<> zap("Auxiliary program to decompose detector to separate calibrations.");
36 
37  zap['a'] = make_field(detectorFile, "detector file");
38  zap['o'] = make_field(outputFile, "detector calibrations file (json format)") = "";
39  zap['p'] = make_field(precision) = 1.0e-3;
40  zap['d'] = make_field(debug) = 1;
41 
42  zap(argc, argv);
43  }
44  catch(const exception &error) {
45  FATAL(error.what() << endl);
46  }
47 
48 
49  JDetector detector;
50 
51  try {
52  load(detectorFile, detector);
53  }
54  catch(const JException& error) {
55  FATAL(error);
56  }
57 
58  if (!hasDetectorAddressMap(detector.getID())) {
59  FATAL("No detector address map for detector identier " << detector.getID() << endl);
60  }
61 
62  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
63 
64 
65  // Test compatibility of modules with reference(s).
66 
67  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
68 
69  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
70 
71  if (!JModule::compare(buffer, *module, precision)) {
72  ERROR("Module " << setw(10) << module->getID() << " incompatible with reference." << endl);
73  }
74  }
75 
76 
77  JPMTCalibration calibration;
78  JModulePosition position;
79  JModuleRotation rotation;
80 
81  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
82 
83  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
84 
85  position.push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
86  rotation.push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module)));
87 
88  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
89  calibration.push_back(JPMTCalibration_t(pmt->getID(), getCalibration(JCalibration(), *pmt)));
90  }
91  }
92 
93 
94  json js;
95 
96  js[Result_t] = OK_t;
97 
98  js[Data_t][0][PMTT0s_t] = json(calibration);
99  js[Data_t][0][DOMPositions_t] = json(position);
100  js[Data_t][0][DOMRotations_t] = json(rotation);
101 
102  DEBUG(setw(4) << js << endl);
103 
104  if (outputFile != "") {
105 
106  ostream* out = open<ostream>(outputFile.c_str());
107 
108  *out << js;
109 
110  close(out);
111  }
112 }
JEEP::close
void close(std::istream *pf)
Close file.
Definition: JeepToolkit.hh:342
JDETECTOR::JModulePosition
std::vector< JModulePosition_t > JModulePosition
Module position.
Definition: JDetectorCalibration.hh:242
JDETECTOR::getCalibration
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
Definition: JDetectorToolkit.hh:846
JMessage.hh
JPrint.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
JDetectorCalibration.hh
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
main
int main(int argc, char **argv)
Definition: JDestructDetector.cc:23
debug
int debug
debug level
Definition: JSirene.cc:59
JDETECTOR::PMTT0s_t
static const std::string PMTT0s_t
Definition: JDetectorCalibration.hh:38
JDetectorAddressMapToolkit.hh
JDETECTOR::JPMTCalibration
std::vector< JPMTCalibration_t > JPMTCalibration
PMT calibration.
Definition: JDetectorCalibration.hh:241
JDETECTOR::Data_t
static const std::string Data_t
Definition: JDetectorCalibration.hh:36
JDETECTOR::JModuleRotation
std::vector< JModuleRotation_t > JModuleRotation
Module rotation.
Definition: JDetectorCalibration.hh:243
JParser.hh
JDetectorToolkit.hh
JDETECTOR::DOMRotations_t
static const std::string DOMRotations_t
Definition: JDetectorCalibration.hh:40
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JAANET::getPosition
JPosition3D getPosition(const Vec &v)
Get position.
Definition: JAAnetToolkit.hh:197
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
JDETECTOR::DOMPositions_t
static const std::string DOMPositions_t
Definition: JDetectorCalibration.hh:39
std
Definition: jaanetDictionary.h:36
JDETECTOR::OK_t
static const std::string OK_t
Definition: JDetectorCalibration.hh:54
JeepToolkit.hh
JDETECTOR::Result_t
static const std::string Result_t
Detector calibration key words for JSON I/O.
Definition: JDetectorCalibration.hh:34
JDetector.hh
JDETECTOR::hasDetectorAddressMap
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
Definition: JDetectorAddressMapToolkit.hh:499
JDETECTOR::getRotation
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
Definition: JDetectorToolkit.hh:823
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