CMS 3D CMS Logo

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