1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 * @file AliHLTMUONUtils.cxx
20 * @author Artur Szostak <artursz@iafrica.com>
22 * @brief Implementation of AliHLTMUONUtils utility routines.
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"
40 AliHLTUInt32_t AliHLTMUONUtils::PackTriggerRecordFlags(
41 AliHLTMUONParticleSign sign, bool hitset[4]
47 case kSignMinus: flags = 0x80000000; break;
48 case kSignPlus: flags = 0x40000000; break;
49 default: flags = 0x00000000; break;
52 return flags | (hitset[0] ? 0x1 : 0) | (hitset[1] ? 0x2 : 0)
53 | (hitset[2] ? 0x4 : 0) | (hitset[3] ? 0x8 : 0);
57 void AliHLTMUONUtils::UnpackTriggerRecordFlags(
58 AliHLTUInt32_t flags, AliHLTMUONParticleSign& sign, bool hitset[4]
61 AliHLTUInt32_t signbits = flags & 0xC0000000;
64 case 0x80000000: sign = kSignMinus; break;
65 case 0x40000000: sign = kSignPlus; break;
66 default: sign = kSignUnknown; break;
68 hitset[0] = (flags & 0x1) == 1;
69 hitset[1] = (flags & 0x2) == 1;
70 hitset[2] = (flags & 0x4) == 1;
71 hitset[3] = (flags & 0x8) == 1;
75 AliHLTUInt32_t AliHLTMUONUtils::PackTrackDecisionBits(bool highPt, bool lowPt)
77 return (highPt ? 0x2 : 0) | (lowPt ? 0x1 : 0);
81 void AliHLTMUONUtils::UnpackTrackDecisionBits(
82 AliHLTUInt32_t bits, bool& highPt, bool& lowPt
85 lowPt = (bits & 0x1) == 1;
86 highPt = (bits & 0x2) == 1;
90 AliHLTUInt32_t AliHLTMUONUtils::PackPairDecisionBits(
91 bool highMass, bool lowMass, bool unlike,
92 AliHLTUInt8_t highPtCount, AliHLTUInt8_t lowPtCount
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 );
99 return (highMass ? 0x40 : 0) | (lowMass ? 0x20 : 0) | (unlike ? 0x10 : 0)
100 | ((highPtCount & 0x3) << 2) | (lowPtCount & 0x3);
104 void AliHLTMUONUtils::UnpackPairDecisionBits(
105 AliHLTUInt32_t bits, bool& highMass, bool& lowMass, bool& unlike,
106 AliHLTUInt8_t& highPtCount, AliHLTUInt8_t& lowPtCount
109 highMass = (bits & 0x40) == 1;
110 lowMass = (bits & 0x20) == 1;
111 unlike = (bits & 0x10) == 1;
112 highPtCount = (bits & 0xC) >> 2;
113 lowPtCount = bits & 0x3;
117 bool AliHLTMUONUtils::HeaderOk(
118 const AliHLTMUONTriggerRecordsBlockStruct& block,
122 // The block must have the correct type.
123 if (block.fHeader.fType != kTriggerRecordsDataBlock)
125 if (reason != NULL) *reason = kHeaderContainsWrongType;
129 // The block's record width must be the correct size.
130 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTriggerRecordStruct))
132 if (reason != NULL) *reason = kHeaderContainsWrongRecordWidth;
140 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTrigRecsDebugBlockStruct& block)
142 // The block must have the correct type.
143 if (block.fHeader.fType != kTrigRecsDebugDataBlock) return false;
144 // The block's record width must be the correct size.
145 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTrigRecInfoStruct))
151 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTriggerChannelsBlockStruct& block)
153 // The block must have the correct type.
154 if (block.fHeader.fType != kTriggerChannelsDataBlock) return false;
155 // The block's record width must be the correct size.
156 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTriggerChannelStruct))
162 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONRecHitsBlockStruct& block)
164 // The block must have the correct type.
165 if (block.fHeader.fType != kRecHitsDataBlock) return false;
166 // The block's record width must be the correct size.
167 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONRecHitStruct))
173 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONClustersBlockStruct& block)
175 // The block must have the correct type.
176 if (block.fHeader.fType != kClustersDataBlock) return false;
177 // The block's record width must be the correct size.
178 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONClusterStruct))
184 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONChannelsBlockStruct& block)
186 // The block must have the correct type.
187 if (block.fHeader.fType != kChannelsDataBlock) return false;
188 // The block's record width must be the correct size.
189 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONChannelStruct))
195 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONMansoTracksBlockStruct& block)
197 // The block must have the correct type.
198 if (block.fHeader.fType != kMansoTracksDataBlock) return false;
199 // The block's record width must be the correct size.
200 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONMansoTrackStruct))
206 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONMansoCandidatesBlockStruct& block)
208 // The block must have the correct type.
209 if (block.fHeader.fType != kMansoCandidatesDataBlock) return false;
210 // The block's record width must be the correct size.
211 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONMansoCandidateStruct))
217 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONSinglesDecisionBlockStruct& block)
219 // The block must have the correct type.
220 if (block.fHeader.fType != kSinglesDecisionDataBlock) return false;
221 // The block's record width must be the correct size.
222 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTrackDecisionStruct))
228 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONPairsDecisionBlockStruct& block)
230 // The block must have the correct type.
231 if (block.fHeader.fType != kPairsDecisionDataBlock) return false;
232 // The block's record width must be the correct size.
233 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONPairDecisionStruct))
239 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerRecordStruct& tr)
241 // Make sure that the reserved bits in the fFlags field are set
243 if ((tr.fFlags & 0x3FFFFFF0) != 0) return false;
245 // Make sure the sign is not invalid.
246 if ((tr.fFlags & 0xC0000000) == 3) return false;
248 // Check that fHit[i] is nil if the corresponding bit in the
249 // flags word is zero.
250 const AliHLTMUONRecHitStruct& nilhit
251 = AliHLTMUONConstants::NilRecHitStruct();
252 if ((tr.fFlags & 0x1) == 0 and tr.fHit[0] != nilhit) return false;
253 if ((tr.fFlags & 0x2) == 0 and tr.fHit[1] != nilhit) return false;
254 if ((tr.fFlags & 0x4) == 0 and tr.fHit[2] != nilhit) return false;
255 if ((tr.fFlags & 0x8) == 0 and tr.fHit[3] != nilhit) return false;
261 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerRecordsBlockStruct& block)
263 if (not HeaderOk(block)) return false;
265 // Check if any ID is duplicated.
266 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
268 AliHLTInt32_t id = block.fTriggerRecord[i].fId;
269 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
271 if (id == block.fTriggerRecord[j].fId)
276 // Check integrity of individual trigger records.
277 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
279 if (not IntegrityOk(block.fTriggerRecord[i])) return false;
286 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTrigRecsDebugBlockStruct& block)
288 if (not HeaderOk(block)) return false;
293 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerChannelsBlockStruct& block)
295 if (not HeaderOk(block)) return false;
300 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONRecHitsBlockStruct& block)
302 if (not HeaderOk(block)) return false;
307 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONClustersBlockStruct& block)
309 if (not HeaderOk(block)) return false;
311 // Check if any ID is duplicated.
312 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
314 AliHLTInt32_t id = block.fCluster[i].fId;
315 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
317 if (id == block.fCluster[j].fId)
326 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONChannelsBlockStruct& block)
328 if (not HeaderOk(block)) return false;
333 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoTrackStruct& track)
335 // Make sure that the reserved bits in the fFlags field are set
337 if ((track.fFlags & 0x3FFFFFF0) != 0) return false;
339 // Make sure the sign is not invalid.
340 if ((track.fFlags & 0xC0000000) == 0xC0000000) return false;
342 // Check that fHit[i] is nil if the corresponding bit in the
343 // flags word is zero.
344 const AliHLTMUONRecHitStruct& nilhit
345 = AliHLTMUONConstants::NilRecHitStruct();
346 if ((track.fFlags & 0x1) == 0 and track.fHit[0] != nilhit) return false;
347 if ((track.fFlags & 0x2) == 0 and track.fHit[1] != nilhit) return false;
348 if ((track.fFlags & 0x4) == 0 and track.fHit[2] != nilhit) return false;
349 if ((track.fFlags & 0x8) == 0 and track.fHit[3] != nilhit) return false;
355 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoTracksBlockStruct& block)
357 if (not HeaderOk(block)) return false;
359 // Check if any ID is duplicated.
360 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
362 AliHLTInt32_t id = block.fTrack[i].fId;
363 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
365 if (id == block.fTrack[j].fId)
370 // Check that the tracks have integrity.
371 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
373 if (not IntegrityOk(block.fTrack[i])) return false;
380 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoCandidatesBlockStruct& block)
382 if (not HeaderOk(block)) return false;
384 // Check that the tracks have integrity.
385 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
387 if (not IntegrityOk(block.fCandidate[i].fTrack)) return false;
394 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTrackDecisionStruct& decision)
396 // Make sure that the reserved bits in the fTriggerBits field are set
398 if ((decision.fTriggerBits & 0xFFFFFFFC) != 0) return false;
403 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONSinglesDecisionBlockStruct& block)
405 if (not HeaderOk(block)) return false;
407 // Check that the trigger bits for each track have integrity.
408 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
410 if (not IntegrityOk(block.fDecision[i])) return false;
417 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONPairDecisionStruct& decision)
419 // Make sure that the reserved bits in the fTriggerBits field are set
421 if ((decision.fTriggerBits & 0xFFFFFF80) != 0) return false;
423 // The high mass or low mass bits can only be set if unlike bit is set.
424 if ((decision.fTriggerBits & 0x00000010) == 0
425 and (decision.fTriggerBits & 0x00000060) != 0
429 // Neither the high pt (hipt) or low pt (lopt) count bits can be > 2.
430 // And the sum must not be > 2.
431 AliHLTUInt8_t lowPtCount = (decision.fTriggerBits & 0x00000003);
432 AliHLTUInt8_t highPtCount = (decision.fTriggerBits & 0x0000000C) >> 2;
433 if (lowPtCount + highPtCount > 2) return false;
439 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONPairsDecisionBlockStruct& block)
441 if (not HeaderOk(block)) return false;
443 // Check that the trigger bits for each track pair have integrity.
444 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
446 if (not IntegrityOk(block.fDecision[i])) return false;