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