File indexing completed on 2024-04-06 12:14:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include "Geometry/CaloEventSetup/plugins/CaloGeometryBuilder.h"
0021 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0022 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
0023 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
0024 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0025 #include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h"
0026 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
0027 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
0028 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0029 #include "Geometry/HcalTowerAlgo/interface/CaloTowerGeometry.h"
0030 #include "Geometry/ForwardGeometry/interface/CastorGeometry.h"
0031 #include "Geometry/ForwardGeometry/interface/ZdcGeometry.h"
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033
0034 namespace {
0035 template <typename Record>
0036 void makeToken(edm::ESConsumesCollector& cc,
0037 std::vector<std::string>& list,
0038 std::string const& tag,
0039 edm::ESGetToken<CaloSubdetectorGeometry, Record>& token) {
0040 auto found = std::find(list.begin(), list.end(), tag);
0041 edm::LogVerbatim("CaloGeometryBuilder") << "Finds tag " << tag << " : " << (found != list.end());
0042 if (found != list.end()) {
0043 token = cc.consumesFrom<CaloSubdetectorGeometry, Record>(edm::ESInputTag{"", *found});
0044 list.erase(found);
0045 }
0046 }
0047 }
0048
0049
0050
0051
0052 CaloGeometryBuilder::CaloGeometryBuilder(const edm::ParameterSet& iConfig) {
0053
0054
0055 auto cc = setWhatProduced(this, &CaloGeometryBuilder::produceAligned);
0056
0057
0058 auto caloList = iConfig.getParameter<std::vector<std::string> >("SelectedCalos");
0059 if (caloList.empty())
0060 throw cms::Exception("Configuration") << "No calorimeter specified for geometry, aborting";
0061
0062 makeToken(cc, caloList, HcalGeometry::producerTag(), hcalToken_);
0063 makeToken(cc, caloList, ZdcGeometry::producerTag(), zdcToken_);
0064 makeToken(cc, caloList, CastorGeometry::producerTag(), castorToken_);
0065 makeToken(cc, caloList, EcalBarrelGeometry::producerTag(), ecalBarrelToken_);
0066 makeToken(cc, caloList, EcalEndcapGeometry::producerTag(), ecalEndcapToken_);
0067 makeToken(cc, caloList, EcalPreshowerGeometry::producerTag(), ecalPreshowerToken_);
0068 makeToken(cc, caloList, CaloTowerGeometry::producerTag(), caloTowerToken_);
0069
0070
0071 auto hgcBegin = std::partition(caloList.begin(), caloList.end(), [](std::string const& elem) {
0072 return elem.find(HGCalGeometry::producerTag()) == std::string::npos;
0073 });
0074
0075 for (auto iter = hgcBegin; iter != caloList.end(); ++iter) {
0076 hgcalTokens_.emplace_back(cc.consumesFrom<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", *iter}), *iter);
0077 }
0078
0079 caloList.erase(hgcBegin, caloList.end());
0080
0081
0082 if (not caloList.empty()) {
0083 cms::Exception ex{"Configuration"};
0084 ex << "Reconstruction geometry requested for a not implemented sub-detectors:";
0085 for (auto const& elem : caloList) {
0086 ex << " " << elem;
0087 }
0088 throw ex;
0089 }
0090 }
0091
0092
0093
0094 CaloGeometryBuilder::ReturnType CaloGeometryBuilder::produceAligned(const CaloGeometryRecord& iRecord) {
0095 ReturnType pCalo = std::make_unique<CaloGeometry>();
0096
0097
0098
0099 if (hcalToken_.isInitialized()) {
0100 edm::LogVerbatim("CaloGeometryBuilder") << "Building HCAL reconstruction geometry";
0101
0102 auto const& pG = iRecord.get(hcalToken_);
0103 pCalo->setSubdetGeometry(DetId::Hcal, HcalBarrel, &pG);
0104 pCalo->setSubdetGeometry(DetId::Hcal, HcalEndcap, &pG);
0105 pCalo->setSubdetGeometry(DetId::Hcal, HcalOuter, &pG);
0106 pCalo->setSubdetGeometry(DetId::Hcal, HcalForward, &pG);
0107 }
0108 if (zdcToken_.isInitialized()) {
0109 edm::LogVerbatim("CaloGeometryBuilder") << "Building ZDC reconstruction geometry";
0110 auto const& pG = iRecord.get(zdcToken_);
0111 pCalo->setSubdetGeometry(DetId::Calo, HcalZDCDetId::SubdetectorId, &pG);
0112 }
0113 if (castorToken_.isInitialized()) {
0114 edm::LogVerbatim("CaloGeometryBuilder") << "Building CASTOR reconstruction geometry";
0115 auto const& pG = iRecord.get(castorToken_);
0116 pCalo->setSubdetGeometry(DetId::Calo, HcalCastorDetId::SubdetectorId, &pG);
0117 }
0118
0119
0120 if (ecalBarrelToken_.isInitialized()) {
0121 edm::LogVerbatim("CaloGeometryBuilder") << "Building EcalBarrel reconstruction geometry";
0122 auto const& pG = iRecord.get(ecalBarrelToken_);
0123 pCalo->setSubdetGeometry(DetId::Ecal, EcalBarrel, &pG);
0124 }
0125
0126 if (ecalEndcapToken_.isInitialized()) {
0127 edm::LogVerbatim("CaloGeometryBuilder") << "Building EcalEndcap reconstruction geometry";
0128 auto const& pG = iRecord.get(ecalEndcapToken_);
0129 pCalo->setSubdetGeometry(DetId::Ecal, EcalEndcap, &pG);
0130 }
0131
0132 if (ecalPreshowerToken_.isInitialized()) {
0133 edm::LogVerbatim("CaloGeometryBuilder") << "Building EcalPreshower reconstruction geometry";
0134 const auto& pG = iRecord.get(ecalPreshowerToken_);
0135 pCalo->setSubdetGeometry(DetId::Ecal, EcalPreshower, &pG);
0136 }
0137
0138
0139 if (caloTowerToken_.isInitialized()) {
0140 edm::LogVerbatim("CaloGeometryBuilder") << "Building TOWER reconstruction geometry";
0141 const auto& pG = iRecord.get(caloTowerToken_);
0142 pCalo->setSubdetGeometry(DetId::Calo, 1, &pG);
0143 }
0144
0145 for (auto const& hgcTokenLabel : hgcalTokens_) {
0146 edm::LogVerbatim("CaloGeometryBuilder") << "Building " << hgcTokenLabel.second << " reconstruction geometry";
0147 auto const& pHG = iRecord.get(hgcTokenLabel.first);
0148 const auto& topo = pHG.topology();
0149 pCalo->setSubdetGeometry(topo.detector(), topo.subDetector(), &pHG);
0150 }
0151
0152 return pCalo;
0153 }