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 <map>
5 
6 #include "evt/Evt.hh"
7 
10 #include "JDetector/JPMTAddress.hh"
11 #include "JDetector/JTimeRange.hh"
12 #include "JDAQ/JDAQ.hh"
13 #include "JDAQ/JDAQClock.hh"
14 #include "JDAQ/JDAQTimeslice.hh"
16 
17 
18 /**
19  * \author mdejong
20  */
21 
22 namespace KM3NETDAQ {
23 
29 
30 
31  /**
32  * Timeslice with Monte Carlo event.
33  */
35  public JDAQTimeslice
36  {
37  public:
38  /**
39  * Constructor.
40  * This constructor converts the Monte Carlo event to a DAQ timeslice.
41  * In this, both the PMT and CLB simulations are applied.
42  * If the simulator is available and the given time window is valid,
43  * the K40 background is generated and added to the timeslice data.
44  * N.B. The given time window extends the time range of hits in the event, if any.
45  *
46  *
47  * \param chronometer chronometer
48  * \param simbad detector simulator
49  * \param event Monte Carlo event
50  * \param period time window [ns]
51  */
52  JEventTimeslice(const JDAQChronometer& chronometer,
53  const JDetectorSimulator& simbad,
54  const Evt& event,
55  const JTimeRange& period = JTimeRange::DEFAULT_RANGE) :
57  {
58  using namespace std;
59  using namespace JDETECTOR;
60  using namespace JAANET;
62 
63  setDAQChronometer(chronometer);
64 
65 
66  if (simbad.hasPMTSimulator() &&
67  simbad.hasCLBSimulator()) {
68 
69  const JTimeConverter 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  data[address.first].resize(NUMBER_OF_PMTS);
86 
87  data[address.first][address.second].push_back(JPMTSignal(converter.putTime(getTime(*hit)), (int) getNPE(*hit)));
88  }
89  }
90  }
91 
92 
93  if (simbad.hasK40Simulator() && period.is_valid()) {
94 
95 
97 
98  for (JMap_t::const_iterator i = data.begin(); i != data.end(); ++i) {
99  time_range.combine(getTimeRange(i->second));
100  }
101 
102  time_range.add(period);
103 
104 
105  JModuleData buffer;
106 
107  for (JDetector::const_iterator module = simbad->begin(); module != simbad->end(); ++module) {
108 
109 
110  // signal
111 
112  JMap_t::iterator i = data.find(distance(simbad->begin(),module));
113 
114  if (i != data.end())
115  buffer.swap(i->second);
116  else
117  buffer.reset(module->size());
118 
119 
120  // background
121 
122  simbad.generateHits(*module, time_range, buffer);
123 
124  this->push_back(JDAQSuperFrame(JDAQSuperFrameHeader(chronometer, module->getID())));
125 
126  simbad(*module, buffer, *(this->rbegin()));
127  }
128 
129  } else {
130 
131  for (JMap_t::iterator i = data.begin(); i != data.end(); ++i) {
132 
133  const JModule& module = simbad.getModule(JModuleAddress(i->first));
134 
135  this->push_back(JDAQSuperFrame(JDAQSuperFrameHeader(chronometer, module.getID())));
136 
137  simbad(module, i->second, *(this->rbegin()));
138  }
139  }
140  }
141  }
142  };
143 }
144 
145 #endif
static const JRange< double, std::less< double > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:506
void reset(size_t size)
Reset buffers.
Data structure for PMT analogue signal.
Data structure for a composite optical module.
Definition: JModule.hh:47
Data structure for PMT data corresponding to a detector module.
double putTime() const
Get Monte Carlo minus DAQ/trigger hit time.
Timeslice with Monte Carlo event.
int second
index of PMT in module data structure.
Definition: JPMTAddress.hh:100
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
bool hasPMT(const JObjectID &id) const
Has PMT.
Definition: JPMTRouter.hh:114
range_type & combine(const range_type &range)
Combine ranges.
Definition: JRange.hh:371
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.
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:385
int getID() const
Get identifier.
Definition: JObjectID.hh:54
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Data time slice.
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
Auxiliary class to convert DAQ/trigger hit time to/from Monte Carlo hit time.
double getNPE(const Hit &hit)
Get true charge of hit.
JEventTimeslice(const JDAQChronometer &chronometer, const JDetectorSimulator &simbad, const Evt &event, const JTimeRange &period=JTimeRange::DEFAULT_RANGE)
Constructor.
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.
const JPMTAddress & getAddress(const JObjectID &id) const
Get address of PMT.
Definition: JPMTRouter.hh:78