Belle II Software  release-08-01-10
HoughPlaneBoolean.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 //-----------------------------------------------------------------------------
10 // Description : A class to represent a Hough parameter plane with simple
11 // counter.
12 //-----------------------------------------------------------------------------
13 
14 #ifndef TRGCDCHoughPlaneBoolean_FLAG_
15 #define TRGCDCHoughPlaneBoolean_FLAG_
16 
17 #include <string.h>
18 #include "trg/cdc/HoughPlaneBase.h"
19 
20 #ifdef TRGCDC_SHORT_NAMES
21 #define TCHPlaneBoolean TRGCDCHoughPlaneBoolean
22 #endif
23 
24 namespace Belle2 {
32 
33  public:
35  TRGCDCHoughPlaneBoolean(const std::string& name,
37  unsigned nX,
38  float xMin,
39  float xMax,
40  unsigned nY,
41  float yMin,
42  float yMax);
43 
45  virtual ~TRGCDCHoughPlaneBoolean();
46 
49 
52 
53  public:// Selectors
54 
56  unsigned entry(unsigned id) const override;
57 
58  unsigned entry(unsigned x, unsigned y) const override;
59  int maxEntry(void) const override;
60 
62  const std::vector<unsigned>& patternId(unsigned cellId) const;
63 
64  public:// Modifiers
65 
67  unsigned setEntry(unsigned serialId, unsigned n) override;
68 
70  // cppcheck-suppress virtualCallInConstructor
71  void clear(void) override;
72 
74  void vote(float rx,
75  float ry,
76  int weight = 1) override;
77 
78 #ifdef __clang__
79 #pragma clang diagnostic push
80 #pragma clang diagnostic ignored "-Woverloaded-virtual"
81 #endif
82 
84  // using TRGCDCHoughPlaneBase::vote; // to be checked
85  void vote(float rx,
86  float ry,
87  float charge,
88  int weight = 1);
89 
91  // using TRGCDCHoughPlaneBase::vote; // to be checked
92  void vote(unsigned patternId, int weight);
93 
94 #ifdef __clang__
95 #pragma clang diagnostic pop
96 #endif
97 
99  void voteUsedInTrasan(float rx,
100  float ry,
101  float charge,
102  int weight = 1);
103 
105  void registerPattern(unsigned id) override;
106 
108  void preparePatterns(unsigned nPatterns);
109 
110  protected:
111 
113  void add(unsigned cellId, int weight) override;
114 
115  private:
117  unsigned _n;
119  unsigned* const _cell;
121  unsigned _nPatterns;
123  unsigned** _patterns;
125  unsigned* _nActive;
126 
128  std::vector<unsigned>* _reverse;
129 
130  friend class TRGCDCHoughPlaneMulti2;
131  };
132 
133 //-----------------------------------------------------------------------------
134 
135  inline
136  unsigned
137  TRGCDCHoughPlaneBoolean::setEntry(unsigned serialId, unsigned n)
138  {
139  const unsigned b0 = serialId / 32;
140  const unsigned b1 = serialId % 32;
141 
142 #ifdef TRASAN_DEBUG
143  if (b0 >= _n)
144  std::cout << "TRGCDCHoughPlaneBoolean !!! given serialId is too large : "
145  << "max=" << _n * 32 << ",serialId=" << serialId << std::endl;
146 #endif
147 
148  if (n > 0)
149  _cell[b0] |= (1 << b1);
150  else
151  _cell[b0] &= (~(1 << b1));
152 
153  return (_cell[b0] >> b1) & 1;
154  }
155 
156  inline
157  void
159  {
160  memset(_cell, 0, _n * sizeof(unsigned));
162  }
163 
164  inline
165  void
167  float ry,
168  int weight)
169  {
170  vote(rx, ry, 0, weight);
171  }
172 
173  inline
174  unsigned
175  TRGCDCHoughPlaneBoolean::entry(unsigned serialId) const
176  {
177  const unsigned b0 = serialId / 32;
178  const unsigned b1 = serialId % 32;
179 
180 #ifdef TRASAN_DEBUG
181  if (b0 >= _n)
182  std::cout << "TRGCDCHoughPlaneBoolean::entry !!! given serialId is too large"
183  << " : "
184  << "max=" << _n * 32 << ",serialId=" << serialId << std::endl;
185 #endif
186 
187  return (_cell[b0] >> b1) & 1;
188  }
189 
190  inline
191  unsigned
192  TRGCDCHoughPlaneBoolean::entry(unsigned x, unsigned y) const
193  {
194  return entry(nY() * x + y);
195  }
196 
197  inline
198  int
200  {
201 #ifdef TRASAN_DEBUG
202  std::cout << "TRGCDCHoughPlaneBoolean::maxEntry !!! "
203  << " this function has no meaning for TRGCDCHoughPlaneBooolean object"
204  << std::endl;
205 #endif
206  return 1;
207  }
208 
209  inline
210  void
211  TRGCDCHoughPlaneBoolean::add(unsigned a, int b)
212  {
213  if (b > 0)
214  setEntry(a, 1);
215  else
216  setEntry(a, 0);
217  }
218 
219  inline
220  const std::vector<unsigned>&
221  TRGCDCHoughPlaneBoolean:: patternId(unsigned cellId) const
222  {
223  return _reverse[cellId];
224  }
225 
227 } // namespace Belle2
228 
229 #endif
A class to represent a Hough parameter plane.
A class to represent a Hough parameter plane.
unsigned _n
nX * nY / 32 + 1
unsigned _nPatterns
number of patterns
TRGCDCHoughPlaneBoolean & operator=(TRGCDCHoughPlaneBoolean &)=delete
Assignement operator, delete.
std::vector< unsigned > * _reverse
Pattern ID's for each cell.
unsigned * _nActive
number of active cells
TRGCDCHoughPlaneBoolean(TRGCDCHoughPlaneBoolean &)=delete
Copy constructor, deleted.
A class to represent a Hough parameter plane.
An abstract class to represent a Hough transformation.
void registerPattern(unsigned id) override
registers a pattern..
virtual void clear(void)=0
Clears all entries.
float xMin(void) const
returns min. of x.
void voteUsedInTrasan(float rx, float ry, float charge, int weight=1)
Votes with charge decision.
unsigned nY(void) const
return # of y bins.
void add(unsigned cellId, int weight) override
Add to a cell.
float xMax(void) const
returns max. of x.
void preparePatterns(unsigned nPatterns)
allocate memory for patterns.
void vote(float rx, float ry, int weight=1) override
Votes.
float charge(void) const
returns charge for this plane.
unsigned serialId(unsigned x, unsigned y) const
returns serial ID for position (x, y).
int maxEntry(void) const override
returns max. count in a plane.
float yMax(void) const
returns max. of y.
TRGCDCHoughPlaneBoolean(const std::string &name, const TRGCDCHoughTransformation &transformation, unsigned nX, float xMin, float xMax, unsigned nY, float yMin, float yMax)
Contructor.
const std::vector< unsigned > & patternId(unsigned cellId) const
returns pattern ID which activates specified cell.
void clear(void) override
clear all entries.
const TRGCDCHoughTransformation & transformation(void) const
returns Hough transformation object.
std::string name(void) const
returns name.
unsigned entry(unsigned id) const override
returns entry in a cell.
unsigned nX(void) const
returns # of x bins.
float yMin(void) const
returns min. of y.
virtual ~TRGCDCHoughPlaneBoolean()
Destructor.
unsigned setEntry(unsigned serialId, unsigned n) override
Sets entry.
Abstract base class for different kinds of events.