#include #include #include #include #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JModuleRouter.hh" #include "JCalibrate/JTDC_t.hh" #include "JLang/JObjectIO.hh" #include "JSupport/JMeta.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Auxiliary program to merge the time offsets of two detector files. * \author acreusot, mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; typedef pair pair_type; pair_type detectorFile_a; pair_type detectorFile_b; string outputFile; double precision; int debug; try { JParser<> zap("Auxiliary program to merge the time offsets of two detector files."\ "\nThe TDC constraints correspond to those used in conjuction with the detector file."); zap['a'] = make_field(detectorFile_a, " "); zap['b'] = make_field(detectorFile_b, " "); zap['o'] = make_field(outputFile) = ""; zap['p'] = make_field(precision) = 1.0e-3; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } JDetector detector_a; JDetector detector_b; try { load(detectorFile_a.first, detector_a); load(detectorFile_b.first, detector_b); } catch(const std::exception& error) { FATAL(error.what()); } if (detector_a.getID() != detector_b.getID()) { FATAL("Detector identifier " << detector_a.getID() << " != " << detector_b.getID() << endl); } const JModuleRouter router(detector_b); for (JDetector::iterator module = detector_a.begin(); module != detector_a.end(); ++module) { if (!router.hasModule(module->getID())) { FATAL("Missing module " << module->getID() << " in " << detectorFile_b.first << endl); } for (size_t pmt = 0; pmt != module->size(); ++pmt) { if (detectorFile_a.second.has(module->getID(), pmt)) { if (detectorFile_b.second.has(module->getID(), pmt)) ASSERT(fabs((*module)[pmt].getT0() - router.getModule(module->getID())[pmt].getT0()) <= precision, "PMT " << setw(10) << module->getID() << '.' << FILL(2,'0') << pmt << FILL() << " constraint."); else (*module)[pmt].setCalibration(router.getModule(module->getID())[pmt].getCalibration()); } } } NOTICE("Store calibration data on file " << outputFile << endl); detector_a.comment.add(JMeta(argc, argv)); store(outputFile, detector_a); }