Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
software/JCompass/JAHRSMonitor.cc File Reference

Program to monitor AHRS data. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#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

int main ( int  argc,
char **  argv 
)

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

38 {
39  using namespace std;
40  using namespace JPP;
41 
43  JLimit_t& numberOfEvents = inputFile.getLimit();
44  string outputFile;
45  string detectorFile;
46  string ahrsFile;
48  int qaqc;
49  int debug;
50 
51  try {
52 
53  JParser<> zap("Program to monitor AHRS data.");
54 
55  zap['f'] = make_field(inputFile, "output of JConvertDB -q ahrs");
56  zap['n'] = make_field(numberOfEvents) = JLimit::max();
57  zap['o'] = make_field(outputFile, "");
58  zap['a'] = make_field(detectorFile);
59  zap['c'] = make_field(ahrsFile, "output of JAHRSCalibration");
60  zap['q'] = make_field(Q, "quantile");
61  zap['Q'] = make_field(qaqc) = 0;
62  zap['d'] = make_field(debug) = 2;
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  const JModuleRouter router(detector);
81 
82  const JAHRSCalibration_t calibration(ahrsFile.c_str());
83  const JAHRSValidity is_valid;
84 
86 
87  const JStringRouter string(detector);
88 
89  TH1D h0("h0", NULL, 100, 0.0, 5.0);
90  TH1D h1("h1", NULL, 100, 0.0, 5.0);
91  TH2D h2("h2", NULL, 100, 0.0, 5.0, 100, 0.0, 5.0);
92  TH1D hn("hn", NULL, 100, 0.0, 1.0e4);
93 
94  TH2D* ha = new TH2D("ha", NULL,
95  string.size(), -0.5, string.size() - 0.5,
96  range.getUpperLimit(), 1 - 0.5, range.getUpperLimit() + 0.5);
97 
98  for (Int_t i = 1; i <= ha->GetXaxis()->GetNbins(); ++i) {
99  ha->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(string.at(i-1)));
100  }
101  for (Int_t i = 1; i <= ha->GetYaxis()->GetNbins(); ++i) {
102  ha->GetYaxis()->SetBinLabel(i, MAKE_CSTRING(i));
103  }
104 
105  TH2D* hb = (TH2D*) ha->Clone("hb");
106  TH2D* hc = (TH2D*) ha->Clone("hc");
107 
108  typedef map<int, int> map_type;
109 
110  map_type data;
111 
112  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
113  if (module->getFloor() != 0) {
114  data[module->getID()] = 0;
115  }
116  }
117 
118  while (inputFile.hasNext()) {
119 
120  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
121 
122  const JAHRS* parameters = inputFile.next();
123 
124  if (router.hasModule(parameters->DOMID)) {
125 
126  const JLocation& location = router.getModule(parameters->DOMID);
127 
128  if (location.getFloor() != 0) {
129 
130  const double A = sqrt(parameters->AHRS_A0 * parameters->AHRS_A0 +
131  parameters->AHRS_A1 * parameters->AHRS_A1 +
132  parameters->AHRS_A2 * parameters->AHRS_A2);
133  const double H = sqrt(parameters->AHRS_H0 * parameters->AHRS_H0 +
134  parameters->AHRS_H1 * parameters->AHRS_H1 +
135  parameters->AHRS_H2 * parameters->AHRS_H2);
136 
137  h0.Fill(A);
138  h1.Fill(H);
139  h2.Fill(A,H);
140 
141  ha->Fill((double) string.getIndex(location.getString()), (double) location.getFloor());
142 
143  if (is_valid(*parameters)) {
144 
145  hb->Fill((double) string.getIndex(location.getString()), (double) location.getFloor());
146 
147  if (calibration.has(parameters->DOMID)) {
148  hc->Fill((double) string.getIndex(location.getString()), (double) location.getFloor());
149  }
150  }
151 
152  if (is_valid(*parameters) && calibration.has(parameters->DOMID))
153  data[parameters->DOMID] += 1;
154  else
155  DEBUG("AHRS "
156  << setw(16) << parameters->UNIXTIME << ' '
157  << setw(4) << parameters->DUID << ' '
158  << setw(2) << parameters->FLOORID << ' '
159  << is_valid(*parameters)
160  << calibration.has(parameters->DOMID) << ' '
161  << FIXED(7,3) << parameters->AHRS_A0 << ' '
162  << FIXED(7,3) << parameters->AHRS_A1 << ' '
163  << FIXED(7,3) << parameters->AHRS_A2 << ' '
164  << FIXED(7,3) << parameters->AHRS_H0 << ' '
165  << FIXED(7,3) << parameters->AHRS_H1 << ' '
166  << FIXED(7,3) << parameters->AHRS_H2 << endl);
167  }
168  }
169  }
170  STATUS(endl);
171 
172  for (map_type::const_iterator i = data.begin(); i != data.end(); ++i) {
173  hn.Fill(i->second);
174  }
175 
176  if (debug >= status_t) {
177 
178  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
179 
180  map_type::const_iterator p = data.find(module->getID());
181 
182  if (p != data.end()) {
183  cout << getLabel(module->getLocation()) << ' ' << setw(8) << module->getID() << ' ' << setw(6) << p->second << endl;
184  }
185  }
186  }
187 
188  if (outputFile != "") {
189 
190  TFile out(outputFile.c_str(), "recreate");
191 
192  out << h0 << h1 << h2 << hn;
193  out << *ha << *hb << *hc;
194 
195  out.Write();
196  out.Close();
197  }
198 
199  JQuantile q1("", true);
200 
201  for (map_type::const_iterator i = data.begin(); i != data.end(); ++i) {
202  q1.put(i->second);
203  }
204 
205  for (vector<double>::const_iterator i = Q.begin(); i != Q.end(); ++i) {
206  QAQC(' ' << FIXED(8,3) << q1.getQuantile(*i));
207  }
208  QAQC(endl);
209 
210  return 0;
211 }
Utility class to parse command line options.
Definition: JParser.hh:1711
General exception.
Definition: JException.hh:24
Q(UTCMax_s-UTCMin_s)-livetime_s
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
double AHRS_H2
Definition: JAHRS.hh:39
Auxiliary data structure for running average, standard deviation and quantiles.
Definition: JQuantile.hh:43
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition: JLocation.hh:246
#define STATUS(A)
Definition: JMessage.hh:63
bool is_valid(const json &js)
Check validity of JSon data.
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
static const double H
Planck constant [eV s].
*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 for floating point format specification.
Definition: JManip.hh:446
string outputFile
floor_range getRangeOfFloors(const JDetector &detector)
Get range of floors.
Calibration.
Definition: JHead.hh:328
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:226
status
Definition: JMessage.hh:30
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
int getIndex()
Get index for user I/O manipulation.
Definition: JManip.hh:26
double AHRS_A1
Definition: JAHRS.hh:32
#define FATAL(A)
Definition: JMessage.hh:67
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
int getString() const
Get string number.
Definition: JLocation.hh:134
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
double AHRS_H0
Definition: JAHRS.hh:37
Router for mapping of string identifier to index.
General purpose class for object reading from a list of file names.
#define QAQC(A)
QA/QC output macro.
Definition: JMessage.hh:100
double AHRS_A2
Definition: JAHRS.hh:33
Auxiliary class to map module identifier to AHRS calibration.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
std::map< int, range_type > map_type
double AHRS_A0
Definition: JAHRS.hh:31
do set_variable DETECTOR_TXT $WORKDIR detector
source $JPP_DIR setenv csh $JPP_DIR &dev null eval JShellParser o a A
int qaqc
QA/QC file descriptor.
long long int UNIXTIME
[ms]
Definition: JAHRS.hh:26
double AHRS_H1
Definition: JAHRS.hh:38
int debug
debug level
Auxiliary data structure to check validity of AHRS data.
Definition: JAHRSToolkit.hh:20
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62