CMS 3D CMS Logo

ZdcNumberingScheme.cc
Go to the documentation of this file.
1 // File: ZdcNumberingScheme.cc
3 // Date: 02.04
4 // Description: Numbering scheme for Zdc
5 // Modifications:
10 #include <CLHEP/Units/SystemOfUnits.h>
11 #include <iostream>
12 
13 //#define EDM_ML_DEBUG
14 
16  verbosity = iv;
17  if (verbosity > 0)
18  edm::LogVerbatim("ForwardSim") << "Creating ZDCNumberingScheme";
19 }
20 
22 
23 unsigned int ZdcNumberingScheme::getUnitID(const G4Step* aStep) {
24  uint32_t index = 0;
25  int level = detectorLevel(aStep);
26 
27  if (level > 0) {
28  std::vector<int> copyno;
29  std::vector<G4String> name;
30 
31  detectorLevel(aStep, level, copyno, name);
32 
33  int zside = 0;
34  int channel = 0;
35  int fiber = 0;
36  int layer = 0;
38 
39  for (int ich = 0; ich < level; ich++) {
40  if (name[ich] == "ZDC") {
41  if (copyno[ich] == 1)
42  zside = 1;
43  if (copyno[ich] == 2)
44  zside = -1;
45  } else if (name[ich] == "ZDC_EMLayer") {
47 #ifdef EDM_ML_DEBUG
48  layer = copyno[ich];
49 #endif
50  } else if (name[ich] == "ZDC_EMFiber") {
51  fiber = copyno[ich];
52  if (fiber < 20)
53  channel = 1;
54  else if (fiber < 39)
55  channel = 2;
56  else if (fiber < 58)
57  channel = 3;
58  else if (fiber < 77)
59  channel = 4;
60  else
61  channel = 5;
62  } else if (name[ich] == "ZDC_LumLayer") {
64  layer = copyno[ich];
65  channel = layer;
66  } else if (name[ich] == "ZDC_HadLayer") {
68  layer = copyno[ich];
69  if (layer < 6)
70  channel = 1;
71  else if (layer < 12)
72  channel = 2;
73  else if (layer < 18)
74  channel = 3;
75  else
76  channel = 4;
77  }
78 #ifdef EDM_ML_DEBUG
79  else if (name[ich] == "ZDC_LumGas") {
80  fiber = 1;
81  } else if (name[ich] == "ZDC_HadFiber") {
82  fiber = copyno[ich];
83  }
84 #endif
85  }
86 
87 #ifdef EDM_ML_DEBUG
88  unsigned intindex = 0;
89  intindex = packZdcIndex(section, layer, fiber, channel, zside);
90 #endif
91 
92  bool true_for_positive_eta = (zside != -1);
93 
94  HcalZDCDetId zdcId(section, true_for_positive_eta, channel);
95  index = zdcId.rawId();
96 #ifdef EDM_ML_DEBUG
97  edm::LogVerbatim("ForwardSim") << "DetectorId:\n" << zdcId;
98 
99  edm::LogVerbatim("ForwardSim") << "ZdcNumberingScheme:"
100  << " getUnitID - # of levels = " << level;
101  for (int ich = 0; ich < level; ich++)
102  edm::LogVerbatim("ForwardSim") << " " << ich << ": copyno " << copyno[ich] << " name=" << name[ich]
103  << " section " << section << " zside " << zside << " layer " << layer << " fiber "
104  << fiber << " channel " << channel << "packedIndex =" << intindex
105  << " detId raw: " << index;
106 
107 #endif
108  }
109 
110  return index;
111 }
112 
113 unsigned ZdcNumberingScheme::packZdcIndex(int section, int layer, int fiber, int channel, int z) {
114  unsigned int idx = ((z - 1) & 1) << 20; //bit 20
115  idx += (channel & 7) << 17; //bits 17-19
116  idx += (fiber & 255) << 9; //bits 9-16
117  idx += (layer & 127) << 2; //bits 2-8
118  idx += (section & 3); //bits 0-1
119 
120 #ifdef EDM_ML_DEBUG
121  edm::LogVerbatim("ForwardSim") << "ZDC packing: section " << section << " layer " << layer << " fiber " << fiber
122  << " channel " << channel << " zside " << z << "idx: " << idx;
123  int newsubdet, newlayer, newfiber, newchannel, newz;
124  unpackZdcIndex(idx, newsubdet, newlayer, newfiber, newchannel, newz);
125 #endif
126 
127  return idx;
128 }
129 
131  const unsigned int& idx, int& section, int& layer, int& fiber, int& channel, int& z) {
132  z = 1 + ((idx >> 20) & 1);
133  channel = (idx >> 17) & 7;
134  fiber = (idx >> 9) & 255;
135  layer = (idx >> 2) & 127;
136  section = idx & 3;
137 
138 #ifdef EDM_ML_DEBUG
139  edm::LogVerbatim("ForwardSim") << "ZDC unpacking: idx:" << idx << " -> section " << section << " layer " << layer
140  << " fiber " << fiber << " channel " << channel << " zside " << z;
141 #endif
142 }
143 
144 int ZdcNumberingScheme::detectorLevel(const G4Step* aStep) {
145  //Find number of levels
146  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
147  int level = 0;
148  if (touch)
149  level = ((touch->GetHistoryDepth()) + 1);
150  return level;
151 }
152 
153 void ZdcNumberingScheme::detectorLevel(const G4Step* aStep,
154  int& level,
155  std::vector<int>& copyno,
156  std::vector<G4String>& name) {
157  //Get name and copy numbers
158  if (level > 0) {
159  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
160  for (int ii = 0; ii < level; ii++) {
161  int i = level - ii - 1;
162  name.emplace_back(touch->GetVolume(i)->GetName());
163  copyno.emplace_back(touch->GetReplicaNumber(i));
164  }
165  }
166 }
static unsigned int packZdcIndex(int subDet, int layer, int fiber, int channel, int z)
Log< level::Info, true > LogVerbatim
int zside(DetId const &)
int detectorLevel(const G4Step *)
float float float z
unsigned int getUnitID(const G4Step *aStep)
void setVerbosity(const int)
ii
Definition: cuy.py:589
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static void unpackZdcIndex(const unsigned int &idx, int &subDet, int &layer, int &fiber, int &channel, int &z)