Jpp 19.3.0
the software that should make you happy
Loading...
Searching...
No Matches
examples/JDB/JCheckHV.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <limits>
5#include <vector>
6#include <map>
7
8#include "TROOT.h"
9#include "TFile.h"
10#include "TH1D.h"
11#include "TGraph.h"
12
13#include "JDB/JDB.hh"
14#include "JDB/JSelector.hh"
16#include "JDB/JDBToolkit.hh"
19#include "JDB/JPMTHV.hh"
20#include "JDB/JLocation_t.hh"
21#include "JDB/JSupport.hh"
22
23#include "JROOT/JGraph.hh"
24#include "JROOT/JRootToolkit.hh"
25#include "JROOT/JManager.hh"
26
27#include "Jeep/JPrint.hh"
28#include "Jeep/JParser.hh"
29#include "Jeep/JMessage.hh"
30
31
32/**
33 * \file
34 *
35 * Auxiliary program to check HV.
36 * \author mdejong
37 */
38int main(int argc, char **argv)
39{
40 using namespace std;
41 using namespace JPP;
42
43 JServer server;
44 string usr;
45 string pwd;
46 string cookie;
47 string outputFile;
48 string detid;
49 vector<int> runs;
50 long long int numberOfRows;
51 double precision;
52 int debug;
53
54 try {
55
56 JParser<> zap("Auxiliary program to check HV.");
57
58 zap['s'] = make_field(server) = getServernames();
59 zap['u'] = make_field(usr) = "";
60 zap['!'] = make_field(pwd) = "";
61 zap['C'] = make_field(cookie) = "";
62 zap['o'] = make_field(outputFile) = "hv.root";
63 zap['D'] = make_field(detid, "Detector identifier");
64 zap['R'] = make_field(runs, "Run(s)");
65 zap['n'] = make_field(numberOfRows, "Maximal number of rows") = numeric_limits<long long int>::max();
66 zap['e'] = make_field(precision) = 0.5;
67 zap['d'] = make_field(debug) = 2;
68
69 zap(argc, argv);
70 }
71 catch(const exception &error) {
72 FATAL(error.what() << endl);
73 }
74
75
77 JManager<JLocation_t, TH1D> H1(new TH1D("HV[%]", NULL, 201, -256.0, +256.0));
78
79 map<JUPI_t, int> errors;
80 map<JUPI_t, int> aliens;
81
82 try {
83
84 JDB::reset(usr, pwd, cookie);
85
86 const int ID = getDetector<int> (detid);
87 detid = getDetector<string>(detid);
88
90
91 {
92 ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(ID));
93
94 for (JDetectorIntegration parameters; rs >> parameters; ) {
95
96 if (parameters.PMTUPI.getPBS() == PBS::PMT) {
97 detector[parameters.PMTUPI] = JLocation_t(parameters.DUID, parameters.FLOORID, parameters.CABLEPOS);
98 }
99 }
100
101 rs.Close();
102 }
103
104 for (const int run : runs) {
105
106 const JPMTHV HV(ID, run);
107
108 JSelector selection(&JDatalogNumbers::PARAMETER_NAME, "pmt_highvolt");
109
110 selection += getSelector<JDatalogNumbers>(detid, run, run);
111
112 ResultSet& rs = getResultSet(getTable<JDatalogNumbers>(), selection);
113
114 long long int counter = 0;
115
116 for (JDatalogNumbers parameters; rs >> parameters && counter != numberOfRows; ++counter) {
117
118 STATUS(setw(10) << counter << '\r'); DEBUG(endl);
119
120 const JUPI_t upi = parameters.SOURCE_NAME;
121 const JLocation_t location = detector[upi];
122
123 DEBUG(location << ' ' << FIXED(7,1) << HV(upi) << ' ' << FIXED(7,1) << parameters.DATA_VALUE << endl);
124
125 if (location.is_valid()) {
126
127 G1[location].put(parameters.getTime(), parameters.DATA_VALUE);
128
129 H1[location]->Fill(HV(upi).value - parameters.DATA_VALUE);
130
131 if (fabs(HV(upi).value - parameters.DATA_VALUE) > precision) {
132
133 ERROR("HV " << location << " set/read " << FIXED(7,1) << HV(upi) << "/" << FIXED(7,1) << parameters.DATA_VALUE << endl);
134
135 errors[upi] += 1;
136 }
137
138 } else {
139
140 aliens[upi] += 1;
141 }
142
143 STATUS(endl);
144 }
145
146 rs.Close();
147 }
148
149 if (debug >= warning_t) {
150 for (map<JUPI_t, int>::const_iterator i = errors.begin(); i != errors.end(); ++i) {
151 cout << "Error HV " << setw(32) << left << i->first << right << ' ' << detector[i->first] << ' ' << setw(3) << i->second << endl;
152 }
153 for (map<JUPI_t, int>::const_iterator i = aliens.begin(); i != aliens.end(); ++i) {
154 cout << "Alien UPI " << setw(32) << left << i->first << right << ' ' << setw(3) << i->second << endl;
155 }
156 }
157 }
158 catch(const exception& error) {
159 FATAL(error.what() << endl);
160 }
161
162
163 TFile out(outputFile.c_str(), "recreate");
164
165 for (map<JLocation_t, JGraph_t>::const_iterator i = G1.begin(); i != G1.end(); ++i) {
166 out << JGraph(i->second, MAKE_CSTRING("G[" << i->first << "].hv"));
167 }
168
169 out << H1;
170
171 out.Write();
172 out.Close();
173}
string outputFile
ROOT TTree parameter settings.
Dynamic ROOT object management.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
Double_t G1(const Double_t x)
Integral of method g1.
Definition JQuantiles.cc:37
Auxiliary class for PMT HVs.
Definition JPMTHV.hh:20
Utility class to parse command line options.
Definition JParser.hh:1698
const char * map
Definition elog.cc:87
int main(int argc, char **argv)
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Auxiliary data structure for location of product in detector.
bool is_valid() const
Check validity of location.
Wrapper class for server name.
Definition JDB.hh:54
Universal product identifier (UPI).
Definition JUPI_t.hh:33
Template definition for getting table specific selector.
Auxiliary data structure to build TGraph.
Definition JGraph.hh:44