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