Jpp  18.4.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
examples/JDB/JCompass.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <vector>
4 #include <map>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TGraph.h"
9 
10 #include "JDB/JAHRS.hh"
11 #include "JDB/JSupport.hh"
12 
13 #include "JROOT/JGraph.hh"
14 
15 #include "JDetector/JDetector.hh"
18 #include "JDetector/JCompass.hh"
19 
22 
23 #include "JLang/JComparator.hh"
25 
26 #include "Jeep/JPrint.hh"
27 #include "Jeep/JParser.hh"
28 #include "Jeep/JMessage.hh"
29 
30 
31 /**
32  * \file
33  *
34  * Example program to monitor AHRS data.
35  * \author mdejong
36  */
37 int main(int argc, char **argv)
38 {
39  using namespace std;
40  using namespace JPP;
41 
43  JLimit_t& numberOfEvents = inputFile.getLimit();
44  string outputFile;
45  string detectorFile;
46  double Tmax_s;
47  size_t numberOfModules;
48  int debug;
49 
50  try {
51 
52  JParser<> zap("Example program to monitor AHRS data.");
53 
54  zap['f'] = make_field(inputFile);
55  zap['n'] = make_field(numberOfEvents) = JLimit::max();
56  zap['o'] = make_field(outputFile) = "ahrs.root";
57  zap['a'] = make_field(detectorFile);
58  zap['T'] = make_field(Tmax_s) = 600.0; // [s]
59  zap['N'] = make_field(numberOfModules) = 10;
60  zap['d'] = make_field(debug) = 2;
61 
62  zap(argc, argv);
63  }
64  catch(const exception &error) {
65  FATAL(error.what() << endl);
66  }
67 
69 
70  try {
71  load(detectorFile, detector);
72  }
73  catch(const JException& error) {
74  FATAL(error);
75  }
76 
77  const JModuleRouter router(detector);
78 
79  typedef vector<JAHRS> buffer_type; // data type
80  typedef map<int, buffer_type> map_type; // string -> data
81 
82  map_type data;
83 
84  for (int counter = 0; inputFile.hasNext(); ++counter) {
85 
86  STATUS("counter: " << setw(8) << counter << '\r' << flush); DEBUG(endl);
87 
88  const JAHRS* parameters = inputFile.next();
89 
90  if (router.hasModule(parameters->DOMID)) {
91 
92  const JLocation location = router.getModule(parameters->DOMID);
93 
94  data[location.getString()].push_back(*parameters);
95  }
96  }
97  STATUS(endl);
98 
99 
102 
103  for (map_type::iterator string = data.begin(); string != data.end(); ++string) {
104 
105  if (!string->second.empty()) {
106 
107  sort(string->second.begin(), string->second.end(), make_comparator(&JAHRS::UNIXTIME));
108 
109  for (buffer_type::const_iterator p = string->second.begin(); p != string->second.end(); ) {
110 
111  set<int> buffer;
112 
113  buffer_type::const_iterator q = p;
114 
115  for ( ; q != string->second.end() && q->UNIXTIME - p->UNIXTIME <= Tmax_s * 1.0e3; ++q) {
116  buffer.insert(q->DOMID);
117  }
118 
119  if (buffer.size() > numberOfModules) {
120 
122 
123  for (buffer_type::const_iterator i = p; i != q; ++i) {
125  }
126 
127  Q.normalise();
128 
129  JDirection3D u(0.0, 0.0, 1.0);
130 
131  u.rotate(Q);
132 
133  const double t1 = p->UNIXTIME * 1.0e-3 + 0.5*Tmax_s;
134 
135  ZO[string->first].put(t1, atan2(u.getDY(), u.getDX()));
136  ZA[string->first].put(t1, sqrt(u.getDX()*u.getDX() + u.getDY()* u.getDY()));
137  }
138 
139  p = q;
140  }
141  }
142  }
143 
144 
145  TFile out(outputFile.c_str(), "recreate");
146 
147  for (map<int, JGraph_t>::const_iterator i = ZO.begin(); i != ZO.end(); ++i) {
148  out << JGraph(i->second, MAKE_CSTRING("G[" << i->first << "].orientation"));
149  }
150 
151  for (map<int, JGraph_t>::const_iterator i = ZA.begin(); i != ZA.end(); ++i) {
152  out << JGraph(i->second, MAKE_CSTRING("G[" << i->first << "].amplitude"));
153  }
154 
155  out.Write();
156  out.Close();
157 }
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
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
const JModule & getModule(const JObjectID &id) const
Get module parameters.
std::map< int, buffer_type > map_type
string -&gt; hits
Definition: JPerth.cc:68
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Auxiliary data structure to build TGraph.
Definition: JGraph.hh:42
string outputFile
Data structure for detector geometry and calibration.
std::vector< JHitW0 > buffer_type
hits
Definition: JPerth.cc:67
JQuaternion3D getQuaternion() const
Get quaternion.
Definition: JCompass.hh:201
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:226
JDirection3D & rotate(const JRotation3D &R)
Rotate.
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
double getDY() const
Get y direction.
Definition: JVersor3D.hh:106
double getDX() const
Get x direction.
Definition: JVersor3D.hh:95
Data structure for compass in three dimensions.
Definition: JCompass.hh:49
then awk string
ROOT TTree parameter settings.
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...
Data structure for unit quaternion in three dimensions.
Direct access to module in detector data structure.
int getString() const
Get string number.
Definition: JLocation.hh:134
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.
bool hasModule(const JObjectID &id) const
Has module.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
JQuaternion3D & normalise()
Normalise quaternion.
do set_variable DETECTOR_TXT $WORKDIR detector
double u[N+1]
Definition: JPolint.hh:865
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62