#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/offline/Evt.hh" #include "km3net-dataformat/offline/io_online.hh" #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JModuleRouter.hh" #include "JAAnet/JHead.hh" #include "JAAnet/JHeadToolkit.hh" #include "JDAQ/JDAQEventIO.hh" #include "JDAQ/JDAQSummarysliceIO.hh" #include "JSupport/JSingleFileScanner.hh" #include "JSupport/JTreeScanner.hh" #include "JSupport/JFileRecorder.hh" #include "JSupport/JMonteCarloFileSupportkit.hh" #include "JSupport/JSupportToolkit.hh" #include "JSupport/JSupport.hh" #include "JSupport/JMeta.hh" #include "Jeep/JeepToolkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \author mdejong */ /** * Auxiliary program to convert data to Dusj format. */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; JSingleFileScanner inputFile; JFileRecorder::typelist> outputFile; JLimit_t& numberOfEvents = inputFile.getLimit(); string detectorFile; int debug; try { JParser<> zap("Auxiliary program to convert data to Dusj format."); zap['f'] = make_field(inputFile); zap['o'] = make_field(outputFile) = "dusj.evt"; zap['a'] = make_field(detectorFile); zap['n'] = make_field(numberOfEvents) = JLimit::max(); zap['d'] = make_field(debug) = 2; zap(argc, argv); } catch(const exception& error) { FATAL(error.what() << endl); } JDetector detector; try { load(detectorFile, detector); } catch(const JException& error) { FATAL(error); } const JModuleRouter router(detector); outputFile.open(); Vec offset(0,0,0); int mc_run_id = 0; Head header; try { header = getHeader(inputFile); JHead buffer(header); offset = getOffset(buffer); mc_run_id = buffer.start_run.run_id; } catch(const exception& error) { JHead buffer(header); buffer.start_run.run_id = getRunNumber(inputFile); buffer.push(&JHead::start_run); copy(buffer, header); } { JHead buffer(header); buffer.DAQ.livetime_s = getLivetime(inputFile); buffer.push(&JHead::DAQ); copy(buffer, header); } outputFile.put(header); outputFile.put(JMeta(argc, argv)); for (JTreeScanner mc(inputFile); inputFile.hasNext(); ) { STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl); JDAQEvent* tev = inputFile.next(); Evt out; if (mc.getEntries() != 0) { Evt* event = mc.getEntry(tev->getCounter()); if (event != NULL) { out = *event; if (out.mc_run_id == 0) { out.mc_run_id = mc_run_id; } for (vector::iterator i = out.mc_trks.begin(); i != out.mc_trks.end(); ++i) { i->pos += offset; } } } else { out.mc_id = inputFile.getCounter(); out.mc_run_id = tev->getRunNumber(); } read(out, *tev); out.hits.clear(); for (JDAQEvent::const_iterator i = tev->begin(); i != tev->end(); ++i) { const JModule& module = router.getModule(i->getModuleID()); const JPMT& pmt = module.getPMT (i->getPMT()); Hit hit; hit.id = out.hits.size() + 1; hit.dom_id = i->getModuleID(); //hit.channel_id = i->getPMT(); //hit.tdc = i->getT(); //hit.tot = i->getToT(); hit.pmt_id = pmt.getID(); hit.t = i->getT(); // getTime(i->getT(), pmt.getCalibration()); hit.a = i->getToT(); // getToT (i->getToT(), pmt.getCalibration()); //hit.pos = Vec(pmt.getX(), pmt.getY(), pmt.getZ()); //hit.dir = Vec(pmt.getDX(), pmt.getDY(), pmt.getDZ()); out.hits.push_back(hit); } // time offset double t0 = numeric_limits::max(); for (vector::const_iterator i = out.hits.begin(); i != out.hits.end(); ++i) { if (t0 > i->t) { t0 = i->t; } } for (vector::iterator i = out.hits.begin(); i != out.hits.end(); ++i) { i->t -= t0; } if (out.mc_t > 0.0 && t0 != numeric_limits::max()) { out.mc_t -= t0; } out.id = inputFile.getCounter(); outputFile.put(out); } STATUS(endl); /* JSingleFileScanner::typelist> io(inputFile); io >> outputFile; */ outputFile.close(); }