#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TH1D.h" #include "TH2D.h" #include "TRandom3.h" #include "km3net-dataformat/online/JDAQ.hh" #include "km3net-dataformat/online/JDAQClock.hh" #include "km3net-dataformat/online/JDAQTimeslice.hh" #include "JTimeslice/JRandomTimeslice.hh" #include "JROOT/JManager.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Example program to test generation of KM3NETDAQ::JDAQTimeslice with random data. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; string outputFile; Long64_t numberOfSlices; double rate_Hz; pair recycling; UInt_t seed; int debug; try { JParser<> zap("Example program to test generation of time slices with random data."); zap['o'] = make_field(outputFile, "output file") = "timeslice.root"; zap['n'] = make_field(numberOfSlices); zap['B'] = make_field(rate_Hz, "background rate [Hz]"); zap['N'] = make_field(recycling, "number of recycles / time interval for sampling data") = make_pair(0, 0.0); zap['S'] = make_field(seed, "seed") = 0; zap['d'] = make_field(debug, "debug") = 0; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } gRandom->SetSeed(seed); const JDAQHit::JPMT_t PMT_L0[] = { 0, 1 }; JManager H0(new TH1D("h0[%]", NULL, 100, 0.0, getFrameTime())); for (Long64_t counter = 0; counter != numberOfSlices; ++counter) { STATUS("slice: " << setw(10) << counter << '\r'); DEBUG(endl); JRandomTimeslice timeslice; timeslice.resize(1); vector buffer; if (rate_Hz > 0.0) { double period_ns = 1.0e9 / (NUMBER_OF_PMTS * rate_Hz); for (double t1 = 0.0 * getFrameTime() + gRandom->Exp(period_ns); t1 < 0.5 * getFrameTime(); t1 += gRandom->Exp(period_ns)) { buffer.push_back(JDAQHit(PMT_L0[0], t1, 0)); } period_ns *= 2.0; for (double t1 = 0.5 * getFrameTime() + gRandom->Exp(period_ns); t1 < 1.0 * getFrameTime(); t1 += gRandom->Exp(period_ns)) { buffer.push_back(JDAQHit(PMT_L0[1], t1, 0)); } } timeslice[0].add(buffer.size(), buffer.data()); TH1D* h0 = H0[0]; for (JDAQSuperFrame::const_iterator hit = timeslice[0].begin(); hit != timeslice[0].end(); ++hit) { h0->Fill((Double_t) hit->getT()); } for (size_t i = 1; i <= recycling.first; ++i) { timeslice.recycle(recycling.second); TH1D* h0 = H0[i]; for (JDAQSuperFrame::const_iterator hit = timeslice[0].begin(); hit != timeslice[0].end(); ++hit) { h0->Fill((Double_t) hit->getT()); } } } STATUS(endl); TFile out(outputFile.c_str(), "recreate"); out << H0; out.Write(); out.Close(); }