Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
30 
31 
32  /**
33  * General purpose muon trigger.
34  *
35  * The 3D match criterion is used followed by a scan of directions.
36  * For each direction, the 1D match criterion is applied.
37  * A trigger is fired when the specified minimum number of hits is
38  * detected for any of the directions.
39  */
40  class JTrigger3N :
41  public JTriggerInterface
42  {
43  public:
44  /**
45  * Trigger parameters.
46  */
47  struct JParameters
48  {
49  /**
50  * Constructor.
51  *
52  * \param option enable/disable trigger
53  * \param number_of_hits minimal number of hits to trigger event
54  * \param number_of_modules minimal number of modules to trigger event
55  * \param Tmax_ns maximal time between first and last hit [ns]
56  * \param omega set of directions
57  * \param match3d 3D match operator
58  * \param match1d 1D match operator
59  * \param factory_limit maximal number of hits to apply trigger logic (above this limit, always trigger)
60  */
61  JParameters(const bool option,
62  const int number_of_hits,
63  const int number_of_modules,
64  const double Tmax_ns,
65  const JOmega3D& omega,
66  const match_type& match3d,
67  const match_type& match1d,
68  const int factory_limit) :
69  enabled (option),
70  numberOfHits (number_of_hits),
71  numberOfModules(number_of_modules),
72  TMaxEvent_ns (Tmax_ns),
73  rotator (omega),
74  match3D (match3d.clone()),
75  match1D (match1d.clone()),
76  factoryLimit (factory_limit)
77  {}
78 
79 
80  bool enabled;
83  double TMaxEvent_ns;
88  };
89 
90 
91  /**
92  * Constructor.
93  *
94  * \param input trigger parameters
95  */
96  JTrigger3N(const JParameters& input) :
97  parameters(input)
98  {
99  if (parameters.numberOfHits == 0) {
101  }
102 
103  if (parameters.numberOfHits == 1) {
105  }
106 
108  }
109 
110 
111  /**
112  * Process trigger.
113  *
114  * \param input input data
115  * \param out output data
116  */
117  void operator()(const JTriggerInput& input, std::back_insert_iterator<JTriggerOutput> out) const
118  {
119  using std::distance;
120 
121  if (parameters.enabled && input.size() >= parameters.numberOfHits) {
122 
123  const match_type& match3D = *parameters.match3D;
124  const match_type& match1D = *parameters.match1D;
125 
126  for (JTriggerInput::const_iterator p = input.begin(), q = p; p != input.end(); ) {
127 
128  for (++q; q->getT() - p->getT() < parameters.TMaxEvent_ns; ++q) {}
129 
130  if (distance (p,q) >= parameters.numberOfHits &&
132 
133  if (distance(p,q) < parameters.factoryLimit) {
134 
135  do {
136 
137  if (distance (p,q) >= parameters.numberOfHits &&
139 
140  // copy
141 
142  JTriggerInput::iterator root = buffer.begin();
143  JTriggerInput::iterator __p = buffer.begin();
144  JTriggerInput::iterator __q = buffer.begin();
145 
146  *root = *p;
147 
148  ++__p;
149  ++__q;
150 
151  for (JTriggerInput::const_iterator i = p; ++i != q; ) {
152  if (match3D(*p,*i)) {
153  *__q = *i;
154  ++__q;
155  }
156  }
157 
158  if (distance (root,__q) >= parameters.numberOfHits &&
160 
161  __q = clusterize(__p, __q, match3D, parameters.numberOfHits - 1);
162 
163  if (distance (root,__q) >= parameters.numberOfHits &&
165 
166  for (JGEOMETRY3D::JRotator3D_t::const_iterator R = parameters.rotator.begin(); R != parameters.rotator.end(); ++R) {
167 
168  for (JTriggerInput::iterator i = root; i != __q; ++i) {
169  i->JPosition3D::rotate(*R);
170  }
171 
172  JTriggerInput::iterator __z = partition(__p, __q, JBind2nd(match1D,*root));
173 
174  if (distance (root,__z) >= parameters.numberOfHits &&
176 
177  __z = clusterize(__p, __z, match1D, parameters.numberOfHits - 1);
178 
179  if (distance (root,__z) >= parameters.numberOfHits &&
181 
182  *out = JEvent(input.getDAQChronometer(), root, __q, this->getTriggerBit());
183  ++out;
184 
185  break;
186  }
187  }
188  }
189  }
190  }
191  }
192 
193  ++p;
194 
195  } while (q->getT() - p->getT() >= parameters.TMaxEvent_ns);
196 
197  } else {
198 
199  // Anomalous large event
200 
201  *out = JEvent(input.getDAQChronometer(), p, q, this->getTriggerBit());
202  ++out;
203 
204  p = q;
205  }
206 
207  } else {
208 
209  for (++p; q->getT() - p->getT() >= parameters.TMaxEvent_ns; ++p) {}
210  }
211  }
212  }
213  }
214 
215 
217 
218  private:
220  };
221 }
222 
223 #endif
std::vector< value_type > buffer
Definition: JTrigger3N.hh:219
JBinder2nd< JHit_t > JBind2nd(const JMatch< JHit_t > &match, const JHit_t &second)
Auxiliary method to create JBinder2nd object.
Definition: JBind2nd.hh:70
Algorithms for hit clustering and sorting.
JLANG::JSharedPointer< match_type > match1D
Definition: JTrigger3N.hh:86
Direction set covering (part of) solid angle.
Definition: JOmega3D.hh:62
Function object interface for hit matching.
Definition: JMatch.hh:27
JParameters parameters
Definition: JTrigger3N.hh:216
General purpose muon trigger.
Definition: JTrigger3N.hh:40
const_iterator end() const
get iterator to end of data (without end marker)
Base class for match operations inside clusterize methods.
JHitIterator_t clusterize(JHitIterator_t __begin, JHitIterator_t __end, const JMatch< JHit_t > &match, const int Nmin=1)
Partition data according given binary match operator.
Definition: JAlgorithm.hh:45
void operator()(const JTriggerInput &input, std::back_insert_iterator< JTriggerOutput > out) const
Process trigger.
Definition: JTrigger3N.hh:117
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
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:61
JModuleCounter getNumberOfModules
Function object to count unique modules.
JGEOMETRY3D::JRotator3D rotator
Definition: JTrigger3N.hh:84
int size() const
get size of data (without end marker)
JTriggerbit_t getTriggerBit() const
Get the trigger bit.
Data structure for input to trigger algorithm.
Rotation set.
Definition: JRotator3D.hh:29
JTrigger3N(const JParameters &input)
Constructor.
Definition: JTrigger3N.hh:96
JLANG::JSharedPointer< match_type > match3D
Definition: JTrigger3N.hh:85
Triggered event.
Definition: JEvent.hh:31