Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:53

0001 #include "DataFormats/TrackReco/interface/HitPattern.h"
0002 
0003 /* This file contains the function used to read back v12 versions of HitPatterns from a ROOT file.
0004    The function is called by a ROOT IO rule.
0005  */
0006 
0007 using namespace reco;
0008 
0009 namespace {
0010   constexpr unsigned short HitSize = 11;
0011   constexpr unsigned short PatternSize = 50;
0012   constexpr int MaxHitsV12 = (PatternSize * sizeof(uint16_t) * 8) / HitSize;
0013 
0014   auto getHitFromOldHitPattern(const uint16_t hitPattern[], const int position) {
0015     const uint16_t bitEndOffset = (position + 1) * HitSize;
0016     const uint8_t secondWord = (bitEndOffset >> 4);
0017     const uint8_t secondWordBits = bitEndOffset & (16 - 1);  // that is, bitEndOffset % 32
0018     if (secondWordBits >= HitSize) {
0019       // full block is in this word
0020       const uint8_t lowBitsToTrash = secondWordBits - HitSize;
0021       return (hitPattern[secondWord] >> lowBitsToTrash) & ((1 << HitSize) - 1);
0022     }
0023     const uint8_t firstWordBits = HitSize - secondWordBits;
0024     const uint16_t firstWordBlock = hitPattern[secondWord - 1] >> (16 - firstWordBits);
0025     const uint16_t secondWordBlock = hitPattern[secondWord] & ((1 << secondWordBits) - 1);
0026     return firstWordBlock + (secondWordBlock << firstWordBits);
0027   }
0028 
0029   auto hitTypeFromOldHitPattern(const uint16_t pattern) {
0030     // for this version we just have to add a 0 bit to the top of the pattern
0031     constexpr unsigned short HitTypeMask = 0x3;
0032     constexpr unsigned short HitTypeOffset = 0;
0033 
0034     constexpr uint16_t VALID_CONST = (uint16_t)TrackingRecHit::valid;
0035     constexpr uint16_t MISSING_CONST = (uint16_t)TrackingRecHit::missing;
0036     constexpr uint16_t INACTIVE_CONST = (uint16_t)TrackingRecHit::inactive;
0037     constexpr uint16_t BAD_CONST = (uint16_t)TrackingRecHit::bad;
0038 
0039     const uint16_t rawHitType = (pattern >> HitTypeOffset) & HitTypeMask;
0040 
0041     TrackingRecHit::Type hitType = TrackingRecHit::valid;
0042     switch (rawHitType) {
0043       case VALID_CONST:
0044         hitType = TrackingRecHit::valid;
0045         break;
0046       case MISSING_CONST:
0047         hitType = TrackingRecHit::missing;
0048         break;
0049       case INACTIVE_CONST:
0050         hitType = TrackingRecHit::inactive;
0051         break;
0052       case BAD_CONST:
0053         hitType = TrackingRecHit::bad;
0054         break;
0055     }
0056     return hitType;
0057   };
0058 }  // namespace
0059 
0060 bool reco::HitPattern::fillNewHitPatternWithOldHitPattern_v12(const uint16_t oldHitPattern[],
0061                                                               uint8_t hitCount,
0062                                                               uint8_t beginTrackHits,
0063                                                               uint8_t endTrackHits,
0064                                                               uint8_t beginInner,
0065                                                               uint8_t endInner,
0066                                                               uint8_t beginOuter,
0067                                                               uint8_t endOuter,
0068                                                               HitPattern* newObj) {
0069   newObj->clear();
0070   bool ret = true;
0071   for (int i = 0; i < MaxHitsV12; i++) {
0072     uint16_t pattern = getHitFromOldHitPattern(oldHitPattern, i);
0073     if (pattern == 0) {
0074       break;
0075     }
0076     if (!newObj->appendHit(pattern, hitTypeFromOldHitPattern(pattern))) {
0077       ret = false;
0078       break;
0079     }
0080   }
0081   newObj->hitCount = hitCount;
0082   newObj->beginTrackHits = beginTrackHits;
0083   newObj->endTrackHits = endTrackHits;
0084   newObj->beginInner = beginInner;
0085   newObj->endInner = endInner;
0086   newObj->beginOuter = beginOuter;
0087   newObj->endOuter = endOuter;
0088   return ret;
0089 }