File indexing completed on 2024-05-10 02:21:19
0001
0002
0003
0004
0005
0006
0007 #include "SimG4CMS/Forward/interface/BscNumberingScheme.h"
0008 #include "SimG4CMS/Forward/interface/ForwardName.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010
0011 #include <CLHEP/Units/SystemOfUnits.h>
0012 #include "globals.hh"
0013
0014 namespace {
0015 int detectorLevel(const G4Step* aStep) {
0016
0017 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0018 return (touch) ? ((touch->GetHistoryDepth()) + 1) : 0;
0019 }
0020
0021 void detectorLevel(const G4Step* aStep, int level, std::vector<int>& copyno, std::vector<G4String>& name) {
0022
0023 if (level > 0) {
0024 copyno.reserve(level);
0025 name.reserve(level);
0026 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0027 for (int ii = 0; ii < level; ++ii) {
0028 int i = level - ii - 1;
0029 name.push_back(ForwardName::getName(touch->GetVolume(i)->GetName()));
0030 copyno.push_back(touch->GetReplicaNumber(i));
0031 }
0032 }
0033 }
0034 }
0035
0036 namespace BscNumberingScheme {
0037 unsigned int getUnitID(const G4Step* aStep) {
0038 unsigned int intindex = 0;
0039 int level = detectorLevel(aStep);
0040
0041 LogDebug("BscSim") << "BscNumberingScheme number of levels= " << level;
0042
0043 if (level > 0) {
0044 std::vector<int> copyno;
0045 std::vector<G4String> name;
0046 detectorLevel(aStep, level, copyno, name);
0047
0048 int det = 0;
0049 int zside = 0;
0050 int station = 0;
0051 for (int ich = 0; ich < level; ich++) {
0052
0053 if (name[ich] == "BSC1" || name[ich] == "BSC2") {
0054 zside = copyno[ich] - 1;
0055 } else if (name[ich] == "BSCTrap") {
0056 det = 0;
0057 station = 2 * (copyno[ich] - 1);
0058 } else if (name[ich] == "BSCTubs") {
0059 det = 1;
0060 station = copyno[ich] - 1;
0061 } else if (name[ich] == "BSCTTop") {
0062 ++station;
0063 } else if (name[ich] == "BSC2Pad") {
0064 det = 2;
0065 station = copyno[ich] - 1;
0066 }
0067
0068 LogDebug("BscSim") << "BscNumberingScheme "
0069 << "ich=" << ich << "copyno" << copyno[ich] << "name=" << name[ich];
0070 }
0071 intindex = packBscIndex(zside, det, station);
0072 LogDebug("BscSim") << "BscNumberingScheme : det " << det << " zside " << zside << " station " << station
0073 << " UnitID 0x" << std::hex << intindex << std::dec;
0074
0075 for (int ich = 0; ich < level; ich++)
0076 LogDebug("BscSim") << " name = " << name[ich] << " copy = " << copyno[ich];
0077
0078 LogDebug("BscSim") << " packed index = 0x" << std::hex << intindex << std::dec;
0079 }
0080
0081 return intindex;
0082 }
0083
0084 unsigned int packBscIndex(int zside, int det, int station) {
0085 unsigned int idx = 6 << 28;
0086 idx += (zside << 5) & 32;
0087 idx += (det << 3) & 24;
0088 idx += (station & 7);
0089 LogDebug("BscSim") << "Bsc packing: det " << det << " zside " << zside << " station " << station << "-> 0x"
0090 << std::hex << idx << std::dec;
0091
0092
0093 return idx;
0094 }
0095
0096 void unpackBscIndex(const unsigned int& idx) {
0097 int zside, det, station;
0098 zside = (idx & 32) >> 5;
0099 det = (idx & 24) >> 3;
0100 station = idx & 7;
0101 LogDebug("BscSim") << " Bsc unpacking: 0x " << std::hex << idx << std::dec << " -> det " << det << " zside "
0102 << zside << " station " << station;
0103 }
0104 }