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 {
17  namespace tau {
18 
19  namespace {
20  // Re-implemented from PFCandidate.cc
21  int translateTypeToAbsPdgId(int type) {
22  switch (type) {
24  return 211; // pi+
26  return 11;
28  return 13;
30  return 22;
32  return 130; // K_L0
34  return 1; // dummy pdg code
36  return 2; // dummy pdg code
38  default:
39  return 0;
40  }
41  }
42  } // namespace
43  std::vector<CandidatePtr> flattenPiZeros(const std::vector<RecoTauPiZero>::const_iterator& piZerosBegin,
44  const std::vector<RecoTauPiZero>::const_iterator& piZerosEnd) {
45  std::vector<CandidatePtr> output;
46 
47  for (std::vector<RecoTauPiZero>::const_iterator piZero = piZerosBegin; piZero != piZerosEnd; ++piZero) {
48  for (size_t iDaughter = 0; iDaughter < piZero->numberOfDaughters(); ++iDaughter) {
49  output.push_back(CandidatePtr(piZero->daughterPtr(iDaughter)));
50  }
51  }
52  return output;
53  }
54 
55  std::vector<CandidatePtr> flattenPiZeros(const std::vector<RecoTauPiZero>& piZeros) {
56  return flattenPiZeros(piZeros.begin(), piZeros.end());
57  }
58 
59  std::vector<reco::CandidatePtr> pfCandidates(const reco::Jet& jet, int particleId, bool sort) {
60  return pfCandidatesByPdgId(jet, translateTypeToAbsPdgId(particleId), sort);
61  }
62 
63  std::vector<CandidatePtr> pfCandidates(const Jet& jet, const std::vector<int>& particleIds, bool sort) {
64  std::vector<int> pdgIds;
65  for (auto particleId : particleIds)
66  pdgIds.push_back(translateTypeToAbsPdgId(particleId));
67  return pfCandidatesByPdgId(jet, pdgIds, sort);
68  }
69 
70  std::vector<reco::CandidatePtr> pfCandidatesByPdgId(const reco::Jet& jet, int pdgId, bool sort) {
71  CandPtrs pfCands = jet.daughterPtrVector();
72  CandPtrs selectedPFCands = filterPFCandidates(pfCands.begin(), pfCands.end(), pdgId, sort);
73  return selectedPFCands;
74  }
75 
76  std::vector<reco::CandidatePtr> pfCandidatesByPdgId(const reco::Jet& jet,
77  const std::vector<int>& pdgIds,
78  bool sort) {
79  const CandPtrs& pfCands = jet.daughterPtrVector();
81  // Get each desired candidate type, unsorted for now
82  for (std::vector<int>::const_iterator pdgId = pdgIds.begin(); pdgId != pdgIds.end(); ++pdgId) {
83  CandPtrs&& selectedPFCands = filterPFCandidates(pfCands.begin(), pfCands.end(), *pdgId, false);
84  output.insert(output.end(), selectedPFCands.begin(), selectedPFCands.end());
85  }
86  if (sort)
87  std::sort(output.begin(), output.end(), SortPFCandsDescendingPt());
88  return output;
89  }
90 
91  std::vector<reco::CandidatePtr> pfGammas(const reco::Jet& jet, bool sort) { return pfCandidates(jet, 22, sort); }
92 
93  std::vector<reco::CandidatePtr> pfChargedCands(const reco::Jet& jet, bool sort) {
94  const CandPtrs& pfCands = jet.daughterPtrVector();
96  CandPtrs&& mus = filterPFCandidates(pfCands.begin(), pfCands.end(), 13, false);
97  CandPtrs&& es = filterPFCandidates(pfCands.begin(), pfCands.end(), 11, false);
98  CandPtrs&& chs = filterPFCandidates(pfCands.begin(), pfCands.end(), 211, false);
99  output.reserve(mus.size() + es.size() + chs.size());
100  output.insert(output.end(), mus.begin(), mus.end());
101  output.insert(output.end(), es.begin(), es.end());
102  output.insert(output.end(), chs.begin(), chs.end());
103  if (sort)
104  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 
115  RawParticle(math::XYZTLorentzVector(part->px(), part->py(), part->pz(), part->energy()),
116  math::XYZTLorentzVector(part->vertex().x(), part->vertex().y(), part->vertex().z(), 0.)),
117  part->charge(),
118  0.,
119  0.,
120  bField);
121  theParticle.propagateToEcalEntrance(false);
122  if (theParticle.getSuccess() != 0) {
123  pos = math::XYZPointF(theParticle.particle().vertex());
124  }
125  return pos;
126  }
127 
128  } // namespace tau
129 } // namespace reco
reco::tau::pfChargedCands
std::vector< CandidatePtr > pfChargedCands(const Jet &jet, bool sort=true)
Extract all non-neutral candidates from a PFJet.
Definition: RecoTauCommonUtilities.cc:93
RawParticle
Definition: RawParticle.h:37
reco::Jet
Base class for all types of Jets.
Definition: Jet.h:20
BaseParticlePropagator::propagateToEcalEntrance
bool propagateToEcalEntrance(bool first=true)
Definition: BaseParticlePropagator.cc:450
BaseParticlePropagator::particle
RawParticle const & particle() const
The particle being propagated.
Definition: BaseParticlePropagator.h:164
reco::PFCandidate::e
Definition: PFCandidate.h:46
metsig::tau
Definition: SignAlgoResolutions.h:49
PFCandidate.h
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
RawParticle::vertex
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:320
pos
Definition: PixelAliasList.h:18
reco::PFCandidate::positionAtECALEntrance
const math::XYZPointF & positionAtECALEntrance() const
Definition: PFCandidate.h:362
reco::tau::atECALEntrance
math::XYZPointF atECALEntrance(const reco::Candidate *part, double bField)
Definition: RecoTauCommonUtilities.cc:108
reco::PFCandidate::h
Definition: PFCandidate.h:45
BaseParticlePropagator.h
reco::PFCandidate::h_HF
Definition: PFCandidate.h:50
Jet.h
BaseParticlePropagator::getSuccess
int getSuccess() const
Has propagation been performed and was barrel or endcap reached ?
Definition: BaseParticlePropagator.h:296
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
RawParticle::charge
double charge() const
get the MEASURED charge
Definition: RawParticle.h:294
reco::tau::flattenPiZeros
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.
Definition: RecoTauCommonUtilities.cc:43
BaseParticlePropagator
Definition: BaseParticlePropagator.h:82
reco::PFCandidate::X
Definition: PFCandidate.h:44
CandidateFwd.h
part
part
Definition: HCALResponse.h:20
reco::PFCandidate::mu
Definition: PFCandidate.h:47
Jet
Definition: Jet.py:1
RecoTauCommonUtilities.h
reco::tau::SortPFCandsDescendingPt
Definition: RecoTauCommonUtilities.h:33
Vertex.h
reco::tau::pfGammas
std::vector< CandidatePtr > pfGammas(const Jet &jet, bool sort=true)
Extract all pfGammas from a PFJet.
Definition: RecoTauCommonUtilities.cc:91
reco::PFCandidate::egamma_HF
Definition: PFCandidate.h:51
CosmicGenFilterHelix_cfi.pdgIds
pdgIds
Definition: CosmicGenFilterHelix_cfi.py:5
CandPtrs
std::vector< reco::CandidatePtr > CandPtrs
Definition: RecoTauCommonUtilities.cc:13
reco::tau::filterPFCandidates
std::vector< CandidatePtr > filterPFCandidates(const Iterator &begin, const Iterator &end, int pdgId, bool sort=true)
Definition: RecoTauCommonUtilities.h:41
reco::PFCandidate::gamma
Definition: PFCandidate.h:48
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
reco::Candidate
Definition: Candidate.h:27
type
type
Definition: HCALResponse.h:21
reco::tau::pfCandidatesByPdgId
std::vector< CandidatePtr > pfCandidatesByPdgId(const Jet &jet, int pdgId, bool sort=true)
Definition: RecoTauCommonUtilities.cc:70
Calorimetry_cff.bField
bField
Definition: Calorimetry_cff.py:292
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
metsig::jet
Definition: SignAlgoResolutions.h:47
reco::PFCandidate::h0
Definition: PFCandidate.h:49
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
Candidate.h
reco::CandidatePtr
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
reco::tau::pfCandidates
std::vector< CandidatePtr > pfCandidates(const Jet &jet, int particleId, bool sort=true)
Definition: RecoTauCommonUtilities.cc:59
CandIter
CandPtrs::iterator CandIter
Definition: RecoTauCommonUtilities.cc:14
math::XYZPointF
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10