]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/AliHLTMUONUtils.cxx
Adding the hit reconstruction algorithm and modifications for the hit rec component...
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONUtils.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /**
19  * @file   AliHLTMUONUtils.cxx
20  * @author Artur Szostak <artursz@iafrica.com>
21  * @date   
22  * @brief  Implementation of AliHLTMUONUtils utility routines.
23  */
24
25 #include "AliHLTMUONUtils.h"
26 #include "AliHLTMUONConstants.h"
27 #include "AliHLTMUONTriggerRecordsBlockStruct.h"
28 #include "AliHLTMUONTrigRecsDebugBlockStruct.h"
29 #include "AliHLTMUONTriggerChannelsBlockStruct.h"
30 #include "AliHLTMUONRecHitsBlockStruct.h"
31 #include "AliHLTMUONClustersBlockStruct.h"
32 #include "AliHLTMUONChannelsBlockStruct.h"
33 #include "AliHLTMUONMansoTracksBlockStruct.h"
34 #include "AliHLTMUONMansoCandidatesBlockStruct.h"
35 #include "AliHLTMUONSinglesDecisionBlockStruct.h"
36 #include "AliHLTMUONPairsDecisionBlockStruct.h"
37 #include <cassert>
38
39
40 AliHLTUInt32_t AliHLTMUONUtils::PackTriggerRecordFlags(
41                 AliHLTMUONParticleSign sign, bool hitset[4]
42         )
43 {
44         AliHLTUInt32_t flags;
45         switch (sign)
46         {
47         case kSignMinus: flags = 0x80000000; break;
48         case kSignPlus:  flags = 0x40000000; break;
49         default:         flags = 0x00000000; break;
50         }
51
52         return flags | (hitset[0] ? 0x1 : 0) | (hitset[1] ? 0x2 : 0)
53                 | (hitset[2] ? 0x4 : 0) | (hitset[3] ? 0x8 : 0);
54 }
55
56
57 void AliHLTMUONUtils::UnpackTriggerRecordFlags(
58                 AliHLTUInt32_t flags, AliHLTMUONParticleSign& sign, bool hitset[4]
59         )
60 {
61         AliHLTUInt32_t signbits = flags & 0xC0000000;
62         switch (signbits)
63         {
64         case 0x80000000: sign = kSignMinus;   break;
65         case 0x40000000: sign = kSignPlus;    break;
66         default:         sign = kSignUnknown; break;
67         }
68         hitset[0] = (flags & 0x1) == 1;
69         hitset[1] = (flags & 0x2) == 1;
70         hitset[2] = (flags & 0x4) == 1;
71         hitset[3] = (flags & 0x8) == 1;
72 }
73
74
75 AliHLTUInt32_t AliHLTMUONUtils::PackTrackDecisionBits(bool highPt, bool lowPt)
76 {
77         return (highPt ? 0x2 : 0) | (lowPt ? 0x1 : 0);
78 }
79
80
81 void AliHLTMUONUtils::UnpackTrackDecisionBits(
82                 AliHLTUInt32_t bits, bool& highPt, bool& lowPt
83         )
84 {
85         lowPt  = (bits & 0x1) == 1;
86         highPt = (bits & 0x2) == 1;
87 }
88
89
90 AliHLTUInt32_t AliHLTMUONUtils::PackPairDecisionBits(
91                 bool highMass, bool lowMass, bool unlike,
92                 AliHLTUInt8_t highPtCount, AliHLTUInt8_t lowPtCount
93         )
94 {
95         assert( highPtCount + lowPtCount <= 2 );
96         // highMass and lowMass must be false if unlike is false:
97         assert( not unlike ? (highMass == false and lowMass == false) : true );
98         
99         return (highMass ? 0x40 : 0) | (lowMass ? 0x20 : 0) | (unlike ? 0x10 : 0)
100                 | ((highPtCount & 0x3) << 2) | (lowPtCount & 0x3);
101 }
102
103
104 void AliHLTMUONUtils::UnpackPairDecisionBits(
105                 AliHLTUInt32_t bits, bool& highMass, bool& lowMass, bool& unlike,
106                 AliHLTUInt8_t& highPtCount, AliHLTUInt8_t& lowPtCount
107         )
108 {
109         highMass = (bits & 0x40) == 1;
110         lowMass  = (bits & 0x20) == 1;
111         unlike   = (bits & 0x10) == 1;
112         highPtCount = (bits & 0xC) >> 2;
113         lowPtCount = bits & 0x3;
114 }
115
116
117 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTriggerRecordsBlockStruct& block)
118 {
119         // The block must have the correct type.
120         if (block.fHeader.fType != kTriggerRecordsDataBlock) return false;
121         // The block's record width must be the correct size.
122         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTriggerRecordStruct))
123                 return false;
124         return true;
125 }
126
127
128 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTrigRecsDebugBlockStruct& block)
129 {
130         // The block must have the correct type.
131         if (block.fHeader.fType != kTrigRecsDebugDataBlock) return false;
132         // The block's record width must be the correct size.
133         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTrigRecInfoStruct))
134                 return false;
135         return true;
136 }
137
138
139 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTriggerChannelsBlockStruct& block)
140 {
141         // The block must have the correct type.
142         if (block.fHeader.fType != kTriggerChannelsDataBlock) return false;
143         // The block's record width must be the correct size.
144         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTriggerChannelStruct))
145                 return false;
146         return true;
147 }
148
149
150 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONRecHitsBlockStruct& block)
151 {
152         // The block must have the correct type.
153         if (block.fHeader.fType != kRecHitsDataBlock) return false;
154         // The block's record width must be the correct size.
155         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONRecHitStruct))
156                 return false;
157         return true;
158 }
159
160
161 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONClustersBlockStruct& block)
162 {
163         // The block must have the correct type.
164         if (block.fHeader.fType != kClustersDataBlock) return false;
165         // The block's record width must be the correct size.
166         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONClusterStruct))
167                 return false;
168         return true;
169 }
170
171
172 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONChannelsBlockStruct& block)
173 {
174         // The block must have the correct type.
175         if (block.fHeader.fType != kChannelsDataBlock) return false;
176         // The block's record width must be the correct size.
177         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONChannelStruct))
178                 return false;
179         return true;
180 }
181
182
183 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONMansoTracksBlockStruct& block)
184 {
185         // The block must have the correct type.
186         if (block.fHeader.fType != kMansoTracksDataBlock) return false;
187         // The block's record width must be the correct size.
188         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONMansoTrackStruct))
189                 return false;
190         return true;
191 }
192
193
194 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONMansoCandidatesBlockStruct& block)
195 {
196         // The block must have the correct type.
197         if (block.fHeader.fType != kMansoCandidatesDataBlock) return false;
198         // The block's record width must be the correct size.
199         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONMansoCandidateStruct))
200                 return false;
201         return true;
202 }
203
204
205 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONSinglesDecisionBlockStruct& block)
206 {
207         // The block must have the correct type.
208         if (block.fHeader.fType != kSinglesDecisionDataBlock) return false;
209         // The block's record width must be the correct size.
210         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTrackDecisionStruct))
211                 return false;
212         return true;
213 }
214
215
216 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONPairsDecisionBlockStruct& block)
217 {
218         // The block must have the correct type.
219         if (block.fHeader.fType != kPairsDecisionDataBlock) return false;
220         // The block's record width must be the correct size.
221         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONPairDecisionStruct))
222                 return false;
223         return true;
224 }
225
226
227 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerRecordStruct& tr)
228 {
229         // Make sure that the reserved bits in the fFlags field are set
230         // to zero.
231         if ((tr.fFlags & 0x3FFFFFF0) != 0) return false;
232
233         // Make sure the sign is not invalid.
234         if ((tr.fFlags & 0xC0000000) == 3) return false;
235
236         // Check that fHit[i] is nil if the corresponding bit in the
237         // flags word is zero.
238         const AliHLTMUONRecHitStruct& nilhit
239                 = AliHLTMUONConstants::NilRecHitStruct();
240         if ((tr.fFlags & 0x1) == 0 and tr.fHit[0] != nilhit) return false;
241         if ((tr.fFlags & 0x2) == 0 and tr.fHit[1] != nilhit) return false;
242         if ((tr.fFlags & 0x4) == 0 and tr.fHit[2] != nilhit) return false;
243         if ((tr.fFlags & 0x8) == 0 and tr.fHit[3] != nilhit) return false;
244
245         return true;
246 }
247
248
249 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerRecordsBlockStruct& block)
250 {
251         if (not HeaderOk(block)) return false;
252
253         // Check if any ID is duplicated.
254         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
255         {
256                 AliHLTInt32_t id = block.fTriggerRecord[i].fId;
257                 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
258                 {
259                         if (id == block.fTriggerRecord[j].fId)
260                                 return false;
261                 }
262         }
263
264         // Check integrity of individual trigger records.
265         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
266         {
267                 if (not IntegrityOk(block.fTriggerRecord[i])) return false;
268         }
269
270         return true;
271 }
272
273
274 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTrigRecsDebugBlockStruct& block)
275 {
276         if (not HeaderOk(block)) return false;
277         return true;
278 }
279
280
281 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerChannelsBlockStruct& block)
282 {
283         if (not HeaderOk(block)) return false;
284         return true;
285 }
286
287
288 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONRecHitsBlockStruct& block)
289 {
290         if (not HeaderOk(block)) return false;
291         return true;
292 }
293
294
295 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONClustersBlockStruct& block)
296 {
297         if (not HeaderOk(block)) return false;
298
299         // Check if any ID is duplicated.
300         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
301         {
302                 AliHLTInt32_t id = block.fCluster[i].fId;
303                 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
304                 {
305                         if (id == block.fCluster[j].fId)
306                                 return false;
307                 }
308         }
309         
310         return true;
311 }
312
313
314 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONChannelsBlockStruct& block)
315 {
316         if (not HeaderOk(block)) return false;
317         return true;
318 }
319
320
321 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoTrackStruct& track)
322 {
323         // Make sure that the reserved bits in the fFlags field are set
324         // to zero.
325         if ((track.fFlags & 0x3FFFFFF0) != 0) return false;
326
327         // Make sure the sign is not invalid.
328         if ((track.fFlags & 0xC0000000) == 0xC0000000) return false;
329
330         // Check that fHit[i] is nil if the corresponding bit in the
331         // flags word is zero.
332         const AliHLTMUONRecHitStruct& nilhit
333                 = AliHLTMUONConstants::NilRecHitStruct();
334         if ((track.fFlags & 0x1) == 0 and track.fHit[0] != nilhit) return false;
335         if ((track.fFlags & 0x2) == 0 and track.fHit[1] != nilhit) return false;
336         if ((track.fFlags & 0x4) == 0 and track.fHit[2] != nilhit) return false;
337         if ((track.fFlags & 0x8) == 0 and track.fHit[3] != nilhit) return false;
338         
339         return true;
340 }
341
342
343 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoTracksBlockStruct& block)
344 {
345         if (not HeaderOk(block)) return false;
346
347         // Check if any ID is duplicated.
348         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
349         {
350                 AliHLTInt32_t id = block.fTrack[i].fId;
351                 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
352                 {
353                         if (id == block.fTrack[j].fId)
354                                 return false;
355                 }
356         }
357
358         // Check that the tracks have integrity.
359         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
360         {
361                 if (not IntegrityOk(block.fTrack[i])) return false;
362         }
363
364         return true;
365 }
366
367
368 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoCandidatesBlockStruct& block)
369 {
370         if (not HeaderOk(block)) return false;
371
372         // Check that the tracks have integrity.
373         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
374         {
375                 if (not IntegrityOk(block.fCandidate[i].fTrack)) return false;
376         }
377         
378         return true;
379 }
380
381
382 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTrackDecisionStruct& decision)
383 {
384         // Make sure that the reserved bits in the fTriggerBits field are set
385         // to zero.
386         if ((decision.fTriggerBits & 0xFFFFFFFC) != 0) return false;
387         return true;
388 }
389
390
391 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONSinglesDecisionBlockStruct& block)
392 {
393         if (not HeaderOk(block)) return false;
394
395         // Check that the trigger bits for each track have integrity.
396         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
397         {
398                 if (not IntegrityOk(block.fDecision[i])) return false;
399         }
400         
401         return true;
402 }
403
404
405 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONPairDecisionStruct& decision)
406 {
407         // Make sure that the reserved bits in the fTriggerBits field are set
408         // to zero.
409         if ((decision.fTriggerBits & 0xFFFFFF80) != 0) return false;
410         
411         // The high mass or low mass bits can only be set if unlike bit is set.
412         if ((decision.fTriggerBits & 0x00000010) == 0
413             and (decision.fTriggerBits & 0x00000060) != 0
414            )
415                 return false;
416         
417         // Neither the high pt (hipt) or low pt (lopt) count bits can be > 2.
418         // And the sum must not be > 2.
419         AliHLTUInt8_t lowPtCount = (decision.fTriggerBits & 0x00000003);
420         AliHLTUInt8_t highPtCount = (decision.fTriggerBits & 0x0000000C) >> 2;
421         if (lowPtCount + highPtCount > 2) return false;
422         
423         return true;
424 }
425
426
427 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONPairsDecisionBlockStruct& block)
428 {
429         if (not HeaderOk(block)) return false;
430
431         // Check that the trigger bits for each track pair have integrity.
432         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
433         {
434                 if (not IntegrityOk(block.fDecision[i])) return false;
435         }
436         
437         return true;
438 }