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