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  for(int zside = -1; zside <= 1; zside+=2) {
49  for(unsigned int bin1 = 0; bin1 != nBinsEta_; bin1++) {
50  for(unsigned int bin2 = 0; bin2 != nBinsPhi_; bin2++) {
51  l1t::HGCalTowerID towerId(zside, bin1, bin2);
52  tower_coords_.emplace_back(towerId.rawId(),
53  (binsEta_[bin1+1] + binsEta_[bin1])/2,
54  (binsPhi_[bin2+1] + binsPhi_[bin2])/2);
55  }
56  }
57  }
58 
59  if(conf.getParameter<bool>("readMappingFile")) {
60  // We read the TC to TT mapping from file,
61  // otherwise we derive the TC to TT mapping on the fly from eta-phi coord. of the TCs
62  std::ifstream l1tTriggerTowerMappingStream(conf.getParameter<edm::FileInPath>("L1TTriggerTowerMapping").fullPath());
63  if(!l1tTriggerTowerMappingStream.is_open()) {
64  throw cms::Exception("MissingDataFile")
65  << "Cannot open HGCalTriggerGeometry L1TTriggerTowerMapping file\n";
66  }
67 
68  unsigned trigger_cell_id = 0;
69  unsigned short iEta = 0;
70  unsigned short iPhi = 0;
71 
72  for(; l1tTriggerTowerMappingStream >> trigger_cell_id >> iEta >> iPhi;) {
73  if(iEta >= nBinsEta_ || iPhi >= nBinsPhi_) {
74  throw edm::Exception(edm::errors::Configuration, "Configuration")
75  << "HGCalTriggerTowerGeometryHelper warning inconsistent mapping TC : " << trigger_cell_id
76  << " to TT iEta: " << iEta << " iPhi: " << iPhi
77  << " when max #bins eta: " << nBinsEta_ << " phi: " << nBinsPhi_ << std::endl;
78  }
79  l1t::HGCalTowerID towerId(HGCalDetId(trigger_cell_id).zside(), iEta, iPhi);
80  cells_to_trigger_towers_[trigger_cell_id] = towerId.rawId();
81  }
82  l1tTriggerTowerMappingStream.close();
83 
84  }
85 }
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:34
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 88 of file HGCalTriggerTowerGeometryHelper.cc.

References tower_coords_.

Referenced by HGCalTowerMap2DImpl::newTowerMaps().

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

Definition at line 93 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().

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