#ifndef __JTIMESLICE__JEVENTTIMESLICE__ #define __JTIMESLICE__JEVENTTIMESLICE__ #include #include #include "km3net-dataformat/offline/Evt.hh" #include "km3net-dataformat/online/JDAQ.hh" #include "km3net-dataformat/online/JDAQChronometer.hh" #include "km3net-dataformat/definitions/pmt_status.hh" #include "km3net-dataformat/definitions/module_status.hh" #include "km3net-dataformat/tools/time_converter.hh" #include "JAAnet/JAAnetToolkit.hh" #include "JDetector/JDetectorSimulator.hh" #include "JDetector/JPMTDefaultSimulatorInterface.hh" #include "JDetector/JPMTAddress.hh" #include "JDetector/JTimeRange.hh" #include "JTimeslice/JTimesliceL0.hh" /** * \author mdejong */ namespace KM3NETDAQ { using JDETECTOR::JDetectorSimulator; using JDETECTOR::JTimeRange; /** * Timeslice with Monte Carlo event. */ struct JEventTimeslice : public JTimesliceL0 { /** * Constructor. * * This constructor converts the Monte Carlo event to a DAQ timeslice. * In this, both the PMT and CLB simulations are applied. * If the K40 simulator is available and the given time window is valid, * the K40 background is generated and added to the time slice data. * N.B. The given time window extends the time range of hits in the event, if any. * * * \param chronometer chronometer * \param simbad detector simulator * \param event Monte Carlo event * \param period time window [ns] */ JEventTimeslice(const JDAQChronometer& chronometer, const JDetectorSimulator& simbad, const Evt& event, const JTimeRange& period = JTimeRange::DEFAULT_RANGE()) { using namespace std; using namespace JPP; setDAQChronometer(chronometer); if (simbad.hasPMTSimulator() && simbad.hasCLBSimulator()) { const time_converter converter(event, chronometer); const JTimeRange timeRange = (period.is_valid() ? getTimeRange(event, period) : getTimeRange(event)); typedef map JMap_t; // map module index to data JMap_t data; for (vector::const_iterator hit = event.mc_hits.begin(); hit != event.mc_hits.end(); ++hit) { if (simbad.hasPMT(hit->pmt_id)) { const JPMTAddress& address = simbad.getAddress(hit->pmt_id); if (!period.is_valid() || timeRange(getTime(*hit))) { if (!simbad.getModule(address).has(MODULE_OUT_OF_SYNC) && !simbad.getPMT (address).has(OUT_OF_SYNC)) { data[address.first].resize(NUMBER_OF_PMTS); data[address.first][address.second].push_back(JPMTSignal(converter.putTime(getTime(*hit)), (int) getNPE(*hit))); } } } } if (simbad.hasK40Simulator() && period.is_valid()) { JTimeRange time_range(JTimeRange::DEFAULT_RANGE()); for (JMap_t::const_iterator i = data.begin(); i != data.end(); ++i) { time_range.combine(getTimeRange(i->second)); } time_range.add(period); JModuleData buffer; for (JDetector::const_iterator module = simbad->begin(); module != simbad->end(); ++module) { if (!module->empty()) { // signal JMap_t::iterator i = data.find(distance(simbad->begin(),module)); if (i != data.end()) buffer.swap(i->second); else buffer.reset(module->size()); // background simbad.generateHits(*module, time_range, buffer); this->push_back(JDAQSuperFrame(JDAQSuperFrameHeader(chronometer, module->getID()))); simbad(*module, buffer, *(this->rbegin())); } } } else { for (JMap_t::iterator i = data.begin(); i != data.end(); ++i) { const JModule& module = simbad.getModule(JModuleAddress(i->first)); this->push_back(JDAQSuperFrame(JDAQSuperFrameHeader(chronometer, module.getID()))); simbad(module, i->second, *(this->rbegin())); } } } } }; } #endif