File indexing completed on 2024-09-07 04:37:47
0001 #include "PhysicsTools/IsolationAlgos/interface/CITKIsolationConeDefinitionBase.h"
0002
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Framework/interface/ConsumesCollector.h"
0005 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0006 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0007 #include "DataFormats/Math/interface/deltaR.h"
0008
0009 namespace pat {
0010 typedef edm::Ptr<pat::PackedCandidate> PackedCandidatePtr;
0011 }
0012
0013 class MuonPFIsolationWithConeVeto : public citk::IsolationConeDefinitionBase {
0014 public:
0015 MuonPFIsolationWithConeVeto(const edm::ParameterSet& c)
0016 : citk::IsolationConeDefinitionBase(c),
0017 _vetoThreshold(c.getParameter<double>("VetoThreshold")),
0018 _vetoConeSize2(std::pow(c.getParameter<double>("VetoConeSize"), 2.0)),
0019 _miniAODVertexCodes(c.getParameter<std::vector<unsigned> >("miniAODVertexCodes")) {
0020 char buf[50];
0021 snprintf(buf, 49, "ThresholdVeto%03.0f-ConeVeto%03.0f", 100 * _vetoThreshold, 100 * std::sqrt(_vetoConeSize2));
0022 _additionalCode = std::string(buf);
0023 }
0024 MuonPFIsolationWithConeVeto(const MuonPFIsolationWithConeVeto&) = delete;
0025 MuonPFIsolationWithConeVeto& operator=(const MuonPFIsolationWithConeVeto&) = delete;
0026
0027 void setConsumes(edm::ConsumesCollector) override {}
0028
0029 bool isInIsolationCone(const reco::CandidatePtr& physob, const reco::CandidatePtr& other) const final;
0030
0031
0032 ~MuonPFIsolationWithConeVeto() override {}
0033
0034 private:
0035 const double _vetoThreshold, _vetoConeSize2;
0036 const std::vector<unsigned> _miniAODVertexCodes;
0037 edm::EDGetTokenT<reco::VertexCollection> _vtxToken;
0038 };
0039
0040 DEFINE_EDM_PLUGIN(CITKIsolationConeDefinitionFactory, MuonPFIsolationWithConeVeto, "MuonPFIsolationWithConeVeto");
0041
0042 bool MuonPFIsolationWithConeVeto::isInIsolationCone(const reco::CandidatePtr& physob,
0043 const reco::CandidatePtr& iso_obj) const {
0044 if (iso_obj->pt() <= _vetoThreshold)
0045 return false;
0046 const double deltar2 = reco::deltaR2(*physob, *iso_obj);
0047 if (deltar2 <= _vetoConeSize2 || deltar2 >= _coneSize2)
0048 return false;
0049
0050
0051 const pat::PackedCandidatePtr aspacked(iso_obj);
0052 const reco::PFCandidatePtr aspf(iso_obj);
0053
0054 bool result = true;
0055 if (aspacked.isNonnull() && aspacked.get()) {
0056 if (aspacked->charge() != 0) {
0057 bool is_vertex_allowed = false;
0058 for (const unsigned vtxtype : _miniAODVertexCodes) {
0059 if (vtxtype == aspacked->fromPV()) {
0060 is_vertex_allowed = true;
0061 break;
0062 }
0063 }
0064 result = result && (is_vertex_allowed);
0065 }
0066 } else if (aspf.isNonnull() && aspf.get()) {
0067 } else {
0068 throw cms::Exception("InvalidIsolationInput") << "The supplied candidate to be used as isolation "
0069 << "was neither a reco::PFCandidate nor a pat::PackedCandidate!";
0070 }
0071 return result;
0072 }