Jpp  18.0.0-rc.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCompareDynamicPositions.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <fstream>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH1D.h"
9 #include "TH2D.h"
10 #include "TGraph.h"
11 
12 #include "JROOT/JManager.hh"
13 #include "JROOT/JGraph.hh"
14 #include "JROOT/JRootToolkit.hh"
15 
16 #include "JDetector/JDetector.hh"
18 
19 #include "JDynamics/JDynamics.hh"
20 
21 #include "JTools/JQuantile.hh"
22 
23 #include "JAcoustics/JEvt.hh"
24 #include "JAcoustics/JSupport.hh"
25 
27 #include "JSupport/JMeta.hh"
28 #include "JSupport/JSupport.hh"
29 
30 #include "Jeep/JPrint.hh"
31 #include "Jeep/JParser.hh"
32 #include "Jeep/JMessage.hh"
33 
34 
35 /**
36  *
37  * Example program to compare dynamic position calibrations.
38  *
39  * \author cgatius
40  */
41 int main(int argc, char **argv)
42 {
43  using namespace std;
44  using namespace JPP;
45 
48  string detectorFile;
49  string outputFile;
50  double Tstep_s;
51  int debug;
52 
53  try {
54 
55  JParser<> zap("Example program to compare dynamic position calibrations.");
56 
57  zap['a'] = make_field(detectorFile);
58  zap['f'] = make_field(calibrationFile1, "output of JKatoomba[.sh]");
59  zap['F'] = make_field(calibrationFile2, "output of JKatoomba[.sh]");
60  zap['o'] = make_field(outputFile) = "compare_dynamic_positions.root";
61  zap['T'] = make_field(Tstep_s) = 600.0;
62  zap['d'] = make_field(debug) = 1;
63 
64  zap(argc, argv);
65  }
66  catch(const exception &error) {
67  FATAL(error.what() << endl);
68  }
69 
70 
72 
73  try {
74  load(detectorFile, detector);
75  }
76  catch(const JException& error) {
77  FATAL(error);
78  }
79 
80  getMechanics.load(detector.getID());
81 
82 
83  JDynamics dynamics1(detector, 0.0);
84 
85  STATUS("loading input from file " << calibrationFile1 << "... " << flush);
86 
87  dynamics1.load(calibrationFile1);
88 
89  STATUS("OK" << endl);
90 
91  Double_t xmin1 = numeric_limits<Double_t>::max();
92  Double_t xmax1 = numeric_limits<Double_t>::lowest();
93 
94  for (JDynamics::JPosition::const_iterator string = dynamics1.position.begin(); string != dynamics1.position.end(); ++string) {
95 
96  if (!string->second.empty()) {
97  xmin1 = min(xmin1, string->second.getXmin());
98  xmax1 = max(xmax1, string->second.getXmax());
99  }
100  }
101 
102  JDynamics dynamics2(detector, 0.0);
103 
104  STATUS("loading input from file " << calibrationFile1 << "... " << flush);
105 
106  dynamics2.load(calibrationFile2);
107 
108  STATUS("OK" << endl);
109 
110  Double_t xmin2 = numeric_limits<Double_t>::max();
111  Double_t xmax2 = numeric_limits<Double_t>::lowest();
112 
113  for (JDynamics::JPosition::const_iterator string = dynamics2.position.begin(); string != dynamics2.position.end(); ++string) {
114 
115  if (!string->second.empty()) {
116  xmin2 = min(xmin2, string->second.getXmin());
117  xmax2 = max(xmax2, string->second.getXmax());
118  }
119  }
120 
121  Double_t xmin = numeric_limits<Double_t>::max();
122  Double_t xmax = numeric_limits<Double_t>::lowest();
123 
124  //latest start time and earliest end time
125  xmin = max(xmin1, xmin2);
126  xmax = min(xmax1, xmax2);
127 
128  const JFormat_t format(4, 0, std::ios_base::fmtflags(), '0');
129 
132  JManager<int,TH1D> HC(new TH1D ("M[%].comparetx", NULL, 100, 0, 2),'%', format);
133  JManager<int,TH1D> HD(new TH1D ("N[%].comparety", NULL, 100, 0, 2),'%', format);
134 
135  for (JDynamics::JPosition::const_iterator string1 = dynamics1.position.begin(); string1 != dynamics1.position.end(); ++string1) {
136  for (JDynamics::JPosition::const_iterator string2 = dynamics2.position.begin(); string2 != dynamics2.position.end(); ++string2) {
137 
138  if (string1->first == string2->first) {
139 
140  TH1D* hc = HC[string1->first];
141  TH1D* hd = HD[string1->first];
142 
143  for (Double_t t = xmin; t <= xmax; t = t + Tstep_s) {
144 
145  HO[string1->first].put(t, (string1->second(t).tx - string2->second(t).tx) * 1000);
146  HA[string1->first].put(t, (string1->second(t).ty - string2->second(t).ty) * 1000);
147  hc->Fill((string1->second(t).tx - string2->second(t).tx) * 1000);
148  hd->Fill((string1->second(t).ty - string2->second(t).ty) * 1000);
149  }
150 
151  break;
152  }
153  }
154  }
155 
156  TFile out(outputFile.c_str(), "recreate");
157 
158  out << HC << HD;
159  for (map<int, JGraph_t>::const_iterator i = HO.begin(); i != HO.end(); ++i) {
160  out << JGraph(i->second, MAKE_CSTRING("H[" << i->first << "].comparetx"));
161  }
162 
163  for (map<int, JGraph_t>::const_iterator i = HA.begin(); i != HA.end(); ++i) {
164  out << JGraph(i->second, MAKE_CSTRING("K[" << i->first << "].comparety"));
165  }
166 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
static JDetectorMechanics getMechanics
Function object to get string mechanics.
Definition: JMechanics.hh:243
#define STATUS(A)
Definition: JMessage.hh:63
ROOT TTree parameter settings.
JPosition position
position calibration
Definition: JDynamics.hh:598
Detector data structure.
Definition: JDetector.hh:89
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Dynamic ROOT object management.
Auxiliary data structure to build TGraph.
Definition: JGraph.hh:42
string outputFile
Data structure for detector geometry and calibration.
void load(JObjectIterator_t &input)
Load calibration data.
Definition: JDynamics.hh:505
data_type::const_iterator const_iterator
Definition: JDynamics.hh:307
const_iterator end() const
end of calibration data
Definition: JDynamics.hh:360
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
I/O formatting auxiliaries.
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.
void load(const std::string &file_name)
Load mechanical model parameters from file.
Definition: JMechanics.hh:142
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...
Dynamic detector calibration.
Definition: JDynamics.hh:63
const double xmin
Definition: JQuadrature.cc:23
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:359
do set_variable DETECTOR_TXT $WORKDIR detector
Acoustic event fit.
Data structure for format specifications.
Definition: JManip.hh:522
int debug
debug level