CMS 3D CMS Logo

RecoTauCommonUtilities.cc
Go to the documentation of this file.
2 
8 
10 
11 #include <algorithm>
12 
13 typedef std::vector<reco::CandidatePtr> CandPtrs;
14 typedef CandPtrs::iterator CandIter;
15 
16 namespace reco { namespace tau {
17 
18 namespace {
19  // Re-implemented from PFCandidate.cc
20  int translateTypeToAbsPdgId(int type) {
21  switch( type ) {
22  case reco::PFCandidate::h: return 211; // pi+
23  case reco::PFCandidate::e: return 11;
24  case reco::PFCandidate::mu: return 13;
25  case reco::PFCandidate::gamma: return 22;
26  case reco::PFCandidate::h0: return 130; // K_L0
27  case reco::PFCandidate::h_HF: return 1; // dummy pdg code
28  case reco::PFCandidate::egamma_HF: return 2; // dummy pdg code
30  default: return 0;
31  }
32  }
33 }
34 std::vector<CandidatePtr>
35 flattenPiZeros(const std::vector<RecoTauPiZero>::const_iterator& piZerosBegin, const std::vector<RecoTauPiZero>::const_iterator& piZerosEnd) {
36  std::vector<CandidatePtr> output;
37 
38  for(std::vector<RecoTauPiZero>::const_iterator piZero = piZerosBegin;
39  piZero != piZerosEnd; ++piZero) {
40  for(size_t iDaughter = 0; iDaughter < piZero->numberOfDaughters();
41  ++iDaughter) {
42  output.push_back(CandidatePtr(piZero->daughterPtr(iDaughter)));
43  }
44  }
45  return output;
46 }
47 
48 std::vector<CandidatePtr>
49 flattenPiZeros(const std::vector<RecoTauPiZero>& piZeros) {
50  return flattenPiZeros(piZeros.begin(), piZeros.end());
51 }
52 
53 std::vector<reco::CandidatePtr> pfCandidates(const reco::Jet& jet,
54  int particleId, bool sort) {
55  return pfCandidatesByPdgId(jet, translateTypeToAbsPdgId(particleId), sort);
56 }
57 
58 std::vector<CandidatePtr> pfCandidates(const Jet& jet,
59  const std::vector<int>& particleIds,
60  bool sort) {
61  std::vector<int> pdgIds;
62  for (auto particleId : particleIds)
63  pdgIds.push_back(translateTypeToAbsPdgId(particleId));
64  return pfCandidatesByPdgId(jet, pdgIds, sort);
65 }
66 
67 std::vector<reco::CandidatePtr> pfCandidatesByPdgId(const reco::Jet& jet,
68  int pdgId, bool sort) {
69  CandPtrs pfCands = jet.daughterPtrVector();
70  CandPtrs selectedPFCands = filterPFCandidates(
71  pfCands.begin(), pfCands.end(), pdgId, sort);
72  return selectedPFCands;
73 }
74 
75 std::vector<reco::CandidatePtr> pfCandidatesByPdgId(const reco::Jet& jet,
76  const std::vector<int>& pdgIds, bool sort) {
77  const CandPtrs& pfCands = jet.daughterPtrVector();
79  // Get each desired candidate type, unsorted for now
80  for(std::vector<int>::const_iterator pdgId = pdgIds.begin();
81  pdgId != pdgIds.end(); ++pdgId) {
82  CandPtrs&& selectedPFCands = filterPFCandidates(pfCands.begin(), pfCands.end(), *pdgId, false);
83  output.insert(output.end(), selectedPFCands.begin(), selectedPFCands.end());
84  }
85  if (sort) std::sort(output.begin(), output.end(), SortPFCandsDescendingPt());
86  return output;
87 }
88 
89 std::vector<reco::CandidatePtr> pfGammas(const reco::Jet& jet, bool sort) {
90  return pfCandidates(jet, 22, sort);
91 }
92 
93 std::vector<reco::CandidatePtr> pfChargedCands(const reco::Jet& jet,
94  bool sort) {
95  const CandPtrs& pfCands = jet.daughterPtrVector();
97  CandPtrs&& mus = filterPFCandidates(pfCands.begin(), pfCands.end(), 13, false);
98  CandPtrs&& es = filterPFCandidates(pfCands.begin(), pfCands.end(), 11, false);
99  CandPtrs&& chs = filterPFCandidates(pfCands.begin(), pfCands.end(), 211, false);
100  output.reserve(mus.size() + es.size() + chs.size());
101  output.insert(output.end(), mus.begin(), mus.end());
102  output.insert(output.end(), es.begin(), es.end());
103  output.insert(output.end(), chs.begin(), chs.end());
104  if (sort) std::sort(output.begin(), output.end(), SortPFCandsDescendingPt());
105  return output;
106 }
107 
109  const reco::PFCandidate* pfCand = dynamic_cast<const reco::PFCandidate*>(part);
110  if (pfCand)
111  return pfCand->positionAtECALEntrance();
112 
114  BaseParticlePropagator theParticle =
116  part->py(),
117  part->pz(),
118  part->energy()),
119  math::XYZTLorentzVector(part->vertex().x(),
120  part->vertex().y(),
121  part->vertex().z(),
122  0.)),
123  part->charge(),
124  0.,0.,bField);
125  theParticle.propagateToEcalEntrance(false);
126  if(theParticle.getSuccess()!=0){
127  pos = math::XYZPointF(theParticle.particle().vertex());
128  }
129  return pos;
130 }
131 
132 
133 } }
std::vector< CandidatePtr > pfCandidatesByPdgId(const Jet &jet, int pdgId, bool sort=true)
type
Definition: HCALResponse.h:21
std::vector< CandidatePtr > pfCandidates(const Jet &jet, int particleId, bool sort=true)
virtual double pz() const =0
z coordinate of momentum vector
math::XYZPointF atECALEntrance(const reco::Candidate *part, double bField)
Base class for all types of Jets.
Definition: Jet.h:20
int getSuccess() const
Has propagation been performed and was barrel or endcap reached ?
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
RawParticle const & particle() const
The particle being propagated.
std::vector< CandidatePtr > pfChargedCands(const Jet &jet, bool sort=true)
Extract all non-neutral candidates from a PFJet.
const math::XYZPointF & positionAtECALEntrance() const
Definition: PFCandidate.h:368
virtual const daughters & daughterPtrVector() const
references to daughtes
std::vector< CandidatePtr > flattenPiZeros(const std::vector< RecoTauPiZero >::const_iterator &, const std::vector< RecoTauPiZero >::const_iterator &)
Flatten a list of pi zeros into a list of there constituent PFCandidates.
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual double energy() const =0
energy
virtual double py() const =0
y coordinate of momentum vector
std::vector< reco::CandidatePtr > CandPtrs
Definition: Jet.py:1
bool propagateToEcalEntrance(bool first=true)
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:339
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
part
Definition: HCALResponse.h:20
virtual int charge() const =0
electric charge
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
virtual const Point & vertex() const =0
vertex position
virtual double px() const =0
x coordinate of momentum vector
std::vector< CandidatePtr > filterPFCandidates(const Iterator &begin, const Iterator &end, int pdgId, bool sort=true)
CandPtrs::iterator CandIter
std::vector< CandidatePtr > pfGammas(const Jet &jet, bool sort=true)
Extract all pfGammas from a PFJet.