Jpp
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 (module identifiers, module locations and PMT identifiers 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 
115  module = getModule(demo.get(module.getID()), module.getID(), module.getLocation());
116 
117  module.rotate(*i);
118  }
119  }
120 
121  for (JModulePosition::const_iterator i = position.begin(); i != position.end(); ++i) {
122 
123  if (moduleRouter.hasModule(i->getID())) {
124 
125  JModule& module = detector.getModule(moduleRouter.getAddress(i->getID()));
126 
127  module.add(*i);
128  }
129  }
130 
131  for (JPMTCalibration::const_iterator i = calibration.begin(); i != calibration.end(); ++i) {
132 
133  if (pmtRouter.hasPMT(i->getID())) {
134 
135  JPMT& pmt = detector.getPMT(pmtRouter.getAddress(i->getID()));
136 
137  pmt.setCalibration(*i);
138  }
139  }
140 
141 
142  detector.comment.add(JMeta(argc,argv));
143 
144  try {
146  }
147  catch(const JException& error) {
148  FATAL(error);
149  }
150 }
JMeta.hh
JEEP::close
void close(std::istream *pf)
Close file.
Definition: JeepToolkit.hh:342
JMessage.hh
JPrint.hh
JAANET::is_valid
bool is_valid(const T &value)
Check validity of given value.
Definition: JHead.hh:823
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:476
std::vector
Definition: JSTDTypes.hh:12
JDETECTOR::JPMTRouter::hasPMT
bool hasPMT(const JObjectID &id) const
Has PMT.
Definition: JPMTRouter.hh:114
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JDETECTOR::JPMTRouter
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
JDetectorCalibration.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
JDETECTOR::PMTT0s_t
static const std::string PMTT0s_t
Definition: JDetectorCalibration.hh:38
JLANG::JObjectID::getID
int getID() const
Get identifier.
Definition: JObjectID.hh:55
JDetectorAddressMapToolkit.hh
JDETECTOR::Data_t
static const std::string Data_t
Definition: JDetectorCalibration.hh:36
JModuleRouter.hh
JDETECTOR::JModule
Data structure for a composite optical module.
Definition: JModule.hh:49
JDETECTOR::JPMTRouter::getAddress
const JPMTAddress & getAddress(const JObjectID &id) const
Get address of PMT.
Definition: JPMTRouter.hh:78
JDETECTOR::JModule::rotate
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:230
JDETECTOR::JPMT
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:53
JParser.hh
JDetectorToolkit.hh
JDETECTOR::JModuleLocation::getLocation
const JModuleLocation & getLocation() const
Get location.
Definition: JModuleLocation.hh:68
JDETECTOR::JModuleRouter
Router for direct addressing of module data in detector data structure.
Definition: JModuleRouter.hh:34
JDETECTOR::store
void store(const JString &file_name, const JDetector &detector)
Store detector to output file.
Definition: JDetectorToolkit.hh:552
JDETECTOR::JCalibration::setCalibration
void setCalibration(const JCalibration &cal)
Set calibration.
Definition: JDetector/JCalibration.hh:72
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
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JAANET::detector
Detector file.
Definition: JHead.hh:130
JSUPPORT::JMeta
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
JPMTRouter.hh
JDETECTOR::DOMPositions_t
static const std::string DOMPositions_t
Definition: JDetectorCalibration.hh:39
std
Definition: jaanetDictionary.h:36
main
int main(int argc, char **argv)
Definition: JConstructDetector.cc:26
JeepToolkit.hh
JDETECTOR::JModule::add
JModule & add(const JVector3D &pos)
Add position.
Definition: JModule.hh:335
JDETECTOR::JDetectorAddressMap
Lookup table for PMT addresses in detector.
Definition: JDetectorAddressMap.hh:25
JDetector.hh
JDETECTOR::hasDetectorAddressMap
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
Definition: JDetectorAddressMapToolkit.hh:499
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JLANG::JException
General exception.
Definition: JException.hh:23
JDETECTOR::JDetectorAddressMap::get
const JModuleAddressMap & get(const int id) const
Get module address map.
Definition: JDetectorAddressMap.hh:69
JDETECTOR::getDetectorAddressMap
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
Definition: JDetectorAddressMapToolkit.hh:363