Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-18 02:25:11

0001 #include "FWCore/Framework/interface/EventSetup.h"
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/stream/EDProducer.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Utilities/interface/EDGetToken.h"
0010 #include "FWCore/Utilities/interface/InputTag.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 #include "DataFormats/EgammaCandidates/interface/HIPhotonIsolation.h"
0014 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
0015 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0016 
0017 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
0018 
0019 #include "RecoHI/HiEgammaAlgos/interface/EcalClusterIsoCalculator.h"
0020 #include "RecoHI/HiEgammaAlgos/interface/HcalRechitIsoCalculator.h"
0021 #include "RecoHI/HiEgammaAlgos/interface/TrackIsoCalculator.h"
0022 
0023 class photonIsolationHIProducer : public edm::stream::EDProducer<> {
0024 public:
0025   explicit photonIsolationHIProducer(const edm::ParameterSet& ps);
0026 
0027   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0028 
0029 private:
0030   void produce(edm::Event& evt, const edm::EventSetup& es) override;
0031 
0032   edm::EDGetTokenT<reco::PhotonCollection> photonProducer_;
0033   edm::EDGetTokenT<EcalRecHitCollection> barrelEcalHits_;
0034   edm::EDGetTokenT<EcalRecHitCollection> endcapEcalHits_;
0035   edm::EDGetTokenT<HBHERecHitCollection> hbhe_;
0036   edm::EDGetTokenT<HFRecHitCollection> hf_;
0037   edm::EDGetTokenT<HORecHitCollection> ho_;
0038   edm::EDGetTokenT<reco::BasicClusterCollection> barrelClusters_;
0039   edm::EDGetTokenT<reco::BasicClusterCollection> endcapClusters_;
0040   edm::EDGetTokenT<reco::TrackCollection> tracks_;
0041 
0042   const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_;
0043   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
0044 
0045   std::string trackQuality_;
0046 };
0047 
0048 photonIsolationHIProducer::photonIsolationHIProducer(const edm::ParameterSet& config)
0049     : photonProducer_(consumes(config.getParameter<edm::InputTag>("photonProducer"))),
0050       barrelEcalHits_(consumes(config.getParameter<edm::InputTag>("ebRecHitCollection"))),
0051       endcapEcalHits_(consumes(config.getParameter<edm::InputTag>("eeRecHitCollection"))),
0052       hbhe_(consumes(config.getParameter<edm::InputTag>("hbhe"))),
0053       hf_(consumes(config.getParameter<edm::InputTag>("hf"))),
0054       ho_(consumes(config.getParameter<edm::InputTag>("ho"))),
0055       barrelClusters_(consumes(config.getParameter<edm::InputTag>("basicClusterBarrel"))),
0056       endcapClusters_(consumes(config.getParameter<edm::InputTag>("basicClusterEndcap"))),
0057       tracks_(consumes(config.getParameter<edm::InputTag>("trackCollection"))),
0058       ecalClusterToolsESGetTokens_{consumesCollector()},
0059       geometryToken_{esConsumes()},
0060       trackQuality_(config.getParameter<std::string>("trackQuality")) {
0061   produces<reco::HIPhotonIsolationMap>();
0062 }
0063 
0064 void photonIsolationHIProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
0065   edm::Handle<reco::PhotonCollection> photons;
0066   evt.getByToken(photonProducer_, photons);
0067   edm::Handle<EcalRecHitCollection> barrelEcalHits;
0068   evt.getByToken(barrelEcalHits_, barrelEcalHits);
0069   edm::Handle<EcalRecHitCollection> endcapEcalHits;
0070   evt.getByToken(endcapEcalHits_, endcapEcalHits);
0071   edm::Handle<HBHERecHitCollection> hbhe;
0072   evt.getByToken(hbhe_, hbhe);
0073   edm::Handle<HFRecHitCollection> hf;
0074   evt.getByToken(hf_, hf);
0075   edm::Handle<HORecHitCollection> ho;
0076   evt.getByToken(ho_, ho);
0077   edm::Handle<reco::BasicClusterCollection> barrelClusters;
0078   evt.getByToken(barrelClusters_, barrelClusters);
0079   edm::Handle<reco::BasicClusterCollection> endcapClusters;
0080   evt.getByToken(endcapClusters_, endcapClusters);
0081   edm::Handle<reco::TrackCollection> trackCollection;
0082   evt.getByToken(tracks_, trackCollection);
0083 
0084   auto outputMap = std::make_unique<reco::HIPhotonIsolationMap>();
0085   reco::HIPhotonIsolationMap::Filler filler(*outputMap);
0086   std::vector<reco::HIPhotonIsolation> isoVector;
0087 
0088   EcalClusterIsoCalculator CxC(barrelClusters, endcapClusters);
0089   edm::ESHandle<CaloGeometry> geometryHandle = es.getHandle(geometryToken_);
0090   const CaloGeometry* geometry = nullptr;
0091   if (geometryHandle.isValid()) {
0092     geometry = geometryHandle.product();
0093   }
0094   HcalRechitIsoCalculator RxC(geometry, hbhe, hf, ho);
0095   TrackIsoCalculator TxC(*trackCollection, trackQuality_);
0096   EcalClusterLazyTools lazyTool(evt, ecalClusterToolsESGetTokens_.get(es), barrelEcalHits_, endcapEcalHits_);
0097 
0098   for (reco::PhotonCollection::const_iterator phoItr = photons->begin(); phoItr != photons->end(); ++phoItr) {
0099     reco::HIPhotonIsolation iso;
0100     // HI-style isolation info
0101     iso.ecalClusterIsoR1(CxC.getBkgSubEcalClusterIso(phoItr->superCluster(), 1, 0));
0102     iso.ecalClusterIsoR2(CxC.getBkgSubEcalClusterIso(phoItr->superCluster(), 2, 0));
0103     iso.ecalClusterIsoR3(CxC.getBkgSubEcalClusterIso(phoItr->superCluster(), 3, 0));
0104     iso.ecalClusterIsoR4(CxC.getBkgSubEcalClusterIso(phoItr->superCluster(), 4, 0));
0105     iso.ecalClusterIsoR5(CxC.getBkgSubEcalClusterIso(phoItr->superCluster(), 5, 0));
0106 
0107     iso.hcalRechitIsoR1(RxC.getBkgSubHcalRechitIso(phoItr->superCluster(), 1, 0));
0108     iso.hcalRechitIsoR2(RxC.getBkgSubHcalRechitIso(phoItr->superCluster(), 2, 0));
0109     iso.hcalRechitIsoR3(RxC.getBkgSubHcalRechitIso(phoItr->superCluster(), 3, 0));
0110     iso.hcalRechitIsoR4(RxC.getBkgSubHcalRechitIso(phoItr->superCluster(), 4, 0));
0111     iso.hcalRechitIsoR5(RxC.getBkgSubHcalRechitIso(phoItr->superCluster(), 5, 0));
0112 
0113     iso.trackIsoR1PtCut20(TxC.getBkgSubTrackIso(*phoItr, 1, 2));
0114     iso.trackIsoR2PtCut20(TxC.getBkgSubTrackIso(*phoItr, 2, 2));
0115     iso.trackIsoR3PtCut20(TxC.getBkgSubTrackIso(*phoItr, 3, 2));
0116     iso.trackIsoR4PtCut20(TxC.getBkgSubTrackIso(*phoItr, 4, 2));
0117     iso.trackIsoR5PtCut20(TxC.getBkgSubTrackIso(*phoItr, 5, 2));
0118 
0119     // ecal spike rejection info (seed timing)
0120     const reco::CaloClusterPtr seed = phoItr->superCluster()->seed();
0121     const DetId& id = lazyTool.getMaximum(*seed).first;
0122     float time = -999.;
0123     const EcalRecHitCollection& rechits = (phoItr->isEB() ? *barrelEcalHits : *endcapEcalHits);
0124     EcalRecHitCollection::const_iterator it = rechits.find(id);
0125     if (it != rechits.end()) {
0126       time = it->time();
0127     }
0128     iso.seedTime(time);
0129 
0130     // ecal spike rejectino info (swiss cross)
0131     float eMax = lazyTool.eMax(*seed);
0132     float eRight = lazyTool.eRight(*seed);
0133     float eLeft = lazyTool.eLeft(*seed);
0134     float eTop = lazyTool.eTop(*seed);
0135     float eBottom = lazyTool.eBottom(*seed);
0136     iso.swissCrx(1 - (eRight + eLeft + eTop + eBottom) / eMax);
0137 
0138     isoVector.push_back(iso);
0139   }
0140   filler.insert(photons, isoVector.begin(), isoVector.end());
0141   filler.fill();
0142   evt.put(std::move(outputMap));
0143 }
0144 
0145 void photonIsolationHIProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0146   edm::ParameterSetDescription desc;
0147 
0148   desc.add<edm::InputTag>("photonProducer", edm::InputTag("photons"));
0149   desc.add<edm::InputTag>("ebRecHitCollection", edm::InputTag("ecalRecHit:EcalRecHitsEB"));
0150   desc.add<edm::InputTag>("eeRecHitCollection", edm::InputTag("ecalRecHit:EcalRecHitsEE"));
0151   desc.add<edm::InputTag>("hbhe", edm::InputTag("hbhereco"));
0152   desc.add<edm::InputTag>("hf", edm::InputTag("hfreco"));
0153   desc.add<edm::InputTag>("ho", edm::InputTag("horeco"));
0154   desc.add<edm::InputTag>("basicClusterBarrel", edm::InputTag("islandBasicClusters:islandBarrelBasicClusters"));
0155   desc.add<edm::InputTag>("basicClusterEndcap", edm::InputTag("islandBasicClusters:islandEndcapBasicClusters"));
0156   desc.add<edm::InputTag>("trackCollection", edm::InputTag("hiGeneralTracks"));
0157   desc.add<std::string>("trackQuality", "highPurity");
0158 
0159   descriptions.add("photonIsolationHIProducer", desc);
0160 }
0161 
0162 DEFINE_FWK_MODULE(photonIsolationHIProducer);