5 #include "dbclient/KM3NeTDBClient.h"
9 #include "JDB/JDBincludes.hh"
38 int main(
const int argc,
const char *
const argv[])
56 JParser<> zap(
"Auxiliary program to compute the PMT thresholds according to the small ToT fraction (i.e. the noise to signal ratio).");
62 zap[
'a'] =
make_field(detectorFile,
"detector file");
63 zap[
'f'] =
make_field(inputFile,
"output file of JIntegrateToT");
65 zap[
't'] =
make_field(stfCut,
"small ToT fraction cut-off") = 0.5;
66 zap[
'T'] =
make_field(testType,
"test type") =
"TH-TUNING-SEA-v1";
70 catch(
const exception& error) {
71 FATAL(error.what() << endl);
92 NOTICE(
"connecting to the database..." << endl);
97 ResultSet& rs =
getResultSet(getTable<JPersons>(), selector);
107 while (rs >> parameters) {
108 detectorInt.push_back(parameters);
112 catch(
const exception& error) {
113 FATAL(error.what() << endl);
117 ifstream istr(inputFile.c_str());
120 if (curPar.runId != prevRunId) {
121 NOTICE(
"Extracting thresholds for run " << curPar.runId << endl);
122 runNumbers.push_back(
to_string(curPar.runId));
125 vParameters.push_back(curPar);
126 prevRunId = curPar.runId;
130 for (
unsigned int r = 0;
r < runNumbers.size(); ++
r) {
136 if (rs >> parameters) {
140 DEBUG(
"Run setup " << rs_oid << endl);
142 catch(
const exception& error) {
143 FATAL(error.what() << endl);
151 while (rs >> parameters) {
152 if (parameters.
NAME.find(
"PMT_THRESHOLD") != string::npos) {
158 catch(
const exception& error) {
159 FATAL(error.what() << endl);
168 while (rs >> parameters) {
170 if (parameters.
VALUE !=
"") {
177 catch(
const exception& error) {
178 FATAL(error.what() << endl);
183 if (i->PMTID != -1) {
184 const JUPI_t upi = i->PMTUPI;
186 if (p == umap.end()) {
188 os << upi.
getPBS() << JUPI_t::SEPARATOR
191 p = umap.find(os.str());
193 if (p != umap.end()) {
195 parameters[id].threshold = p->second;
197 ERROR(
"Missing threshold data PMT " << upi << endl);
203 for (
unsigned int pmt = 0; pmt < vParameters.size(); ++pmt) {
204 const int domId = vParameters[pmt].domId;
205 const int pmtId = vParameters[pmt].pmtId;
207 const double threshold = parameters[id].threshold;
208 if (vParameters[pmt].runId == stoi(runNumbers[
r])) {
209 vParameters[pmt].threshold = threshold;
219 int previousSerial = -1;
221 double defaultth = -1;
223 bool calibratedPmt =
false;
224 sort(vParameters.begin(), vParameters.end());
225 for (
unsigned int pmt = 0; pmt < vParameters.size(); ++pmt) {
226 const int domId = vParameters[pmt].domId;
227 const int pmtId = vParameters[pmt].pmtId;
229 if (pmtSerial != previousSerial) {
233 previousSerial = pmtSerial;
234 if ((calibratedPmt ==
true) && (newPmt ==
false))
continue;
238 if (newPmt ==
true) {
239 defaultth = vParameters[pmt].threshold;
241 calibratedPmt =
false;
243 const double curth = vParameters[pmt].threshold;
244 const double noise = vParameters[pmt].noise;
245 const double signal = vParameters[pmt].signal;
246 const double ratio = signal ? noise/signal : 0;
247 if ((ratio > stfCut) || (ratio == 0)) {
253 calibratedPmt =
true;
256 if (vParameters[pmt].runId == stoi(runNumbers.back())) {
257 NOTICE(
"Bad channel for pmt " << pmtId <<
"(upi "
258 << pmtSerial <<
"), floor " << floorId <<
"(dom " << domId <<
"), du "
262 if (optth > defaultth) {
263 NOTICE(
"Non default thresholds " << optth <<
" for pmt " << pmtId <<
"(upi "
264 << pmtSerial <<
"), floor " << floorId <<
"(dom " << domId <<
"), du "
265 << duId <<
" with a STF of " << ratio << endl);
268 if (calibratedPmt ==
true) {
271 THcalibrations.push_back(THcal);
276 js[
User_t] = person.LOGIN;
283 ofs << setw(2) << setprecision(8);
286 NOTICE(validPmts <<
" calibrated PMTs among " << totalPmts << endl);
288 catch(
const exception& error) {
289 FATAL(error.what() << endl);
Utility class to parse command line options.
int main(int argc, char *argv[])
int getFloor() const
Get floor number.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
const std::string & getVariant() const
Get variant.
static const std::string Time_t
static const std::string Tests_t
static const JPBS_t PMT(3, 4, 2, 3)
PBS of photo-multiplier tube (PMT)
static const std::string OK_t
Router for direct addressing of module data in detector data structure.
Auxiliary class for PMT parameters including threshold.
T get(const JHead &header)
Get object from header.
*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
static const std::string Location_t
Universal product identifier (UPI).
Dynamic ROOT object management.
Auxiliary class for specifying selection of database data.
Data structure for detector geometry and calibration.
const JPBS_t & getPBS() const
Get PBS.
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
I/O formatting auxiliaries.
Auxiliary data structure for location of product in detector.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
int getID() const
Get identifier.
static const std::string Test_t
Auxiliary class for map of PMT parameters.
const JPMT & getPMT(const int index) const
Get PMT.
General purpose messaging.
std::string toString() const
Convert UPI.
int getString() const
Get string number.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Auxililary class to get date and time.
Utility class to parse command line options.
static const std::string Type_t
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
std::string to_string(const T &value)
Convert value to string.
ResultSet & getResultSet(const std::string &query)
Get result set.
std::vector< JServer > getServernames()
Get list of names of available database servers.
Wrapper class for server name.
static const std::string User_t
Detector calibration key words for JSON I/O.
JUPIHelper getUPI
Function object for mapping PBS and serial number to UPI.
do set_variable DETECTOR_TXT $WORKDIR detector
static const std::string End_t
static const std::string Start_t
Template definition for getting table specific selector.
Data structure for PMT threshold calibration.