Jpp  master_rocky
the software that should make you happy
JTrigger3N.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JTRIGGER3N__
2 #define __JTRIGGER__JTRIGGER3N__
3 
4 #include <vector>
5 #include <iterator>
6 
10 
11 #include "JTrigger/JEvent.hh"
12 #include "JTrigger/JMatch.hh"
13 #include "JTrigger/JBind2nd.hh"
14 #include "JTrigger/JAlgorithm.hh"
18 
19 
20 /**
21  * \author mdejong
22  */
23 
24 namespace JTRIGGER {}
25 namespace JPP { using namespace JTRIGGER; }
26 
27 namespace JTRIGGER {
28 
31 
32 
33  /**
34  * General purpose muon trigger.
35  *
36  * The 3D match criterion is used followed by a scan of directions.
37  * For each direction, the 1D match criterion is applied.
38  * A trigger is fired when the specified minimum number of hits is
39  * detected for any of the directions.
40  */
41  class JTrigger3N :
42  public JTriggerInterface
43  {
44  public:
45 
47 
48  /**
49  * Trigger parameters.
50  */
51  struct JParameters
52  {
53  /**
54  * Constructor.
55  *
56  * \param option enable/disable trigger
57  * \param number_of_hits minimal number of hits to trigger event
58  * \param number_of_modules minimal number of modules to trigger event
59  * \param Tmax_ns maximal time between first and last hit [ns]
60  * \param omega set of directions
61  * \param match3d 3D match operator
62  * \param match1d 1D match operator
63  * \param factory_limit maximal number of hits to apply trigger logic (above this limit, always trigger)
64  */
65  JParameters(const bool option,
66  const int number_of_hits,
67  const int number_of_modules,
68  const double Tmax_ns,
69  const JOmega3D& omega,
70  const match_type& match3d,
71  const match_type& match1d,
72  const int factory_limit) :
73  enabled (option),
74  numberOfHits (number_of_hits),
75  numberOfModules(number_of_modules),
76  TMaxEvent_ns (Tmax_ns),
77  rotator (omega),
78  match3D (match3d.clone()),
79  match1D (match1d.clone()),
80  factoryLimit (factory_limit)
81  {}
82 
83 
84  bool enabled;
87  double TMaxEvent_ns;
92  };
93 
94 
95  /**
96  * Constructor.
97  *
98  * \param input trigger parameters
99  */
100  JTrigger3N(const JParameters& input) :
101  parameters(input)
102  {
103  if (parameters.numberOfHits == 0) {
105  }
106 
107  if (parameters.numberOfHits == 1) {
109  }
110 
112  }
113 
114 
115  /**
116  * Process trigger.
117  *
118  * \param input input data
119  * \param out output data
120  */
121  void operator()(const JTriggerInput& input, std::back_insert_iterator<JTriggerOutput> out) const
122  {
123  using std::distance;
124 
125  if (parameters.enabled && input.size() >= (size_t) parameters.numberOfHits) {
126 
127  const match_type& match3D = *parameters.match3D;
128  const match_type& match1D = *parameters.match1D;
129 
130  for (JTriggerInput::const_iterator p = input.begin(), q = p; p != input.end(); ) {
131 
132  for (++q; q->getT() - p->getT() < parameters.TMaxEvent_ns; ++q) {}
133 
134  if (distance (p,q) >= parameters.numberOfHits &&
136 
137  if (distance(p,q) < parameters.factoryLimit) {
138 
139  do {
140 
141  if (distance (p,q) >= parameters.numberOfHits &&
143 
144  // copy
145 
146  JTriggerInput::iterator root = buffer.begin();
147  JTriggerInput::iterator __p = buffer.begin();
148  JTriggerInput::iterator __q = buffer.begin();
149 
150  *root = *p;
151 
152  ++__p;
153  ++__q;
154 
155  for (JTriggerInput::const_iterator i = p; ++i != q; ) {
156  if (match3D(*p,*i)) {
157  *__q = *i;
158  ++__q;
159  }
160  }
161 
162  if (distance (root,__q) >= parameters.numberOfHits &&
164 
165  __q = clusterize(__p, __q, match3D, parameters.numberOfHits - 1);
166 
167  if (distance (root,__q) >= parameters.numberOfHits &&
169 
170  for (JGEOMETRY3D::JRotator3D_t::const_iterator R = parameters.rotator.begin(); R != parameters.rotator.end(); ++R) {
171 
172  for (JTriggerInput::iterator i = root; i != __q; ++i) {
173  i->JPosition3D::rotate(*R);
174  }
175 
176  JTriggerInput::iterator __z = partition(__p, __q, JBind2nd(match1D,*root));
177 
178  if (distance (root,__z) >= parameters.numberOfHits &&
180 
181  __z = clusterize(__p, __z, match1D, parameters.numberOfHits - 1);
182 
183  if (distance (root,__z) >= parameters.numberOfHits &&
185 
186  *out = JEvent(input.getDAQChronometer(), root, __q, this->getTriggerBit());
187  ++out;
188 
189  break;
190  }
191  }
192  }
193  }
194  }
195  }
196 
197  ++p;
198 
199  } while (q->getT() - p->getT() >= parameters.TMaxEvent_ns);
200 
201  } else {
202 
203  // Anomalous large event
204 
205  JEvent event(input.getDAQChronometer(), p, q, this->getTriggerBit());
206 
207  event.addTriggerBit(FACTORY_LIMIT);
208 
209  *out = event;
210  ++out;
211 
212  p = q;
213  }
214 
215  } else {
216 
217  for (++p; q->getT() - p->getT() >= parameters.TMaxEvent_ns; ++p) {}
218  }
219  }
220  }
221  }
222 
223 
225 
226  private:
228  };
229 }
230 
231 #endif
Algorithms for hit clustering and sorting.
Base class for match operations for cluster and hit-preprocessing methods.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Direction set covering (part of) solid angle.
Definition: JOmega3D.hh:68
Triggered event.
Function object interface for hit matching.
Definition: JMatch.hh:27
General purpose muon trigger.
Definition: JTrigger3N.hh:43
void operator()(const JTriggerInput &input, std::back_insert_iterator< JTriggerOutput > out) const
Process trigger.
Definition: JTrigger3N.hh:121
JParameters parameters
Definition: JTrigger3N.hh:224
std::vector< value_type > buffer
Definition: JTrigger3N.hh:227
JTrigger3N(const JParameters &input)
Constructor.
Definition: JTrigger3N.hh:100
JLANG::JSharedPointer< match_type > JMatch_t
Definition: JTrigger3N.hh:46
Data structure for input to trigger algorithm.
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JFIT::JEvent JEvent
Definition: JHistory.hh:353
Auxiliary classes and methods for triggering.
JBinder2nd< JHit_t > JBind2nd(const JMatch< JHit_t > &match, const JHit_t &second)
Auxiliary method to create JBinder2nd object.
Definition: JBind2nd.hh:66
static const struct JTRIGGER::clusterize clusterize
static const JModuleCounter getNumberOfModules
Function object to count unique modules.
Definition: root.py:1
JParameters(const bool option, const int number_of_hits, const int number_of_modules, const double Tmax_ns, const JOmega3D &omega, const match_type &match3d, const match_type &match1d, const int factory_limit)
Constructor.
Definition: JTrigger3N.hh:65
static const int FACTORY_LIMIT
Bit indicating max nhits reached in trigger.
Definition: trigger.hh:16