Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JConstructDetector.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"
11 #include "JDetector/JPMTRouter.hh"
12 #include "JSupport/JMeta.hh"
13 
14 #include "Jeep/JeepToolkit.hh"
15 #include "Jeep/JPrint.hh"
16 #include "Jeep/JParser.hh"
17 #include "Jeep/JMessage.hh"
18 
19 
20 /**
21  * \file
22  *
23  * Auxiliary program to compose detector from separate calibrations.
24  * \author mdejong
25  */
26 int main(int argc, char **argv)
27 {
28  using namespace std;
29  using namespace JPP;
30 
31  string detectorFile;
32  string inputFile;
33  string outputFile;
34  int debug;
35 
36  try {
37 
38  JParser<> zap("Auxiliary program to compose detector from separate calibrations.");
39 
40  zap['a'] = make_field(detectorFile, "detector file (identifier and location of modules as well as identifier and status of PMTs are used)");
41  zap['f'] = make_field(inputFile, "detector calibrations file (json format)");
42  zap['o'] = make_field(outputFile, "detector file") = "";
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 JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
66 
67  const JModuleRouter moduleRouter(detector);
68  const JPMTRouter pmtRouter (detector);
69 
70 
71  json js;
72 
73  istream* in = open<istream>(inputFile.c_str());
74 
75  *in >> js;
76 
77  close(in);
78 
79  DEBUG(setw(4) << js << endl);
80 
81  JPMTCalibration calibration;
82  JModulePosition position;
83  JModuleRotation rotation;
84 
85  if (is_valid(js)) {
86 
87  json::const_iterator data = js.find(Data_t);
88 
89  if (data != js.end()) {
90 
91  for (size_t i = 0; i != data->size(); ++i) {
92 
93  if (data->at(i).contains(PMTT0s_t)) {
94  calibration = data->at(i)[PMTT0s_t].get<JPMTCalibration>();
95  }
96 
97  if (data->at(i).contains(DOMPositions_t)) {
98  position = data->at(i)[DOMPositions_t].get<JModulePosition>();
99  }
100 
101  if (data->at(i).contains(DOMRotations_t)) {
102  rotation = data->at(i)[DOMRotations_t].get<JModuleRotation>();
103  }
104  }
105  }
106  }
107 
108 
109  for (JModuleRotation::const_iterator i = rotation.begin(); i != rotation.end(); ++i) {
110 
111  if (moduleRouter.hasModule(i->getID())) {
112 
113  JModule& module = detector.getModule(moduleRouter.getAddress(i->getID()));
114  const JModule buffer = getModule(demo.get(module.getID()), module.getID());
115 
116  if (module.size() != buffer.size()) {
117  FATAL("Module size " << module.size() << " != " << buffer.size() << endl);
118  }
119 
120  for (size_t i = 0; i != module.size(); ++i) {
121  module.getPMT(i).setAxis(buffer.getPMT(i).getAxis());
122  }
123 
124  module.rotate(*i);
125  }
126  }
127 
128  for (JModulePosition::const_iterator i = position.begin(); i != position.end(); ++i) {
129 
130  if (moduleRouter.hasModule(i->getID())) {
131 
132  JModule& module = detector.getModule(moduleRouter.getAddress(i->getID()));
133 
134  module.add(*i);
135  }
136  }
137 
138  for (JPMTCalibration::const_iterator i = calibration.begin(); i != calibration.end(); ++i) {
139 
140  if (pmtRouter.hasPMT(i->getID())) {
141 
142  JPMT& pmt = detector.getPMT(pmtRouter.getAddress(i->getID()));
143 
144  pmt.setCalibration(*i);
145  }
146  }
147 
148 
149  detector.comment.add(JMeta(argc,argv));
150 
151  try {
153  }
154  catch(const JException& error) {
155  FATAL(error);
156  }
157 }
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
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
Detector data structure.
Definition: JDetector.hh:80
Router for direct addressing of module data in detector data structure.
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
void setAxis(const JAxis3D &axis)
Set axis.
Definition: JAxis3D.hh:109
bool hasPMT(const JObjectID &id) const
Has PMT.
Definition: JPMTRouter.hh:114
Lookup table for PMT addresses in detector.
string outputFile
Data structure for detector geometry and calibration.
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
int getID() const
Get identifier.
Definition: JObjectID.hh:50
bool is_valid(const json &js)
Check validity of JSon data.
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:47
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
ROOT I/O of application specific meta data.
Direct access to PMT in detector data structure.
int debug
debug level
Definition: JSirene.cc:63
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:211
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:351
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
void setCalibration(const JCalibration &cal)
Set calibration.
nlohmann::json json
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
const JAxis3D & getAxis() const
Get axis.
Definition: JAxis3D.hh:98
static const std::string PMTT0s_t
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38
static const std::string Data_t
const JPMTAddress & getAddress(const JObjectID &id) const
Get address of PMT.
Definition: JPMTRouter.hh:78
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
JModule & add(const JVector3D &pos)
Add position.
Definition: JModule.hh:456