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] == "FP420Ex1") {
00089 stationgen = 1;
00090
00091
00092 } else if(name[ich] == "FP420Ex3") {
00093 stationgen = 2;
00094 } else if(name[ich] == "SISTATION") {
00095 station = stationgen;
00096 } else if(name[ich] == "SIPLANE") {
00097 plane = copyno[ich];
00098
00099
00100
00101
00102
00103
00104
00105
00106 } else if(name[ich] == "SENSOR2") {
00107
00108
00109 zside = 3 * copyno[ich];
00110 } else if(name[ich] == "SENSOR1") {
00111
00112
00113 zside = copyno[ich];
00114 }
00115
00116
00117
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127 intindex = packFP420Index (det, zside, station, plane);
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 delete[] copyno;
00141 delete[] name;
00142 }
00143
00144 return intindex;
00145
00146 }
00147
00148 unsigned FP420NumberingScheme::packFP420Index(int det, int zside, int station,int plane){
00149 unsigned int idx = ((det-1)&1)<<20;
00150 idx += (zside&7)<<7;
00151
00152 idx += (station&7)<<4;
00153 idx += (plane&15);
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 return idx;
00164 }
00165
00166
00167
00168 void FP420NumberingScheme::unpackFP420Index(const unsigned int& idx, int& det,
00169 int& zside, int& station,
00170 int& plane) {
00171 det = (idx>>20)&1;
00172 det += 1;
00173 zside = (idx>>7)&7;
00174
00175 station = (idx>>4)&7;
00176 plane = idx&15;
00177
00178
00179
00180
00181
00182 }
00183
00184