Jpp  18.2.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JClusterBuilder.hh
Go to the documentation of this file.
1 #ifndef __JCLUSTERBUILDER__
2 #define __JCLUSTERBUILDER__
3 
4 #include<vector>
5 #include<algorithm>
6 #include<set>
7 #include<iterator>
8 
9 #include "JTrigger/JBuildL1.hh"
10 #include "JTrigger/JHitL0.hh"
11 #include "JTrigger/JHitL1.hh"
12 #include "JTrigger/JHitToolkit.hh"
14 #include "JDetector/JModule.hh"
16 #include "JMonitor/JCluster.hh"
17 
18 /**
19  * \author mjongen
20  */
21 
22 namespace JMONITOR {}
23 namespace JPP { using namespace JMONITOR; }
24 
25 namespace JMONITOR {
26  using namespace std ;
27  using namespace JTRIGGER ;
28  using JDETECTOR::JModule ;
30 
31  /**
32  Local coincidence cluster builder.
33 
34  A coincidence cluster is defined as two or more hits on the same DOM
35  within the defined time window.
36 
37  Given a JDAQSuperframe (for the hits) and the corresponding JModule
38  (for the timing) all the coincidence clusters are extracted and sorted
39  by multiplicity.
40 
41  Internally, the clusters are stored as a vector of JClusters
42 
43  \param frame JDAQSuperframe containing the hits
44  \param module module corresponding to the JDAQSuperframe
45  \param window time window used for clustering
46  **/
47  class JClusterBuilder : public JBuildL1<JHitL1>, public vector<JCluster>, public JModule {
48 
49  public :
50 
51  /// default constructor
52  JClusterBuilder(const double window, const bool combine) : JBuildL1<JHitL1>(JBuildL1Parameters(window,combine)), JModule(), max_multiplicity(31), end_iterators(max_multiplicity+2) {
53  // order using std::partition
54  setEndIterators() ;
55  }
56 
57  /// constructor
58  JClusterBuilder( const JDAQSuperFrame& frame, const JModule& module, const double window, const bool combine ) : JBuildL1<JHitL1>(JBuildL1Parameters(window,combine)), JModule(module), max_multiplicity(31), end_iterators(max_multiplicity+2) {
59  // use the () operator of JBuildL1 to build L1s
60  (*this)(frame,module,back_inserter( *( (vector<JCluster>*)this) ) ) ;
61 
62  // order using std::partition
63  setEndIterators() ;
64  }
65 
66  /**
67  This is a way to re-use the allocated memory.
68 
69  It behaves like the constructor, but new memory does not
70  have to be allocated for vector<JCluster> all the time.
71  **/
72  void reset( const JDAQSuperFrame& frame, const JModule& module ) {
73  static_cast<JModule>(*this) = module ;
74 
75  vector<JCluster>::clear() ; // vector is emptied, but memory stays allocated
76  (*this)(frame,module,back_inserter( *( (vector<JCluster>*)this) ) ) ;
77 
78  setEndIterators() ;
79  }
80 
81  /// returns begin iterator for clusters with exactly the given multiplicity
82  vector<JCluster>::const_iterator begin_m( unsigned int multiplicity ) const {
83  // restrict to allowed range
84  multiplicity = max( (unsigned int)0,multiplicity) ;
85  multiplicity = min(max_multiplicity,multiplicity) ;
86  return end_iterators[multiplicity+1] ;
87  }
88 
89  /// returns end iterator for clusters with exactly the given multiplicity
90  vector<JCluster>::const_iterator end_m( unsigned int multiplicity ) const {
91  // restrict to allowed range
92  multiplicity = max( (unsigned int)0,multiplicity) ;
93  multiplicity = min(max_multiplicity,multiplicity) ;
94  return end_iterators[multiplicity] ;
95  }
96 
97  /// returns begin iterator for clusters with at least the given multiplicity
98  vector<JCluster>::const_iterator begin_inclusive_m( unsigned int multiplicity ) const {
99  return end_iterators[max_multiplicity+1] ;
100  }
101 
102  /// returns end iterator for clusters with at least the given multiplicity
103  vector<JCluster>::const_iterator end_inclusive_m( unsigned int multiplicity ) const {
104  return end_m(multiplicity) ;
105  }
106 
107  /// return the number of clusters with exactly the given multiplicity
108  unsigned int getNclusters( const unsigned int multiplicity ) const {
109  return distance( begin_m(multiplicity), end_m(multiplicity) ) ;
110  }
111 
112  /// return the number of clusters with at least the given multiplicity
113  unsigned int getInclusiveNclusters( const unsigned int multiplicity ) const {
114  return distance( begin_inclusive_m(multiplicity), end_inclusive_m(multiplicity) ) ;
115  }
116 
117  protected :
118 
119  /**
120  Use std::partition to sort the clusters in order of decreasing multiplicity.
121  The end_iterators denote the boundaries.
122  **/
124  end_iterators[0] = vector<JCluster>::end() ;
125  for( unsigned int m=max_multiplicity; m>0; --m ) {
126  end_iterators[m] = partition( vector<JCluster>::begin(), vector<JCluster>::end(), MinimalMultiplicityFunctor(m) ) ;
127  }
128  end_iterators[max_multiplicity+1] = vector<JCluster>::begin() ;
129  }
130 
131  /**
132  functor that compares the multiplicity of a JCluster to some fixed given
133  multiplicity.
134  **/
136  public :
137 
138  MinimalMultiplicityFunctor( const unsigned int _m ) : m(_m) {}
139 
140  bool operator()(const JCluster& cluster) const {
141  return cluster.getMultiplicity() >= m ;
142  }
143 
144  protected :
145 
146  const unsigned int m ;
147  } ;
148 
149  /// the highest allowed value for the multiplicity
150  const unsigned int max_multiplicity ;
151 
152  /**
153  iterators pointing to the first element whose multiplicity is
154  lower than the index
155  **/
157  } ;
158 
159 }
160 
161 #endif
A JHitL1 with a multiplicity.
Definition: JCluster.hh:34
functor that compares the multiplicity of a JCluster to some fixed given multiplicity.
unsigned int getMultiplicity() const
Returns the multiplicity evaluated at the last call to setMultiplicity.
Definition: JCluster.hh:50
JClusterBuilder(const JDAQSuperFrame &frame, const JModule &module, const double window, const bool combine)
constructor
Data structure for L1 hit.
Definition: JHitL1.hh:34
Data structure for a composite optical module.
Definition: JModule.hh:68
unsigned int getInclusiveNclusters(const unsigned int multiplicity) const
return the number of clusters with at least the given multiplicity
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
void reset(const JDAQSuperFrame &frame, const JModule &module)
This is a way to re-use the allocated memory.
vector< JCluster >::const_iterator end_m(unsigned int multiplicity) const
returns end iterator for clusters with exactly the given multiplicity
void setEndIterators()
Use std::partition to sort the clusters in order of decreasing multiplicity.
Tools for handling different hit types.
Basic data structure for L0 hit.
vector< vector< JCluster >::iterator > end_iterators
iterators pointing to the first element whose multiplicity is lower than the index ...
JClusterBuilder(const double window, const bool combine)
default constructor
bool operator()(const JCluster &cluster) const
vector< JCluster >::const_iterator end_inclusive_m(unsigned int multiplicity) const
returns end iterator for clusters with at least the given multiplicity
const unsigned int max_multiplicity
the highest allowed value for the multiplicity
JRange< T, JComparator_t > combine(const JRange< T, JComparator_t > &first, const JRange< T, JComparator_t > &second)
Combine ranges.
Definition: JRange.hh:676
Template L1 hit builder.
Definition: JBuildL1.hh:85
unsigned int getNclusters(const unsigned int multiplicity) const
return the number of clusters with exactly the given multiplicity
vector< JCluster >::const_iterator begin_inclusive_m(unsigned int multiplicity) const
returns begin iterator for clusters with at least the given multiplicity
Auxiliary data structure for L1 build parameters.
Definition: JBuildL1.hh:37
Local coincidence cluster builder.
Data frame of one optical module.
vector< JCluster >::const_iterator begin_m(unsigned int multiplicity) const
returns begin iterator for clusters with exactly the given multiplicity
Basic data structure for L1 hit.
Data structure for optical module.