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/Photon.h"
0010 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.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::Photon> recoPhotonPtr;
0029 }
0030 
0031 namespace pat {
0032   typedef edm::Ptr<pat::PackedCandidate> PackedCandidatePtr;
0033 }
0034 
0035 class PhotonPFIsolationWithConeVeto : public citk::IsolationConeDefinitionBase {
0036 public:
0037   PhotonPFIsolationWithConeVeto(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         _vertexIndex(c.getParameter<int>("vertexIndex")),
0043         _isolateAgainst(c.getParameter<std::string>("isolateAgainst")) {
0044     char buf[50];
0045     sprintf(buf, "BarVeto%.2f-EndVeto%.2f", std::sqrt(_vetoConeSize2EB), std::sqrt(_vetoConeSize2EE));
0046     _additionalCode = std::string(buf);
0047     auto decimal = _additionalCode.find('.');
0048     while (decimal != std::string::npos) {
0049       _additionalCode.erase(decimal, 1);
0050       decimal = _additionalCode.find('.');
0051     }
0052   }
0053   PhotonPFIsolationWithConeVeto(const PhotonPFIsolationWithConeVeto&) = delete;
0054   PhotonPFIsolationWithConeVeto& operator=(const PhotonPFIsolationWithConeVeto&) = delete;
0055 
0056   void setConsumes(edm::ConsumesCollector) override {}
0057 
0058   bool isInIsolationCone(const reco::CandidatePtr& photon, const reco::CandidatePtr& pfCandidate) const final;
0059 
0060   //! Destructor
0061   ~PhotonPFIsolationWithConeVeto() override{};
0062 
0063 private:
0064   const float _vetoConeSize2EB, _vetoConeSize2EE;
0065   const std::vector<unsigned> _miniAODVertexCodes;
0066   const unsigned _vertexIndex;
0067   const std::string _isolateAgainst;
0068   edm::EDGetTokenT<reco::VertexCollection> _vtxToken;
0069 };
0070 
0071 DEFINE_EDM_PLUGIN(CITKIsolationConeDefinitionFactory, PhotonPFIsolationWithConeVeto, "PhotonPFIsolationWithConeVeto");
0072 
0073 bool PhotonPFIsolationWithConeVeto::isInIsolationCone(const reco::CandidatePtr& photon,
0074                                                       const reco::CandidatePtr& pfCandidate) const {
0075   reco::recoPhotonPtr photonref(photon);
0076   pat::PackedCandidatePtr aspacked(pfCandidate);
0077   reco::PFCandidatePtr aspf(pfCandidate);
0078   const reco::CaloClusterPtr& seed = photonref->superCluster()->seed();
0079   bool isEB = (seed->seed().subdetId() == EcalBarrel);
0080   const float deltar2 = reco::deltaR2(*photon, *pfCandidate);
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(_vertexIndex)) {
0088           is_vertex_allowed = true;
0089           break;
0090         }
0091       }
0092       result &= (is_vertex_allowed);
0093     }
0094     result &= deltar2 > vetoConeSize2 && deltar2 < _coneSize2;
0095   } else if (aspf.isNonnull() && aspf.get()) {
0096     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 }