Jpp  15.0.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMergeDetector.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JDetector/JDetector.hh"
9 
10 #include "JSupport/JMeta.hh"
11 
12 #include "Jeep/JParser.hh"
13 #include "Jeep/JMessage.hh"
14 
15 
16 /**
17  * \file
18  *
19  * Auxiliary program to merge detector files.
20  *
21  * \author mdejong
22  */
23 int main(int argc, char **argv)
24 {
25  using namespace std;
26  using namespace JPP;
27 
28  vector<string> detectorFile;
29  string tcalset;
30  string pcalset;
31  string rcalset;
32  string outputFile;
33  int debug;
34 
35  try {
36 
37  JParser<> zap("Auxiliary program to merge detector files.");
38 
39  zap['a'] = make_field(detectorFile);
40  zap['o'] = make_field(outputFile);
41  zap['t'] = make_field(tcalset, "tcal: t0 (time offsets) calibration set from file") = "";
42  zap['p'] = make_field(pcalset, "pcal: position (x,y,z) calibration set from file") = "";
43  zap['q'] = make_field(rcalset, "rcal: orientation (quaterions) calibration set from file") = "";
44  zap['d'] = make_field(debug) = 1;
45 
46  zap(argc, argv);
47  }
48  catch(const exception &error) {
49  FATAL(error.what() << endl);
50  }
51 
52 
54 
55  for (vector<string>::const_iterator i = detectorFile.begin(); i != detectorFile.end(); ++i) {
56 
57  JDetector buffer;
58 
59  try {
60  load(*i, buffer);
61  }
62  catch(const JException& error) {
63  FATAL(error);
64  }
65 
66  if (detector.empty())
67  detector = buffer;
68  else
69  copy(buffer.begin(), buffer.end(), back_inserter(detector));
70  }
71 
72  if (tcalset != "") {
73 
74  JDetector buffer;
75 
76  try {
77  load(tcalset, buffer);
78  }
79  catch(const JException& error) {
80  FATAL(error);
81  }
82 
83  JPMTRouter router(detector);
84 
85  for (const auto& module : buffer) {
86  for (const auto& pmt : module) {
87  if (router.hasPMT(pmt.getID()))
88  detector.getPMT(router.getAddress(pmt.getID())).setCalibration(pmt.getCalibration());
89  else
90  FATAL("Missing PMT " << pmt.getID() << endl);
91  }
92  }
93  }
94 
95  if (pcalset != "") {
96 
97  JDetector buffer;
98 
99  try {
100  load(pcalset, buffer);
101  }
102  catch(const JException& error) {
103  FATAL(error);
104  }
105 
106  JModuleRouter router(detector);
107 
108  for (const auto& module : buffer) {
109  if (router.hasModule(module.getID())) {
110 
111  if (module.getFloor() != 0)
112  detector.getModule(router.getAddress(module.getID())).set(module.getCenter());
113  else
114  detector.getModule(router.getAddress(module.getID())).set(module.getPosition());
115 
116  } else
117  FATAL("Missing module " << module.getID() << endl);
118  }
119  }
120 
121  if (rcalset != "") {
122 
123  JDetector buffer;
124 
125  try {
126  load(rcalset, buffer);
127  }
128  catch(const JException& error) {
129  FATAL(error);
130  }
131 
132  JModuleRouter router(detector);
133 
134  for (const auto& module : buffer) {
135  if (router.hasModule(module.getID()))
136  detector.getModule(router.getAddress(module.getID())).rotate(getRotation(detector.getModule(router.getAddress(module.getID())),module));
137  else
138  FATAL("Missing module " << module.getID() << endl);
139  }
140  }
141 
142  detector.comment.add(JMeta(argc,argv));
143 
144  try {
146  }
147  catch(const JException& error) {
148  FATAL(error);
149  }
150 }
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
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
bool hasPMT(const JObjectID &id) const
Has PMT.
Definition: JPMTRouter.hh:114
string outputFile
Data structure for detector geometry and calibration.
Detector file.
Definition: JHead.hh:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
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
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.
const JModuleAddress & getAddress(const JObjectID &id) const
Get address of module.
bool hasModule(const JObjectID &id) const
Has module.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
do set_variable DETECTOR_TXT $WORKDIR detector
const JPMTAddress & getAddress(const JObjectID &id) const
Get address of PMT.
Definition: JPMTRouter.hh:78