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),
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.push_back(
DetId(neighbors[
i].rawId()));
285 return vNeighborsDetId;
289 std::vector<DetId> vNeighborsDetId;
292 if (neighbors[
i].oldFormat()) neighbors[
i].changeForm();
293 vNeighborsDetId.push_back(
DetId(neighbors[
i].rawId()));
295 return vNeighborsDetId;
299 std::vector<DetId> vNeighborsDetId;
303 vNeighborsDetId.push_back(
DetId(neighbor.
rawId()));
305 return vNeighborsDetId;
309 std::vector<DetId> vNeighborsDetId;
313 vNeighborsDetId.push_back(
DetId(neighbor.
rawId()));
315 return vNeighborsDetId;
320 std::vector<DetId> vNeighborsDetId;
323 vNeighborsDetId.push_back(neighbor);
325 return vNeighborsDetId;
330 std::vector<DetId> vNeighborsDetId;
333 vNeighborsDetId.push_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)) ||
477 if (depth < 1) 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 nDepthBins, startingBin;
724 if (depth > nDepthBins) {
737 (ieta > 0) ? ++ieta : --ieta;
742 (ieta > 0) ? --ieta : ++ieta;
755 int ieta = detId.
ieta();
758 int nDepthBins, startingBin;
774 (ieta > 0) ? --ieta : ++ieta;
775 }
else if (depth <= 0) {
780 ieta = (ieta > 0) ? etaRing : -etaRing;
811 static const double twopi =
M_PI+
M_PI;
851 static const double twopi =
M_PI+
M_PI;
867 if (phi<0.0) phi += twopi;
868 if (phi>twopi) phi -= twopi;
869 int phibin(1),
unit(1);
882 if (unit == 2) iphi = (phibin-1)*2+1;
883 else if (unit == 4) iphi = (phibin-1)*4+3;
888 std::vector<int> & readoutDepths,
889 const bool one)
const {
892 SegmentationMap::const_iterator
pos;
896 throw cms::Exception(
"HcalTopology") <<
"No depth segmentation found for ring" <<
ring;
901 throw cms::Exception(
"HcalTopology") <<
"No depth segmentation found for ring" <<
ring;
906 readoutDepths = pos->second;
910 const std::vector<int> & readoutDepths,
920 const unsigned depth,
921 const bool one)
const {
922 std::vector<int> readoutDepths;
924 int d1 = std::lower_bound(readoutDepths.begin(), readoutDepths.end(),
depth) - readoutDepths.begin();
925 int d2 = std::upper_bound(readoutDepths.begin(), readoutDepths.end(),
depth) - readoutDepths.begin();
926 return std::pair<int, int>(d1, d2);
950 int ieta = (keta > 0) ? keta : -keta;
959 if ((ietal < (
int)(
etaTable.size())) && (ieta > 0))
960 return std::pair<double,double>(
etaTable[ieta-1],etaTable[ietal]);
962 return std::pair<double,double>(0,0);
969 const int ip (hid.
iphi() ) ;
970 const int ie (hid.
ietaAbs() ) ;
972 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
974 ( ip - 1 )*18 +
dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*
kHBhalf :
976 2*
kHBhalf + ( ip - 1 )*8 + ( ip/2 )*20 +
977 ( ( ie==16 || ie==17 ) ? ie - 16 :
978 ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) +
dp - 1 :
979 ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) +
dp - 1 :
980 ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) +
dp - 1 :
981 26 + 2*( ie - 29 ) +
dp - 1 ) ) ) ) + zn*
kHEhalf :
986 ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
987 2*( ie - 29 ) + (
dp - 1 ) + zn*
kHFhalf : 0xFFFFFFFFu ) ) ) ) ;
994 const int ip (hid.
iphi() ) ;
995 const int ie (hid.
ietaAbs() ) ;
997 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
998 unsigned int retval = 0xFFFFFFFFu;
1000 retval=( ip - 1 )*18 +
dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*
kHBhalf;
1011 const int ip (hid.
iphi() ) ;
1012 const int ie (hid.
ietaAbs() ) ;
1014 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1015 unsigned int retval = 0xFFFFFFFFu;
1017 retval=( ip - 1 )*8 + ( ip/2 )*20 +
1018 ( ( ie==16 || ie==17 ) ? ie - 16 :
1019 ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) +
dp - 1 :
1020 ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) +
dp - 1 :
1021 ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) +
dp - 1 :
1022 26 + 2*( ie - 29 ) +
dp - 1 ) ) ) ) + zn*
kHEhalf;
1033 const int ip (hid.
iphi() ) ;
1034 const int ie (hid.
ietaAbs() ) ;
1035 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1037 unsigned int retval = 0xFFFFFFFFu;
1039 retval=( ip - 1 )*15 + ( ie - 1 ) + zn*
kHOhalf;
1049 const int ip (hid.
iphi() ) ;
1050 const int ie (hid.
ietaAbs() ) ;
1052 const int zn (hid.
zside() < 0 ? 1 : 0 ) ;
1054 unsigned int retval = 0xFFFFFFFFu;
1056 retval = ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
1057 2*( ie - 29 ) + (
dp - 1 ) + zn*
kHFhalf;
1059 retval=
dp-1+2*(ip-1);
1069 unsigned int ietaAbs = tid.
ietaAbs();
1070 unsigned int iphi = tid.
iphi();
1071 unsigned int ivers = tid.
version();
1075 if ((iphi-1)%4==0) index = (iphi-1)*32 + (ietaAbs-1) - (12*((iphi-1)/4));
1076 else index = (iphi-1)*28 + (ietaAbs-1) + (4*(((iphi-1)/4)+1));
1077 if (zside == -1) index +=
kHThalf;
1081 index += (36 * (ietaAbs - 30) + ((iphi - 1)/2));
1090 int ieta = tid.
ieta();
1091 int iphi = tid.
iphi();
1093 unsigned int index=0xFFFFFFFFu;
1103 index = ((iphi+1)/4-1) + 18*channel + 27*(ieta+1);
1108 if (channel>2) channel-=1;
1109 index = ((iphi+1)/4-1) + 18*channel + 54*(ieta+1) + 108;
1113 if (channel==8) channel = 2;
1115 index = (iphi-1)/18 + 4*channel + 6*(ieta+1) + 324;
1120 index = (ieta+2) + 420;
1124 if (ieta<0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 348;
1125 else if (ieta>0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 6 + 348;
1126 else index = ((iphi+1)/6-1) + 36*channel + 6*(ieta+2) + 348;
1137 if (
abs(ieta)==4) index = ((iphi-1)%36) + (((zside+1)*36)/2) + 72 + 425;
1138 else index = (iphi-1) + (36*(zside+1)*2) + 425;
1146 unsigned int retval(0);
1176 << std::hex << retval <<
std::dec << std::endl;
1187 int in ( denseid ) ;
1194 iz = ( in<
kHFhalf ? 1 : -1 ) ;
1198 ip += 1 + ( in>21 ? 2 : 0 ) ;
1199 if( 3 == ip%4 ) in -= 22 ;
1205 iz = ( in<
kHOhalf ? 1 : -1 ) ;
1209 ie = 1 + ( in - 15*( ip - 1 ) ) ;
1210 }
else if ( in > 2*
kHBhalf - 1 ) {
1213 iz = ( in<
kHEhalf ? 1 : -1 ) ;
1218 if( 0 == ip%2 ) in %= 28 ;
1219 ie = 15 + ( in<2 ? 1 + in : 2 +
1220 ( in<20 ? 1 + ( in - 2 )/2 : 9 +
1221 ( in<26 ? 1 + ( in - 20 )/3 : 3 ) ) ) ;
1224 ( in<20 ? 1 + ( in - 2 )%2 :
1225 ( in<26 ? 1 + ( in - 20 )%3 :
1226 ( 1 + ( in - 26 )%2 ) ) ) ) ) ;
1228 iz = ( in<
kHBhalf ? 1 : -1 ) ;
1243 if (denseid <
ncells()) {
1251 if (ie > 12) {ie = 54 -ie; iz = -1;}
1252 else {ie += 29; iz = 1;}
1259 if (ie > 14) {ie = 30 -ie; iz = -1;}
1260 else {ie += 1; iz = 1;}
1261 }
else if (denseid >= (
HBSize_)) {
1284 <<
" : " << hid.
rawId() <<
std::dec <<
" | " << hid << std::endl;
int getNPhi(const int type) 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 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
std::vector< double > dPhiTableHF
std::vector< int > getDepth(const int det, const int phi, const int zside, const unsigned int eta) const
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
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
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
bool neighbor(int endcap, int sector, int SectIndex, int id, int sub, int station)
std::vector< HcalDDDRecConstants::HcalEtaBin > etaBinsHE_
int ieta() const
get the rbx name (if relevant)
const std::vector< double > & getPhiOffs() const
HcalTopologyMode::Mode mode() 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
U second(std::pair< T, U > const &p)
int getMaxDepth(const int type) const
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
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
int getDepthEta16(const int det, const int iphi, const int zside) const
bool validRaw(const HcalDetId &id) const
int decAIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
int getMinDepth(const int itype, const int ieta, const int iphi, const int zside) const
int maxDepth(HcalSubdetector subdet) 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
Abs< T >::type abs(const T &t)
virtual std::vector< DetId > west(const DetId &id) const
virtual DetId denseId2detId(unsigned int) const
return a linear packed id
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
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
virtual std::vector< DetId > up(const DetId &id) 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
bool isPlan1ToBeMergedId(const HcalDetId &id) const
int firstHEQuadPhiRing() const
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)
virtual std::vector< DetId > east(const DetId &id) const
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
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