QwAnalysis
QwHitPattern.h
Go to the documentation of this file.
1 /*!
2  * \file QwHitPattern.h
3  * \brief Definition of the hit patterns used in the tracking tree search
4  *
5  * \author Wouter Deconinck
6  * \date 2009-12-08
7  */
8 
9 #ifndef QWHITPATTERN_H
10 #define QWHITPATTERN_H
11 
12 // System headers
13 #include <iostream>
14 
15 // Qweak headers
16 #include "VQwTrackingElement.h"
17 #include "QwObjectCounter.h"
18 
19 // Forward declarations
20 class QwHit;
21 class QwHitContainer;
22 
23 /**
24  * \class QwHitPattern
25  * \ingroup QwTracking
26  * \brief Hit patterns used in the tracking tree search
27  *
28  * The hit patterns used in the tree search have a rather peculiar format.
29  * Each level of depth in the pattern has a resolution that is twice as good
30  * as the previous level. The top level has a resolution of one, meaning that
31  * one bit indicates whether a track is present or not. The second level has
32  * two bits, etc.
33  *
34  * A pattern is stored for every layer of the tracking detector (or every wire
35  * in the case of the VDCs, where the interpretation is rotated over 90 degrees).
36  *
37  * The options file indicates the number of tree levels (how many times we
38  * go to finer binning). The total number of bits is determined using
39  * bit shift operators:
40  * Total number of bins + 1 = (1UL << levels) == 2^levels
41  * Number of bins at bottom = (1UL << (levels - 1)) == 2^(levels-1)
42  * For e.g. 4 levels we need 1 + 2 + 4 + 8 = 15 = (2^4 - 1) bits.
43  */
44 class QwHitPattern: public VQwTrackingElement, public QwObjectCounter<QwHitPattern> {
45 
46  public:
47 
48  /// \brief Default constructor
51  { };
52  /// \brief Constructor with hit pattern depth
53  QwHitPattern(const unsigned int levels)
54  : fLevels(levels),fBins(0),fBinWidth(0),fPattern(0),fPatternHash(0)
55  {
56  SetNumberOfLevels(levels);
57  Reset();
58  };
59  /// \brief Copy constructor
60  QwHitPattern(const QwHitPattern& pattern)
61  : VQwTrackingElement(pattern),QwObjectCounter<QwHitPattern>(pattern),
62  fLevels(pattern.fLevels),
63  fBins(pattern.fBins),fBinWidth(pattern.fBinWidth)
64  {
65  fPattern = new unsigned char[fBins];
66  for (unsigned int bin = 0; bin < fBins; bin++)
67  fPattern[bin] = pattern.fPattern[bin];
68  fPatternHash = new unsigned int[fBinWidth];
69  for (unsigned int hash = 0; hash < fBinWidth; hash++)
70  fPatternHash[hash] = pattern.fPatternHash[hash];
71  };
72 
73  /// \brief Delete the hit pattern
74  virtual ~QwHitPattern() {
75  if (fLevels == 0) return;
76  if (fPattern) delete[] fPattern;
77  if (fPatternHash) delete[] fPatternHash;
78  };
79 
80  /// \brief Set the hit pattern depth
81  void SetNumberOfLevels(const unsigned int levels) {
82  fLevels = levels;
83  if (fLevels == 0) return;
84  fBins = (1UL << fLevels); // total number of bins, i.e. 2^fLevels
85  fBinWidth = (1UL << (fLevels - 1)); // maximum bin division, i.e. 2^(fLevels-1)
86  fPattern = new unsigned char[fBins];
87  fPatternHash = new unsigned int[fBinWidth];
88  };
89  /// \brief Get the hit pattern depth
90  unsigned int GetNumberOfLevels() const { return fLevels; };
91  /// \brief Get the number of bins
92  unsigned int GetNumberOfBins() const { return fBins; };
93  /// \brief Get the finest bin width
94  unsigned int GetFinestBinWidth() const { return fBinWidth; };
95 
96  /// \brief Reset the contents of the hit pattern
97  void Reset() {
98  for (unsigned int bin = 0; bin < fBins; bin++)
99  fPattern[bin] = 0;
100  for (unsigned int hash = 0; hash < fBinWidth; hash++)
101  fPatternHash[hash] = 0;
102  };
103 
104  /// \brief Set the hit pattern bins for the specified HDC-type hit
105  void SetHDCHit(double detectorwidth, QwHit* hit);
106  /// \brief Set the hit pattern bins for the specified VDC-type hit
107  void SetVDCHit(double detectorwidth, QwHit* hit);
108  /// \brief Set the hit pattern bins for the specified HDC-type hit list
109  void SetHDCHitList(double detectorwidth, QwHitContainer* hitlist);
110  /// \brief Set the hit pattern bins for the specified VDC-type hit list
111  void SetVDCHitList(double detectorwidth, QwHitContainer* hitlist);
112 
113  /// \brief Has this pattern any hit?
114  bool HasHits() const {
115  if (fPattern == 0) return false;
116  else return fPattern[fBins-2] == 1;
117  };
118 
119  /// \brief Get the hit pattern
120  void GetPattern(char* pattern) const {
121  for (unsigned int bin = 0; bin < fBins; bin++)
122  pattern[bin] = fPattern[bin];
123  };
124  /// \brief Get the hit pattern hash
125  void GetPatternHash(int* patternhash) const {
126  for (unsigned int hash = 0; hash < fBinWidth; hash++)
127  patternhash[hash] = fPatternHash[hash];
128  };
129 
130  /// \brief Assignment operator
131  QwHitPattern& operator=(const QwHitPattern& rhs);
132  /// \brief Addition-assignment operator
133  QwHitPattern& operator+=(const QwHitPattern& rhs);
134 
135  private:
136 
137  /// \brief Recursive tree pattern method on a point with resolution
138  void _SetPoint (double position, double resolution, double detectorwidth);
139 
140  /// \brief Recursive tree pattern method on a range of points
141  void _SetPoints (double pos_start, double pos_end, double detectorwidth);
142 
143 
144  unsigned int fLevels; ///< Depth of the tree search
145 
146  unsigned int fBins; ///< Number of bins
147  unsigned int fBinWidth; ///< Width of each bin
148 
149  unsigned char* fPattern; //! ///< Hit pattern
150  unsigned int* fPatternHash; //! ///< Hash of the hit pattern
151 
152  friend std::ostream& operator<< (std::ostream& stream, const QwHitPattern& hitpattern);
153 
155 
156 }; // class QwHitPattern
157 
158 #endif // QWHITPATTERN_H
QwHitPattern & operator+=(const QwHitPattern &rhs)
Addition-assignment operator.
Definition: QwHitPattern.cc:73
bool HasHits() const
Has this pattern any hit?
Definition: QwHitPattern.h:114
unsigned int fLevels
Depth of the tree search.
Definition: QwHitPattern.h:144
unsigned int fBinWidth
Width of each bin.
Definition: QwHitPattern.h:147
Hit patterns used in the tracking tree search.
Definition: QwHitPattern.h:44
unsigned char * fPattern
Definition: QwHitPattern.h:149
Memory management structure to count objects.
unsigned int GetNumberOfLevels() const
Get the hit pattern depth.
Definition: QwHitPattern.h:90
void SetHDCHitList(double detectorwidth, QwHitContainer *hitlist)
Set the hit pattern bins for the specified HDC-type hit list.
Definition: QwHitPattern.cc:93
friend std::ostream & operator<<(std::ostream &stream, const QwHitPattern &hitpattern)
///&lt; Hash of the hit pattern
void _SetPoint(double position, double resolution, double detectorwidth)
Recursive tree pattern method on a point with resolution.
void SetVDCHitList(double detectorwidth, QwHitContainer *hitlist)
Set the hit pattern bins for the specified VDC-type hit list.
unsigned int GetFinestBinWidth() const
Get the finest bin width.
Definition: QwHitPattern.h:94
QwHitPattern(const unsigned int levels)
Constructor with hit pattern depth.
Definition: QwHitPattern.h:53
Memory management class to count object instantiations.
QwHitPattern & operator=(const QwHitPattern &rhs)
Assignment operator.
Definition: QwHitPattern.cc:38
void SetNumberOfLevels(const unsigned int levels)
Set the hit pattern depth.
Definition: QwHitPattern.h:81
void GetPatternHash(int *patternhash) const
Get the hit pattern hash.
Definition: QwHitPattern.h:125
ClassDef(QwHitPattern, 1)
QwHitPattern(const QwHitPattern &pattern)
Copy constructor.
Definition: QwHitPattern.h:60
Definition of virtual base class for all tracking elements.
virtual ~QwHitPattern()
Delete the hit pattern.
Definition: QwHitPattern.h:74
void SetHDCHit(double detectorwidth, QwHit *hit)
Set the hit pattern bins for the specified HDC-type hit.
void SetVDCHit(double detectorwidth, QwHit *hit)
Set the hit pattern bins for the specified VDC-type hit.
unsigned int * fPatternHash
///&lt; Hit pattern
Definition: QwHitPattern.h:150
void _SetPoints(double pos_start, double pos_end, double detectorwidth)
Recursive tree pattern method on a range of points.
Hit structure uniquely defining each hit.
Definition: QwHit.h:43
unsigned int fBins
Number of bins.
Definition: QwHitPattern.h:146
void Reset()
Reset the contents of the hit pattern.
Definition: QwHitPattern.h:97
unsigned int GetNumberOfBins() const
Get the number of bins.
Definition: QwHitPattern.h:92
void GetPattern(char *pattern) const
Get the hit pattern.
Definition: QwHitPattern.h:120
QwHitPattern()
Default constructor.
Definition: QwHitPattern.h:49
Virtual base class for all tracking elements.