#include #include #include #include #include "JDetector/JDetector.hh" #include "JDetector/JDetectorCalibration.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JDetectorAddressMapToolkit.hh" #include "JSon/JSon.hh" #include "Jeep/JeepToolkit.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Auxiliary program to decompose detector to separate calibrations. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; string detectorFile; string outputFile; double precision; int debug; try { JParser<> zap("Auxiliary program to decompose detector to separate calibrations."); zap['a'] = make_field(detectorFile, "detector file"); zap['o'] = make_field(outputFile, "detector calibrations file in JSON format "\ "(should contain wild card \'" << FILENAME_WILD_CARD << "\')"); zap['p'] = make_field(precision) = 1.0e-5; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } if (!hasWildCard(outputFile)) { FATAL("No wild card \'" << FILENAME_WILD_CARD << "\' in " << outputFile); } JDetector detector; try { load(detectorFile, detector); } catch(const JException& error) { FATAL(error); } if (!hasDetectorAddressMap(detector.getID())) { FATAL("No detector address map for detector identier " << detector.getID() << endl); } const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID()); // Test compatibility of modules with reference(s). for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { if (module->getFloor() != 0) { JModule buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation()); const JRotation3D R = getRotation(buffer, *module); buffer.rotate(R); if (!JModule::compare(buffer, *module, precision)) { FATAL("Module " << setw(10) << module->getID() << ' ' << module->getLocation() << " incompatible with reference." << endl); } } } const json error = { {Message_t, "" }, {Code_t, OK_t }, {Arguments_t, json::array() } }; { json js; JPMTCalibration data; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) { data.push_back(JPMTCalibration_t(pmt->getID(), getCalibration(JCalibration(), *pmt))); } } js[Data_t][0][DetID_t] = json(detector.getID()); js[Data_t][0][PMTT0s_t] = json(data); js[Error_t] = json(error); store(setWildCard(outputFile.c_str(), TCAL), js); } { json js; JModulePosition data[2]; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation()); if (buffer.getFloor() == 0) data[0].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module))); else data[1].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module))); } js[Data_t][0][DetID_t] = json(detector.getID()); js[Data_t][0][BasePositions_t] = json(data[0]); js[Data_t][0][DOMPositions_t] = json(data[1]); js[Error_t] = json(error); store(setWildCard(outputFile.c_str(), PCAL), js); } { json js; JModuleRotation data[2]; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation()); if (module->getFloor() == 0) data[0].push_back(JModuleRotation_t(module->getID(), JQuaternion3D())); else data[1].push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module))); } js[Data_t][0][DetID_t] = json(detector.getID()); js[Data_t][0][BaseRotations_t] = json(data[0]); js[Data_t][0][DOMRotations_t] = json(data[1]); js[Error_t] = json(error); store(setWildCard(outputFile.c_str(), RCAL), js); } { json js; JModuleCalibration data; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { data.push_back(JModuleCalibration_t(module->getID(), module->getT0())); } js[Data_t][0][DetID_t] = json(detector.getID()); js[Data_t][0][DOMAcousticT0_t] = json(data); js[Error_t] = json(error); store(setWildCard(outputFile.c_str(), ACAL), js); } { json js; JCompassRotation data; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { data.push_back(JCompassRotation_t(module->getID(), module->getQuaternion())); } js[Data_t][0][DetID_t] = json(detector.getID()); js[Data_t][0][DOMCompassRotations_t] = json(data); js[Error_t] = json(error); store(setWildCard(outputFile.c_str(), CCAL), js); } { json js; { JPMTStatus data; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) { data.push_back(JPMTStatus_t(pmt->getID(), pmt->getStatus())); } } js[Data_t][0][PMTStatusInfo_t ] = json(data); } { JModuleStatus data[2]; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { if (module->getFloor() == 0) data[0].push_back(JModuleStatus_t(module->getID(), module->getStatus())); else data[1].push_back(JModuleStatus_t(module->getID(), module->getStatus())); } js[Data_t][0][BaseStatusInfo_t] = json(data[0]); js[Data_t][0][DOMStatusInfo_t] = json(data[1]); } { js[Data_t][0][DetID_t] = json(detector.getID()); js[Error_t] = json(error); } store(setWildCard(outputFile.c_str(), SCAL), js); } return 0; }