CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:
9 #include "CLHEP/Units/GlobalSystemOfUnits.h"
10 #include <iostream>
11 #undef debug
12 
14  verbosity = iv;
15  if (verbosity>0)
16  std::cout << "Creating ZDCNumberingScheme" << std::endl;
17 }
18 
20  if (verbosity>0)
21  std::cout<< " Deleting ZdcNumberingScheme" << std::endl;
22 }
23 
24 
25 void ZdcNumberingScheme::setVerbosity(const int iv){ verbosity = iv; }
26 
27 unsigned int ZdcNumberingScheme::getUnitID(const G4Step* aStep) const {
28 
29  unsigned intindex=0;
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)zside = 1;
48  if(copyno[ich] == 2)zside = -1;
49  }
50  else if (name[ich] == "ZDC_EMLayer") {
51  section = HcalZDCDetId::EM;
52  layer = copyno[ich];
53  }
54  else if (name[ich] == "ZDC_EMFiber") {
55  fiber = copyno[ich];
56  if (fiber < 20)
57  channel = 1;
58  else if (fiber < 39)
59  channel = 2;
60  else if (fiber < 58)
61  channel = 3;
62  else if (fiber < 77)
63  channel = 4;
64  else
65  channel = 5;
66  }
67  else if (name[ich] == "ZDC_LumLayer") {
68  section = HcalZDCDetId::LUM;
69  layer = copyno[ich];
70  channel = layer;
71  }
72  else if (name[ich] == "ZDC_LumGas") {
73  fiber = 1;
74  }
75  else if (name[ich] == "ZDC_HadLayer") {
76  section = HcalZDCDetId::HAD;
77  layer = copyno[ich];
78  if (layer < 6)
79  channel = 1;
80  else if (layer < 12)
81  channel = 2;
82  else if (layer < 18)
83  channel = 3;
84  else
85  channel = 4;
86  }
87  else if (name[ich] == "ZDC_HadFiber") {
88  fiber = copyno[ich];
89  }
90  }
91 
92  // intindex = myPacker.packZdcIndex (section, layer, fiber, channel, zside);
93  intindex = packZdcIndex (section, layer, fiber, channel, zside);
94  bool true_for_positive_eta = true;
95  //if(zside == 1)true_for_positive_eta = true;
96  if(zside == -1)true_for_positive_eta = false;
97 
98  HcalZDCDetId zdcId(section, true_for_positive_eta, channel);
99  index = zdcId.rawId();
100 
101 #ifdef debug
102  std::cout<<"DetectorId: ";
103  std::cout<<zdcId<<std::endl;
104 
105 
106  std::cout<< "ZdcNumberingScheme:"
107  << " getUnitID - # of levels = "
108  << level << std::endl;
109  for (int ich = 0; ich < level; ich++)
110  std::cout<< " " << ich << ": copyno " << copyno[ich]
111  << " name=" << name[ich]
112  << " section " << section << " zside " << zside
113  << " layer " << layer << " fiber " << fiber
114  << " channel " << channel << "packedIndex ="
115  << intindex << " detId raw: "<<index<<std::endl;
116 
117 #endif
118 
119  delete[] copyno;
120  delete[] name;
121  }
122 
123  return index;
124 
125 }
126 
127 unsigned ZdcNumberingScheme::packZdcIndex(int section, int layer, int fiber,
128  int channel, int z){
129  unsigned int idx = ((z-1)&1)<<20; //bit 20
130  idx += (channel&7)<<17; //bits 17-19
131  idx += (fiber&255)<<9; //bits 9-16
132  idx += (layer&127)<<2; //bits 2-8
133  idx += (section&3); //bits 0-1
134 
135  #ifdef debug
136  std::cout<< "ZDC packing: section " << section << " layer " << layer << " fiber "
137  << fiber << " channel " << channel << " zside " << z << "idx: " <<idx << std::endl;
138  int newsubdet, newlayer, newfiber, newchannel, newz;
139  unpackZdcIndex(idx, newsubdet, newlayer, newfiber, newchannel, newz);
140  #endif
141 
142  return idx;
143 }
144 
145 
146 void ZdcNumberingScheme::unpackZdcIndex(const unsigned int& idx, int& section,
147  int& layer, int& fiber,
148  int& channel, int& z) {
149  z = 1 + ((idx>>20)&1);
150  channel = (idx>>17)&7;
151  fiber = (idx>>9)&255;
152  layer = (idx>>2)&127;
153  section = idx&3;
154 
155  #ifdef debug
156  std::cout<< "ZDC unpacking: idx:"<< idx << " -> section " << section
157  << " layer " << layer << " fiber " << fiber << " channel "
158  << channel << " zside " << z << std::endl;
159  #endif
160 }
161 
162 int ZdcNumberingScheme::detectorLevel(const G4Step* aStep) const {
163 
164  //Find number of levels
165  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
166  int level = 0;
167  if (touch) level = ((touch->GetHistoryDepth())+1);
168  return level;
169 }
170 
171 void ZdcNumberingScheme::detectorLevel(const G4Step* aStep, int& level,
172  int* copyno, G4String* name) const {
173 
174  //Get name and copy numbers
175  if (level > 0) {
176  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
177  for (int ii = 0; ii < level; ii++) {
178  int i = level - ii - 1;
179  name[ii] = touch->GetVolume(i)->GetName();
180  copyno[ii] = touch->GetReplicaNumber(i);
181  }
182  }
183 }
static unsigned int packZdcIndex(int subDet, int layer, int fiber, int channel, int z)
int i
Definition: DBlmapReader.cc:9
virtual unsigned int getUnitID(const G4Step *aStep) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
Definition: DDAxes.h:10
void setVerbosity(const int)
static void unpackZdcIndex(const unsigned int &idx, int &subDet, int &layer, int &fiber, int &channel, int &z)
tuple cout
Definition: gather_cfg.py:41
tuple level
Definition: testEve_cfg.py:34
int detectorLevel(const G4Step *) const