17 bool copyGammasFromPiZeros,
19 double minAbsPhotonSumPt_insideSignalCone,
20 double minRelPhotonSumPt_insideSignalCone,
21 double minAbsPhotonSumPt_outsideSignalCone,
22 double minRelPhotonSumPt_outsideSignalCone)
23 : signalConeSize_(signalConeSize),
24 minAbsPhotonSumPt_insideSignalCone_(minAbsPhotonSumPt_insideSignalCone),
25 minRelPhotonSumPt_insideSignalCone_(minRelPhotonSumPt_insideSignalCone),
26 minAbsPhotonSumPt_outsideSignalCone_(minAbsPhotonSumPt_outsideSignalCone),
27 minRelPhotonSumPt_outsideSignalCone_(minRelPhotonSumPt_outsideSignalCone),
30 tau_ = std::make_unique<PFTau>();
55 LogDebug(
"TauConstructorAddPFCand") <<
" region = " << region <<
", type = " << type <<
": Pt = " << ptr->pt()
56 <<
", eta = " << ptr->eta() <<
", phi = " << ptr->phi();
61 LogDebug(
"TauConstructorAddPFCand") <<
"--> adding PFCand to tauP4.";
80 tau_->signalTauChargedHadronCandidatesRestricted().reserve(size);
81 tau_->selectedSignalChargedHadrCands_.reserve(size);
83 tau_->isolationTauChargedHadronCandidatesRestricted().reserve(size);
84 tau_->selectedIsolationChargedHadrCands_.reserve(size);
90 LogDebug(
"TauConstructorCheckOverlap") <<
" pfGammas: #entries = " << pfGammas.size();
91 for (std::vector<CandidatePtr>::const_iterator
pfGamma = pfGammas.begin();
pfGamma != pfGammas.end(); ++
pfGamma) {
93 if ((*pfGamma).refCore() == neutral.
refCore() && (*pfGamma).key() == neutral.
key())
99 LogDebug(
"TauConstructorCheckOverlap") <<
" piZeros: #entries = " << piZeros.size();
100 for (std::vector<reco::RecoTauPiZero>::const_iterator piZero = piZeros.begin(); piZero != piZeros.end();
102 size_t numPFGammas = piZero->numberOfDaughters();
103 for (
size_t iPFGamma = 0; iPFGamma < numPFGammas; ++iPFGamma) {
105 LogDebug(
"TauConstructorCheckOverlap") <<
"pfGamma = " << pfGamma.
id() <<
":" << pfGamma.
key();
106 if (pfGamma.
id() == neutral.
id() && pfGamma.
key() == neutral.key())
114 LogDebug(
"TauConstructorAddChH") <<
" region = " << region <<
": Pt = " << chargedHadron.
pt()
115 <<
", eta = " << chargedHadron.
eta() <<
", phi = " << chargedHadron.
phi();
118 std::vector<CandidatePtr> neutrals_cleaned;
119 for (std::vector<CandidatePtr>::const_iterator neutral = neutrals.begin(); neutral != neutrals.end(); ++neutral) {
120 LogDebug(
"TauConstructorAddChH") <<
"neutral = " << neutral->id() <<
":" << neutral->key();
121 bool isUnique =
true;
130 checkOverlap(*neutral,
tau_->isolationPiZeroCandidatesRestricted(), isUnique);
132 LogDebug(
"TauConstructorAddChH") <<
"--> isUnique = " << isUnique;
134 neutrals_cleaned.push_back(*neutral);
137 if (neutrals_cleaned.size() != neutrals.size()) {
142 tau_->signalTauChargedHadronCandidatesRestricted().push_back(chargedHadron_cleaned);
143 p4_ += chargedHadron_cleaned.
p4();
148 for (std::vector<CandidatePtr>::const_iterator neutral = neutrals.begin(); neutral != neutrals.end(); ++neutral) {
149 if (
std::abs((*neutral)->pdgId()) == 22)
151 else if (
std::abs((*neutral)->pdgId()) == 130)
155 tau_->isolationTauChargedHadronCandidatesRestricted().push_back(chargedHadron_cleaned);
163 for (std::vector<CandidatePtr>::const_iterator neutral = neutrals.begin(); neutral != neutrals.end(); ++neutral) {
164 if (
std::abs((*neutral)->pdgId()) == 22)
166 else if (
std::abs((*neutral)->pdgId()) == 130)
174 tau_->signalPiZeroCandidatesRestricted().reserve(size);
180 tau_->isolationPiZeroCandidatesRestricted().reserve(size);
187 LogDebug(
"TauConstructorAddPi0") <<
" region = " << region <<
": Pt = " << piZero.
pt() <<
", eta = " << piZero.
eta()
188 <<
", phi = " << piZero.
phi();
190 tau_->signalPiZeroCandidatesRestricted().push_back(piZero);
199 tau_->isolationPiZeroCandidatesRestricted().push_back(piZero);
219 template <
typename T1,
typename T2>
220 void checkMatchedProductIds(
const T1& t1,
const T2& t2) {
221 if (t1.id() != t2.id()) {
223 <<
"Error: the input tag"
224 <<
" for the PF candidate collection provided to the RecoTauBuilder "
225 <<
" does not match the one that was used to build the source jets."
226 <<
" Please update the pfCandSrc paramters for the PFTau builders.";
234 checkMatchedProductIds(candPtr,
pfCands_);
241 template <
typename T>
242 bool ptDescending(
const T&
a,
const T&
b) {
243 return a.pt() > b.pt();
245 template <
typename T>
246 bool ptDescendingPtr(
const T& a,
const T& b) {
247 return a->pt() > b->pt();
253 std::sort(
tau_->signalTauChargedHadronCandidatesRestricted().begin(),
254 tau_->signalTauChargedHadronCandidatesRestricted().end(),
255 ptDescending<PFRecoTauChargedHadron>);
256 std::sort(
tau_->isolationTauChargedHadronCandidatesRestricted().begin(),
257 tau_->isolationTauChargedHadronCandidatesRestricted().end(),
258 ptDescending<PFRecoTauChargedHadron>);
259 std::sort(
tau_->signalPiZeroCandidatesRestricted().begin(),
260 tau_->signalPiZeroCandidatesRestricted().end(),
261 ptDescending<RecoTauPiZero>);
262 std::sort(
tau_->isolationPiZeroCandidatesRestricted().begin(),
263 tau_->isolationPiZeroCandidatesRestricted().end(),
264 ptDescending<RecoTauPiZero>);
270 std::sort(sortedCollection->begin(), sortedCollection->end(), ptDescendingPtr<CandidatePtr>);
272 for (std::vector<CandidatePtr>::const_iterator particle = sortedCollection->begin();
273 particle != sortedCollection->end();
275 colkey.second->push_back(*particle);
283 double minAbsPhotonSumPt_insideSignalCone,
284 double minRelPhotonSumPt_insideSignalCone,
285 double minAbsPhotonSumPt_outsideSignalCone,
286 double minRelPhotonSumPt_outsideSignalCone) {
292 unsigned int nPiZeros = 0;
294 for (std::vector<RecoTauPiZero>::const_iterator piZero = piZeros.begin(); piZero != piZeros.end(); ++piZero) {
295 double photonSumPt_insideSignalCone = 0.;
296 double photonSumPt_outsideSignalCone = 0.;
297 int numPhotons = piZero->numberOfDaughters();
298 for (
int idxPhoton = 0; idxPhoton < numPhotons; ++idxPhoton) {
301 if (dR < dRsignalCone) {
302 photonSumPt_insideSignalCone += photon->
pt();
304 photonSumPt_outsideSignalCone += photon->
pt();
307 if (photonSumPt_insideSignalCone > minAbsPhotonSumPt_insideSignalCone ||
308 photonSumPt_insideSignalCone > (minRelPhotonSumPt_insideSignalCone * tau.
pt()) ||
309 photonSumPt_outsideSignalCone > minAbsPhotonSumPt_outsideSignalCone ||
310 photonSumPt_outsideSignalCone > (minRelPhotonSumPt_outsideSignalCone * tau.
pt()))
318 unsigned int trackIndex = (nCharged - 1) * (maxPiZeros + 1);
324 if (nPiZeros > maxPiZeros)
325 nPiZeros = maxPiZeros;
331 LogDebug(
"TauConstructorGet") <<
"Start getting";
344 unsigned int nCharged = 0;
346 double leadChargedHadronPt = 0.;
347 int leadChargedHadronCharge = 0;
348 for (std::vector<PFRecoTauChargedHadron>::const_iterator chargedHadron =
349 tau_->signalTauChargedHadronCandidatesRestricted().begin();
350 chargedHadron !=
tau_->signalTauChargedHadronCandidatesRestricted().end();
355 charge += chargedHadron->charge();
356 if (chargedHadron->pt() > leadChargedHadronPt) {
357 leadChargedHadronPt = chargedHadron->pt();
358 leadChargedHadronCharge = chargedHadron->charge();
363 tau_->setCharge(charge);
365 tau_->setCharge(leadChargedHadronCharge);
368 tau_->setPdgId(
tau_->charge() < 0 ? 15 : -15);
375 tau_->setSignalConeSize(dRsignalCone);
382 tau_->setDecayMode(dm);
384 LogDebug(
"TauConstructorGet") <<
"Pt = " <<
tau_->pt() <<
", eta = " <<
tau_->eta() <<
", phi = " <<
tau_->phi()
385 <<
", mass = " <<
tau_->mass() <<
", dm = " <<
tau_->decayMode();
392 tau_->setisolationPFGammaCandsEtSum(
399 if (setupLeadingObjects) {
400 typedef std::vector<CandidatePtr>::const_iterator Iter;
405 tau_->setleadCand(*leadingCand);
408 Iter leadingChargedCand =
412 tau_->setleadChargedHadrCand(*leadingChargedCand);
418 tau_->setleadNeutralCand(*leadingGammaCand);
void addPFCand(Region region, ParticleType type, const CandidatePtr &ptr, bool skipAddToP4=false)
Append a PFCandidateRef/Ptr to a given collection.
void addTauChargedHadron(Region region, const PFRecoTauChargedHadron &chargedHadron)
Add a ChargedHadron to the given collection.
double minRelPhotonSumPt_outsideSignalCone_
reco::Candidate::LorentzVector p4_
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
CollectionMap collections_
void reserve(Region region, ParticleType type, size_t size)
Reserve a set amount of space for a given RefVector.
double pt() const final
transverse momentum
double sumPFCandPt(InputIterator begin, InputIterator end)
Sum the pT of a collection of PFCandidates.
virtual double pt() const =0
transverse momentum
std::vector< CandidatePtr > * getCollection(Region region, ParticleType type)
std::unique_ptr< reco::PFTau > tau_
std::unique_ptr< reco::PFTau > get(bool setupLeadingCandidates=true)
InputIterator leadCand(InputIterator begin, InputIterator end)
const LorentzVector & p4() const final
four-momentum Lorentz vector
virtual const daughters & daughterPtrVector() const
references to daughtes
const edm::Handle< edm::View< reco::Candidate > > & pfCands_
SortedCollectionMap sortedCollections_
const std::vector< RecoTauPiZero > & signalPiZeroCandidates() const
Retrieve the association of signal region gamma candidates into candidate PiZeros.
SortedListPtr getSortedCollection(Region region, ParticleType type)
RefCore const & refCore() const
Abs< T >::type abs(const T &t)
std::vector< CandidatePtr > neutralPFCandidates_
void addPFCands(Region region, ParticleType type, const InputIterator &begin, const InputIterator &end)
bool isNonnull() const
Checks for non-null.
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
double minAbsPhotonSumPt_outsideSignalCone_
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
RecoTauConstructor(const JetBaseRef &jetRef, const edm::Handle< edm::View< reco::Candidate > > &pfCands, bool copyGammasFromPiZeros=false, const StringObjectFunction< reco::PFTau > *signalConeSize=nullptr, double minAbsPhotonSumPt_insideSignalCone=2.5, double minRelPhotonSumPt_insideSignalCone=0., double minAbsPhotonSumPt_outsideSignalCone=1.e+9, double minRelPhotonSumPt_outsideSignalCone=1.e+9)
Constructor with PFCandidate Handle.
void reserveTauChargedHadron(Region region, size_t size)
Reserve a set amount of space for the ChargedHadrons.
void reservePiZero(Region region, size_t size)
Reserve a set amount of space for the PiZeros.
ProductID id() const
Accessor for product ID.
double minRelPhotonSumPt_insideSignalCone_
std::shared_ptr< std::vector< CandidatePtr > > SortedListPtr
void sortAndCopyIntoTau()
const std::vector< PFRecoTauChargedHadron > & signalTauChargedHadronCandidates() const
Retrieve the association of signal region PF candidates into candidate PFRecoTauChargedHadrons.
void addPiZero(Region region, const RecoTauPiZero &piZero)
Add a PiZero to the given collection.
const StringObjectFunction< reco::PFTau > * signalConeSize_
double minAbsPhotonSumPt_insideSignalCone_
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)
CandidatePtr convertToPtr(const PFCandidatePtr &pfPtr) const
double phi() const final
momentum azimuthal angle
const CandidatePtr & getChargedPFCandidate() const
reference to "charged" PFCandidate (either charged PFCandidate or PFNeutralHadron) ...
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
tuple size
Write out results.
std::vector< CandidatePtr > pfGammas(const Jet &jet, bool sort=true)
Extract all pfGammas from a PFJet.
const std::vector< CandidatePtr > & getNeutralPFCandidates() const
references to additional neutral PFCandidates
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
double eta() const final
momentum pseudorapidity