CMS 3D CMS Logo

PhotonPFIsolationWithConeVeto.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  _vertexIndex(c.getParameter<int> ("vertexIndex")),
44  _isolateAgainst(c.getParameter<std::string>("isolateAgainst")) {
45  char buf[50];
46  sprintf(buf,"BarVeto%.2f-EndVeto%.2f",
47  std::sqrt(_vetoConeSize2EB),
48  std::sqrt(_vetoConeSize2EE));
49  _additionalCode = std::string(buf);
50  auto decimal = _additionalCode.find('.');
51  while( decimal != std::string::npos ) {
52  _additionalCode.erase(decimal,1);
53  decimal = _additionalCode.find('.');
54  }
55  }
58 
60 
61  bool isInIsolationCone(const reco::CandidatePtr& photon,
62  const reco::CandidatePtr& pfCandidate) const final;
63 
66 
67 private:
68  const float _vetoConeSize2EB, _vetoConeSize2EE;
69  const std::vector<unsigned> _miniAODVertexCodes;
70  const unsigned _vertexIndex;
73 };
74 
77  "PhotonPFIsolationWithConeVeto");
78 
81  const reco::CandidatePtr& pfCandidate ) const {
82  reco::recoPhotonPtr photonref(photon);
83  pat::PackedCandidatePtr aspacked(pfCandidate);
84  reco::PFCandidatePtr aspf(pfCandidate);
85  const reco::CaloClusterPtr& seed = photonref->superCluster()->seed();
86  bool isEB = ( seed->seed().subdetId() == EcalBarrel );
87  const float deltar2 = reco::deltaR2(*photon,*pfCandidate);
88  const float vetoConeSize2 = ( isEB ? _vetoConeSize2EB : _vetoConeSize2EE );
89  bool result = true;
90  if( aspacked.isNonnull() && aspacked.get() ) {
91  if( aspacked->charge() != 0 ) {
92  bool is_vertex_allowed = false;
93  for( const unsigned vtxtype : _miniAODVertexCodes ) {
94  if( vtxtype == aspacked->fromPV(_vertexIndex) ) {
95  is_vertex_allowed = true;
96  break;
97  }
98  }
99  result &= ( is_vertex_allowed );
100  }
101  result &= deltar2 > vetoConeSize2 && deltar2 < _coneSize2 ;
102  } else if ( aspf.isNonnull() && aspf.get() ) {
103  result &= deltar2 > vetoConeSize2 && deltar2 < _coneSize2;
104  } else {
105  throw cms::Exception("InvalidIsolationInput")
106  << "The supplied candidate to be used as isolation "
107  << "was neither a reco::PFCandidate nor a pat::PackedCandidate!";
108  }
109  return result;
110 }
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
const std::vector< unsigned > _miniAODVertexCodes
bool isInIsolationCone(const reco::CandidatePtr &photon, const reco::CandidatePtr &pfCandidate) const final
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
edm::Ptr< pat::PackedCandidate > PackedCandidatePtr
Definition: HeavyIon.h:7
void setConsumes(edm::ConsumesCollector) override
int charge() const override
electric charge
const PVAssoc fromPV(size_t ipv=0) const
T sqrt(T t)
Definition: SSEVec.h:18
edm::EDGetTokenT< reco::VertexCollection > _vtxToken
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
edm::Ptr< reco::Photon > recoPhotonPtr
~PhotonPFIsolationWithConeVeto() override
Destructor.
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
fixed size matrix
#define DEFINE_EDM_PLUGIN(factory, type, name)
PhotonPFIsolationWithConeVeto(const edm::ParameterSet &c)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40