#include #include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TH1D.h" #include "TGraph.h" #include "JDB/JDB.hh" #include "JDB/JSelector.hh" #include "JDB/JSelectorSupportkit.hh" #include "JDB/JDBToolkit.hh" #include "JDB/JDetectorIntegration.hh" #include "JDB/JDatalogNumbers.hh" #include "JDB/JPMTHVRunSettings.hh" #include "JDB/JLocation_t.hh" #include "JDB/JSupport.hh" #include "JROOT/JGraph.hh" #include "JROOT/JRootToolkit.hh" #include "JROOT/JManager.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Auxiliary program to check HV. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; JServer server; string usr; string pwd; string cookie; string outputFile; string detid; vector runs; long long int numberOfRows; double precision; int debug; try { JParser<> zap("Auxiliary program to check HV."); zap['s'] = make_field(server) = getServernames(); zap['u'] = make_field(usr) = ""; zap['!'] = make_field(pwd) = ""; zap['C'] = make_field(cookie) = ""; zap['o'] = make_field(outputFile) = "hv.root"; zap['D'] = make_field(detid, "Detector identifier"); zap['R'] = make_field(runs, "Run(s)"); zap['n'] = make_field(numberOfRows, "Maximal number of rows") = numeric_limits::max(); zap['e'] = make_field(precision) = 0.5; zap['d'] = make_field(debug) = 2; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } map G1; JManager H1(new TH1D("HV[%]", NULL, 201, -1500.0, +1500.0)); map errors; try { JDB::reset(usr, pwd, cookie); const int ID = getDetector (detid); detid = getDetector(detid); typedef map detector_type; detector_type detector; { ResultSet& rs = getResultSet(getTable(), getSelector(ID)); for (JDetectorIntegration parameters; rs >> parameters; ) { if (parameters.PMTUPI.getPBS() == PBS::PMT) { detector[parameters.PMTUPI] = JLocation_t(parameters.DUID, parameters.FLOORID, parameters.CABLEPOS); } } rs.Close(); } for (const int run : runs) { map HV; { ResultSet& rs = getResultSet(getTable(), getSelector(detid, run)); for (JPMTHVRunSettings parameters; rs >> parameters; ) { const JLocation_t location(parameters.DUID, parameters.FLOORID, parameters.CABLEPOS); if (parameters.CABLEPOS != parameters.PMTINTID) { WARNING("PMT " << location << " position " << parameters.PMTINTID << endl); } HV[location] = parameters.HV_VALUE; } rs.Close(); } if (debug >= debug_t) { cout << "HV settings " << setw(8) << run << endl; for (map::const_iterator i = HV.begin(); i != HV.end(); ++i) { cout << i->first << ' ' << FIXED(6,1) << i->second << endl; } } JSelector selection(&JDatalogNumbers::PARAMETER_NAME, "pmt_highvolt@"); selection += getSelector(detid, run, run); ResultSet& rs = getResultSet(getTable(), selection); long long int counter = 0; for (JDatalogNumbers parameters; rs >> parameters && counter != numberOfRows; ++counter) { STATUS(setw(10) << counter << '\r'); DEBUG(endl); const JUPI_t upi = parameters.SOURCE_NAME; const JLocation_t location = detector[upi]; DEBUG(location << ' ' << FIXED(7,1) << HV[location] << ' ' << FIXED(7,1) << parameters.DATA_VALUE << endl); if (location.is_valid()) { G1[location].put(parameters.getTime(), parameters.DATA_VALUE); H1[location]->Fill(HV[location] - parameters.DATA_VALUE); if (fabs(HV[location] - parameters.DATA_VALUE) > precision) { ERROR("HV " << location << " set/read " << FIXED(7,1) << HV[location] << "/" << FIXED(7,1) << parameters.DATA_VALUE << endl); } } else { errors[upi] += 1; } STATUS(endl); } rs.Close(); } } catch(const exception& error) { FATAL(error.what() << endl); } for (map::const_iterator i = errors.begin(); i != errors.end(); ++i) { ERROR("Alien UPI " << setw(24) << i->first << ' ' << i->second << endl); } TFile out(outputFile.c_str(), "recreate"); for (map::const_iterator i = G1.begin(); i != G1.end(); ++i) { out << JGraph(i->second, MAKE_CSTRING("G[" << i->first << "].hv")); } out << H1; out.Write(); out.Close(); }