Belle II Software  release-05-01-25
HoughPlaneBoolean.h
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : HoughPlaneBoolean.h
5 // Section : TRG CDC
6 // Owner : Yoshihito Iwasaki
7 // Email : yoshihito.iwasaki@kek.jp
8 //-----------------------------------------------------------------------------
9 // Description : A class to represent a Hough parameter plane with simple
10 // counter.
11 //-----------------------------------------------------------------------------
12 // $Log$
13 //-----------------------------------------------------------------------------
14 
15 #ifndef TRGCDCHoughPlaneBoolean_FLAG_
16 #define TRGCDCHoughPlaneBoolean_FLAG_
17 
18 #include <string.h>
19 #include "trg/cdc/HoughPlaneBase.h"
20 
21 #ifdef TRGCDC_SHORT_NAMES
22 #define TCHPlaneBoolean TRGCDCHoughPlaneBoolean
23 #endif
24 
25 namespace Belle2 {
31  class TRGCDCHoughPlaneBoolean : public TRGCDCHoughPlaneBase {
33 
34  public:
36  TRGCDCHoughPlaneBoolean(const std::string& name,
37  const TRGCDCHoughTransformation& transformation,
38  unsigned nX,
39  float xMin,
40  float xMax,
41  unsigned nY,
42  float yMin,
43  float yMax);
44 
46  virtual ~TRGCDCHoughPlaneBoolean();
47 
48  public:// Selectors
49 
51  unsigned entry(unsigned id) const override;
52 
53  unsigned entry(unsigned x, unsigned y) const override;
54  int maxEntry(void) const override;
55 
57  const std::vector<unsigned>& patternId(unsigned cellId) const;
58 
59  public:// Modifiers
60 
62  unsigned setEntry(unsigned serialId, unsigned n) override;
63 
65  void clear(void) override;
66 
68  void vote(float rx,
69  float ry,
70  int weight = 1) override;
71 
73  // using TRGCDCHoughPlaneBase::vote; // to be checked
74  void vote(float rx,
75  float ry,
76  float charge,
77  int weight = 1);
78 
80  void voteUsedInTrasan(float rx,
81  float ry,
82  float charge,
83  int weight = 1);
84 
86  // using TRGCDCHoughPlaneBase::vote; // to be checked
87  void vote(unsigned patternId, int weight);
88 
90  void registerPattern(unsigned id) override;
91 
93  void preparePatterns(unsigned nPatterns);
94 
95  protected:
96 
98  void add(unsigned cellId, int weight) override;
99 
100  private:
102  unsigned _n;
104  unsigned* const _cell;
106  unsigned _nPatterns;
108  unsigned** _patterns;
110  unsigned* _nActive;
111 
113  std::vector<unsigned>* _reverse;
114 
115  friend class TRGCDCHoughPlaneMulti2;
116  };
117 
118 //-----------------------------------------------------------------------------
119 
120  inline
121  unsigned
122  TRGCDCHoughPlaneBoolean::setEntry(unsigned serialId, unsigned n)
123  {
124  const unsigned b0 = serialId / 32;
125  const unsigned b1 = serialId % 32;
126 
127 #ifdef TRASAN_DEBUG
128  if (b0 >= _n)
129  std::cout << "TRGCDCHoughPlaneBoolean !!! given serialId is too large : "
130  << "max=" << _n * 32 << ",serialId=" << serialId << std::endl;
131 #endif
132 
133  if (n > 0)
134  _cell[b0] |= (1 << b1);
135  else
136  _cell[b0] &= (~(1 << b1));
137 
138  return (_cell[b0] >> b1) & 1;
139  }
140 
141  inline
142  void
144  {
145  memset(_cell, 0, _n * sizeof(unsigned));
147  }
148 
149  inline
150  void
152  float ry,
153  int weight)
154  {
155  vote(rx, ry, 0, weight);
156  }
157 
158  inline
159  unsigned
160  TRGCDCHoughPlaneBoolean::entry(unsigned serialId) const
161  {
162  const unsigned b0 = serialId / 32;
163  const unsigned b1 = serialId % 32;
164 
165 #ifdef TRASAN_DEBUG
166  if (b0 >= _n)
167  std::cout << "TRGCDCHoughPlaneBoolean::entry !!! given serialId is too large"
168  << " : "
169  << "max=" << _n * 32 << ",serialId=" << serialId << std::endl;
170 #endif
171 
172  return (_cell[b0] >> b1) & 1;
173  }
174 
175  inline
176  unsigned
177  TRGCDCHoughPlaneBoolean::entry(unsigned x, unsigned y) const
178  {
179  return entry(nY() * x + y);
180  }
181 
182  inline
183  int
185  {
186 #ifdef TRASAN_DEBUG
187  std::cout << "TRGCDCHoughPlaneBoolean::maxEntry !!! "
188  << " this function has no meaning for TRGCDCHoughPlaneBooolean object"
189  << std::endl;
190 #endif
191  return 1;
192  }
193 
194  inline
195  void
196  TRGCDCHoughPlaneBoolean::add(unsigned a, int b)
197  {
198  if (b > 0)
199  setEntry(a, 1);
200  else
201  setEntry(a, 0);
202  }
203 
204  inline
205  const std::vector<unsigned>&
206  TRGCDCHoughPlaneBoolean:: patternId(unsigned cellId) const
207  {
208  return _reverse[cellId];
209  }
210 
212 } // namespace Belle2
213 
214 #endif
Belle2::TRGCDCHoughPlaneBoolean::clear
void clear(void) override
clear all entries.
Definition: HoughPlaneBoolean.h:143
Belle2::TRGCDCHoughPlaneBoolean::_n
unsigned _n
nX * nY / 32 + 1
Definition: HoughPlaneBoolean.h:102
Belle2::TRGCDCHoughPlaneBoolean::maxEntry
int maxEntry(void) const override
returns max. count in a plane.
Definition: HoughPlaneBoolean.h:184
Belle2::TRGCDCHoughPlaneBase::yMax
float yMax(void) const
returns max. of y.
Definition: HoughPlaneBase.h:320
Belle2::TRGCDCHoughPlaneBoolean::vote
void vote(float rx, float ry, int weight=1) override
Votes.
Definition: HoughPlaneBoolean.h:151
Belle2::TRGCDCHoughPlaneBase::serialId
unsigned serialId(unsigned x, unsigned y) const
returns serial ID for position (x, y).
Definition: HoughPlaneBase.h:343
Belle2::TRGCDCHoughPlaneBase::name
std::string name(void) const
returns name.
Definition: HoughPlaneBase.h:244
Belle2::TRGCDCHoughPlaneBase::charge
float charge(void) const
returns charge for this plane.
Definition: HoughPlaneBase.h:230
Belle2::TRGCDCHoughPlaneBoolean::setEntry
unsigned setEntry(unsigned serialId, unsigned n) override
Sets entry.
Definition: HoughPlaneBoolean.h:122
Belle2::TRGCDCHoughPlaneBoolean::_cell
unsigned *const _cell
cell
Definition: HoughPlaneBoolean.h:104
Belle2::TRGCDCHoughPlaneBoolean::add
void add(unsigned cellId, int weight) override
Add to a cell.
Definition: HoughPlaneBoolean.h:196
Belle2::TRGCDCHoughPlaneMulti2
A class to represent a Hough parameter plane.
Definition: HoughPlaneMulti2.h:34
Belle2::TRGCDCHoughPlaneBoolean::_patterns
unsigned ** _patterns
patterns
Definition: HoughPlaneBoolean.h:108
Belle2::TRGCDCHoughPlaneBase::nY
unsigned nY(void) const
return # of y bins.
Definition: HoughPlaneBase.h:297
Belle2::TRGCDCHoughPlaneBase::clear
virtual void clear(void)=0
Clears all entries.
Definition: HoughPlaneBase.h:500
Belle2::TRGCDCHoughPlaneBoolean::entry
unsigned entry(unsigned id) const override
returns entry in a cell.
Definition: HoughPlaneBoolean.h:160
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TRGCDCHoughPlaneBoolean::_nActive
unsigned * _nActive
number of active cells
Definition: HoughPlaneBoolean.h:110
Belle2::TRGCDCHoughPlaneBoolean::registerPattern
void registerPattern(unsigned id) override
registers a pattern..
Definition: HoughPlaneBoolean.cc:210
Belle2::TRGCDCHoughPlaneBase::transformation
const TRGCDCHoughTransformation & transformation(void) const
returns Hough transformation object.
Definition: HoughPlaneBase.h:523
Belle2::TRGCDCHoughPlaneBoolean::~TRGCDCHoughPlaneBoolean
virtual ~TRGCDCHoughPlaneBoolean()
Destructor.
Definition: HoughPlaneBoolean.cc:47
Belle2::TRGCDCHoughPlaneBoolean::_nPatterns
unsigned _nPatterns
number of patterns
Definition: HoughPlaneBoolean.h:106
Belle2::TRGCDCHoughPlaneBase::xMin
float xMin(void) const
returns min. of x.
Definition: HoughPlaneBase.h:258
Belle2::TRGCDCHoughPlaneBoolean::preparePatterns
void preparePatterns(unsigned nPatterns)
allocate memory for patterns.
Definition: HoughPlaneBoolean.cc:256
Belle2::TRGCDCHoughPlaneBoolean::voteUsedInTrasan
void voteUsedInTrasan(float rx, float ry, float charge, int weight=1)
Votes with charge decision.
Definition: HoughPlaneBoolean.cc:142
Belle2::TRGCDCHoughPlaneBase::xMax
float xMax(void) const
returns max. of x.
Definition: HoughPlaneBase.h:274
Belle2::TRGCDCHoughPlaneBoolean::patternId
const std::vector< unsigned > & patternId(unsigned cellId) const
returns pattern ID which activates specified cell.
Definition: HoughPlaneBoolean.h:206
Belle2::TRGCDCHoughPlaneBoolean::_reverse
std::vector< unsigned > * _reverse
Pattern ID's for each cell.
Definition: HoughPlaneBoolean.h:113
Belle2::TRGCDCHoughPlaneBase::nX
unsigned nX(void) const
returns # of x bins.
Definition: HoughPlaneBase.h:251
Belle2::TRGCDCHoughPlaneBase::yMin
float yMin(void) const
returns min. of y.
Definition: HoughPlaneBase.h:304
Belle2::TRGCDCHoughPlaneBoolean::TRGCDCHoughPlaneBoolean
TRGCDCHoughPlaneBoolean(const std::string &name, const TRGCDCHoughTransformation &transformation, unsigned nX, float xMin, float xMax, unsigned nY, float yMin, float yMax)
Contructor.
Definition: HoughPlaneBoolean.cc:28