CMS 3D CMS Logo

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