File indexing completed on 2024-10-29 06:08:38
0001 #ifndef RecoParticleFlow_PFClusterProducer_PFHGCalRecHitCreator_h
0002 #define RecoParticleFlow_PFClusterProducer_PFHGCalRecHitCreator_h
0003
0004 #include "RecoParticleFlow/PFClusterProducer/interface/PFRecHitCreatorBase.h"
0005
0006 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0007 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0008 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0009
0010 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0011 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0012 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0013 #include "Geometry/CaloGeometry/interface/TruncatedPyramid.h"
0014 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0015
0016 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
0017 #include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h"
0018 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
0019 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
0020 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
0021 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
0022
0023 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0024
0025 template <typename DET, PFLayer::Layer Layer, DetId::Detector det, unsigned subdet>
0026 class PFHGCalRecHitCreator : public PFRecHitCreatorBase {
0027 public:
0028 PFHGCalRecHitCreator(const edm::ParameterSet& iConfig, edm::ConsumesCollector& cc)
0029 : PFRecHitCreatorBase(iConfig, cc),
0030 recHitToken_(cc.consumes<HGCRecHitCollection>(iConfig.getParameter<edm::InputTag>("src"))),
0031 geometryInstance_(iConfig.getParameter<std::string>("geometryInstance")),
0032 geomToken_(cc.esConsumes()) {}
0033
0034 void importRecHits(std::unique_ptr<reco::PFRecHitCollection>& out,
0035 std::unique_ptr<reco::PFRecHitCollection>& cleaned,
0036 const edm::Event& iEvent,
0037 const edm::EventSetup& iSetup) override {
0038
0039 edm::ESHandle<CaloGeometry> geoHandle = iSetup.getHandle(geomToken_);
0040 recHitTools_.setGeometry(*geoHandle);
0041
0042 for (unsigned int i = 0; i < qualityTests_.size(); ++i) {
0043 qualityTests_.at(i)->beginEvent(iEvent, iSetup);
0044 }
0045
0046 edm::Handle<HGCRecHitCollection> recHitHandle;
0047 iEvent.getByToken(recHitToken_, recHitHandle);
0048 const HGCRecHitCollection& rechits = *recHitHandle;
0049
0050 const CaloGeometry* geom = geoHandle.product();
0051
0052 unsigned skipped_rechits = 0;
0053 for (const auto& hgrh : rechits) {
0054 const DET detid(hgrh.detid());
0055
0056 if (det != detid.det() or (subdet != 0 and subdet != detid.subdetId())) {
0057 throw cms::Exception("IncorrectHGCSubdetector")
0058 << "det expected: " << det << " det gotten: " << detid.det() << " ; "
0059 << "subdet expected: " << subdet << " subdet gotten: " << detid.subdetId() << std::endl;
0060 }
0061
0062 double energy = hgrh.energy();
0063 double time = hgrh.time();
0064
0065 auto thisCell = geom->getSubdetectorGeometry(det, subdet)->getGeometry(detid);
0066
0067
0068 if (!thisCell) {
0069 LogDebug("PFHGCalRecHitCreator") << "warning detid " << detid.rawId() << " not found in geometry" << std::endl;
0070 ++skipped_rechits;
0071 continue;
0072 }
0073
0074 reco::PFRecHit rh(std::move(thisCell), detid.rawId(), Layer, energy);
0075
0076 bool rcleaned = false;
0077 bool keep = true;
0078
0079
0080 for (unsigned int i = 0; i < qualityTests_.size(); ++i) {
0081 if (!qualityTests_.at(i)->test(rh, hgrh, rcleaned)) {
0082 keep = false;
0083 }
0084 }
0085
0086 if (keep) {
0087 rh.setTime(time);
0088 out->push_back(rh);
0089 } else if (rcleaned)
0090 cleaned->push_back(rh);
0091 }
0092 edm::LogInfo("HGCalRecHitCreator") << "Skipped " << skipped_rechits << " out of " << rechits.size() << " rechits!"
0093 << std::endl;
0094 edm::LogInfo("HGCalRecHitCreator") << "Created " << out->size() << " PFRecHits!" << std::endl;
0095 }
0096
0097 protected:
0098 edm::EDGetTokenT<HGCRecHitCollection> recHitToken_;
0099 std::string geometryInstance_;
0100
0101 private:
0102 hgcal::RecHitTools recHitTools_;
0103 edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
0104 };
0105
0106 #include "DataFormats/DetId/interface/DetId.h"
0107 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0108 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0109 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0110
0111 typedef PFHGCalRecHitCreator<HGCalDetId, PFLayer::HGCAL, DetId::Forward, HGCEE> PFHGCEERecHitCreator;
0112 typedef PFHGCalRecHitCreator<HGCalDetId, PFLayer::HGCAL, DetId::Forward, HGCHEF> PFHGCHEFRecHitCreator;
0113 typedef PFHGCalRecHitCreator<HcalDetId, PFLayer::HGCAL, DetId::Hcal, HcalEndcap> PFHGCHEBRecHitCreator;
0114
0115 typedef PFHGCalRecHitCreator<HGCSiliconDetId, PFLayer::HGCAL, DetId::HGCalEE, ForwardEmpty> PFHGCalEERecHitCreator;
0116 typedef PFHGCalRecHitCreator<HGCSiliconDetId, PFLayer::HGCAL, DetId::HGCalHSi, ForwardEmpty> PFHGCalHSiRecHitCreator;
0117 typedef PFHGCalRecHitCreator<HGCScintillatorDetId, PFLayer::HGCAL, DetId::HGCalHSc, ForwardEmpty>
0118 PFHGCalHScRecHitCreator;
0119
0120 #endif