#include #include #include #include "TRandom3.h" #include "km3net-dataformat/online/JDAQTimeslice.hh" #include "km3net-dataformat/online/JDAQSummaryslice.hh" #include "JTimeslice/JRandomTimeslice.hh" #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JDetectorSupportkit.hh" #include "JDetector/JDetectorSimulator.hh" #include "JDetector/JPMTParametersMap.hh" #include "JDetector/JK40DefaultSimulator.hh" #include "JDetector/JPMTDefaultSimulator.hh" #include "JDetector/JCLBDefaultSimulator.hh" #include "JDAQ/JHighRateVeto.hh" #include "JTrigger/JSuperFrame2D.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using namespace JPP; /** * Auxiliary class to generate background for specific PMT. */ class JK40Simulator_t : public JK40DefaultSimulatorInterface { public: /** * Constructor. * * \param pmt PMT * \param R_Hz rate [Hz] */ JK40Simulator_t(const int pmt, const double R_Hz) : pmt (pmt), R_Hz(R_Hz) {} /** * Get singles rate as a function of PMT. * * \param pmt PMT identifier * \return rate [Hz] */ virtual double getSinglesRate(const JPMTIdentifier& pmt) const { if (pmt.getPMTAddress() == this->pmt) return R_Hz; else return 0.0; } /** * Get multiples rate as a function of optical module. * * \param module optical module identifier * \param M multiplicity (M >= 2) * \return rate [Hz] */ virtual double getMultiplesRate(const JModuleIdentifier& module, const int M) const { return 0.0; } /** * Get probability of coincidence. * * \param ct cosine space angle between PMT axes * \return probability */ virtual double getProbability(const double ct) const { return 0.0; } int pmt; double R_Hz; }; } /** * \file * Test program for JHighRateVeto.hh. * * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; UInt_t seed; int debug; try { JParser<> zap("Test program for JHighRateVeto.hh."); zap['S'] = make_field(seed) = 0; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } gRandom->SetSeed(seed); JDetector detector; detector.setVersion(JDetectorVersion::V3); detector.push_back(getModule(1001)); JDetectorSimulator simbad(detector); JPMTParametersMap pmtParameters; DEBUG(detector); const double R_Hz = 2 * HIGH_RATE_VETO_HZ; const double sigma_Hz = R_Hz / sqrt((double) getMaximalNumberOfHits()); for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) { DEBUG("Test setting rate of PMT " << setw(2) << pmt << " " << FIXED(7,1) << R_Hz << " [Hz]" << endl); try { simbad.reset(new JK40Simulator_t(pmt, R_Hz)); simbad.reset(new JPMTDefaultSimulator(pmtParameters, detector)); simbad.reset(new JCLBDefaultSimulator()); } catch(const JException& error) { FATAL(error.what() << endl); } const JRandomTimeslice timeslice(JDAQChronometer(), simbad); for (JDAQTimeslice::const_iterator frame = timeslice.begin(); frame != timeslice.end(); ++frame) { typedef vector buffer1D_type; typedef vector buffer2D_type; buffer2D_type buffer(NUMBER_OF_PMTS, buffer1D_type()); for (JDAQFrame::const_iterator hit = frame->begin(); hit != frame->end(); ++hit) { buffer[hit->getPMT()].push_back(*hit); } for (int i = 0; i != NUMBER_OF_PMTS; ++i) { DEBUG("PMT " << setw(2) << i << ' ' << setw(4) << buffer[i].size() << ' ' << frame->testHighRateVeto(i) << endl); if (!frame->empty()) { DEBUG(setw(9) << frame->rbegin()->getT() << endl); } ASSERT(buffer[i].size() == (i == pmt ? getMaximalNumberOfHits() : 0u)); ASSERT(frame->testHighRateVeto(i) == (i == pmt ? true : false)); } } // process data typedef JSuperFrame2D JSuperFrame2D_t; for (JDAQTimeslice::const_iterator frame = timeslice.begin(); frame != timeslice.end(); ++frame) { JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame, detector[0]); ASSERT(buffer[pmt].empty(), "Processed data PMT (enable use of high-rate veto) " << setw(2) << pmt); } // disable use of high-rate veto detector[0].getPMT(pmt).getStatus().set(HIGH_RATE_VETO_DISABLE); for (JDAQTimeslice::const_iterator frame = timeslice.begin(); frame != timeslice.end(); ++frame) { JSuperFrame2D_t& buffer = JSuperFrame2D_t::demultiplex(*frame, detector[0]); ASSERT(!buffer[pmt].empty(), "Processed data PMT (disable use of high-rate veto) " << setw(2) << pmt); } detector[0].getPMT(pmt).getStatus().reset(HIGH_RATE_VETO_DISABLE); const JDAQSummaryslice summary(timeslice); for (JDAQSummaryslice::const_iterator frame = summary.begin(); frame != summary.end(); ++frame) { for (int i = 0; i != NUMBER_OF_PMTS; ++i) { DEBUG("PMT " << setw(2) << i << ' ' << SCIENTIFIC(7,1) << frame->getRate(i) << ' ' << frame->testHighRateVeto(i) << endl); ASSERT(frame->testHighRateVeto(i) == (i == pmt ? true : false)); if (i == pmt) ASSERT(frame->getRate(i) >= R_Hz - 5.0 * sigma_Hz && frame->getRate(i) <= R_Hz + 5.0 * sigma_Hz); else ASSERT(frame->getRate(i) == 0.0); } } } return 0; }