Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:54

0001 #include "RecoTauTag/RecoTau/interface/pfRecoTauChargedHadronAuxFunctions.h"
0002 
0003 #include "DataFormats/Candidate/interface/Candidate.h"
0004 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0005 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0006 
0007 #include <TMath.h>
0008 
0009 namespace reco {
0010   namespace tau {
0011 
0012     const reco::Track* getTrackFromChargedHadron(const reco::PFRecoTauChargedHadron& chargedHadron) {
0013       // Charged hadron made from track (reco::Track) - RECO/AOD only
0014       if (chargedHadron.getTrack().isNonnull()) {
0015         return chargedHadron.getTrack().get();
0016       }
0017       // In MiniAOD, even isolated tracks are saved as candidates, so the track Ptr doesn't exist
0018       const pat::PackedCandidate* chargedPFPCand =
0019           dynamic_cast<const pat::PackedCandidate*>(chargedHadron.getChargedPFCandidate().get());
0020       if (chargedPFPCand != nullptr) {
0021         return chargedPFPCand->bestTrack();
0022       }
0023       const pat::PackedCandidate* lostTrackCand =
0024           dynamic_cast<const pat::PackedCandidate*>(chargedHadron.getLostTrackCandidate().get());
0025       if (lostTrackCand != nullptr) {
0026         return lostTrackCand->bestTrack();
0027       }
0028       return nullptr;
0029     }
0030 
0031     void setChargedHadronP4(reco::PFRecoTauChargedHadron& chargedHadron, double scaleFactor_neutralPFCands) {
0032       double chargedHadronP = 0.;
0033       double chargedHadronPx = 0.;
0034       double chargedHadronPy = 0.;
0035       double chargedHadronPz = 0.;
0036       double SumNeutrals = 0.;
0037       if (chargedHadron.algoIs(reco::PFRecoTauChargedHadron::kChargedPFCandidate) ||
0038           chargedHadron.algoIs(reco::PFRecoTauChargedHadron::kPFNeutralHadron)) {
0039         const reco::CandidatePtr& chargedPFCand = chargedHadron.getChargedPFCandidate();
0040         assert(chargedPFCand.isNonnull());
0041         chargedHadronP += chargedPFCand->p();
0042         chargedHadronPx = chargedPFCand->px();
0043         chargedHadronPy = chargedPFCand->py();
0044         chargedHadronPz = chargedPFCand->pz();
0045       } else if (chargedHadron.algoIs(reco::PFRecoTauChargedHadron::kTrack)) {
0046         const reco::Track* track = getTrackFromChargedHadron(chargedHadron);
0047         if (track != nullptr) {
0048           chargedHadronP += track->p();
0049           chargedHadronPx = track->px();
0050           chargedHadronPy = track->py();
0051           chargedHadronPz = track->pz();
0052         } else {  // lost tracks from MiniAOD that don't have track information saved
0053           const reco::CandidatePtr& lostTrack = chargedHadron.getLostTrackCandidate();
0054           assert(lostTrack.isNonnull());
0055           chargedHadronP += lostTrack->p();
0056           chargedHadronPx = lostTrack->px();
0057           chargedHadronPy = lostTrack->py();
0058           chargedHadronPz = lostTrack->pz();
0059         }
0060       } else
0061         assert(0);
0062       const std::vector<reco::CandidatePtr>& neutralPFCands = chargedHadron.getNeutralPFCandidates();
0063       for (std::vector<reco::CandidatePtr>::const_iterator neutralPFCand = neutralPFCands.begin();
0064            neutralPFCand != neutralPFCands.end();
0065            ++neutralPFCand) {
0066         SumNeutrals += (*neutralPFCand)->p();
0067       }
0068       double noNeutrals = chargedHadronP;
0069       chargedHadronP += scaleFactor_neutralPFCands * SumNeutrals;
0070       double ptRatio = chargedHadronP / noNeutrals;
0071       chargedHadronPx *= ptRatio;
0072       chargedHadronPy *= ptRatio;
0073       chargedHadronPz *= ptRatio;
0074 
0075       reco::Candidate::LorentzVector chargedHadronP4 =
0076           compChargedHadronP4fromPxPyPz(chargedHadronPx, chargedHadronPy, chargedHadronPz);
0077       chargedHadron.setP4(chargedHadronP4);
0078     }
0079 
0080     reco::Candidate::LorentzVector compChargedHadronP4fromPxPyPz(double chargedHadronPx,
0081                                                                  double chargedHadronPy,
0082                                                                  double chargedHadronPz) {
0083       const double chargedPionMass = 0.13957;  // GeV
0084       double chargedHadronEn = sqrt(chargedHadronPx * chargedHadronPx + chargedHadronPy * chargedHadronPy +
0085                                     chargedHadronPz * chargedHadronPz + chargedPionMass * chargedPionMass);
0086       reco::Candidate::LorentzVector chargedHadronP4(
0087           chargedHadronPx, chargedHadronPy, chargedHadronPz, chargedHadronEn);
0088       return chargedHadronP4;
0089     }
0090 
0091     reco::Candidate::LorentzVector compChargedHadronP4fromPThetaPhi(double chargedHadronP,
0092                                                                     double chargedHadronTheta,
0093                                                                     double chargedHadronPhi) {
0094       double chargedHadronPx = chargedHadronP * TMath::Cos(chargedHadronPhi) * TMath::Sin(chargedHadronTheta);
0095       double chargedHadronPy = chargedHadronP * TMath::Sin(chargedHadronPhi) * TMath::Sin(chargedHadronTheta);
0096       double chargedHadronPz = chargedHadronP * TMath::Cos(chargedHadronTheta);
0097       return compChargedHadronP4fromPxPyPz(chargedHadronPx, chargedHadronPy, chargedHadronPz);
0098     }
0099 
0100   }  // namespace tau
0101 }  // namespace reco