#include #include #include #include #include #include #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JDetectorSupportkit.hh" #include "JDetector/JDetectorParameters.hh" #include "JDetector/JAnchor.hh" #include "JSupport/JMeta.hh" #include "Jeep/JeepToolkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { static const char* const ARCA_t = "ARCA"; // KM3NeT/ARCA detector static const char* const ORCA_t = "ORCA"; // KM3NeT/ORCA detector static const char* const Antares_t = "Antares"; // Antares detector } /** * \file * * Auxiliary program to generate detector files. * * The footprint of the detector can be provided through an input file (option -f). * * When no input file for the footprint is specified, * the footprint is according the so-called WPD reference detector which is subsequently scaled * according the specified line distance (JDETECTOR::JDetectorParameters::lineDistance_m).\n * The specified number of lines (JDETECTOR::JDetectorParameters::numberOfLines) is then selected from * this footprint according the specified detector type (JDETECTOR::JDetectorParameters::detectorType).\n * The list of options includes: * 1. remove outer positions (massive); * 2. remove inner positions (hollow); * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; string inputFile; string outputFile; int detectorID; string variant; JDetectorParameters parameters; double Zmin_m; string option; int debug; // default values parameters.detectorType = 1; // parameters.floorDistance_m = 0.0; // [m] parameters.numberOfFloors = 18; // parameters.lineDistance_m = 0.0; // [m] parameters.numberOfLines = 0; // try { JParser<> zap("Auxiliary program to generate detector files."); JDetectorParametersHelper helper(parameters); zap['f'] = make_field(inputFile, "anchor positions") = ""; zap['o'] = make_field(outputFile, "detector file"); zap['D'] = make_field(detectorID, "detector identifier"); zap['V'] = make_field(variant, "detector version") = getDetectorVersions(); zap['@'] = make_field(helper, "detector parameters") = JPARSER::initialised(); zap['z'] = make_field(Zmin_m, "distance from seabed [m]") = 100.; zap['O'] = make_field(option, "detector type") = ARCA_t, ORCA_t, Antares_t; zap['d'] = make_field(debug) = 0; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } JDetectorHeader header; if (option == ARCA_t) header = getARCADetectorHeader(); else if (option == ORCA_t) header = getORCADetectorHeader(); else if (option == Antares_t) ; else FATAL("Invalid option " << option << endl); JDetector detector(detectorID, variant, header); if (!hasDetectorAddressMap(detector.getID())) { FATAL("No detector address map for detector identifier " << detector.getID() << endl); } detector.comment.add(JMeta(argc,argv)); const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID()); deque footprint; if (inputFile != "") { const string file_name = getFullFilename(LD_LIBRARY_PATH, inputFile); NOTICE("Reading file " << file_name << ".. " << flush); ifstream in(file_name.c_str()); if (in) { for (JAnchor anchor; in >> anchor && footprint.size() < parameters.numberOfLines; ) { footprint.push_back(anchor); } in.close(); NOTICE("OK" << endl); } else { FATAL("Error opening file " << inputFile); } } else { // WPD footprint footprint.push_back(JAnchor( 1, 6, -7)); footprint.push_back(JAnchor( 2, 188, 9)); footprint.push_back(JAnchor( 3, 131, 153)); footprint.push_back(JAnchor( 4, -85, 120)); footprint.push_back(JAnchor( 5, -175, 39)); footprint.push_back(JAnchor( 6, -64, -181)); footprint.push_back(JAnchor( 7, 90, -178)); footprint.push_back(JAnchor( 8, 368, 20)); footprint.push_back(JAnchor( 9, 251, 159)); footprint.push_back(JAnchor( 10, 264, -146)); footprint.push_back(JAnchor( 11, 189, 293)); footprint.push_back(JAnchor( 12, 12, 309)); footprint.push_back(JAnchor( 13, -176, 338)); footprint.push_back(JAnchor( 14, -266, 149)); footprint.push_back(JAnchor( 15, -336, -1)); footprint.push_back(JAnchor( 16, -248, -174)); footprint.push_back(JAnchor( 17, -196, -348)); footprint.push_back(JAnchor( 18, -18, -350)); footprint.push_back(JAnchor( 19, 211, -339)); footprint.push_back(JAnchor( 20, 541, -12)); footprint.push_back(JAnchor( 21, 442, 183)); footprint.push_back(JAnchor( 22, 422, -125)); footprint.push_back(JAnchor( 23, 364, 287)); footprint.push_back(JAnchor( 24, 342, -323)); footprint.push_back(JAnchor( 25, 297, 499)); footprint.push_back(JAnchor( 26, 51, 452)); footprint.push_back(JAnchor( 27, -78, 488)); footprint.push_back(JAnchor( 28, -281, 508)); footprint.push_back(JAnchor( 29, -325, 304)); footprint.push_back(JAnchor( 30, -455, 128)); footprint.push_back(JAnchor( 31, -541, 15)); footprint.push_back(JAnchor( 32, -429, -142)); footprint.push_back(JAnchor( 33, -327, -316)); footprint.push_back(JAnchor( 34, -255, -488)); footprint.push_back(JAnchor( 35, -103, -508)); footprint.push_back(JAnchor( 36, 74, -469)); footprint.push_back(JAnchor( 37, 289, -452)); footprint.push_back(JAnchor( 38, 715, 0)); footprint.push_back(JAnchor( 39, 653, 154)); footprint.push_back(JAnchor( 40, 614, -141)); footprint.push_back(JAnchor( 41, 530, 269)); footprint.push_back(JAnchor( 42, 512, -323)); footprint.push_back(JAnchor( 43, 473, 472)); footprint.push_back(JAnchor( 44, 458, -473)); footprint.push_back(JAnchor( 45, 395, 632)); footprint.push_back(JAnchor( 46, 205, 630)); footprint.push_back(JAnchor( 47, 1, 667)); footprint.push_back(JAnchor( 48, -160, 644)); footprint.push_back(JAnchor( 49, -352, 639)); footprint.push_back(JAnchor( 50, -413, 460)); footprint.push_back(JAnchor( 51, -564, 286)); footprint.push_back(JAnchor( 52, -636, 125)); footprint.push_back(JAnchor( 53, -717, 23)); footprint.push_back(JAnchor( 54, -605, -139)); footprint.push_back(JAnchor( 55, -518, -279)); footprint.push_back(JAnchor( 56, -482, -448)); footprint.push_back(JAnchor( 57, -379, -595)); footprint.push_back(JAnchor( 58, -211, -619)); footprint.push_back(JAnchor( 59, 8, -652)); footprint.push_back(JAnchor( 60, 214, -619)); footprint.push_back(JAnchor( 61, 395, -617)); footprint.push_back(JAnchor( 62, 886, -12)); footprint.push_back(JAnchor( 63, 802, 155)); footprint.push_back(JAnchor( 64, 844, -128)); footprint.push_back(JAnchor( 65, 697, 285)); footprint.push_back(JAnchor( 66, 731, -275)); footprint.push_back(JAnchor( 67, 621, 450)); footprint.push_back(JAnchor( 68, 600, -497)); footprint.push_back(JAnchor( 69, 568, 593)); footprint.push_back(JAnchor( 70, 517, -586)); footprint.push_back(JAnchor( 71, 430, 776)); footprint.push_back(JAnchor( 72, 240, 758)); footprint.push_back(JAnchor( 73, 70, 783)); footprint.push_back(JAnchor( 74, -75, 803)); footprint.push_back(JAnchor( 75, -252, 809)); footprint.push_back(JAnchor( 76, -478, 771)); footprint.push_back(JAnchor( 77, -510, 590)); footprint.push_back(JAnchor( 78, -643, 468)); footprint.push_back(JAnchor( 79, -741, 284)); footprint.push_back(JAnchor( 80, -845, 175)); footprint.push_back(JAnchor( 81, -907, -6)); footprint.push_back(JAnchor( 82, -792, -142)); footprint.push_back(JAnchor( 83, -737, -340)); footprint.push_back(JAnchor( 84, -639, -492)); footprint.push_back(JAnchor( 85, -518, -596)); footprint.push_back(JAnchor( 86, -455, -751)); footprint.push_back(JAnchor( 87, -260, -814)); footprint.push_back(JAnchor( 88, -103, -819)); footprint.push_back(JAnchor( 89, 106, -764)); footprint.push_back(JAnchor( 90, 274, -754)); footprint.push_back(JAnchor( 91, 417, -762)); footprint.push_back(JAnchor( 92, 1094, -4)); footprint.push_back(JAnchor( 93, 1010, 120)); footprint.push_back(JAnchor( 94, 992, -171)); footprint.push_back(JAnchor( 95, 898, 324)); footprint.push_back(JAnchor( 96, 901, -298)); footprint.push_back(JAnchor( 97, 768, 471)); footprint.push_back(JAnchor( 98, 818, -477)); footprint.push_back(JAnchor( 99, 731, 632)); footprint.push_back(JAnchor(100, 713, -633)); footprint.push_back(JAnchor(101, 625, 772)); footprint.push_back(JAnchor(102, 661, -759)); footprint.push_back(JAnchor(103, 530, 949)); footprint.push_back(JAnchor(104, 345, 960)); footprint.push_back(JAnchor(105, 221, 931)); footprint.push_back(JAnchor(106, -29, 962)); footprint.push_back(JAnchor(107, -155, 967)); footprint.push_back(JAnchor(108, -382, 917)); footprint.push_back(JAnchor(109, -545, 965)); footprint.push_back(JAnchor(110, -634, 779)); footprint.push_back(JAnchor(111, -731, 600)); footprint.push_back(JAnchor(112, -852, 471)); footprint.push_back(JAnchor(113, -903, 322)); footprint.push_back(JAnchor(114, -976, 166)); footprint.push_back(JAnchor(115, -1100, 11)); footprint.push_back(JAnchor(116, -1006, -131)); footprint.push_back(JAnchor(117, -867, -332)); footprint.push_back(JAnchor(118, -800, -504)); footprint.push_back(JAnchor(119, -706, -593)); footprint.push_back(JAnchor(120, -604, -800)); footprint.push_back(JAnchor(121, -503, -933)); footprint.push_back(JAnchor(122, -318, -927)); footprint.push_back(JAnchor(123, -177, -926)); footprint.push_back(JAnchor(124, -10, -894)); footprint.push_back(JAnchor(125, 155, -919)); footprint.push_back(JAnchor(126, 381, -967)); footprint.push_back(JAnchor(127, 531, -900)); footprint.push_back(JAnchor(128, 1091, 311)); footprint.push_back(JAnchor(129, 1061, -285)); footprint.push_back(JAnchor(130, 966, 481)); footprint.push_back(JAnchor(131, 958, -457)); footprint.push_back(JAnchor(132, 905, 658)); footprint.push_back(JAnchor(133, 863, -630)); footprint.push_back(JAnchor(134, 788, 742)); footprint.push_back(JAnchor(135, 686, 911)); footprint.push_back(JAnchor(136, 277, 1113)); footprint.push_back(JAnchor(137, 92, 1094)); footprint.push_back(JAnchor(138, -84, 1127)); footprint.push_back(JAnchor(139, -302, 1062)); footprint.push_back(JAnchor(140, -732, 892)); footprint.push_back(JAnchor(141, -793, 761)); footprint.push_back(JAnchor(142, -901, 661)); footprint.push_back(JAnchor(143, -1012, 456)); footprint.push_back(JAnchor(144, -1101, 280)); footprint.push_back(JAnchor(145, -1077, -326)); footprint.push_back(JAnchor(146, -973, -457)); footprint.push_back(JAnchor(147, -883, -602)); footprint.push_back(JAnchor(148, -822, -771)); footprint.push_back(JAnchor(149, -689, -910)); footprint.push_back(JAnchor(150, -457, -1066)); footprint.push_back(JAnchor(151, -268, -1067)); footprint.push_back(JAnchor(152, -58, -1080)); footprint.push_back(JAnchor(153, 72, -1100)); footprint.push_back(JAnchor(154, 280, -1081)); // scale positions to specified distance for (deque::iterator i = footprint.begin(); i != footprint.end(); ++i) { i->mul(parameters.lineDistance_m * 0.5 / 90.0); } if (parameters.numberOfLines > footprint.size()) { FATAL("Available footprint inconsistent with specified number of lines " << parameters.numberOfLines << " > " << footprint.size() << endl); } // select specified number of lines sort(footprint.begin(), footprint.end()); if (parameters.detectorType == 2) { // hollow detector while (parameters.numberOfLines < footprint.size()) { footprint.pop_front(); } } else { // massive detector while (parameters.numberOfLines < footprint.size()) { footprint.pop_back(); } } // reset object identifiers for (deque::iterator i = footprint.begin(); i != footprint.end(); ++i) { static_cast(*i) = JObjectID(distance(footprint.begin(),i) + 1); } } for (deque::iterator i = footprint.begin(); i != footprint.end(); ++i) { DEBUG(i->getID() << ' ' << i->getX() << ' ' << i->getY() << endl); } // build detector int PMT = 1; for (deque::const_iterator anchor = footprint.begin(); anchor != footprint.end(); ++anchor) { { const JVector3D position(anchor->getX(), anchor->getY(), option == ARCA_t ? ARCA_TBARZ_M : option == ORCA_t ? ORCA_TBARZ_M : 0.0); const JLocation location(anchor->getID(), 0); const int id = demo.getModuleID(location); JModule module(id, location); module.set(position); module.compile(); detector.push_back(module); } for (unsigned int floor = 1; floor <= parameters.numberOfFloors; ++floor) { const JVector3D position(anchor->getX(), anchor->getY(), Zmin_m + (floor - 1) * parameters.floorDistance_m); const JLocation location(anchor->getID(), floor); const int id = demo.getModuleID(location); JModule module; if (option == ARCA_t || option == ORCA_t) module = getModule (id, location); else if (option == Antares_t) module = getModule(id, location); else FATAL("Invalid option " << option << endl); module.add(position); for (JModule::iterator pmt = module.begin(); pmt != module.end(); ++pmt, ++PMT) { pmt->setID(PMT++); //pmt->setCalibration(JCalibration((R + position.getZ())/C)); } detector.push_back(module); } } // Store detector. try { store(outputFile, detector); } catch(const JException& error) { FATAL(error); } return 0; }