]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/AliHLTMUONUtils.cxx
Modifying some routines to return more state.
[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(
118                 const AliHLTMUONTriggerRecordsBlockStruct& block,
119                 WhyNotValid* reason
120         )
121 {
122         // The block must have the correct type.
123         if (block.fHeader.fType != kTriggerRecordsDataBlock)
124         {
125                 if (reason != NULL) *reason = kHeaderContainsWrongType;
126                 return false;
127         }
128         
129         // The block's record width must be the correct size.
130         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTriggerRecordStruct))
131         {
132                 if (reason != NULL) *reason = kHeaderContainsWrongRecordWidth;
133                 return false;
134         }
135         
136         return true;
137 }
138
139
140 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTrigRecsDebugBlockStruct& block)
141 {
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))
146                 return false;
147         return true;
148 }
149
150
151 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTriggerChannelsBlockStruct& block)
152 {
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))
157                 return false;
158         return true;
159 }
160
161
162 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONRecHitsBlockStruct& block)
163 {
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))
168                 return false;
169         return true;
170 }
171
172
173 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONClustersBlockStruct& block)
174 {
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))
179                 return false;
180         return true;
181 }
182
183
184 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONChannelsBlockStruct& block)
185 {
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))
190                 return false;
191         return true;
192 }
193
194
195 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONMansoTracksBlockStruct& block)
196 {
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))
201                 return false;
202         return true;
203 }
204
205
206 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONMansoCandidatesBlockStruct& block)
207 {
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))
212                 return false;
213         return true;
214 }
215
216
217 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONSinglesDecisionBlockStruct& block)
218 {
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))
223                 return false;
224         return true;
225 }
226
227
228 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONPairsDecisionBlockStruct& block)
229 {
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))
234                 return false;
235         return true;
236 }
237
238
239 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerRecordStruct& tr)
240 {
241         // Make sure that the reserved bits in the fFlags field are set
242         // to zero.
243         if ((tr.fFlags & 0x3FFFFFF0) != 0) return false;
244
245         // Make sure the sign is not invalid.
246         if ((tr.fFlags & 0xC0000000) == 3) return false;
247
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;
256
257         return true;
258 }
259
260
261 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerRecordsBlockStruct& block)
262 {
263         if (not HeaderOk(block)) return false;
264
265         // Check if any ID is duplicated.
266         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
267         {
268                 AliHLTInt32_t id = block.fTriggerRecord[i].fId;
269                 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
270                 {
271                         if (id == block.fTriggerRecord[j].fId)
272                                 return false;
273                 }
274         }
275
276         // Check integrity of individual trigger records.
277         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
278         {
279                 if (not IntegrityOk(block.fTriggerRecord[i])) return false;
280         }
281
282         return true;
283 }
284
285
286 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTrigRecsDebugBlockStruct& block)
287 {
288         if (not HeaderOk(block)) return false;
289         return true;
290 }
291
292
293 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerChannelsBlockStruct& block)
294 {
295         if (not HeaderOk(block)) return false;
296         return true;
297 }
298
299
300 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONRecHitsBlockStruct& block)
301 {
302         if (not HeaderOk(block)) return false;
303         return true;
304 }
305
306
307 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONClustersBlockStruct& block)
308 {
309         if (not HeaderOk(block)) return false;
310
311         // Check if any ID is duplicated.
312         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
313         {
314                 AliHLTInt32_t id = block.fCluster[i].fId;
315                 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
316                 {
317                         if (id == block.fCluster[j].fId)
318                                 return false;
319                 }
320         }
321         
322         return true;
323 }
324
325
326 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONChannelsBlockStruct& block)
327 {
328         if (not HeaderOk(block)) return false;
329         return true;
330 }
331
332
333 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoTrackStruct& track)
334 {
335         // Make sure that the reserved bits in the fFlags field are set
336         // to zero.
337         if ((track.fFlags & 0x3FFFFFF0) != 0) return false;
338
339         // Make sure the sign is not invalid.
340         if ((track.fFlags & 0xC0000000) == 0xC0000000) return false;
341
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;
350         
351         return true;
352 }
353
354
355 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoTracksBlockStruct& block)
356 {
357         if (not HeaderOk(block)) return false;
358
359         // Check if any ID is duplicated.
360         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
361         {
362                 AliHLTInt32_t id = block.fTrack[i].fId;
363                 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
364                 {
365                         if (id == block.fTrack[j].fId)
366                                 return false;
367                 }
368         }
369
370         // Check that the tracks have integrity.
371         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
372         {
373                 if (not IntegrityOk(block.fTrack[i])) return false;
374         }
375
376         return true;
377 }
378
379
380 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONMansoCandidatesBlockStruct& block)
381 {
382         if (not HeaderOk(block)) return false;
383
384         // Check that the tracks have integrity.
385         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
386         {
387                 if (not IntegrityOk(block.fCandidate[i].fTrack)) return false;
388         }
389         
390         return true;
391 }
392
393
394 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTrackDecisionStruct& decision)
395 {
396         // Make sure that the reserved bits in the fTriggerBits field are set
397         // to zero.
398         if ((decision.fTriggerBits & 0xFFFFFFFC) != 0) return false;
399         return true;
400 }
401
402
403 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONSinglesDecisionBlockStruct& block)
404 {
405         if (not HeaderOk(block)) return false;
406
407         // Check that the trigger bits for each track have integrity.
408         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
409         {
410                 if (not IntegrityOk(block.fDecision[i])) return false;
411         }
412         
413         return true;
414 }
415
416
417 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONPairDecisionStruct& decision)
418 {
419         // Make sure that the reserved bits in the fTriggerBits field are set
420         // to zero.
421         if ((decision.fTriggerBits & 0xFFFFFF80) != 0) return false;
422         
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
426            )
427                 return false;
428         
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;
434         
435         return true;
436 }
437
438
439 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONPairsDecisionBlockStruct& block)
440 {
441         if (not HeaderOk(block)) return false;
442
443         // Check that the trigger bits for each track pair have integrity.
444         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
445         {
446                 if (not IntegrityOk(block.fDecision[i])) return false;
447         }
448         
449         return true;
450 }