File indexing completed on 2024-05-10 02:21:19
0001 #include "SimG4CMS/Forward/interface/BHMNumberingScheme.h"
0002 #include "SimG4CMS/Forward/interface/ForwardName.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include <CLHEP/Units/SystemOfUnits.h>
0005 #include "globals.hh"
0006
0007 namespace {
0008 int detectorLevel(const G4Step* aStep) {
0009
0010 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0011 return (touch) ? ((touch->GetHistoryDepth()) + 1) : 0;
0012 }
0013
0014 std::vector<int> detectorLevelCopyNo(const G4Step* aStep, int level) {
0015
0016 std::vector<int> copyno;
0017 if (level > 0) {
0018 copyno.reserve(level);
0019 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0020 for (int ii = 0; ii < level; ++ii) {
0021 int i = level - ii - 1;
0022 copyno.push_back(touch->GetReplicaNumber(i));
0023 }
0024 }
0025 return copyno;
0026 }
0027 }
0028
0029 namespace BHMNumberingScheme {
0030 unsigned int getUnitID(const G4Step* aStep) {
0031 unsigned intindex = 0;
0032 int level = detectorLevel(aStep);
0033
0034 LogDebug("BHMSim") << "BHMNumberingScheme number of levels= " << level;
0035 if (level > 0) {
0036 auto copyno = detectorLevelCopyNo(aStep, level);
0037
0038 if (level > 3) {
0039 int subdet = copyno[0];
0040 int zside = copyno[3];
0041 int station = copyno[1];
0042 intindex = packIndex(subdet, zside, station);
0043 LogDebug("BHMSim") << "BHMNumberingScheme : subdet " << subdet << " zside " << zside << " station " << station;
0044 }
0045 }
0046 LogDebug("BHMSim") << "BHMNumberingScheme : UnitID 0x" << std::hex << intindex << std::dec;
0047
0048 return intindex;
0049 }
0050
0051 unsigned int packIndex(int subdet, int zside, int station) {
0052 unsigned int idx = ((6 << 28) | (subdet & 0x7) << 25);
0053 idx |= ((zside & 0x3) << 5) | (station & 0x1F);
0054 LogDebug("BHMSim") << "BHM packing: subdet " << subdet << " zside " << zside << " station " << station << "-> 0x"
0055 << std::hex << idx << std::dec;
0056 return idx;
0057 }
0058
0059 void unpackIndex(const unsigned int& idx, int& subdet, int& zside, int& station) {
0060 subdet = (idx >> 25) >> 0x7;
0061 zside = (idx >> 5) & 0x3;
0062 station = idx & 0x1F;
0063 LogDebug("BHMSim") << " Bsc unpacking: 0x " << std::hex << idx << std::dec << " -> subdet " << subdet << " zside "
0064 << zside << " station " << station;
0065 }
0066
0067 }