CMS 3D CMS Logo

pfRecoTauChargedHadronAuxFunctions.cc
Go to the documentation of this file.
2 
6 
7 #include <TMath.h>
8 
9 namespace reco { namespace tau {
10 
12  // Charged hadron made from track (reco::Track) - RECO/AOD only
13  if ( chargedHadron.getTrack().isNonnull()) {
14  return chargedHadron.getTrack().get();
15  }
16  // In MiniAOD, even isolated tracks are saved as candidates, so the track Ptr doesn't exist
17  const pat::PackedCandidate* chargedPFPCand = dynamic_cast<const pat::PackedCandidate*> (chargedHadron.getChargedPFCandidate().get());
18  if (chargedPFPCand != nullptr) {
19  return chargedPFPCand->bestTrack();
20  }
21  const pat::PackedCandidate* lostTrackCand = dynamic_cast<const pat::PackedCandidate*> (chargedHadron.getLostTrackCandidate().get());
22  if (lostTrackCand != nullptr) {
23  return lostTrackCand->bestTrack();
24  }
25  return nullptr;
26 }
27 
28 void setChargedHadronP4(reco::PFRecoTauChargedHadron& chargedHadron, double scaleFactor_neutralPFCands)
29 {
30  double chargedHadronP = 0.;
31  double chargedHadronPx = 0.;
32  double chargedHadronPy = 0.;
33  double chargedHadronPz = 0.;
34  double SumNeutrals = 0.;
37  const reco::CandidatePtr& chargedPFCand = chargedHadron.getChargedPFCandidate();
38  assert(chargedPFCand.isNonnull());
39  chargedHadronP += chargedPFCand->p();
40  chargedHadronPx = chargedPFCand->px();
41  chargedHadronPy = chargedPFCand->py();
42  chargedHadronPz = chargedPFCand->pz();
43  } else if ( chargedHadron.algoIs(reco::PFRecoTauChargedHadron::kTrack) ) {
44  const reco::Track* track = getTrackFromChargedHadron(chargedHadron);
45  if (track != nullptr) {
46  chargedHadronP += track->p();
47  chargedHadronPx = track->px();
48  chargedHadronPy = track->py();
49  chargedHadronPz = track->pz();
50  } else { // lost tracks from MiniAOD that don't have track information saved
51  const reco::CandidatePtr& lostTrack = chargedHadron.getLostTrackCandidate();
52  assert(lostTrack.isNonnull());
53  chargedHadronP += lostTrack->p();
54  chargedHadronPx = lostTrack->px();
55  chargedHadronPy = lostTrack->py();
56  chargedHadronPz = lostTrack->pz();
57  }
58  } else assert(0);
59  const std::vector<reco::CandidatePtr>& neutralPFCands = chargedHadron.getNeutralPFCandidates();
60  for ( std::vector<reco::CandidatePtr>::const_iterator neutralPFCand = neutralPFCands.begin();
61  neutralPFCand != neutralPFCands.end(); ++neutralPFCand ) {
62  SumNeutrals += (*neutralPFCand)->p();
63  }
64  double noNeutrals=chargedHadronP;
65  chargedHadronP+=scaleFactor_neutralPFCands*SumNeutrals;
66  double ptRatio=chargedHadronP/noNeutrals;
67  chargedHadronPx*=ptRatio;
68  chargedHadronPy*=ptRatio;
69  chargedHadronPz*=ptRatio;
70 
71 
72  reco::Candidate::LorentzVector chargedHadronP4 = compChargedHadronP4fromPxPyPz(chargedHadronPx, chargedHadronPy, chargedHadronPz);
73  chargedHadron.setP4(chargedHadronP4);
74 }
75 
76 reco::Candidate::LorentzVector compChargedHadronP4fromPxPyPz(double chargedHadronPx, double chargedHadronPy, double chargedHadronPz)
77 {
78  const double chargedPionMass = 0.13957; // GeV
79  double chargedHadronEn = sqrt(chargedHadronPx*chargedHadronPx + chargedHadronPy*chargedHadronPy + chargedHadronPz*chargedHadronPz + chargedPionMass*chargedPionMass);
80  reco::Candidate::LorentzVector chargedHadronP4(chargedHadronPx, chargedHadronPy, chargedHadronPz, chargedHadronEn);
81  return chargedHadronP4;
82 }
83 
84 reco::Candidate::LorentzVector compChargedHadronP4fromPThetaPhi(double chargedHadronP, double chargedHadronTheta, double chargedHadronPhi)
85 {
86  double chargedHadronPx = chargedHadronP*TMath::Cos(chargedHadronPhi)*TMath::Sin(chargedHadronTheta);
87  double chargedHadronPy = chargedHadronP*TMath::Sin(chargedHadronPhi)*TMath::Sin(chargedHadronTheta);
88  double chargedHadronPz = chargedHadronP*TMath::Cos(chargedHadronTheta);
89  return compChargedHadronP4fromPxPyPz(chargedHadronPx, chargedHadronPy, chargedHadronPz);
90 }
91 
92 }} // end namespace reco::tau
double p() const
momentum vector magnitude
Definition: TrackBase.h:654
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:666
const reco::Track * bestTrack() const override
return a pointer to the track if present. otherwise, return a null pointer
T sqrt(T t)
Definition: SSEVec.h:18
const TrackPtr & getTrack() const
reference to reco::Track
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:678
reco::Candidate::LorentzVector compChargedHadronP4fromPThetaPhi(double, double, double)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
const reco::Track * getTrackFromChargedHadron(const reco::PFRecoTauChargedHadron &chargedHadron)
fixed size matrix
bool algoIs(PFRecoTauChargedHadronAlgorithm algo) const
Check whether a given algo produced this charged hadron.
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)
const CandidatePtr & getChargedPFCandidate() const
reference to "charged" PFCandidate (either charged PFCandidate or PFNeutralHadron) ...
void setP4(const LorentzVector &p4) final
set 4-momentum
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:672
const std::vector< CandidatePtr > & getNeutralPFCandidates() const
references to additional neutral PFCandidates
const CandidatePtr & getLostTrackCandidate() const
reference to "lostTrack Candidate" when chadron built with tracks stored as pat::PackedCandidates ...
reco::Candidate::LorentzVector compChargedHadronP4fromPxPyPz(double, double, double)