#include #include #include #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JModuleRouter.hh" #include "JDetector/JPMTRouter.hh" #include "JDetector/JDetectorCalibration.hh" #include "JLang/JEquation_t.hh" #include "JSupport/JMeta.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using namespace JPP; /** * List of valid keys. */ static const std::set keys = { TCAL, PCAL, RCAL, ACAL, CCAL, SCAL }; } /** * \file * * Auxiliary program to merge detector files. * * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; vector detectorFile; vector calset; string outputFile; int debug; try { JParser<> zap("Auxiliary program to merge detector files."); zap['a'] = make_field(detectorFile); zap['o'] = make_field(outputFile); zap['@'] = make_field(calset, "import calibration sets \" = [; = ]\"" << endl << "possible keys: " << JEEPZ() << keys) = JPARSER::initialised(); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } map calibration; for (vector::const_iterator i = calset.begin(); i != calset.end(); ++i) { if (keys.count(i->getKey()) == 0) FATAL("Invalid calibration set \"" << i->getKey() << "\"" << endl); else calibration[i->getKey()] = trim(i->getValue()); } JDetector detector; for (vector::const_iterator i = detectorFile.begin(); i != detectorFile.end(); ++i) { JDetector buffer; try { load(*i, buffer); } catch(const JException& error) { FATAL(error); } if (detector.empty()) detector = buffer; else copy(buffer.begin(), buffer.end(), back_inserter(detector)); } if (calibration.count(TCAL)) { JDetector buffer; try { load(calibration[TCAL], buffer); } catch(const JException& error) { FATAL(error); } JPMTRouter router(detector); for (const auto& module : buffer) { for (const auto& pmt : module) { if (router.hasPMT(pmt.getID())) detector.getPMT(router.getAddress(pmt.getID())).setCalibration(pmt.getCalibration()); else FATAL("Missing PMT " << pmt.getID() << endl); } } } if (calibration.count(PCAL)) { JDetector buffer; try { load(calibration[PCAL], buffer); } catch(const JException& error) { FATAL(error); } JModuleRouter router(detector); for (const auto& module : buffer) { if (router.hasModule(module.getID())) { if (module.getFloor() != 0) detector.getModule(router.getAddress(module.getID())).set(module.getCenter()); else detector.getModule(router.getAddress(module.getID())).set(module.getPosition()); } else FATAL("Missing module " << module.getID() << endl); } } if (calibration.count(RCAL)) { JDetector buffer; try { load(calibration[RCAL], buffer); } catch(const JException& error) { FATAL(error); } JModuleRouter router(detector); for (const auto& module : buffer) { if (router.hasModule(module.getID())) { if (module.getFloor() != 0) { JModule& object = detector.getModule(router.getAddress(module.getID())); const JRotation3D R = getRotation(object, module); const JPosition3D center = object.getCenter(); object.sub(center); object.rotate(R); object.add(center); } } else FATAL("Missing module " << module.getID() << endl); } } if (calibration.count(ACAL)) { JDetector buffer; try { load(calibration[ACAL], buffer); } catch(const JException& error) { FATAL(error); } JModuleRouter router(detector); for (const auto& module : buffer) { if (router.hasModule(module.getID())) { detector.getModule(router.getAddress(module.getID())).setT0(module.getT0()); } else FATAL("Missing module " << module.getID() << endl); } } if (calibration.count(CCAL)) { JDetector buffer; try { load(calibration[CCAL], buffer); } catch(const JException& error) { FATAL(error); } JModuleRouter router(detector); for (const auto& module : buffer) { if (router.hasModule(module.getID())) { detector.getModule(router.getAddress(module.getID())).setQuaternion(module.getQuaternion()); } else FATAL("Missing module " << module.getID() << endl); } } if (calibration.count(SCAL)) { JDetector buffer; try { load(calibration[SCAL], buffer); } catch(const JException& error) { FATAL(error); } { JModuleRouter router(detector); for (const auto& module : buffer) { if (router.hasModule(module.getID())) detector.getModule(router.getAddress(module.getID())).setStatus(module.getStatus()); else FATAL("Missing module " << module.getID() << endl); } } { JPMTRouter router(detector); for (const auto& module : buffer) { for (const auto& pmt : module) { if (router.hasPMT(pmt.getID())) detector.getPMT(router.getAddress(pmt.getID())).setStatus(pmt.getStatus()); else FATAL("Missing PMT " << pmt.getID() << endl); } } } } detector.comment.add(JMeta(argc,argv)); try { store(outputFile, detector); } catch(const JException& error) { FATAL(error); } }