Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JNarrabri.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/JGraph.hh"
13 #include "JROOT/JRootToolkit.hh"
14 #include "JROOT/JManager.hh"
15 
16 #include "JDetector/JDetector.hh"
18 
20 #include "JSupport/JMeta.hh"
21 #include "JSupport/JSupport.hh"
22 
24 
25 #include "JAcoustics/JEvt.hh"
26 #include "JAcoustics/JSupport.hh"
27 
28 #include "JDynamics/JDynamics.hh"
29 
30 #include "Jeep/JPrint.hh"
31 #include "Jeep/JParser.hh"
32 #include "Jeep/JMessage.hh"
33 
34 
35 /**
36  * \file
37  * Example program to check contents of acoustic events.
38  *
39  * \author mdejong
40  */
41 int main(int argc, char **argv)
42 {
43  using namespace std;
44  using namespace JPP;
45 
47  JLimit_t& numberOfEvents = inputFile.getLimit();
48  string detectorFile;
49  string outputFile;
50  double Tmax_s;
51  int debug;
52 
53  try {
54 
55  JParser<> zap("Example program to check contents of acoustic events.");
56 
57  zap['f'] = make_field(inputFile, "output of JKatoomba[.sh]");
58  zap['n'] = make_field(numberOfEvents) = JLimit_t::max();
59  zap['a'] = make_field(detectorFile);
60  zap['o'] = make_field(outputFile) = "narrabri.root";
61  zap['T'] = make_field(Tmax_s);
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 
81  JDynamics dynamics(detector, Tmax_s);
82 
83  STATUS("loading input from file(s) " << inputFile << "... " << flush);
84 
85  dynamics.load(inputFile);
86 
87  STATUS("OK" << endl);
88 
89 
92 
93  Double_t xmin = numeric_limits<Double_t>::max();
94  Double_t xmax = numeric_limits<Double_t>::lowest();
95 
96  for (JDynamics::JPosition::const_iterator string = dynamics.position.begin(); string != dynamics.position.end(); ++string) {
97 
98  if (!string->second.empty()) {
99  xmin = min(xmin, string->second.getXmin());
100  xmax = max(xmax, string->second.getXmax());
101  }
102  }
103 
104  const JFormat_t format(4, 0, std::ios_base::fmtflags(), '0');
105 
106  JManager<int, TH2D> H2(new TH2D ("[%].tilt", NULL, 300, -3.0, +3.0, 300, -3.0, +3.0), '%', format);
107  JManager<int, TH1D> HT(new TH1D ("[%].time", NULL, 200, 0.0, 4.0), '%', format);
108 
109  JManager<int, TH1D> HO(new TH1D ("H[%].orientation", NULL, 1000, xmin, xmax), '%', format);
110  JManager<int, TH1D> HA(new TH1D ("H[%].amplitude", NULL, 1000, xmin, xmax), '%', format);
111 
112  for (JDynamics::JPosition::const_iterator string = dynamics.position.begin(); string != dynamics.position.end(); ++string) {
113 
114  TH1D* ho = HO[string->first];
115  TH1D* ha = HA[string->first];
116 
117  for (Int_t i = 1; i <= HO->GetXaxis()->GetNbins(); ++i) {
118 
119  const Double_t x = HO->GetXaxis()->GetBinCenter(i);
120 
121  const JMODEL::JString tilt = string->second(x);
122 
123  ho->SetBinContent(i, tilt.getAngle());
124  ha->SetBinContent(i, tilt.getLength());
125  }
126  }
127 
128 
129  for (JDynamics::JPosition::const_iterator string = dynamics.position.begin(); string != dynamics.position.end(); ++string) {
130 
131  if (string->second.size() > 1) {
132 
133  TH2D* h2 = H2[string->first];
134  TH1D* hc = HT[string->first];
135 
136  for (typename JDynamics::JPosition::function_type::const_iterator q = string->second.begin(), p = q++; q != string->second.end(); ++p, ++q) {
137 
138  const double t1 = q->getX() - p->getX();
139 
140  hc->Fill(log10(t1));
141 
142  if (t1 > 0 && t1 < Tmax_s) {
143  h2->Fill(600.0e3 * (q->getY().tx - p->getY().tx) / t1, // [mrad/10 min]
144  600.0e3 * (q->getY().ty - p->getY().ty) / t1); // [mrad/10 min]
145  }
146  }
147 
148  for (typename JDynamics::JPosition::function_type::const_iterator i = string->second.begin(); i != string->second.end(); ++i) {
149  ZO[string->first].put(i->getX(), i->getY().getAngle());
150  ZA[string->first].put(i->getX(), i->getY().getLength());
151  }
152  }
153  }
154 
155 
156  TFile out(outputFile.c_str(), "recreate");
157 
158  out << H2 << HT << HO << HA;
159 
160  for (map<int, JGraph_t>::const_iterator i = ZO.begin(); i != ZO.end(); ++i) {
161  out << JGraph(i->second, MAKE_CSTRING("G[" << i->first << "].orientation"));
162  }
163 
164  for (map<int, JGraph_t>::const_iterator i = ZA.begin(); i != ZA.end(); ++i) {
165  out << JGraph(i->second, MAKE_CSTRING("G[" << i->first << "].amplitude"));
166  }
167 
168  out.Write();
169  out.Close();
170 }
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
ROOT TTree parameter settings of various packages.
double getAngle() const
Get angle.
collection_type::const_iterator const_iterator
Definition: JPolfit.hh:157
#define STATUS(A)
Definition: JMessage.hh:63
ROOT TTree parameter settings.
JPosition position
position calibration
Definition: JDynamics.hh:576
Detector data structure.
Definition: JDetector.hh:80
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
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:485
data_type::const_iterator const_iterator
Definition: JDynamics.hh:295
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
const_iterator end() const
end of calibration data
Definition: JDynamics.hh:348
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:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
ROOT I/O of application specific meta data.
Dynamic detector calibration.
int debug
debug level
Definition: JSirene.cc:63
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:61
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:347
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
Acoustic event fit.
Data structure for format specifications.
Definition: JManip.hh:522
double getLength() const
Get length.