#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TH2D.h" #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/offline/Evt.hh" #include "km3net-dataformat/offline/Hit.hh" #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JPMTRouter.hh" #include "JDetector/JTimeRange.hh" #include "JSupport/JMultipleFileScanner.hh" #include "JSupport/JSupport.hh" #include "Jeep/JTimer.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Example program to determine speed of JDETECTOR::JPMTRouter. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; JMultipleFileScanner inputFile; JLimit_t& numberOfEvents = inputFile.getLimit(); string outputFile; string detectorFile; int debug; try { JParser<> zap("Example program to determine speed of PMT router."); zap['f'] = make_field(inputFile); zap['o'] = make_field(outputFile) = "router.root"; zap['a'] = make_field(detectorFile); zap['n'] = make_field(numberOfEvents) = JLimit::max(); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception& error) { FATAL(error.what() << endl); } cout.tie(&cerr); JDetector detector; try { load(detectorFile, detector); } catch(const JException& error) { FATAL(error); } const JPMTRouter router(detector); typedef map map_t; map_t zmap; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) { zmap[pmt->getID()] = module->getLocation(); } } typedef JTOOLS::JRange JRange_t; JRange_t floor = JRange_t::DEFAULT_RANGE; JRange_t string = JRange_t::DEFAULT_RANGE; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { floor .include(module->getFloor()); string.include(module->getString()); } NOTICE("String " << string.getLowerLimit() << " - " << string.getUpperLimit() << endl); NOTICE("Floor " << floor .getLowerLimit() << " - " << floor .getUpperLimit() << endl); TFile out(outputFile.c_str(), "recreate"); TH2D h1("h1", NULL, string.getLength() + 1, string.getLowerLimit() - 0.5, string.getUpperLimit() + 0.5, floor.getLength() + 1, floor.getLowerLimit() - 0.5, floor.getUpperLimit() + 0.5); TH2D h2("h2", NULL, string.getLength() + 1, string.getLowerLimit() - 0.5, string.getUpperLimit() + 0.5, floor.getLength() + 1, floor.getLowerLimit() - 0.5, floor.getUpperLimit() + 0.5); JTimer t1("map"); JTimer t2("router"); while (inputFile.hasNext()) { STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl); const Evt* event = inputFile.next(); t1.start(); for (vector::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) { const JLocation& pos = zmap[hit->pmt_id]; h1.Fill((double) pos.getString(), (double) pos.getFloor()); } t1.stop(); } STATUS(endl); inputFile.rewind(); while (inputFile.hasNext()) { STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl); const Evt* event = inputFile.next(); t2.start(); for (vector::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) { const JLocation& pos = router.getParentModule(hit->pmt_id); h2.Fill((double) pos.getString(), (double) pos.getFloor()); } t2.stop(); } STATUS(endl); t1.print(cout); t2.print(cout); out.Write(); out.Close(); }