17 #include <boost/ptr_container/ptr_vector.hpp>
43 template <
typename Prod>
50 typedef std::vector<std::unique_ptr<CleanerEntryType>>
CleanerList;
76 template <
typename Prod>
79 tau_token = consumes<reco::PFTauCollection>(tauSrc_);
81 typedef std::vector<edm::ParameterSet>
VPSet;
84 for (VPSet::const_iterator cleanerPSet =
cleaners.begin(); cleanerPSet !=
cleaners.end(); ++cleanerPSet) {
85 auto cleanerEntry = std::make_unique<CleanerEntryType>();
90 cleanerEntry->tolerance_ = cleanerPSet->getParameter<
double>(
"tolerance");
91 cleaners_.emplace_back(
std::move(cleanerEntry));
97 outputSelector_ = std::make_unique<StringCutObjectSelector<reco::PFTau>>(
selection);
101 verbosity_ =
pset.getParameter<
int>(
"verbosity");
107 template <
typename Prod>
112 template <
typename T>
132 template <
typename T>
134 std::ostringstream os;
137 for (
unsigned iEntry = 0; iEntry <
numEntries; ++iEntry) {
146 struct PFTauRankType {
147 PFTauRankType(
const reco::PFTauRef& tauRef) : idx_(tauRef.
key()), tauRef_(tauRef) {}
150 std::cout <<
label <<
" (" << tauRef_.id() <<
":" << tauRef_.key() <<
", idx = " << idx_ <<
"):";
151 assert(tauRef_.key() == idx_);
152 std::cout <<
" Pt = " << tauRef_->pt() <<
", eta = " << tauRef_->eta() <<
", phi = " << tauRef_->phi()
153 <<
", mass = " << tauRef_->mass() <<
" (decayMode = " << tauRef_->decayMode() <<
")";
156 if (tauRef_->jetRef().isNonnull()) {
157 std::cout <<
" Pt = " << tauRef_->jetRef()->pt() <<
", eta = " << tauRef_->jetRef()->eta()
158 <<
", phi = " << tauRef_->jetRef()->phi() <<
", mass = " << tauRef_->jetRef()->mass()
159 <<
", area = " << tauRef_->jetRef()->jetArea();
163 const std::vector<reco::PFRecoTauChargedHadron>& signalTauChargedHadronCandidates =
164 tauRef_->signalTauChargedHadronCandidates();
165 size_t numChargedHadrons = signalTauChargedHadronCandidates.size();
166 for (
size_t iChargedHadron = 0; iChargedHadron < numChargedHadrons; ++iChargedHadron) {
168 std::cout <<
" chargedHadron #" << iChargedHadron <<
":" << std::endl;
171 const std::vector<reco::RecoTauPiZero>& signalPiZeroCandidates = tauRef_->signalPiZeroCandidates();
172 size_t numPiZeros = signalPiZeroCandidates.size();
173 std::cout <<
"signalPiZeroCandidates = " << numPiZeros << std::endl;
174 for (
size_t iPiZero = 0; iPiZero < numPiZeros; ++iPiZero) {
176 std::cout <<
" piZero #" << iPiZero <<
": Pt = " << piZero.
pt() <<
", eta = " << piZero.
eta()
177 <<
", phi = " << piZero.
phi() <<
", mass = " << piZero.
mass() << std::endl;
179 const auto& isolationCands = tauRef_->isolationCands();
180 size_t numCands = isolationCands.size();
181 std::cout <<
"isolationCands = " << numCands << std::endl;
182 for (
size_t iCand = 0; iCand < numCands; ++iCand) {
183 const auto&
cand = isolationCands.at(iCand);
184 std::cout <<
" pfCand #" << iCand <<
" (" <<
cand.id() <<
":" <<
cand.key() <<
"):"
185 <<
" Pt = " <<
cand->pt() <<
", eta = " <<
cand->eta() <<
", phi = " <<
cand->phi() << std::endl;
187 std::cout <<
" ranks = " << format_vT(ranks_) << std::endl;
188 std::cout <<
" tolerances = " << format_vT(tolerances_) << std::endl;
193 std::vector<float> ranks_;
194 std::vector<float> tolerances_;
197 bool isHigherRank(
const PFTauRankType*
tau1,
const PFTauRankType*
tau2) {
206 for (
size_t i = 0;
i <
tau1->N_; ++
i) {
207 const float& val1 =
tau1->ranks_[
i];
208 const float& val2 =
tau2->ranks_[
i];
209 double av = 0.5 * (val1 + val2);
211 if (val1 < (val2 -
thresh))
213 else if (val2 < (val1 -
thresh))
220 template <
typename Prod>
223 std::cout <<
"<RecoTauCleanerImpl::produce>:" << std::endl;
227 for (
typename CleanerList::iterator cleaner = cleaners_.begin(); cleaner != cleaners_.end(); ++cleaner) {
228 (*cleaner)->plugin_->setup(evt, es);
236 std::list<PFTauRankType*> rankedTaus;
237 size_t N = inputTaus->size();
240 PFTauRankType* rankedTau =
new PFTauRankType(inputRef);
241 rankedTau->N_ = cleaners_.size();
242 rankedTau->ranks_.reserve(rankedTau->N_);
243 rankedTau->tolerances_.reserve(rankedTau->N_);
244 for (
typename CleanerList::const_iterator cleaner = cleaners_.begin(); cleaner != cleaners_.end(); ++cleaner) {
245 rankedTau->ranks_.push_back((*(*cleaner)->plugin_)(inputRef));
246 rankedTau->tolerances_.push_back((*cleaner)->tolerance_);
249 std::ostringstream os;
250 os <<
"rankedTau #" <<
idx;
251 rankedTau->print(os.str());
253 rankedTaus.push_back(rankedTau);
255 rankedTaus.sort(isHigherRank);
258 typedef std::vector<reco::PFTauRef> PFTauRefs;
259 PFTauRefs dirty(inputTaus->size());
260 size_t idx_sorted = 0;
261 for (std::list<PFTauRankType*>::const_iterator rankedTau = rankedTaus.begin(); rankedTau != rankedTaus.end();
263 dirty[idx_sorted] = (*rankedTau)->tauRef_;
265 std::cout <<
"dirty[" << idx_sorted <<
"] = " << dirty[idx_sorted].id() <<
":" << dirty[idx_sorted].key()
273 PFTauRefs cleanTaus = reco::tau::cleanOverlaps<PFTauRefs, RemoveDuplicateJets>(dirty);
276 auto output = std::make_unique<Prod>();
280 for (PFTauRefs::const_iterator
tau = cleanTaus.begin();
tau != cleanTaus.end(); ++
tau) {
282 bool selected =
true;
283 if (outputSelector_.get() && !(*outputSelector_)(**tau)) {
287 output->push_back(convert<output_type>(*
tau));
307 vps_description_for_cleaners.
add<
double>(
"tolerance", 0);
312 vps_description_for_cleaners.
addOptional<
int>(
"passForCharge");
313 vps_description_for_cleaners.
addOptional<
double>(
"selectionFailValue");
314 vps_description_for_cleaners.
addOptional<std::vector<unsigned int>>(
"nprongs");
316 vps_description_for_cleaners.
addOptional<
double>(
"minTrackPt");
324 std::vector<edm::ParameterSet> default_cleaners;
325 default_cleaners.reserve(7);
331 cleaner_Charge.
addParameter<
double>(
"selectionFailValue", 0);
332 cleaner_Charge.
addParameter<std::vector<unsigned int>>(
"nprongs",
338 default_cleaners.push_back(cleaner_Charge);
346 default_cleaners.push_back(temp2);
354 default_cleaners.push_back(temp2);
361 default_cleaners.push_back(temp2);
369 temp2.
addParameter<
double>(
"selectionFailValue", 1000.0);
371 default_cleaners.push_back(temp2);
379 temp2.
addParameter<
double>(
"selectionFailValue", 1000.0);
381 default_cleaners.push_back(temp2);
388 "isolationPFChargedHadrCandsPtSum() + isolationPFGammaCandsEtSum()");
390 temp2.
addParameter<
double>(
"selectionFailValue", 1000.0);
392 default_cleaners.push_back(temp2);
395 desc.addVPSet(
"cleaners", vps_description_for_cleaners, default_cleaners);
398 desc.add<
int>(
"verbosity", 0);
400 descriptions.
add(
"RecoTauCleaner",
desc);