File indexing completed on 2024-04-06 12:04:33
0001 #include "DataFormats/L1THGCal/interface/HGCalTowerMap.h"
0002 #include "FWCore/Utilities/interface/EDMException.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0005
0006 using namespace l1t;
0007
0008 HGCalTowerMap::HGCalTowerMap(const std::vector<HGCalTowerCoord>& tower_ids, const int layer = 0) : layer_(layer) {
0009 for (auto tower_id : tower_ids) {
0010 towerMap_[tower_id.rawId] = l1t::HGCalTower(0., 0., tower_id.eta, tower_id.phi, tower_id.rawId);
0011 }
0012 }
0013
0014 const HGCalTowerMap& HGCalTowerMap::operator+=(const HGCalTowerMap& map) {
0015 if (nTowers() != map.nTowers()) {
0016 throw edm::Exception(edm::errors::StdException, "StdException")
0017 << "HGCalTowerMap: Trying to add HGCalTowerMaps with different bins: " << nTowers() << " and " << map.nTowers()
0018 << endl;
0019 }
0020
0021 for (const auto& tower : map.towers()) {
0022 auto this_tower = towerMap_.find(tower.first);
0023 if (this_tower == towerMap_.end()) {
0024 throw edm::Exception(edm::errors::StdException, "StdException")
0025 << "HGCalTowerMap: Trying to add HGCalTowerMaps but could not find bin: " << tower.first << endl;
0026 } else {
0027 this_tower->second += tower.second;
0028 }
0029 }
0030 return *this;
0031 }
0032
0033 bool HGCalTowerMap::addEt(const std::unordered_map<unsigned short, float>& towerIDandShares, float etEm, float etHad) {
0034 for (const auto& towerIDandShare : towerIDandShares) {
0035 auto this_tower = towerMap_.find(towerIDandShare.first);
0036 if (this_tower == towerMap_.end())
0037 return false;
0038 this_tower->second.addEtEm(etEm * towerIDandShare.second);
0039 this_tower->second.addEtHad(etHad * towerIDandShare.second);
0040 }
0041 return true;
0042 }