35 const std::vector<reco::PFRecoTauChargedHadron>&,
36 const std::vector<RecoTauPiZero>&,
37 const std::vector<CandidatePtr>&)
const override;
40 std::unique_ptr<RecoTauQualityCuts>
qcuts_;
65 isolationConeSize_(pset.getParameter<double>(
"isolationConeSize")),
66 signalConeSize_(pset.getParameter<std::
string>(
"signalConeSize")),
67 minAbsPhotonSumPt_insideSignalCone_(pset.getParameter<double>(
"minAbsPhotonSumPt_insideSignalCone")),
68 minRelPhotonSumPt_insideSignalCone_(pset.getParameter<double>(
"minRelPhotonSumPt_insideSignalCone")),
69 minAbsPhotonSumPt_outsideSignalCone_(pset.getParameter<double>(
"minAbsPhotonSumPt_outsideSignalCone")),
70 minRelPhotonSumPt_outsideSignalCone_(pset.getParameter<double>(
"minRelPhotonSumPt_outsideSignalCone")) {
71 typedef std::vector<edm::ParameterSet>
VPSet;
73 for (VPSet::const_iterator decayMode = decayModes.begin(); decayMode != decayModes.end(); ++decayMode) {
75 info.
nCharged_ = decayMode->getParameter<uint32_t>(
"nCharged");
76 info.
nPiZeros_ = decayMode->getParameter<uint32_t>(
"nPiZeros");
77 info.
maxPFCHs_ = decayMode->getParameter<uint32_t>(
"maxTracks");
78 info.
maxPiZeros_ = decayMode->getParameter<uint32_t>(
"maxPiZeros");
98 if (mode_ == kRemoveChargedDaughterOverlaps) {
99 if (chargedHadron->getChargedPFCandidate().isNonnull())
101 }
else if (mode_ == kRemoveChargedAndNeutralDaughterOverlaps) {
103 for (reco::CompositePtrCandidate::daughters::const_iterator daughter = daughters.begin();
104 daughter != daughters.end();
115 const PiZeroList::const_iterator& piZerosEnd) {
116 for (
auto const& ptr :
flattenPiZeros(piZerosBegin, piZerosEnd)) {
129 for (reco::CompositePtrCandidate::daughters::const_iterator daughter = daughters.begin();
130 daughter != daughters.end();
140 const ChargedHadronList::const_iterator& chargedHadronsBegin,
141 const ChargedHadronList::const_iterator& chargedHadronsEnd) {
143 for (ChargedHadronList::const_iterator chargedHadron = chargedHadronsBegin; chargedHadron != chargedHadronsEnd;
146 for (reco::CompositePtrCandidate::daughters::const_iterator daughter = daughters.begin();
147 daughter != daughters.end();
158 class SortPi0sDescendingPt {
163 double square(
double x) {
return x * x; }
168 const std::vector<reco::PFRecoTauChargedHadron>& chargedHadrons,
169 const std::vector<RecoTauPiZero>& piZeros,
170 const std::vector<CandidatePtr>& regionalExtras)
const {
172 std::cout <<
"<RecoTauBuilderCombinatoricPlugin::operator()>:" << std::endl;
173 std::cout <<
" processing jet: Pt = " << jet->pt() <<
", eta = " << jet->eta() <<
", phi = " << jet->eta()
175 <<
" mass = " << jet->mass() <<
", area = " << jet->jetArea() << std::endl;
185 typedef std::vector<CandidatePtr>
CandPtrs;
188 std::cout <<
"#chargedHadrons = " << chargedHadrons.size() << std::endl;
190 for (ChargedHadronList::const_iterator chargedHadron = chargedHadrons.begin();
191 chargedHadron != chargedHadrons.end();
193 std::cout <<
"chargedHadron #" << idx <<
":" << std::endl;
197 std::cout <<
"#piZeros = " << piZeros.size() << std::endl;
199 for (PiZeroList::const_iterator piZero = piZeros.begin(); piZero != piZeros.end(); ++piZero) {
200 std::cout <<
"piZero #" << idx <<
":" << std::endl;
212 CandPtrs regionalJunk =
qcuts_->filterCandRefs(regionalExtras);
215 for (std::vector<decayModeInfo>::const_iterator decayMode =
decayModesToBuild_.begin();
219 size_t piZerosToBuild = decayMode->nPiZeros_;
221 size_t tracksToBuild = decayMode->nCharged_;
223 std::cout <<
"piZerosToBuild = " << piZerosToBuild << std::endl;
224 std::cout <<
"#piZeros = " << piZeros.size() << std::endl;
225 std::cout <<
"tracksToBuild = " << tracksToBuild << std::endl;
226 std::cout <<
"#chargedHadrons = " << chargedHadrons.size() << std::endl;
230 if (chargedHadrons.size() < tracksToBuild)
234 ChargedHadronList::const_iterator chargedHadron_begin = chargedHadrons.begin();
235 ChargedHadronList::const_iterator chargedHadron_end = chargedHadrons.end();
236 chargedHadron_end =
takeNElements(chargedHadron_begin, chargedHadron_end, decayMode->maxPFCHs_);
239 ChargedHadronCombo trackCombos(chargedHadron_begin, chargedHadron_end, tracksToBuild);
241 CandPtrs::iterator pfch_end = pfchs.end();
242 pfch_end =
takeNElements(pfchs.begin(), pfch_end, decayMode->maxPFCHs_);
252 trackCombo->combo_begin(),
253 trackCombo->combo_end(),
256 PiZeroList cleanSignalPiZeros = signalPiZeroXCleaner(piZeros);
259 std::sort(cleanSignalPiZeros.begin(), cleanSignalPiZeros.end(), SortPi0sDescendingPt());
263 if (cleanSignalPiZeros.size() < piZerosToBuild)
267 PiZeroList::iterator signalPiZero_begin = cleanSignalPiZeros.begin();
268 PiZeroList::iterator signalPiZero_end = cleanSignalPiZeros.end();
269 signalPiZero_end =
takeNElements(signalPiZero_begin, signalPiZero_end, decayMode->maxPiZeros_);
272 PiZeroCombo piZeroCombos(signalPiZero_begin, signalPiZero_end, piZerosToBuild);
291 trackCombo->combo_begin(),
292 trackCombo->combo_end(),
295 PiZeroList precleanedIsolationPiZeros = isolationPiZeroXCleaner(piZeros);
296 std::set<reco::CandidatePtr> toRemove;
298 signalPiZero != piZeroCombo->combo_end();
300 toRemove.insert(signalPiZero->daughterPtrVector().begin(), signalPiZero->daughterPtrVector().end());
303 for (
auto const& precleanedPiZero : precleanedIsolationPiZeros) {
304 std::set<reco::CandidatePtr> toCheck(precleanedPiZero.daughterPtrVector().begin(),
305 precleanedPiZero.daughterPtrVector().end());
306 std::vector<reco::CandidatePtr> cleanDaughters;
308 toCheck.begin(), toCheck.end(), toRemove.begin(), toRemove.end(), std::back_inserter(cleanDaughters));
310 if (cleanDaughters.size() == precleanedPiZero.daughterPtrVector().size()) {
311 cleanIsolationPiZeros.push_back(precleanedPiZero);
315 std::cout <<
"#cleanIsolationPiZeros = " << cleanIsolationPiZeros.size() << std::endl;
317 for (PiZeroList::const_iterator piZero = cleanIsolationPiZeros.begin();
318 piZero != cleanIsolationPiZeros.end();
320 std::cout <<
"piZero #" << idx <<
":" << std::endl;
330 chargedHadrons.size() - tracksToBuild);
349 using namespace reco::tau::cone;
356 pfChargedHadronXCleanerType pfChargedHadronXCleaner_comboChargedHadrons(trackCombo->combo_begin(),
357 trackCombo->combo_end());
360 isolationConeFilter, pfChargedHadronXCleaner_comboChargedHadrons);
363 chargedHadrons.begin(), chargedHadrons.end());
368 pfCandXCleanerType pfCandXCleaner_allChargedHadrons(pfChargedHadronXCleaner_allChargedHadrons,
372 isolationConeFilter, pfCandXCleaner_allChargedHadrons);
385 RegionalJunkConeAndIdFilter pfChargedJunk(pfchCandSelector,
386 isolationConeFilter);
388 RegionalJunkConeAndIdFilter pfGammaJunk(pfgammaCandSelector,
389 isolationConeFilter);
391 RegionalJunkConeAndIdFilter pfNeutralJunk(pfnhCandSelector,
392 isolationConeFilter);
395 boost::make_filter_iterator(
396 isolationConeFilterPiZero, cleanIsolationPiZeros.begin(), cleanIsolationPiZeros.end()),
397 boost::make_filter_iterator(
398 isolationConeFilterPiZero, cleanIsolationPiZeros.end(), cleanIsolationPiZeros.end()));
406 std::cout <<
"adding isolation PFChargedHadrons from trackCombo:" << std::endl;
410 boost::make_filter_iterator(
411 isolationConeFilterChargedHadron, trackCombo->remainder_begin(), trackCombo->remainder_end()),
412 boost::make_filter_iterator(
413 isolationConeFilterChargedHadron, trackCombo->remainder_end(), trackCombo->remainder_end()));
418 std::cout <<
"adding isolation PFChargedHadrons not considered in trackCombo:" << std::endl;
422 boost::make_filter_iterator(pfCandFilter_comboChargedHadrons, pfch_end, pfchs.end()),
423 boost::make_filter_iterator(pfCandFilter_comboChargedHadrons, pfchs.end(), pfchs.end()));
427 std::cout <<
"adding isolation PFChargedHadrons from 'regional junk':" << std::endl;
431 boost::make_filter_iterator(pfChargedJunk, regionalJunk.begin(), regionalJunk.end()),
432 boost::make_filter_iterator(pfChargedJunk, regionalJunk.end(), regionalJunk.end()));
436 std::cout <<
"adding isolation PFGammas not considered in PiZeros:" << std::endl;
441 boost::make_filter_iterator(pfCandFilter_allChargedHadrons, pfgammas.begin(), pfgammas.end()),
442 boost::make_filter_iterator(pfCandFilter_allChargedHadrons, pfgammas.end(), pfgammas.end()));
447 boost::make_filter_iterator(pfGammaJunk, regionalJunk.begin(), regionalJunk.end()),
448 boost::make_filter_iterator(pfGammaJunk, regionalJunk.end(), regionalJunk.end()));
453 boost::make_filter_iterator(pfCandFilter_allChargedHadrons, pfnhs.begin(), pfnhs.end()),
454 boost::make_filter_iterator(pfCandFilter_allChargedHadrons, pfnhs.end(), pfnhs.end()));
459 boost::make_filter_iterator(pfNeutralJunk, regionalJunk.begin(), regionalJunk.end()),
460 boost::make_filter_iterator(pfNeutralJunk, regionalJunk.end(), regionalJunk.end()));
462 std::unique_ptr<reco::PFTau> tauPtr = tau.
get(
true);
466 if (primaryVertexRef.isNonnull()) {
467 tauPtr->setVertex(primaryVertexRef->position());
470 double tauEn = tauPtr->energy();
471 double tauPz = tauPtr->pz();
472 const double chargedPionMass = 0.13957;
473 double tauMass =
std::max(tauPtr->mass(), chargedPionMass);
474 double bendCorrMass2 = 0.;
475 const std::vector<RecoTauPiZero>& piZeros = tauPtr->signalPiZeroCandidates();
476 for (
auto const& piZero : piZeros) {
477 double piZeroEn = piZero.energy();
478 double piZeroPx = piZero.px();
479 double piZeroPy = piZero.py();
480 double piZeroPz = piZero.pz();
481 double tau_wo_piZeroPx = tauPtr->px() - piZeroPx;
482 double tau_wo_piZeroPy = tauPtr->py() - piZeroPy;
485 bendCorrMass2 +=
square(((piZeroPz * tauEn - piZeroEn * tauPz) / tauMass) * piZero.bendCorrEta());
487 square(((piZeroPy * tau_wo_piZeroPx - piZeroPx * tau_wo_piZeroPy) / tauMass) * piZero.bendCorrPhi());
490 tauPtr->setBendCorrMass(
sqrt(bendCorrMass2));
506 "RecoTauBuilderCombinatoricPlugin");
reco::VertexRef primaryVertex(const reco::JetBaseRef &jet) const
Get primary vertex associated to this jet.
std::vector< CandidatePtr > pfCandidatesByPdgId(const Jet &jet, int pdgId, bool sort=true)
InputIterator takeNElements(const InputIterator &begin, const InputIterator &end, size_t N)
void reserve(Region region, ParticleType type, size_t size)
Reserve a set amount of space for a given RefVector.
void addTauChargedHadrons(Region region, const InputIterator &begin, const InputIterator &end)
Add a list of charged hadrons to the input collection.
std::vector< std::unique_ptr< reco::PFTau > > output_type
double pt() const final
transverse momentum
CombinatoricIterator< T > end()
std::vector< reco::PFRecoTauChargedHadron > ChargedHadronList
ParameterSet const & getParameterSet(ParameterSetID const &id)
double minRelPhotonSumPt_outsideSignalCone_
RecoTauBuilderCombinatoricPlugin(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
std::unique_ptr< reco::PFTau > get(bool setupLeadingCandidates=true)
std::vector< CandidatePtr > pfChargedCands(const Jet &jet, bool sort=true)
Extract all non-neutral candidates from a PFJet.
double minAbsPhotonSumPt_outsideSignalCone_
tau::CombinatoricGenerator< PiZeroList > PiZeroCombo
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.
void addPiZeros(Region region, const InputIterator &begin, const InputIterator &end)
Add a list of pizeros to the input collection.
std::vector< decayModeInfo > decayModesToBuild_
double minAbsPhotonSumPt_insideSignalCone_
return_type operator()(const reco::JetBaseRef &, const std::vector< reco::PFRecoTauChargedHadron > &, const std::vector< RecoTauPiZero > &, const std::vector< CandidatePtr > &) const override
std::vector< reco::CandidatePtr > CandPtrs
StringObjectFunction< reco::PFTau > signalConeSize_
const reco::Candidate::LorentzVector & p4() const
void addPFCands(Region region, ParticleType type, const InputIterator &begin, const InputIterator &end)
void initialize(const PtrIter &chargedHadronsBegin, const PtrIter &chargedHadronsEnd)
tau::CombinatoricGenerator< ChargedHadronList > ChargedHadronCombo
std::vector< CandidatePtr > daughters
collection of references to daughters
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
void reservePiZero(Region region, size_t size)
Reserve a set amount of space for the PiZeros.
T getParameter(std::string const &) const
static double square(double x)
~RecoTauBuilderCombinatoricPlugin() override
double minRelPhotonSumPt_insideSignalCone_
#define DEFINE_EDM_PLUGIN(factory, type, name)
double isolationConeSize_
const edm::Handle< edm::View< reco::Candidate > > & getPFCands() const
Hack to be able to convert Ptrs to Refs.
std::unique_ptr< RecoTauQualityCuts > qcuts_
void initialize(const PtrIter &particlesBegin, const PtrIter &particlesEnd)
std::vector< RecoTauPiZero > PiZeroList
iterator::value_type::ValueIter combo_iterator
Transform a pizero to remove given candidates.
CombinatoricIterator< T > begin()