17 #include <boost/ptr_container/ptr_vector.hpp> 43 template<
typename Prod>
52 typedef std::vector<std::unique_ptr<CleanerEntryType> >
CleanerList;
79 template<
typename Prod>
85 typedef std::vector<edm::ParameterSet>
VPSet;
88 for ( VPSet::const_iterator cleanerPSet = cleaners.begin();
89 cleanerPSet != cleaners.end(); ++cleanerPSet ) {
90 auto cleanerEntry = std::make_unique<CleanerEntryType>();
95 cleanerEntry->tolerance_ = cleanerPSet->getParameter<
double>(
"tolerance");
101 if ( !selection.empty() ) {
112 template<
typename Prod>
135 template <
typename T>
138 std::ostringstream os;
141 for (
unsigned iEntry = 0; iEntry <
numEntries; ++iEntry ) {
143 if ( iEntry < (numEntries - 1) ) os <<
", ";
152 : idx_(tauRef.
key()),
158 std::cout << label <<
" (" << tauRef_.id() <<
":" << tauRef_.key() <<
", idx = " << idx_ <<
"):";
159 assert(tauRef_.key() == idx_);
160 std::cout <<
" Pt = " << tauRef_->pt() <<
", eta = " << tauRef_->eta() <<
", phi = " << tauRef_->phi() <<
", mass = " << tauRef_->mass() <<
" (decayMode = " << tauRef_->decayMode() <<
")";
163 if ( tauRef_->jetRef().isNonnull() ) {
164 std::cout <<
" Pt = " << tauRef_->jetRef()->pt() <<
", eta = " << tauRef_->jetRef()->eta() <<
", phi = " << tauRef_->jetRef()->phi()
165 <<
", mass = " << tauRef_->jetRef()->mass() <<
", area = " << tauRef_->jetRef()->jetArea();
169 const std::vector<reco::PFRecoTauChargedHadron>& signalTauChargedHadronCandidates = tauRef_->signalTauChargedHadronCandidates();
170 size_t numChargedHadrons = signalTauChargedHadronCandidates.size();
171 for (
size_t iChargedHadron = 0; iChargedHadron < numChargedHadrons; ++iChargedHadron ) {
173 std::cout <<
" chargedHadron #" << iChargedHadron <<
":" << std::endl;
176 const std::vector<reco::RecoTauPiZero>& signalPiZeroCandidates = tauRef_->signalPiZeroCandidates();
177 size_t numPiZeros = signalPiZeroCandidates.size();
178 std::cout <<
"signalPiZeroCandidates = " << numPiZeros << std::endl;
179 for (
size_t iPiZero = 0; iPiZero < numPiZeros; ++iPiZero ) {
181 std::cout <<
" piZero #" << iPiZero <<
": Pt = " << piZero.
pt() <<
", eta = " << piZero.
eta() <<
", phi = " << piZero.
phi() <<
", mass = " << piZero.
mass() << std::endl;
183 const auto& isolationCands = tauRef_->isolationCands();
184 size_t numCands = isolationCands.size();
185 std::cout <<
"isolationCands = " << numCands << std::endl;
186 for (
size_t iCand = 0; iCand < numCands; ++iCand ) {
187 const auto&
cand = isolationCands.at(iCand);
188 std::cout <<
" pfCand #" << iCand <<
" (" <<
cand.id() <<
":" <<
cand.key() <<
"):" 189 <<
" Pt = " <<
cand->pt() <<
", eta = " <<
cand->eta() <<
", phi = " <<
cand->phi() << std::endl;
191 std::cout <<
" ranks = " << format_vT(ranks_) << std::endl;
192 std::cout <<
" tolerances = " << format_vT(tolerances_) << std::endl;
197 std::vector<float> ranks_;
198 std::vector<float> tolerances_;
201 bool isHigherRank(
const PFTauRankType*
tau1,
const PFTauRankType*
tau2)
208 assert(tau1->N_ == tau1->ranks_.size());
209 assert(tau1->N_ == tau2->ranks_.size());
210 assert(tau1->N_ == tau1->tolerances_.size());
211 for (
size_t i = 0;
i < tau1->N_; ++
i ) {
212 const float& val1 = tau1->ranks_[
i];
213 const float& val2 = tau2->ranks_[
i];
214 double av = 0.5*(val1 + val2);
215 double thresh = av*tau1->tolerances_[
i];
216 if ( val1 < (val2 - thresh) )
return true;
217 else if ( val2 < (val1 - thresh) )
return false;
223 template<
typename Prod>
227 std::cout <<
"<RecoTauCleanerImpl::produce>:" << std::endl;
231 for (
typename CleanerList::iterator cleaner =
cleaners_.begin();
232 cleaner !=
cleaners_.end(); ++cleaner ) {
233 (*cleaner)->plugin_->setup(evt, es);
241 std::list<PFTauRankType*> rankedTaus;
242 size_t N = inputTaus->size();
245 PFTauRankType* rankedTau =
new PFTauRankType(inputRef);
247 rankedTau->ranks_.reserve(rankedTau->N_);
248 rankedTau->tolerances_.reserve(rankedTau->N_);
249 for (
typename CleanerList::const_iterator cleaner =
cleaners_.begin();
250 cleaner !=
cleaners_.end(); ++cleaner ) {
251 rankedTau->ranks_.push_back((*(*cleaner)->plugin_)(inputRef));
252 rankedTau->tolerances_.push_back((*cleaner)->tolerance_);
255 std::ostringstream os;
256 os <<
"rankedTau #" <<
idx;
257 rankedTau->print(os.str());
259 rankedTaus.push_back(rankedTau);
261 rankedTaus.sort(isHigherRank);
264 typedef std::vector<reco::PFTauRef> PFTauRefs;
265 PFTauRefs dirty(inputTaus->size());
266 size_t idx_sorted = 0;
267 for ( std::list<PFTauRankType*>::const_iterator rankedTau = rankedTaus.begin();
268 rankedTau != rankedTaus.end(); ++rankedTau ) {
269 dirty[idx_sorted] = (*rankedTau)->tauRef_;
271 std::cout <<
"dirty[" << idx_sorted <<
"] = " << dirty[idx_sorted].id() <<
":" << dirty[idx_sorted].key() << std::endl;
278 PFTauRefs cleanTaus = reco::tau::cleanOverlaps<PFTauRefs, RemoveDuplicateJets>(dirty);
281 auto output = std::make_unique<Prod>();
285 for ( PFTauRefs::const_iterator
tau = cleanTaus.begin();
286 tau != cleanTaus.end(); ++
tau ) {
288 bool selected =
true;
293 output->push_back(convert<output_type>(*
tau));
314 vps_description_for_cleaners.
add<
double>(
"tolerance", 0);
319 vps_description_for_cleaners.
addOptional<
int>(
"passForCharge");
320 vps_description_for_cleaners.
addOptional<
double>(
"selectionFailValue");
321 vps_description_for_cleaners.
addOptional<std::vector<unsigned int>>(
"nprongs");
323 vps_description_for_cleaners.
addOptional<
double>(
"minTrackPt");
331 std::vector<edm::ParameterSet> default_cleaners;
332 default_cleaners.reserve(7);
338 cleaner_Charge.
addParameter<
double>(
"selectionFailValue", 0);
339 cleaner_Charge.
addParameter<std::vector<unsigned int>>(
"nprongs", {1, 3,});
341 default_cleaners.push_back(cleaner_Charge);
349 default_cleaners.push_back(temp2);
357 default_cleaners.push_back(temp2);
364 default_cleaners.push_back(temp2);
372 temp2.
addParameter<
double>(
"selectionFailValue", 1000.0);
374 default_cleaners.push_back(temp2);
382 temp2.
addParameter<
double>(
"selectionFailValue", 1000.0);
384 default_cleaners.push_back(temp2);
390 temp2.
addParameter<
std::string>(
"selectionPassFunction",
"isolationPFChargedHadrCandsPtSum() + isolationPFGammaCandsEtSum()");
392 temp2.
addParameter<
double>(
"selectionFailValue", 1000.0);
394 default_cleaners.push_back(temp2);
397 desc.
addVPSet(
"cleaners", vps_description_for_cleaners, default_cleaners);
400 desc.
add<
int>(
"verbosity", 0);
402 descriptions.
add(
"RecoTauCleaner", desc);
T getParameter(std::string const &) const
RecoTauCleanerImpl< reco::PFTauRefVector > RecoTauRefCleaner
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
double eta() const final
momentum pseudorapidity
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
bool operator()(const reco::PFTauRef &a, const reco::PFTauRef &b) const
std::vector< std::unique_ptr< CleanerEntryType > > CleanerList
double pt() const final
transverse momentum
key_type key() const
Accessor for product key.
RecoTauCleanerImpl< reco::PFTauCollection > RecoTauCleaner
S & print(S &os, JobReport::InputFile const &f)
edm::EDGetTokenT< reco::PFTauCollection > tau_token
void print(std::ostream &stream=std::cout) const
#define DEFINE_FWK_MODULE(type)
Container::value_type value_type
Long64_t numEntries(TFile *hdl, std::string const &trname)
void addParameter(std::string const &name, T const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
def convert(infile, ofile)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
reco::tau::RecoTauCleanerPlugin Cleaner
std::unique_ptr< const StringCutObjectSelector< reco::PFTau > > outputSelector_
void produce(edm::Event &evt, const edm::EventSetup &es) override
double phi() const final
momentum azimuthal angle
Prod::value_type output_type
~RecoTauCleanerImpl() override
T get(const Candidate &c)
RecoTauCleanerImpl(const edm::ParameterSet &pset)
double mass() const final
mass
std::shared_ptr< Cleaner > plugin_