CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 BscNumberingScheme::BscNumberingScheme() { LogDebug("BscSim") << " Creating BscNumberingScheme"; }
15 
16 int BscNumberingScheme::detectorLevel(const G4Step* aStep) const {
17  //Find number of levels
18  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
19  return (touch) ? ((touch->GetHistoryDepth()) + 1) : 0;
20 }
21 
22 void BscNumberingScheme::detectorLevel(const G4Step* aStep, int& level, int* copyno, G4String* name) const {
23  //Get name and copy numbers
24  if (level > 0) {
25  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
26  for (int ii = 0; ii < level; ++ii) {
27  int i = level - ii - 1;
28  name[ii] = ForwardName::getName(touch->GetVolume(i)->GetName());
29  copyno[ii] = touch->GetReplicaNumber(i);
30  }
31  }
32 }
33 
34 unsigned int BscNumberingScheme::getUnitID(const G4Step* aStep) const {
35  unsigned int intindex = 0;
36  int level = detectorLevel(aStep);
37 
38  LogDebug("BscSim") << "BscNumberingScheme number of levels= " << level;
39 
40  if (level > 0) {
41  int* copyno = new int[level];
42  G4String* name = new G4String[level];
43  detectorLevel(aStep, level, copyno, name);
44 
45  int det = 0;
46  int zside = 0;
47  int station = 0;
48  for (int ich = 0; ich < level; ich++) {
49  // new and old set up configurations are possible:
50  if (name[ich] == "BSC1" || name[ich] == "BSC2") {
51  zside = copyno[ich] - 1;
52  } else if (name[ich] == "BSCTrap") {
53  det = 0;
54  station = 2 * (copyno[ich] - 1);
55  } else if (name[ich] == "BSCTubs") {
56  det = 1;
57  station = copyno[ich] - 1;
58  } else if (name[ich] == "BSCTTop") {
59  ++station;
60  } else if (name[ich] == "BSC2Pad") {
61  det = 2;
62  station = copyno[ich] - 1;
63  }
64 
65  LogDebug("BscSim") << "BscNumberingScheme "
66  << "ich=" << ich << "copyno" << copyno[ich] << "name=" << name[ich];
67  }
68  intindex = packBscIndex(zside, det, station);
69  LogDebug("BscSim") << "BscNumberingScheme : det " << det << " zside " << zside << " station " << station
70  << " UnitID 0x" << std::hex << intindex << std::dec;
71 
72  for (int ich = 0; ich < level; ich++)
73  LogDebug("BscSim") << " name = " << name[ich] << " copy = " << copyno[ich];
74 
75  LogDebug("BscSim") << " packed index = 0x" << std::hex << intindex << std::dec;
76 
77  delete[] copyno;
78  delete[] name;
79  }
80 
81  return intindex;
82 }
83 
84 unsigned int BscNumberingScheme::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 BscNumberingScheme::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 " << zside
102  << " station " << station;
103 }
int zside(DetId const &)
int ii
Definition: cuy.py:589
unsigned int getUnitID(const G4Step *aStep) const
static unsigned int packBscIndex(int det, int zside, int station)
static void unpackBscIndex(const unsigned int &idx)
int detectorLevel(const G4Step *) const
std::string getName(const G4String &)
Definition: ForwardName.cc:3
tuple level
Definition: testEve_cfg.py:47
#define LogDebug(id)