#include #include #include #include #include #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JDetectorAddressMap.hh" #include "JDetector/JDetectorSupportkit.hh" #include "JDetector/JModule.hh" #include "JMath/JConstants.hh" #include "JTools/JRange.hh" #include "JSystem/JDateAndTime.hh" #include "JGeometry3D/JGeometry3DToolkit.hh" #include "JGeometry3D/JCylinder3D.hh" #include "JGeometry3D/JQuaternion3D.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { /** * Print options. */ const char* const default_t = "default"; //!< as-is const char* const modules_t = "modules"; //!< modules const char* const pmts_t = "pmts"; //!< PMTs const char* const geometry_t = "geometry"; //!< geometry const char* const comment_t = "comment"; //!< comment const char* const header_t = "header"; //!< header const char* const identifier_t = "identifier"; //!< identifier const char* const version_t = "version"; //!< version const char* const can_t = "can"; //!< can const char* const center_t = "center"; //!< center const char* const summary_t = "summary"; //!< summary const char* const HEADER_t = "HEADER"; //!< header in zsh format const char* const IDENTIFIER_t = "IDENTIFIER"; //!< identifier in zsh format const char* const VERSION_t = "VERSION"; //!< version in zsh format const char* const CAN_t = "CAN"; //!< can in zsh format const char* const CENTER_t = "CENTER"; //!< center in zsh format const char* const SUMMARY_t = "SUMMARY"; //!< summary in zsh format } /** * \file * * Auxiliary program to print detector file in human friendly format. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; string detectorFile; string option; double precision; int debug; try { JParser<> zap("Auxiliary program to print detector file in human friendly format."); zap['a'] = make_field(detectorFile); zap['O'] = make_field(option) = default_t, pmts_t, modules_t, geometry_t, comment_t, header_t, version_t, identifier_t, can_t, center_t, summary_t, HEADER_t, VERSION_t, IDENTIFIER_t, CAN_t, CENTER_t, SUMMARY_t; zap['p'] = make_field(precision, "precision for match with reference module") = 1.0e-5; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } JDetector detector; try { load(detectorFile, detector); } catch(const JException& error) { FATAL(error); } if (option == default_t) { cout << detector << endl; } else if (option == modules_t) { const JDetectorBuilder& demo = getDetectorBuilder(detector.getID()); for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { cout << "Module"; cout << ' ' << noshowpos << setw(8) << right << module->getID(); cout << ' ' << noshowpos << setw(3) << right << module->getString(); cout << ' ' << noshowpos << setw(2) << right << module->getFloor(); cout << ' ' << FIXED(7,2) << module->getX(); cout << ' ' << FIXED(7,2) << module->getY(); cout << ' ' << FIXED(7,2) << module->getZ(); cout << ' ' << FIXED(8,2) << module->getT0(); if (module->getFloor() != 0) { { JModule buffer = demo.getModule(module->getID(), module->getLocation()); const JQuaternion3D Q = getRotation(buffer, *module); const JQuaternion3D::decomposition q1(Q, JVector3Z_t); const double phi = (JVector3Z_t.getDot(q1.twist) >= 0.0 ? +1.0 : -1.0) * q1.twist.getAngle(); cout << ' ' << FIXED(7,2) << phi; } { const JQuaternion3D Q = module->getQuaternion(); const JQuaternion3D::decomposition q1(Q, JVector3Z_t); const double phi = (JVector3Z_t.getDot(q1.twist) >= 0.0 ? +1.0 : -1.0) * q1.twist.getAngle(); cout << ' ' << FIXED(7,2) << phi; } { JModule buffer = demo.getModule(module->getID(), module->getLocation()); const JRotation3D R = getRotation(buffer, *module); buffer.rotate(R); cout << ' ' << (JModule::compare(buffer, *module, precision) ? "==" : "!=") << ' ' << (demo.get(module->getID()) == demo.getDefaultModuleAddressMap() ? "default" : "custom"); } } cout << endl; } } else if (option == pmts_t) { for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) { cout << "PMT"; cout << ' ' << noshowpos << setw(8) << right << pmt->getID(); cout << ' ' << FIXED(7,2) << pmt->getX(); cout << ' ' << FIXED(7,2) << pmt->getY(); cout << ' ' << FIXED(7,2) << pmt->getZ(); cout << ' ' << FIXED(6,3) << pmt->getDX(); cout << ' ' << FIXED(6,3) << pmt->getDY(); cout << ' ' << FIXED(6,3) << pmt->getDZ(); cout << ' ' << FIXED(8,2) << pmt->getT0(); cout << ' ' << noshowpos << setw(8) << right << pmt->getStatus(); cout << endl; } } } else if (option == geometry_t) { cout << "Maximal distance [m] = " << FIXED(6,1) << getMaximalDistance(detector) << endl; cout << "Maximal time [ns] = " << FIXED(6,1) << getMaximalTime (detector) << endl; } else if (option == comment_t) { cout << detector.comment << endl; } else if (option == header_t || option == HEADER_t) { if (option == header_t) { cout << detector.getProperties() << endl; cout << "name = " << (isARCADetector(detector) ? "ARCA" : isORCADetector(detector) ? "ORCA" : "unknown") << endl; cout << "validity = " << JDateAndTime(detector.getLowerLimit(), true).toString() << ' ' << JDateAndTime(detector.getUpperLimit(), true).toString() << endl; } else { cout << "set_variable UTM_EAST " << FIXED(12,2) << detector.getUTMEast() << ";" << endl; cout << "set_variable UTM_NORTH " << FIXED(12,2) << detector.getUTMNorth() << ";" << endl; cout << "set_variable UTM_Z " << FIXED(12,2) << detector.getUTMZ() << ";" << endl; cout << "set_variable UTM_ZONE " << FIXED(12,2) << detector.getUTMZone() << ";" << endl; cout << "set_variable UTM_WGS " << FIXED(12,2) << detector.getWGS() << ";" << endl; } } else if (option == version_t || option == VERSION_t) { if (option == version_t) { cout << detector.getVersion() << endl; } else { cout << "set_variable DETECTOR_VERSION " << detector.getVersion() << ";" << endl; } } else if (option == identifier_t || option == IDENTIFIER_t) { if (option == identifier_t) { cout << "Detector " << detector.getID() << endl; } else { cout << "set_variable DETECTOR_ID " << detector.getID() << ";" << endl; } } else if (option == can_t || option == CAN_t) { const JCylinder3D cylinder(detector.begin(), detector.end()); const double V = (cylinder.getZmax() - cylinder.getZmin()) * PI * cylinder.getRadius() * cylinder.getRadius(); const double D = getMaximalDistance(detector); if (option == can_t) { cout << "X = " << FIXED(7,1) << cylinder.getX() << endl; cout << "Y = " << FIXED(7,1) << cylinder.getY() << endl; cout << "Zmin = " << FIXED(7,1) << cylinder.getZmin() << endl; cout << "Zmax = " << FIXED(7,1) << cylinder.getZmax() << endl; cout << "Radius = " << FIXED(7,1) << cylinder.getRadius() << endl; cout << "Depth = " << FIXED(7,1) << detector.getUTMZ() << endl; cout << "Volume = " << SCIENTIFIC(12,3) << V << endl; cout << "Distance = " << FIXED(9,3) << D << endl; } else { cout << "set_variable CAN_X_M " << FIXED(7,1) << cylinder.getX() << ";" << endl; cout << "set_variable CAN_Y_M " << FIXED(7,1) << cylinder.getY() << ";" << endl; cout << "set_variable CAN_ZMIN_M " << FIXED(7,1) << cylinder.getZmin() << ";" << endl; cout << "set_variable CAN_ZMAX_M " << FIXED(7,1) << cylinder.getZmax() << ";" << endl; cout << "set_variable CAN_RADIUS_M " << FIXED(7,1) << cylinder.getRadius() << ";" << endl; cout << "set_variable CAN_DEPTH_M " << FIXED(7,1) << detector.getUTMZ() << ";" << endl; cout << "set_variable CAN_VOLUME_M3 " << SCIENTIFIC(12,3) << V << ";" << endl; cout << "set_variable CAN_DISTANCE_M " << FIXED(9,3) << D << ";" << endl; } } else if (option == center_t || option == CENTER_t) { const JCenter3D center(detector.begin(), detector.end()); if (option == center_t) { cout << "center = "; cout << showpos << FIXED(8,3) << center.getX() << ' '; cout << showpos << FIXED(8,3) << center.getY() << ' '; cout << showpos << FIXED(8,3) << center.getZ() << endl; } else { cout << "set_variable CENTER_X_M " << FIXED(7,1) << center.getX() << ";" << endl; cout << "set_variable CENTER_Y_M " << FIXED(7,1) << center.getY() << ";" << endl; cout << "set_variable CENTER_Z_M " << FIXED(7,1) << center.getZ() << ";" << endl; } } else if (option == summary_t || option == SUMMARY_t) { const int numberOfStrings = getNumberOfStrings(detector); const int numberOfFloors = getNumberOfFloors (detector); const int numberOfModules = getNumberOfModules(detector); const int numberOfPMTs = getNumberOfPMTs (detector); typedef JTOOLS::JRange JRange_t; const JRange_t string(make_array(detector.begin(), detector.end(), &JModule::getString)); const JRange_t floor (make_array(detector.begin(), detector.end(), &JModule::getFloor)); set strings; set modules; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { strings.insert(module->getString()); modules.insert(module->getID()); } if (option == summary_t) { cout << "Number of strings = " << setw(4) << numberOfStrings << endl; cout << "Number of floors = " << setw(4) << numberOfFloors << endl; cout << "Number of modules = " << setw(4) << numberOfModules << endl; cout << "Number of PMTs = " << setw(4) << numberOfPMTs << endl; cout << "First string = " << setw(4) << string.first << endl; cout << "Last string = " << setw(4) << string.second << endl; cout << "First floor = " << setw(4) << floor .first << endl; cout << "Last floor = " << setw(4) << floor .second << endl; } else { cout << "set_variable NUMBER_OF_STRINGS " << setw(4) << numberOfStrings << ";" << endl; cout << "set_variable NUMBER_OF_FLOORS " << setw(4) << numberOfFloors << ";" << endl; cout << "set_variable NUMBER_OF_MODULES " << setw(4) << numberOfModules << ";" << endl; cout << "set_variable NUMBER_OF_PMTS " << setw(4) << numberOfPMTs << ";" << endl; cout << "set_variable FIRST_STRING " << setw(4) << string.first << ";" << endl; cout << "set_variable LAST_STRING " << setw(4) << string.second << ";" << endl; cout << "set_variable FIRST_FLOOR " << setw(4) << floor .first << ";" << endl; cout << "set_variable LAST_FLOOR " << setw(4) << floor .second << ";" << endl; cout << "set_array STRINGS "; copy(strings.begin(), strings.end(), ostream_iterator(cout, " ")); cout << ";" << endl; cout << "set_array MODULES "; copy(modules.begin(), modules.end(), ostream_iterator(cout, " ")); cout << ";" << endl; } } }