Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:11

0001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0002 
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 
0006 #include "DataFormats/Candidate/interface/Candidate.h"
0007 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0008 
0009 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0010 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0011 
0012 #include "FWCore/Framework/interface/ConsumesCollector.h"
0013 
0014 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0015 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0016 
0017 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositVetoFactory.h"
0018 #include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
0019 
0020 #include "PhysicsTools/IsolationAlgos/interface/CITKIsolationConeDefinitionBase.h"
0021 #include "DataFormats/Math/interface/deltaR.h"
0022 
0023 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0024 
0025 #include <unordered_map>
0026 
0027 namespace reco {
0028   typedef edm::Ptr<reco::GsfElectron> GsfElectronPtr;
0029 }
0030 
0031 namespace pat {
0032   typedef edm::Ptr<pat::PackedCandidate> PackedCandidatePtr;
0033 }
0034 
0035 class ElectronPFIsolationWithConeVeto : public citk::IsolationConeDefinitionBase {
0036 public:
0037   ElectronPFIsolationWithConeVeto(const edm::ParameterSet& c)
0038       : citk::IsolationConeDefinitionBase(c),
0039         _vetoConeSize2EB(std::pow(c.getParameter<double>("VetoConeSizeBarrel"), 2.0)),
0040         _vetoConeSize2EE(std::pow(c.getParameter<double>("VetoConeSizeEndcaps"), 2.0)),
0041         _miniAODVertexCodes(c.getParameter<std::vector<unsigned> >("miniAODVertexCodes")),
0042         _isolateAgainst(c.getParameter<std::string>("isolateAgainst")) {
0043     char buf[50];
0044     sprintf(buf, "BarVeto%.2f-EndVeto%.2f", std::sqrt(_vetoConeSize2EB), std::sqrt(_vetoConeSize2EE));
0045     _additionalCode = std::string(buf);
0046     auto decimal = _additionalCode.find('.');
0047     while (decimal != std::string::npos) {
0048       _additionalCode.erase(decimal, 1);
0049       decimal = _additionalCode.find('.');
0050     }
0051   }
0052   ElectronPFIsolationWithConeVeto(const ElectronPFIsolationWithConeVeto&) = delete;
0053   ElectronPFIsolationWithConeVeto& operator=(const ElectronPFIsolationWithConeVeto&) = delete;
0054 
0055   void setConsumes(edm::ConsumesCollector) override {}
0056 
0057   bool isInIsolationCone(const reco::CandidatePtr& physob, const reco::CandidatePtr& other) const final;
0058 
0059   //! Destructor
0060   ~ElectronPFIsolationWithConeVeto() override{};
0061 
0062 private:
0063   const float _vetoConeSize2EB, _vetoConeSize2EE;
0064   const std::vector<unsigned> _miniAODVertexCodes;
0065   const std::string _isolateAgainst;
0066   edm::EDGetTokenT<reco::VertexCollection> _vtxToken;
0067 };
0068 
0069 DEFINE_EDM_PLUGIN(CITKIsolationConeDefinitionFactory,
0070                   ElectronPFIsolationWithConeVeto,
0071                   "ElectronPFIsolationWithConeVeto");
0072 
0073 bool ElectronPFIsolationWithConeVeto::isInIsolationCone(const reco::CandidatePtr& physob,
0074                                                         const reco::CandidatePtr& iso_obj) const {
0075   reco::GsfElectronPtr eleref(physob);
0076   pat::PackedCandidatePtr aspacked(iso_obj);
0077   reco::PFCandidatePtr aspf(iso_obj);
0078   const reco::CaloClusterPtr& seed = eleref->superCluster()->seed();
0079   bool isEB = (seed->seed().subdetId() == EcalBarrel);
0080   const float deltar2 = reco::deltaR2(*physob, *iso_obj);
0081   const float vetoConeSize2 = (isEB ? _vetoConeSize2EB : _vetoConeSize2EE);
0082   bool result = true;
0083   if (aspacked.isNonnull() && aspacked.get()) {
0084     if (aspacked->charge() != 0) {
0085       bool is_vertex_allowed = false;
0086       for (const unsigned vtxtype : _miniAODVertexCodes) {
0087         if (vtxtype == aspacked->fromPV()) {
0088           is_vertex_allowed = true;
0089           break;
0090         }
0091       }
0092       result = result && (is_vertex_allowed);
0093     }
0094     result = result && (deltar2 > vetoConeSize2 && deltar2 < _coneSize2);
0095   } else if (aspf.isNonnull() && aspf.get()) {
0096     result = result && (deltar2 > vetoConeSize2 && deltar2 < _coneSize2);
0097   } else {
0098     throw cms::Exception("InvalidIsolationInput") << "The supplied candidate to be used as isolation "
0099                                                   << "was neither a reco::PFCandidate nor a pat::PackedCandidate!";
0100   }
0101   return result;
0102 }