Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:14

0001 // -*- C++ -*-
0002 //
0003 // Package:    CaloGeometryBuilder
0004 // Class:      CaloGeometryBuilder
0005 //
0006 /**\class CaloGeometryBuilder CaloGeometryBuilder.h tmp/CaloGeometryBuilder/interface/CaloGeometryBuilder.h
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jeremiah Mans
0015 //         Created:  Mon Oct  3 11:35:27 CDT 2005
0016 //
0017 //
0018 
0019 // user include files
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 }  // namespace
0048 
0049 //
0050 // member functions
0051 //
0052 CaloGeometryBuilder::CaloGeometryBuilder(const edm::ParameterSet& iConfig) {
0053   //the following line is needed to tell the framework what
0054   // data is being produced
0055   auto cc = setWhatProduced(this, &CaloGeometryBuilder::produceAligned);
0056 
0057   //now do what ever other initialization is needed
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   // Move HGC elements to the end
0071   auto hgcBegin = std::partition(caloList.begin(), caloList.end(), [](std::string const& elem) {
0072     return elem.find(HGCalGeometry::producerTag()) == std::string::npos;
0073   });
0074   // Process HGC elements
0075   for (auto iter = hgcBegin; iter != caloList.end(); ++iter) {
0076     hgcalTokens_.emplace_back(cc.consumesFrom<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", *iter}), *iter);
0077   }
0078   // Erase HGC elements
0079   caloList.erase(hgcBegin, caloList.end());
0080 
0081   // Throw if any elements are left
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 // ------------ method called to produce the data  ------------
0093 
0094 CaloGeometryBuilder::ReturnType CaloGeometryBuilder::produceAligned(const CaloGeometryRecord& iRecord) {
0095   ReturnType pCalo = std::make_unique<CaloGeometry>();
0096 
0097   // look for HCAL parts
0098   // assume 'HCAL' for all of HCAL.
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   // look for Ecal Barrel
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   // look for Ecal Endcap
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   // look for Ecal Preshower
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   // look for TOWER parts
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 }