Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-29 06:08:38

0001 #ifndef RecoParticleFlow_PFClusterProducer_PFPSRecHitCreator_h
0002 #define RecoParticleFlow_PFClusterProducer_PFPSRecHitCreator_h
0003 
0004 #include "RecoParticleFlow/PFClusterProducer/interface/PFRecHitCreatorBase.h"
0005 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0006 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0007 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0008 
0009 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0010 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0011 #include "DataFormats/EcalDetId/interface/ESDetId.h"
0012 
0013 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0014 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0015 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0016 #include "Geometry/CaloGeometry/interface/TruncatedPyramid.h"
0017 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0018 
0019 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
0020 #include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h"
0021 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
0022 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
0023 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
0024 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
0025 
0026 class PFPSRecHitCreator final : public PFRecHitCreatorBase {
0027 public:
0028   PFPSRecHitCreator(const edm::ParameterSet& iConfig, edm::ConsumesCollector& cc)
0029       : PFRecHitCreatorBase(iConfig, cc),
0030         recHitToken_(cc.consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("src"))),
0031         geomToken_(cc.esConsumes()) {}
0032 
0033   void importRecHits(std::unique_ptr<reco::PFRecHitCollection>& out,
0034                      std::unique_ptr<reco::PFRecHitCollection>& cleaned,
0035                      const edm::Event& iEvent,
0036                      const edm::EventSetup& iSetup) override {
0037     beginEvent(iEvent, iSetup);
0038 
0039     edm::Handle<EcalRecHitCollection> recHitHandle;
0040     edm::ESHandle<CaloGeometry> geoHandle = iSetup.getHandle(geomToken_);
0041 
0042     // get the ecal geometry
0043     const CaloSubdetectorGeometry* psGeometry = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
0044 
0045     iEvent.getByToken(recHitToken_, recHitHandle);
0046     for (const auto& erh : *recHitHandle) {
0047       ESDetId detid(erh.detid());
0048       auto energy = erh.energy();
0049 
0050       PFLayer::Layer layer = PFLayer::NONE;
0051 
0052       switch (detid.plane()) {
0053         case 1:
0054           layer = PFLayer::PS1;
0055           break;
0056         case 2:
0057           layer = PFLayer::PS2;
0058           break;
0059         default:
0060           throw cms::Exception("PFRecHitBadInput")
0061               << "incorrect preshower plane !! plane number " << detid.plane() << std::endl;
0062       }
0063 
0064       auto thisCell = psGeometry->getGeometry(detid);
0065 
0066       // find rechit geometry
0067       if (!thisCell) {
0068         edm::LogError("PFPSRecHitCreator")
0069             << "warning detid " << detid.rawId() << " not found in geometry" << std::endl;
0070         continue;
0071       }
0072 
0073       out->emplace_back(std::move(thisCell), detid.rawId(), layer, energy);
0074       auto& rh = out->back();
0075       rh.setDepth(detid.plane());
0076       rh.setTime(erh.time());
0077 
0078       bool rcleaned = false;
0079       bool keep = true;
0080       bool hi = true;  // all ES rhs are produced, independently on the ECAL SRP decision
0081 
0082       //Apply Q tests
0083       for (const auto& qtest : qualityTests_) {
0084         if (!qtest->test(rh, erh, rcleaned, hi)) {
0085           keep = false;
0086         }
0087       }
0088 
0089       if (rcleaned)
0090         cleaned->push_back(std::move(out->back()));
0091       if (!keep)
0092         out->pop_back();
0093     }
0094   }
0095 
0096 protected:
0097   edm::EDGetTokenT<EcalRecHitCollection> recHitToken_;
0098 
0099 private:
0100   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
0101 };
0102 
0103 #endif