CMS 3D CMS Logo

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