Jpp  18.6.0-rc.1
the software that should make you happy
 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 
13 
14 #include "JAAnet/JAAnetToolkit.hh"
15 
18 #include "JDetector/JPMTAddress.hh"
19 #include "JDetector/JTimeRange.hh"
20 
22 
23 
24 /**
25  * \author mdejong
26  */
27 
28 namespace KM3NETDAQ {
29 
32 
33 
34  /**
35  * Timeslice with Monte Carlo event.
36  */
37  struct JEventTimeslice :
38  public JTimesliceL0
39  {
40  /**
41  * Constructor.
42  *
43  * This constructor converts the Monte Carlo event to a DAQ timeslice.
44  * In this, both the PMT and CLB simulations are applied.
45  * If the K40 simulator is available and the given time window is valid,
46  * the K40 background is generated and added to the time slice data.
47  * N.B. The given time window extends the time range of hits in the event, if any.
48  *
49  *
50  * \param chronometer chronometer
51  * \param simbad detector simulator
52  * \param event Monte Carlo event
53  * \param period time window [ns]
54  */
55  JEventTimeslice(const JDAQChronometer& chronometer,
56  const JDetectorSimulator& simbad,
57  const Evt& event,
58  const JTimeRange& period = JTimeRange::DEFAULT_RANGE())
59  {
60  using namespace std;
61  using namespace JPP;
62 
63  setDAQChronometer(chronometer);
64 
65 
66  if (simbad.hasPMTSimulator() &&
67  simbad.hasCLBSimulator()) {
68 
69  const time_converter converter(event, chronometer);
70 
71  const JTimeRange timeRange = (period.is_valid() ? getTimeRange(event, period) : getTimeRange(event));
72 
73  typedef map<int, JModuleData> JMap_t; // map module index to data
74 
75  JMap_t data;
76 
77  for (vector<Hit>::const_iterator hit = event.mc_hits.begin(); hit != event.mc_hits.end(); ++hit) {
78 
79  if (simbad.hasPMT(hit->pmt_id)) {
80 
81  const JPMTAddress& address = simbad.getAddress(hit->pmt_id);
82 
83  if (!period.is_valid() || timeRange(getTime(*hit))) {
84 
85  if (!simbad.getModule(address).has(MODULE_OUT_OF_SYNC) &&
86  !simbad.getPMT (address).has(OUT_OF_SYNC)) {
87 
88  data[address.first].resize(NUMBER_OF_PMTS);
89 
90  data[address.first][address.second].push_back(JPMTSignal(converter.putTime(getTime(*hit)), (int) getNPE(*hit)));
91  }
92  }
93  }
94  }
95 
96 
97  if (simbad.hasK40Simulator() && period.is_valid()) {
98 
99 
101 
102  for (JMap_t::const_iterator i = data.begin(); i != data.end(); ++i) {
103  time_range.combine(getTimeRange(i->second));
104  }
105 
106  time_range.add(period);
107 
108 
109  JModuleData buffer;
110 
111  for (JDetector::const_iterator module = simbad->begin(); module != simbad->end(); ++module) {
112 
113  if (!module->empty()) {
114 
115  // signal
116 
117  JMap_t::iterator i = data.find(distance(simbad->begin(),module));
118 
119  if (i != data.end())
120  buffer.swap(i->second);
121  else
122  buffer.reset(module->size());
123 
124  // background
125 
126  simbad.generateHits(*module, time_range, buffer);
127 
128  this->push_back(JDAQSuperFrame(JDAQSuperFrameHeader(chronometer, module->getID())));
129 
130  simbad(*module, buffer, *(this->rbegin()));
131  }
132  }
133 
134  } else {
135 
136  for (JMap_t::iterator i = data.begin(); i != data.end(); ++i) {
137 
138  const JModule& module = simbad.getModule(JModuleAddress(i->first));
139 
140  this->push_back(JDAQSuperFrame(JDAQSuperFrameHeader(chronometer, module.getID())));
141 
142  simbad(module, i->second, *(this->rbegin()));
143  }
144  }
145  }
146  }
147  };
148 }
149 
150 #endif
void reset(size_t size)
Reset buffers.
Data structure for PMT analogue signal.
Data structure for a composite optical module.
Definition: JModule.hh:67
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.
int second
index of PMT in module data structure.
Definition: JPMTAddress.hh:100
bool hasPMT(const JObjectID &id) const
Has PMT.
Definition: JPMTRouter.hh:116
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
const JPMT & getPMT(const JPMTAddress &address) const
Get PMT.
Definition: JPMTRouter.hh:92
Auxiliary class to convert DAQ hit time to/from Monte Carlo hit time.
range_type & combine(const range_type &range)
Combine ranges.
Definition: JRange.hh:432
double getTime(const Hit &hit)
Get true time of hit.
const JModule & getModule(const JModuleAddress &address) const
Get module.
Definition: JPMTRouter.hh:152
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
int first
index of module in detector data structure
bool hasPMTSimulator() const
Check availability of PMT simulator.
bool has(const int bit) const
Test PMT status.
Definition: JStatus.hh:120
range_type & add(argument_type x)
Add offset.
Definition: JRange.hh:446
int getID() const
Get identifier.
Definition: JObjectID.hh:50
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
double putTime() const
Get Monte Carlo time minus DAQ/trigger time.
void setDAQChronometer(const JDAQChronometer &chronometer)
Set DAQ chronometer.
Address of module in detector data structure.
bool hasK40Simulator() const
Check availability of K40 simulator.
Auxiliary include file for time conversion between DAQ/trigger hit and Monte Carlo hit...
bool hasCLBSimulator() const
Check availability of CLB simulator.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]).
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:48
static const int OUT_OF_SYNC
Enable (disable) synchronous signal from this PMT if this status bit is 0 (1);.
Definition: pmt_status.hh:17
static const int MODULE_OUT_OF_SYNC
Enable (disable) synchronous signal from this module if this status bit is 0 (1);.
Auxiliaries for creation of time slice data.
double getNPE(const Hit &hit)
Get true charge of hit.
virtual void generateHits(const JModule &module, const JTimeRange &period, JModuleData &output) const override
Generate hits.
static JRange< double, std::less< double > > DEFAULT_RANGE()
Default range.
Definition: JRange.hh:555
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.
JEventTimeslice(const JDAQChronometer &chronometer, const JDetectorSimulator &simbad, const Evt &event, const JTimeRange &period=JTimeRange::DEFAULT_RANGE())
Constructor.
const JPMTAddress & getAddress(const JObjectID &id) const
Get address of PMT.
Definition: JPMTRouter.hh:80
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20