]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/src/RegionOfInterest.hpp
This commit was generated by cvs2svn to compensate for changes in r11742,
[u/mrichter/AliRoot.git] / HLT / MUON / src / RegionOfInterest.hpp
CommitLineData
8356cc1d 1////////////////////////////////////////////////////////////////////////////////
2//
3// Author: Artur Szostak
4// Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
5//
6////////////////////////////////////////////////////////////////////////////////
7
8#ifndef dHLT_REGION_OF_INTEREST_HPP
9#define dHLT_REGION_OF_INTEREST_HPP
10
11#include "BasicTypes.hpp"
12#include "Utils.hpp"
13#include "Cluster.hpp"
14
15namespace dHLT
16{
17
18
19const Int NUMBER_OF_TRACKING_CHAMBERS = 10;
20
21typedef UInt ROI;
22
23enum
24{
25 INVALID_ROI = 0xFFFFFFFF
26};
27
28
29/* Identification numbers specifying the tracking chambers of the dimuon
30 spectrometer.
31 */
32enum ChamberID
33{
34 UnknownChamber = -1,
35 Chamber1 = 0,
36 Chamber2 = 1,
37 Chamber3 = 2,
38 Chamber4 = 3,
39 Chamber5 = 4,
40 Chamber6 = 5,
41 Chamber7 = 6,
42 Chamber8 = 7,
43 Chamber9 = 8,
44 Chamber10 = 9
45};
46
47
48/* The region of interest object is used to encode/decode and work with boundary
49 box type regions of interest. The 32 bit ROI codes are used to communicate
50 regions of interest between different parts of the dHLT system. This is more
51 efficient than sending 20 byte long region of interest objects.
52 */
53class RegionOfInterest
54{
55public:
56
57 RegionOfInterest()
58 {
59 chamber = Chamber1;
60 left = right = top = bottom = 0.0;
61 };
62
63 /* This constructor decodes the ROI bit pattern into a region of
64 interest object.
65 */
66 RegionOfInterest(const ROI& code)
67 {
68 Decode(code);
69 };
70
71 /* Creates a region of interest around the given point for the
72 specified chamber.
73 */
74 RegionOfInterest(const ClusterPoint& point, const ChamberID chamber)
75 {
76 CreateToContain(point, chamber);
77 };
78
79 /* Creates a region of interest around all the given points and for the
80 specified chamber.
81 */
82 RegionOfInterest(const ClusterPoint* points, const UInt count, const ChamberID chamber)
83 {
84 CreateToContain(points, count, chamber);
85 };
86
87 /* Creates a region of interest with the specified boundaries and for
88 the specified chamber.
89 */
90 RegionOfInterest(const Float left, const Float right, const Float bottom, const Float top, const ChamberID chamber)
91 {
92 Assert( 0 <= chamber and chamber < NUMBER_OF_TRACKING_CHAMBERS );
93 this->chamber = chamber;
94 this->left = left;
95 this->right = right;
96 this->bottom = bottom;
97 this->top = top;
98 };
99
100
101 /* Checks if the point is contained in this region of interest.
102 */
103 bool Contains(const ClusterPoint& point) const
104 {
105 return left <= point.x and point.x <= right and
106 bottom <= point.y and point.y <= top;
107 };
108
109
110 /* Checks if the point is contained in this region of interest and the
111 chamber number corresponds to this region object.
112 */
113 bool Contains(const ClusterPoint& point, const ChamberID chamber) const
114 {
115 return left <= point.x and point.x <= right and
116 bottom <= point.y and point.y <= top and
117 this->chamber == chamber;
118 };
119
120
121 /* Checks if the specified region of interest is contained in this
122 region of interest object.
123 */
124 bool Contains(const RegionOfInterest& roi) const
125 {
126 return chamber == roi.chamber and
127 left <= roi.left and right >= roi.right and
128 bottom <= roi.bottom and top >= roi.top;
129 };
130
131
132 /* Creates a region of interest around the given point for the
133 specified chamber.
134 */
135 void CreateToContain(const ClusterPoint& point, const ChamberID chamber);
136
137 /* Extends the region of interest to contain the specified point.
138 */
139 void ExpandToContain(const ClusterPoint& point);
140
141 /* Creates a region of interest around all the given points and for the
142 specified chamber.
143 */
144 void CreateToContain(const ClusterPoint* points, const UInt count, const ChamberID chamber);
145
146 /* Checks if the region of interest is within the boundaries imposed on
147 the specific chamber plane. This boundary is aproximately the square
148 box around the chamber's detection region.
149 */
150 bool InBounds();
151
152 /* Encodes the region of interest into a 32 bit code.
153 */
154 ROI Encode() const;
155
156 /* Encodes the region of interest into a 32 bit code, and returns the
157 hierarchal level the region was encoded at and the left and right
158 grid coordinate of the bottom left corner of the region boundary box.
159 */
160 ROI Encode(UChar& level, UInt& l, UInt& b) const;
161
162 /* Decodes a 32 bit region of interest code into this region of interest
163 object.
164 */
165 void Decode(const ROI code);
166
167 /* Decodes the chamber number of the region of interest 32 bit code.
168 */
169 static ChamberID DecodeChamber(const ROI code);
170
171 /* Decodes the 32 bit region of interest code into the chamber number,
172 hierarchal level, left and right grid coordinates of the region
173 boundary box.
174 */
175 static void Decode(const ROI code, ChamberID& chamber, UChar& level, UInt& l, UInt& b);
176
177 /* Returns the chamber number of the region of interest.
178 */
179 ChamberID Chamber() const { return chamber; };
180
181 /* Returns the left hand boundary of the region of interest.
182 */
183 Float Left() const { return left; };
184
185 /* Returns the right hand boundary of the region of interest.
186 */
187 Float Right() const { return right; };
188
189 /* Returns the bottom boundary of the region of interest.
190 */
191 Float Bottom() const { return bottom; };
192
193 /* Returns the top boundary of the region of interest.
194 */
195 Float Top() const { return top; };
196
197
198 /* Typecast operator for implicit typecasing to 32 bit ROI codes.
199 */
200 operator ROI () const { return Encode(); };
201
202
203private:
204
205 /* Converts the internal region of interest boundary box, which is
206 specified in as floats, into a regular integer grid.
207 l = left boundary, r = right boundary, b = bottom boundary,
208 t = top boundary.
209 */
210 inline void ConvertToGrid(UInt& l, UInt& r, UInt& b, UInt& t) const;
211
212 /* Performs the inverse conversion of the method ConvertToGrid.
213 That is converts from a regular integer grid back to the internal
214 floating point boundary box specification.
215 */
216 inline void ConvertBackFromGrid(const UInt l, const UInt r, const UInt b, const UInt t);
217
218 /* Internal method for decoding 32 bit region codes. This method is
219 called by the Decode methods.
220 */
221 static void DecodeBits(const ROI code, ChamberID& chamber, UChar& colevel, UInt& l, UInt& b);
222
223
224 // Boundary box scale numbers for each chamber. These are the boundary
225 // boxes around the chambers detection surface.
226 static Float planescale[NUMBER_OF_TRACKING_CHAMBERS];
227
228 static UInt indexoffsets[13]; // Offset numbers used in the encoding and decoding process.
229
230
231 ChamberID chamber; // Specifies the chamber the region of interest is on.
232 Float left; // Left boundary of boundary box.
233 Float right; // Right boundary of boundary box.
234 Float bottom; // Bottom boundary of boundary box.
235 Float top; // Top boundary of boundary box.
236};
237
238
239} // dHLT
240
241#endif // dHLT_REGION_OF_INTEREST_HPP