CMS 3D CMS Logo

BHMNumberingScheme.cc
Go to the documentation of this file.
4 #include <CLHEP/Units/SystemOfUnits.h>
5 #include "globals.hh"
6 
7 namespace {
8  int detectorLevel(const G4Step* aStep) {
9  //Find number of levels
10  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
11  return (touch) ? ((touch->GetHistoryDepth()) + 1) : 0;
12  }
13 
14  std::vector<int> detectorLevelCopyNo(const G4Step* aStep, int level) {
15  //Get copy numbers
16  std::vector<int> copyno;
17  if (level > 0) {
18  copyno.reserve(level);
19  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
20  for (int ii = 0; ii < level; ++ii) {
21  int i = level - ii - 1;
22  copyno.push_back(touch->GetReplicaNumber(i));
23  }
24  }
25  return copyno;
26  }
27 } // namespace
28 
29 namespace BHMNumberingScheme {
30  unsigned int getUnitID(const G4Step* aStep) {
31  unsigned intindex = 0;
32  int level = detectorLevel(aStep);
33 
34  LogDebug("BHMSim") << "BHMNumberingScheme number of levels= " << level;
35  if (level > 0) {
36  auto copyno = detectorLevelCopyNo(aStep, level);
37 
38  if (level > 3) {
39  int subdet = copyno[0];
40  int zside = copyno[3];
41  int station = copyno[1];
42  intindex = packIndex(subdet, zside, station);
43  LogDebug("BHMSim") << "BHMNumberingScheme : subdet " << subdet << " zside " << zside << " station " << station;
44  }
45  }
46  LogDebug("BHMSim") << "BHMNumberingScheme : UnitID 0x" << std::hex << intindex << std::dec;
47 
48  return intindex;
49  }
50 
51  unsigned int packIndex(int subdet, int zside, int station) {
52  unsigned int idx = ((6 << 28) | (subdet & 0x7) << 25); // Use 6 as the detector name
53  idx |= ((zside & 0x3) << 5) | (station & 0x1F); // bits 0-4:station 5-6:side
54  LogDebug("BHMSim") << "BHM packing: subdet " << subdet << " zside " << zside << " station " << station << "-> 0x"
55  << std::hex << idx << std::dec;
56  return idx;
57  }
58 
59  void unpackIndex(const unsigned int& idx, int& subdet, int& zside, int& station) {
60  subdet = (idx >> 25) >> 0x7;
61  zside = (idx >> 5) & 0x3;
62  station = idx & 0x1F;
63  LogDebug("BHMSim") << " Bsc unpacking: 0x " << std::hex << idx << std::dec << " -> subdet " << subdet << " zside "
64  << zside << " station " << station;
65  }
66 
67 } // namespace BHMNumberingScheme
int zside(DetId const &)
unsigned int packIndex(int subdet, int zside, int station)
unsigned int getUnitID(const G4Step *aStep)
ii
Definition: cuy.py:589
void unpackIndex(const unsigned int &idx, int &subdet, int &zside, int &station)
#define LogDebug(id)