68{
71
73
75 string usr;
76 string pwd;
77 string cookie;
81 double fraction;
82 string testType;
84
85 try {
86
87 JParser<> zap(
"Auxiliary program to compute the PMT thresholds according to the small time-over-threshold fraction.");
88
93 zap[
'f'] =
make_field(inputFile,
"list of file names (output of JCalibrateToT)");
96 zap[
't'] =
make_field(fraction,
"maximal fraction of signal allowed for noise.") = 0.5;
97 zap[
'T'] =
make_field(testType,
"test type") =
"TH-TUNING-SEA-v1";
99
100 zap(argc, argv);
101 }
102 catch(const exception& error) {
103 FATAL(error.what() << endl);
104 }
105
106
107 if (inputFile.empty()) {
108 FATAL(
"No input files.");
109 }
110
113
114 try {
115
116 JDB::reset(usr, pwd, cookie);
117
119
120 rs >> person;
121
122 rs.Close();
123 }
124 catch(const exception& error) {
125 FATAL(error.what() << endl);
126 }
127
128
129 const JDAQHeader header = getDAQHeader(inputFile[0].c_str());
131
134
136
137 try {
138
140
142 detector[parameters.DOMID][parameters.CABLEPOS] = parameters;
143 }
144
145 rs.Close();
146 }
147 catch(const exception& error) {
148 FATAL(error.what() << endl);
149 }
150
151
152 struct parameters_type {
153 int threshold;
154 double signal;
155 double noise;
156 };
157
160
163
164 for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
165
166 const JDAQHeader header = getDAQHeader(i->c_str());
167
169
171
173
174 TFile* in = TFile::Open(i->c_str(), "exist");
175
176 if (in == NULL || !in->IsOpen()) {
177 FATAL(
"File: " << *i <<
" not opened." << endl);
178 }
179
180 for (detector_type::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
181
182 if (!module->second.empty()) {
183
185
186 if (h2s != NULL) {
187
188 for (int ix = 1; ix <= h2s->GetXaxis()->GetNbins(); ++ix) {
189
190 double noise = 0.0;
191 double signal = 0.0;
192
193 for (int iy = 1; iy <= h2s->GetYaxis()->GetNbins(); ++iy) {
194
195 const double x = h2s->GetYaxis()->GetBinCenter(iy);
196 const double y = h2s->GetBinContent(ix, iy);
197
199
200 if (range(x)) {
202 }
203 }
204
205 const JUPI_t upi =
module->second.at(ix-1).PMTUPI;
206
207 data[upi].push_back({ getPMTThreshold(upi).value, signal, noise});
208 }
209
210 } else {
211
212 WARNING(
"No histogram for module " << module->first <<
"; skip." << endl);
213 }
214 }
215 }
216
217 in->Close();
218 }
219
220
222
223 for (map_type::iterator i =
data.begin(); i !=
data.end(); ++i) {
224
225 sort(i->second.begin(), i->second.end(),
make_comparator(¶meters_type::threshold));
226
227 int threshold = i->second.begin()->threshold;
228
229 for (data_type::const_iterator p = i->second.begin(); p != i->second.end(); ++p) {
230
231 if (p->noise <= fraction * p->signal) {
232
233 threshold = p->threshold;
234
235 break;
236 }
237 }
238
239 if (
debug >=
debug_t || threshold > i->second.begin()->threshold) {
240
241 cout << "PMT " << left << setw(32) << i->first << " -> " << right << setw(3) << threshold << " (" << i->second.begin()->threshold << ")" << endl;
242
243 for (data_type::const_iterator p = i->second.begin(); p != i->second.end(); ++p) {
244 DEBUG(setw(3) << p->threshold <<
' ' <<
FIXED(7,0) << p->noise <<
"/" <<
FIXED(7,0) << p->signal <<
' ' << (p->noise <= fraction * p->signal) << endl);
245 }
246 }
247
249 }
250
251
253
255
256 js[
User_t] = person.LOGIN;
262
264
265 out << setw(2) << setprecision(8);
266 out << js;
267
268 out.close();
269 }
270}
#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.