5 #include "dbclient/KM3NeTDBClient.h" 
    9 #include "JDB/JDBincludes.hh" 
   38 int main(
const int argc, 
const char * 
const argv[])
 
   55     JParser<> zap(
"Auxiliary program to compute the PMT thresholds according to the small ToT fraction (i.e. the noise to signal ratio).");
 
   60     zap[
'a'] = 
make_field(detectorFile, 
"detector file");
 
   61     zap[
'f'] = 
make_field(inputFile, 
"output file of JIntegrateToT");
 
   63     zap[
't'] = 
make_field(stfCut, 
"small ToT fraction cut-off") = 0.5;
 
   64     zap[
'T'] = 
make_field(testType, 
"test type") = 
"TH-TUNING-SEA-v1";
 
   68   catch(
const exception& error) {
 
   69     FATAL(error.what() << endl);
 
   90     NOTICE(
"connecting to the database..." << endl);
 
   95       ResultSet& rs = 
getResultSet(getTable<JPersons>(), selector);
 
  105       while (rs >> parameters) {
 
  106         detectorInt.push_back(parameters);
 
  110     catch(
const exception& error) {
 
  111       FATAL(error.what() << endl);
 
  115     ifstream istr(inputFile.c_str());
 
  118       if (curPar.runId != prevRunId) {
 
  119         NOTICE(
"Extracting thresholds for run " << curPar.runId << endl);
 
  120         runNumbers.push_back(
to_string(curPar.runId));
 
  123       vParameters.push_back(curPar);
 
  124       prevRunId = curPar.runId;
 
  128     for (
unsigned int r = 0; 
r < runNumbers.size(); ++
r) {
 
  134         if (rs >> parameters) {
 
  138         DEBUG(
"Run setup " << rs_oid << endl);
 
  140       catch(
const exception& error) {
 
  141         FATAL(error.what() << endl);
 
  149         while (rs >> parameters) {
 
  150           if (parameters.
NAME.find(
"PMT_THRESHOLD") != string::npos) {
 
  156       catch(
const exception& error) {
 
  157         FATAL(error.what() << endl);
 
  166         while (rs >> parameters) {
 
  168             if (parameters.
VALUE != 
"") {
 
  175       catch(
const exception& error) {
 
  176         FATAL(error.what() << endl);
 
  181         if (i->PMTID != -1) {
 
  182           const JUPI_t upi = i->PMTUPI;
 
  184           if (p == umap.end()) {
 
  186             os << upi.
getPBS() << JUPI_t::SEPARATOR
 
  189             p = umap.find(os.str());
 
  191           if (p != umap.end()) {
 
  193             parameters[id].threshold = p->second;
 
  195             ERROR(
"Missing threshold data PMT " << upi << endl);
 
  201       for (
unsigned int pmt = 0; pmt < vParameters.size(); ++pmt) {
 
  202         const int domId = vParameters[pmt].domId;
 
  203         const int pmtId = vParameters[pmt].pmtId;
 
  205         const double threshold = parameters[id].threshold;
 
  206         if (vParameters[pmt].runId == stoi(runNumbers[
r])) {
 
  207           vParameters[pmt].threshold = threshold;
 
  217     int previousSerial = -1;
 
  219     double defaultth = -1;
 
  221     bool calibratedPmt = 
false;
 
  222     sort(vParameters.begin(), vParameters.end());
 
  223     for (
unsigned int pmt = 0; pmt < vParameters.size(); ++pmt) {
 
  224       const int domId = vParameters[pmt].domId;
 
  225       const int pmtId = vParameters[pmt].pmtId;
 
  227       if (pmtSerial != previousSerial) {
 
  231       previousSerial = pmtSerial;
 
  232       if ((calibratedPmt == 
true) && (newPmt == 
false)) 
continue;
 
  236       if (newPmt == 
true) {
 
  237         defaultth = vParameters[pmt].threshold;
 
  239         calibratedPmt = 
false;
 
  241       const double curth = vParameters[pmt].threshold;
 
  242       const double noise = vParameters[pmt].noise;
 
  243       const double signal = vParameters[pmt].signal;
 
  244       const double ratio = signal ? noise/signal : 0;
 
  245       if ((ratio > stfCut) || (ratio == 0)) {
 
  251         calibratedPmt = 
true; 
 
  254         if (vParameters[pmt].runId == stoi(runNumbers.back())) {
 
  255           NOTICE(
"Bad channel for pmt " << pmtId << 
"(upi "  
  256                  << pmtSerial << 
"), floor " << floorId << 
"(dom " << domId << 
"), du "  
  260         if (optth > defaultth) {
 
  261           NOTICE(
"Non default thresholds " << optth << 
" for pmt " << pmtId << 
"(upi "  
  262                  << pmtSerial << 
"), floor " << floorId << 
"(dom " << domId << 
"), du "  
  263                  << duId << 
" with a STF of " << ratio << endl);
 
  266       if (calibratedPmt == 
true) { 
 
  269         THcalibrations.push_back(THcal);
 
  274     js[
User_t] = person.LOGIN;
 
  281     ofs << setw(2) << setprecision(8);
 
  284     NOTICE(validPmts << 
" calibrated PMTs among " << totalPmts << endl);
 
  286   catch(
const exception& error) {
 
  287     FATAL(error.what() << endl);
 
Utility class to parse command line options. 
 
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 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. 
 
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. 
 
static const std::string EndTime_t
 
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
 
std::string to_string(const T &value)
Convert value to string. 
 
ResultSet & getResultSet(const std::string &query)
Get result set. 
 
static const std::string StartTime_t
 
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
 
Template definition for getting table specific selector. 
 
Data structure for PMT threshold calibration. 
 
#define DEBUG(A)
Message macros. 
 
int main(int argc, char *argv[])