67{
70
72
74 string usr;
75 string pwd;
76 string cookie;
80 double fraction;
81 string testType;
83
84 try {
85
86 JParser<> zap(
"Auxiliary program to compute the PMT thresholds according to the small time-over-threshold fraction.");
87
92 zap[
'f'] =
make_field(inputFile,
"list of file names (output of JCalibrateToT)");
95 zap[
't'] =
make_field(fraction,
"maximal fraction of signal allowed for noise.") = 0.5;
96 zap[
'T'] =
make_field(testType,
"test type") =
"TH-TUNING-SEA-v1";
98
99 zap(argc, argv);
100 }
101 catch(const exception& error) {
102 FATAL(error.what() << endl);
103 }
104
105
106 if (inputFile.empty()) {
107 FATAL(
"No input files.");
108 }
109
112
113 try {
114
115 JDB::reset(usr, pwd, cookie);
116
118
119 rs >> person;
120
121 rs.Close();
122 }
123 catch(const exception& error) {
124 FATAL(error.what() << endl);
125 }
126
127
128 const JDAQHeader header = getDAQHeader(inputFile[0].c_str());
130
133
135
136 try {
137
139
141 detector[parameters.DOMID][parameters.CABLEPOS] = parameters;
142 }
143
144 rs.Close();
145 }
146 catch(const exception& error) {
147 FATAL(error.what() << endl);
148 }
149
150
151 struct parameters_type {
152 int threshold;
153 double signal;
154 double noise;
155 };
156
159
162
163 for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
164
165 const JDAQHeader header = getDAQHeader(i->c_str());
166
168
170
172
173 TFile* in = TFile::Open(i->c_str(), "exist");
174
175 if (in == NULL || !in->IsOpen()) {
176 FATAL(
"File: " << *i <<
" not opened." << endl);
177 }
178
179 for (detector_type::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
180
181 if (!module->second.empty()) {
182
184
185 if (h2s != NULL) {
186
187 for (int ix = 1; ix <= h2s->GetXaxis()->GetNbins(); ++ix) {
188
189 double noise = 0.0;
190 double signal = 0.0;
191
192 for (int iy = 1; iy <= h2s->GetYaxis()->GetNbins(); ++iy) {
193
194 const double x = h2s->GetYaxis()->GetBinCenter(iy);
195 const double y = h2s->GetBinContent(ix, iy);
196
198
199 if (range(x)) {
201 }
202 }
203
204 const JUPI_t upi =
module->second.at(ix-1).PMTUPI;
205
206 data[upi].push_back({ getPMTThreshold(upi).value, signal, noise});
207 }
208
209 } else {
210
211 WARNING(
"No histogram for module " << module->first <<
"; skip." << endl);
212 }
213 }
214 }
215
216 in->Close();
217 }
218
219
221
222 for (map_type::iterator i =
data.begin(); i !=
data.end(); ++i) {
223
224 sort(i->second.begin(), i->second.end(),
make_comparator(¶meters_type::threshold));
225
226 int threshold = i->second.begin()->threshold;
227
228 for (data_type::const_iterator p = i->second.begin(); p != i->second.end(); ++p) {
229
230 if (p->noise <= fraction * p->signal) {
231
232 threshold = p->threshold;
233
234 break;
235 }
236 }
237
238 if (
debug >=
debug_t || threshold > i->second.begin()->threshold) {
239
240 cout << "PMT " << left << setw(32) << i->first << " -> " << right << setw(3) << threshold << " (" << i->second.begin()->threshold << ")" << endl;
241
242 for (data_type::const_iterator p = i->second.begin(); p != i->second.end(); ++p) {
243 DEBUG(setw(3) << p->threshold <<
' ' <<
FIXED(7,0) << p->noise <<
"/" <<
FIXED(7,0) << p->signal <<
' ' << (p->noise <= fraction * p->signal) << endl);
244 }
245 }
246
248 }
249
250
252
254
255 js[
User_t] = person.LOGIN;
261
263
264 out << setw(2) << setprecision(8);
265 out << js;
266
267 out.close();
268 }
269}
#define DEBUG(A)
Message macros.
#define ASSERT(A,...)
Assert macro.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
#define MAKE_CSTRING(A)
Make C-string.
Auxiliary class for PMT thresholds.
Utility class to parse command line options.
int getDetectorID() const
Get detector identifier.
int getRunNumber() const
Get run number.
static const char *const _2SToT
Histogram naming.
ResultSet & getResultSet(const std::string &query)
Get result set.
const char * getTable()
Get table name.
std::vector< JServer > getServernames()
Get list of names of available database servers.
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< event_type > data_type
static const std::string Tests_t
static const std::string User_t
static const std::string Location_t
static const std::string Time_t
static const std::string Test_t
static const std::string OK_t
static const std::string End_t
static const std::string Type_t
static const std::string Start_t
std::map< int, range_type > map_type
Auxiliary data structure for floating point format specification.
Type definition of range.
Wrapper class for server name.
Universal product identifier (UPI).
Template definition for getting table specific selector.
Data structure for PMT threshold calibration.
Auxiliary class for date and time.
std::string toString() const
Get ASCII formatted date and time.