CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
HGCalTriggerTowerGeometryHelper Class Reference

#include <HGCalTriggerTowerGeometryHelper.h>

Public Member Functions

void eventSetup (const edm::EventSetup &es)
 
const std::vector< l1t::HGCalTowerCoord > & getTowerCoordinates () const
 
unsigned short getTriggerTower (const l1t::HGCalTriggerCell &) const
 
unsigned short getTriggerTower (const l1t::HGCalTriggerSums &) const
 
unsigned short getTriggerTowerFromEtaPhi (const float &eta, const float &phi) const
 
 HGCalTriggerTowerGeometryHelper (const edm::ParameterSet &conf)
 
 ~HGCalTriggerTowerGeometryHelper ()
 

Private Attributes

std::vector< double > binsEta_
 
std::vector< double > binsPhi_
 
std::unordered_map< unsigned, short > cells_to_trigger_towers_
 
double maxEta_
 
double maxPhi_
 
double minEta_
 
double minPhi_
 
unsigned int nBinsEta_
 
unsigned int nBinsPhi_
 
std::vector< l1t::HGCalTowerCoordtower_coords_
 
HGCalTriggerTools triggerTools_
 

Detailed Description

Handles the mapping between TCs and TTs. The mapping can be provided externally (via a mapping file) or can be derived on the fly based on the TC eta-phi coordinates. The bin boundaries need anyhow to be provided to establish the eta-phi coordinates of the towers (assumed as the Tower Center for the moment)

Definition at line 27 of file HGCalTriggerTowerGeometryHelper.h.

Constructor & Destructor Documentation

◆ HGCalTriggerTowerGeometryHelper()

HGCalTriggerTowerGeometryHelper::HGCalTriggerTowerGeometryHelper ( const edm::ParameterSet conf)

Definition at line 13 of file HGCalTriggerTowerGeometryHelper.cc.

14  : minEta_(conf.getParameter<double>("minEta")),
15  maxEta_(conf.getParameter<double>("maxEta")),
16  minPhi_(conf.getParameter<double>("minPhi")),
17  maxPhi_(conf.getParameter<double>("maxPhi")),
18  nBinsEta_(conf.getParameter<int>("nBinsEta")),
19  nBinsPhi_(conf.getParameter<int>("nBinsPhi")),
20  binsEta_(conf.getParameter<std::vector<double> >("binsEta")),
21  binsPhi_(conf.getParameter<std::vector<double> >("binsPhi")) {
22  if (!binsEta_.empty() && ((unsigned int)(binsEta_.size()) != nBinsEta_ + 1)) {
23  throw edm::Exception(edm::errors::Configuration, "Configuration")
24  << "HGCalTriggerTowerGeometryHelper nBinsEta for the tower map not consistent with binsEta size" << std::endl;
25  }
26 
27  if (!binsPhi_.empty() && ((unsigned int)(binsPhi_.size()) != nBinsPhi_ + 1)) {
28  throw edm::Exception(edm::errors::Configuration, "Configuration")
29  << "HGCalTriggerTowerGeometryHelper nBinsPhi for the tower map not consistent with binsPhi size" << std::endl;
30  }
31 
32  // if the bin vecctor is empty we assume the bins to be regularly spaced
33  if (binsEta_.empty()) {
34  for (unsigned int bin1 = 0; bin1 != nBinsEta_ + 1; bin1++) {
35  binsEta_.push_back(minEta_ + bin1 * ((maxEta_ - minEta_) / nBinsEta_));
36  }
37  }
38 
39  // if the bin vecctor is empty we assume the bins to be regularly spaced
40  if (binsPhi_.empty()) {
41  for (unsigned int bin2 = 0; bin2 != nBinsPhi_ + 1; bin2++) {
42  binsPhi_.push_back(minPhi_ + bin2 * ((maxPhi_ - minPhi_) / nBinsPhi_));
43  }
44  }
45 
46  for (int zside = -1; zside <= 1; zside += 2) {
47  for (unsigned int bin1 = 0; bin1 != nBinsEta_; bin1++) {
48  for (unsigned int bin2 = 0; bin2 != nBinsPhi_; bin2++) {
49  l1t::HGCalTowerID towerId(zside, bin1, bin2);
50  tower_coords_.emplace_back(towerId.rawId(),
51  zside * ((binsEta_[bin1 + 1] + binsEta_[bin1]) / 2),
52  (binsPhi_[bin2 + 1] + binsPhi_[bin2]) / 2);
53  }
54  }
55  }
56 
57  if (conf.getParameter<bool>("readMappingFile")) {
58  // We read the TC to TT mapping from file,
59  // otherwise we derive the TC to TT mapping on the fly from eta-phi coord. of the TCs
60  std::ifstream l1tTriggerTowerMappingStream(conf.getParameter<edm::FileInPath>("L1TTriggerTowerMapping").fullPath());
61  if (!l1tTriggerTowerMappingStream.is_open()) {
62  throw cms::Exception("MissingDataFile") << "Cannot open HGCalTriggerGeometry L1TTriggerTowerMapping file\n";
63  }
64 
65  unsigned trigger_cell_id = 0;
66  unsigned short iEta = 0;
67  unsigned short iPhi = 0;
68 
69  for (; l1tTriggerTowerMappingStream >> trigger_cell_id >> iEta >> iPhi;) {
70  if (iEta >= nBinsEta_ || iPhi >= nBinsPhi_) {
71  throw edm::Exception(edm::errors::Configuration, "Configuration")
72  << "HGCalTriggerTowerGeometryHelper warning inconsistent mapping TC : " << trigger_cell_id
73  << " to TT iEta: " << iEta << " iPhi: " << iPhi << " when max #bins eta: " << nBinsEta_
74  << " phi: " << nBinsPhi_ << std::endl;
75  }
76  l1t::HGCalTowerID towerId(triggerTools_.zside(DetId(trigger_cell_id)), iEta, iPhi);
77  cells_to_trigger_towers_[trigger_cell_id] = towerId.rawId();
78  }
79  l1tTriggerTowerMappingStream.close();
80  }
81 }

References binsEta_, binsPhi_, cells_to_trigger_towers_, edm::errors::Configuration, Exception, edm::FileInPath::fullPath(), edm::ParameterSet::getParameter(), L1TowerCalibrationProducer_cfi::iEta, createfilelist::int, maxEta_, maxPhi_, minEta_, minPhi_, nBinsEta_, nBinsPhi_, tower_coords_, ecaldqm::towerId(), triggerTools_, HGCalTriggerTools::zside(), and ecaldqm::zside().

◆ ~HGCalTriggerTowerGeometryHelper()

HGCalTriggerTowerGeometryHelper::~HGCalTriggerTowerGeometryHelper ( )
inline

Definition at line 31 of file HGCalTriggerTowerGeometryHelper.h.

31 {}

Member Function Documentation

◆ eventSetup()

void HGCalTriggerTowerGeometryHelper::eventSetup ( const edm::EventSetup es)
inline

◆ getTowerCoordinates()

const std::vector< l1t::HGCalTowerCoord > & HGCalTriggerTowerGeometryHelper::getTowerCoordinates ( ) const

Definition at line 83 of file HGCalTriggerTowerGeometryHelper.cc.

83  {
84  return tower_coords_;
85 }

References tower_coords_.

Referenced by HGCalTowerMap2DImpl::newTowerMaps().

◆ getTriggerTower() [1/2]

unsigned short HGCalTriggerTowerGeometryHelper::getTriggerTower ( const l1t::HGCalTriggerCell thecell) const

Definition at line 122 of file HGCalTriggerTowerGeometryHelper.cc.

122  {
123  unsigned int trigger_cell_id = thecell.detId();
124  // NOTE: if the TC is not found in the map than it is mapped via eta-phi coords.
125  // this can be considered dangerous (silent failure of the map) but it actually allows to save
126  // memory mapping explicitly only what is actually needed
127  auto tower_id_itr = cells_to_trigger_towers_.find(trigger_cell_id);
128  if (tower_id_itr != cells_to_trigger_towers_.end())
129  return tower_id_itr->second;
130 
131  return getTriggerTowerFromEtaPhi(thecell.position().eta(), thecell.position().phi());
132 }

References cells_to_trigger_towers_, l1t::HGCalTriggerCell::detId(), PV3DBase< T, PVType, FrameType >::eta(), getTriggerTowerFromEtaPhi(), PV3DBase< T, PVType, FrameType >::phi(), and l1t::HGCalTriggerCell::position().

Referenced by HGCalTowerMap2DImpl::buildTowerMap2D().

◆ getTriggerTower() [2/2]

unsigned short HGCalTriggerTowerGeometryHelper::getTriggerTower ( const l1t::HGCalTriggerSums thesum) const

◆ getTriggerTowerFromEtaPhi()

unsigned short HGCalTriggerTowerGeometryHelper::getTriggerTowerFromEtaPhi ( const float &  eta,
const float &  phi 
) const

Definition at line 87 of file HGCalTriggerTowerGeometryHelper.cc.

87  {
88  auto bin_eta_l = std::lower_bound(binsEta_.begin(), binsEta_.end(), fabs(eta));
89  unsigned int bin_eta = 0;
90  // we add a protection for TCs in Hadron part which are outside the boundaries and possible rounding effects
91  if (bin_eta_l == binsEta_.end()) {
92  if (fabs(eta) < minEta_) {
93  bin_eta = 0;
94  } else if (fabs(eta) >= maxEta_) {
95  bin_eta = nBinsEta_;
96  } else {
97  edm::LogError("HGCalTriggerTowerGeometryHelper")
98  << " did not manage to map eta " << eta << " to any Trigger Tower\n";
99  }
100  } else {
101  bin_eta = bin_eta_l - binsEta_.begin() - 1;
102  }
103 
104  auto bin_phi_l = std::lower_bound(binsPhi_.begin(), binsPhi_.end(), phi);
105  unsigned int bin_phi = 0;
106  if (bin_phi_l == binsPhi_.end()) {
107  if (phi < minPhi_) {
108  bin_phi = nBinsPhi_;
109  } else if (phi >= maxPhi_) {
110  bin_phi = 0;
111  } else {
112  edm::LogError("HGCalTriggerTowerGeometryHelper")
113  << " did not manage to map phi " << phi << " to any Trigger Tower\n";
114  }
115  } else {
116  bin_phi = bin_phi_l - binsPhi_.begin() - 1;
117  }
118  int zside = eta < 0 ? -1 : 1;
119  return l1t::HGCalTowerID(zside, bin_eta, bin_phi).rawId();
120 }

References binsEta_, binsPhi_, PVValHelper::eta, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, maxEta_, maxPhi_, minEta_, minPhi_, nBinsEta_, nBinsPhi_, phi, l1t::HGCalTowerID::rawId(), and ecaldqm::zside().

Referenced by getTriggerTower().

Member Data Documentation

◆ binsEta_

std::vector<double> HGCalTriggerTowerGeometryHelper::binsEta_
private

◆ binsPhi_

std::vector<double> HGCalTriggerTowerGeometryHelper::binsPhi_
private

◆ cells_to_trigger_towers_

std::unordered_map<unsigned, short> HGCalTriggerTowerGeometryHelper::cells_to_trigger_towers_
private

◆ maxEta_

double HGCalTriggerTowerGeometryHelper::maxEta_
private

◆ maxPhi_

double HGCalTriggerTowerGeometryHelper::maxPhi_
private

◆ minEta_

double HGCalTriggerTowerGeometryHelper::minEta_
private

◆ minPhi_

double HGCalTriggerTowerGeometryHelper::minPhi_
private

◆ nBinsEta_

unsigned int HGCalTriggerTowerGeometryHelper::nBinsEta_
private

◆ nBinsPhi_

unsigned int HGCalTriggerTowerGeometryHelper::nBinsPhi_
private

◆ tower_coords_

std::vector<l1t::HGCalTowerCoord> HGCalTriggerTowerGeometryHelper::tower_coords_
private

◆ triggerTools_

HGCalTriggerTools HGCalTriggerTowerGeometryHelper::triggerTools_
private
HGCalTriggerTowerGeometryHelper::maxEta_
double maxEta_
Definition: HGCalTriggerTowerGeometryHelper.h:46
HGCalTriggerTools::eventSetup
void eventSetup(const edm::EventSetup &)
Definition: HGCalTriggerTools.cc:35
HGCalTriggerTowerGeometryHelper::nBinsPhi_
unsigned int nBinsPhi_
Definition: HGCalTriggerTowerGeometryHelper.h:50
ecaldqm::zside
int zside(DetId const &)
Definition: EcalDQMCommonUtils.cc:189
HGCalTriggerTowerGeometryHelper::cells_to_trigger_towers_
std::unordered_map< unsigned, short > cells_to_trigger_towers_
Definition: HGCalTriggerTowerGeometryHelper.h:43
DetId
Definition: DetId.h:17
edm::FileInPath
Definition: FileInPath.h:64
HGCalTriggerTowerGeometryHelper::maxPhi_
double maxPhi_
Definition: HGCalTriggerTowerGeometryHelper.h:48
PVValHelper::eta
Definition: PVValidationHelpers.h:69
HGCalTriggerTowerGeometryHelper::triggerTools_
HGCalTriggerTools triggerTools_
Definition: HGCalTriggerTowerGeometryHelper.h:55
HGCalTriggerTools::zside
int zside(const DetId &) const
Definition: HGCalTriggerTools.cc:210
l1t::HGCalTowerID
Definition: HGCalTowerID.h:8
l1t::HGCalTriggerCell::detId
uint32_t detId() const
Definition: HGCalTriggerCell.h:25
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
createfilelist.int
int
Definition: createfilelist.py:10
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
HGCalTriggerTowerGeometryHelper::minPhi_
double minPhi_
Definition: HGCalTriggerTowerGeometryHelper.h:47
DDAxes::phi
ecaldqm::towerId
unsigned towerId(DetId const &)
Definition: EcalDQMCommonUtils.cc:79
l1t::HGCalTriggerCell::position
const GlobalPoint & position() const
Definition: HGCalTriggerCell.h:26
l1t::HGCalTriggerSums::position
const GlobalPoint & position() const
Definition: HGCalTriggerSums.h:26
Exception
Definition: hltDiff.cc:246
HGCalTriggerTowerGeometryHelper::nBinsEta_
unsigned int nBinsEta_
Definition: HGCalTriggerTowerGeometryHelper.h:49
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HGCalTriggerTowerGeometryHelper::getTriggerTowerFromEtaPhi
unsigned short getTriggerTowerFromEtaPhi(const float &eta, const float &phi) const
Definition: HGCalTriggerTowerGeometryHelper.cc:87
L1TowerCalibrationProducer_cfi.iEta
iEta
Definition: L1TowerCalibrationProducer_cfi.py:60
HGCalTriggerTowerGeometryHelper::binsPhi_
std::vector< double > binsPhi_
Definition: HGCalTriggerTowerGeometryHelper.h:53
HGCalTriggerTowerGeometryHelper::binsEta_
std::vector< double > binsEta_
Definition: HGCalTriggerTowerGeometryHelper.h:52
l1t::HGCalTowerID::rawId
unsigned short rawId() const
Definition: HGCalTowerID.h:25
edm::errors::Configuration
Definition: EDMException.h:36
HGCalTriggerTowerGeometryHelper::tower_coords_
std::vector< l1t::HGCalTowerCoord > tower_coords_
Definition: HGCalTriggerTowerGeometryHelper.h:42
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
HGCalTriggerTowerGeometryHelper::minEta_
double minEta_
Definition: HGCalTriggerTowerGeometryHelper.h:45