00001 #include "Geometry/ForwardGeometry/interface/ZdcTopology.h"
00002 #include <cmath>
00003 #include <iostream>
00004
00005
00006 static const int ICH_EM_MAX = 5;
00007 static const int ICH_HAD_MAX = 4;
00008 static const int ICH_LUM_MAX = 2;
00009
00010 ZdcTopology::ZdcTopology() :
00011 excludeEM_(false),
00012 excludeHAD_(false),
00013 excludeLUM_(false),
00014 excludeZP_(false),
00015 excludeZN_(false),
00016 firstEMModule_(1),
00017 lastEMModule_(5),
00018 firstHADModule_(1),
00019 lastHADModule_(4),
00020 firstLUMModule_(1),
00021 lastLUMModule_(2)
00022 {
00023 }
00024
00025 bool ZdcTopology::valid(const HcalZDCDetId& id) const {
00026
00027 bool ok=validRaw(id);
00028 ok=ok && !isExcluded(id);
00029 return ok;
00030 }
00031
00032 bool ZdcTopology::isExcluded(const HcalZDCDetId& id) const {
00033 bool exed=false;
00034
00035
00036 switch(id.zside()){
00037 case( 1): exed = excludeZP_; break;
00038 case(-1): exed = excludeZN_; break;
00039 default: exed = false;
00040 }
00041
00042
00043 switch (id.section()) {
00044 case(HcalZDCDetId::EM) : exed = excludeEM_; break;
00045 case(HcalZDCDetId::HAD) : exed = excludeHAD_; break;
00046 case(HcalZDCDetId::LUM) : exed = excludeLUM_; break;
00047 default: exed = false;
00048 }
00049
00050
00051 if (!exed && !exclusionList_.empty()) {
00052 std::vector<HcalZDCDetId>::const_iterator
00053 i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
00054 if (i!=exclusionList_.end() && *i==id) exed=true;
00055 }
00056 return exed;
00057 }
00058
00059 void ZdcTopology::exclude(const HcalZDCDetId& id) {
00060 std::vector<HcalZDCDetId>::iterator
00061 i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
00062 if (i==exclusionList_.end() || *i!=id) {
00063 exclusionList_.insert(i,id);
00064 }
00065 }
00066
00067 void ZdcTopology::exclude(int zside) {
00068 switch(zside){
00069 case( 1): excludeZP_ = true; break;
00070 case(-1): excludeZN_ = true; break;
00071 default: break;
00072 }
00073 }
00074
00075 void ZdcTopology::exclude(int zside, HcalZDCDetId::Section section) {
00076 switch(zside){
00077 case( 1): excludeZP_ = true; break;
00078 case(-1): excludeZN_ = true; break;
00079 default: break;
00080 }
00081 switch (section) {
00082 case(HcalZDCDetId::EM) : excludeEM_ = true; break;
00083 case(HcalZDCDetId::HAD) : excludeHAD_ = true; break;
00084 case(HcalZDCDetId::LUM) : excludeLUM_ = true; break;
00085 default: break;
00086 }
00087 }
00088
00089 int ZdcTopology::exclude(int zside, HcalZDCDetId::Section section, int ich1, int ich2) {
00090 bool exed = false;
00091 switch(zside){
00092 case( 1): exed = excludeZP_; break;
00093 case(-1): exed = excludeZN_; break;
00094 default: exed = false;
00095 }
00096 if (exed) return 0;
00097
00098 switch (section) {
00099 case(HcalZDCDetId::EM) : exed = excludeEM_; break;
00100 case(HcalZDCDetId::HAD) : exed = excludeHAD_; break;
00101 case(HcalZDCDetId::LUM) : exed = excludeLUM_; break;
00102 default: exed = false;
00103 }
00104 if (exed) return 0;
00105
00106 bool isPositive = false;
00107 if(zside = 1)isPositive = true;
00108
00109 int n = 0;
00110 for (int ich = ich1; ich < ich2; ich++){
00111 HcalZDCDetId id(section, isPositive, ich);
00112 if(validRaw(id))exclude(id);
00113 n++;
00114 }
00115 return n;
00116 }
00117
00118 bool ZdcTopology::validRaw(const HcalZDCDetId& id) const{
00119 bool ok = true;
00120 if(abs(id.zside())!=1)return false;
00121 if(id.depth() <= 0)return false;
00122 if(!(id.section()== HcalZDCDetId::EM ||
00123 id.section()== HcalZDCDetId::HAD ||
00124 id.section()== HcalZDCDetId::LUM)) return false;
00125 if(id.section()== HcalZDCDetId::EM && id.depth() > ICH_EM_MAX)
00126 return false;
00127 if(id.section()== HcalZDCDetId::HAD && id.depth() > ICH_HAD_MAX)
00128 return false;
00129 if(id.section()== HcalZDCDetId::LUM && id.depth() > ICH_LUM_MAX)
00130 return false;
00131 return ok;
00132 }
00133
00134 std::vector<DetId> ZdcTopology::transverse(const DetId& id) const{
00135 std::vector<DetId> vNeighborsDetId;
00136 HcalZDCDetId zdcId = HcalZDCDetId(id);
00137 HcalZDCDetId zdcDetId;
00138 if(validRaw(zdcId) && zdcId.section()== HcalZDCDetId::EM){
00139 bool isPositive = false;
00140 if(zdcId.zside()==1)isPositive = true;
00141 if(zdcId.depth()==1){
00142 zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.depth()+1);
00143 vNeighborsDetId.push_back(zdcDetId.rawId());
00144 return vNeighborsDetId;
00145 }
00146 if(zdcId.depth()== ICH_EM_MAX){
00147 zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.depth()-1);
00148 vNeighborsDetId.push_back(zdcDetId.rawId());
00149 return vNeighborsDetId;
00150 }
00151 zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.depth()-1);
00152 vNeighborsDetId.push_back(zdcDetId.rawId());
00153 zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.depth()+1);
00154 vNeighborsDetId.push_back(zdcDetId.rawId());
00155 }
00156 return vNeighborsDetId;
00157 }
00158
00159 std::vector<DetId> ZdcTopology::longitudinal(const DetId& id) const{
00160 std::vector<DetId> vNeighborsDetId;
00161 HcalZDCDetId zdcId = HcalZDCDetId(id);
00162 HcalZDCDetId zdcDetId;
00163 if(validRaw(zdcId) && zdcId.section()== HcalZDCDetId::HAD){
00164 bool isPositive = false;
00165 if(zdcId.zside()==1)isPositive = true;
00166 if(zdcId.depth()==1){
00167 zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.depth()+1);
00168 vNeighborsDetId.push_back(zdcDetId.rawId());
00169 return vNeighborsDetId;
00170 }
00171 if(zdcId.depth()== ICH_HAD_MAX){
00172 zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.depth()-1);
00173 vNeighborsDetId.push_back(zdcDetId.rawId());
00174 return vNeighborsDetId;
00175 }
00176 zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.depth()-1);
00177 vNeighborsDetId.push_back(zdcDetId.rawId());
00178 zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.depth()+1);
00179 vNeighborsDetId.push_back(zdcDetId.rawId());
00180 }
00181 if(validRaw(zdcId) && zdcId.section()== HcalZDCDetId::LUM){
00182 bool isPositive = false;
00183 if(zdcId.zside()==1)isPositive = true;
00184 if(zdcId.depth()==1){
00185 zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.depth()+1);
00186 vNeighborsDetId.push_back(zdcDetId.rawId());
00187 return vNeighborsDetId;
00188 }
00189 if(zdcId.depth()== ICH_LUM_MAX){
00190 zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.depth()-1);
00191 vNeighborsDetId.push_back(zdcDetId.rawId());
00192 return vNeighborsDetId;
00193 }
00194 }
00195 return vNeighborsDetId;
00196 }
00197
00198 std::vector<DetId> ZdcTopology::east(const DetId& id) const
00199 {
00200 std::cout << "ZdcTopology::east() not yet implemented" << std::endl;
00201 std::vector<DetId> vNeighborsDetId;
00202 return vNeighborsDetId;
00203 }
00204
00205 std::vector<DetId> ZdcTopology::west(const DetId& id) const
00206 {
00207 std::cout << "ZdcTopology::west() not yet implemented" << std::endl;
00208 std::vector<DetId> vNeighborsDetId;
00209 return vNeighborsDetId;
00210 }
00211
00212 std::vector<DetId> ZdcTopology::north(const DetId& id) const
00213 {
00214 std::cout << "ZdcTopology::north() not yet implemented" << std::endl;
00215 std::vector<DetId> vNeighborsDetId;
00216 return vNeighborsDetId;
00217 }
00218 std::vector<DetId> ZdcTopology::south(const DetId& id) const
00219 {
00220 std::cout << "ZdcTopology::south() not yet implemented" << std::endl;
00221 std::vector<DetId> vNeighborsDetId;
00222 return vNeighborsDetId;
00223 }
00224 std::vector<DetId> ZdcTopology::up(const DetId& id) const
00225 {
00226 std::cout << "ZdcTopology::up() not yet implemented" << std::endl;
00227 std::vector<DetId> vNeighborsDetId;
00228 return vNeighborsDetId;
00229 }
00230 std::vector<DetId> ZdcTopology::down(const DetId& id) const
00231 {
00232 std::cout << "ZdcTopology::down() not yet implemented" << std::endl;
00233 std::vector<DetId> vNeighborsDetId;
00234 return vNeighborsDetId;
00235 }
00236
00237 int ZdcTopology::ncells(HcalZDCDetId::Section section) const{
00238 int ncells = 0;
00239 switch (section) {
00240 case(HcalZDCDetId::EM) : ncells = ICH_EM_MAX; break;
00241 case(HcalZDCDetId::HAD) : ncells = ICH_HAD_MAX; break;
00242 case(HcalZDCDetId::LUM) : ncells = ICH_LUM_MAX; break;
00243 case(HcalZDCDetId::Unknown) : ncells =0; break;
00244 }
00245 return ncells;
00246 }
00247
00248 int ZdcTopology::firstCell(HcalZDCDetId::Section section)const {
00249 int firstCell = 0;
00250 switch (section) {
00251 case(HcalZDCDetId::EM) : firstCell = firstEMModule_ ; break;
00252 case(HcalZDCDetId::HAD) : firstCell = firstHADModule_; break;
00253 case(HcalZDCDetId::LUM) : firstCell = firstLUMModule_; break;
00254 case(HcalZDCDetId::Unknown) : firstCell = 0; break;
00255 }
00256 return firstCell;
00257 }
00258
00259 int ZdcTopology::lastCell(HcalZDCDetId::Section section) const {
00260 int lastCell = 0;
00261 switch (section) {
00262 case(HcalZDCDetId::EM) : lastCell = lastEMModule_; break;
00263 case(HcalZDCDetId::HAD) : lastCell = lastHADModule_; break;
00264 case(HcalZDCDetId::LUM) : lastCell = lastLUMModule_; break;
00265 case(HcalZDCDetId::Unknown) : lastCell = 0; break;
00266 }
00267 return lastCell;
00268 }
00269
00270
00271
00272
00273