Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-18 09:15:19

0001 #ifndef RecoParticleFlow_PFClusterProducer_PFHcalRecHitCreator_h
0002 #define RecoParticleFlow_PFClusterProducer_PFHcalRecHitCreator_h
0003 
0004 #include "RecoParticleFlow/PFClusterProducer/interface/PFRecHitCreatorBase.h"
0005 
0006 #include "DataFormats/HcalRecHit/interface/HORecHit.h"
0007 #include "DataFormats/HcalRecHit/interface/HFRecHit.h"
0008 #include "DataFormats/HcalRecHit/interface/HBHERecHit.h"
0009 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0010 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0011 
0012 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0013 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0014 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0015 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0016 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0017 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0018 
0019 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
0020 
0021 template <typename Digi, typename Geometry, PFLayer::Layer Layer, int Detector>
0022 class PFHcalRecHitCreator final : public PFRecHitCreatorBase {
0023 public:
0024   PFHcalRecHitCreator(const edm::ParameterSet& iConfig, edm::ConsumesCollector& cc)
0025       : PFRecHitCreatorBase(iConfig, cc),
0026         recHitToken_(cc.consumes<edm::SortedCollection<Digi> >(iConfig.getParameter<edm::InputTag>("src"))),
0027         geomToken_(cc.esConsumes()),
0028         topoToken_(cc.esConsumes()) {}
0029 
0030   void importRecHits(std::unique_ptr<reco::PFRecHitCollection>& out,
0031                      std::unique_ptr<reco::PFRecHitCollection>& cleaned,
0032                      const edm::Event& iEvent,
0033                      const edm::EventSetup& iSetup) override {
0034     beginEvent(iEvent, iSetup);
0035 
0036     edm::Handle<edm::SortedCollection<Digi> > recHitHandle;
0037 
0038     edm::ESHandle<CaloGeometry> geoHandle = iSetup.getHandle(geomToken_);
0039     edm::ESHandle<HcalTopology> hcalTopology = iSetup.getHandle(topoToken_);
0040 
0041     // get the hcal geometry and topology
0042     const CaloSubdetectorGeometry* gTmp = geoHandle->getSubdetectorGeometry(DetId::Hcal, Detector);
0043     const Geometry* hcalGeo = dynamic_cast<const Geometry*>(gTmp);
0044     const HcalTopology* theHcalTopology = hcalTopology.product();
0045 
0046     iEvent.getByToken(recHitToken_, recHitHandle);
0047     for (const auto& erh : *recHitHandle) {
0048       HcalDetId detid = (HcalDetId)erh.detid();
0049       HcalSubdetector esd = (HcalSubdetector)detid.subdetId();
0050 
0051       //since hbhe are together kill other detector
0052       if (esd != Detector && Detector != HcalOther)
0053         continue;
0054 
0055       if (theHcalTopology->getMergePositionFlag() && esd == HcalEndcap) {
0056         detid = theHcalTopology->idFront(detid);
0057       }
0058 
0059       auto energy = erh.energy();
0060       auto time = erh.time();
0061       auto depth = detid.depth();
0062 
0063       auto thisCell = hcalGeo->getGeometry(detid);
0064 
0065       // find rechit geometry
0066       if (!thisCell) {
0067         edm::LogError("PFHcalRecHitCreator")
0068             << "warning detid " << detid.rawId() << " not found in geometry" << std::endl;
0069         continue;
0070       }
0071 
0072       reco::PFRecHit rh(thisCell, detid.rawId(), Layer, energy);
0073       rh.setTime(time);  //Mike: This we will use later
0074       rh.setDepth(depth);
0075 
0076       bool rcleaned = false;
0077       bool keep = true;
0078 
0079       //Apply Q tests
0080       for (const auto& qtest : qualityTests_) {
0081         if (!qtest->test(rh, erh, rcleaned)) {
0082           keep = false;
0083         }
0084       }
0085 
0086       if (keep) {
0087         out->push_back(std::move(rh));
0088       } else if (rcleaned)
0089         cleaned->push_back(std::move(rh));
0090     }
0091   }
0092 
0093 protected:
0094   edm::EDGetTokenT<edm::SortedCollection<Digi> > recHitToken_;
0095   int hoDepth_;
0096 
0097 private:
0098   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
0099   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> topoToken_;
0100 };
0101 
0102 typedef PFHcalRecHitCreator<HBHERecHit, CaloSubdetectorGeometry, PFLayer::HCAL_BARREL1, HcalBarrel> PFHBRecHitCreator;
0103 typedef PFHcalRecHitCreator<HORecHit, CaloSubdetectorGeometry, PFLayer::HCAL_BARREL2, HcalOuter> PFHORecHitCreator;
0104 typedef PFHcalRecHitCreator<HBHERecHit, CaloSubdetectorGeometry, PFLayer::HCAL_ENDCAP, HcalEndcap> PFHERecHitCreator;
0105 typedef PFHcalRecHitCreator<HFRecHit, CaloSubdetectorGeometry, PFLayer::HF_EM, HcalForward> PFHFEMRecHitCreator;
0106 typedef PFHcalRecHitCreator<HFRecHit, CaloSubdetectorGeometry, PFLayer::HF_HAD, HcalForward> PFHFHADRecHitCreator;
0107 
0108 #endif