Jpp  18.5.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JParramatta.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 
4 #include "TROOT.h"
5 #include "TFile.h"
6 #include "TH1D.h"
7 #include "TH2D.h"
8 #include "TProfile.h"
9 #include "TGraph.h"
10 
12 #include "JSupport/JTreeScanner.hh"
13 
14 #include "JROOT/JRootToolkit.hh"
15 #include "JROOT/JGraph.hh"
16 #include "JROOT/JManager.hh"
17 
18 #include "JAcoustics/JEvt.hh"
19 #include "JAcoustics/JSuperEvt.hh"
20 #include "JAcoustics/JSupport.hh"
21 
23 
24 #include "Jeep/JPrint.hh"
25 #include "Jeep/JParser.hh"
26 #include "Jeep/JMessage.hh"
27 
28 
29 /**
30  * \file
31  *
32  * Example program to plot acoustic fit results.
33  * \author mdejong
34  */
35 int main(int argc, char **argv)
36 {
37  using namespace std;
38  using namespace JPP;
39 
40  typedef JTYPELIST<JEvt, JSuperEvt>::typelist typelist;
41 
43  JLimit_t& numberOfEvents = inputFile.getLimit();
44  string outputFile;
45  double Z;
46  int debug;
47 
48  try {
49 
50  JParser<> zap("Example program to plot acoustic fit results.");
51 
52  zap['f'] = make_field(inputFile, "input file (output of JKatoomba[.sh]/JFremantle[.sh])");
53  zap['n'] = make_field(numberOfEvents) = JLimit::max();
54  zap['o'] = make_field(outputFile) = "parramatta.root";
55  zap['Z'] = make_field(Z, "detector height (for 2nd order tilt correction)") = 0.0;
56  zap['d'] = make_field(debug) = 2;
57 
58  zap(argc, argv);
59  }
60  catch(const exception &error) {
61  FATAL(error.what() << endl);
62  }
63 
64  Z *= 0.5; // half height
65 
66  const JFormat_t format(4, 0, std::ios_base::fmtflags(), '0');
67 
68  TH1D h1("chi2/NDF", NULL, 500, 0.0, 10.0);
69 
70  JGraph_t g0;
71  JGraph_t g1;
72 
76 
77  JManager<int, TProfile> H1(new TProfile("stretching[%]", NULL, 50, 0.0, 1.0e2));
78  JManager<int, TH2D> H2(new TH2D("[%].tiltdeviation", NULL, 300, -4.0, +4.0, 300, -4.0, +4.0), '%', format);
79 
81 
82  for (counter_type counter = 0; in.hasNext() && counter != inputFile.getLimit(); ++counter) {
83 
84  STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
85 
86  const JEvt* evt = in.next();
87 
88  h1.Fill(evt->chi2 / evt->ndf);
89 
90  const double t1 = 0.5 * (evt->UNIXTimeStart + evt->UNIXTimeStop);
91 
92  g0.put(t1, evt->nhit - evt->npar);
93  g1.put(t1, evt->chi2 / evt->ndf);
94 
95  double Tx = 0;
96  double Ty = 0;
97 
98  for (JEvt::const_iterator i = evt->begin(); i != evt->end(); ++i) {
99 
100  const int id = i->id;
101  const double tx = (i->tx + i->tx2 * Z) * 1.0e3; // [mrad]
102  const double ty = (i->ty + i->ty2 * Z) * 1.0e3; // [mrad]
103  const double vs = i->vs * 1.0e2; // [%]
104  const double ts = sqrt(tx*tx + ty*ty);
105 
106  Tx += tx;
107  Ty += ty;
108 
109  H1 ->Fill(ts, vs);
110  H1[id]->Fill(ts, vs);
111 
112  GO[id].put(t1, atan2(ty, tx));
113  GA[id].put(t1, ts);
114  GS[id].put(t1, vs);
115  }
116 
117  Tx /= evt->size();
118  Ty /= evt->size();
119 
120  for (JEvt::const_iterator i = evt->begin(); i != evt->end(); ++i) {
121 
122  const double tx = (i->tx + i->tx2 * Z*Z) * 1.0e3; // [mrad]
123  const double ty = (i->ty + i->ty2 * Z*Z) * 1.0e3; // [mrad]
124 
125  H2 ->Fill(tx - Tx, ty - Ty);
126  H2[i->id]->Fill(tx - Tx, ty - Ty);
127  }
128  }
129  STATUS(endl);
130 
131  TFile out(outputFile.c_str(), "recreate");
132 
133  out << h1
134  << JGraph(g0, "g0")
135  << JGraph(g1, "g1");
136 
137  out << H1 << *H1 << H2 << *H2;
138 
139  for (map<int, JGraph_t>::const_iterator i = GO.begin(); i != GO.end(); ++i) {
140  out << JGraph(i->second, MAKE_CSTRING("G[" << FILL(4,'0') << i->first << "].orientation"));
141  }
142 
143  for (map<int, JGraph_t>::const_iterator i = GA.begin(); i != GA.end(); ++i) {
144  out << JGraph(i->second, MAKE_CSTRING("G[" << FILL(4,'0') << i->first << "].amplitude"));
145  }
146 
147  for (map<int, JGraph_t>::const_iterator i = GS.begin(); i != GS.end(); ++i) {
148  out << JGraph(i->second, MAKE_CSTRING("G[" << FILL(4,'0') << i->first << "].stretching"));
149  }
150 
151  out.Write();
152  out.Close();
153 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int npar
number of fit parameters
int main(int argc, char *argv[])
Definition: Main.cc:15
Data structure for graph data.
Definition: JGraph.hh:21
#define STATUS(A)
Definition: JMessage.hh:63
ROOT TTree parameter settings.
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Long64_t counter_type
Type definition for counter.
Dynamic ROOT object management.
Auxiliary class for multiplexing object iterators.
Auxiliary data structure to build TGraph.
Definition: JGraph.hh:42
string outputFile
Type list.
Definition: JTypeList.hh:22
double UNIXTimeStop
stop time
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
I/O formatting auxiliaries.
std::vector< double > vs
Acoustic event fit.
double ndf
weighed number of degrees of freedom
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Acoustic event fit.
virtual const pointer_type & next() override
Get next element.
virtual bool hasNext() override
Check availability of next element.
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
int nhit
number of hits
double UNIXTimeStart
start time
General purpose class for object reading from a list of file names.
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:48
Utility class to parse command line options.
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
Acoustic event fit.
Data structure for format specifications.
Definition: JManip.hh:524
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25