CMS 3D CMS Logo

ElectronPFIsolationWithConeVeto.cc
Go to the documentation of this file.
2 
5 
8 
11 
13 
16 
19 
22 
24 
25 #include <unordered_map>
26 
27 namespace reco {
29 }
30 
31 namespace pat {
33 }
34 
36 public:
39  _vetoConeSize2EB(std::pow(c.getParameter<double>("VetoConeSizeBarrel"), 2.0)),
40  _vetoConeSize2EE(std::pow(c.getParameter<double>("VetoConeSizeEndcaps"), 2.0)),
41  _miniAODVertexCodes(c.getParameter<std::vector<unsigned> >("miniAODVertexCodes")),
42  _isolateAgainst(c.getParameter<std::string>("isolateAgainst")) {
43  char buf[50];
44  sprintf(buf, "BarVeto%.2f-EndVeto%.2f", std::sqrt(_vetoConeSize2EB), std::sqrt(_vetoConeSize2EE));
46  auto decimal = _additionalCode.find('.');
47  while (decimal != std::string::npos) {
48  _additionalCode.erase(decimal, 1);
49  decimal = _additionalCode.find('.');
50  }
51  }
54 
56 
57  bool isInIsolationCone(const reco::CandidatePtr& physob, const reco::CandidatePtr& other) const final;
58 
61 
62 private:
64  const std::vector<unsigned> _miniAODVertexCodes;
67 };
68 
71  "ElectronPFIsolationWithConeVeto");
72 
74  const reco::CandidatePtr& iso_obj) const {
75  reco::GsfElectronPtr eleref(physob);
76  pat::PackedCandidatePtr aspacked(iso_obj);
77  reco::PFCandidatePtr aspf(iso_obj);
78  const reco::CaloClusterPtr& seed = eleref->superCluster()->seed();
79  bool isEB = (seed->seed().subdetId() == EcalBarrel);
80  const float deltar2 = reco::deltaR2(*physob, *iso_obj);
81  const float vetoConeSize2 = (isEB ? _vetoConeSize2EB : _vetoConeSize2EE);
82  bool result = true;
83  if (aspacked.isNonnull() && aspacked.get()) {
84  if (aspacked->charge() != 0) {
85  bool is_vertex_allowed = false;
86  for (const unsigned vtxtype : _miniAODVertexCodes) {
87  if (vtxtype == aspacked->fromPV()) {
88  is_vertex_allowed = true;
89  break;
90  }
91  }
92  result = result && (is_vertex_allowed);
93  }
94  result = result && (deltar2 > vetoConeSize2 && deltar2 < _coneSize2);
95  } else if (aspf.isNonnull() && aspf.get()) {
96  result = result && (deltar2 > vetoConeSize2 && deltar2 < _coneSize2);
97  } else {
98  throw cms::Exception("InvalidIsolationInput") << "The supplied candidate to be used as isolation "
99  << "was neither a reco::PFCandidate nor a pat::PackedCandidate!";
100  }
101  return result;
102 }
IsolationConeDefinitionBase(const edm::ParameterSet &c)
ElectronPFIsolationWithConeVeto & operator=(const ElectronPFIsolationWithConeVeto &)=delete
bool isInIsolationCone(const reco::CandidatePtr &physob, const reco::CandidatePtr &other) const final
edm::EDGetTokenT< reco::VertexCollection > _vtxToken
edm::Ptr< reco::GsfElectron > GsfElectronPtr
edm::Ptr< pat::PackedCandidate > PackedCandidatePtr
Definition: HeavyIon.h:7
T sqrt(T t)
Definition: SSEVec.h:23
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
ElectronPFIsolationWithConeVeto(const edm::ParameterSet &c)
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void setConsumes(edm::ConsumesCollector) override
fixed size matrix
const std::vector< unsigned > _miniAODVertexCodes
#define DEFINE_EDM_PLUGIN(factory, type, name)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:155