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 getTriggerTowerFromTriggerCell (const unsigned tcId, 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_
 

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 25 of file HGCalTriggerTowerGeometryHelper.h.

Constructor & Destructor Documentation

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

Definition at line 14 of file HGCalTriggerTowerGeometryHelper.cc.

References binsEta_, binsPhi_, cells_to_trigger_towers_, edm::errors::Configuration, Exception, edm::FileInPath::fullPath(), edm::ParameterSet::getParameter(), createfilelist::int, maxEta_, maxPhi_, minEta_, minPhi_, nBinsEta_, nBinsPhi_, l1t::HGCalTowerID::rawId(), tower_coords_, DataFormats::L1THGCal::towerId, and ecaldqm::zside().

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

Definition at line 29 of file HGCalTriggerTowerGeometryHelper.h.

References PVValHelper::eta.

29 {}

Member Function Documentation

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

Definition at line 89 of file HGCalTriggerTowerGeometryHelper.cc.

References tower_coords_.

Referenced by HGCalTowerMap2DImpl::newTowerMaps().

89  {
90  return tower_coords_;
91 }
std::vector< l1t::HGCalTowerCoord > tower_coords_
unsigned short HGCalTriggerTowerGeometryHelper::getTriggerTowerFromTriggerCell ( const unsigned  tcId,
const float &  eta,
const float &  phi 
) const

Definition at line 94 of file HGCalTriggerTowerGeometryHelper.cc.

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

Referenced by HGCalTowerMap2DImpl::buildTowerMap2D().

94  {
95  // NOTE: if the TC is not found in the map than it is mapped via eta-phi coords.
96  // this can be considered dangerous (silent failure of the map) but it actually allows to save
97  // memory mapping explicitly only what is actually needed
98  auto tower_id_itr = cells_to_trigger_towers_.find(trigger_cell_id);
99  if(tower_id_itr != cells_to_trigger_towers_.end()) return tower_id_itr->second;
100 
101  auto bin_eta_l = std::lower_bound(binsEta_.begin(), binsEta_.end(), fabs(eta));
102  unsigned int bin_eta = 0;
103  // we add a protection for TCs in Hadron part which are outside the boundaries and possible rounding effects
104  if(bin_eta_l == binsEta_.end()) {
105  if(fabs(eta) < minEta_) {
106  bin_eta = 0;
107  } else if(fabs(eta) >= maxEta_) {
108  bin_eta = nBinsEta_;
109  } else {
110  edm::LogError("HGCalTriggerTowerGeometryHelper") << " did not manage to map TC " << trigger_cell_id << " (eta: " << eta << ") to any Trigger Tower\n";
111  }
112  } else {
113  bin_eta = bin_eta_l - binsEta_.begin() - 1;
114  }
115 
116 
117  auto bin_phi_l = std::lower_bound(binsPhi_.begin(), binsPhi_.end(), phi);
118  unsigned int bin_phi = 0;
119  if(bin_phi_l == binsPhi_.end()) {
120  if(phi < minPhi_) {
121  bin_phi = nBinsPhi_;
122  } else if(phi >= maxPhi_) {
123  bin_phi = 0;
124  } else {
125  edm::LogError("HGCalTriggerTowerGeometryHelper") << " did not manage to map TC " << trigger_cell_id << " (phi: " << phi << ") to any Trigger Tower\n";
126  }
127  } else {
128  bin_phi = bin_phi_l - binsPhi_.begin() - 1;
129  }
130  int zside = eta < 0 ? -1 : 1;
131  return l1t::HGCalTowerID(zside, bin_eta, bin_phi).rawId();
132 }
int zside(DetId const &)
unsigned short rawId() const
Definition: HGCalTowerID.h:24
std::unordered_map< unsigned, short > cells_to_trigger_towers_

Member Data Documentation

std::vector<double> HGCalTriggerTowerGeometryHelper::binsEta_
private
std::vector<double> HGCalTriggerTowerGeometryHelper::binsPhi_
private
std::unordered_map<unsigned, short> HGCalTriggerTowerGeometryHelper::cells_to_trigger_towers_
private
double HGCalTriggerTowerGeometryHelper::maxEta_
private
double HGCalTriggerTowerGeometryHelper::maxPhi_
private
double HGCalTriggerTowerGeometryHelper::minEta_
private
double HGCalTriggerTowerGeometryHelper::minPhi_
private
unsigned int HGCalTriggerTowerGeometryHelper::nBinsEta_
private
unsigned int HGCalTriggerTowerGeometryHelper::nBinsPhi_
private
std::vector<l1t::HGCalTowerCoord> HGCalTriggerTowerGeometryHelper::tower_coords_
private