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