Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JNTupleToDetector.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
6 #include "JDetector/JDetector.hh"
11 #include "JIO/JFileStreamIO.hh"
12 
13 #include "Jeep/JParser.hh"
14 #include "Jeep/JMessage.hh"
15 #include "Jeep/JTimer.hh"
16 
17 
18 /**
19  * \file
20  *
21  * Program to convert ntuples to detector.
22  * \author mdejong
23  */
24 int main(int argc, char **argv)
25 {
26  using namespace std;
27 
28  string detectorFile;
29  string ntupleFile;
30  string outputFile;
31  int debug;
32 
33  try {
34 
35  JParser<> zap("Program to convert ntuples to detector.");
36 
37  zap['a'] = make_field(detectorFile);
38  zap['f'] = make_field(ntupleFile);
39  zap['o'] = make_field(outputFile) = "";
40  zap['d'] = make_field(debug) = 0;
41 
42  zap(argc, argv);
43  }
44  catch(const exception &error) {
45  FATAL(error.what() << endl);
46  }
47 
48 
49  using namespace JPP;
50 
51 
53 
54  try {
55  load(detectorFile, detector);
56  }
57  catch(const JException& error) {
58  FATAL(error);
59  }
60 
61 
62  const JModuleRouter router(detector);
63  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
64 
65 
66  JTimer timer("module");
67 
68  JFileStreamReader in(ntupleFile.c_str());
69 
70  for (JModuleGeometry geometry; in.load(geometry); ) {
71 
72  DEBUG(geometry << endl);
73 
74  const int id = geometry.getID();
75 
76  if (router.hasModule(id)) {
77 
78  timer.start();
79 
80  const JEulerMatrix3D R(geometry.getEulerAngle());
81 
82  JModule master = getModule(demo.get(id), id);
83 
84  master.rotate(R);
85  master.add(geometry.getPosition());
86 
87  JModule& module = detector.getModule(router.getAddress(id));
88 
89  if (module.size() == master.size()) {
90 
91  for (int pmt = 0; pmt != (int) master.size(); ++pmt) {
92  module.getPMT(pmt).setAxis(master.getPMT(pmt).getAxis());
93  }
94 
95  module.compile();
96 
97  } else {
98 
99  ERROR("Module sizes inconsistent " << module.size() << " != " << master.size() << endl);
100  }
101 
102  timer.stop();
103 
104  } else {
105 
106  ERROR("Missing module " << geometry.getID() << endl);
107  }
108  }
109 
110  in.close();
111 
112  timer.print(cout);
113 
114  if (outputFile != "") {
115 
116  if (outputFile == "%") {
117  outputFile = detectorFile;
118  }
119 
120  try {
122  }
123  catch(const JException& error) {
124  FATAL(error);
125  }
126  }
127 }
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:23
then echo Test string reversed by master(hit< return > to continue)." $DIR/JProcess -c "$DIR/JEcho" -rC fi if (( 1 ))
int main(int argc, char *argv[])
Definition: Main.cc:15
Data structure for a composite optical module.
Definition: JModule.hh:68
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
void setAxis(const JAxis3D &axis)
Set axis.
Definition: JAxis3D.hh:109
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...
Detector file.
Definition: JHead.hh:226
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
void compile()
Compile module data.
Definition: JModule.hh:282
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
Auxiliary class for CPU timing and usage.
Definition: JTimer.hh:32
#define ERROR(A)
Definition: JMessage.hh:66
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
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
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.
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
Binary buffered file input.
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62