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