Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JTriggerMXShower.hh
Go to the documentation of this file.
1#ifndef __JTRIGGER__JTRIGGERMXSHOWER__
2#define __JTRIGGER__JTRIGGERMXSHOWER__
3
4#include <vector>
5#include <set>
6
17#include "JMath/JMathToolkit.hh"
20
21
22/**
23 * \author mdejong
24 */
25
26namespace JTRIGGER {}
27namespace JPP { using namespace JTRIGGER; }
28
29namespace JTRIGGER {
30
36
37
38 /**
39 * Module attributes.
40 */
41 struct JAttributes {
42 double Tmin_ns; //!< minimal time difference [ns]
43 double Tmax_ns; //!< maximal time difference [ns]
44 };
45
46
47 /**
48 * Set module attributes.
49 *
50 * \param first first module
51 * \param second second module
52 * \param attributes module attributes
53 */
54 inline void setAttributes(const JModule& first,
55 const JModule& second,
56 JAttributes& attributes)
57 {
58 using namespace JPP;
59
60 typedef JTriggerMXShower_t::JParameters JParameters_t;
61
62 // get trigger parameters
63
64 const JParameters_t& parameters = JParametersHelper<JParameters_t>::getParameters();
65
66 const double d = getDistance(first.getPosition(), second.getPosition());
67
68 double t1 = 0.0;
69
70 if (d <= 0.5 * parameters.DMax_m)
71 t1 = d * getIndexOfRefraction() * getInverseSpeedOfLight() + parameters.TMaxExtra_ns;
72 else if (d <= parameters.DMax_m)
73 t1 = (parameters.DMax_m - d) * getIndexOfRefraction() * getInverseSpeedOfLight() + parameters.TMaxExtra_ns;
74
75 attributes.Tmin_ns = -t1;
76 attributes.Tmax_ns = +t1;
77 }
78
79
80 /**
81 * Shower trigger.
82 */
84 public JTriggerMXShower_t,
85 public JTriggerInterface,
86 public std::vector<JVector3D>
87 {
88 public:
89
90 /**
91 * Type definition of module mapper.
92 */
94
95
96 /**
97 * Constructor.
98 *
99 * \param input trigger parameters
100 * \param detector detector;
101 */
103 const JDetector& detector) :
104 parameters(input),
106 match(parameters.DMax_m, parameters.TMaxExtra_ns)
107 {
108 using namespace JPP;
109
111
112 if (parameters.numberOfHits == 0) {
113 parameters.numberOfHits = 1;
114 }
115
116 if (parameters.numberOfHits == 1) {
117 parameters.factoryLimit = 1;
118 }
119
120 if (parameters.numberOfModules < 1) {
121 parameters.numberOfModules = 1;
122 }
123
124 // vertices
125
126 if (parameters.RMax_m > 0.0 &&
127 parameters.Xv_m > 0.0) {
128
129 this->push_back(JVector3D(0.0,0.0,0.0));
130
131 for (double x = 0.5*parameters.Xv_m; x < parameters.RMax_m + 0.5*parameters.Xv_m; x += parameters.Xv_m) {
132 for (double y = 0.5*parameters.Xv_m; y < parameters.RMax_m + 0.5*parameters.Xv_m; y += parameters.Xv_m) {
133 for (double z = 0.5*parameters.Xv_m; z < parameters.RMax_m + 0.5*parameters.Xv_m; z += parameters.Xv_m) {
134 if (x*x + y*y + z*z <= parameters.RMax_m*parameters.RMax_m) {
135 this->push_back(JVector3D(-x,-y,-z));
136 this->push_back(JVector3D(-x,-y,+z));
137 this->push_back(JVector3D(-x,+y,-z));
138 this->push_back(JVector3D(-x,+y,+z));
139 this->push_back(JVector3D(+x,-y,-z));
140 this->push_back(JVector3D(+x,-y,+z));
141 this->push_back(JVector3D(+x,+y,-z));
142 this->push_back(JVector3D(+x,+y,+z));
143 }
144 }
145 }
146 }
147 }
148 }
149
150
151 /**
152 * Process trigger.
153 *
154 * \param inputL1 input L1 data
155 * \param inputL0 input L0 data
156 * \param out output data
157 */
158 template<class JElement_t>
159 void operator()(const JTriggerInput& inputL1,
160 const JTimeslice<JElement_t> inputL0,
161 std::back_insert_iterator<JTriggerOutput> out) const
162 {
163 typedef JTimesliceClone<JElement_t> JTimeslice_t;
164 typedef typename JTimeslice_t::value_type JFrame_t;
165 typedef typename JModuleMapper_t::container_type container_type;
166
167 if (parameters.enabled) {
168
169 JTimeslice_t clone(inputL0, mapper);
170
171 for (JTriggerInput::const_iterator root = inputL1.begin(); root != inputL1.end(); ++root) {
172
173 buffer.clear();
174
175 const container_type& zip = mapper.getList(root->getModuleID());
176
177 for (typename container_type::const_iterator mod = zip.begin(); mod != zip.end(); ++mod) {
178
179 const double Tmin = root->getT() + mod->Tmin_ns;
180 const double Tmax = root->getT() + mod->Tmax_ns;
181
182 JFrame_t& frame = clone[mod->first];
183
184 if (!frame.empty()) {
185
186 frame.fast_forward(root->getT() - TMaxEvent_ns);
187
188 for (typename JFrame_t::const_iterator i = frame.get(); *i <= Tmax; ++i) {
189
190 if (*i >= Tmin) {
191 buffer.push_back(JHitR1(frame.getModuleID(),
192 frame.getPosition(),
193 frame.getJHit(*i)));
194 }
195 }
196 }
197 }
198
199 if (distance (buffer.begin(), buffer.end()) >= parameters.numberOfHits - 1 &&
200 getNumberOfModules(buffer.begin(), buffer.end()) >= parameters.numberOfModules - 1) {
201
202 if (distance(buffer.begin(), buffer.end()) < parameters.factoryLimit) {
203
204 JTriggerInput::iterator q = clusterize(buffer.begin(), buffer.end(), match, parameters.numberOfHits - 1);
205
206 if (distance (buffer.begin(), q) >= parameters.numberOfHits - 1 &&
207 getNumberOfModules(buffer.begin(), q) >= parameters.numberOfModules - 1) {
208
209 if (check(*root, buffer.begin(), q)) {
210 *out = JEvent(inputL1.getDAQChronometer(), *root, buffer.begin(), q, this->getTriggerBit());
211 ++out;
212 }
213 }
214
215 } else {
216
217 // Anomalous large event
218
219 JEvent event(inputL1.getDAQChronometer(), *root, buffer.begin(), buffer.end(), this->getTriggerBit());
220
221 event.addTriggerBit(FACTORY_LIMIT);
222
223 *out = event;
224 ++out;
225 }
226 }
227 }
228 }
229 }
230
231
232 /**
233 * Check event.
234 *
235 * \param root root hit
236 * \param __begin begin of data
237 * \param __end end of data
238 * \return true if accepted; else false
239 */
240 template<class T>
241 inline bool check(const JHitR1& root, T __begin, T __end) const
242 {
243 using namespace std;
244 using namespace JPP;
245
246 if (!this->empty()) {
247
248 const double U = getIndexOfRefraction() * getInverseSpeedOfLight();
249
250 for (const_iterator u = this->begin(); u != this->end(); ++u) {
251
252 const JVector3D p0 = root.getPosition() + *u; // vertex position
253 const double t0 = root.getT() - u->getLength() * U; // vertex time
254
255 size_t n = 1; // number of hits
256 set<int> m({root.getModuleID()}); // number of modules
257
258 for (T p = __begin; p != __end; ++p) {
259
260 const double t1 = p->getT() - p0.getDistance(*p) * U; // vertex time
261
262 if (fabs(t1 - t0) <= parameters.TMaxExtra_ns) {
263 n += 1;
264 m.insert(p->getModuleID());
265 }
266 }
267
268 if (n >= (size_t) parameters.numberOfHits &&
269 m.size() >= (size_t) parameters.numberOfModules) {
270 return true;
271 }
272 }
273
274 return false;
275
276 } else {
277
278 return true;
279 }
280 }
281
282 private:
288 };
289}
290
291#endif
Algorithms for hit clustering and sorting.
Data structure for detector geometry and calibration.
Match operator for Cherenkov light from shower in any direction.
Auxiliary methods for geometrical methods.
Map of associated modules in detector.
Physics constants.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Detector data structure.
Definition JDetector.hh:96
Mapper for directly addressing of associated modules in the detector data structure.
const container_type & getList(const JObjectID &id) const
Get list with module data matching given module.
Data structure for a composite optical module.
Definition JModule.hh:75
const JPosition3D & getPosition() const
Get position.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
double getDistance(const JVector3D &pos) const
Get distance to point.
Definition JVector3D.hh:270
Triggered event.
Data frame with end marker.
Definition JFrame_t.hh:30
Reduced data structure for L1 hit.
Definition JHitR1.hh:35
3G match criterion.
Definition JMatch3G.hh:31
Clone of JTimeslice.
Time slice with calibrated data.
Definition JTimeslice.hh:29
Data structure for input to trigger algorithm.
void operator()(const JTriggerInput &inputL1, const JTimeslice< JElement_t > inputL0, std::back_insert_iterator< JTriggerOutput > out) const
Process trigger.
JModuleMapper< JAttributes > JModuleMapper_t
Type definition of module mapper.
std::vector< JHitR1 > buffer
JParametersHelper< JParameters > parameters
JTriggerMXShower(const JParameters &input, const JDetector &detector)
Constructor.
bool check(const JHitR1 &root, T __begin, T __end) const
Check event.
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
const double getInverseSpeedOfLight()
Get inverse speed of light.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JFIT::JEvent JEvent
Definition JHistory.hh:404
const int n
Definition JPolint.hh:791
Auxiliary classes and methods for triggering.
JHitIterator_t clusterize(JHitIterator_t __begin, JHitIterator_t __end, const JMatch_t &match, const int Nmin=1)
Partition data according given binary match operator.
Definition JAlgorithm.hh:38
static const JModuleCounter getNumberOfModules
Function object to count unique modules.
void setAttributes(const JModule &first, const JModule &second, JAttributes &attributes)
Set module attributes.
Definition root.py:1
Detector file.
Definition JHead.hh:227
Auxiliary class to match modules according maximal distance.
Module attributes.
double Tmin_ns
minimal time difference [ns]
double Tmax_ns
maximal time difference [ns]
Wrapper class to share parameters.
static const JParameters_t & getParameters()
Get latest parameters.
Shower trigger parameters.
static const int FACTORY_LIMIT
Bit indicating max nhits reached in trigger.
Definition trigger.hh:16