CMS 3D CMS Logo

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

#include <HGCalTriggerTowerGeometryHelper.h>

Public Member Functions

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)
 
const bool isNose ()
 
void setGeometry (const HGCalTriggerGeometryBase *const geom)
 
 ~HGCalTriggerTowerGeometryHelper ()
 

Private Attributes

std::vector< double > binsEta_
 
std::vector< double > binsPhi_
 
std::unordered_map< unsigned, short > cells_to_trigger_towers_
 
bool doNose_
 
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.

References binsEta_, binsPhi_, cells_to_trigger_towers_, edm::errors::Configuration, doNose_, 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().

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

◆ ~HGCalTriggerTowerGeometryHelper()

HGCalTriggerTowerGeometryHelper::~HGCalTriggerTowerGeometryHelper ( )
inline

Definition at line 31 of file HGCalTriggerTowerGeometryHelper.h.

31 {}

Member Function Documentation

◆ getTowerCoordinates()

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

Definition at line 84 of file HGCalTriggerTowerGeometryHelper.cc.

References tower_coords_.

Referenced by HGCalTowerMap2DImpl::newTowerMaps().

84  {
85  return tower_coords_;
86 }
std::vector< l1t::HGCalTowerCoord > tower_coords_

◆ getTriggerTower() [1/2]

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

Definition at line 123 of file HGCalTriggerTowerGeometryHelper.cc.

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().

123  {
124  unsigned int trigger_cell_id = thecell.detId();
125  // NOTE: if the TC is not found in the map than it is mapped via eta-phi coords.
126  // this can be considered dangerous (silent failure of the map) but it actually allows to save
127  // memory mapping explicitly only what is actually needed
128  auto tower_id_itr = cells_to_trigger_towers_.find(trigger_cell_id);
129  if (tower_id_itr != cells_to_trigger_towers_.end())
130  return tower_id_itr->second;
131 
132  return getTriggerTowerFromEtaPhi(thecell.position().eta(), thecell.position().phi());
133 }
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
uint32_t detId() const
const GlobalPoint & position() const
std::unordered_map< unsigned, short > cells_to_trigger_towers_
unsigned short getTriggerTowerFromEtaPhi(const float &eta, const float &phi) const

◆ getTriggerTower() [2/2]

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

Definition at line 135 of file HGCalTriggerTowerGeometryHelper.cc.

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

135  {
136  return getTriggerTowerFromEtaPhi(thesum.position().eta(), thesum.position().phi());
137 }
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
const GlobalPoint & position() const
unsigned short getTriggerTowerFromEtaPhi(const float &eta, const float &phi) const

◆ getTriggerTowerFromEtaPhi()

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

Definition at line 88 of file HGCalTriggerTowerGeometryHelper.cc.

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

Referenced by getTriggerTower().

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

◆ isNose()

const bool HGCalTriggerTowerGeometryHelper::isNose ( )
inline

◆ setGeometry()

void HGCalTriggerTowerGeometryHelper::setGeometry ( const HGCalTriggerGeometryBase *const  geom)
inline

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

◆ doNose_

bool HGCalTriggerTowerGeometryHelper::doNose_
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