]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/src/AliHLTMUONCoreRegionOfInterest.h
Dropping references to AliMUONLocalTrigger which are depricated. This is a temporary...
[u/mrichter/AliRoot.git] / HLT / MUON / src / AliHLTMUONCoreRegionOfInterest.h
1 #ifndef ALIHLTMUONCOREREGIONOFINTEREST_H
2 #define ALIHLTMUONCOREREGIONOFINTEREST_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 ////////////////////////////////////////////////////////////////////////////////
9 //
10 // Author: Artur Szostak
11 // Email:  artur@alice.phy.uct.ac.za | artursz@iafrica.com
12 //
13 // The region of interest object is used to encode/decode and work with boundary
14 // box type regions of interest. The 32 bit ROI codes are used to communicate
15 // regions of interest between different parts of the dHLT system. This is more
16 // efficient than sending 20 byte long region of interest objects.
17 //
18 ////////////////////////////////////////////////////////////////////////////////
19
20 #include "AliHLTMUONBasicTypes.h"
21 #include "AliHLTMUONUtils.h"
22 #include "AliHLTMUONCoreCluster.h"
23
24
25 typedef UInt AliHLTMUONCoreROI;
26
27 enum
28 {
29         kInvalidROI = 0xFFFFFFFF
30 };
31
32
33 /* Identification numbers specifying the tracking chambers of the dimuon
34    spectrometer.
35  */
36 enum AliHLTMUONCoreChamberID
37 {
38         kUnknownChamber = -1,
39         kChamber1 = 0,
40         kChamber2 = 1,
41         kChamber3 = 2,
42         kChamber4 = 3,
43         kChamber5 = 4,
44         kChamber6 = 5,
45         kChamber7 = 6,
46         kChamber8 = 7,
47         kChamber9 = 8,
48         kChamber10 = 9
49 };
50
51
52 class AliHLTMUONCoreRegionOfInterest
53 {
54 public:
55
56         AliHLTMUONCoreRegionOfInterest()
57                 : fChamber(kChamber1), fLeft(0.0), fRight(0.0), fBottom(0.0), fTop(0.0)
58         {
59                 fChamber = kChamber1;
60                 fLeft = fRight = fBottom = fTop = 0.0;
61         }
62         
63         /* This constructor decodes the ROI bit pattern into a region of
64            interest object.
65          */
66         AliHLTMUONCoreRegionOfInterest(const AliHLTMUONCoreROI& code)
67                 : fChamber(kChamber1), fLeft(0.0), fRight(0.0), fBottom(0.0), fTop(0.0)
68         {
69                 Decode(code);
70         }
71
72         /* Creates a region of interest around the given point for the
73            specified chamber.
74          */
75         AliHLTMUONCoreRegionOfInterest(
76                         const AliHLTMUONCoreClusterPoint& point0,
77                         AliHLTMUONCoreChamberID chamber0
78                 )
79                 : fChamber(kChamber1), fLeft(0.0), fRight(0.0), fBottom(0.0), fTop(0.0)
80         {
81                 CreateToContain(point0, chamber0);
82         }
83
84         /* Creates a region of interest around all the given points and for the
85            specified chamber.
86          */
87         AliHLTMUONCoreRegionOfInterest(
88                         const AliHLTMUONCoreClusterPoint* points0, UInt count0,
89                         AliHLTMUONCoreChamberID chamber0
90                 )
91                 : fChamber(kChamber1), fLeft(0.0), fRight(0.0), fBottom(0.0), fTop(0.0)
92         {
93                 CreateToContain(points0, count0, chamber0);
94         }
95
96         /* Creates a region of interest with the specified boundaries and for
97            the specified chamber.
98          */
99         AliHLTMUONCoreRegionOfInterest(
100                         Float left, Float right, Float bottom, Float top,
101                         AliHLTMUONCoreChamberID chamber
102                 );
103
104         /* Checks if the point is contained in this region of interest.
105          */
106         bool Contains(const AliHLTMUONCoreClusterPoint& point) const;
107
108         /* Checks if the point is contained in this region of interest and the
109            chamber number corresponds to this region object.
110          */
111         bool Contains(
112                         const AliHLTMUONCoreClusterPoint& point,
113                         AliHLTMUONCoreChamberID chamber
114                 ) const;
115
116         /* Checks if the specified region of interest is contained in this
117            region of interest object.
118          */
119         bool Contains(const AliHLTMUONCoreRegionOfInterest& roi) const;
120
121         /* Creates a region of interest around the given point for the
122            specified chamber.
123          */
124         void CreateToContain(
125                         const AliHLTMUONCoreClusterPoint& point,
126                         AliHLTMUONCoreChamberID chamber
127                 );
128
129         /* Extends the region of interest to contain the specified point.
130          */
131         void ExpandToContain(const AliHLTMUONCoreClusterPoint& point);
132
133         /* Creates a region of interest around all the given points and for the
134            specified chamber.
135          */
136         void CreateToContain(
137                         const AliHLTMUONCoreClusterPoint* points, UInt count,
138                         AliHLTMUONCoreChamberID chamber
139                 );
140
141         /* Checks if the region of interest is within the boundaries imposed on
142            the specific chamber plane. This boundary is aproximately the square
143            box around the chamber's detection region.
144          */
145         bool InBounds();
146
147         /* Encodes the region of interest into a 32 bit code.
148          */
149         AliHLTMUONCoreROI Encode() const;
150         
151         /* Encodes the region of interest into a 32 bit code, and returns the
152            hierarchal level the region was encoded at and the left and right
153            grid coordinate of the bottom left corner of the region boundary box.
154          */
155         AliHLTMUONCoreROI Encode(UChar& level, UInt& l, UInt& b) const;
156
157         /* Decodes a 32 bit region of interest code into this region of interest
158            object.
159          */
160         void Decode(AliHLTMUONCoreROI code);
161
162         /* Decodes the chamber number of the region of interest 32 bit code.
163          */
164         static AliHLTMUONCoreChamberID DecodeChamber(AliHLTMUONCoreROI code);
165
166         /* Decodes the 32 bit region of interest code into the chamber number,
167            hierarchal level, left and right grid coordinates of the region
168            boundary box. 
169          */
170         static void Decode(
171                         AliHLTMUONCoreROI code, AliHLTMUONCoreChamberID& chamber,
172                         UChar& level, UInt& l, UInt& b
173                 );
174
175         /* Returns the chamber number of the region of interest.
176          */
177         AliHLTMUONCoreChamberID Chamber() const { return fChamber; };
178         
179         /* Returns the left hand boundary of the region of interest.
180          */
181         Float Left() const    { return fLeft; };
182         
183         /* Returns the right hand boundary of the region of interest.
184          */
185         Float Right() const   { return fRight; };
186         
187         /* Returns the bottom boundary of the region of interest.
188          */
189         Float Bottom() const  { return fBottom; };
190         
191         /* Returns the top boundary of the region of interest.
192          */
193         Float Top() const     { return fTop; };
194
195
196         /* Typecast operator for implicit typecasing to 32 bit ROI codes.
197          */
198         operator AliHLTMUONCoreROI () const { return Encode(); };
199
200
201 private:
202
203         /* Converts the internal region of interest boundary box, which is
204            specified in as floats, into a regular integer grid.
205            l = left boundary, r = right boundary, b = bottom boundary, 
206            t = top boundary.
207          */
208         inline void ConvertToGrid(UInt& l, UInt& r, UInt& b, UInt& t) const;
209         
210         /* Performs the inverse conversion of the method ConvertToGrid.
211            That is converts from a regular integer grid back to the internal
212            floating point boundary box specification.
213          */
214         inline void ConvertBackFromGrid(register UInt l, register UInt r, register UInt b, register UInt t);
215
216         /* Internal method for decoding 32 bit region codes. This method is
217            called by the Decode methods.
218          */
219         static void DecodeBits(
220                         AliHLTMUONCoreROI code, AliHLTMUONCoreChamberID& chamber,
221                         UChar& colevel, UInt& l, UInt& b
222                 );
223
224         enum {kNumberOfTrackingChambers = 10};  // Number of tracking chambers.
225
226         // Boundary box scale numbers for each chamber. These are the boundary
227         // boxes around the chambers detection surface.
228         static Float fgPlaneScale[kNumberOfTrackingChambers];  // scale numbers.
229
230         static UInt fgIndexOffsets[13];  // Offset numbers used in the encoding and decoding process.
231
232
233         AliHLTMUONCoreChamberID fChamber; // Specifies the chamber the region of interest is on.
234         Float fLeft;        // Left boundary of boundary box.
235         Float fRight;       // Right boundary of boundary box.
236         Float fBottom;      // Bottom boundary of boundary box.
237         Float fTop;         // Top boundary of boundary box.
238 };
239
240
241 //-----------------------------------------------------------------------------
242 // Inline methods:
243
244
245 inline AliHLTMUONCoreRegionOfInterest::AliHLTMUONCoreRegionOfInterest(
246                 Float left, Float right, Float bottom, Float top,
247                 AliHLTMUONCoreChamberID chamber
248         )
249         : fChamber(kChamber1), fLeft(0.0), fRight(0.0), fBottom(0.0), fTop(0.0)
250 {
251 // Creates a region of interest with the specified boundaries and for
252 // the specified chamber.
253
254         Assert( 0 <= chamber && chamber < (AliHLTMUONCoreChamberID)kNumberOfTrackingChambers );
255         fChamber = chamber;
256         fLeft = left;
257         fRight = right;
258         fBottom = bottom;
259         fTop = top;
260 }
261
262
263 inline bool AliHLTMUONCoreRegionOfInterest::Contains(const AliHLTMUONCoreClusterPoint& point) const
264 {
265 // Checks if the point is contained in this region of interest.
266
267         return fLeft <= point.X()
268           && point.X() <= fRight
269           && fBottom <= point.Y()
270           && point.Y() <= fTop;
271 }
272
273
274 inline bool AliHLTMUONCoreRegionOfInterest::Contains(
275                 const AliHLTMUONCoreClusterPoint& point,
276                 AliHLTMUONCoreChamberID chamber
277         ) const
278 {
279 // Checks if the point is contained in this region of interest and the
280 // chamber number corresponds to this region object.
281
282         return fLeft <= point.X()
283           && point.X() <= fRight
284           && fBottom <= point.Y()
285           && point.Y() <= fTop
286           && fChamber == chamber;
287 }
288
289
290 inline bool AliHLTMUONCoreRegionOfInterest::Contains(
291                 const AliHLTMUONCoreRegionOfInterest& roi
292         ) const
293 {
294 // Checks if the specified region of interest is contained in this
295 // region of interest object.
296
297         return fChamber == roi.fChamber
298           && fLeft <= roi.fLeft
299           && fRight >= roi.fRight
300           && fBottom <= roi.fBottom
301           && fTop >= roi.fTop;
302 }
303
304
305 #endif // ALIHLTMUONCOREREGIONOFINTEREST_H
306