Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTriggerMXShower.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JTRIGGERMXSHOWER__
2 #define __JTRIGGER__JTRIGGERMXSHOWER__
3 
7 #include "JTrigger/JTimeslice.hh"
9 #include "JDetector/JDetector.hh"
11 #include "JMath/JMathToolkit.hh"
12 #include "JTools/JConstants.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JTRIGGER {}
20 namespace JPP { using namespace JTRIGGER; }
21 
22 namespace JTRIGGER {
23 
24  using JDETECTOR::JModule;
28 
29 
30  /**
31  * Module attributes.
32  */
33  struct JAttributes {
34  double Tmin_ns; //!< minimal time difference [ns]
35  double Tmax_ns; //!< maximal time difference [ns]
36  };
37 
38 
39  /**
40  * Set module attributes.
41  *
42  * \param first first module
43  * \param second second module
44  * \param attributes module attributes
45  */
46  inline void setAttributes(const JModule& first,
47  const JModule& second,
48  JAttributes& attributes)
49  {
50  using namespace JMATH;
51  using namespace JTOOLS;
52 
53  typedef JTriggerMXShower_t::JParameters JParameters_t;
54 
55  // get trigger parameters
56 
57  const JParameters_t& parameters = JParametersHelper<JParameters_t>::getParameters();
58 
59  const double d = getDistance(first, second);
60 
61  double t1 = 0.0;
62 
63  if (d <= 0.5 * parameters.DMax_m)
64  t1 = d * getIndexOfRefraction() * getInverseSpeedOfLight() + parameters.TMaxExtra_ns;
65  else if (d <= parameters.DMax_m)
66  t1 = (parameters.DMax_m - d) * getIndexOfRefraction() * getInverseSpeedOfLight() + parameters.TMaxExtra_ns;
67 
68  attributes.Tmin_ns = -t1;
69  attributes.Tmax_ns = +t1;
70  }
71 
72 
73  /**
74  * Shower trigger.
75  */
77  public JTriggerMXShower_t,
78  public JTriggerInterface
79  {
80  public:
81 
82  /**
83  * Type definition of module mapper.
84  */
86 
87 
88  /**
89  * Constructor.
90  *
91  * \param input trigger parameters
92  * \param detector detector;
93  */
95  const JDetector& detector) :
96  parameters(input),
97  mapper(detector, JMaximalDistance(parameters.DMax_m)),
98  match(parameters.DMax_m, parameters.TMaxExtra_ns)
99  {
100  using namespace JTOOLS;
101 
102  TMaxEvent_ns = parameters.DMax_m * getIndexOfRefraction() * getInverseSpeedOfLight() + parameters.TMaxExtra_ns;
103 
104  if (parameters.numberOfHits == 0) {
105  parameters.numberOfHits = 1;
106  }
107 
108  if (parameters.numberOfHits == 1) {
109  parameters.factoryLimit = 1;
110  }
111 
112  if (parameters.numberOfModules < 1) {
113  parameters.numberOfModules = 1;
114  }
115  }
116 
117 
118  /**
119  * Process trigger.
120  *
121  * \param inputL1 input L1 data
122  * \param inputL0 input L0 data
123  * \param out output data
124  */
125  template<class JElement_t>
126  void operator()(const JTriggerInput& inputL1,
127  const JTimeslice<JElement_t> inputL0,
128  std::back_insert_iterator<JTriggerOutput> out) const
129  {
131  typedef typename JTimeslice_t::value_type JFrame_t;
132  typedef typename JModuleMapper_t::container_type container_type;
133 
134  if (parameters.enabled) {
135 
136  JTimeslice_t clone(inputL0, mapper);
137 
138  for (JTriggerInput::const_iterator root = inputL1.begin(); root != inputL1.end(); ++root) {
139 
140  buffer.clear();
141 
142  const container_type& zip = mapper.getList(root->getModuleID());
143 
144  for (typename container_type::const_iterator mod = zip.begin(); mod != zip.end(); ++mod) {
145 
146  const double Tmin = root->getT() + mod->Tmin_ns;
147  const double Tmax = root->getT() + mod->Tmax_ns;
148 
149  JFrame_t& frame = clone[mod->first];
150 
151  frame.fast_forward(root->getT() - TMaxEvent_ns);
152 
153  for (typename JFrame_t::const_iterator i = frame.get(); *i <= Tmax; ++i) {
154 
155  if (*i >= Tmin) {
156  buffer.push_back(JHitR1(frame.getModuleID(),
157  frame.getPosition(),
158  frame.getJHit(*i)));
159  }
160  }
161  }
162 
163  if (distance (buffer.begin(), buffer.end()) >= parameters.numberOfHits - 1 &&
164  getNumberOfModules(buffer.begin(), buffer.end()) >= parameters.numberOfModules - 1) {
165 
166  if (distance(buffer.begin(), buffer.end()) < parameters.factoryLimit) {
167 
168  JTriggerInput::iterator q = clusterize(buffer.begin(), buffer.end(), match, parameters.numberOfHits - 1);
169 
170  if (distance (buffer.begin(), q) >= parameters.numberOfHits - 1 &&
171  getNumberOfModules(buffer.begin(), q) >= parameters.numberOfModules - 1) {
172  *out = JEvent(inputL1.getDAQChronometer(), *root, buffer.begin(), q, this->getTriggerBit());
173  ++out;
174  }
175 
176  } else {
177 
178  // Anomalous large event
179 
180  *out = JEvent(inputL1.getDAQChronometer(), *root, buffer.begin(), buffer.end(), this->getTriggerBit());
181  ++out;
182  }
183  }
184  }
185  }
186  }
187 
188  private:
193  double TMaxEvent_ns;
194  };
195 }
196 
197 #endif
3G match criterion.
Definition: JMatch3G.hh:29
Auxiliary methods for geometrical methods.
Data structure for a composite optical module.
Definition: JModule.hh:47
Shower trigger parameters.
double getIndexOfRefraction()
Get average index of refraction of water.
Definition: JConstants.hh:111
Detector data structure.
Definition: JDetector.hh:77
static const JParameters_t & getParameters()
Get latest parameters.
Data structure for detector geometry and calibration.
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
Definition: JMathToolkit.hh:98
double Tmin_ns
minimal time difference [ns]
const_iterator end() const
get iterator to end of data (without end marker)
const double getInverseSpeedOfLight()
Get inverse speed of light.
Definition: JConstants.hh:100
Constants.
Auxiliary class to match modules according maximal distance.
JModuleMapper< JAttributes > JModuleMapper_t
Type definition of module mapper.
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
std::vector< JHitR1 > buffer
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
Module attributes.
JTimeslice< hit_type > JTimeslice_t
Definition: JDataFilter.cc:94
void setAttributes(const JModule &first, const JModule &second, JAttributes_t &attributes)
Template method to set module attributes.
double Tmax_ns
maximal time difference [ns]
void operator()(const JTriggerInput &inputL1, const JTimeslice< JElement_t > inputL0, std::back_insert_iterator< JTriggerOutput > out) const
Process trigger.
JParametersHelper< JParameters > parameters
Mapper for directly addressing of associated modules in the detector data structure.
Map of associated modules in detector.
Clone of JTimeslice.
Reduced data structure for L1 hit.
Definition: JHitR1.hh:31
Data structure for input to trigger algorithm.
int getNumberOfModules(const JDetector &detector)
Get number of modules.
JTriggerMXShower(const JParameters &input, const JDetector &detector)
Constructor.
Triggered event.
Definition: JEvent.hh:31
Time slice with calibrated data.
Definition: JTimeslice.hh:26
JTriggerbit_t getTriggerBit()
Get the trigger bit.