]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/OnlineAnalysis/AliHLTMUONMansoTrackerFSM.h
ALIROOT-5433 Transition to CDHv3 in HLT
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONMansoTrackerFSM.h
CommitLineData
e0679afb 1#ifndef ALIHLTMUONMANSOTRACKERFSM_H
2#define ALIHLTMUONMANSOTRACKERFSM_H
b92524d0 3/**************************************************************************
bc5cb6d6 4 * This file is property of and copyright by the ALICE HLT Project *
b92524d0 5 * All rights reserved. *
6 * *
7 * Primary Authors: *
8 * Artur Szostak <artursz@iafrica.com> *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
bc5cb6d6 15 * about the suitability of this software for any purpose. It is *
b92524d0 16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
e0679afb 18
1d8ae082 19// $Id$
e0679afb 20
a3d4b6ba 21///
22/// @file AliHLTMUONMansoTrackerFSM.h
23/// @author Artur Szostak <artursz@iafrica.com>
24/// @date 29 May 2007
25/// @brief Declaration of the AliHLTMUONMansoTrackerFSM class which implements the Manso tracking algorithm.
26///
e0679afb 27
bc5cb6d6 28#include "AliHLTLogging.h"
e0679afb 29#include "AliHLTMUONDataTypes.h"
30#include "AliHLTMUONList.h"
31#include "AliHLTMUONCountedList.h"
32#include "AliHLTMUONRecHitsBlockStruct.h"
b92524d0 33#include "AliHLTMUONMansoTrackerFSMCallback.h"
34#include <cassert>
e0679afb 35
bc5cb6d6 36extern "C" struct AliHLTMUONTriggerRecordStruct;
37extern "C" struct AliHLTMUONMansoTrackStruct;
38extern "C" struct AliHLTMUONMansoCandidateStruct;
39
a3d4b6ba 40/**
41 * The AliHLTMUONMansoTrackerFSM implements the Manso tracking
42 * algorithm as a finite state machine, which partially reconstructs
43 * tracks in the muon spectrometer.
44 */
bc5cb6d6 45class AliHLTMUONMansoTrackerFSM : public AliHLTLogging
e0679afb 46{
47public:
48
49 AliHLTMUONMansoTrackerFSM();
bc5cb6d6 50 virtual ~AliHLTMUONMansoTrackerFSM();
e0679afb 51
52
53 /* This is the starting point for the tracking algorithm. The tracker is
54 called at this point with the specified trigger record. It needs to figure
55 out which cluster blocks it needs and request them with calls to
56 RequestClusters.
57 Any memory allocated at this point should be released in the Reset method.
58
59 Note: Reset should be called for before calling FindTrack, for the
60 second or subsequent method calls to FindTrack.
61 */
b92524d0 62 virtual void FindTrack(const AliHLTMUONTriggerRecordStruct& trigger);
e0679afb 63
64 /* When requested clusters have been found by the framework they are returned
65 to the tracker using this method.
66 This method should implement any processing of the cluster blocks. If more
67 more regions of interest are identified then appropriate request should me
68 made using RequestClusters. The tag parameter will be the same one as was
69 passed to RequestClusters.
70 */
b92524d0 71 virtual void ReturnClusters(
72 void* tag, const AliHLTMUONRecHitStruct* clusters,
73 AliHLTUInt32_t count
74 );
e0679afb 75
76 /* When no more clusters are to be expected for the request with the corresponding
77 tag value, then this method is called.
78 Any final processing can be placed in here and when the track is found then
79 the algorithm can call FoundTrack otherwise NoTrackFound to indicate end of
80 processing.
81 */
82 virtual void EndOfClusters(void* tag);
83
84 /* Called to receive track information after receiving a FoundTrack call.
85 The tracker should fill the track data block with all relevant information.
b92524d0 86 The method will return false if the momentum could not be calculated from
87 the hits found. The hits in the track structure will however still be filled.
e0679afb 88 */
b92524d0 89 virtual bool FillTrackData(AliHLTMUONMansoTrackStruct& track);
e0679afb 90
91 /* Called when the tracker should be reset to a initial state.
92 All extra internal allocated data structured should be released.
93 */
94 virtual void Reset();
95
96 /* To set the TrackerCallback callback object.
97 */
2b401483 98 void SetCallback(AliHLTMUONMansoTrackerFSMCallback* callback)
e0679afb 99 {
100 fCallback = callback;
101 };
bc5cb6d6 102
103 /// Returns the flag indicating if track candidates are stored.
104 bool MakeCandidates() const { return fMakeCandidates; }
105
106 /// Sets the flag to indicate if track candidates are stored or not.
107 void MakeCandidates(bool value) { fMakeCandidates = value; }
108
109 /// Returns the number of track candidates found in the list returned by TrackCandidates().
110 AliHLTUInt32_t TrackCandidatesCount() const { return fCandidatesCount; }
111
112 /// Returns the array of track candidates.
113 const AliHLTMUONMansoCandidateStruct* TrackCandidates() const { return fCandidates; }
114
115 /// Removes all the elements in the track candidates array.
116 void ZeroTrackCandidatesList() { fCandidatesCount = 0; }
e0679afb 117
118 /* Get and set methods for the a and b parameters used to build the region
b92524d0 119 of interests. Refer to AliRegionOfInterest for details about a and b parameters.
e0679afb 120 */
121 static AliHLTFloat32_t GetA7() { return fgA7; };
122 static void SetA7(AliHLTFloat32_t value) { fgA7 = value; };
123 static AliHLTFloat32_t GetA8() { return fgA8; };
124 static void SetA8(AliHLTFloat32_t value) { fgA8 = value; };
125 static AliHLTFloat32_t GetA9() { return fgA9; };
126 static void SetA9(AliHLTFloat32_t value) { fgA9 = value; };
127 static AliHLTFloat32_t GetA10() { return fgA10; };
128 static void SetA10(AliHLTFloat32_t value) { fgA10 = value; };
129
130 static AliHLTFloat32_t GetB7() { return fgB7; };
131 static void SetB7(AliHLTFloat32_t value) { fgB7 = value; };
132 static AliHLTFloat32_t GetB8() { return fgB8; };
133 static void SetB8(AliHLTFloat32_t value) { fgB8 = value; };
134 static AliHLTFloat32_t GetB9() { return fgB9; };
135 static void SetB9(AliHLTFloat32_t value) { fgB9 = value; };
136 static AliHLTFloat32_t GetB10() { return fgB10; };
137 static void SetB10(AliHLTFloat32_t value) { fgB10 = value; };
138
139 static AliHLTFloat32_t GetZ7() { return fgZ7; };
140 static void SetZ7(AliHLTFloat32_t value) { fgZ7 = value; };
141 static AliHLTFloat32_t GetZ8() { return fgZ8; };
142 static void SetZ8(AliHLTFloat32_t value) { fgZ8 = value; };
143 static AliHLTFloat32_t GetZ9() { return fgZ9; };
144 static void SetZ9(AliHLTFloat32_t value) { fgZ9 = value; };
145 static AliHLTFloat32_t GetZ10() { return fgZ10; };
146 static void SetZ10(AliHLTFloat32_t value) { fgZ10 = value; };
147 static AliHLTFloat32_t GetZ11() { return fgZ11; };
148 static void SetZ11(AliHLTFloat32_t value) { fgZ11 = value; };
149 static AliHLTFloat32_t GetZ13() { return fgZ13; };
150 static void SetZ13(AliHLTFloat32_t value) { fgZ13 = value; };
151
152
153protected:
154
155 class AliRegionOfInterest
156 {
157 public:
158
159 AliRegionOfInterest() : fCentre(), fRs(0.0) {};
160
b92524d0 161 AliRegionOfInterest(AliHLTMUONRecHitStruct p, AliHLTFloat32_t a, AliHLTFloat32_t b)
e0679afb 162 : fCentre(), fRs(0)
163 {
164 Create(p, a, b);
165 };
166
167 /* Creates a region of interest. In this implementation it is a
168 circular disk.
169
170 The point p is the intersecting point of the track with the chamber.
171 For more details and for details about the parameters a and b refer to:
172 "A first algorithm for dimuon High Level Trigger"
173 Ref ID: ALICE-INT-2002-04 version 1.0
174 equation:
175 Rs = a * Rp + b
176 given on page 3 section 4.
177 */
b92524d0 178 void Create(AliHLTMUONRecHitStruct p, AliHLTFloat32_t a, AliHLTFloat32_t b);
e0679afb 179
180 /* Returns true if the point p is within the region of interest.
181 */
b92524d0 182 bool Contains(AliHLTMUONRecHitStruct p) const;
e0679afb 183
184 void GetBoundaryBox(AliHLTFloat32_t& left, AliHLTFloat32_t& right, AliHLTFloat32_t& bottom, AliHLTFloat32_t& top) const;
bc5cb6d6 185
186 /// Returns the centre point of the region of interest.
187 const AliHLTMUONRecHitStruct& Centre() const { return fCentre; }
188
189 /// Returns the radius of the region of interest disk.
190 AliHLTFloat32_t Radius() const { return fRs; }
e0679afb 191
192 private:
193
b92524d0 194 AliHLTMUONRecHitStruct fCentre; // The centre point of the region of interest.
e0679afb 195 AliHLTFloat32_t fRs; // The redius of the region of interest around fcentre.
196 };
197
198
199 class AliVertex
200 {
201 public:
202
203 AliVertex(AliHLTFloat32_t x = 0.0, AliHLTFloat32_t y = 0.0, AliHLTFloat32_t z = 0.0);
b92524d0 204 AliVertex(AliHLTMUONRecHitStruct xy, AliHLTFloat32_t z);
e0679afb 205
b92524d0 206 AliHLTMUONRecHitStruct AsXYPoint() const
e0679afb 207 {
b92524d0 208 AliHLTMUONRecHitStruct p;
2b401483 209 p.fX = fX; p.fY = fY; p.fZ = 0;
b92524d0 210 return p;
e0679afb 211 };
212
213 // Get/set methods:
214 AliHLTFloat32_t X() const { return fX; };
215 AliHLTFloat32_t Y() const { return fY; };
216 AliHLTFloat32_t Z() const { return fZ; };
217 AliHLTFloat32_t& X() { return fX; };
218 AliHLTFloat32_t& Y() { return fY; };
219 AliHLTFloat32_t& Z() { return fZ; };
220 void X(AliHLTFloat32_t value) { fX = value; };
221 void Y(AliHLTFloat32_t value) { fY = value; };
222 void Z(AliHLTFloat32_t value) { fZ = value; };
223
224 private:
225
226 AliHLTFloat32_t fX, fY, fZ; // 3D coordinates.
227 };
228
229
230 class AliLine
231 {
232 public:
233
234 /* Creates a vector line between points A and B.
235 ax, ay, az are x, y and z coordinates for space point A respectively.
236 simmilarly for B.
237 */
238 AliLine(
239 AliHLTFloat32_t ax = 0.0, AliHLTFloat32_t ay = 0.0, AliHLTFloat32_t az = 0.0,
240 AliHLTFloat32_t bx = 0.0, AliHLTFloat32_t by = 0.0, AliHLTFloat32_t bz = 0.0
241 );
242
243 /* Creates a vector line between vertices A and B.
244 */
245 AliLine(AliVertex a, AliVertex b);
246
247 /* Finds the intersection point with the xy plain specified by the z coordinate.
248 The z coordiante would be the distance of the n'th chamber to the interaction
249 vertex.
250 */
b92524d0 251 AliHLTMUONRecHitStruct FindIntersectWithXYPlain(AliHLTFloat32_t z) const;
e0679afb 252
253 private:
254
255 // Parameters for the vector line: L = M*t + C
256 AliHLTFloat32_t fMx, fMy, fMz, fCx, fCy, fCz; // line parameters.
257 };
258
259
2b401483 260 class AliTagData
e0679afb 261 {
2b401483 262 public:
bc5cb6d6 263 AliTagData() : fChamber(kChamber1), fRoi(), fLine(), fCandidate(NULL) {};
2b401483 264
b92524d0 265 AliHLTMUONChamberName fChamber; // The chamber on which the region of interest lies.
e0679afb 266 AliRegionOfInterest fRoi; // Region of interest on the next station.
267 AliLine fLine; // line between a cluster point and the previous station.
bc5cb6d6 268 AliHLTMUONMansoCandidateStruct* fCandidate; // Track candidate related to the RoI.
e0679afb 269 };
270
2b401483 271 class AliStation5Data
e0679afb 272 {
2b401483 273 public:
274 AliStation5Data() : fClusterPoint(), fTag() {};
275
b92524d0 276 AliHLTMUONRecHitStruct fClusterPoint; // Cluster point found on station 5.
e0679afb 277 AliTagData fTag; // Chamber, ROI and line data for station 5.
e0679afb 278 };
279
b92524d0 280 typedef AliHLTMUONCountedList<AliStation5Data> Station5List;
e0679afb 281
2b401483 282 class AliStation4Data
e0679afb 283 {
2b401483 284 public:
e0679afb 285 AliStation4Data() : fClusterPoint(), fSt5tag() {};
286
287 AliStation4Data(const AliStation4Data& data) :
288 fClusterPoint(data.fClusterPoint), fSt5tag(data.fSt5tag)
289 {};
290
291 AliStation4Data& operator = (const AliStation4Data& data)
292 {
293 fClusterPoint = data.fClusterPoint;
294 fSt5tag = data.fSt5tag;
295 return *this;
296 };
2b401483 297
298 AliHLTMUONRecHitStruct fClusterPoint; // Cluster point found on station 4.
299 const AliTagData* fSt5tag; // Corresponding station 5 tag.
e0679afb 300 };
301
b92524d0 302 typedef AliHLTMUONList<AliStation4Data> Station4List;
e0679afb 303
304
b92524d0 305 void ReceiveClustersChamber7(const AliHLTMUONRecHitStruct* clusters, AliHLTUInt32_t count, const AliTagData* data);
306 void ReceiveClustersChamber8(const AliHLTMUONRecHitStruct* clusters, AliHLTUInt32_t count, const AliTagData* data);
307 void ReceiveClustersChamber9(const AliHLTMUONRecHitStruct* clusters, AliHLTUInt32_t count);
308 void ReceiveClustersChamber10(const AliHLTMUONRecHitStruct* clusters, AliHLTUInt32_t count);
e0679afb 309 void EndOfClustersChamber7();
310 void EndOfClustersChamber8();
311 void EndOfClustersChamber9();
312 void EndOfClustersChamber10();
313
bc5cb6d6 314 void ProjectToStation4(AliStation5Data* data, AliHLTFloat32_t station5z, AliHLTUInt32_t chamberSt5);
e0679afb 315 void ProcessClusters();
316
317#ifdef DEBUG
318public:
319#endif
320 // States for state machine 4 (SM4).
321 enum StatesSM4
322 {
323 kSM4Idle,
324 kWaitChamber8,
325 kWaitMoreChamber8,
326 kWaitChamber7,
327 kWaitMoreChamber7
328 };
329
330 // States for state machine 5 (SM5).
331 enum StatesSM5
332 {
333 kSM5Idle,
334 kWaitChamber10,
335 kWaitMoreChamber10,
336 kWaitChamber9,
337 kWaitMoreChamber9,
338 kSM5Done
339 };
340
341protected:
342
2b401483 343 AliHLTMUONMansoTrackerFSMCallback* fCallback; // Pointer to the callback interface from which we fetch reco hits and to which we publish results.
e0679afb 344
345 StatesSM4 fSm4state; // State of SM4 used for fetching clusters on chambers 7 and 8.
346 StatesSM5 fSm5state; // State of SM5 used for fetching clusters on chambers 9 and 10.
b92524d0 347 AliHLTUInt32_t fRequestsCompleted; // Number of requests for station 4 that have completed.
348 AliHLTMUONChamberName fSt4chamber; // The chamber on station 4 that data was retreived from.
e0679afb 349
350 AliVertex fV1; // The impact (hit) vertex for trigger station 1.
351 AliTagData fMc1; // Trigger station 1 data.
352
e0679afb 353 Station5List fSt5data; // List of found cluster points for station 5 and their tag data.
e0679afb 354 Station4List fSt4points; // The found cluster points for station 4.
355
356 // Iterators used in the FoundTrack, FillTrackData methods.
357 Station5List::Iterator fSt5rec; // current station 5 record
358 Station4List::Iterator fFoundPoint; // current found point
b92524d0 359 AliHLTInt32_t fTriggerId; // The current ID number of the trigger record being processed.
360 AliHLTInt32_t fTrackId; // Track ID counter for the current track.
e0679afb 361
bc5cb6d6 362 bool fMakeCandidates; // Indicates if the track candidates should be recorded.
363 AliHLTUInt32_t fCandidatesCount; // The number of track candidates in the fCandidates list.
364 AliHLTUInt32_t fCandidatesSize; // Number of elements that the fCandidates list can store.
365 AliHLTMUONMansoCandidateStruct* fCandidates; // The track candidates buffer.
e0679afb 366
367 /* To request clusters from the boundary box specified by the 'left', 'right',
368 'top' and 'bottom' boundaries and on the given chamber use this method call.
369 Supply a tag parameter if you want the request uniquely identified.
370 This is usefull to supply a pointer to some internal state data structure
371 to figure out where processing should continue in the ReturnClusters or
372 EndOfClusters methods.
373 */
2b401483 374 void RequestClusters(
e0679afb 375 AliHLTFloat32_t left, AliHLTFloat32_t right, AliHLTFloat32_t bottom, AliHLTFloat32_t top,
b92524d0 376 AliHLTMUONChamberName chamber, const void* tag = NULL
e0679afb 377 )
378 {
b92524d0 379 assert( fCallback != NULL );
e0679afb 380 fCallback->RequestClusters(this, left, right, bottom, top, chamber, tag);
381 };
382
383 /* When no more cluster requests will be generated by this tracker then this
384 method should be called.
385 DO NOT request more clusters after calling this method.
386 */
2b401483 387 void EndOfClusterRequests()
e0679afb 388 {
b92524d0 389 assert( fCallback != NULL );
e0679afb 390 fCallback->EndOfClusterRequests(this);
391 };
392
393 /* When the tracker has found a track it should call this method to inform
394 the rest of the system. At this point all cluster blocks received with
395 ReturnClusters are to be considered released and MUST NOT be accessed.
396 */
2b401483 397 void FoundTrack()
e0679afb 398 {
b92524d0 399 assert( fCallback != NULL );
e0679afb 400 fCallback->FoundTrack(this);
401 };
402
403 /* If the tracker is finished processing the trigger record but has not found
404 a track it should call this method to inform the rest of the system.
405 At this point all cluster blocks received with ReturnClusters are to be
406 considered released and MUST NOT be accessed.
407 */
2b401483 408 void NoTrackFound()
e0679afb 409 {
b92524d0 410 assert( fCallback != NULL );
e0679afb 411 fCallback->NoTrackFound(this);
412 };
bc5cb6d6 413
414 /**
415 * Adds a new track candidate to the fCandidates list and returns the pointer
416 * to the new structure to be filled.
417 * \returns a pointer to the new structure and NULL if we ran out of space.
418 */
419 AliHLTMUONMansoCandidateStruct* AddTrackCandidate();
e0679afb 420
421private:
422
423 // Not allowed to copy this object.
424 AliHLTMUONMansoTrackerFSM(const AliHLTMUONMansoTrackerFSM& tracker);
b92524d0 425 AliHLTMUONMansoTrackerFSM& operator = (const AliHLTMUONMansoTrackerFSM& tracker);
e0679afb 426
427 static AliHLTFloat32_t fgA7, fgB7; // Parameters used to create a region of interest for the 7'th chamber.
428 static AliHLTFloat32_t fgA8, fgB8; // Parameters used to create a region of interest for the 8'th chamber.
429 static AliHLTFloat32_t fgA9, fgB9; // Parameters used to create a region of interest for the 9'th chamber.
430 static AliHLTFloat32_t fgA10, fgB10; // Parameters used to create a region of interest for the 10'th chamber.
431 static AliHLTFloat32_t fgZ7, fgZ8, fgZ9, fgZ10, fgZ11, fgZ13; // Z coordinates of chambers 7 to 10.
432
433};
434
435
e0679afb 436#endif // ALIHLTMUONMANSOTRACKERFSM_H