CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: TotemT1Organization.cc,v 1.1 2006/05/17 16:18:58 sunanda Exp $
12 //
13 
14 // system include files
15 
16 // user include files
20 
21 #include "G4VPhysicalVolume.hh"
22 #include "G4VTouchable.hh"
23 
24 //
25 // constructors and destructor
26 //
28  _needUpdateData(false),
29  _currentUnitID(-1),
30  _currentPlane(-1),
31  _currentCSC(-1),
32  _currentLayer(-1),
33  _currentObjectType(Undefined) {
34 
35  edm::LogInfo("ForwardSim") << "Creating TotemT1Organization";
36 }
37 
39 }
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 
50 uint32_t TotemT1Organization :: GetUnitID(const G4Step* aStep) {
51 
52  int currLAOT;
53  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
54  G4VPhysicalVolume* physVol;
55  int ii =0;
56  for ( ii = 0; ii < touch->GetHistoryDepth(); ii++ ){
57  physVol = touch->GetVolume(ii);
58 
59 #ifdef SCRIVI
60  LogDebug("ForwardSim") << "physVol=" << physVol->GetName()
61  << ", level=" << ii << ", physVol->GetCopyNo()="
62  << physVol->GetCopyNo();
63 #endif
64 
65  if(physVol->GetName() == "TotemT1" &&
66  physVol->GetCopyNo()==1) _currentDetectorPosition = 1;
67  if(physVol->GetName() == "TotemT1" &&
68  physVol->GetCopyNo()==2) _currentDetectorPosition = 2;
69  }
70 
71  touch = aStep->GetPreStepPoint()->GetTouchable();
72  physVol=touch->GetVolume(0);
73 
74  currLAOT=physVol->GetCopyNo();
75  _currentObjectType=static_cast<ObjectType>(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)) _currentPlane=touch->GetVolume(2)->GetCopyNo();
83  }
84 #ifdef SCRIVI
85  LogDebug("ForwardSim") << "CURRENT CSC "<<_currentCSC << "\n"
86  << "CURRENT PLANE "<<_currentPlane;
87 #endif
88  _needUpdateUnitID=true;
89  return GetCurrentUnitID();
90 }
91 
93 
95 #ifdef SCRIVI
96  LogDebug("ForwardSim") << "GetCurrentUnitID()=" << _currentUnitID;
97  << endl;
98 #endif
99  return _currentUnitID;
100 }
101 
103 
104 #ifdef SCRIVI
105  LogDebug("ForwardSim") << "_currentUnitID=" << currentUnitID;
106 #endif
107  _currentUnitID=currentUnitID;
108  _needUpdateData=true;
109 }
110 
112 
114 #ifdef SCRIVI
115  LogDebug("ForwardSim") << "GetCurrentDetectorPosition()="
117 #endif
119 }
120 
121 void TotemT1Organization :: SetCurrentDetectorPosition(int currentDetectorPosition) {
122 
123 #ifdef SCRIVI
124  LogDebug("ForwardSim") << "_currentDetectorPosition=" << currentDetectorPosition;
125 #endif
126  _currentDetectorPosition=currentDetectorPosition;
127  _needUpdateUnitID=true;
128 }
129 
131 
133 
134 #ifdef SCRIVI
135  LogDebug("ForwardSim") << "GetCurrentPlane()=" << _currentPlane;
136 #endif
137  return _currentPlane;
138 }
139 
141 
142 #ifdef SCRIVI
143  LogDebug("ForwardSim") << "_currentPlane=" << currentPlane;
144 #endif
145  _currentPlane=currentPlane;
146  _needUpdateUnitID=true;
147 }
148 
150 
152 #ifdef SCRIVI
153  LogDebug("ForwardSim") << "GetCurrentCSC()=" << _currentCSC;
154 #endif
155  return _currentCSC;
156 }
157 
159 
160 #ifdef SCRIVI
161  LogDebug("ForwardSim") << "_currentCSC=" << currentCSC;
162 #endif
163  _currentCSC=currentCSC;
164  _needUpdateUnitID=true;
165 }
166 
168 
170 #ifdef SCRIVI
171  LogDebug("ForwardSim") << "GetCurrentLayer()=" << _currentLayer;
172 #endif
173  return _currentLayer;
174 }
175 
177 
178 #ifdef SCRIVI
179  LogDebug("ForwardSim") << "_currentLayer=" << currentLayer;
180 #endif
181  _currentLayer=currentLayer;
182  _needUpdateUnitID=true;
183 }
184 
186 
188 #ifdef SCRIVI
189  LogDebug("ForwardSim") << "GetCurrentObjectType()=" << _currentObjectType;
190 #endif
191  return _currentObjectType;
192 }
193 
195 
196 #ifdef SCRIVI
197  LogDebug("ForwardSim") << "_currentObjectType=" << currentObjectType;
198 #endif
199  _currentObjectType=currentObjectType;
200  _needUpdateUnitID=true;
201 }
202 
204 
205  int result(static_cast<int>(objectType));
206  if (result<0 || result>=MaxObjectTypes) {
207  result = 0;
208  edm::LogInfo("ForwardSim") << "Invalid ObjectType value (" << objectType
209  << "). Now is \"Undefined\"";
210  }
211  return result;
212 }
213 
215  return FromObjectTypeToInt(objectType)+layer*MaxObjectTypes;
216 }
217 
218 
219 //
220 // private member functions
221 //
222 
224  if (_needUpdateUnitID) {
225 #ifdef SCRIVI
226  LogDebug("ForwardSim") << "UnitID update needed.";
227 #endif
228  const_cast<TotemT1Organization *>(this)->_FromDataToUnitID();
229  } else {
230 #ifdef SCRIVI
231  LogDebug("ForwardSim") << "UnitID update not needed.";
232 #endif
233  }
234 }
235 
237 
238  if (_needUpdateData) {
239 #ifdef SCRIVI
240  LogDebug("ForwardSim") << "Data update needed.";
241 #endif
242  const_cast<TotemT1Organization *>(this)->_FromUnitIDToData();
243  } else {
244 #ifdef SCRIVI
245  LogDebug("ForwardSim") << "Data update not needed.";
246 #endif
247  }
248 }
249 
251 
252  int currDP, currCSC, currOT, currPLA;
253  unsigned long currPL, currLA;
254 
255  // currDP: 0..4 (5)
256  // currPL: 0..infty
257  // currCSC: 0..6 (7)
258  // currLA: 0..infty
259  // currOT: 0..MaxObjectTypes-1 (MaxObjectTypes)
260 
261  currDP = (_currentUnitID/100000) % 5;// 3;
262  currCSC = (_currentUnitID/5)%7;
263  currOT = (_currentUnitID/(5*7))%MaxObjectTypes;
264  currPLA = _currentUnitID/(5*7*MaxObjectTypes);
265 
267  splitter.Split(currPLA,currPL,currLA);
268 
269 #ifdef SCRIVI
270  LogDebug("ForwardSim") << "currDP=" << currDP << ", currPL=" << currPL
271  << ", currCSC=" << currCSC << ", currLA=" << currLA
272  << ", currOT=" << currOT << ", currPLA=" << currPLA
273  << ", _currentUnitID=" << _currentUnitID;
274 #endif
275  _currentPlane=currPL-1;
276  _currentCSC=currCSC-1;
277  _currentLayer=currLA-1;
278  _currentObjectType=static_cast<ObjectType>(currOT);
279 
280  switch(currDP) {
281  case 0:
283  break;
284  case 1:
286  break;
287  case 2:
289  break;
290  case 3:
292  break;
293  case 4:
295  break;
296  }
297  _needUpdateData=false;
298 }
299 
301  int currDP, currPL, currCSC, currLA, currOT;
302 #ifdef SCRIVI
303  LogDebug("ForwardSim") << " CURRENT DETECTOR POSITION (0-3) "
305 #endif
306  switch(_currentDetectorPosition) {
307  case 0:
308  currDP=0;
309  break;
310  case 1:
311  currDP=1;
312  break;
313  case 2:
314  currDP=2;
315  break;
316  case 3:
317  currDP=3;
318  break;
319  case 4:
320  currDP=4;
321  break;
322  default:
324  currDP=0;
325  edm::LogInfo("ForwardSim") << "Invalid _currentDetectorPosition value ("
327  << "). Now is \"Undefined\"";
328  }
329 
330  if (_currentPlane<-1) {
331  edm::LogInfo("ForwardSim") << "Invalid _currentPlane value ("
332  << _currentPlane << "). Now is -1";
333  _currentPlane=-1;
334  }
335  currPL=_currentPlane+1;
336 
337  if (_currentCSC<-1 || _currentCSC>5) {
338  edm::LogInfo("ForwardSim") << "Invalid _currentCSC value (" << _currentCSC
339  << "). Now is -1";
340  _currentCSC=-1;
341  }
342  currCSC=_currentCSC+1;
343 
344  if (_currentLayer<-1) {
345  edm::LogInfo("ForwardSim") << "Invalid _currentLayer value ("
346  << _currentLayer << "). Now is -1";
347  _currentLayer=-1;
348  }
349  currLA=_currentLayer+1;
350 
352 
353  // currDP: 0..2 (3)
354  // currPL: 0..infty
355  // currCSC: 0..6 (7)
356  // currLA: 0..infty
357  // currOT: 0..MaxObjectTypes-1 (MaxObjectTypes)
358 
359  TotemNumberMerger merger;
360  int currPLA(merger.Merge(currPL,currLA));
361 
362  _currentUnitID=currDP*100000+5*(currCSC+7*(currOT+MaxObjectTypes*(currPLA)));
363 #ifdef SCRIVI
364  LogDebug("ForwardSim") << "currDP=" << currDP << ", currPL=" << currPL
365  << ", currCSC=" << currCSC << ", currLA=" << currLA
366  << ", currOT=" << currOT << ", currPLA=" << currPLA
367  << ", _currentUnitID=" << _currentUnitID;
368 #endif
369 
370  _needUpdateUnitID=false;
371 }
#define LogDebug(id)
void SetCurrentUnitID(int currentUnitID)
void _checkDataUpdate(void) const
int GetCurrentDetectorPosition(void) const
ObjectType GetCurrentObjectType(void) const
int GetCurrentCSC(void) const
void SetCurrentCSC(int currentCSC)
void SetCurrentLayer(int currentLayer)
unsigned long Merge(unsigned long value1, unsigned long value2) const
int ii
Definition: cuy.py:588
void Split(unsigned long source, unsigned long &value1, unsigned long &value2) const
uint32_t GetUnitID(const G4Step *aStep)
def splitter
Definition: confdb.py:11
int GetCurrentUnitID(void) const
void _checkUnitIDUpdate(void) const
void SetCurrentDetectorPosition(int currentDetectorPosition)
tuple result
Definition: query.py:137
void SetCurrentObjectType(ObjectType currentObjectType)
int GetCurrentLayer(void) const
void SetCurrentPlane(int currentPlane)
int GetCurrentPlane(void) const
int FromObjectTypeToInt(ObjectType objectType)