Jpp  18.4.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintDynamics.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"
8 
9 #include "JDynamics/JDynamics.hh"
10 
11 #include "JTools/JQuantile.hh"
12 
13 #include "JAcoustics/JEvt.hh"
14 #include "JAcoustics/JSupport.hh"
15 
17 #include "JSupport/JMeta.hh"
18 
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 
22 
23 /**
24  * \file
25  * Example program to print dynamic detector calibration.
26  *
27  * \author mdejong
28  */
29 int main(int argc, char **argv)
30 {
31  using namespace std;
32  using namespace JPP;
33 
34  const char* const short_t = "short";
35  const char* const long_t = "long";
36  const char* const fft_t = "fft";
37 
39  string detectorFile;
40  string outputFile;
41  string format;
42  double Tmax_s;
43  int debug;
44 
45  try {
46 
47  JParser<> zap("Example program to print dynamic detector calibration.");
48 
49  zap['a'] = make_field(detectorFile);
50  zap['+'] = make_field(calibrationFile);
51  zap['o'] = make_field(outputFile) = "";
52  zap['F'] = make_field(format) = short_t, long_t, fft_t;
53  zap['T'] = make_field(Tmax_s) = 1000.0;
54  zap['d'] = make_field(debug) = 1;
55 
56  zap(argc, argv);
57  }
58  catch(const exception &error) {
59  FATAL(error.what() << endl);
60  }
61 
62 
64 
65  try {
66  load(detectorFile, detector);
67  }
68  catch(const JException& error) {
69  FATAL(error);
70  }
71 
72  JDynamics dynamics(detector, 0.0);
73 
74  dynamics.load(calibrationFile);
75 
76  filebuf buffer;
77 
78  if (outputFile != "") {
79  buffer.open(outputFile.c_str(), ios::out);
80  }
81 
82  ostream os(buffer.is_open() ? &buffer : cout.rdbuf());
83 
84  JComment comment;
85 
86  comment.add("documentation: https://common.pages.km3net.de/jpp/Position_calibration.PDF");
87 
88  if (format == short_t)
89  comment.add("format: string number; UTC [s]; Tx; Ty");
90  else if (format == long_t)
91  comment.add("format: https://indico.cern.ch/event/1014814/contributions/4259426/attachments/2201529/3724129/KM3NeT_position_file_format.pdf");
92  else if (format == fft_t)
93  comment.add("format: <T>");
94 
95  DEBUG(comment);
96 
97  comment.add(JMeta(argc, argv));
98  /*
99  for (JMultipleFileScanner<JMeta> in(calibrationFile); in.hasNext(); ) {
100  comment.add(*in.next());
101  }
102  */
103 
104  if (format == short_t) {
105 
106  os << comment;
107  os << setw(4) << detector.getID() << ' ' << detector.getUTMGrid() << ' ' << detector.getUTMPosition() << endl;
108 
109  for (JDynamics::JPosition::const_iterator string = dynamics.position.begin(); string != dynamics.position.end(); ++string) {
110  for (typename JDynamics::JPosition::function_type::const_iterator i = string->second.begin(); i != string->second.end(); ++i) {
111  os << setw(4) << string->first << ';'
112  << FIXED(20,5) << i->getX() << ';'
113  << FIXED( 9,6) << i->getY().tx << ';'
114  << FIXED( 9,6) << i->getY().ty << endl;
115  }
116  }
117  }
118 
119  if (format == long_t) {
120 
121  os << comment;
122  os << setw(4) << detector.getID() << ' ' << detector.getUTMGrid() << ' ' << detector.getUTMPosition() << endl;
123 
124  for (typename JDynamics::JPosition::function_type::const_iterator i = dynamics.position.begin()->second.begin(); i != dynamics.position.begin()->second.end(); ++i) {
125 
126  const double t1 = i->getX();
127 
128  dynamics.update(t1);
129 
130  os << FIXED(20,5) << t1 << ' '
131  << FIXED(20,5) << t1 << ' '
132  << setw(4) << detector.size() << endl;
133 
134  for (JDetector::const_iterator module = dynamics.begin(); module != dynamics.end(); ++module) {
135 
136  os << setw(4) << module->getString() << ' '
137  << setw(2) << module->getFloor() << ' '
138  << setw(10) << module->getID() << endl;
139 
140  os << FIXED(9,2) << module->getX() << ' '
141  << FIXED(9,2) << module->getY() << ' '
142  << FIXED(9,2) << module->getZ() << ' '
143  << FIXED(9,2) << -1.0 << ' '
144  << FIXED(9,2) << -1.0 << ' '
145  << FIXED(9,2) << -1.0 << endl;
146  }
147  }
148  }
149 
150  if (format == fft_t) {
151 
152  double xmin = numeric_limits<double>::max();
153  double xmax = numeric_limits<double>::lowest();
154 
155  for (JDynamics::JPosition::const_iterator string = dynamics.position.begin(); string != dynamics.position.end(); ++string) {
156  if (!string->second.empty()) {
157  xmin = min(xmin, string->second.getXmin());
158  xmax = max(xmax, string->second.getXmax());
159  }
160  }
161 
162  for (double x = xmin; x <= xmax; x += Tmax_s) {
163 
164  JQuantile Q;
165 
166  for (JDynamics::JPosition::const_iterator string = dynamics.position.begin(); string != dynamics.position.end(); ++string) {
167  if (!string->second.empty()) {
168  Q.put(string->second(x).getLength());
169  }
170  }
171 
172  os << FIXED(9,5) << Q.getMean() << endl;
173  }
174  }
175 
176  buffer.close();
177 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:24
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
Definition: Main.cc:15
collection_type::const_iterator const_iterator
Definition: JPolfit.hh:184
ROOT TTree parameter settings.
JPosition position
position calibration
Definition: JDynamics.hh:615
Detector data structure.
Definition: JDetector.hh:89
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
Data structure for detector geometry and calibration.
void load(JObjectIterator_t &input)
Load calibration data.
Definition: JDynamics.hh:523
data_type::const_iterator const_iterator
Definition: JDynamics.hh:326
const_iterator end() const
end of calibration data
Definition: JDynamics.hh:377
Detector file.
Definition: JHead.hh:226
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
ROOT I/O of application specific meta data.
then awk string
Dynamic detector calibration.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
bool update(const double t1_s)
Get detector calibrated at given time.
Definition: JDynamics.hh:538
Auxiliary class for comment.
Definition: JComment.hh:41
Dynamic detector calibration.
Definition: JDynamics.hh:81
const double xmin
Definition: JQuadrature.cc:23
Auxiliary data structure for average.
Definition: JKatoomba_t.hh:76
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
const_iterator begin() const
begin of calibration data
Definition: JDynamics.hh:376
void put(const double x)
Put value.
Definition: JKatoomba_t.hh:101
JComment & add(const std::string &comment)
Add comment.
Definition: JComment.hh:100
long double getMean() const
Get mean value.
Definition: JKatoomba_t.hh:113
do set_variable DETECTOR_TXT $WORKDIR detector
Acoustic event fit.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62