17 bool copyGammasFromPiZeros,
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();
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) {
106 if (
pfGamma.id() == neutral.id() &&
pfGamma.key() == neutral.key())
117 const std::vector<CandidatePtr>& neutrals =
chargedHadron.getNeutralPFCandidates();
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>);
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);
287 unsigned int nCharged =
tau.signalTauChargedHadronCandidates().size();
293 const std::vector<RecoTauPiZero>& piZeros =
tau.signalPiZeroCandidates();
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();
326 return static_cast<PFTau::hadronicDecayMode>(trackIndex +
nPiZeros);
331 LogDebug(
"TauConstructorGet") <<
"Start getting";
346 double leadChargedHadronPt = 0.;
347 int leadChargedHadronCharge = 0;
348 for (std::vector<PFRecoTauChargedHadron>::const_iterator
chargedHadron =
349 tau_->signalTauChargedHadronCandidatesRestricted().begin();
365 tau_->setCharge(leadChargedHadronCharge);
368 tau_->setPdgId(
tau_->charge() < 0 ? 15 : -15);
375 tau_->setSignalConeSize(dRsignalCone);
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);