CMS 3D CMS Logo

BscNumberingScheme.cc
Go to the documentation of this file.
1 // File: BscNumberingScheme.cc
3 // Date: 02.2006
4 // Description: Numbering scheme for Bsc
5 // Modifications:
10 //
11 #include "CLHEP/Units/GlobalSystemOfUnits.h"
12 #include "globals.hh"
13 
14 namespace {
15  int detectorLevel(const G4Step* aStep) {
16  //Find number of levels
17  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
18  return (touch) ? ((touch->GetHistoryDepth()) + 1) : 0;
19  }
20 
21  void detectorLevel(const G4Step* aStep, int level, std::vector<int>& copyno, std::vector<G4String>& name) {
22  //Get name and copy numbers
23  if (level > 0) {
24  copyno.reserve(level);
25  name.reserve(level);
26  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
27  for (int ii = 0; ii < level; ++ii) {
28  int i = level - ii - 1;
29  name.push_back(ForwardName::getName(touch->GetVolume(i)->GetName()));
30  copyno.push_back(touch->GetReplicaNumber(i));
31  }
32  }
33  }
34 } // namespace
35 
36 namespace BscNumberingScheme {
37  unsigned int getUnitID(const G4Step* aStep) {
38  unsigned int intindex = 0;
39  int level = detectorLevel(aStep);
40 
41  LogDebug("BscSim") << "BscNumberingScheme number of levels= " << level;
42 
43  if (level > 0) {
44  std::vector<int> copyno;
45  std::vector<G4String> name;
46  detectorLevel(aStep, level, copyno, name);
47 
48  int det = 0;
49  int zside = 0;
50  int station = 0;
51  for (int ich = 0; ich < level; ich++) {
52  // new and old set up configurations are possible:
53  if (name[ich] == "BSC1" || name[ich] == "BSC2") {
54  zside = copyno[ich] - 1;
55  } else if (name[ich] == "BSCTrap") {
56  det = 0;
57  station = 2 * (copyno[ich] - 1);
58  } else if (name[ich] == "BSCTubs") {
59  det = 1;
60  station = copyno[ich] - 1;
61  } else if (name[ich] == "BSCTTop") {
62  ++station;
63  } else if (name[ich] == "BSC2Pad") {
64  det = 2;
65  station = copyno[ich] - 1;
66  }
67 
68  LogDebug("BscSim") << "BscNumberingScheme "
69  << "ich=" << ich << "copyno" << copyno[ich] << "name=" << name[ich];
70  }
71  intindex = packBscIndex(zside, det, station);
72  LogDebug("BscSim") << "BscNumberingScheme : det " << det << " zside " << zside << " station " << station
73  << " UnitID 0x" << std::hex << intindex << std::dec;
74 
75  for (int ich = 0; ich < level; ich++)
76  LogDebug("BscSim") << " name = " << name[ich] << " copy = " << copyno[ich];
77 
78  LogDebug("BscSim") << " packed index = 0x" << std::hex << intindex << std::dec;
79  }
80 
81  return intindex;
82  }
83 
84  unsigned int packBscIndex(int zside, int det, int station) {
85  unsigned int idx = 6 << 28; // autre numero que les detecteurs existants
86  idx += (zside << 5) & 32; // vaut 0 ou 1 bit 5
87  idx += (det << 3) & 24; //bit 3-4 det:0-1-2 2 bits:0-1
88  idx += (station & 7); //bits 0-2 station:0-7=8-->2**3 =8 3 bits:0-2
89  LogDebug("BscSim") << "Bsc packing: det " << det << " zside " << zside << " station " << station << "-> 0x"
90  << std::hex << idx << std::dec;
91 
92  // unpackBscIndex(idx);
93  return idx;
94  }
95 
96  void unpackBscIndex(const unsigned int& idx) {
97  int zside, det, station;
98  zside = (idx & 32) >> 5;
99  det = (idx & 24) >> 3;
100  station = idx & 7;
101  LogDebug("BscSim") << " Bsc unpacking: 0x " << std::hex << idx << std::dec << " -> det " << det << " zside "
102  << zside << " station " << station;
103  }
104 } // namespace BscNumberingScheme
int zside(DetId const &)
void unpackBscIndex(const unsigned int &idx)
ii
Definition: cuy.py:589
std::string getName(const G4String &)
Definition: ForwardName.cc:3
unsigned int packBscIndex(int det, int zside, int station)
unsigned int getUnitID(const G4Step *aStep)
#define LogDebug(id)