Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef RecoParticleFlow_PFClusterProducer_PFHBHeRecHitCreator_h
0002 #define RecoParticleFlow_PFClusterProducer_PFHBHeRecHitCreator_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/CaloTopology/interface/HcalTopology.h"
0017 
0018 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
0019 class PFHBHERecHitCreator : public PFRecHitCreatorBase {
0020 public:
0021   PFHBHERecHitCreator(const edm::ParameterSet& iConfig, edm::ConsumesCollector& cc)
0022       : PFRecHitCreatorBase(iConfig, cc),
0023         recHitToken_(cc.consumes<edm::SortedCollection<HBHERecHit> >(iConfig.getParameter<edm::InputTag>("src"))),
0024         geomToken_(cc.esConsumes()) {}
0025 
0026   void importRecHits(std::unique_ptr<reco::PFRecHitCollection>& out,
0027                      std::unique_ptr<reco::PFRecHitCollection>& cleaned,
0028                      const edm::Event& iEvent,
0029                      const edm::EventSetup& iSetup) override {
0030     beginEvent(iEvent, iSetup);
0031 
0032     edm::Handle<edm::SortedCollection<HBHERecHit> > recHitHandle;
0033 
0034     edm::ESHandle<CaloGeometry> geoHandle = iSetup.getHandle(geomToken_);
0035 
0036     // get the ecal geometry
0037     const CaloSubdetectorGeometry* hcalBarrelGeo = geoHandle->getSubdetectorGeometry(DetId::Hcal, HcalBarrel);
0038     const CaloSubdetectorGeometry* hcalEndcapGeo = geoHandle->getSubdetectorGeometry(DetId::Hcal, HcalEndcap);
0039 
0040     iEvent.getByToken(recHitToken_, recHitHandle);
0041     for (const auto& erh : *recHitHandle) {
0042       const HcalDetId detid = erh.idFront();
0043       HcalSubdetector esd = (HcalSubdetector)detid.subdetId();
0044 
0045       auto energy = erh.energy();
0046       auto time = erh.time();
0047       auto depth = detid.depth();
0048 
0049       CaloCellGeometryMayOwnPtr thisCell;
0050       PFLayer::Layer layer = PFLayer::HCAL_BARREL1;
0051       switch (esd) {
0052         case HcalBarrel:
0053           thisCell = hcalBarrelGeo->getGeometry(detid);
0054           layer = PFLayer::HCAL_BARREL1;
0055           break;
0056 
0057         case HcalEndcap:
0058           thisCell = hcalEndcapGeo->getGeometry(detid);
0059           layer = PFLayer::HCAL_ENDCAP;
0060           break;
0061         default:
0062           break;
0063       }
0064 
0065       // find rechit geometry
0066       if (!thisCell) {
0067         edm::LogError("PFHBHERecHitCreator") << "warning detid " << std::hex << detid.rawId() << std::dec << " "
0068                                              << detid << " not found in geometry" << std::endl;
0069         continue;
0070       }
0071 
0072       reco::PFRecHit rh(std::move(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<HBHERecHit> > recHitToken_;
0095 
0096 private:
0097   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
0098 };
0099 
0100 #endif