Go to the documentation of this file.00001
00002
00003
00004
00005
00007 #include "SimG4CMS/FP420/interface/FP420NumberingScheme.h"
00008
00009 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00010 #include "globals.hh"
00011 #include <iostream>
00012
00013
00014
00015 FP420NumberingScheme::FP420NumberingScheme() {
00016
00017 }
00018
00019 FP420NumberingScheme::~FP420NumberingScheme() {
00020
00021 }
00022
00023
00024 int FP420NumberingScheme::detectorLevel(const G4Step* aStep) const {
00025
00026
00027 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00028 int level = 0;
00029 if (touch) level = ((touch->GetHistoryDepth())+1);
00030 return level;
00031 }
00032
00033 void FP420NumberingScheme::detectorLevel(const G4Step* aStep, int& level,
00034 int* copyno, G4String* name) const {
00035
00036
00037 if (level > 0) {
00038 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00039 for (int ii = 0; ii < level; ii++) {
00040 int i = level - ii - 1;
00041 name[ii] = touch->GetVolume(i)->GetName();
00042 copyno[ii] = touch->GetReplicaNumber(i);
00043 }
00044 }
00045 }
00046
00047
00048
00049
00050 unsigned int FP420NumberingScheme::getUnitID(const G4Step* aStep) const {
00051
00052 unsigned intindex=0;
00053 int level = detectorLevel(aStep);
00054
00055
00056
00057
00058 if (level > 0) {
00059 int* copyno = new int[level];
00060 G4String* name = new G4String[level];
00061 detectorLevel(aStep, level, copyno, name);
00062
00063
00064
00065 int det = 1;
00066 int stationgen = 0;
00067 int zside = 0;
00068 int station = 0;
00069 int plane = 0;
00070 for (int ich=0; ich < level; ich++) {
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 if(name[ich] == "FP420E") {
00087 det = copyno[ich];
00088 } else if(name[ich] == "HPS240E") {
00089 det = copyno[ich] + 2 ;
00090 } else if(name[ich] == "FP420Ex1" || name[ich] == "HPS240Ex1") {
00091 stationgen = 1;
00092
00093
00094 } else if(name[ich] == "FP420Ex3" || name[ich] == "HPS240Ex3") {
00095 stationgen = 2;
00096 } else if(name[ich] == "SISTATION" || name[ich] == "HPS240SISTATION") {
00097 station = stationgen;
00098 } else if(name[ich] == "SIPLANE" || name[ich] == "HPS240SIPLANE") {
00099 plane = copyno[ich];
00100
00101
00102
00103
00104
00105
00106
00107
00108 } else if(name[ich] == "SENSOR2" || name[ich] == "HPS240SENSOR2") {
00109
00110
00111 zside = 3 * copyno[ich];
00112 } else if(name[ich] == "SENSOR1" || name[ich] == "HPS240SENSOR1") {
00113
00114
00115 zside = copyno[ich];
00116 }
00117
00118
00119
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 intindex = packFP420Index (det, zside, station, plane);
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 delete[] copyno;
00144 delete[] name;
00145 }
00146
00147 return intindex;
00148
00149 }
00150
00151 unsigned FP420NumberingScheme::packFP420Index(int det, int zside, int station,int plane){
00152
00153 unsigned int idx = ((det-1)&3)<<19;
00154
00155 idx += (zside&7)<<7;
00156
00157 idx += (station&7)<<4;
00158 idx += (plane&15);
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 return idx;
00169 }
00170
00171
00172
00173 void FP420NumberingScheme::unpackFP420Index(const unsigned int& idx, int& det,
00174 int& zside, int& station,
00175 int& plane) {
00176 det = (idx>>19)&3;
00177
00178 det += 1;
00179 zside = (idx>>7)&7;
00180
00181 station = (idx>>4)&7;
00182 plane = idx&15;
00183
00184
00185
00186
00187
00188 }
00189
00190