CMS 3D CMS Logo

TotemT1Organization.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Forward
4 // Class : TotemT1Organization
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: R. Capra
10 // Created: Tue May 16 10:14:34 CEST 2006
11 //
12 
13 // system include files
14 
15 // user include files
20 
21 #include "G4VPhysicalVolume.hh"
22 #include "G4VTouchable.hh"
23 #include "globals.hh"
24 
25 //
26 // constructors and destructor
27 //
29  : _needUpdateUnitID(false),
30  _needUpdateData(false),
31  _currentUnitID(-1),
32  _currentPlane(-1),
33  _currentCSC(-1),
34  _currentLayer(-1),
35  _currentObjectType(Undefined) {
36  edm::LogVerbatim("ForwardSim") << "Creating TotemT1Organization";
37 }
38 
40 
41 //
42 // member functions
43 //
44 
45 uint32_t TotemT1Organization ::getUnitID(const G4Step* aStep) const {
46  return const_cast<TotemT1Organization*>(this)->getUnitID(aStep);
47 }
48 
49 uint32_t TotemT1Organization ::getUnitID(const G4Step* aStep) {
50  int currLAOT;
51  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
52  G4VPhysicalVolume* physVol;
53  int ii = 0;
54  for (ii = 0; ii < touch->GetHistoryDepth(); ii++) {
55  physVol = touch->GetVolume(ii);
56 
57 #ifdef SCRIVI
58  LogDebug("ForwardSim") << "physVol=" << physVol->GetName() << ", level=" << ii
59  << ", physVol->GetCopyNo()=" << physVol->GetCopyNo();
60 #endif
61 
62  std::string dName = ForwardName::getName(physVol->GetName());
63  if (dName == "TotemT1") {
64  if (physVol->GetCopyNo() == 1)
66  else if (physVol->GetCopyNo() == 2)
68  }
69  }
70 
71  touch = aStep->GetPreStepPoint()->GetTouchable();
72  physVol = touch->GetVolume(0);
73 
74  currLAOT = physVol->GetCopyNo();
75  _currentObjectType = static_cast<ObjectType>(currLAOT % MaxObjectTypes);
76  _currentLayer = currLAOT / MaxObjectTypes;
77  _currentPlane = -1;
78  _currentCSC = -1;
79 
80  if (touch->GetVolume(1)) {
81  _currentCSC = touch->GetVolume(1)->GetCopyNo();
82  if (touch->GetVolume(2))
83  _currentPlane = touch->GetVolume(2)->GetCopyNo();
84  }
85 #ifdef SCRIVI
86  LogDebug("ForwardSim") << "CURRENT CSC " << _currentCSC << "\n"
87  << "CURRENT PLANE " << _currentPlane;
88 #endif
89  _needUpdateUnitID = true;
90  return getCurrentUnitID();
91 }
92 
95 #ifdef SCRIVI
96  LogDebug("ForwardSim") << "getCurrentUnitID()=" << _currentUnitID;
97  << endl;
98 #endif
99  return _currentUnitID;
100 }
101 
102 void TotemT1Organization ::setCurrentUnitID(int currentUnitID) {
103 #ifdef SCRIVI
104  LogDebug("ForwardSim") << "_currentUnitID=" << currentUnitID;
105 #endif
106  _currentUnitID = currentUnitID;
107  _needUpdateData = true;
108 }
109 
112 #ifdef SCRIVI
113  LogDebug("ForwardSim") << "getCurrentDetectorPosition()=" << _currentDetectorPosition;
114 #endif
116 }
117 
118 void TotemT1Organization ::setCurrentDetectorPosition(int currentDetectorPosition) {
119 #ifdef SCRIVI
120  LogDebug("ForwardSim") << "_currentDetectorPosition=" << currentDetectorPosition;
121 #endif
122  _currentDetectorPosition = currentDetectorPosition;
123  _needUpdateUnitID = true;
124 }
125 
128 
129 #ifdef SCRIVI
130  LogDebug("ForwardSim") << "getCurrentPlane()=" << _currentPlane;
131 #endif
132  return _currentPlane;
133 }
134 
136 #ifdef SCRIVI
137  LogDebug("ForwardSim") << "_currentPlane=" << currentPlane;
138 #endif
139  _currentPlane = currentPlane;
140  _needUpdateUnitID = true;
141 }
142 
145 #ifdef SCRIVI
146  LogDebug("ForwardSim") << "getCurrentCSC()=" << _currentCSC;
147 #endif
148  return _currentCSC;
149 }
150 
152 #ifdef SCRIVI
153  LogDebug("ForwardSim") << "_currentCSC=" << currentCSC;
154 #endif
155  _currentCSC = currentCSC;
156  _needUpdateUnitID = true;
157 }
158 
161 #ifdef SCRIVI
162  LogDebug("ForwardSim") << "getCurrentLayer()=" << _currentLayer;
163 #endif
164  return _currentLayer;
165 }
166 
168 #ifdef SCRIVI
169  LogDebug("ForwardSim") << "_currentLayer=" << currentLayer;
170 #endif
171  _currentLayer = currentLayer;
172  _needUpdateUnitID = true;
173 }
174 
177 #ifdef SCRIVI
178  LogDebug("ForwardSim") << "getCurrentObjectType()=" << _currentObjectType;
179 #endif
180  return _currentObjectType;
181 }
182 
184 #ifdef SCRIVI
185  LogDebug("ForwardSim") << "_currentObjectType=" << currentObjectType;
186 #endif
187  _currentObjectType = currentObjectType;
188  _needUpdateUnitID = true;
189 }
190 
192  int result(static_cast<int>(objectType));
193  if (result < 0 || result >= MaxObjectTypes) {
194  result = 0;
195  edm::LogVerbatim("ForwardSim") << "Invalid ObjectType value (" << objectType << "). Now is \"Undefined\"";
196  }
197  return result;
198 }
199 
201  return fromObjectTypeToInt(objectType) + layer * MaxObjectTypes;
202 }
203 
204 //
205 // private member functions
206 //
207 
209  if (_needUpdateUnitID) {
210 #ifdef SCRIVI
211  LogDebug("ForwardSim") << "UnitID update needed.";
212 #endif
213  const_cast<TotemT1Organization*>(this)->_FromDataToUnitID();
214  } else {
215 #ifdef SCRIVI
216  LogDebug("ForwardSim") << "UnitID update not needed.";
217 #endif
218  }
219 }
220 
222  if (_needUpdateData) {
223 #ifdef SCRIVI
224  LogDebug("ForwardSim") << "Data update needed.";
225 #endif
226  const_cast<TotemT1Organization*>(this)->_FromUnitIDToData();
227  } else {
228 #ifdef SCRIVI
229  LogDebug("ForwardSim") << "Data update not needed.";
230 #endif
231  }
232 }
233 
235  int currDP, currCSC, currOT, currPLA;
236  unsigned long currPL, currLA;
237 
238  // currDP: 0..4 (5)
239  // currPL: 0..infty
240  // currCSC: 0..6 (7)
241  // currLA: 0..infty
242  // currOT: 0..MaxObjectTypes-1 (MaxObjectTypes)
243 
244  currDP = (_currentUnitID / 100000) % 5; // 3;
245  currCSC = (_currentUnitID / 5) % 7;
246  currOT = (_currentUnitID / (5 * 7)) % MaxObjectTypes;
247  currPLA = _currentUnitID / (5 * 7 * MaxObjectTypes);
248 
250  splitter.Split(currPLA, currPL, currLA);
251 
252 #ifdef SCRIVI
253  LogDebug("ForwardSim") << "currDP=" << currDP << ", currPL=" << currPL << ", currCSC=" << currCSC
254  << ", currLA=" << currLA << ", currOT=" << currOT << ", currPLA=" << currPLA
255  << ", _currentUnitID=" << _currentUnitID;
256 #endif
257  _currentPlane = currPL - 1;
258  _currentCSC = currCSC - 1;
259  _currentLayer = currLA - 1;
260  _currentObjectType = static_cast<ObjectType>(currOT);
261 
262  switch (currDP) {
263  case 0:
265  break;
266  case 1:
268  break;
269  case 2:
271  break;
272  case 3:
274  break;
275  case 4:
277  break;
278  }
279  _needUpdateData = false;
280 }
281 
283  int currDP, currPL, currCSC, currLA, currOT;
284 #ifdef SCRIVI
285  LogDebug("ForwardSim") << " CURRENT DETECTOR POSITION (0-3) " << _currentDetectorPosition;
286 #endif
287  switch (_currentDetectorPosition) {
288  case 0:
289  currDP = 0;
290  break;
291  case 1:
292  currDP = 1;
293  break;
294  case 2:
295  currDP = 2;
296  break;
297  case 3:
298  currDP = 3;
299  break;
300  case 4:
301  currDP = 4;
302  break;
303  default:
305  currDP = 0;
306  edm::LogVerbatim("ForwardSim") << "Invalid _currentDetectorPosition value (" << _currentDetectorPosition
307  << "). Now is \"Undefined\"";
308  }
309 
310  if (_currentPlane < -1) {
311  edm::LogVerbatim("ForwardSim") << "Invalid _currentPlane value (" << _currentPlane << "). Now is -1";
312  _currentPlane = -1;
313  }
314  currPL = _currentPlane + 1;
315 
316  if (_currentCSC < -1 || _currentCSC > 5) {
317  edm::LogVerbatim("ForwardSim") << "Invalid _currentCSC value (" << _currentCSC << "). Now is -1";
318  _currentCSC = -1;
319  }
320  currCSC = _currentCSC + 1;
321 
322  if (_currentLayer < -1) {
323  edm::LogVerbatim("ForwardSim") << "Invalid _currentLayer value (" << _currentLayer << "). Now is -1";
324  _currentLayer = -1;
325  }
326  currLA = _currentLayer + 1;
327 
329 
330  // currDP: 0..2 (3)
331  // currPL: 0..infty
332  // currCSC: 0..6 (7)
333  // currLA: 0..infty
334  // currOT: 0..MaxObjectTypes-1 (MaxObjectTypes)
335 
336  TotemNumberMerger merger;
337  int currPLA(merger.Merge(currPL, currLA));
338 
339  _currentUnitID = currDP * 100000 + 5 * (currCSC + 7 * (currOT + MaxObjectTypes * (currPLA)));
340 #ifdef SCRIVI
341  LogDebug("ForwardSim") << "currDP=" << currDP << ", currPL=" << currPL << ", currCSC=" << currCSC
342  << ", currLA=" << currLA << ", currOT=" << currOT << ", currPLA=" << currPLA
343  << ", _currentUnitID=" << _currentUnitID;
344 #endif
345 
346  _needUpdateUnitID = false;
347 }
Log< level::Info, true > LogVerbatim
void setCurrentObjectType(ObjectType currentObjectType)
def splitter(iterator, n)
Definition: confdb.py:11
void _checkDataUpdate(void) const
int getCurrentPlane(void) const
void setCurrentDetectorPosition(int currentDetectorPosition)
void setCurrentLayer(int currentLayer)
void setCurrentUnitID(int currentUnitID)
ObjectType getCurrentObjectType(void) const
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
int getCurrentUnitID(void) const
int getCurrentCSC(void) const
void setCurrentPlane(int currentPlane)
ii
Definition: cuy.py:589
unsigned long Merge(unsigned long value1, unsigned long value2) const
void setCurrentCSC(int currentCSC)
int getCurrentDetectorPosition(void) const
std::string getName(const G4String &)
Definition: ForwardName.cc:3
int fromObjectTypeToInt(ObjectType objectType)
uint32_t getUnitID(const G4Step *aStep) const override
void _checkUnitIDUpdate(void) const
int getCurrentLayer(void) const
#define LogDebug(id)