Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
8 
12 #include "JDetector/JPMTAddress.hh"
13 #include "JDetector/JTimeRange.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  };
139 }
140 
141 #endif
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:569
void reset(size_t size)
Reset buffers.
Data structure for PMT analogue signal.
Data structure for a composite optical module.
Definition: JModule.hh:50
Data structure for PMT data corresponding to a detector module.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
double putTime() const
Get Monte Carlo minus DAQ/trigger hit time.
int second
index of PMT in module data structure.
Definition: JPMTAddress.hh:100
JEventTimeslice(const JDAQChronometer &chronometer, const JDetectorSimulator &simbad, const Evt &event, const JTimeRange &period=JTimeRange::DEFAULT_RANGE)
Constructor.
bool hasPMT(const JObjectID &id) const
Has PMT.
Definition: JPMTRouter.hh:114
range_type & combine(const range_type &range)
Combine ranges.
Definition: JRange.hh:434
double getTime(const Hit &hit)
Get true time of hit.
JRange< double > JTimeRange
Type definition for time range.
const JModule & getModule(const JModuleAddress &address) const
Get module.
Definition: JPMTRouter.hh:150
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
virtual void generateHits(const JModule &module, const JTimeRange &period, JModuleData &output) const
Generate hits.
int first
index of module in detector data structure
bool hasPMTSimulator() const
Check availability of PMT simulator.
range_type & add(argument_type x)
Add offset.
Definition: JRange.hh:448
int getID() const
Get identifier.
Definition: JObjectID.hh:55
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
void setDAQChronometer(const JDAQChronometer &chronometer)
Set DAQ chronometer.
Address of module in detector data structure.
bool hasK40Simulator() const
Check availability of K40 simulator.
bool hasCLBSimulator() const
Check availability of CLB simulator.
Address of PMT in detector data structure.
Definition: JPMTAddress.hh:32
Base class class for generation of time slice data.
Definition: JTimesliceL0.hh:18
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition: Evt.hh:44
Auxiliaries for creation of time slice data.
Auxiliary class to convert DAQ/trigger hit time to/from Monte Carlo hit time.
double getNPE(const Hit &hit)
Get true charge of hit.
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
Data frame of one optical module.
Timeslice with Monte Carlo event.
const JPMTAddress & getAddress(const JObjectID &id) const
Get address of PMT.
Definition: JPMTRouter.hh:78
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19