Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
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  if (module->getFloor() != 0) {
70 
71  JModule buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
72 
73  const JRotation3D R = getRotation(buffer, *module);
74 
75  buffer.rotate(R);
76 
77  if (!JModule::compare(buffer, *module, precision)) {
78  ERROR("Module " << setw(10) << module->getID() << ' ' << module->getLocation() << " incompatible with reference." << endl);
79  }
80  }
81  }
82 
83 
84  JPMTCalibration calibration;
85  JModulePosition position;
86  JModuleRotation rotation;
87 
88  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
89 
90  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
91 
92  {
93  position.push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
94  }
95  if (module->getFloor() != 0) {
96  rotation.push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module)));
97  }
98 
99  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
100  calibration.push_back(JPMTCalibration_t(pmt->getID(), getCalibration(JCalibration(), *pmt)));
101  }
102  }
103 
104 
105  json js;
106 
107  js[Result_t] = OK_t;
108 
109  js[Data_t][0][PMTT0s_t] = json(calibration);
110  js[Data_t][0][DOMPositions_t] = json(position);
111  js[Data_t][0][DOMRotations_t] = json(rotation);
112 
113  if (outputFile != "") {
114 
115  ostream* out = open<ostream>(outputFile.c_str());
116 
117  *out << setw(2) << setprecision(8);
118  *out << js;
119 
120  close(out);
121  }
122 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
Data structure for a composite optical module.
Definition: JModule.hh:57
static const std::string DOMPositions_t
static const std::string OK_t
Detector data structure.
Definition: JDetector.hh:80
Rotation matrix.
Definition: JRotation3D.hh:111
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
Lookup table for PMT addresses in detector.
Data structure for time calibration.
string outputFile
Data structure for detector geometry and calibration.
static const std::string Result_t
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
void close(std::istream *pf)
Close file.
Definition: JeepToolkit.hh:346
Auxiliary methods for handling file names, type names and environment.
static const std::string DOMRotations_t
JPosition3D getPosition(const Vec &pos)
Get position.
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:63
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:351
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:40
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
nlohmann::json json
Auxiliary data structure for module rotation.
Auxiliary data structure for module position.
static const std::string PMTT0s_t
do set_variable DETECTOR_TXT $WORKDIR detector
static const std::string Data_t
Auxiliary data structure for PMT time calibration.
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number