#include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "JSupport/JMeta.hh" #include "JSupport/JSingleFileScanner.hh" #include "dbclient/KM3NeTDBClient.h" #include "JDB/JDB.hh" #include "JDB/JDBToolkit.hh" #include "JDB/JDBincludes.hh" #include "JDB/JSelector.hh" #include "JDB/JSelectorSupportkit.hh" #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JCalibrate/JFitToT.hh" #include "JCalibrate/JHVInterpolator.hh" #include "JROOT/JManager.hh" #include "TFile.h" /** * \file * * Program to create input data for HV-tuning. * \author bjung */ int main(int argc, char **argv) { using namespace std; using namespace JPP; JServer server; string usr; string pwd; string cookie; map inputFiles; string detectorFile; string outputFile; int debug; try { JParser<> zap("Program to create input data for HV-tuning."); zap['s'] = make_field(server) = getServernames(); zap['u'] = make_field(usr) = ""; zap['!'] = make_field(pwd) = ""; zap['C'] = make_field(cookie) = ""; zap['f'] = make_field(inputFiles, "map of run numbers to file names (i.e. to the output of JFitToT)"); zap['a'] = make_field(detectorFile, "detector file"); zap['o'] = make_field(outputFile, "output file"); zap['d'] = make_field(debug, "debug") = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } JDetector detector; JManager manager(new TMultiGraph(), "%.HVxG"); try { load(detectorFile, detector); JDB::reset(usr, pwd, cookie); // Extract gain and high-voltage data for (map::const_iterator fileIt = inputFiles.cbegin(); fileIt != inputFiles.cend(); ++fileIt) { const int runNr = fileIt->first; NOTICE("Extracting Gain-/HV-data for run " << runNr << endl); { TFile fitData(fileIt->second.c_str(), "READ"); JSelector selector = getSelector(getDetector(detector.getID()), runNr); ResultSet& rs = getResultSet(getTable(), selector); for (JPMTHVRunSettings table; rs >> table; ) { const int domID = detector.getModule(JLocation(table.DUID, table.FLOORID)).getID(); const string pmtID = MAKE_STRING(right << domID << '.' << FILL(2,'0') << table.CABLEPOS); const TH1* h1 = (TH1*) fitData.Get(MAKE_CSTRING(pmtID << FITTOT_SUFFIX)); const TF1* f1 = (h1 != NULL ? h1->GetFunction(FITTOT_FNAME.c_str()) : NULL); JHVInterpolator interpolator(*(manager[pmtID])); if (f1 != NULL) { const int Ngain = f1->GetParNumber(FITTOT_GAIN_PARNAME); const double gain = f1->GetParameter(Ngain); const double gainError = f1->GetParError (Ngain); interpolator.AddPoint(table.HV_VALUE, gain, gainError); } } rs.Close(); } } } catch (const exception& error) { FATAL(error.what() << endl); } // Write output TFile out(outputFile.c_str(), "RECREATE"); putObject(out, JMeta(argc, argv)); for (map::const_iterator i = inputFiles.cbegin(); i != inputFiles.cend(); ++i) { for (JSingleFileScanner in(i->second); in.hasNext(); ) { putObject(out, *in.next()); } } out << manager; out.Close(); }