Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
#include "Geometry/ForwardGeometry/interface/CastorTopology.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <cmath>
#include <iostream>
#include <algorithm>

static const int MODULE_EM_MAX = 2;
static const int MODULE_HAD_MAX = 12;

CastorTopology::CastorTopology()
    : excludeEM_(false),
      excludeHAD_(false),
      excludeZP_(false),
      excludeZN_(false),
      firstEMModule_(1),
      lastEMModule_(2),
      firstHADModule_(3),
      lastHADModule_(14) {}

bool CastorTopology::valid(const HcalCastorDetId& id) const { return (validRaw(id) && !isExcluded(id)); }

bool CastorTopology::isExcluded(const HcalCastorDetId& id) const {
  bool exed = false;

  // check for section exclutions
  switch (id.section()) {
    case (HcalCastorDetId::EM):
      exed = excludeEM_;
      break;
    case (HcalCastorDetId::HAD):
      exed = excludeHAD_;
      break;
    default:
      exed = false;
  }

  // check the entire list
  if (!exed && !exclusionList_.empty()) {
    std::vector<HcalCastorDetId>::const_iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
    if (i != exclusionList_.end() && *i == id)
      exed = true;
  }
  return exed;
}

void CastorTopology::exclude(const HcalCastorDetId& id) {
  std::vector<HcalCastorDetId>::iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
  if (i == exclusionList_.end() || *i != id) {
    exclusionList_.insert(i, id);
  }
}

void CastorTopology::exclude(int zside) {
  switch (zside) {
    case (1):
      excludeZP_ = true;
      break;
    case (-1):
      excludeZN_ = true;
      break;
    default:
      break;
  }
}

void CastorTopology::exclude(int zside, HcalCastorDetId::Section section) {
  switch (zside) {
    case (1):
      excludeZP_ = true;
      break;
    case (-1):
      excludeZN_ = true;
      break;
    default:
      break;
  }
  switch (section) {
    case (HcalCastorDetId::EM):
      excludeEM_ = true;
      break;
    case (HcalCastorDetId::HAD):
      excludeHAD_ = true;
      break;
    default:
      break;
  }
}

int CastorTopology::exclude(int zside,
                            HcalCastorDetId::Section section1,
                            int isec1,
                            int imod1,
                            HcalCastorDetId::Section section2,
                            int isec2,
                            int imod2) {
  bool exed = false;
  switch (zside) {
    case (1):
      exed = excludeZP_;
      break;
    case (-1):
      exed = excludeZN_;
      break;
    default:
      exed = false;
  }
  if (exed)
    return 0;

  /* NOTE not so sure about the exclusion */
  if (section1 == HcalCastorDetId::EM && section2 == HcalCastorDetId::EM) {
    exed = excludeEM_;
  } else if (section1 == HcalCastorDetId::HAD && section2 == HcalCastorDetId::HAD) {
    exed = excludeHAD_;
  } else {
    exed = false;
  };

  if (exed)
    return 0;

  bool isPositive = false;
  if (zside == 1)
    isPositive = true;

  int n = 0;
  for (int isec = isec1; isec < isec2; isec++) {
    for (int imod = imod1; imod < imod2; imod++) {
      HcalCastorDetId id(section1, isPositive, isec, imod);
      if (validRaw(id))
        exclude(id);
      n++;
    }
  }
  return n;
}

bool CastorTopology::validRaw(const HcalCastorDetId& id) const {
  return HcalCastorDetId::validDetId(id.section(), id.zside() > 0, id.sector(), id.module());
}

std::vector<DetId> CastorTopology::incSector(const DetId& id) const {
  std::vector<DetId> vNeighborsDetId;
  HcalCastorDetId castorId = HcalCastorDetId(id);
  HcalCastorDetId castorDetId;
  if (validRaw(castorId)) {
    bool isPositive = false;
    if (castorId.zside() == 1)
      isPositive = true;
    if (castorId.sector() == 1) {
      castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector() + 1, castorId.module());
      vNeighborsDetId.emplace_back(castorDetId.rawId());
      return vNeighborsDetId;
    }
    if (castorId.sector() == 16) {
      castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector() - 1, castorId.module());
      vNeighborsDetId.emplace_back(castorDetId.rawId());
      return vNeighborsDetId;
    }
    castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector() - 1, castorId.module());
    vNeighborsDetId.emplace_back(castorDetId.rawId());
    castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector() + 1, castorId.module());
    vNeighborsDetId.emplace_back(castorDetId.rawId());
  }
  return vNeighborsDetId;
}

std::vector<DetId> CastorTopology::incModule(const DetId& id) const {
  std::vector<DetId> vNeighborsDetId;
  HcalCastorDetId castorId = HcalCastorDetId(id);
  HcalCastorDetId castorDetId;
  if (validRaw(castorId) && castorId.section() == HcalCastorDetId::EM) {
    bool isPositive = false;
    if (castorId.zside() == 1)
      isPositive = true;
    if (castorId.module() == 1) {
      castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() + 1);
      vNeighborsDetId.emplace_back(castorDetId.rawId());
      return vNeighborsDetId;
    }
    if (castorId.module() == MODULE_EM_MAX) {
      castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() - 1);
      vNeighborsDetId.emplace_back(castorDetId.rawId());
      return vNeighborsDetId;
    }
    castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() - 1);
    vNeighborsDetId.emplace_back(castorDetId.rawId());
    castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() + 1);
    vNeighborsDetId.emplace_back(castorDetId.rawId());
  }
  if (validRaw(castorId) && castorId.section() == HcalCastorDetId::HAD) {
    bool isPositive = false;
    if (castorId.zside() == 1)
      isPositive = true;
    if (castorId.module() == 1) {
      castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() + 1);
      vNeighborsDetId.emplace_back(castorDetId.rawId());
      return vNeighborsDetId;
    }
    if (castorId.module() == MODULE_HAD_MAX) {
      castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() - 1);
      vNeighborsDetId.emplace_back(castorDetId.rawId());
      return vNeighborsDetId;
    }
  }
  return vNeighborsDetId;
}

std::vector<DetId> CastorTopology::east(const DetId& /*id*/) const {
  edm::LogVerbatim("ForwardGeom") << "CastorTopology::east() not yet implemented";
  std::vector<DetId> vNeighborsDetId;
  return vNeighborsDetId;
}

std::vector<DetId> CastorTopology::west(const DetId& /*id*/) const {
  edm::LogVerbatim("ForwardGeom") << "CastorTopology::west() not yet implemented";
  std::vector<DetId> vNeighborsDetId;
  return vNeighborsDetId;
}

std::vector<DetId> CastorTopology::north(const DetId& /*id*/) const {
  edm::LogVerbatim("ForwardGeom") << "CastorTopology::north() not yet implemented";
  std::vector<DetId> vNeighborsDetId;
  return vNeighborsDetId;
}
std::vector<DetId> CastorTopology::south(const DetId& /*id*/) const {
  edm::LogVerbatim("ForwardGeom") << "CastorTopology::south() not yet implemented";
  std::vector<DetId> vNeighborsDetId;
  return vNeighborsDetId;
}
std::vector<DetId> CastorTopology::up(const DetId& /*id*/) const {
  edm::LogVerbatim("ForwardGeom") << "CastorTopology::up() not yet implemented";
  std::vector<DetId> vNeighborsDetId;
  return vNeighborsDetId;
}
std::vector<DetId> CastorTopology::down(const DetId& /*id*/) const {
  edm::LogVerbatim("ForwardGeom") << "CastorTopology::down() not yet implemented";
  std::vector<DetId> vNeighborsDetId;
  return vNeighborsDetId;
}

int CastorTopology::ncells(HcalCastorDetId::Section section) const {
  int ncells = 0;
  switch (section) {
    case (HcalCastorDetId::EM):
      ncells = MODULE_EM_MAX * 16;
      break;
    case (HcalCastorDetId::HAD):
      ncells = MODULE_HAD_MAX * 16;
      break;
    case (HcalCastorDetId::Unknown):
      ncells = 0;
      break;
  }
  return ncells;
}

int CastorTopology::firstCell(HcalCastorDetId::Section section) const {
  int firstCell = 0;
  switch (section) {
    case (HcalCastorDetId::EM):
      firstCell = firstEMModule_;
      break;
    case (HcalCastorDetId::HAD):
      firstCell = firstHADModule_;
      break;
    case (HcalCastorDetId::Unknown):
      firstCell = 0;
      break;
  }
  return firstCell;
}

int CastorTopology::lastCell(HcalCastorDetId::Section section) const {
  int lastCell = 0;
  switch (section) {
    case (HcalCastorDetId::EM):
      lastCell = lastEMModule_;
      break;
    case (HcalCastorDetId::HAD):
      lastCell = lastHADModule_;
      break;
    case (HcalCastorDetId::Unknown):
      lastCell = 0;
      break;
  }
  return lastCell;
}