Jpp
JEventTimeslice.hh
Go to the documentation of this file.
1 #ifndef __JTIMESLICE__JEVENTTIMESLICE__
2 #define __JTIMESLICE__JEVENTTIMESLICE__
3 
4 #include <exception>
5 #include <map>
6 
7 #include "evt/Evt.hh"
8 
12 #include "JDetector/JPMTAddress.hh"
13 #include "JDetector/JTimeRange.hh"
14 #include "JDAQ/JDAQ.hh"
15 #include "JDAQ/JDAQChronometer.hh"
18 
19 
20 /**
21  * \author mdejong
22  */
23 
24 namespace KM3NETDAQ {
25 
28 
29 
30  /**
31  * Timeslice with Monte Carlo event.
32  */
33  struct JEventTimeslice :
34  public JTimesliceL0
35  {
36  /**
37  * Constructor.
38  *
39  * This constructor converts the Monte Carlo event to a DAQ timeslice.
40  * In this, both the PMT and CLB simulations are applied.
41  * If the K40 simulator is available and the given time window is valid,
42  * the K40 background is generated and added to the time slice data.
43  * N.B. The given time window extends the time range of hits in the event, if any.
44  *
45  *
46  * \param chronometer chronometer
47  * \param simbad detector simulator
48  * \param event Monte Carlo event
49  * \param period time window [ns]
50  */
51  JEventTimeslice(const JDAQChronometer& chronometer,
52  const JDetectorSimulator& simbad,
53  const Evt& event,
54  const JTimeRange& period = JTimeRange::DEFAULT_RANGE)
55  {
56  using namespace std;
57  using namespace JPP;
58 
59  setDAQChronometer(chronometer);
60 
61 
62  if (simbad.hasPMTSimulator() &&
63  simbad.hasCLBSimulator()) {
64 
65  const JTimeConverter converter(event, chronometer);
66 
67  const JTimeRange timeRange = (period.is_valid() ? getTimeRange(event, period) : getTimeRange(event));
68 
69  typedef map<int, JModuleData> JMap_t; // map module index to data
70 
71  JMap_t data;
72 
73  for (vector<Hit>::const_iterator hit = event.mc_hits.begin(); hit != event.mc_hits.end(); ++hit) {
74 
75  if (simbad.hasPMT(hit->pmt_id)) {
76 
77  const JPMTAddress& address = simbad.getAddress(hit->pmt_id);
78 
79  if (!period.is_valid() || timeRange(getTime(*hit))) {
80 
81  data[address.first].resize(NUMBER_OF_PMTS);
82 
83  data[address.first][address.second].push_back(JPMTSignal(converter.putTime(getTime(*hit)), (int) getNPE(*hit)));
84  }
85  }
86  }
87 
88 
89  if (simbad.hasK40Simulator() && period.is_valid()) {
90 
91 
93 
94  for (JMap_t::const_iterator i = data.begin(); i != data.end(); ++i) {
95  time_range.combine(getTimeRange(i->second));
96  }
97 
98  time_range.add(period);
99 
100 
101  JModuleData buffer;
102 
103  for (JDetector::const_iterator module = simbad->begin(); module != simbad->end(); ++module) {
104 
105 
106  // signal
107 
108  JMap_t::iterator i = data.find(distance(simbad->begin(),module));
109 
110  if (i != data.end())
111  buffer.swap(i->second);
112  else
113  buffer.reset(module->size());
114 
115 
116  // background
117 
118  simbad.generateHits(*module, time_range, buffer);
119 
120  this->push_back(JDAQSuperFrame(JDAQSuperFrameHeader(chronometer, module->getID())));
121 
122  simbad(*module, buffer, *(this->rbegin()));
123  }
124 
125  } else {
126 
127  for (JMap_t::iterator i = data.begin(); i != data.end(); ++i) {
128 
129  const JModule& module = simbad.getModule(JModuleAddress(i->first));
130 
131  this->push_back(JDAQSuperFrame(JDAQSuperFrameHeader(chronometer, module.getID())));
132 
133  simbad(module, i->second, *(this->rbegin()));
134  }
135  }
136  }
137 
138  try {
139  applyHighRateVeto(dynamic_cast<const JPMTDefaultSimulatorInterface&>(simbad.getPMTSimulator()));
140  }
141  catch(const std::exception& error) {};
142  }
143  };
144 }
145 
146 #endif
KM3NETDAQ::JDAQChronometer::setDAQChronometer
void setDAQChronometer(const JDAQChronometer &chronometer)
Set DAQ chronometer.
Definition: JDAQChronometer.hh:99
JDAQ.hh
JDETECTOR::JModuleAddress::first
int first
index of module in detector data structure
Definition: JModuleAddress.hh:90
KM3NETDAQ::JEventTimeslice
Timeslice with Monte Carlo event.
Definition: JEventTimeslice.hh:33
KM3NETDAQ::JEventTimeslice::JEventTimeslice
JEventTimeslice(const JDAQChronometer &chronometer, const JDetectorSimulator &simbad, const Evt &event, const JTimeRange &period=JTimeRange::DEFAULT_RANGE)
Constructor.
Definition: JEventTimeslice.hh:51
JAANET::getTimeRange
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e.
Definition: JAAnetToolkit.hh:134
JDETECTOR::JModuleData
Data structure for PMT data corresponding to a detector module.
Definition: JPMTSimulator.hh:211
JTOOLS::JRange::add
range_type & add(argument_type x)
Add offset.
Definition: JRange.hh:437
JTRIGGER::JTimeConverter::putTime
double putTime() const
Get Monte Carlo minus DAQ/trigger hit time.
Definition: JTimeConverter.hh:77
std::vector
Definition: JSTDTypes.hh:12
JTOOLS::JRange< double >
event
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
Definition: JVoltageOptimizer_utils.hh:26
JAANET::getNPE
double getNPE(const Hit &hit)
Get true charge of hit.
Definition: JAAnetToolkit.hh:104
JDETECTOR::JPMTRouter::hasPMT
bool hasPMT(const JObjectID &id) const
Has PMT.
Definition: JPMTRouter.hh:114
JTRIGGER::JTimeConverter
Auxiliary class to convert DAQ/trigger hit time to/from Monte Carlo hit time.
Definition: JTimeConverter.hh:36
JTOOLS::JRange< double >::DEFAULT_RANGE
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:558
JTimeConverter.hh
KM3NETDAQ::NUMBER_OF_PMTS
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
JTOOLS::JRange::combine
range_type & combine(const range_type &range)
Combine ranges.
Definition: JRange.hh:423
distance
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: PhysicsEvent.hh:434
JTimeRange.hh
KM3NETDAQ::JTimesliceL0
Auxiliary class for time slice data.
Definition: JTimesliceL0.hh:25
JDAQChronometer.hh
JTOOLS::JTimeRange
JRange< double > JTimeRange
Type definition for time range.
Definition: JTools/JTimeRange.hh:19
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDetectorSimulator.hh
JDETECTOR::JDetectorSimulator::hasPMTSimulator
bool hasPMTSimulator() const
Check availability of PMT simulator.
Definition: JDetectorSimulator.hh:80
JLANG::JObjectID::getID
int getID() const
Get identifier.
Definition: JObjectID.hh:55
JAAnetToolkit.hh
JDETECTOR::JModuleAddress
Address of module in detector data structure.
Definition: JModuleAddress.hh:30
JAANET::getTime
double getTime(const Hit &hit)
Get true time of hit.
Definition: JAAnetToolkit.hh:87
JDETECTOR::JModule
Data structure for a composite optical module.
Definition: JModule.hh:49
JDETECTOR::JPMTRouter::getAddress
const JPMTAddress & getAddress(const JObjectID &id) const
Get address of PMT.
Definition: JPMTRouter.hh:78
KM3NETDAQ::JDAQSuperFrameHeader
DAQ super frame header.
Definition: JDAQSuperFrameHeader.hh:25
std::map
Definition: JSTDTypes.hh:16
JDETECTOR::JPMTAddress
Address of PMT in detector data structure.
Definition: JPMTAddress.hh:32
JTimesliceL0.hh
std
Definition: jaanetDictionary.h:36
JDETECTOR::JDetectorSimulator
Detector simulation.
Definition: JDetectorSimulator.hh:33
JPMTDefaultSimulatorInterface.hh
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
KM3NETDAQ::JTimesliceL0::applyHighRateVeto
void applyHighRateVeto(const JPMTDefaultSimulatorInterface &pmtSimulator)
Apply high-rate veto.
Definition: JTimesliceL0.hh:40
KM3NETDAQ::JDAQSuperFrame
Data frame of one optical module.
Definition: JDAQSuperFrame.hh:27
JDETECTOR::JDetectorSimulator::hasK40Simulator
bool hasK40Simulator() const
Check availability of K40 simulator.
Definition: JDetectorSimulator.hh:68
JDETECTOR::JDetectorSimulator::getPMTSimulator
const JPMTSimulator & getPMTSimulator() const
Get PMT simulator.
Definition: JDetectorSimulator.hh:116
JDETECTOR::JPMTSignal
Data structure for PMT analogue signal.
Definition: JPMTSimulator.hh:76
JDETECTOR::JDetectorSimulator::generateHits
virtual void generateHits(const JModule &module, const JTimeRange &period, JModuleData &output) const
Generate hits.
Definition: JDetectorSimulator.hh:180
JDETECTOR::JModuleData::reset
void reset(size_t size)
Reset buffers.
Definition: JPMTSimulator.hh:228
JPMTAddress.hh
JDETECTOR::JDetectorSimulator::hasCLBSimulator
bool hasCLBSimulator() const
Check availability of CLB simulator.
Definition: JDetectorSimulator.hh:91
JDETECTOR::JPMTRouter::getModule
const JModule & getModule(const JModuleAddress &address) const
Get module.
Definition: JPMTRouter.hh:150
JDETECTOR::JPMTAddress::second
int second
index of PMT in module data structure.
Definition: JPMTAddress.hh:100
KM3NETDAQ::JDAQChronometer
DAQ chronometer.
Definition: JDAQChronometer.hh:26