Jpp  19.1.0
the software that should make you happy
Functions
software/JCompass/JAHRSMonitor.cc File Reference

Program to monitor AHRS data. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "JLang/JComparator.hh"
#include "JLang/JComparison.hh"
#include "JDB/JSupport.hh"
#include "JDB/JAHRS.hh"
#include "JDB/JAHRSCalibration_t.hh"
#include "JDB/JAHRSToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSystem/JStat.hh"
#include "JTools/JQuantile.hh"
#include "JROOT/JRootToolkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JStringRouter.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to monitor AHRS data.

Author
mdejong

Definition in file software/JCompass/JAHRSMonitor.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 41 of file software/JCompass/JAHRSMonitor.cc.

42 {
43  using namespace std;
44  using namespace JPP;
45 
47  JLimit_t& numberOfEvents = inputFile.getLimit();
48  string outputFile;
49  string detectorFile;
50  string ahrsFile;
51  double precision;
53  int qaqc;
54  int debug;
55 
56  try {
57 
58  JParser<> zap("Program to monitor AHRS data.");
59 
60  zap['f'] = make_field(inputFile, "output of JConvertDB -q ahrs");
61  zap['n'] = make_field(numberOfEvents) = JLimit::max();
62  zap['o'] = make_field(outputFile, "histogram output") = "";
63  zap['a'] = make_field(detectorFile);
64  zap['c'] = make_field(ahrsFile, "output of JAHRSCalibration");
65  zap['p'] = make_field(precision, "precision") = 1.0e-6;
66  zap['q'] = make_field(Q, "quantile");
67  zap['Q'] = make_field(qaqc) = 0;
68  zap['d'] = make_field(debug) = 2;
69 
70  zap(argc, argv);
71  }
72  catch(const exception &error) {
73  FATAL(error.what() << endl);
74  }
75 
76 
78 
79  try {
80  load(detectorFile, detector);
81  }
82  catch(const JException& error) {
83  FATAL(error);
84  }
85 
86  const JModuleRouter router(detector);
87 
88  const JAHRSCalibration_t calibration(ahrsFile.c_str());
89  const JAHRSValidity is_valid;
90 
91  const floor_range range = getRangeOfFloors(detector);
92 
93  const JStringRouter string(detector);
94 
95  TH1D h0("h0", NULL, 100, 0.0, 5.0);
96  TH1D h1("h1", NULL, 100, 0.0, 5.0);
97  TH2D h2("h2", NULL, 100, 0.0, 5.0, 100, 0.0, 5.0);
98  TH1D hn("hn", NULL, 100, 0.0, 1.0e4);
99 
100  TH2D* ha = new TH2D("ha", NULL,
101  string.size(), -0.5, string.size() - 0.5,
102  range.getUpperLimit(), 1 - 0.5, range.getUpperLimit() + 0.5);
103 
104  for (Int_t i = 1; i <= ha->GetXaxis()->GetNbins(); ++i) {
105  ha->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
106  }
107  for (Int_t i = 1; i <= ha->GetYaxis()->GetNbins(); ++i) {
108  ha->GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i));
109  }
110 
111  TH2D* hb = (TH2D*) ha->Clone("hb");
112  TH2D* hc = (TH2D*) ha->Clone("hc");
113  TH2D* hd = (TH2D*) ha->Clone("hd");
114 
115  typedef map<int, int> map_type;
116 
117  map_type data;
118 
119  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
120  if (module->getFloor() != 0) {
121  data[module->getID()] = 0;
122  }
123  }
124 
125  map<int, vector<JAHRS> > buffer;
126 
127  while (inputFile.hasNext()) {
128 
129  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
130 
131  const JAHRS* parameters = inputFile.next();
132 
133  if (router.hasModule(parameters->DOMID)) {
134 
135  const JLocation& location = router.getModule(parameters->DOMID);
136 
137  if (location.getFloor() != 0) {
138 
139  const double A = sqrt(parameters->AHRS_A0 * parameters->AHRS_A0 +
140  parameters->AHRS_A1 * parameters->AHRS_A1 +
141  parameters->AHRS_A2 * parameters->AHRS_A2);
142  const double H = sqrt(parameters->AHRS_H0 * parameters->AHRS_H0 +
143  parameters->AHRS_H1 * parameters->AHRS_H1 +
144  parameters->AHRS_H2 * parameters->AHRS_H2);
145 
146  h0.Fill(A);
147  h1.Fill(H);
148  h2.Fill(A,H);
149 
150  ha->Fill((double) string.getIndex(location.getString()), (double) location.getFloor());
151 
152  if (is_valid(*parameters)) {
153 
154  hb->Fill((double) string.getIndex(location.getString()), (double) location.getFloor());
155 
156  if (calibration.has(parameters->DOMID)) {
157  hc->Fill((double) string.getIndex(location.getString()), (double) location.getFloor());
158  }
159  }
160 
161  if (is_valid(*parameters) && calibration.has(parameters->DOMID))
162  buffer[parameters->DOMID].push_back(*parameters);
163  else
164  DEBUG("AHRS "
165  << setw(16) << parameters->UNIXTIME << ' '
166  << setw(4) << parameters->DUID << ' '
167  << setw(2) << parameters->FLOORID << ' '
168  << FIXED(7,3) << parameters->AHRS_A0 << ' '
169  << FIXED(7,3) << parameters->AHRS_A1 << ' '
170  << FIXED(7,3) << parameters->AHRS_A2 << ' '
171  << FIXED(7,3) << parameters->AHRS_H0 << ' '
172  << FIXED(7,3) << parameters->AHRS_H1 << ' '
173  << FIXED(7,3) << parameters->AHRS_H2 << ' '
174  << is_valid(*parameters)
175  << calibration.has(parameters->DOMID) << endl);
176  }
177  }
178  }
179  STATUS(endl);
180 
181 
182  for (map<int, vector<JAHRS> >::iterator i = buffer.begin(); i != buffer.end(); ++i) {
183 
184  data[i->first] = 1;
185 
186  if (i->second.size() >= 2u) {
187 
188  sort(i->second.begin(), i->second.end(), make_comparator(&JAHRS::UNIXTIME));
189 
190  for (vector<JAHRS>::const_iterator q = i->second.begin(), p = q++; q != i->second.end(); ++p, ++q) {
191 
192  if ((fabs(p->AHRS_A0 - q->AHRS_A0) > precision ||
193  fabs(p->AHRS_A1 - q->AHRS_A1) > precision ||
194  fabs(p->AHRS_A2 - q->AHRS_A2) > precision)
195  &&
196  (fabs(p->AHRS_H0 - q->AHRS_H0) > precision ||
197  fabs(p->AHRS_H1 - q->AHRS_H1) > precision ||
198  fabs(p->AHRS_H2 - q->AHRS_H2) > precision)) {
199 
200  data[i->first] += 1;
201  }
202  }
203  }
204  }
205 
206  for (map_type::const_iterator i = data.begin(); i != data.end(); ++i) {
207 
208  const JLocation& location = router.getModule(i->first);
209 
210  hn.Fill(i->second);
211 
212  hd->Fill((double) string.getIndex(location.getString()), (double) location.getFloor(), i->second);
213  }
214 
215  if (debug >= status_t) {
216 
217  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
218 
219  map_type::const_iterator p = data.find(module->getID());
220 
221  if (p != data.end()) {
222  cout << getLabel(module->getLocation()) << ' ' << setw(8) << module->getID() << ' ' << setw(6) << p->second << endl;
223  }
224  }
225  }
226 
227  if (outputFile != "") {
228 
229  TFile out(outputFile.c_str(), "recreate");
230 
231  out << h0 << h1 << h2 << hn;
232  out << *ha << *hb << *hc << *hd;
233 
234  out.Write();
235  out.Close();
236  }
237 
238  JQuantile q1("", true);
239 
240  int n_no_data_compass = 0;
241  for (map_type::const_iterator i = data.begin(); i != data.end(); ++i) {
242  if (i->second > 0) {
243  q1.put(i->second);
244  }
245  else {
246  n_no_data_compass++;
247  }
248  }
249 
250  for (vector<double>::const_iterator i = Q.begin(); i != Q.end(); ++i) {
251  QAQC(' '
252  << FIXED(5,0) << n_no_data_compass << ' '
253  << FIXED(8,3) << q1.getQuantile(*i));
254  }
255  QAQC(endl);
256 
257  return 0;
258 }
string outputFile
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define QAQC(A)
QA/QC output macro.
Definition: JMessage.hh:100
int qaqc
QA/QC file descriptor.
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:72
Detector data structure.
Definition: JDetector.hh:96
Logical location of module.
Definition: JLocation.hh:40
int getFloor() const
Get floor number.
Definition: JLocation.hh:146
int getString() const
Get string number.
Definition: JLocation.hh:135
Router for direct addressing of module data in detector data structure.
General exception.
Definition: JException.hh:24
Utility class to parse command line options.
Definition: JParser.hh:1698
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition: JLocation.hh:247
floor_range getRangeOfFloors(const JDetector &detector)
Get range of floors.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
@ status_t
status
Definition: JMessage.hh:30
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
int getIndex()
Get index for user I/O manipulation.
Definition: JManip.hh:26
static const double H
Planck constant [eV s].
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool is_valid(const json &js)
Check validity of JSon data.
std::map< int, range_type > map_type
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Calibration.
Definition: JHead.hh:330
Detector file.
Definition: JHead.hh:227
Auxiliary class to map module identifier to AHRS calibration.
Auxiliary data structure to check validity of AHRS data.
Definition: JAHRSToolkit.hh:20
double AHRS_H2
Definition: JAHRS.hh:39
long long int UNIXTIME
[ms]
Definition: JAHRS.hh:26
double AHRS_A1
Definition: JAHRS.hh:32
double AHRS_H1
Definition: JAHRS.hh:38
double AHRS_H0
Definition: JAHRS.hh:37
double AHRS_A0
Definition: JAHRS.hh:31
double AHRS_A2
Definition: JAHRS.hh:33
Router for mapping of string identifier to index.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
Auxiliary data structure for running average, standard deviation and quantiles.
Definition: JQuantile.hh:46