#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TProfile.h" #include "TRandom3.h" #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JDetectorSupportkit.hh" #include "JDetector/JModuleRouter.hh" #include "JDetector/JDetectorSimulator.hh" #include "JDetector/JPMTParametersMap.hh" #include "JDetector/JK40DefaultSimulator.hh" #include "JDetector/JPMTDefaultSimulator.hh" #include "JDetector/JCLBDefaultSimulator.hh" #include "JTrigger/JHit.hh" #include "JTrigger/JFrame.hh" #include "JTrigger/JTimeslice.hh" #include "JTrigger/JSuperFrame2D.hh" #include "JTrigger/JHitL0.hh" #include "JTrigger/JHitL1.hh" #include "JTrigger/JBuildL1.hh" #include "JTrigger/JBuildL2.hh" #include "JTimeslice/JRandomTimeslice.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Example program to test JTRIGGER::JBuildL1 and JTRIGGER::JBuildL2 hit coincidence building with random data. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; typedef JOption JK40DefaultSimulator_t; string outputFile; Long64_t numberOfEvents; JPMTParametersMap pmtParameters; JK40DefaultSimulator_t k40Simulator = JK40DefaultSimulator::getInstance(); UInt_t seed; double Tmax_ns; int debug; try { JParser<> zap("Example program to test hit coincidence building with random data."); zap['o'] = make_field(outputFile) = "randomL2.root"; zap['n'] = make_field(numberOfEvents); zap['P'] = make_field(pmtParameters) = JPARSER::initialised(); zap['B'] = make_field(k40Simulator) = JPARSER::initialised(); zap['S'] = make_field(seed) = 0; zap['T'] = make_field(Tmax_ns) = 20.0; // [ns] zap['d'] = make_field(debug) = 0; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } gRandom->SetSeed(seed); using namespace KM3NETDAQ; JDetector detector; detector.push_back(getModule(1001)); JDetectorSimulator simbad(detector); simbad.reset(new JPMTDefaultSimulator(pmtParameters, detector)); simbad.reset(new JCLBDefaultSimulator()); simbad.reset(k40Simulator.clone()); TFile out(outputFile.c_str(), "recreate"); TProfile hn("hn", NULL, 31, 0.5, +31.5); TProfile hc("hc", NULL, 21, -1.05, +1.05); TProfile ht("ht", NULL, 20, 0.5, +20.5); const JModuleRouter moduleRouter(detector); typedef double hit_type; typedef vector JFrameL1_t; typedef JSuperFrame2D JSuperFrame2D_t; typedef JBuildL1 JBuildL1_t; const JBuildL1_t buildL1(JBuildL1Parameters((hit_type) Tmax_ns, true)); JSuperFrame2D_t buffer; for (int event_count = 0; event_count < numberOfEvents; ++event_count) { STATUS("event: " << setw(10) << event_count << '\r'); DEBUG(endl); const int frame_index = 1; const JDAQChronometer chronometer(detector.getID(), 1, event_count, JDAQUTCExtended(getTimeOfFrame(frame_index))); JRandomTimeslice timeslice(chronometer, simbad); for (JDAQTimeslice::const_iterator super_frame = timeslice.begin(); super_frame != timeslice.end(); ++super_frame) { if (moduleRouter.hasModule(super_frame->getModuleID())) { // calibration const JModule& module = detector.getModule(moduleRouter.getAddress(super_frame->getModuleID())); buffer(*super_frame, module); JFrameL1_t dataL1; buildL1(buffer, back_inserter(dataL1)); if (!dataL1.empty()) { JBuildL2 buildL2(JL2Parameters(1, Tmax_ns, -1.0)); JFrameL1_t d1(dataL1); JFrameL1_t d2; for (int i = 1; i <= hn.GetNbinsX(); ++i) { buildL2.numberOfHits = (int) hn.GetBinCenter(i); d2.clear(); buildL2(buffer, d1, back_inserter(d2)); hn.Fill((double) buildL2.numberOfHits, (double) d2.size() / (double) dataL1.size()); d1.swap(d2); } } if (!dataL1.empty()) { JBuildL2 buildL2(JL2Parameters(2, Tmax_ns, -1.0)); JFrameL1_t d1(dataL1); JFrameL1_t d2; for (int i = 1; i <= hc.GetNbinsX(); ++i) { buildL2.ctMin = hc.GetBinCenter(i); d2.clear(); buildL2(buffer, d1, back_inserter(d2)); hc.Fill(buildL2.ctMin, (double) d2.size() / (double) dataL1.size()); d1.swap(d2); } } if (!dataL1.empty()) { JBuildL2 buildL2(JL2Parameters(2, 0.0, -1.0)); JFrameL1_t d1(dataL1); JFrameL1_t d2; for (int i = ht.GetNbinsX(); i != 0; --i) { buildL2.TMaxLocal_ns = ht.GetBinCenter(i); d2.clear(); buildL2(buffer, d1, back_inserter(d2)); ht.Fill(buildL2.TMaxLocal_ns, (double) d2.size() / (double) dataL1.size()); d1.swap(d2); } } } } } NOTICE(endl); out.Write(); out.Close(); }