CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FP420NumberingScheme.cc
Go to the documentation of this file.
1 // File: FP420NumberingScheme.cc
3 // Date: 02.2006
4 // Description: Numbering scheme for FP420
5 // Modifications: 08.2008 mside and fside added
8 //
9 #include "CLHEP/Units/GlobalSystemOfUnits.h"
10 #include "globals.hh"
11 #include <iostream>
12 
13 //UserVerbosity FP420NumberingScheme::cout("FP420NumberingScheme","silent","FP420NumberingScheme");
14 
16 // sn0=3, pn0=6, rn0=7;
17 }
18 
20  // std::cout << " Deleting FP420NumberingScheme" << std::endl;
21 }
22 
23 
24 int FP420NumberingScheme::detectorLevel(const G4Step* aStep) const {
25 
26  //Find number of levels
27  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
28  int level = 0;
29  if (touch) level = ((touch->GetHistoryDepth())+1);
30  return level;
31 }
32 
33 void FP420NumberingScheme::detectorLevel(const G4Step* aStep, int& level,
34  int* copyno, G4String* name) const {
35 
36  //Get name and copy numbers
37  if (level > 0) {
38  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
39  for (int ii = 0; ii < level; ii++) {
40  int i = level - ii - 1;
41  name[ii] = touch->GetVolume(i)->GetName();
42  copyno[ii] = touch->GetReplicaNumber(i);
43  }
44  }
45 }
46 
47 
48 
49 
50 unsigned int FP420NumberingScheme::getUnitID(const G4Step* aStep) const {
51 
52  unsigned intindex=0;
53  int level = detectorLevel(aStep);
54 
55  // std::cout << "FP420NumberingScheme number of levels= " << level << std::endl;
56 
57  // unsigned int intIndex = 0;
58  if (level > 0) {
59  int* copyno = new int[level];
60  G4String* name = new G4String[level];
61  detectorLevel(aStep, level, copyno, name);
62 
63  // int det = static_cast<int>(FP420);;
64 
65  int det = 1;
66  int stationgen = 0;
67  int zside = 0;
68  int station = 0;
69  int plane = 0;
70  for (int ich=0; ich < level; ich++) {
71  /*
72  // old set up configuration with equidistant stations
73  if(name[ich] == "FP420Ex") {
74  stationgen = copyno[ich];
75  } else if(name[ich] == "SISTATION") {
76  station = stationgen;
77  } else if(name[ich] == "SIPLANE") {
78  plane = copyno[ich];
79  } else if(name[ich] == "SIDETL") {
80  zside = 1;
81  } else if(name[ich] == "SIDETR") {
82  zside = 2;
83  }
84 */
85  // new and old set up configurations are possible:
86  if(name[ich] == "FP420E") {
87  det = copyno[ich];
88  } else if(name[ich] == "FP420Ex1") {
89  stationgen = 1;
90  // } else if(name[ich] == "FP420Ex2") {
91  // stationgen = 2;
92  } else if(name[ich] == "FP420Ex3") {
93  stationgen = 2;// was =3
94  } else if(name[ich] == "SISTATION") {
95  station = stationgen;
96  } else if(name[ich] == "SIPLANE") {
97  plane = copyno[ich];
98  // SIDETL (or R) can be ether X or Y type in next schemes of readout
99  // !!! (=...) zside
100  //
101  // 1 2 <---copyno
102  // Front(=2) Empty(=4) Back(=6) <--SIDETR OR SENSOR2
103  // 1 2 <---copyno
104  // Front(=1) Back(=3) Empty(=5) <--SIDETL OR SENSOR1
105  //
106  } else if(name[ich] == "SENSOR2") {
107  // } else if(name[ich] == "SIDETR") {
108  // zside = 4 * copyno[ich] - 2 ;//= 2 6 (copyno=1,2)
109  zside = 3 * copyno[ich];//= 3 6 (copyno=1,2)
110  } else if(name[ich] == "SENSOR1") {
111  // } else if(name[ich] == "SIDETL") {
112  // zside = 2 * copyno[ich] - 1 ;//= 1 3 (copyno=1,2)
113  zside = copyno[ich];//= 1 2 (copyno=1,2)
114  }
115  //
116  // std::cout << "FP420NumberingScheme " << "ich=" << ich << "copyno" << copyno[ich] << "name=" << name[ich] << std::endl;
117  //
118  }
119  // det = 1 for +FP420 , = 2 for -FP420 / (det-1) = 0,1
120  // 0 is as default for every below:
121  // Z index
122  // station number 1 - 5 (in reality just 2 ones)
123  // superplane(superlayer) number 1 - 10 (in reality just 5 ones)
124 
125  // intindex = myPacker.packEcalIndex (det, zside, station, plane);
126  // intindex = myPacker.packCastorIndex (det, zside, station, plane);
127  intindex = packFP420Index (det, zside, station, plane);
128  /*
129  //
130  std::cout << "FP420NumberingScheme det=" << det << " zside=" << zside << " station=" <<station << " plane=" << plane << std::endl;
131 
132  for (int ich = 0; ich < level; ich++) {
133  std::cout <<" name = " << name[ich] <<" copy = " << copyno[ich] << std::endl;
134  std::cout << " packed index = intindex" << intindex << std::endl;
135  }
136  //
137  */
138 
139 
140  delete[] copyno;
141  delete[] name;
142  }
143 
144  return intindex;
145 
146 }
147 
148 unsigned FP420NumberingScheme::packFP420Index(int det, int zside, int station,int plane){
149  unsigned int idx = ((det-1)&1)<<20; //bit 20 (det-1): 0 ,1= 2-->2**1=2 -> 2-1 -> ((det-1)&1) 1 bit: 0
150  idx += (zside&7)<<7; //bits 7-9 zside: 0- 7= 8-->2**3 =8 -> 8-1 -> (zside&7) 3 bits:0-2
151  // idx += (zside&3)<<7; //bits 7-8 zside: 0- 2= 3-->2**2 =4 -> 4-1 -> (zside&3) 2 bits:0-1
152  idx += (station&7)<<4; //bits 4-6 station:0- 7= 8-->2**3 =8 -> 8-1 ->(station&7) 3 bits:0-2
153  idx += (plane&15); //bits 0-3 plane: 0-15=16-->2**4 =16 -> 16-1 ->(plane&15) 4 bits:0-3
154 
155  //
156 
157  // std::cout << "FP420 packing: det " << det << " zside " << zside << " station " << station << " plane " << plane << " idx " << idx << std::endl;
158  // int newdet, newzside, newstation,newplane;
159  // unpackFP420Index(idx, newdet, newzside, newstation,newplane);
160 
161  //
162 
163  return idx;
164 }
165 
166 
167 
168 void FP420NumberingScheme::unpackFP420Index(const unsigned int& idx, int& det,
169  int& zside, int& station,
170  int& plane) {
171  det = (idx>>20)&1;
172  det += 1;
173  zside = (idx>>7)&7;
174  // zside = (idx>>7)&3;
175  station = (idx>>4)&7;
176  plane = idx&15;
177  //
178 
179  // std::cout << " FP420unpacking: idx=" << idx << " zside " << zside << " station " << station << " plane " << plane << std::endl;
180 
181  //
182 }
183 
184 
int i
Definition: DBlmapReader.cc:9
virtual int detectorLevel(const G4Step *) const
static void unpackFP420Index(const unsigned int &idx, int &det, int &zside, int &station, int &superplane)
virtual unsigned int getUnitID(const G4Step *aStep) const
static unsigned int packFP420Index(int det, int zside, int station, int superplane)
tuple level
Definition: testEve_cfg.py:34