Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
software/JDB/JPMTThreshold.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <vector>
4#include <map>
5#include <filesystem>
6
7#include "TF1.h"
8
9#include "JDB/JDB.hh"
10#include "JDB/JSelector.hh"
12#include "JDB/JDBToolkit.hh"
13#include "JDB/JPMTThreshold.hh"
15
17
18#include "JSupport/JMeta.hh"
19
20#include "Jeep/JParser.hh"
21#include "Jeep/JMessage.hh"
22
23
24/**
25 * \file
26 * Auxiliary program to set PMT thresholds according DAQ configuration of a given data taking run.
27 * \author mdejong
28 */
29int main(const int argc, const char * const argv[])
30{
31 using namespace std;
32 using namespace JPP;
33
34 JServer server;
35 string usr;
36 string pwd;
37 string cookie;
38 string detid;
39 int run;
40 string pmtFile;
41 string formula;
42 int debug;
43
44 try {
45
46 JParser<> zap("Auxiliary program to set PMT thresholds according DAQ configuration of a given data taking run.");
47
48 zap['s'] = make_field(server) = getServernames();
49 zap['u'] = make_field(usr) = "";
50 zap['!'] = make_field(pwd) = "";
51 zap['C'] = make_field(cookie) = "";
52 zap['D'] = make_field(detid);
53 zap['r'] = make_field(run);
54 zap['P'] = make_field(pmtFile, "PMT parameters file") = "";
55 zap['F'] = make_field(formula, "transfer function") = "((x * 1.0)/255.0 * 1.6 + 0.8 - 0.989) / 0.44"; // "((x * 1.0)/255.0 * 1.6 + 0.8 - 1) / 0.44";
56 zap['d'] = make_field(debug) = 1;
57
58 zap(argc, argv);
59 }
60 catch(const exception& error) {
61 FATAL(error.what() << endl);
62 }
63
64
65 JPMTParametersMap parameters;
66
67 if (pmtFile != "" && filesystem::is_regular_file(pmtFile)) {
68 parameters.load(pmtFile.c_str());
69 }
70
71
72 TF1 f1("user", formula.c_str());
73
74 if (!f1.IsValid()) {
75 FATAL("Formula <" << formula << "> invalid." << endl);
76 }
77
78
79 typedef vector<JDetectorIntegration> detector_type;
80
81 JPMTThreshold getPMTThreshold;
82 detector_type detector;
83
84
85 try {
86
87 JDB::reset(usr, pwd, cookie);
88
89 const int id = getDetector<int>(detid);
90
91 getPMTThreshold.configure(id, run);
92
93 DEBUG(getPMTThreshold);
94
95 ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(id));
96
97 for (JDetectorIntegration parameters; rs >> parameters; ) {
98 detector.push_back(parameters);
99 }
100
101 rs.Close();
102 }
103 catch(const exception& error) {
104 FATAL(error.what() << endl);
105 }
106
107
108 for (vector<JDetectorIntegration>::const_iterator i = detector.begin(); i != detector.end(); ++i) {
109
110 if (i->PMTID != -1) {
111
112 try {
113
114 const JPMTThreshold::result_type threshold = getPMTThreshold(i->PMTUPI);
115
116 const double value = f1.Eval((double) threshold.value);
117
118 if (debug >= debug_t) {
119
120 cout << FILL(4,'0') << i->DUID << FILL() << '.'
121 << FILL(2,'0') << i->FLOORID << FILL() << '['
122 << FILL(2,'0') << i->CABLEPOS << FILL() << ']'
123 << ' '
124 << setw(3) << threshold.value << ' '
125 << FIXED(5,2) << value << ' ';
126
127 if (threshold.is_default) {
128 cout << "* (" << FIXED(5,2) << JPMTParameters().threshold << ")";
129 }
130
131 cout << endl;
132 }
133
134 if (!threshold.is_default) {
135
136 const JPMTIdentifier id(i->DOMID, i->CABLEPOS);
137
138 parameters[id].threshold = value;
139 }
140 }
141 catch(const exception& error) {
142 WARNING("Error at "
143 << FILL(4,'0') << i->DUID << FILL() << '.'
144 << FILL(2,'0') << i->FLOORID << FILL() << '['
145 << FILL(2,'0') << i->CABLEPOS << FILL() << ']'
146 << ' '
147 << error.what() << endl);
148 }
149 }
150 }
151
152 if (pmtFile != "") {
153
154 parameters.comment.add(JMeta(argc, argv));
155
156 parameters.store(pmtFile.c_str());
157
158 } else {
159
160 cout << parameters << endl;
161 }
162}
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#define WARNING(A)
Definition JMessage.hh:65
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2107
Auxiliary class for PMT thresholds.
void configure(const int id, const int run)
Configure PMT thresholds for given detector and run.
Auxiliary class for map of PMT parameters.
Data structure for PMT parameters.
double threshold
threshold [npe]
Utility class to parse command line options.
Definition JParser.hh:1664
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for sequence of same character.
Definition JManip.hh:330
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Wrapper class for server name.
Definition JDB.hh:54
Template definition for getting table specific selector.
JComment & add(const std::string &comment)
Add comment.
Definition JComment.hh:100
void store(const char *file_name) const
Store to output file.
void load(const char *file_name)
Load from input file.
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72