00001
00002
00003
00005 #include "SimG4CMS/Forward/interface/CastorNumberingScheme.h"
00006 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008
00009 #include "CLHEP/Units/SystemOfUnits.h"
00010 #include <iostream>
00011
00012 #define debug
00013
00014 CastorNumberingScheme::CastorNumberingScheme() {
00015 edm::LogInfo("ForwardSim") << "Creating CastorNumberingScheme";
00016 }
00017
00018 CastorNumberingScheme::~CastorNumberingScheme() {
00019 edm::LogInfo("ForwardSim") << "Deleting CastorNumberingScheme";
00020 }
00021
00022 uint32_t CastorNumberingScheme::getUnitID(const G4Step* aStep) const {
00023
00024 uint32_t intindex = 0;
00025
00026 uint32_t index=0;
00027 int level = detectorLevel(aStep);
00028
00029 #ifdef debug
00030 LogDebug("ForwardSim") << "CastorNumberingScheme number of levels= " <<level;
00031 #endif
00032
00033 if (level > 0) {
00034 int* copyno = new int[level];
00035 G4String* name = new G4String[level];
00036
00037 detectorLevel(aStep, level, copyno, name);
00038
00039 int zside = 0;
00040 int sector = 0;
00041 int module = 0;
00042
00043
00044
00045 for (int ich=0; ich < level; ich++) {
00046 if(name[ich] == "CAST") {
00047
00048 zside = copyno[ich];
00049 } else if(name[ich] == "CAES" || name[ich] == "CEDS") {
00050
00051
00052 sector = copyno[ich];
00053 } else if(name[ich] == "CAHS" || name[ich] == "CHDS") {
00054
00055
00056 sector = copyno[ich];
00057 } else if(name[ich] == "CAER" || name[ich] == "CEDR") {
00058
00059 module = copyno[ich];
00060 } else if(name[ich] == "CAHR" || name[ich] == "CHDR") {
00061
00062 module = copyno[ich] + 2;
00063 } else if(name[ich] == "C3EF" || name[ich] == "C3HF") {
00064
00065 sector = sector*2 - 1 ;
00066 } else if(name[ich] == "C4EF" || name[ich] == "C4HF") {
00067
00068 sector = sector*2 ;
00069 }
00070
00071
00072 #ifdef debug
00073 LogDebug("ForwardSim") << "CastorNumberingScheme " << "ich = " << ich
00074 << "copyno" << copyno[ich] << "name = "
00075 << name[ich];
00076 #endif
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 intindex = packIndex(zside, sector, module);
00091
00092 bool true_for_positive_eta;
00093 if(zside = 1)true_for_positive_eta = true;
00094 if(zside = -1)true_for_positive_eta = false;
00095
00096 HcalCastorDetId castorId = HcalCastorDetId(true_for_positive_eta, sector, module);
00097 index = castorId.rawId();
00098
00099 #ifdef debug
00100 LogDebug("ForwardSim") << "CastorNumberingScheme :" <<" zside "
00101 << zside << " sector " << sector << " module "
00102 << module << " UnitID 0x" << std::hex << intindex
00103 << std::dec;
00104 #endif
00105
00106 delete[] copyno;
00107 delete[] name;
00108 }
00109 return index;
00110
00111 }
00112
00113
00114
00115 uint32_t CastorNumberingScheme::packIndex(int z, int sector, int module) {
00116
00117
00118
00119
00120
00121
00122
00123
00124 uint32_t idx=((z-1)&1)<<8;
00125 idx+=(sector&15)<<4;
00126 idx+=(module&15);
00127 return idx;
00128
00129 }
00130
00131
00132
00133 void CastorNumberingScheme::unpackIndex(const uint32_t& idx, int& z, int& sector, int& module) {
00134
00135
00136
00137
00138
00139
00140
00141 z = (idx>>8)&1;
00142 z += 1;
00143 sector = (idx>>4)&15;
00144 module= (idx&15);
00145 }
00146
00147 int CastorNumberingScheme::detectorLevel(const G4Step* aStep) const {
00148
00149
00150 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00151 int level = 0;
00152 if (touch) level = ((touch->GetHistoryDepth())+1);
00153 return level;
00154 }
00155
00156 void CastorNumberingScheme::detectorLevel(const G4Step* aStep, int& level,
00157 int* copyno, G4String* name) const {
00158
00159
00160 if (level > 0) {
00161 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00162 for (int ii = 0; ii < level; ii++) {
00163 int i = level - ii - 1;
00164 name[ii] = touch->GetVolume(i)->GetName();
00165 copyno[ii] = touch->GetReplicaNumber(i);
00166 }
00167 }
00168 }