Jpp  16.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JConstructDetector.cc File Reference

Auxiliary program to compose detector from 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/JDetectorAddressMapToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JPMTRouter.hh"
#include "JSupport/JMeta.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 compose detector from separate calibrations.

Author
mdejong

Definition in file JConstructDetector.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 26 of file JConstructDetector.cc.

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); // position of reference module may not exactly be at origin
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:35
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
Data structure for a composite optical module.
Definition: JModule.hh:68
static const std::string DOMPositions_t
Detector data structure.
Definition: JDetector.hh:89
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
Lookup table for PMT addresses in detector.
string outputFile
Detector file.
Definition: JHead.hh:224
#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
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, calibration and status.
Definition: JPMT.hh:43
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
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:173
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:315
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
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:42
static const std::string Data_t
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:420