11 #include "CLHEP/Units/GlobalPhysicalConstants.h" 18 const bool mergePosition) :
19 hcons_(hcons), mergePosition_(mergePosition),
22 firstHERing_(999), lastHERing_(0),
23 firstHFRing_(29), lastHFRing_(41),
24 firstHORing_(1), lastHORing_(15),
25 firstHEDoublePhiRing_(999), firstHEQuadPhiRing_(999),
26 firstHFQuadPhiRing_(40), firstHETripleDepthRing_(999),
42 int unit = (
int)((
i.dphi+0.01)/(5.0*CLHEP::deg));
86 double eta = etaBinsHE_[etaBinsHE_.size()-1].etaMax;
96 for (
auto &
i : etaBinsHE_) {
102 const double fiveDegInRad = 2*
M_PI/72;
116 std::cout <<
"Set segmentation for ring " <<
ring <<
" with " 117 << segmentation.size() <<
" elements:";
118 for (
unsigned int k=0;
k<segmentation.size(); ++
k)
125 std::cout <<
"Set Plan-1 segmentation for ring " <<
ring <<
" with " 126 << segmentation.size() <<
" elements:";
127 for (
unsigned int k=0;
k<segmentation.size(); ++
k)
187 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";
212 if (
id.iphi()<1 ||
id.iphi()>
IPHI_MAX ||
id.ieta()==0)
return false;
213 if (
id.
depth() != 0)
return false;
215 if (
id.ietaAbs() > 28) {
218 if ((
id.iphi() % 4) != 1)
return false;
219 if (
id.ietaAbs() > 32)
return false;
223 if (
id.ietaAbs()<30 ||
id.ietaAbs()>41)
return false;
224 if (
id.ietaAbs()>29 && ((
id.iphi()%2)==0))
return false;
225 if (
id.ietaAbs()>39 && ((
id.iphi()%4)!=3))
return false;
234 }
else if (flag == 1) {
246 switch (
id.subdet()) {
279 std::vector<DetId> vNeighborsDetId;
282 if (neighbors[
i].oldFormat()) neighbors[
i].changeForm();
283 vNeighborsDetId.emplace_back(
DetId(neighbors[
i].rawId()));
285 return vNeighborsDetId;
289 std::vector<DetId> vNeighborsDetId;
292 if (neighbors[
i].oldFormat()) neighbors[
i].changeForm();
293 vNeighborsDetId.emplace_back(
DetId(neighbors[
i].rawId()));
295 return vNeighborsDetId;
299 std::vector<DetId> vNeighborsDetId;
303 vNeighborsDetId.emplace_back(
DetId(neighbor.
rawId()));
305 return vNeighborsDetId;
309 std::vector<DetId> vNeighborsDetId;
313 vNeighborsDetId.emplace_back(
DetId(neighbor.
rawId()));
315 return vNeighborsDetId;
320 std::vector<DetId> vNeighborsDetId;
323 vNeighborsDetId.emplace_back(neighbor);
325 return vNeighborsDetId;
330 std::vector<DetId> vNeighborsDetId;
333 vNeighborsDetId.emplace_back(neighbor);
335 return vNeighborsDetId;
355 int depth_l=
std::min(depth1,depth2);
356 int depth_h=
std::max(depth1,depth2);
359 for (
int ieta=ieta_l; ieta<=ieta_h; ieta++)
360 for (
int iphi=iphi_l; iphi<=iphi_h; iphi++)
399 const int ie (
id.ietaAbs());
400 const int ip (
id.iphi());
403 return ( ( ip >= 1 ) &&
410 ( ( ( ie == 15 ) || ( ie == 16 ) ) &&
430 ( ip%2 == 1 ) ) ) ) ||
441 ( ip%4 == 3 ) ) ) ) ) ) ;
448 int aieta=
id.ietaAbs();
449 int depth=
id.depth();
451 int zside=
id.zside();
454 if ((ieta==0 || iphi<=0 || iphi>maxPhi) || aieta>
maxEta_) ok =
false;
461 (depth<hcons_->getMinDepth(0,aieta,iphi,zside))) ok=
false;
463 if (aieta>
lastHBRing() || depth>2 || (aieta<=14 && depth>1)) ok=
false;
468 (depth<hcons_->getMinDepth(1,aieta,iphi,zside)) ||
473 if (aieta ==
i.ieta) {
477 if (depth < 1) ok =
false;
479 if (depth <
i.depthStart) ok =
false;
512 switch (
id.subdet()) {
516 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+1,
id.
depth());
521 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+4,
id.
depth());
524 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+2,
id.
depth());
527 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+1,
id.
depth());
533 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+4,
id.
depth());
536 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+2,
id.
depth());
538 if (!
validRaw(neighbor)) ok =
false;
550 switch (
id.subdet()) {
554 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-1,
id.
depth());
559 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-4,
id.
depth());
562 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-2,
id.
depth());
565 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-1,
id.
depth());
571 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-4,
id.
depth());
574 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-2,
id.
depth());
576 if (!
validRaw(neighbor)) ok =
false;
597 int aieta=
id.ietaAbs();
602 neighbors[0]=
HcalDetId(
id.subdet(),(aieta+1)*
id.
zside(),((
id.iphi()==1)?(71):(
id.iphi()-2)),
id.
depth());
604 neighbors[0]=
HcalDetId(
id.subdet(),(aieta+1)*
id.
zside(),((
id.iphi()==1)?(71):(
id.iphi()-2)),
id.
depth());
612 if (!
valid(neighbors[0])) n=0;
619 int aieta=
id.ietaAbs();
635 }
else if (aieta==1) {
644 if (!
valid(neighbors[0]) && n==2) {
645 if (!
valid(neighbors[1])) n=0;
648 neighbors[0]=neighbors[1];
651 if (n==2 && !
valid(neighbors[1])) n=1;
652 if (n==1 && !
valid(neighbors[0])) n=0;
659 int iphi,
int zside,
int & nDepthBins,
660 int & startingBin)
const {
691 }
else if (etaRing==17) {
709 std::cerr <<
"Bad HCAL subdetector " << subdet << std::endl;
716 int ieta = detId.
ieta();
719 int iphi = detId.
iphi();
721 int nDepthBins, startingBin;
726 if (depth >= (startingBin+nDepthBins)) {
741 (ieta > 0) ? ++ieta : --ieta;
746 (ieta > 0) ? --ieta : ++ieta;
753 detId =
HcalDetId(subdet, ieta, iphi, depth);
759 int ieta = detId.
ieta();
762 int iphi = detId.
iphi();
764 int nDepthBins, startingBin;
781 (ieta > 0) ? --ieta : ++ieta;
782 }
else if (depth <= 0) {
787 ieta = (ieta > 0) ? etaRing : -etaRing;
789 if (etaRing ==
i.ieta) {
790 depth =
i.depthStart+
i.layer.size()-1;
818 static const double twopi =
M_PI+
M_PI;
858 static const double twopi =
M_PI+
M_PI;
874 if (phi<0.0) phi += twopi;
875 if (phi>twopi) phi -= twopi;
876 int phibin(1),
unit(1);
889 if (unit == 2) iphi = (phibin-1)*2+1;
890 else if (unit == 4) iphi = (phibin-1)*4+3;
895 std::vector<int> & readoutDepths,
896 const bool one)
const {
899 SegmentationMap::const_iterator
pos;
903 throw cms::Exception(
"HcalTopology") <<
"No depth segmentation found for ring" <<
ring;
908 throw cms::Exception(
"HcalTopology") <<
"No depth segmentation found for ring" <<
ring;
913 readoutDepths = pos->second;
917 const std::vector<int> & readoutDepths,
927 const unsigned depth,
928 const bool one)
const {
929 std::vector<int> readoutDepths;
931 int d1 = std::lower_bound(readoutDepths.begin(), readoutDepths.end(),
depth) - readoutDepths.begin();
932 int d2 = std::upper_bound(readoutDepths.begin(), readoutDepths.end(),
depth) - readoutDepths.begin();
933 return std::pair<int, int>(d1, d2);
957 int ieta = (keta > 0) ? keta : -keta;
966 if ((ietal < (
int)(
etaTable.size())) && (ieta > 0))
967 return std::pair<double,double>(
etaTable[ieta-1],etaTable[ietal]);
969 return std::pair<double,double>(0,0);
976 const int ip (hid.
iphi() ) ;
977 const int ie (hid.
ietaAbs() ) ;
979 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
981 ( ip - 1 )*18 +
dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*
kHBhalf :
983 2*
kHBhalf + ( ip - 1 )*8 + ( ip/2 )*20 +
984 ( ( ie==16 || ie==17 ) ? ie - 16 :
985 ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) +
dp - 1 :
986 ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) +
dp - 1 :
987 ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) +
dp - 1 :
988 26 + 2*( ie - 29 ) +
dp - 1 ) ) ) ) + zn*
kHEhalf :
993 ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
994 2*( ie - 29 ) + (
dp - 1 ) + zn*
kHFhalf : 0xFFFFFFFFu ) ) ) ) ;
1001 const int ip (hid.
iphi() ) ;
1002 const int ie (hid.
ietaAbs() ) ;
1004 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1005 unsigned int retval = 0xFFFFFFFFu;
1007 retval=( ip - 1 )*18 +
dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*
kHBhalf;
1018 const int ip (hid.
iphi() ) ;
1019 const int ie (hid.
ietaAbs() ) ;
1021 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1022 unsigned int retval = 0xFFFFFFFFu;
1024 retval=( ip - 1 )*8 + ( ip/2 )*20 +
1025 ( ( ie==16 || ie==17 ) ? ie - 16 :
1026 ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) +
dp - 1 :
1027 ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) +
dp - 1 :
1028 ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) +
dp - 1 :
1029 26 + 2*( ie - 29 ) +
dp - 1 ) ) ) ) + zn*
kHEhalf;
1040 const int ip (hid.
iphi() ) ;
1041 const int ie (hid.
ietaAbs() ) ;
1042 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1044 unsigned int retval = 0xFFFFFFFFu;
1046 retval=( ip - 1 )*15 + ( ie - 1 ) + zn*
kHOhalf;
1056 const int ip (hid.
iphi() ) ;
1057 const int ie (hid.
ietaAbs() ) ;
1059 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1061 unsigned int retval = 0xFFFFFFFFu;
1063 retval = ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
1064 2*( ie - 29 ) + (
dp - 1 ) + zn*
kHFhalf;
1066 retval=
dp-1+2*(ip-1);
1076 unsigned int ietaAbs = tid.
ietaAbs();
1077 unsigned int iphi = tid.
iphi();
1078 unsigned int ivers = tid.
version();
1082 if ((iphi-1)%4==0) index = (iphi-1)*32 + (ietaAbs-1) - (12*((iphi-1)/4));
1083 else index = (iphi-1)*28 + (ietaAbs-1) + (4*(((iphi-1)/4)+1));
1084 if (zside == -1) index +=
kHThalf;
1088 index += (36 * (ietaAbs - 30) + ((iphi - 1)/2));
1097 int ieta = tid.
ieta();
1098 int iphi = tid.
iphi();
1100 unsigned int index=0xFFFFFFFFu;
1110 index = ((iphi+1)/4-1) + 18*channel + 27*(ieta+1);
1115 if (channel>2) channel-=1;
1116 index = ((iphi+1)/4-1) + 18*channel + 54*(ieta+1) + 108;
1120 if (channel==8) channel = 2;
1122 index = (iphi-1)/18 + 4*channel + 6*(ieta+1) + 324;
1127 index = (ieta+2) + 420;
1131 if (ieta<0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 348;
1132 else if (ieta>0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 6 + 348;
1133 else index = ((iphi+1)/6-1) + 36*channel + 6*(ieta+2) + 348;
1144 if (
abs(ieta)==4) index = ((iphi-1)%36) + (((zside+1)*36)/2) + 72 + 425;
1145 else index = (iphi-1) + (36*(zside+1)*2) + 425;
1153 unsigned int retval(0);
1183 << std::hex << retval <<
std::dec << std::endl;
1194 int in ( denseid ) ;
1201 iz = ( in<
kHFhalf ? 1 : -1 ) ;
1205 ip += 1 + ( in>21 ? 2 : 0 ) ;
1206 if( 3 == ip%4 ) in -= 22 ;
1212 iz = ( in<
kHOhalf ? 1 : -1 ) ;
1216 ie = 1 + ( in - 15*( ip - 1 ) ) ;
1217 }
else if ( in > 2*
kHBhalf - 1 ) {
1220 iz = ( in<
kHEhalf ? 1 : -1 ) ;
1225 if( 0 == ip%2 ) in %= 28 ;
1226 ie = 15 + ( in<2 ? 1 + in : 2 +
1227 ( in<20 ? 1 + ( in - 2 )/2 : 9 +
1228 ( in<26 ? 1 + ( in - 20 )/3 : 3 ) ) ) ;
1231 ( in<20 ? 1 + ( in - 2 )%2 :
1232 ( in<26 ? 1 + ( in - 20 )%3 :
1233 ( 1 + ( in - 26 )%2 ) ) ) ) ) ;
1235 iz = ( in<
kHBhalf ? 1 : -1 ) ;
1250 if (denseid <
ncells()) {
1258 if (ie > 12) {ie = 54 -ie; iz = -1;}
1259 else {ie += 29; iz = 1;}
1266 if (ie > 14) {ie = 30 -ie; iz = -1;}
1267 else {ie += 1; iz = 1;}
1268 }
else if (denseid >= (
HBSize_)) {
1291 <<
" : " << 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