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