CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorNumberingScheme.cc
Go to the documentation of this file.
1 // File: CastorNumberingScheme.cc
3 // Description: Numbering scheme for Castor
8 
9 #include "CLHEP/Units/GlobalSystemOfUnits.h"
10 #include "G4LogicalVolumeStore.hh"
11 #include <iostream>
12 
13 //#define castornumschemedebug
14 
15 CastorNumberingScheme::CastorNumberingScheme(): lvCASTFar(0),lvCASTNear(0),
16  lvCAST(0),lvCAES(0),lvCEDS(0),
17  lvCAHS(0),lvCHDS(0),lvCAER(0),
18  lvCEDR(0),lvCAHR(0),lvCHDR(0),
19  lvC3EF(0),lvC3HF(0),lvC4EF(0),
20  lvC4HF(0) {
21  edm::LogInfo("ForwardSim") << "Creating CastorNumberingScheme";
22  const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
23  std::vector<lvp>::const_iterator lvcite;
24  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
25  if (strcmp(((*lvcite)->GetName()).c_str(),"CASTFar") == 0) lvCASTFar = (*lvcite);
26  if (strcmp(((*lvcite)->GetName()).c_str(),"CASTNear") == 0) lvCASTNear = (*lvcite);
27  if (strcmp(((*lvcite)->GetName()).c_str(),"CAST") == 0) lvCAST = (*lvcite);
28  if (strcmp(((*lvcite)->GetName()).c_str(),"CAES") == 0) lvCAES = (*lvcite);
29  if (strcmp(((*lvcite)->GetName()).c_str(),"CEDS") == 0) lvCEDS = (*lvcite);
30  if (strcmp(((*lvcite)->GetName()).c_str(),"CAHS") == 0) lvCAHS = (*lvcite);
31  if (strcmp(((*lvcite)->GetName()).c_str(),"CHDS") == 0) lvCHDS = (*lvcite);
32  if (strcmp(((*lvcite)->GetName()).c_str(),"CAER") == 0) lvCAER = (*lvcite);
33  if (strcmp(((*lvcite)->GetName()).c_str(),"CEDR") == 0) lvCEDR = (*lvcite);
34  if (strcmp(((*lvcite)->GetName()).c_str(),"CAHR") == 0) lvCAHR = (*lvcite);
35  if (strcmp(((*lvcite)->GetName()).c_str(),"CHDR") == 0) lvCHDR = (*lvcite);
36  if (strcmp(((*lvcite)->GetName()).c_str(),"C3EF") == 0) lvC3EF = (*lvcite);
37  if (strcmp(((*lvcite)->GetName()).c_str(),"C3HF") == 0) lvC3HF = (*lvcite);
38  if (strcmp(((*lvcite)->GetName()).c_str(),"C4EF") == 0) lvC4EF = (*lvcite);
39  if (strcmp(((*lvcite)->GetName()).c_str(),"C4HF") == 0) lvC4HF = (*lvcite);
40  }
41 #ifdef castornumschemedebug
42  LogDebug("ForwardSim") << "CastorNumberingScheme:: LogicalVolume pointers\n"
43  << lvCASTFar << " for CASTFar; " << lvCASTNear << " for CASTNear; "
44  << lvCAST << " for CAST; " << lvCAES << " for CAES; "
45  << lvCEDS << " for CEDS; " << lvCAHS << " for CAHS; "
46  << lvCHDS << " for CHDS; " << lvCAER << " for CAER; "
47  << lvCEDR << " for CEDR; " << lvCAHR << " for CAHR; "
48  << lvCHDR << " for CHDR; " << lvC3EF << " for C3EF; "
49  << lvC3HF << " for C3HF; " << lvC4EF << " for C4EF; "
50  << lvC4HF << " for C4HF.";
51 
52  LogDebug("ForwardSim") << "Call to init CastorNumberingScheme\n";
53  for (int mod=0; mod<15; mod++)
54  for (int sec=0; sec<17; sec++)
55  {
56  HcalCastorDetId castorId = HcalCastorDetId(false, sec, mod);
57  LogDebug("ForwardSim") << "Mod: " << mod << " Sec: " << sec << " Id: " << castorId.rawId() << "\n";
58  }
59 
60 #endif
61 
62 }
63 
65  edm::LogInfo("ForwardSim") << "Deleting CastorNumberingScheme";
66 }
67 
68 uint32_t CastorNumberingScheme::getUnitID(const G4Step* aStep) const {
69 
70  uint32_t index=0;
71  int level, copyno[20];
72  lvp lvs[20];
73  detectorLevel(aStep, level, copyno, lvs);
74 
75 #ifdef castornumschemedebug
76  LogDebug("ForwardSim") << "CastorNumberingScheme number of levels= " <<level;
77 #endif
78 
79  if (level > 0) {
80 
81  int zside = 0;
82  int sector = 0;
83  int module = 0;
84 
85  bool farSide = false;
86  int castorGeoVersion = 0; //0 = original // 1 = separated-halves geometry
87 
88  // HcalCastorDetId::Section section;
89  for (int ich=0; ich < level; ich++) {
90  if(lvs[ich] == lvCAST) {
91  // Z index +Z = 1 ; -Z = 2
92  assert (1 <= copyno[ich] && copyno[ich] <= 3);
93  zside = copyno[ich] == 1 ? 1 : 2;
94  } // copyno 2 = Far : 3 = Near
95  else if(lvs[ich] == lvCASTFar || lvs[ich] == lvCASTNear) {
96  castorGeoVersion = 1; //detected separated-halves geometry
97  if(lvs[ich] == lvCASTFar)
98  farSide = true;
99  }
100  else if(lvs[ich] == lvCAES || lvs[ich] == lvCEDS ||
101  lvs[ich] == lvCAHS || lvs[ich] == lvCHDS) {
102  // sector number for dead material 1 - 8
103  int copyn = copyno[ich];
104  if(castorGeoVersion == 1) {
105  //for separated-half geometry the copy numbers do not start at "3 o'clock" and go from 1-8.
106  //instead they start at "12 o'clock" for near side 1-4. and "6 o'clock" for far side 1-4 again
107  if(farSide) {
108  if (copyn<3)
109  copyn += 6; //maps 1->7, 2->8
110  else
111  copyn -= 2; //maps 3->1 and 4->2
112  }
113  else { //nearSide
114  copyn += 2; //maps 1->3, ...
115  }
116  } //endif separated-half geometry
117  if (copyn<5)
118  sector = 5-copyn;
119  else
120  sector = 13-copyn;
121  }
122  else if(lvs[ich] == lvCAER || lvs[ich] == lvCEDR) {
123  // zmodule number 1-2 for EM section (2 copies)
124  module = copyno[ich];
125  }
126  else if(lvs[ich] == lvCAHR || lvs[ich] == lvCHDR) {
127  //zmodule number 3-14 for HAD section (12 copies)
128  module = copyno[ich] + 2;
129  }
130  else if(lvs[ich] == lvC3EF || lvs[ich] == lvC3HF) {
131  // sector number for sensitive material 1 - 16
132  sector = sector*2;
133  }
134  else if(lvs[ich] == lvC4EF || lvs[ich] == lvC4HF) {
135  // sector number for sensitive material 1 - 16
136  sector = sector*2 - 1;
137  }
138 
139 #ifdef castornumschemedebug
140  LogDebug("ForwardSim") << "CastorNumberingScheme " << "ich = " << ich
141  << "copyno = " << copyno[ich] << "name = "
142  << lvs[ich]->GetName();
143 #endif
144  } //end for loop over levels
145 
146  // use for Castor number det = 9
147  //
148  // Z index +Z = 1 ; -Z = 2
149  // sector number 1 - 16
150  // zmodule number 1 - 18
151 
152  bool true_for_positive_eta = false;
153  if(zside == 1) true_for_positive_eta = true;
154 
155  HcalCastorDetId castorId = HcalCastorDetId(true_for_positive_eta, sector, module);
156  index = castorId.rawId();
157 
158 #ifdef castornumschemedebug
159  uint32_t intindex = 0;
160  intindex = packIndex(zside, sector, module);
161  LogDebug("ForwardSim") << "CastorNumberingScheme: " << " zside "
162  << zside << " module " << module << " sector "
163  << sector << " UnitID 0x" << std::hex << intindex
164  << std::dec << " index: " << index;
165 #endif
166  }
167  return index;
168 
169 }
170 
171 //uint32_t CastorNumberingScheme::packIndex(int section, int z, int sector, int module ) {
172 
173 uint32_t CastorNumberingScheme::packIndex(int z, int sector, int module) {
174  /*
175  uint32_t idx=(section&31)<<28; //bits 28-31 (21-27 are free for now)
176  idx+=((z-1)&1)<<20; //bits 20 (1...2)
177  idx+=(sector&15)<<6; //bits 6-9 (1...16)
178  idx+=(module&63); //bits 0-5 (1...18)
179  return idx;
180  */
181 
182  uint32_t idx=((z-1)&1)<<8; //bit 8
183  idx+=(sector&15)<<4; //bits 4-7 (1...16)
184  idx+=(module&15); //bits 0-3 (1...14)
185  return idx;
186 
187 }
188 
189 //void CastorNumberingScheme::unpackIndex(const uint32_t& idx, int& section, int& z, int& sector, int& module) {
190 
191 void CastorNumberingScheme::unpackIndex(const uint32_t& idx, int& z, int& sector, int& module) {
192  /*
193  section = (idx>>28)&31;
194  z = (idx>>20)&1;
195  z += 1;
196  sector = (idx>>6)&15;
197  module= (idx&63);
198  */
199  z = (idx>>8)&1;
200  z += 1;
201  sector = (idx>>4)&15;
202  module = (idx&15);
203 }
204 
205 void CastorNumberingScheme::detectorLevel(const G4Step* aStep, int& level,
206  int* copyno, lvp* lvs) const {
207 
208  //Get name and copy numbers
209  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
210  level = 0;
211  if (touch) level = ((touch->GetHistoryDepth())+1);
212  if (level > 0) {
213  for (int ii = 0; ii < level; ii++) {
214  int i = level - ii - 1;
215  lvs[ii] = touch->GetVolume(i)->GetLogicalVolume();
216  copyno[ii] = touch->GetReplicaNumber(i);
217  }
218  }
219 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
int zside(DetId const &)
int ii
Definition: cuy.py:588
static void unpackIndex(const uint32_t &idx, int &z, int &sector, int &zmodule)
float float float z
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void detectorLevel(const G4Step *, int &, int *, lvp *) const
virtual uint32_t getUnitID(const G4Step *aStep) const
tuple level
Definition: testEve_cfg.py:34
static uint32_t packIndex(int z, int sector, int zmodule)
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
Definition: vlib.h:208