#include #include #include #include #include "TF1.h" #include "JDB/JDB.hh" #include "JDB/JSelector.hh" #include "JDB/JSelectorSupportkit.hh" #include "JDB/JDBToolkit.hh" #include "JDB/JPMTThreshold.hh" #include "JDB/JDetectorIntegration.hh" #include "JDetector/JPMTParametersMap.hh" #include "JSystem/JStat.hh" #include "JSupport/JMeta.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * Auxiliary program to set PMT thresholds according DAQ configuration of a given data taking run. * \author mdejong */ int main(const int argc, const char * const argv[]) { using namespace std; using namespace JPP; JServer server; string usr; string pwd; string cookie; string detid; int run; string pmtFile; string formula; int debug; try { JParser<> zap("Auxiliary program to set PMT thresholds according DAQ configuration of a given data taking run."); zap['s'] = make_field(server) = getServernames(); zap['u'] = make_field(usr) = ""; zap['!'] = make_field(pwd) = ""; zap['C'] = make_field(cookie) = ""; zap['D'] = make_field(detid); zap['r'] = make_field(run); zap['P'] = make_field(pmtFile, "PMT parameters file") = ""; 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"; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception& error) { FATAL(error.what() << endl); } JPMTParametersMap parameters; if (pmtFile != "" && getFileStatus(pmtFile.c_str())) { parameters.load(pmtFile.c_str()); } TF1 f1("user", formula.c_str()); if (!f1.IsValid()) { FATAL("Formula <" << formula << "> invalid." << endl); } typedef vector detector_type; JPMTThreshold getPMTThreshold; detector_type detector; try { JDB::reset(usr, pwd, cookie); const int id = getDetector(detid); getPMTThreshold.configure(id, run); DEBUG(getPMTThreshold); ResultSet& rs = getResultSet(getTable(), getSelector(id)); for (JDetectorIntegration parameters; rs >> parameters; ) { detector.push_back(parameters); } rs.Close(); } catch(const exception& error) { FATAL(error.what() << endl); } for (vector::const_iterator i = detector.begin(); i != detector.end(); ++i) { if (i->PMTID != -1) { try { const JPMTThreshold::result_type threshold = getPMTThreshold(i->PMTUPI); const double value = f1.Eval((double) threshold.value); if (debug >= debug_t) { cout << FILL(4,'0') << i->DUID << FILL() << '.' << FILL(2,'0') << i->FLOORID << FILL() << '[' << FILL(2,'0') << i->CABLEPOS << FILL() << ']' << ' ' << setw(3) << threshold.value << ' ' << FIXED(5,2) << value << ' '; if (threshold.is_default) { cout << "* (" << FIXED(5,2) << JPMTParameters().threshold << ")"; } cout << endl; } if (!threshold.is_default) { const JPMTIdentifier id(i->DOMID, i->CABLEPOS); parameters[id].threshold = value; } } catch(const exception& error) { WARNING("Error at " << FILL(4,'0') << i->DUID << FILL() << '.' << FILL(2,'0') << i->FLOORID << FILL() << '[' << FILL(2,'0') << i->CABLEPOS << FILL() << ']' << ' ' << error.what() << endl); } } } if (pmtFile != "") { parameters.comment.add(JMeta(argc, argv)); parameters.store(pmtFile.c_str()); } else { cout << parameters << endl; } }