File indexing completed on 2023-03-17 11:24:28
0001
0002
0003
0004
0005
0006
0007 #include "SimG4CMS/FP420/interface/FP420NumberingScheme.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009
0010 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0011 #include "globals.hh"
0012 #include "G4Step.hh"
0013 #include <iostream>
0014
0015
0016
0017 FP420NumberingScheme::FP420NumberingScheme() {
0018
0019 }
0020
0021 FP420NumberingScheme::~FP420NumberingScheme() {
0022 #ifdef EDM_ML_DEBUG
0023 edm::LogVerbatim("FP420") << " Deleting FP420NumberingScheme";
0024 #endif
0025 }
0026
0027 int FP420NumberingScheme::detectorLevel(const G4Step* aStep) const {
0028
0029 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0030 int level = 0;
0031 if (touch)
0032 level = ((touch->GetHistoryDepth()) + 1);
0033 return level;
0034 }
0035
0036 void FP420NumberingScheme::detectorLevel(const G4Step* aStep, int& level, int* copyno, G4String* name) const {
0037
0038 if (level > 0) {
0039 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0040 for (int ii = 0; ii < level; ii++) {
0041 int i = level - ii - 1;
0042 name[ii] = touch->GetVolume(i)->GetName();
0043 copyno[ii] = touch->GetReplicaNumber(i);
0044 }
0045 }
0046 }
0047
0048 unsigned int FP420NumberingScheme::getUnitID(const G4Step* aStep) const {
0049 unsigned intindex = 0;
0050 int level = detectorLevel(aStep);
0051
0052 #ifdef EDM_ML_DEBUG
0053 edm::LogVerbatim("FP420") << "FP420NumberingScheme number of levels= " << level;
0054 #endif
0055
0056 if (level > 0) {
0057 int* copyno = new int[level];
0058 G4String* name = new G4String[level];
0059 detectorLevel(aStep, level, copyno, name);
0060
0061
0062
0063 int det = 1;
0064 int stationgen = 0;
0065 int zside = 0;
0066 int station = 0;
0067 int plane = 0;
0068 for (int ich = 0; ich < level; ich++) {
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 if (name[ich] == "FP420E") {
0085 det = copyno[ich];
0086 } else if (name[ich] == "HPS240E") {
0087 det = copyno[ich] + 2;
0088 } else if (name[ich] == "FP420Ex1" || name[ich] == "HPS240Ex1") {
0089 stationgen = 1;
0090
0091
0092 } else if (name[ich] == "FP420Ex3" || name[ich] == "HPS240Ex3") {
0093 stationgen = 2;
0094 } else if (name[ich] == "SISTATION" || name[ich] == "HPS240SISTATION") {
0095 station = stationgen;
0096 } else if (name[ich] == "SIPLANE" || name[ich] == "HPS240SIPLANE") {
0097 plane = copyno[ich];
0098
0099
0100
0101
0102
0103
0104
0105
0106 } else if (name[ich] == "SENSOR2" || name[ich] == "HPS240SENSOR2") {
0107
0108
0109 zside = 3 * copyno[ich];
0110 } else if (name[ich] == "SENSOR1" || name[ich] == "HPS240SENSOR1") {
0111
0112
0113 zside = copyno[ich];
0114 }
0115
0116 #ifdef EDM_ML_DEBUG
0117 edm::LogVerbatim("FP420") << "FP420NumberingScheme "
0118 << "ich=" << ich << "copyno" << copyno[ich] << "name=" << name[ich];
0119 #endif
0120 }
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 intindex = packFP420Index(det, zside, station, plane);
0131
0132 #ifdef EDM_ML_DEBUG
0133 edm::LogVerbatim("FP420") << "FP420NumberingScheme det=" << det << " zside=" << zside << " station=" << station
0134 << " plane=" << plane;
0135 for (int ich = 0; ich < level; ich++) {
0136 edm::LogVerbatim("FP420") << " name = " << name[ich] << " copy = " << copyno[ich];
0137 edm::LogVerbatim("FP420") << " packed index = intindex" << intindex;
0138 }
0139 #endif
0140
0141 delete[] copyno;
0142 delete[] name;
0143 }
0144
0145 return intindex;
0146 }
0147
0148 unsigned FP420NumberingScheme::packFP420Index(int det, int zside, int station, int plane) {
0149
0150 unsigned int idx = ((det - 1) & 3) << 19;
0151
0152 idx += (zside & 7) << 7;
0153
0154 idx += (station & 7) << 4;
0155 idx += (plane & 15);
0156
0157
0158
0159 #ifdef EDM_ML_DEBUG
0160 edm::LogVerbatim("FP420") << "FP420 packing: det " << det << " zside " << zside << " station " << station
0161 << " plane " << plane << " idx " << idx;
0162 #endif
0163
0164
0165
0166
0167
0168 return idx;
0169 }
0170
0171 void FP420NumberingScheme::unpackFP420Index(const unsigned int& idx, int& det, int& zside, int& station, int& plane) {
0172 det = (idx >> 19) & 3;
0173
0174 det += 1;
0175 zside = (idx >> 7) & 7;
0176
0177 station = (idx >> 4) & 7;
0178 plane = idx & 15;
0179
0180
0181 #ifdef EDM_ML_DEBUG
0182 edm::LogVerbatim("FP420") << " FP420unpacking: idx=" << idx << " zside " << zside << " station " << station
0183 << " plane " << plane;
0184 #endif
0185
0186 }