Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:51

0001 #include "L3MuonSumCaloPFIsolationProducer.h"
0002 
0003 // Framework
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/ConsumesCollector.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 #include "DataFormats/Common/interface/AssociationMap.h"
0014 #include "DataFormats/TrackReco/interface/Track.h"
0015 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0016 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0017 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0018 
0019 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateIsolation.h"
0020 
0021 #include "DataFormats/Common/interface/ValueMap.h"
0022 
0023 #include <string>
0024 
0025 using namespace edm;
0026 using namespace std;
0027 using namespace reco;
0028 
0029 /// constructor with config
0030 L3MuonSumCaloPFIsolationProducer::L3MuonSumCaloPFIsolationProducer(const edm::ParameterSet& config) {
0031   recoChargedCandidateProducer_ = consumes<reco::RecoChargedCandidateCollection>(
0032       config.getParameter<edm::InputTag>("recoChargedCandidateProducer"));
0033   pfEcalClusterProducer_ =
0034       consumes<reco::RecoChargedCandidateIsolationMap>(config.getParameter<edm::InputTag>("pfEcalClusterProducer"));
0035   pfHcalClusterProducer_ =
0036       consumes<reco::RecoChargedCandidateIsolationMap>(config.getParameter<edm::InputTag>("pfHcalClusterProducer"));
0037 
0038   produces<edm::ValueMap<float>>();
0039 }
0040 
0041 L3MuonSumCaloPFIsolationProducer::~L3MuonSumCaloPFIsolationProducer() {}
0042 
0043 void L3MuonSumCaloPFIsolationProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0044   edm::ParameterSetDescription desc;
0045   desc.add<edm::InputTag>("recoChargedCandidateProducer", edm::InputTag("hltL1SeededRecoChargedCandidatePF"));
0046   desc.add<edm::InputTag>("pfEcalClusterProducer", edm::InputTag("hltParticleFlowClusterECAL"));
0047   desc.add<edm::InputTag>("pfHcalClusterProducer", edm::InputTag("hltParticleFlowClusterHCAL"));
0048   descriptions.add(("hltL3MuonSumCaloPFIsolationProducer"), desc);
0049 }
0050 
0051 void L3MuonSumCaloPFIsolationProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0052   edm::Handle<reco::RecoChargedCandidateCollection> recochargedcandHandle;
0053   iEvent.getByToken(recoChargedCandidateProducer_, recochargedcandHandle);
0054 
0055   edm::Handle<reco::RecoChargedCandidateIsolationMap> ecalIsolation;
0056   iEvent.getByToken(pfEcalClusterProducer_, ecalIsolation);
0057 
0058   edm::Handle<reco::RecoChargedCandidateIsolationMap> hcalIsolation;
0059   iEvent.getByToken(pfHcalClusterProducer_, hcalIsolation);
0060 
0061   auto caloIsoMap = std::make_unique<edm::ValueMap<float>>();
0062   std::vector<float> isoFloats(recochargedcandHandle->size(), 0);
0063 
0064   for (unsigned int iReco = 0; iReco < recochargedcandHandle->size(); iReco++) {
0065     reco::RecoChargedCandidateRef candRef(recochargedcandHandle, iReco);
0066     reco::RecoChargedCandidateIsolationMap::const_iterator mapiECAL = (*ecalIsolation).find(candRef);
0067     float valisoECAL = mapiECAL->val;
0068     reco::RecoChargedCandidateIsolationMap::const_iterator mapiHCAL = (*hcalIsolation).find(candRef);
0069     float valisoHCAL = mapiHCAL->val;
0070     float caloIso = valisoECAL + valisoHCAL;
0071     isoFloats[iReco] = caloIso;
0072   }
0073 
0074   edm::ValueMap<float>::Filler isoFloatFiller(*caloIsoMap);
0075   isoFloatFiller.insert(recochargedcandHandle, isoFloats.begin(), isoFloats.end());
0076   isoFloatFiller.fill();
0077   iEvent.put(std::move(caloIsoMap));
0078 }