10 #include "CLHEP/Units/GlobalPhysicalConstants.h" 17 const bool mergePosition) :
18 hcons_(hcons), mergePosition_(mergePosition),
21 firstHERing_(999), lastHERing_(0),
22 firstHFRing_(29), lastHFRing_(41),
23 firstHORing_(1), lastHORing_(15),
24 firstHEDoublePhiRing_(999), firstHEQuadPhiRing_(999),
25 firstHFQuadPhiRing_(40), firstHETripleDepthRing_(999),
41 int unit = (
int)((
i.dphi+0.01)/(5.0*CLHEP::deg));
85 double eta = etaBinsHE_[etaBinsHE_.size()-1].etaMax;
95 for (
auto &
i : etaBinsHE_) {
101 const double fiveDegInRad = 2*
M_PI/72;
115 std::cout <<
"Set segmentation for ring " <<
ring <<
" with " 116 << segmentation.size() <<
" elements:";
117 for (
unsigned int k=0;
k<segmentation.size(); ++
k)
124 std::cout <<
"Set Plan-1 segmentation for ring " <<
ring <<
" with " 125 << segmentation.size() <<
" elements:";
126 for (
unsigned int k=0;
k<segmentation.size(); ++
k)
186 edm::LogWarning(
"CaloTopology") <<
"This is an incomplete constructor of HcalTopology - be warned that many functionalities will not be there - revert from this - get from EventSetup";
211 if (
id.iphi()<1 ||
id.iphi()>
IPHI_MAX ||
id.ieta()==0)
return false;
212 if (
id.
depth() != 0)
return false;
214 if (
id.ietaAbs() > 28) {
217 if ((
id.iphi() % 4) != 1)
return false;
218 if (
id.ietaAbs() > 32)
return false;
222 if (
id.ietaAbs()<30 ||
id.ietaAbs()>41)
return false;
223 if (
id.ietaAbs()>29 && ((
id.iphi()%2)==0))
return false;
224 if (
id.ietaAbs()>39 && ((
id.iphi()%4)!=3))
return false;
233 }
else if (flag == 1) {
245 switch (
id.subdet()) {
278 std::vector<DetId> vNeighborsDetId;
281 if (neighbors[
i].oldFormat()) neighbors[
i].changeForm();
282 vNeighborsDetId.emplace_back(
DetId(neighbors[
i].rawId()));
284 return vNeighborsDetId;
288 std::vector<DetId> vNeighborsDetId;
291 if (neighbors[
i].oldFormat()) neighbors[
i].changeForm();
292 vNeighborsDetId.emplace_back(
DetId(neighbors[
i].rawId()));
294 return vNeighborsDetId;
298 std::vector<DetId> vNeighborsDetId;
302 vNeighborsDetId.emplace_back(
DetId(neighbor.
rawId()));
304 return vNeighborsDetId;
308 std::vector<DetId> vNeighborsDetId;
312 vNeighborsDetId.emplace_back(
DetId(neighbor.
rawId()));
314 return vNeighborsDetId;
319 std::vector<DetId> vNeighborsDetId;
322 vNeighborsDetId.emplace_back(neighbor);
324 return vNeighborsDetId;
329 std::vector<DetId> vNeighborsDetId;
332 vNeighborsDetId.emplace_back(neighbor);
334 return vNeighborsDetId;
354 int depth_l=
std::min(depth1,depth2);
355 int depth_h=
std::max(depth1,depth2);
358 for (
int ieta=ieta_l; ieta<=ieta_h; ieta++)
359 for (
int iphi=iphi_l; iphi<=iphi_h; iphi++)
398 const int ie (
id.ietaAbs());
399 const int ip (
id.iphi());
402 return ( ( ip >= 1 ) &&
409 ( ( ( ie == 15 ) || ( ie == 16 ) ) &&
429 ( ip%2 == 1 ) ) ) ) ||
440 ( ip%4 == 3 ) ) ) ) ) ) ;
447 int aieta=
id.ietaAbs();
448 int depth=
id.depth();
450 int zside=
id.zside();
453 if ((ieta==0 || iphi<=0 || iphi>maxPhi) || aieta>
maxEta_) ok =
false;
460 (depth<hcons_->getMinDepth(0,aieta,iphi,zside))) ok=
false;
462 if (aieta>
lastHBRing() || depth>2 || (aieta<=14 && depth>1)) ok=
false;
467 (depth<hcons_->getMinDepth(1,aieta,iphi,zside)) ||
472 if (aieta ==
i.ieta) {
476 if (depth < 1) ok =
false;
478 if (depth <
i.depthStart) ok =
false;
511 switch (
id.subdet()) {
515 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+1,
id.
depth());
520 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+4,
id.
depth());
523 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+2,
id.
depth());
526 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+1,
id.
depth());
532 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+4,
id.
depth());
535 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+2,
id.
depth());
537 if (!
validRaw(neighbor)) ok =
false;
549 switch (
id.subdet()) {
553 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-1,
id.
depth());
558 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-4,
id.
depth());
561 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-2,
id.
depth());
564 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-1,
id.
depth());
570 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-4,
id.
depth());
573 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-2,
id.
depth());
575 if (!
validRaw(neighbor)) ok =
false;
596 int aieta=
id.ietaAbs();
601 neighbors[0]=
HcalDetId(
id.subdet(),(aieta+1)*
id.
zside(),((
id.iphi()==1)?(71):(
id.iphi()-2)),
id.
depth());
603 neighbors[0]=
HcalDetId(
id.subdet(),(aieta+1)*
id.
zside(),((
id.iphi()==1)?(71):(
id.iphi()-2)),
id.
depth());
611 if (!
valid(neighbors[0])) n=0;
618 int aieta=
id.ietaAbs();
634 }
else if (aieta==1) {
643 if (!
valid(neighbors[0]) && n==2) {
644 if (!
valid(neighbors[1])) n=0;
647 neighbors[0]=neighbors[1];
650 if (n==2 && !
valid(neighbors[1])) n=1;
651 if (n==1 && !
valid(neighbors[0])) n=0;
658 int iphi,
int zside,
int & nDepthBins,
659 int & startingBin)
const {
690 }
else if (etaRing==17) {
708 std::cerr <<
"Bad HCAL subdetector " << subdet << std::endl;
715 int ieta = detId.
ieta();
718 int iphi = detId.
iphi();
720 int nDepthBins, startingBin;
725 if (depth >= (startingBin+nDepthBins)) {
740 (ieta > 0) ? ++ieta : --ieta;
745 (ieta > 0) ? --ieta : ++ieta;
752 detId =
HcalDetId(subdet, ieta, iphi, depth);
758 int ieta = detId.
ieta();
761 int iphi = detId.
iphi();
763 int nDepthBins, startingBin;
780 (ieta > 0) ? --ieta : ++ieta;
781 }
else if (depth <= 0) {
786 ieta = (ieta > 0) ? etaRing : -etaRing;
788 if (etaRing ==
i.ieta) {
789 depth =
i.depthStart+
i.layer.size()-1;
817 static const double twopi =
M_PI+
M_PI;
857 static const double twopi =
M_PI+
M_PI;
873 if (phi<0.0) phi += twopi;
874 if (phi>twopi) phi -= twopi;
875 int phibin(1),
unit(1);
888 if (unit == 2) iphi = (phibin-1)*2+1;
889 else if (unit == 4) iphi = (phibin-1)*4+3;
894 std::vector<int> & readoutDepths,
895 const bool one)
const {
898 SegmentationMap::const_iterator
pos;
902 throw cms::Exception(
"HcalTopology") <<
"No depth segmentation found for ring" <<
ring;
907 throw cms::Exception(
"HcalTopology") <<
"No depth segmentation found for ring" <<
ring;
912 readoutDepths = pos->second;
916 const std::vector<int> & readoutDepths,
926 const unsigned depth,
927 const bool one)
const {
928 std::vector<int> readoutDepths;
930 int d1 = std::lower_bound(readoutDepths.begin(), readoutDepths.end(),
depth) - readoutDepths.begin();
931 int d2 = std::upper_bound(readoutDepths.begin(), readoutDepths.end(),
depth) - readoutDepths.begin();
932 return std::pair<int, int>(d1, d2);
956 int ieta = (keta > 0) ? keta : -keta;
965 if ((ietal < (
int)(
etaTable.size())) && (ieta > 0))
966 return std::pair<double,double>(
etaTable[ieta-1],etaTable[ietal]);
968 return std::pair<double,double>(0,0);
975 const int ip (hid.
iphi() ) ;
976 const int ie (hid.
ietaAbs() ) ;
978 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
980 ( ip - 1 )*18 +
dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*
kHBhalf :
982 2*
kHBhalf + ( ip - 1 )*8 + ( ip/2 )*20 +
983 ( ( ie==16 || ie==17 ) ? ie - 16 :
984 ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) +
dp - 1 :
985 ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) +
dp - 1 :
986 ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) +
dp - 1 :
987 26 + 2*( ie - 29 ) +
dp - 1 ) ) ) ) + zn*
kHEhalf :
992 ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
993 2*( ie - 29 ) + (
dp - 1 ) + zn*
kHFhalf : 0xFFFFFFFFu ) ) ) ) ;
1000 const int ip (hid.
iphi() ) ;
1001 const int ie (hid.
ietaAbs() ) ;
1003 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1004 unsigned int retval = 0xFFFFFFFFu;
1006 retval=( ip - 1 )*18 +
dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*
kHBhalf;
1017 const int ip (hid.
iphi() ) ;
1018 const int ie (hid.
ietaAbs() ) ;
1020 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1021 unsigned int retval = 0xFFFFFFFFu;
1023 retval=( ip - 1 )*8 + ( ip/2 )*20 +
1024 ( ( ie==16 || ie==17 ) ? ie - 16 :
1025 ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) +
dp - 1 :
1026 ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) +
dp - 1 :
1027 ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) +
dp - 1 :
1028 26 + 2*( ie - 29 ) +
dp - 1 ) ) ) ) + zn*
kHEhalf;
1039 const int ip (hid.
iphi() ) ;
1040 const int ie (hid.
ietaAbs() ) ;
1041 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1043 unsigned int retval = 0xFFFFFFFFu;
1045 retval=( ip - 1 )*15 + ( ie - 1 ) + zn*
kHOhalf;
1055 const int ip (hid.
iphi() ) ;
1056 const int ie (hid.
ietaAbs() ) ;
1058 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1060 unsigned int retval = 0xFFFFFFFFu;
1062 retval = ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
1063 2*( ie - 29 ) + (
dp - 1 ) + zn*
kHFhalf;
1065 retval=
dp-1+2*(ip-1);
1075 unsigned int ietaAbs = tid.
ietaAbs();
1076 unsigned int iphi = tid.
iphi();
1077 unsigned int ivers = tid.
version();
1081 if ((iphi-1)%4==0) index = (iphi-1)*32 + (ietaAbs-1) - (12*((iphi-1)/4));
1082 else index = (iphi-1)*28 + (ietaAbs-1) + (4*(((iphi-1)/4)+1));
1083 if (zside == -1) index +=
kHThalf;
1087 index += (36 * (ietaAbs - 30) + ((iphi - 1)/2));
1096 int ieta = tid.
ieta();
1097 int iphi = tid.
iphi();
1099 unsigned int index=0xFFFFFFFFu;
1109 index = ((iphi+1)/4-1) + 18*channel + 27*(ieta+1);
1114 if (channel>2) channel-=1;
1115 index = ((iphi+1)/4-1) + 18*channel + 54*(ieta+1) + 108;
1119 if (channel==8) channel = 2;
1121 index = (iphi-1)/18 + 4*channel + 6*(ieta+1) + 324;
1126 index = (ieta+2) + 420;
1130 if (ieta<0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 348;
1131 else if (ieta>0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 6 + 348;
1132 else index = ((iphi+1)/6-1) + 36*channel + 6*(ieta+2) + 348;
1143 if (
abs(ieta)==4) index = ((iphi-1)%36) + (((zside+1)*36)/2) + 72 + 425;
1144 else index = (iphi-1) + (36*(zside+1)*2) + 425;
1152 unsigned int retval(0);
1182 << std::hex << retval <<
std::dec << std::endl;
1193 int in ( denseid ) ;
1200 iz = ( in<
kHFhalf ? 1 : -1 ) ;
1204 ip += 1 + ( in>21 ? 2 : 0 ) ;
1205 if( 3 == ip%4 ) in -= 22 ;
1211 iz = ( in<
kHOhalf ? 1 : -1 ) ;
1215 ie = 1 + ( in - 15*( ip - 1 ) ) ;
1216 }
else if ( in > 2*
kHBhalf - 1 ) {
1219 iz = ( in<
kHEhalf ? 1 : -1 ) ;
1224 if( 0 == ip%2 ) in %= 28 ;
1225 ie = 15 + ( in<2 ? 1 + in : 2 +
1226 ( in<20 ? 1 + ( in - 2 )/2 : 9 +
1227 ( in<26 ? 1 + ( in - 20 )/3 : 3 ) ) ) ;
1230 ( in<20 ? 1 + ( in - 2 )%2 :
1231 ( in<26 ? 1 + ( in - 20 )%3 :
1232 ( 1 + ( in - 26 )%2 ) ) ) ) ) ;
1234 iz = ( in<
kHBhalf ? 1 : -1 ) ;
1249 if (denseid <
ncells()) {
1257 if (ie > 12) {ie = 54 -ie; iz = -1;}
1258 else {ie += 29; iz = 1;}
1265 if (ie > 14) {ie = 30 -ie; iz = -1;}
1266 else {ie += 1; iz = 1;}
1267 }
else if (denseid >= (
HBSize_)) {
1290 <<
" : " << hid.
rawId() <<
std::dec <<
" | " << hid << std::endl;
DetId denseId2detId(unsigned int) const override
return a linear packed id
std::vector< int > getDepth(const int &det, const int &phi, const int &zside, const unsigned int &eta) const
std::vector< int > unitPhiHF
int zside() const
get the z-side of the tower (1/-1)
void getDepthSegmentation(const unsigned ring, std::vector< int > &readoutDepths, const bool flag=false) const
int topoVersion() const override
return a version which identifies the given topology
int decIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
unsigned int numberOfShapes_
unsigned int detId2denseIdPreLS1(const DetId &id) const
std::vector< double > dPhiTableHF
void excludeSubdetector(HcalSubdetector subdet)
HcalSubdetector subdet() const
get the subdetector
std::vector< HcalDDDRecConstants::HcalEtaBin > etaBinsHB_
int phiBin(HcalSubdetector subdet, int etaRing, double phi) const
std::vector< int > unitPhi
bool valid(const DetId &id) const override
CalibDetType calibFlavor() const
get the flavor of this calibration detid
std::vector< DetId > up(const DetId &id) const override
unsigned int detId2denseId(const DetId &id) const override
return a linear packed id
int zside() const
get the z-side of the cell (1/-1)
bool validDetId(HcalSubdetector subdet, int ieta, int iphi, int depth) const
unsigned int detId2denseIdHT(const DetId &id) const
return a linear packed id from HT
unsigned int detId2denseIdHF(const DetId &id) const
return a linear packed id from HF
void exclude(const HcalDetId &id)
const std::vector< double > & getEtaTableHF() const
HcalTopologyMode::TriggerMode triggerMode_
int nPhiBins(int etaRing) const
how many phi segments in this ring
int incIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
bool decrementDepth(HcalDetId &id) const
unsigned int detId2denseIdHB(const DetId &id) const
return a linear packed id from HB
bool decIPhi(const HcalDetId &id, HcalDetId &neighbor) const
bool validHcal(const HcalDetId &id) const
std::vector< HcalDDDRecConstants::HcalEtaBin > etaBinsHE_
int ieta() const
get the rbx name (if relevant)
const std::vector< double > & getPhiOffs() const
std::pair< int, int > getEtaRange(const int &i) const
HcalTopologyMode::Mode mode() const
int getTriggerMode() const
uint32_t rawId() const
get the raw id
U second(std::pair< T, U > const &p)
bool isExcluded(const HcalDetId &id) const
void depthBinInformation(HcalSubdetector subdet, int etaRing, int iphi, int zside, int &nDepthBins, int &startingBin) const
finds the number of depth bins and which is the number to start with
std::vector< HcalEtaBin > getEtaBins(const int &itype) const
int depth() const
get the tower depth
std::pair< int, int > segmentBoundaries(const unsigned ring, const unsigned depth, const bool flag=false) const
bool incIPhi(const HcalDetId &id, HcalDetId &neighbor) const
bool isPlan1MergedId(const HcalDetId &id) const
bool validRaw(const HcalDetId &id) const
std::vector< DetId > south(const DetId &id) const override
int decAIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
int maxDepth(HcalSubdetector subdet) const
int getMinDepth(const int &itype, const int &ieta, const int &iphi, const int &zside) const
HcalTopologyMode::Mode mode_
HcalTopology(const HcalDDDRecConstants *hcons, const bool mergePosition=false)
int etaRing(HcalSubdetector subdet, double eta) const
eta and phi index from eta, phi values
int firstHETripleDepthRing() const
int ieta() const
get the cell ieta
int getDepthEta16(const int &det, const int &iphi, const int &zside) const
Abs< T >::type abs(const T &t)
int getDepthEta29(const int &iphi, const int &zside, const int &type) const
std::vector< double > etaTableHF
int firstHEDoublePhiRing() const
SegmentationMap depthSegmentation_
SegmentationMap depthSegmentationOne_
std::vector< double > etaTable
int ietaAbs() const
get the absolute value of the cell ieta
int iphi() const
get the low-edge iphi (if relevant)
bool validDetIdPreLS1(const HcalDetId &id) const
int iphi() const
get the cell iphi
bool incrementDepth(HcalDetId &id) const
int zside() const
get the sign of ieta (+/-1)
std::vector< double > phioff
const std::vector< double > & getPhiTable() const
int getNoff(const int &i) const
int version() const
get the version code for the trigger tower
int getMaxDepth(const int &type) const
const std::vector< double > & getEtaTable() const
int firstHFQuadPhiRing() const
std::vector< double > dPhiTable
std::vector< DetId > west(const DetId &id) const override
int cboxChannel() const
get the calibration box channel (if relevant)
std::vector< DetId > north(const DetId &id) const override
std::pair< double, double > etaRange(HcalSubdetector subdet, int ieta) const
TString units(TString variable, Char_t axis)
const std::vector< double > & getPhiTableHF() const
std::vector< DetId > down(const DetId &id) const override
int firstHETripleDepthRing_
unsigned int detId2denseIdHO(const DetId &id) const
return a linear packed id from HO
std::vector< HcalDetId > exclusionList_
unsigned int ncells() const override
return a count of valid cells (for dense indexing use)
unsigned int detId2denseIdHE(const DetId &id) const
return a linear packed id from HE
bool isPlan1ToBeMergedId(const HcalDetId &id) const
int firstHEQuadPhiRing() const
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)
void setDepthSegmentation(const unsigned ring, const std::vector< int > &readoutDepths, const bool flag)
int maxHFDepth(int ieta, int iphi) const
int incAIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
unsigned int detId2denseIdCALIB(const DetId &id) const
return a linear packed id from CALIB
int ietaAbs() const
get the absolute value of the tower ieta
int iphi() const
get the tower iphi
std::vector< DetId > east(const DetId &id) const override
double etaMax(HcalSubdetector subdet) const
int firstHEDoublePhiRing_
const HcalDDDRecConstants * hcons_
static const int IPHI_MAX
int getNPhi(const int &type) const
bool validHT(const HcalTrigTowerDetId &id) const