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(const AliHLTMUONTriggerRecordsBlockStruct& block)
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))
128 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTrigRecsDebugBlockStruct& block)
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))
139 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTriggerChannelsBlockStruct& block)
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))
150 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONRecHitsBlockStruct& block)
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))
161 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONClustersBlockStruct& block)
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))
172 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONChannelsBlockStruct& block)
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))
183 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONMansoTracksBlockStruct& block)
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))
194 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONMansoCandidatesBlockStruct& block)
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))
205 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONSinglesDecisionBlockStruct& block)
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))
216 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONPairsDecisionBlockStruct& block)
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))
227 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerRecordStruct& tr)
229 // Make sure that the reserved bits in the fFlags field are set
231 if ((tr.fFlags & 0x3FFFFFF0) != 0) return false;
233 // Make sure the sign is not invalid.
234 if ((tr.fFlags & 0xC0000000) == 3) return false;
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;
249 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerRecordsBlockStruct& block)
251 if (not HeaderOk(block)) return false;
253 // Check if any ID is duplicated.
254 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
256 AliHLTInt32_t id = block.fTriggerRecord[i].fId;
257 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
259 if (id == block.fTriggerRecord[j].fId)
264 // Check integrity of individual trigger records.
265 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
267 if (not IntegrityOk(block.fTriggerRecord[i])) return false;
274 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTrigRecsDebugBlockStruct& block)
276 if (not HeaderOk(block)) return false;
281 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerChannelsBlockStruct& block)
283 if (not HeaderOk(block)) return false;
288 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONRecHitsBlockStruct& block)
290 if (not HeaderOk(block)) return false;
295 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONClustersBlockStruct& block)
297 if (not HeaderOk(block)) return false;
299 // Check if any ID is duplicated.
300 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
302 AliHLTInt32_t id = block.fCluster[i].fId;
303 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
305 if (id == block.fCluster[j].fId)
314 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONChannelsBlockStruct& block)
316 if (not HeaderOk(block)) return false;
321 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoTrackStruct& track)
323 // Make sure that the reserved bits in the fFlags field are set
325 if ((track.fFlags & 0x3FFFFFF0) != 0) return false;
327 // Make sure the sign is not invalid.
328 if ((track.fFlags & 0xC0000000) == 0xC0000000) return false;
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;
343 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoTracksBlockStruct& block)
345 if (not HeaderOk(block)) return false;
347 // Check if any ID is duplicated.
348 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
350 AliHLTInt32_t id = block.fTrack[i].fId;
351 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
353 if (id == block.fTrack[j].fId)
358 // Check that the tracks have integrity.
359 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
361 if (not IntegrityOk(block.fTrack[i])) return false;
368 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoCandidatesBlockStruct& block)
370 if (not HeaderOk(block)) return false;
372 // Check that the tracks have integrity.
373 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
375 if (not IntegrityOk(block.fCandidate[i].fTrack)) return false;
382 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTrackDecisionStruct& decision)
384 // Make sure that the reserved bits in the fTriggerBits field are set
386 if ((decision.fTriggerBits & 0xFFFFFFFC) != 0) return false;
391 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONSinglesDecisionBlockStruct& block)
393 if (not HeaderOk(block)) return false;
395 // Check that the trigger bits for each track have integrity.
396 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
398 if (not IntegrityOk(block.fDecision[i])) return false;
405 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONPairDecisionStruct& decision)
407 // Make sure that the reserved bits in the fTriggerBits field are set
409 if ((decision.fTriggerBits & 0xFFFFFF80) != 0) return false;
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
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;
427 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONPairsDecisionBlockStruct& block)
429 if (not HeaderOk(block)) return false;
431 // Check that the trigger bits for each track pair have integrity.
432 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
434 if (not IntegrityOk(block.fDecision[i])) return false;