]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/MUON/AliHLTMUONUtils.cxx
FindFASTJET
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONUtils.cxx
index c9f797d847aeefd6594000745044bc8685986feb..12c13ff83263b5125a78e6b2c556762c3f852c26 100644 (file)
@@ -13,7 +13,7 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
+// $Id$
 
 ///
 /// @file   AliHLTMUONUtils.cxx
 #include "AliHLTMUONConstants.h"
 #include "AliHLTMUONTriggerRecordsBlockStruct.h"
 #include "AliHLTMUONTrigRecsDebugBlockStruct.h"
-#include "AliHLTMUONTriggerChannelsBlockStruct.h"
 #include "AliHLTMUONRecHitsBlockStruct.h"
 #include "AliHLTMUONClustersBlockStruct.h"
 #include "AliHLTMUONChannelsBlockStruct.h"
 #include "AliHLTMUONMansoTracksBlockStruct.h"
 #include "AliHLTMUONMansoCandidatesBlockStruct.h"
+#include "AliHLTMUONTracksBlockStruct.h"
 #include "AliHLTMUONSinglesDecisionBlockStruct.h"
 #include "AliHLTMUONPairsDecisionBlockStruct.h"
 #include "AliMUONTrackerDDLDecoderEventHandler.h"
@@ -39,6 +39,8 @@
 #include <cmath>
 #include <cassert>
 
+ClassImp(AliHLTMUONUtils);
+
 
 AliHLTUInt32_t AliHLTMUONUtils::PackTriggerRecordFlags(
                AliHLTMUONParticleSign sign, const bool hitset[4]
@@ -93,6 +95,90 @@ void AliHLTMUONUtils::UnpackTriggerRecordFlags(
 }
 
 
+AliHLTUInt32_t AliHLTMUONUtils::PackRecHitFlags(
+               AliHLTUInt8_t chamber, AliHLTUInt16_t detElemId
+       )
+{
+       /// This packs the given parameters into the bits of a word appropriate
+       /// for AliHLTMUONRecHitStruct::fFlags.
+       /// @param chamber    The chamber number in the range [0..13].
+       /// @param detElemId  Detector element ID number.
+       /// @return  Returns the 32 bit packed word.
+       
+       return ((chamber & 0xF) << 12) | (detElemId & 0xFFF);
+}
+
+
+void AliHLTMUONUtils::UnpackRecHitFlags(
+               AliHLTUInt32_t flags, // [in]
+               AliHLTUInt8_t& chamber, // [out]
+               AliHLTUInt16_t& detElemId // [out]
+       )
+{
+       /// This unpacks the AliHLTMUONRecHitStruct::fFlags bits into
+       /// its component fields.
+       /// @param [in]  flags  The flags from an AliHLTMUONRecHitStruct structure.
+       /// @param [out] chamber    Sets the chamber number in the range [0..13].
+       /// @param [out] detElemId  Sets the detector element ID number.
+       
+       chamber = (flags >> 12) & 0xF;
+       detElemId = flags & 0xFFF;
+}
+
+
+AliHLTUInt32_t AliHLTMUONUtils::PackTrackFlags(
+               AliHLTMUONParticleSign sign, const bool hitset[16]
+       )
+{
+       /// This packs the given parameters into the bits of a word appropriate
+       /// for AliHLTMUONTrackStruct::fFlags.
+       /// @param sign    The particle sign.
+       /// @param hitset  Flags to indicate if the corresponding fHits[i] elements
+       ///                was set/filled.
+       /// @return  Returns the 32 bit packed word.
+       
+       AliHLTUInt32_t flags;
+       switch (sign)
+       {
+       case kSignMinus: flags = 0x80000000; break;
+       case kSignPlus:  flags = 0x40000000; break;
+       default:         flags = 0x00000000; break;
+       }
+       
+       for (AliHLTUInt32_t i = 0; i < 16; i++)
+       {
+               flags |= (hitset[i] ? (0x1 << i) : 0);
+       }
+       return flags;
+}
+
+
+void AliHLTMUONUtils::UnpackTrackFlags(
+               AliHLTUInt32_t flags, AliHLTMUONParticleSign& sign, bool hitset[16]
+       )
+{
+       /// This unpacks the AliHLTMUONTrackStruct::fFlags bits into
+       /// its component fields.
+       /// @param flags  The flags from an AliHLTMUONTrackStruct structure.
+       /// @param sign    Sets this to the particle sign.
+       /// @param hitset  Sets the array elements to indicate if the corresponding
+       ///                fHits[i] element was set/filled.
+       
+       AliHLTUInt32_t signbits = flags & 0xC0000000;
+       switch (signbits)
+       {
+       case 0x80000000: sign = kSignMinus;   break;
+       case 0x40000000: sign = kSignPlus;    break;
+       default:         sign = kSignUnknown; break;
+       }
+       
+       for (AliHLTUInt32_t i = 0; i < 16; i++)
+       {
+               hitset[i] = ((flags & (0x1u << i)) == (0x1u << i));
+       }
+}
+
+
 AliHLTUInt32_t AliHLTMUONUtils::PackTrackDecisionBits(bool highPt, bool lowPt)
 {
        ///
@@ -143,11 +229,12 @@ AliHLTUInt32_t AliHLTMUONUtils::PackPairDecisionBits(
        ///                    in the pair.
        /// @return  Returns the 32 bit packed word.
        ///
-       /// Note: Must have highPtCount + lowPtCount <= 2 and unlike == true if
-       /// highMass or lowMass is true.
+       /// Note: Must have highPtCount <= 2, lowPtCount <= 2 and
+       /// unlike == true if highMass or lowMass is true.
        ///
        
-       assert( highPtCount + lowPtCount <= 2 );
+       assert( lowPtCount <= 2 );
+       assert( highPtCount <= 2 );
        // highMass and lowMass must be false if unlike is false:
        assert( not unlike ? (highMass == false and lowMass == false) : true );
        
@@ -391,10 +478,6 @@ AliHLTMUONDataBlockType AliHLTMUONUtils::ParseCommandLineTypeString(const char*
        {
                return kTrigRecsDebugDataBlock;
        }
-       else if (strcmp(type, "trigchannels") == 0)
-       {
-               return kTriggerChannelsDataBlock;
-       }
        else if (strcmp(type, "rechits") == 0)
        {
                return kRecHitsDataBlock;
@@ -415,6 +498,10 @@ AliHLTMUONDataBlockType AliHLTMUONUtils::ParseCommandLineTypeString(const char*
        {
                return kMansoCandidatesDataBlock;
        }
+       else if (strcmp(type, "tracks") == 0)
+       {
+               return kTracksDataBlock;
+       }
        else if (strcmp(type, "singlesdecision") == 0)
        {
                return kSinglesDecisionDataBlock;
@@ -428,6 +515,55 @@ AliHLTMUONDataBlockType AliHLTMUONUtils::ParseCommandLineTypeString(const char*
 }
 
 
+const char* AliHLTMUONUtils::DataBlockTypeToString(AliHLTMUONDataBlockType type)
+{
+       /// Converts a type ID to a type string compatible with
+       /// HLT data types.
+       
+       static char str[kAliHLTComponentDataTypefIDsize+1];
+       AliHLTComponentDataType t;
+       switch (type)
+       {
+       case kTriggerRecordsDataBlock:
+               t = AliHLTMUONConstants::TriggerRecordsBlockDataType();
+               break;
+       case kTrigRecsDebugDataBlock:
+               t = AliHLTMUONConstants::TrigRecsDebugBlockDataType();
+               break;
+       case kRecHitsDataBlock:
+               t = AliHLTMUONConstants::RecHitsBlockDataType();
+               break;
+       case kClustersDataBlock:
+               t = AliHLTMUONConstants::ClusterBlockDataType();
+               break;
+       case kChannelsDataBlock:
+               t = AliHLTMUONConstants::ChannelBlockDataType();
+               break;
+       case kMansoTracksDataBlock:
+               t = AliHLTMUONConstants::MansoTracksBlockDataType();
+               break;
+       case kMansoCandidatesDataBlock:
+               t = AliHLTMUONConstants::MansoCandidatesBlockDataType();
+               break;
+       case kTracksDataBlock:
+               t = AliHLTMUONConstants::TracksBlockDataType();
+               break;
+       case kSinglesDecisionDataBlock:
+               t = AliHLTMUONConstants::SinglesDecisionBlockDataType();
+               break;
+       case kPairsDecisionDataBlock:
+               t = AliHLTMUONConstants::PairsDecisionBlockDataType();
+               break;
+       default:
+               return "UNKNOWN";
+       }
+       memcpy(&str, &t.fID, kAliHLTComponentDataTypefIDsize);
+       // Must insert the NULL character to make this an ANSI C string.
+       str[kAliHLTComponentDataTypefIDsize] = '\0';
+       return &str[0];
+}
+
+
 const char* AliHLTMUONUtils::FailureReasonToString(WhyNotValid reason)
 {
        /// This method converts the WhyNotValid enumeration to a string representation.
@@ -444,8 +580,12 @@ const char* AliHLTMUONUtils::FailureReasonToString(WhyNotValid reason)
        case kParticleSignBitsNotValid: return "kParticleSignBitsNotValid";
        case kHitNotMarkedAsNil: return "kHitNotMarkedAsNil";
        case kInvalidDetElementNumber: return "kInvalidDetElementNumber";
+       case kInvalidChamberNumber: return "kInvalidChamberNumber";
        case kHitIsNil: return "kHitIsNil";
-       case kInvalidChannelCount: return "kInvalidChannelCount";
+       case kInvalidChannelCountB: return "kInvalidChannelCountB";
+       case kInvalidChannelCountNB: return "kInvalidChannelCountNB";
+       case kInvalidChargeB: return "kInvalidChargeB";
+       case kInvalidChargeNB: return "kInvalidChargeNB";
        case kInvalidBusPatchId: return "kInvalidBusPatchId";
        case kInvalidManuId: return "kInvalidManuId";
        case kInvalidChannelAddress: return "kInvalidChannelAddress";
@@ -453,6 +593,8 @@ const char* AliHLTMUONUtils::FailureReasonToString(WhyNotValid reason)
        case kDataWordDifferent: return "kDataWordDifferent";
        case kChiSquareInvalid: return "kChiSquareInvalid";
        case kMomentumVectorNotZero: return "kMomentumVectorNotZero";
+       case kMomentumParamsNotZero: return "kMomentumParamsNotZero";
+       case kDCAVertexNotZero: return "kDCAVertexNotZero";
        case kRoiRadiusInvalid: return "kRoiRadiusInvalid";
        case kHitNotWithinRoi: return "kHitNotWithinRoi";
        case kPtValueNotValid: return "kPtValueNotValid";
@@ -500,11 +642,20 @@ const char* AliHLTMUONUtils::FailureReasonToMessage(WhyNotValid reason)
                        " structure was not set to nil.";
        case kInvalidDetElementNumber:
                return "An invalid detector element ID was found.";
+       case kInvalidChamberNumber:
+               return "An invalid chamber number was found.";
        case kHitIsNil:
                return "The hit cannot be set to a nil value.";
-       case kInvalidChannelCount:
-               return "The number of channels indicated is zero or outside"
-                       " the valid range.";
+       case kInvalidChannelCountB:
+               return "The number of channels in the bending plane indicated"
+                       " is zero or outside the valid range.";
+       case kInvalidChannelCountNB:
+               return "The number of channels in the non-bending plane indicated"
+                       " is zero or outside the valid range.";
+       case kInvalidChargeB:
+               return "The charge in the bending plane does not have a valid value.";
+       case kInvalidChargeNB:
+               return "The charge in the non-bending plane does not have a valid value.";
        case kInvalidBusPatchId:
                return "The bus patch identifier is outside the valid range.";
        case kInvalidManuId:
@@ -517,10 +668,16 @@ const char* AliHLTMUONUtils::FailureReasonToMessage(WhyNotValid reason)
                return "The raw data word is different from the unpacked values.";
        case kChiSquareInvalid:
                return "The chi squared value must be a positive value or -1"
-                       " indicating a fitting error.";
+                       " indicating no fit or a fitting error.";
        case kMomentumVectorNotZero:
                return "The chi sqaured value is set to -1 indicating momentum"
                        " was not fitted, but the momentum vector was not zero.";
+       case kMomentumParamsNotZero:
+               return "The chi sqaured value is set to -1 indicating the track"
+                       " was not fitted, but the fitted momentum parameters are not zero.";
+       case kDCAVertexNotZero:
+               return "The chi sqaured value is set to -1 indicating the track"
+                       " was not fitted, but the DCA vertex is not zero.";
        case kRoiRadiusInvalid:
                return "The region of interest radius is invalid.";
        case kHitNotWithinRoi:
@@ -573,8 +730,12 @@ bool AliHLTMUONUtils::RecordNumberWasSet(WhyNotValid reason)
        case kParticleSignBitsNotValid:
        case kHitNotMarkedAsNil:
        case kInvalidDetElementNumber:
+       case kInvalidChamberNumber:
        case kHitIsNil:
-       case kInvalidChannelCount:
+       case kInvalidChannelCountB:
+       case kInvalidChannelCountNB:
+       case kInvalidChargeB:
+       case kInvalidChargeNB:
        case kInvalidBusPatchId:
        case kInvalidManuId:
        case kInvalidChannelAddress:
@@ -599,12 +760,12 @@ bool AliHLTMUONUtils::HeaderOk(
 {
        /// Method used to check if the header information corresponds to the
        /// supposed type of the raw dHLT data block.
-       /// [in]  \param block  The data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the header is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -647,12 +808,12 @@ bool AliHLTMUONUtils::HeaderOk(
 {
        /// Method used to check if the header information corresponds to the
        /// supposed type of the raw dHLT data block.
-       /// [in]  \param block  The data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the header is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -689,49 +850,66 @@ bool AliHLTMUONUtils::HeaderOk(
 
 
 bool AliHLTMUONUtils::HeaderOk(
-               const AliHLTMUONTriggerChannelsBlockStruct& block,
-               WhyNotValid* reason
+               const AliHLTMUONRecHitsBlockStruct& block,
+               WhyNotValid* reason, AliHLTUInt32_t& reasonCount
        )
 {
        /// Method used to check if the header information corresponds to the
        /// supposed type of the raw dHLT data block.
-       /// [in]  \param block  The data block to check.
-       /// [out] \param reason  If this is not NULL, then it will be filled with
-       ///      the reason code describing why the header is not valid, if and
-       ///      only if a problem is found with the data.
+       /// \param [in]  block  The data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
+       ///      to an array of at least 'reasonCount' number of elements. It will
+       ///      be filled with the reason codes describing why the header is not
+       ///      valid.
+       /// \param [in,out] reasonCount  This should initially specify the size of
+       ///      the array pointed to by 'reason'. It will be filled with the number
+       ///      of items actually filled into the reason array upon exit from this
+       ///      method.
        /// \returns  true if there is no problem with the header and false otherwise.
        
+       AliHLTUInt32_t maxCount = reasonCount;
+       reasonCount = 0;
+       bool result = true;
+       
        // The block must have the correct type.
-       if (block.fHeader.fType != kTriggerChannelsDataBlock)
+       if (block.fHeader.fType != kRecHitsDataBlock)
        {
-               if (reason != NULL) *reason = kHeaderContainsWrongType;
-               return false;
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kHeaderContainsWrongType;
+                       reasonCount++;
+               }
+               result = false;
        }
        
        // The block's record width must be the correct size.
-       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTriggerChannelStruct))
+       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONRecHitStruct))
        {
-               if (reason != NULL) *reason = kHeaderContainsWrongRecordWidth;
-               return false;
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kHeaderContainsWrongRecordWidth;
+                       reasonCount++;
+               }
+               result = false;
        }
        
-       return true;
+       return result;
 }
 
 
 bool AliHLTMUONUtils::HeaderOk(
-               const AliHLTMUONRecHitsBlockStruct& block,
+               const AliHLTMUONClustersBlockStruct& block,
                WhyNotValid* reason, AliHLTUInt32_t& reasonCount
        )
 {
        /// Method used to check if the header information corresponds to the
        /// supposed type of the raw dHLT data block.
-       /// [in]  \param block  The data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the header is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -742,7 +920,7 @@ bool AliHLTMUONUtils::HeaderOk(
        bool result = true;
        
        // The block must have the correct type.
-       if (block.fHeader.fType != kRecHitsDataBlock)
+       if (block.fHeader.fType != kClustersDataBlock)
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -753,7 +931,7 @@ bool AliHLTMUONUtils::HeaderOk(
        }
        
        // The block's record width must be the correct size.
-       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONRecHitStruct))
+       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONClusterStruct))
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -768,18 +946,18 @@ bool AliHLTMUONUtils::HeaderOk(
 
 
 bool AliHLTMUONUtils::HeaderOk(
-               const AliHLTMUONClustersBlockStruct& block,
+               const AliHLTMUONChannelsBlockStruct& block,
                WhyNotValid* reason, AliHLTUInt32_t& reasonCount
        )
 {
        /// Method used to check if the header information corresponds to the
        /// supposed type of the raw dHLT data block.
-       /// [in]  \param block  The data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the header is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -790,7 +968,7 @@ bool AliHLTMUONUtils::HeaderOk(
        bool result = true;
        
        // The block must have the correct type.
-       if (block.fHeader.fType != kClustersDataBlock)
+       if (block.fHeader.fType != kChannelsDataBlock)
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -801,7 +979,7 @@ bool AliHLTMUONUtils::HeaderOk(
        }
        
        // The block's record width must be the correct size.
-       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONClusterStruct))
+       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONChannelStruct))
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -816,18 +994,18 @@ bool AliHLTMUONUtils::HeaderOk(
 
 
 bool AliHLTMUONUtils::HeaderOk(
-               const AliHLTMUONChannelsBlockStruct& block,
+               const AliHLTMUONMansoTracksBlockStruct& block,
                WhyNotValid* reason, AliHLTUInt32_t& reasonCount
        )
 {
        /// Method used to check if the header information corresponds to the
        /// supposed type of the raw dHLT data block.
-       /// [in]  \param block  The data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the header is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -838,7 +1016,7 @@ bool AliHLTMUONUtils::HeaderOk(
        bool result = true;
        
        // The block must have the correct type.
-       if (block.fHeader.fType != kChannelsDataBlock)
+       if (block.fHeader.fType != kMansoTracksDataBlock)
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -849,7 +1027,7 @@ bool AliHLTMUONUtils::HeaderOk(
        }
        
        // The block's record width must be the correct size.
-       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONChannelStruct))
+       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONMansoTrackStruct))
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -864,18 +1042,18 @@ bool AliHLTMUONUtils::HeaderOk(
 
 
 bool AliHLTMUONUtils::HeaderOk(
-               const AliHLTMUONMansoTracksBlockStruct& block,
+               const AliHLTMUONMansoCandidatesBlockStruct& block,
                WhyNotValid* reason, AliHLTUInt32_t& reasonCount
        )
 {
        /// Method used to check if the header information corresponds to the
        /// supposed type of the raw dHLT data block.
-       /// [in]  \param block  The data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the header is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -886,7 +1064,7 @@ bool AliHLTMUONUtils::HeaderOk(
        bool result = true;
        
        // The block must have the correct type.
-       if (block.fHeader.fType != kMansoTracksDataBlock)
+       if (block.fHeader.fType != kMansoCandidatesDataBlock)
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -897,7 +1075,7 @@ bool AliHLTMUONUtils::HeaderOk(
        }
        
        // The block's record width must be the correct size.
-       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONMansoTrackStruct))
+       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONMansoCandidateStruct))
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -912,18 +1090,18 @@ bool AliHLTMUONUtils::HeaderOk(
 
 
 bool AliHLTMUONUtils::HeaderOk(
-               const AliHLTMUONMansoCandidatesBlockStruct& block,
+               const AliHLTMUONTracksBlockStruct& block,
                WhyNotValid* reason, AliHLTUInt32_t& reasonCount
        )
 {
        /// Method used to check if the header information corresponds to the
        /// supposed type of the raw dHLT data block.
-       /// [in]  \param block  The data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the header is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -934,7 +1112,7 @@ bool AliHLTMUONUtils::HeaderOk(
        bool result = true;
        
        // The block must have the correct type.
-       if (block.fHeader.fType != kMansoCandidatesDataBlock)
+       if (block.fHeader.fType != kTracksDataBlock)
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -945,7 +1123,7 @@ bool AliHLTMUONUtils::HeaderOk(
        }
        
        // The block's record width must be the correct size.
-       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONMansoCandidateStruct))
+       if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTrackStruct))
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -966,12 +1144,12 @@ bool AliHLTMUONUtils::HeaderOk(
 {
        /// Method used to check if the header information corresponds to the
        /// supposed type of the raw dHLT data block.
-       /// [in]  \param block  The data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the header is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -1014,12 +1192,12 @@ bool AliHLTMUONUtils::HeaderOk(
 {
        /// Method used to check if the header information corresponds to the
        /// supposed type of the raw dHLT data block.
-       /// [in]  \param block  The data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the header is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -1063,12 +1241,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// trigger record structure is OK and returns true in that case.
-       /// [in] \param tr  The trigger record structure to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  tr  The trigger record structure to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the structure is
        ///      not valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -1129,6 +1307,17 @@ bool AliHLTMUONUtils::IntegrityOk(
                }
                result = false;
        }
+       
+       // Check the individual hits
+       for (int i = 0; i < 4; i++)
+       {
+               AliHLTUInt32_t filledCount = maxCount - reasonCount;
+               if (not IntegrityOk(tr.fHit[i], reason + reasonCount, filledCount))
+               {
+                       reasonCount += filledCount;
+                       result = false;
+               }
+       }
 
        return result;
 }
@@ -1143,12 +1332,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// dHLT raw internal data block is OK and returns true in that case.
-       /// [in] \param block  The trigger record data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The trigger record data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the data block is
        ///      not valid.
-       /// [out] \param recordNum  If this is not NULL, then it is assumed to point
+       /// \param [out] recordNum  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the number of the trigger record that had a problem.
        ///      The value 'recordNum[i]' will only contain a valid value if
@@ -1157,9 +1346,11 @@ bool AliHLTMUONUtils::IntegrityOk(
        ///        - kReservedBitsNotZero
        ///        - kParticleSignBitsNotValid
        ///        - kHitNotMarkedAsNil
+       ///        - kInvalidDetElementNumber
+       ///        - kInvalidChamberNumber
        /// \note You can use RecordNumberWasSet(reason[i]) to check if 'recordNum[i]'
        ///      was set and is valid or not.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason' and 'recordNum'. It will be filled
        ///      with the number of items actually filled into the arrays upon exit
        ///      from this method.
@@ -1219,12 +1410,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// trigger record debug information structure is OK and returns true in that case.
-       /// [in] \param trigInfo  The trigger record debug information structure to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  trigInfo  The trigger record debug information structure to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the structure is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -1246,10 +1437,14 @@ bool AliHLTMUONUtils::IntegrityOk(
        }
 
        // Check that the fDetElemId[i] numbers are valid.
-       if ( not (trigInfo.fDetElemId[0] >= 0 or trigInfo.fDetElemId[0] == -1) or
-            not (trigInfo.fDetElemId[1] >= 0 or trigInfo.fDetElemId[1] == -1) or
-            not (trigInfo.fDetElemId[2] >= 0 or trigInfo.fDetElemId[2] == -1) or
-            not (trigInfo.fDetElemId[3] >= 0 or trigInfo.fDetElemId[3] == -1)
+       if ( not ((trigInfo.fDetElemId[0] >= 100 and trigInfo.fDetElemId[0] < 1500)
+                 or trigInfo.fDetElemId[0] == -1)
+            or not ((trigInfo.fDetElemId[1] >= 100 and trigInfo.fDetElemId[1] < 1500)
+                 or trigInfo.fDetElemId[1] == -1)
+            or not ((trigInfo.fDetElemId[2] >= 100 and trigInfo.fDetElemId[2] < 1500)
+                 or trigInfo.fDetElemId[2] == -1)
+            or not ((trigInfo.fDetElemId[3] >= 100 and trigInfo.fDetElemId[3] < 1500)
+                 or trigInfo.fDetElemId[3] == -1)
           )
        {
                if (reason != NULL and reasonCount < maxCount)
@@ -1273,13 +1468,13 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// dHLT raw internal data block is OK and returns true in that case.
-       /// [in] \param block  The trigger record debugging information data block
+       /// \param [in]  block  The trigger record debugging information data block
        ///      to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the data block is
        ///      not valid.
-       /// [out] \param recordNum  If this is not NULL, then it is assumed to point
+       /// \param [out] recordNum  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the number of the trigger record debug information
        ///      structure that had a problem.
@@ -1289,7 +1484,7 @@ bool AliHLTMUONUtils::IntegrityOk(
        ///        - kInvalidDetElementNumber
        /// \note You can use RecordNumberWasSet(reason[i]) to check if 'recordNum[i]'
        ///      was set and is valid or not.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason' and 'recordNum'. It will be filled
        ///      with the number of items actually filled into the arrays upon exit
        ///      from this method.
@@ -1342,40 +1537,103 @@ bool AliHLTMUONUtils::IntegrityOk(
 
 
 bool AliHLTMUONUtils::IntegrityOk(
-               const AliHLTMUONTriggerChannelsBlockStruct& block,
-               WhyNotValid* reason
+               const AliHLTMUONRecHitStruct& hit,
+               WhyNotValid* reason,
+               AliHLTUInt32_t& reasonCount
        )
 {
        /// This method is used to check more extensively if the integrity of the
-       /// dHLT raw internal data block is OK and returns true in that case.
-       /// [in] \param block  The trigger channels data block to check.
-       /// [out] \param reason  If this is not NULL, then it will be filled with
-       ///      the reason code describing why the data block is not valid, if and
-       ///      only if a problem is found with the data.
-       /// \returns  true if there is no problem with the data and false otherwise.
+       /// reconstructed hit structure is OK and returns true in that case.
+       /// \param [in]  hit  The reconstructed hit structure to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
+       ///      to an array of at least 'reasonCount' number of elements. It will
+       ///      be filled with the reason codes describing why the structure is
+       ///      not valid.
+       /// \param [in,out] reasonCount  This should initially specify the size of
+       ///      the array pointed to by 'reason'. It will be filled with the number
+       ///      of items actually filled into the reason array upon exit from this
+       ///      method.
+       /// \returns  true if there is no problem with the structure and false otherwise.
+       
+       AliHLTUInt32_t maxCount = reasonCount;
+       reasonCount = 0;
+       bool result = true;
+       
+       // If this is a NIL hit then skip all other checks.
+       if (hit == AliHLTMUONConstants::NilRecHitStruct())
+       {
+               return true;
+       }
        
-       if (not HeaderOk(block, reason)) return false;
-       return true;
+       // Make sure that the reserved bits in the fFlags field are set
+       // to zero.
+       if ((hit.fFlags & 0x3FFF0000) != 0)
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kReservedBitsNotZero;
+                       reasonCount++;
+               }
+               result = false;
+       }
+
+       AliHLTUInt32_t detElemId = hit.fFlags & 0x00000FFF;
+       AliHLTUInt32_t chamber = (hit.fFlags & 0x0000F000) >> 12;
+       
+       // Make sure the detector element ID number is valid.
+       if (not (detElemId >= 100 and detElemId < 1500))
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kInvalidDetElementNumber;
+                       reasonCount++;
+               }
+               result = false;
+       }
+       
+       // Make sure the chamber number is valid.
+       if (((detElemId / 100) - 1) != chamber or chamber >= 14)
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kInvalidChamberNumber;
+                       reasonCount++;
+               }
+               result = false;
+       }
+
+       return result;
 }
 
 
 bool AliHLTMUONUtils::IntegrityOk(
                const AliHLTMUONRecHitsBlockStruct& block,
                WhyNotValid* reason,
+               AliHLTUInt32_t* recordNum,
                AliHLTUInt32_t& reasonCount
        )
 {
        /// This method is used to check more extensively if the integrity of the
-       /// dHLT raw internal data block is OK and returns true in that case.
-       /// [in] \param block  The reconstructed hits data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// dHLT raw internal hits data block is OK and returns true in that case.
+       /// \param [in]  block  The reconstructed hits data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the data block is
        ///      not valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
-       ///      the array pointed to by 'reason'. It will be filled with the number
-       ///      of items actually filled into the reason array upon exit from this
-       ///      method.
+       /// \param [out] recordNum  If this is not NULL, then it is assumed to point
+       ///      to an array of at least 'reasonCount' number of elements. It will
+       ///      be filled with the number of the reconstructed hits that had a problem.
+       ///      The value 'recordNum[i]' will only contain a valid value if
+       ///      the corresponding 'reason[i]' contains one of:
+       ///        - kReservedBitsNotZero
+       ///        - kInvalidDetElementNumber
+       ///        - kInvalidChamberNumber
+       /// \note You can use RecordNumberWasSet(reason[i]) to check if 'recordNum[i]'
+       ///      was set and is valid or not.
+       /// \param [in,out] reasonCount  This should initially specify the size of
+       ///      the array pointed to by 'reason' and 'recordNum'. It will be filled
+       ///      with the number of items actually filled into the arrays upon exit
+       ///      from this method.
        /// \returns  true if there is no problem with the data and false otherwise.
        
        AliHLTUInt32_t maxCount = reasonCount;
@@ -1401,6 +1659,24 @@ bool AliHLTMUONUtils::IntegrityOk(
                        }
                }
        }
+
+       // Check integrity of the individual hit structures.
+       for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
+       {
+               AliHLTUInt32_t filledCount = maxCount - reasonCount;
+               if (not IntegrityOk(hit[i], reason+reasonCount, filledCount))
+               {
+                       // reasons filled in IntegrityOk, now we just need to adjust
+                       // reasonCount and fill the recordNum values.
+                       if (recordNum != NULL)
+                       {
+                               for (AliHLTUInt32_t n = 0; n < filledCount; n++)
+                                       recordNum[reasonCount + n] = i;
+                       }
+                       reasonCount += filledCount;
+                       result = false;
+               }
+       }
        
        return result;
 }
@@ -1414,12 +1690,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// cluster structure is OK and returns true in that case.
-       /// [in] \param cluster  The cluster structure to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  cluster  The cluster structure to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the structure is
        ///      not valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -1452,7 +1728,9 @@ bool AliHLTMUONUtils::IntegrityOk(
        }
        
        // Make sure the detector element is a valid value.
-       if (not (cluster.fDetElemId >= 0 or cluster.fDetElemId == -1))
+       if (not ((cluster.fDetElemId >= 100 and cluster.fDetElemId < 1500)
+           or cluster.fDetElemId == -1)
+          )
        {
                if (reason != NULL and reasonCount < maxCount)
                {
@@ -1463,13 +1741,42 @@ bool AliHLTMUONUtils::IntegrityOk(
        }
        
        // The number of channels should be in a reasonable range.
-       // between 1 and the maximum number of channels per DDL.
-       // 1<<17 taken from the 11 bits MANU ID + 6 bits channel address.
-       if (cluster.fNchannels < 1 or (1<<17) < cluster.fNchannels)
+       // Using a value of 5*5*2, 5 pads by 5 pads by 2 cathode planes.
+       if (int(cluster.fNchannelsB) < 1 or (5*5*2) < int(cluster.fNchannelsB))
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kInvalidChannelCountB;
+                       reasonCount++;
+               }
+               result = false;
+       }
+       if (int(cluster.fNchannelsNB) < 1 or (5*5*2) < int(cluster.fNchannelsNB))
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kInvalidChannelCountNB;
+                       reasonCount++;
+               }
+               result = false;
+       }
+
+       
+       // The charge values must be a positive value or -1.
+       if (not (cluster.fChargeB >= 0 or cluster.fChargeB == -1))
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kInvalidChargeB;
+                       reasonCount++;
+               }
+               result = false;
+       }
+       if (not (cluster.fChargeNB >= 0 or cluster.fChargeNB == -1))
        {
                if (reason != NULL and reasonCount < maxCount)
                {
-                       reason[reasonCount] = kInvalidChannelCount;
+                       reason[reasonCount] = kInvalidChargeNB;
                        reasonCount++;
                }
                result = false;
@@ -1488,12 +1795,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// dHLT internal clusters data block is OK and returns true in that case.
-       /// [in] \param block  The clusters data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The clusters data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the data block is
        ///      not valid.
-       /// [out] \param recordNum  If this is not NULL, then it is assumed to point
+       /// \param [out] recordNum  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the number of the cluster structure that had a problem.
        ///      The value 'recordNum[i]' will only contain a valid value if
@@ -1501,10 +1808,13 @@ bool AliHLTMUONUtils::IntegrityOk(
        ///        - kInvalidIdValue
        ///        - kHitIsNil
        ///        - kInvalidDetElementNumber
-       ///        - kInvalidChannelCount
+       ///        - kInvalidChannelCountB
+       ///        - kInvalidChannelCountNB
+       ///        - kInvalidChargeB
+       ///        - kInvalidChargeNB
        /// \note You can use RecordNumberWasSet(reason[i]) to check if 'recordNum[i]'
        ///      was set and is valid or not.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason' and 'recordNum'. It will be filled
        ///      with the number of items actually filled into the arrays upon exit
        ///      from this method.
@@ -1582,12 +1892,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// channel structure is OK and returns true in that case.
-       /// [in] \param cluster  The channel structure to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  cluster  The channel structure to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the structure is
        ///      not valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -1683,12 +1993,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// dHLT internal channels data block is OK and returns true in that case.
-       /// [in] \param block  The channels data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The channels data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the data block is
        ///      not valid.
-       /// [out] \param recordNum  If this is not NULL, then it is assumed to point
+       /// \param [out] recordNum  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the number of the channel structure that had a problem.
        ///      The value 'recordNum[i]' will only contain a valid value if
@@ -1701,7 +2011,7 @@ bool AliHLTMUONUtils::IntegrityOk(
        ///        - kDataWordDifferent
        /// \note You can use RecordNumberWasSet(reason[i]) to check if 'recordNum[i]'
        ///      was set and is valid or not.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason' and 'recordNum'. It will be filled
        ///      with the number of items actually filled into the arrays upon exit
        ///      from this method.
@@ -1712,24 +2022,6 @@ bool AliHLTMUONUtils::IntegrityOk(
        
        const AliHLTMUONChannelStruct* channel =
                reinterpret_cast<const AliHLTMUONChannelStruct*>(&block + 1);
-       
-       // Check if any cluster ID is duplicated.
-       for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
-       {
-               AliHLTInt32_t id = channel[i].fClusterId;
-               for (AliHLTUInt32_t j = i+1; j < block.fHeader.fNrecords; j++)
-               {
-                       if (id == channel[j].fClusterId)
-                       {
-                               if (reason != NULL and reasonCount < maxCount)
-                               {
-                                       reason[reasonCount] = kFoundDuplicateIDs;
-                                       reasonCount++;
-                               }
-                               result = false;
-                       }
-               }
-       }
 
        // Check integrity of individual channel structures.
        for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
@@ -1761,12 +2053,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// Manso track structure is OK and returns true in that case.
-       /// [in] \param track  The track structure to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  track  The track structure to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the structure is
        ///      not valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -1863,6 +2155,17 @@ bool AliHLTMUONUtils::IntegrityOk(
                result = false;
        }
        
+       // Check the individual hits
+       for (int i = 0; i < 4; i++)
+       {
+               AliHLTUInt32_t filledCount = maxCount - reasonCount;
+               if (not IntegrityOk(track.fHit[i], reason + reasonCount, filledCount))
+               {
+                       reasonCount += filledCount;
+                       result = false;
+               }
+       }
+       
        return result;
 }
 
@@ -1876,12 +2179,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// dHLT internal Manso track data block is OK and returns true in that case.
-       /// [in] \param block  The Manso track data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The Manso track data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the data block is
        ///      not valid.
-       /// [out] \param recordNum  If this is not NULL, then it is assumed to point
+       /// \param [out] recordNum  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the number of the Manso track that had a problem.
        ///      The value 'recordNum[i]' will only contain a valid value if
@@ -1893,9 +2196,11 @@ bool AliHLTMUONUtils::IntegrityOk(
        ///        - kHitNotMarkedAsNil
        ///        - kChiSquareInvalid
        ///        - kMomentumVectorNotZero
+       ///        - kInvalidDetElementNumber
+       ///        - kInvalidChamberNumber
        /// \note You can use RecordNumberWasSet(reason[i]) to check if 'recordNum[i]'
        ///      was set and is valid or not.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason' and 'recordNum'. It will be filled
        ///      with the number of items actually filled into the arrays upon exit
        ///      from this method.
@@ -1955,12 +2260,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// Manso track candidate structure is OK and returns true in that case.
-       /// [in] \param track  The track candidate structure to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  track  The track candidate structure to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the structure is
        ///      not valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -2020,12 +2325,12 @@ bool AliHLTMUONUtils::IntegrityOk(
        /// This method is used to check more extensively if the integrity of the
        /// dHLT internal Manso candidates data block is OK and returns true in
        /// that case.
-       /// [in] \param block  The Manso track candidate data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The Manso track candidate data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the data block is
        ///      not valid.
-       /// [out] \param recordNum  If this is not NULL, then it is assumed to point
+       /// \param [out] recordNum  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the number of the track candidate that had a problem.
        ///      The value 'recordNum[i]' will only contain a valid value if
@@ -2040,7 +2345,7 @@ bool AliHLTMUONUtils::IntegrityOk(
        ///        - kHitNotWithinRoi
        /// \note You can use RecordNumberWasSet(reason[i]) to check if 'recordNum[i]'
        ///      was set and is valid or not.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason' and 'recordNum'. It will be filled
        ///      with the number of items actually filled into the arrays upon exit
        ///      from this method.
@@ -2092,6 +2397,240 @@ bool AliHLTMUONUtils::IntegrityOk(
 }
 
 
+bool AliHLTMUONUtils::IntegrityOk(
+               const AliHLTMUONTrackStruct& track,
+               WhyNotValid* reason,
+               AliHLTUInt32_t& reasonCount
+       )
+{
+       /// This method is used to check more extensively if the integrity of the
+       /// full track structure is OK and returns true in that case.
+       /// \param [in]  track  The track structure to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
+       ///      to an array of at least 'reasonCount' number of elements. It will
+       ///      be filled with the reason codes describing why the structure is
+       ///      not valid.
+       /// \param [in,out] reasonCount  This should initially specify the size of
+       ///      the array pointed to by 'reason'. It will be filled with the number
+       ///      of items actually filled into the reason array upon exit from this
+       ///      method.
+       /// \returns  true if there is no problem with the structure and false otherwise.
+       
+       AliHLTUInt32_t maxCount = reasonCount;
+       reasonCount = 0;
+       bool result = true;
+       
+       // Check that the track ID has a valid value.
+       if (not (track.fId >= 0 or track.fId == -1))
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kInvalidIdValue;
+                       reasonCount++;
+               }
+               result = false;
+       }
+       
+       // Check that the corresponding trigger record ID has a valid value.
+       if (not (track.fTrigRec >= 0 or track.fTrigRec == -1))
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kInvalidTriggerIdValue;
+                       reasonCount++;
+               }
+               result = false;
+       }
+       
+       // Make sure that the reserved bits in the fFlags field are set
+       // to zero.
+       if ((track.fFlags & 0x3FFF0000) != 0)
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kReservedBitsNotZero;
+                       reasonCount++;
+               }
+               result = false;
+       }
+
+       // Make sure the sign is not invalid.
+       if ((track.fFlags & 0xC0000000) == 0xC0000000)
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kParticleSignBitsNotValid;
+                       reasonCount++;
+               }
+               result = false;
+       }
+
+       // Check that fHit[i] is nil if the corresponding bit in the
+       // flags word is zero.
+       const AliHLTMUONRecHitStruct& nilhit = AliHLTMUONConstants::NilRecHitStruct();
+       for (int i = 0; i < 16; i++)
+       {
+               if ((track.fFlags & (0x1 << i)) == 0 and track.fHit[i] != nilhit)
+               {
+                       if (reason != NULL and reasonCount < maxCount)
+                       {
+                               reason[reasonCount] = kHitNotMarkedAsNil;
+                               reasonCount++;
+                       }
+                       result = false;
+                       break;
+               }
+       }
+
+       // Check that the chi squared value is valid
+       if (not (track.fChi2 >= 0 or track.fChi2 == -1))
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kChiSquareInvalid;
+                       reasonCount++;
+               }
+               result = false;
+       }
+
+       // Check that if chi squared is -1 then the momentum vector is zero.
+       if (track.fChi2 == -1 and
+           not (track.fPx == 0 and track.fPy == 0 and track.fPz == 0)
+          )
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kMomentumVectorNotZero;
+                       reasonCount++;
+               }
+               result = false;
+       }
+
+       // Check that if chi squared is -1 then the momentum parameters are zero.
+       if (track.fChi2 == -1 and
+           not (track.fInverseBendingMomentum == 0 and track.fThetaX == 0 and track.fThetaY == 0)
+          )
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kMomentumParamsNotZero;
+                       reasonCount++;
+               }
+               result = false;
+       }
+
+       // Check that if chi squared is -1 then the momentum parameters are zero.
+       if (track.fChi2 == -1 and
+           not (track.fX == 0 and track.fY == 0 and track.fZ == 0)
+          )
+       {
+               if (reason != NULL and reasonCount < maxCount)
+               {
+                       reason[reasonCount] = kDCAVertexNotZero;
+                       reasonCount++;
+               }
+               result = false;
+       }
+       
+       // Check the individual hits
+       for (int i = 0; i < 16; i++)
+       {
+               AliHLTUInt32_t filledCount = maxCount - reasonCount;
+               if (not IntegrityOk(track.fHit[i], reason + reasonCount, filledCount))
+               {
+                       reasonCount += filledCount;
+                       result = false;
+               }
+       }
+       
+       return result;
+}
+
+
+bool AliHLTMUONUtils::IntegrityOk(
+               const AliHLTMUONTracksBlockStruct& block,
+               WhyNotValid* reason,
+               AliHLTUInt32_t* recordNum,
+               AliHLTUInt32_t& reasonCount
+       )
+{
+       /// This method is used to check more extensively if the integrity of the
+       /// dHLT internal track data block is OK and returns true in that case.
+       /// \param [in]  block  The track data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
+       ///      to an array of at least 'reasonCount' number of elements. It will
+       ///      be filled with the reason codes describing why the data block is
+       ///      not valid.
+       /// \param [out] recordNum  If this is not NULL, then it is assumed to point
+       ///      to an array of at least 'reasonCount' number of elements. It will
+       ///      be filled with the number of the Manso track that had a problem.
+       ///      The value 'recordNum[i]' will only contain a valid value if
+       ///      the corresponding 'reason[i]' contains one of:
+       ///        - kInvalidIdValue
+       ///        - kInvalidTriggerIdValue
+       ///        - kReservedBitsNotZero
+       ///        - kParticleSignBitsNotValid
+       ///        - kHitNotMarkedAsNil
+       ///        - kChiSquareInvalid
+       ///        - kMomentumVectorNotZero
+       ///        - kMomentumParamsNotZero
+       ///        - kDCAVertexNotZero
+       ///        - kInvalidDetElementNumber
+       ///        - kInvalidChamberNumber
+       /// \note You can use RecordNumberWasSet(reason[i]) to check if 'recordNum[i]'
+       ///      was set and is valid or not.
+       /// \param [in,out] reasonCount  This should initially specify the size of
+       ///      the array pointed to by 'reason' and 'recordNum'. It will be filled
+       ///      with the number of items actually filled into the arrays upon exit
+       ///      from this method.
+       /// \returns  true if there is no problem with the data and false otherwise.
+       
+       AliHLTUInt32_t maxCount = reasonCount;
+       bool result = HeaderOk(block, reason, reasonCount);
+       
+       const AliHLTMUONTrackStruct* track =
+               reinterpret_cast<const AliHLTMUONTrackStruct*>(&block + 1);
+       
+       // Check if any track ID is duplicated.
+       for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
+       {
+               AliHLTInt32_t id = track[i].fId;
+               for (AliHLTUInt32_t j = i+1; j < block.fHeader.fNrecords; j++)
+               {
+                       if (id == track[j].fId)
+                       {
+                               if (reason != NULL and reasonCount < maxCount)
+                               {
+                                       reason[reasonCount] = kFoundDuplicateIDs;
+                                       reasonCount++;
+                               }
+                               result = false;
+                       }
+               }
+       }
+       
+       // Check that all the tracks have integrity.
+       for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
+       {
+               AliHLTUInt32_t filledCount = maxCount - reasonCount;
+               if (not IntegrityOk(track[i], reason+reasonCount, filledCount))
+               {
+                       // reasons filled in IntegrityOk, now we just need to adjust
+                       // reasonCount and fill the recordNum values.
+                       if (recordNum != NULL)
+                       {
+                               for (AliHLTUInt32_t n = 0; n < filledCount; n++)
+                                       recordNum[reasonCount + n] = i;
+                       }
+                       reasonCount += filledCount;
+                       result = false;
+               }
+       }
+       
+       return result;
+}
+
+
 bool AliHLTMUONUtils::IntegrityOk(
                const AliHLTMUONTrackDecisionStruct& decision,
                WhyNotValid* reason,
@@ -2100,12 +2639,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// single track trigger decision structure is OK and returns true in that case.
-       /// [in] \param decision  The trigger decision structure to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  decision  The trigger decision structure to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the structure is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -2163,12 +2702,12 @@ bool AliHLTMUONUtils::IntegrityOk(
        /// This method is used to check more extensively if the integrity of the
        /// dHLT internal single track trigger decision data block is OK and returns
        /// true in that case.
-       /// [in] \param block  The single track trigger decision data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The single track trigger decision data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the data block is
        ///      not valid.
-       /// [out] \param recordNum  If this is not NULL, then it is assumed to point
+       /// \param [out] recordNum  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the number of the trigger decision that had a problem.
        ///      The value 'recordNum[i]' will only contain a valid value if
@@ -2178,7 +2717,7 @@ bool AliHLTMUONUtils::IntegrityOk(
        ///        - kPtValueNotValid
        /// \note You can use RecordNumberWasSet(reason[i]) to check if 'recordNum[i]'
        ///      was set and is valid or not.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason' and 'recordNum'. It will be filled
        ///      with the number of items actually filled into the arrays upon exit
        ///      from this method.
@@ -2238,12 +2777,12 @@ bool AliHLTMUONUtils::IntegrityOk(
 {
        /// This method is used to check more extensively if the integrity of the
        /// track pair trigger decision structure is OK and returns true in that case.
-       /// [in] \param decision  The trigger decision structure to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  decision  The trigger decision structure to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the structure is not
        ///      valid.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason'. It will be filled with the number
        ///      of items actually filled into the reason array upon exit from this
        ///      method.
@@ -2338,12 +2877,12 @@ bool AliHLTMUONUtils::IntegrityOk(
        /// This method is used to check more extensively if the integrity of the
        /// dHLT internal track pair trigger decision data block is OK and returns
        /// true in that case.
-       /// [in] \param block  The track pair trigger decision data block to check.
-       /// [out] \param reason  If this is not NULL, then it is assumed to point
+       /// \param [in]  block  The track pair trigger decision data block to check.
+       /// \param [out] reason  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the reason codes describing why the data block is
        ///      not valid.
-       /// [out] \param recordNum  If this is not NULL, then it is assumed to point
+       /// \param [out] recordNum  If this is not NULL, then it is assumed to point
        ///      to an array of at least 'reasonCount' number of elements. It will
        ///      be filled with the number of the trigger decision that had a problem.
        ///      The value 'recordNum[i]' will only contain a valid value if
@@ -2356,7 +2895,7 @@ bool AliHLTMUONUtils::IntegrityOk(
        ///        - kHighPtCountInvalid
        /// \note You can use RecordNumberWasSet(reason[i]) to check if 'recordNum[i]'
        ///      was set and is valid or not.
-       /// [in/out] \param reasonCount  This should initially specify the size of
+       /// \param [in,out] reasonCount  This should initially specify the size of
        ///      the array pointed to by 'reason' and 'recordNum'. It will be filled
        ///      with the number of items actually filled into the arrays upon exit
        ///      from this method.