Skip to content

Commit

Permalink
Merge pull request #17525 from bsunanda/Run2-hcx106
Browse files Browse the repository at this point in the history
bsunanda:Run2-hcx106 Correct list of valid DetId's and add possibility of getting position of merged DetId
  • Loading branch information
davidlange6 committed Feb 16, 2017
2 parents 33cc6f9 + 9743bf8 commit a85956d
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 39 deletions.
6 changes: 5 additions & 1 deletion Geometry/CaloTopology/interface/HcalTopology.h
Expand Up @@ -156,8 +156,12 @@ class HcalTopology : public CaloSubdetectorTopology {

const HcalDDDRecConstants* dddConstants () const {return hcons_;}
bool withSpecialRBXHBHE() const {return hcons_->withSpecialRBXHBHE();}
HcalDetId mergedDepthDetId(HcalDetId& id) const {return hcons_->mergedDepthDetId(id); }
HcalDetId mergedDepthDetId(const HcalDetId& id) const {return hcons_->mergedDepthDetId(id); }
bool getMergePositionFlag() const {return mergePosition_;}
void unmergeDepthDetId(const HcalDetId& id,
std::vector<HcalDetId>& ids) const {
hcons_->unmergeDepthDetId(id, ids);
}

private:
/** Get the neighbors of the given cell with higher absolute ieta */
Expand Down
2 changes: 1 addition & 1 deletion Geometry/CaloTopology/src/HcalTopology.cc
Expand Up @@ -466,7 +466,7 @@ bool HcalTopology::validRaw(const HcalDetId& id) const {
break;
}
}
}
}
} else {
if (depth>hcons_->getMaxDepth(1,aieta,iphi,zside) ||
aieta<firstHERing() || aieta>lastHERing() ||
Expand Down
7 changes: 5 additions & 2 deletions Geometry/HcalCommonData/interface/HcalDDDRecConstants.h
Expand Up @@ -104,15 +104,17 @@ class HcalDDDRecConstants {
unsigned int numberOfCells(HcalSubdetector) const;
unsigned int nCells(HcalSubdetector) const;
unsigned int nCells() const;
HcalDetId mergedDepthDetId(HcalDetId& id) const;
HcalDetId mergedDepthDetId(const HcalDetId& id) const;
void unmergeDepthDetId(const HcalDetId& id,
std::vector<HcalDetId>& ids) const;
void specialRBXHBHE(const std::vector<HcalDetId>&,
std::vector<HcalDetId> &) const;
bool withSpecialRBXHBHE() const {return (hcons.ldMap()->getSubdet() != 0);}

private:
void getOneEtaBin(int subdet, int ieta, int zside,
std::vector<std::pair<int,double>>& phis,
std::map<int,int>& layers,
std::map<int,int>& layers, bool planOne,
std::vector<HcalDDDRecConstants::HcalEtaBin>& bins) const;
void initialize(void);
unsigned int layerGroupSize(int eta) const;
Expand All @@ -133,6 +135,7 @@ class HcalDDDRecConstants {
int nModule[2], nHalves[2]; // Modules, Halves for HB/HE
std::pair<int,int> depthMaxDf_, depthMaxSp_; // (subdet,maximum depth) default,special
std::map<HcalDetId,HcalDetId> detIdSp_; // Map of Id's for special RBX
std::map<HcalDetId,std::vector<HcalDetId>> detIdSpR_; // Reverse map for RBX
};

#endif
2 changes: 1 addition & 1 deletion Geometry/HcalCommonData/interface/HcalDDDSimConstants.h
Expand Up @@ -40,7 +40,7 @@ class HcalDDDSimConstants {
const int zside) const;
int getDepthEta16M(const int det) const;
int getDepthEta29(const int phi, int zside, int i) const;
int getDepthEta29M(const int i) const;
int getDepthEta29M(const int i, const bool planOne) const;
std::pair<int,double> getDetEta(const double eta, const int depth);
int getEta(const int det, const int lay, const double hetaR);
std::pair<int,int> getEtaDepth(const int det, int etaR, int phi,
Expand Down
49 changes: 41 additions & 8 deletions Geometry/HcalCommonData/src/HcalDDDRecConstants.cc
Expand Up @@ -85,7 +85,7 @@ HcalDDDRecConstants::getEtaBins(const int itype) const {
} else {
phiUse.insert(phiUse.end(),phis.begin(),phis.end());
}
getOneEtaBin(subdet,ieta,zside,phiUse,layers,bins);
getOneEtaBin(subdet,ieta,zside,phiUse,layers,false,bins);
}
}
if (subdetSp == subdet) {
Expand All @@ -104,7 +104,7 @@ HcalDDDRecConstants::getEtaBins(const int itype) const {
}
if (phiUse.size() > 0) {
hcons.ldMap()->getLayerDepth(subdet,ieta,phiUse[0].first,zside,layers);
getOneEtaBin(subdet,ieta,zside,phiUse,layers,bins);
getOneEtaBin(subdet,ieta,zside,phiUse,layers,true,bins);
}
}
}
Expand Down Expand Up @@ -298,7 +298,7 @@ int HcalDDDRecConstants::getMaxDepth (const int itype, const int ieta,
if (layerGroupSize(ieta-1) < lymax) lymax = layerGroupSize(ieta-1);
lmax = (int)(layerGroup(ieta-1, lymax-1));
if (type == 0 && ieta == iEtaMax[type]) lmax = hcons.getDepthEta16M(1);
if (type == 1 && ieta >= hpar->noff[1]) lmax = hcons.getDepthEta29M(0);
if (type == 1 && ieta >= hpar->noff[1]) lmax = hcons.getDepthEta29M(0,false);
}
}
return lmax;
Expand All @@ -320,7 +320,6 @@ int HcalDDDRecConstants::getMinDepth (const int itype, const int ieta,
lmin = hcons.getDepthEta16M(2);
else
lmin = (int)(layerGroup(ieta-1, 0));

}
}
}
Expand Down Expand Up @@ -546,13 +545,28 @@ unsigned int HcalDDDRecConstants::nCells() const {
return (nCells(HcalBarrel)+nCells(HcalEndcap)+nCells(HcalOuter)+nCells(HcalForward));
}

HcalDetId HcalDDDRecConstants::mergedDepthDetId(HcalDetId& id) const {
HcalDetId HcalDDDRecConstants::mergedDepthDetId(const HcalDetId& id) const {

std::map<HcalDetId,HcalDetId>::const_iterator itr = detIdSp_.find(id);
if (itr == detIdSp_.end()) return id;
else return itr->second;
}

void HcalDDDRecConstants::unmergeDepthDetId(const HcalDetId& id,
std::vector<HcalDetId>& ids) const {

ids.clear();
std::map<HcalDetId,std::vector<HcalDetId>>::const_iterator itr = detIdSpR_.find(id);
if (itr == detIdSpR_.end()) {
ids.push_back(id);
} else {
for (unsigned k=0; k<itr->second.size(); ++k) {
HcalDetId hid(id.subdet(),id.ieta(),id.iphi(),(itr->second)[k].depth());
ids.push_back(hid);
}
}
}

void HcalDDDRecConstants::specialRBXHBHE(const std::vector<HcalDetId>& idsOld,
std::vector<HcalDetId>& idsNew) const {
for (unsigned int k=0; k<idsOld.size(); ++k) {
Expand All @@ -565,7 +579,7 @@ void HcalDDDRecConstants::specialRBXHBHE(const std::vector<HcalDetId>& idsOld,

void HcalDDDRecConstants::getOneEtaBin(int subdet, int ieta, int zside,
std::vector<std::pair<int,double> >& phis,
std::map<int,int>& layers,
std::map<int,int>& layers, bool planOne,
std::vector<HcalDDDRecConstants::HcalEtaBin>& bins) const {

unsigned int lymax = (subdet == 1) ? 17 : 19;
Expand Down Expand Up @@ -616,7 +630,7 @@ void HcalDDDRecConstants::getOneEtaBin(int subdet, int ieta, int zside,
if (subdet == 1 && ieta == iEtaMax[subdet-1]
&& dep > hcons.getDepthEta16M(1)) break;
if (subdet == 2 && ieta == hpar->noff[1] &&
dep > hcons.getDepthEta29M(0)) {
dep > hcons.getDepthEta29M(0,planOne)) {
lmax = lymx0;
break;
}
Expand Down Expand Up @@ -823,6 +837,7 @@ void HcalDDDRecConstants::initialize(void) {
//Map of special DetId's
std::vector<int> phis;
int subdet0 = hcons.ldMap()->validDet(phis);
detIdSp_.clear(); detIdSpR_.clear();
if ((subdet0 == static_cast<int>(HcalBarrel)) ||
(subdet0 == static_cast<int>(HcalEndcap))) {
int phi = (phis[0] > 0) ? phis[0] : -phis[0];
Expand Down Expand Up @@ -874,9 +889,16 @@ void HcalDDDRecConstants::initialize(void) {
for (unsigned int k=0; k<phis.size(); ++k) {
zside = (phis[k] > 0) ? 1 : -1;
phi = (phis[k] > 0) ? phis[k] : -phis[k];
if (subdet == 2 && eta == hpar->noff[1] &&
ndepth > hcons.getDepthEta29M(0,true)) break;
HcalDetId newId(subdet,zside*eta,phi,ndepth);
HcalDetId oldId(subdet,zside*eta,phi,odepth);
detIdSp_[newId] = oldId;
std::vector<HcalDetId> ids;
std::map<HcalDetId,std::vector<HcalDetId>>::iterator itr = detIdSpR_.find(oldId);
if (itr != detIdSpR_.end()) ids = itr->second;
ids.push_back(newId);
detIdSpR_[oldId] = ids;
}
}
}
Expand All @@ -886,9 +908,20 @@ void HcalDDDRecConstants::initialize(void) {
<< detIdSp_.size() << " entries" << std::endl;
int l(0);
for (std::map<HcalDetId,HcalDetId>::const_iterator itr=detIdSp_.begin();
itr != detIdSp_.end(); ++itr,++l)
itr != detIdSp_.end(); ++itr,++l) {
std::cout << "[" << l << "] Special " << itr->first << " Standard "
<< itr->second << std::endl;
}
std::cout << "Reverse Map for mapping old to new IDs with "
<< detIdSpR_.size() << " entries" << std::endl;
l = 0;
for (std::map<HcalDetId,std::vector<HcalDetId> >::const_iterator itr=detIdSpR_.begin();
itr != detIdSpR_.end(); ++itr,++l) {
std::cout << "[" << l << "] Standard " << itr->first << " Special";
for (unsigned int k=0; k < itr->second.size(); ++k)
std::cout << " " << (itr->second)[k];
std::cout << std::endl;
}
#endif
}

Expand Down
24 changes: 11 additions & 13 deletions Geometry/HcalCommonData/src/HcalDDDSimConstants.cc
Expand Up @@ -188,9 +188,10 @@ int HcalDDDSimConstants::getDepthEta29(const int phi, const int zside,
return depth;
}

int HcalDDDSimConstants::getDepthEta29M(const int i) const {
int HcalDDDSimConstants::getDepthEta29M(const int i,
const bool planOne) const {
int depth = (i == 1) ? depthEta29[1] : depthEta29[0];
if (i == 0) {
if (i == 0 && planOne) {
std::vector<int> phis;
int detsp = ldmap_.validDet(phis);
if (detsp == 2) {
Expand Down Expand Up @@ -371,11 +372,12 @@ int HcalDDDSimConstants::getMaxDepth(const int det, const int eta,

int dmax(-1);
if (partialDetOnly) {
if (ldmap_.isValid(det,phi,zside))
dmax = ldmap_.getDepthMax(det,eta,phi,zside);
if (ldmap_.isValid(det,phi,zside)) {
dmax = ldmap_.getDepths(eta).second;
}
} else if (det == 1 || det == 2) {
if (ldmap_.isValid(det,phi,zside))
dmax = ldmap_.getDepthMax(det,eta,phi,zside);
dmax = ldmap_.getDepths(eta).second;
else if (det == 2)
dmax = layerGroup(eta-1,maxLayer_);
else if (eta == hpar->etaMax[0])
Expand All @@ -399,20 +401,16 @@ int HcalDDDSimConstants::getMinDepth(const int det, const int eta,
int lmin(-1);
if (partialDetOnly) {
if (ldmap_.isValid(det,phi,zside)) {
if (layerGroupSize(eta-1) > 0) {
unsigned int type = (det == 1) ? 0 : 1;
if (type == 1 && eta == hpar->etaMin[1])
lmin = getDepthEta16(det, phi, zside);
else
lmin = (int)(layerGroup(eta-1, 0));
}
lmin = ldmap_.getDepths(eta).first;
}
} else if (det == 3) { // HF
lmin = 1;
} else if (det == 4) { // HO
lmin = maxDepth[3];
} else {
if (layerGroupSize(eta-1) > 0) {
if (ldmap_.isValid(det,phi,zside)) {
lmin = ldmap_.getDepths(eta).first;
} else if (layerGroupSize(eta-1) > 0) {
lmin = (int)(layerGroup(eta-1, 0));
unsigned int type = (det == 1) ? 0 : 1;
if (type == 1 && eta == hpar->etaMin[1])
Expand Down
6 changes: 5 additions & 1 deletion Geometry/HcalCommonData/src/HcalLayerDepthMap.cc
Expand Up @@ -68,6 +68,10 @@ void HcalLayerDepthMap::initialize(const int subdet, const int ietaMax,
if ((itr->second) > dmax) dmax = (itr->second);
}
}
if (subdet == 2) {
if (eta == ietaMin_) dmin = dep16C_;
else if (eta == ietaMax_) dmax = dep29C_;
}
depthsEta_[eta] = std::pair<int,int>(dmin,dmax);
}
#ifdef EDM_ML_DEBUG
Expand Down Expand Up @@ -162,7 +166,7 @@ int HcalLayerDepthMap::getDepthMax(const int subdet, const int ieta,
std::pair<int,int> HcalLayerDepthMap::getDepths(const int eta) const {

std::map<int,std::pair<int,int> >::const_iterator itr = depthsEta_.find(eta);
if (itr == depthsEta_.end()) return std::pair<int,int>(0,0);
if (itr == depthsEta_.end()) return std::pair<int,int>(-1,-1);
else return itr->second;
}

Expand Down
1 change: 1 addition & 0 deletions Geometry/HcalEventSetup/interface/HcalTopologyIdealEP.h
Expand Up @@ -39,6 +39,7 @@ class HcalTopologyIdealEP : public edm::ESProducer {
private:
// ----------member data ---------------------------
std::string m_restrictions;
bool m_mergePosition;
const edm::ParameterSet m_pSet;
};
#endif
12 changes: 8 additions & 4 deletions Geometry/HcalEventSetup/src/HcalTopologyIdealEP.cc
Expand Up @@ -39,9 +39,12 @@
//
HcalTopologyIdealEP::HcalTopologyIdealEP(const edm::ParameterSet& conf)
: m_restrictions(conf.getUntrackedParameter<std::string>("Exclude")),
m_mergePosition(conf.getUntrackedParameter<bool>("MergePosition")),
m_pSet(conf) {
#ifdef DebugLog
std::cout << "HcalTopologyIdealEP::HcalTopologyIdealEP" << std::endl;
std::cout << "HcalTopologyIdealEP::HcalTopologyIdealEP with Exclude: "
<< m_restrictions << " MergePosition: " << m_mergePosition
<< std::endl;
edm::LogInfo("HCAL") << "HcalTopologyIdealEP::HcalTopologyIdealEP";
#endif
setWhatProduced(this,
Expand All @@ -56,6 +59,7 @@ void HcalTopologyIdealEP::fillDescriptions( edm::ConfigurationDescriptions & des

edm::ParameterSetDescription desc;
desc.addUntracked<std::string>( "Exclude", "" );
desc.addUntracked<bool>("MergePosition", false);
descriptions.add( "hcalTopologyIdeal", desc );
}

Expand All @@ -76,14 +80,14 @@ HcalTopologyIdealEP::produce(const HcalRecNumberingRecord& iRecord) {

#ifdef DebugLog
std::cout << "mode = " << hdc->getTopoMode() << ", maxDepthHB = "
<< hdc->getMaxDepth(0) << ", maxDepthHE = " << hdc->getMaxDepth(1)
<< hdc->getMaxDepth(0) << ", maxDepthHE = " << hdc->getMaxDepth(1)
<< ", maxDepthHF = " << hdc->getMaxDepth(2) << std::endl;
edm::LogInfo("HCAL") << "mode = " << hdc->getTopoMode() << ", maxDepthHB = "
edm::LogInfo("HCAL") << "mode = " << hdc->getTopoMode() << ", maxDepthHB = "
<< hdc->getMaxDepth(0) << ", maxDepthHE = "
<< hdc->getMaxDepth(1) << ", maxDepthHF = "
<< hdc->getMaxDepth(2);
#endif
ReturnType myTopo(new HcalTopology(hdc));
ReturnType myTopo(new HcalTopology(hdc,m_mergePosition));

HcalTopologyRestrictionParser parser(*myTopo);
if (!m_restrictions.empty()) {
Expand Down
4 changes: 4 additions & 0 deletions Geometry/HcalTowerAlgo/interface/HcalGeometry.h
Expand Up @@ -50,6 +50,8 @@ class HcalGeometry : public CaloSubdetectorGeometry {
virtual CaloSubdetectorGeometry::DetIdSet getCells( const GlobalPoint& r,
double dR ) const ;

GlobalPoint getPosition(const DetId& id) const;
GlobalPoint getBackPosition(const DetId& id) const;

static std::string producerTag() { return "HCAL" ; }

Expand Down Expand Up @@ -123,8 +125,10 @@ class HcalGeometry : public CaloSubdetectorGeometry {
/// helper methods for getClosestCell
int etaRing(HcalSubdetector bc, double abseta) const;
int phiBin(HcalSubdetector bc, int etaring, double phi) const;
DetId correctId(const DetId& id) const ;

const HcalTopology& m_topology;
bool m_mergePosition;

mutable edm::AtomicPtrCache<std::vector<DetId>> m_hbIds ;
mutable edm::AtomicPtrCache<std::vector<DetId>> m_heIds ;
Expand Down

0 comments on commit a85956d

Please sign in to comment.