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