11 #include "CLHEP/Units/GlobalPhysicalConstants.h"
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),
26 singlePhiBins_(72), doublePhiBins_(36) {
100 const double fiveDegInRad = 2*
M_PI/72;
114 std::cout <<
"Set segmentation for ring " <<
ring <<
" with "
115 << segmentation.size() <<
" elements:";
116 for (
unsigned int k=0;
k<segmentation.size(); ++
k)
137 mode_(mode), triggerMode_(tmode),
138 firstHBRing_(1), lastHBRing_(16),
139 firstHERing_(16), lastHERing_(29),
140 firstHFRing_(29), lastHFRing_(41),
141 firstHORing_(1), lastHORing_(15),
142 firstHEDoublePhiRing_((mode==HcalTopologyMode::
H2 || mode==HcalTopologyMode::
H2HE)?(22):(21)),
143 firstHEQuadPhiRing_(999), firstHFQuadPhiRing_(40),
144 firstHETripleDepthRing_((mode==HcalTopologyMode::
H2 || mode==HcalTopologyMode::
H2HE)?(24):(27)),
145 singlePhiBins_(72), doublePhiBins_(36),
146 maxDepthHB_(maxDepthHB), maxDepthHE_(maxDepthHE), maxDepthHF_(2),
147 etaHE2HF_(30), etaHF2HE_(29),
148 HBSize_(kHBSizePreLS1),
149 HESize_(kHESizePreLS1),
152 HTSize_(kHTSizePreLS1),
153 numberOfShapes_(( mode==HcalTopologyMode::
SLHC ) ? 500 : 87 ) {
163 HESize_= maxDepthHE*(29-16+1)*IPHI_MAX*2;
178 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";
203 if (
id.iphi()<1 ||
id.iphi()>
IPHI_MAX ||
id.ieta()==0)
return false;
204 if (
id.
depth() != 0)
return false;
207 (
id.ietaAbs()>32))
return false;
209 if (
id.ietaAbs()>ietaMax && ((
id.iphi()%4)!=1))
return false;
212 if (
id.ietaAbs()<30 ||
id.ietaAbs()>41)
return false;
213 if (
id.ietaAbs()>29 && ((
id.iphi()%2)==0))
return false;
214 if (
id.ietaAbs()>39 && ((
id.iphi()%4)!=3))
return false;
222 switch (
id.subdet()) {
255 std::vector<DetId> vNeighborsDetId;
258 if (neighbors[
i].oldFormat()) neighbors[
i].changeForm();
259 vNeighborsDetId.push_back(
DetId(neighbors[
i].rawId()));
261 return vNeighborsDetId;
265 std::vector<DetId> vNeighborsDetId;
268 if (neighbors[
i].oldFormat()) neighbors[
i].changeForm();
269 vNeighborsDetId.push_back(
DetId(neighbors[
i].rawId()));
271 return vNeighborsDetId;
275 std::vector<DetId> vNeighborsDetId;
279 vNeighborsDetId.push_back(
DetId(neighbor.
rawId()));
281 return vNeighborsDetId;
285 std::vector<DetId> vNeighborsDetId;
289 vNeighborsDetId.push_back(
DetId(neighbor.
rawId()));
291 return vNeighborsDetId;
296 std::vector<DetId> vNeighborsDetId;
299 vNeighborsDetId.push_back(neighbor);
301 return vNeighborsDetId;
306 std::vector<DetId> vNeighborsDetId;
309 vNeighborsDetId.push_back(neighbor);
311 return vNeighborsDetId;
331 int depth_l=
std::min(depth1,depth2);
332 int depth_h=
std::max(depth1,depth2);
335 for (
int ieta=ieta_l; ieta<=ieta_h; ieta++)
336 for (
int iphi=iphi_l; iphi<=iphi_h; iphi++)
375 const int ie (
id.ietaAbs());
376 const int ip (
id.iphi());
379 return ( ( ip >= 1 ) &&
386 ( ( ( ie == 15 ) || ( ie == 16 ) ) &&
406 ( ip%2 == 1 ) ) ) ) ||
417 ( ip%4 == 3 ) ) ) ) ) ) ;
424 int aieta=
id.ietaAbs();
425 int depth=
id.depth();
427 if ((ieta==0 || iphi<=0 || iphi>
IPHI_MAX) || aieta>
maxEta_) ok =
false;
435 if (aieta>
lastHBRing() || depth>2 || (aieta<=14 && depth>1)) ok=
false;
449 if (depth < 1) ok =
false;
466 if (aieta>
lastHORing() || iphi>IPHI_MAX || depth!=4) ok=
false;
483 switch (
id.subdet()) {
487 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+1,
id.
depth());
492 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+4,
id.
depth());
495 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+2,
id.
depth());
498 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+1,
id.
depth());
504 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+4,
id.
depth());
507 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()+2,
id.
depth());
509 if (!
validRaw(neighbor)) ok =
false;
521 switch (
id.subdet()) {
525 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-1,
id.
depth());
530 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-4,
id.
depth());
533 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-2,
id.
depth());
536 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-1,
id.
depth());
542 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-4,
id.
depth());
545 else neighbor=
HcalDetId(
id.subdet(),
id.ieta(),
id.iphi()-2,
id.
depth());
547 if (!
validRaw(neighbor)) ok =
false;
568 int aieta=
id.ietaAbs();
573 neighbors[0]=
HcalDetId(
id.subdet(),(aieta+1)*
id.
zside(),((
id.iphi()==1)?(71):(
id.iphi()-2)),
id.
depth());
575 neighbors[0]=
HcalDetId(
id.subdet(),(aieta+1)*
id.
zside(),((
id.iphi()==1)?(71):(
id.iphi()-2)),
id.
depth());
583 if (!
valid(neighbors[0])) n=0;
590 int aieta=
id.ietaAbs();
606 }
else if (aieta==1) {
615 if (!
valid(neighbors[0]) && n==2) {
616 if (!
valid(neighbors[1])) n=0;
619 neighbors[0]=neighbors[1];
622 if (n==2 && !
valid(neighbors[1])) n=1;
623 if (n==1 && !
valid(neighbors[0])) n=0;
630 int & nDepthBins,
int & startingBin)
const {
662 }
else if (etaRing==17) {
680 std::cerr <<
"Bad HCAL subdetector " << subdet << std::endl;
687 int ieta = detId.
ieta();
690 int nDepthBins, startingBin;
695 if (depth > nDepthBins) {
708 (ieta > 0) ? ++ieta : --ieta;
713 (ieta > 0) ? --ieta : ++ieta;
726 int ieta = detId.
ieta();
729 int nDepthBins, startingBin;
745 (ieta > 0) ? --ieta : ++ieta;
746 }
else if (depth <= 0) {
751 ieta = (ieta > 0) ? etaRing : -etaRing;
777 static const double twopi =
M_PI+
M_PI;
817 static const double twopi =
M_PI+
M_PI;
833 if (phi<0.0) phi += twopi;
834 if (phi>twopi) phi -= twopi;
835 int phibin(1),
unit(1);
848 if (unit == 2) iphi = (phibin-1)*2+1;
849 else if (unit == 4) iphi = (phibin-1)*4+3;
858 throw cms::Exception(
"HcalTopology") <<
"No depth segmentation found for ring" <<
ring;
862 readoutDepths = pos->second;
870 std::vector<int> readoutDepths;
872 int d1 = std::lower_bound(readoutDepths.begin(), readoutDepths.end(),
depth) - readoutDepths.begin();
873 int d2 = std::upper_bound(readoutDepths.begin(), readoutDepths.end(),
depth) - readoutDepths.begin();
874 return std::pair<int, int>(d1, d2);
894 int ieta = (keta > 0) ? keta : -keta;
903 if ((ietal < (
int)(
etaTable.size())) && (ieta > 0))
904 return std::pair<double,double>(
etaTable[ieta-1],etaTable[ietal]);
906 return std::pair<double,double>(0,0);
913 const int ip (hid.
iphi() ) ;
914 const int ie (hid.
ietaAbs() ) ;
916 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
918 ( ip - 1 )*18 +
dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*
kHBhalf :
920 2*
kHBhalf + ( ip - 1 )*8 + ( ip/2 )*20 +
921 ( ( ie==16 || ie==17 ) ? ie - 16 :
922 ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) +
dp - 1 :
923 ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) +
dp - 1 :
924 ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) +
dp - 1 :
925 26 + 2*( ie - 29 ) +
dp - 1 ) ) ) ) + zn*
kHEhalf :
930 ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
931 2*( ie - 29 ) + (
dp - 1 ) + zn*
kHFhalf : 0xFFFFFFFFu ) ) ) ) ;
938 const int ip (hid.
iphi() ) ;
939 const int ie (hid.
ietaAbs() ) ;
941 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
942 unsigned int retval = 0xFFFFFFFFu;
944 retval=( ip - 1 )*18 +
dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*
kHBhalf;
955 const int ip (hid.
iphi() ) ;
956 const int ie (hid.
ietaAbs() ) ;
958 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
959 unsigned int retval = 0xFFFFFFFFu;
961 retval=( ip - 1 )*8 + ( ip/2 )*20 +
962 ( ( ie==16 || ie==17 ) ? ie - 16 :
963 ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) +
dp - 1 :
964 ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) +
dp - 1 :
965 ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) +
dp - 1 :
966 26 + 2*( ie - 29 ) +
dp - 1 ) ) ) ) + zn*
kHEhalf;
977 const int ip (hid.
iphi() ) ;
978 const int ie (hid.
ietaAbs() ) ;
979 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
981 unsigned int retval = 0xFFFFFFFFu;
983 retval=( ip - 1 )*15 + ( ie - 1 ) + zn*
kHOhalf;
993 const int ip (hid.
iphi() ) ;
994 const int ie (hid.
ietaAbs() ) ;
996 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
998 unsigned int retval = 0xFFFFFFFFu;
1000 retval = ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
1001 2*( ie - 29 ) + (
dp - 1 ) + zn*
kHFhalf;
1003 retval=
dp-1+2*(ip-1);
1013 unsigned int ietaAbs = tid.
ietaAbs();
1014 unsigned int iphi = tid.
iphi();
1015 unsigned int ivers = tid.
version();
1019 if ((iphi-1)%4==0) index = (iphi-1)*32 + (ietaAbs-1) - (12*((iphi-1)/4));
1020 else index = (iphi-1)*28 + (ietaAbs-1) + (4*(((iphi-1)/4)+1));
1021 if (zside == -1) index +=
kHThalf;
1025 index += (36 * (ietaAbs - 30) + ((iphi - 1)/2));
1034 int ieta = tid.
ieta();
1035 int iphi = tid.
iphi();
1037 unsigned int index=0xFFFFFFFFu;
1047 index = ((iphi+1)/4-1) + 18*channel + 27*(ieta+1);
1052 if (channel>2) channel-=1;
1053 index = ((iphi+1)/4-1) + 18*channel + 54*(ieta+1) + 108;
1057 if (channel==8) channel = 2;
1059 index = (iphi-1)/18 + 4*channel + 6*(ieta+1) + 324;
1064 index = (ieta+2) + 420;
1068 if (ieta<0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 348;
1069 else if (ieta>0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 6 + 348;
1070 else index = ((iphi+1)/6-1) + 36*channel + 6*(ieta+2) + 348;
1081 if (
abs(ieta)==4) index = ((iphi-1)%36) + (((zside+1)*36)/2) + 72 + 425;
1082 else index = (iphi-1) + (36*(zside+1)*2) + 425;
1090 unsigned int retval(0);
1120 << std::hex << retval <<
std::dec << std::endl;
1131 int in ( denseid ) ;
1138 iz = ( in<
kHFhalf ? 1 : -1 ) ;
1142 ip += 1 + ( in>21 ? 2 : 0 ) ;
1143 if( 3 == ip%4 ) in -= 22 ;
1149 iz = ( in<
kHOhalf ? 1 : -1 ) ;
1153 ie = 1 + ( in - 15*( ip - 1 ) ) ;
1154 }
else if ( in > 2*
kHBhalf - 1 ) {
1157 iz = ( in<
kHEhalf ? 1 : -1 ) ;
1162 if( 0 == ip%2 ) in %= 28 ;
1163 ie = 15 + ( in<2 ? 1 + in : 2 +
1164 ( in<20 ? 1 + ( in - 2 )/2 : 9 +
1165 ( in<26 ? 1 + ( in - 20 )/3 : 3 ) ) ) ;
1168 ( in<20 ? 1 + ( in - 2 )%2 :
1169 ( in<26 ? 1 + ( in - 20 )%3 :
1170 ( 1 + ( in - 26 )%2 ) ) ) ) ) ;
1172 iz = ( in<
kHBhalf ? 1 : -1 ) ;
1187 if (denseid <
ncells()) {
1195 if (ie > 12) {ie = 54 -ie; iz = -1;}
1196 else {ie += 29; iz = 1;}
1203 if (ie > 14) {ie = 30 -ie; iz = -1;}
1204 else {ie += 1; iz = 1;}
1205 }
else if (denseid >= (
HBSize_)) {
1228 <<
" : " << hid.
rawId() <<
std::dec <<
" | " << hid << std::endl;
std::vector< int > unitPhiHF
int zside() const
get the z-side of the tower (1/-1)
int decIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
unsigned int numberOfShapes_
unsigned int detId2denseIdPreLS1(const DetId &id) const
virtual unsigned int detId2denseId(const DetId &id) const
return a linear packed id
int getDepthEta16(int i) 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
bool neighbor(int endcap, int sector, int SectIndex, int id, int sub, int station)
std::vector< int > unitPhi
CalibDetType calibFlavor() const
get the flavor of this calibration detid
virtual std::vector< DetId > down(const DetId &id) const
int zside() const
get the z-side of the cell (1/-1)
bool validDetId(HcalSubdetector subdet, int ieta, int iphi, int depth) const
virtual std::vector< DetId > south(const DetId &id) 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
HcalTopology(const HcalDDDRecConstants *hcons)
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
virtual int topoVersion() const
return a version which identifies the given topology
int getNoff(const int i) const
int getTriggerMode() const
uint32_t rawId() const
get the raw id
int getMaxDepth(const int type) const
bool isExcluded(const HcalDetId &id) const
int depth() const
get the tower depth
bool incIPhi(const HcalDetId &id, HcalDetId &neighbor) const
bool validRaw(const HcalDetId &id) const
int decAIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
int maxDepth(HcalSubdetector subdet) const
HcalTopologyMode::Mode mode_
int etaRing(HcalSubdetector subdet, double eta) const
eta and phi index from eta, phi values
void setDepthSegmentation(unsigned ring, const std::vector< int > &readoutDepths)
int firstHETripleDepthRing() const
int ieta() const
get the cell ieta
Abs< T >::type abs(const T &t)
virtual std::vector< DetId > west(const DetId &id) const
void depthBinInformation(HcalSubdetector subdet, int etaRing, int &nDepthBins, int &startingBin) const
finds the number of depth bins and which is the number to start with
virtual DetId denseId2detId(unsigned int) const
return a linear packed id
std::vector< double > etaTableHF
int firstHEDoublePhiRing() const
SegmentationMap depthSegmentation_
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
std::pair< int, int > segmentBoundaries(unsigned ring, unsigned depth) const
int zside() const
get the sign of ieta (+/-1)
std::vector< double > phioff
const std::vector< double > & getPhiTable() const
void getDepthSegmentation(unsigned ring, std::vector< int > &readoutDepths) const
virtual std::vector< DetId > north(const DetId &id) const
int version() const
get the version code for the trigger tower
virtual bool valid(const DetId &id) const
const std::vector< double > & getEtaTable() const
std::pair< int, int > getEtaRange(const int i) const
int firstHFQuadPhiRing() const
Geom::Phi< T > phi() const
virtual std::vector< DetId > up(const DetId &id) const
const std::vector< int > & getDepth(const unsigned int i) const
std::vector< double > dPhiTable
int cboxChannel() const
get the calibration box channel (if relevant)
std::pair< double, double > etaRange(HcalSubdetector subdet, int ieta) const
TString units(TString variable, Char_t axis)
const std::vector< double > & getPhiTableHF() const
int firstHETripleDepthRing_
unsigned int detId2denseIdHO(const DetId &id) const
return a linear packed id from HO
std::vector< HcalDetId > exclusionList_
unsigned int detId2denseIdHE(const DetId &id) const
return a linear packed id from HE
int firstHEQuadPhiRing() const
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)
virtual std::vector< DetId > east(const DetId &id) const
volatile std::atomic< bool > shutdown_flag false
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
virtual unsigned int ncells() const
return a count of valid cells (for dense indexing use)
double etaMax(HcalSubdetector subdet) const
int firstHEDoublePhiRing_
const HcalDDDRecConstants * hcons_
static const int IPHI_MAX
std::vector< HcalEtaBin > getEtaBins(const int itype) const
bool validHT(const HcalTrigTowerDetId &id) const