41 template <
typename Prod>
48 typedef std::vector<std::unique_ptr<CleanerEntryType>>
CleanerList;
74 template <
typename Prod>
77 tau_token = consumes<reco::PFTauCollection>(tauSrc_);
79 typedef std::vector<edm::ParameterSet>
VPSet;
82 for (VPSet::const_iterator cleanerPSet =
cleaners.begin(); cleanerPSet !=
cleaners.end(); ++cleanerPSet) {
83 auto cleanerEntry = std::make_unique<CleanerEntryType>();
88 cleanerEntry->tolerance_ = cleanerPSet->getParameter<
double>(
"tolerance");
89 cleaners_.emplace_back(
std::move(cleanerEntry));
95 outputSelector_ = std::make_unique<StringCutObjectSelector<reco::PFTau>>(
selection);
99 verbosity_ =
pset.getParameter<
int>(
"verbosity");
105 template <
typename Prod>
110 template <
typename T>
130 template <
typename T>
132 std::ostringstream os;
135 for (
unsigned iEntry = 0; iEntry <
numEntries; ++iEntry) {
144 struct PFTauRankType {
145 PFTauRankType(
const reco::PFTauRef& tauRef) : idx_(tauRef.
key()), tauRef_(tauRef) {}
148 std::cout <<
label <<
" (" << tauRef_.id() <<
":" << tauRef_.key() <<
", idx = " << idx_ <<
"):";
149 assert(tauRef_.key() == idx_);
150 std::cout <<
" Pt = " << tauRef_->pt() <<
", eta = " << tauRef_->eta() <<
", phi = " << tauRef_->phi()
151 <<
", mass = " << tauRef_->mass() <<
" (decayMode = " << tauRef_->decayMode() <<
")";
154 if (tauRef_->jetRef().isNonnull()) {
155 std::cout <<
" Pt = " << tauRef_->jetRef()->pt() <<
", eta = " << tauRef_->jetRef()->eta()
156 <<
", phi = " << tauRef_->jetRef()->phi() <<
", mass = " << tauRef_->jetRef()->mass()
157 <<
", area = " << tauRef_->jetRef()->jetArea();
161 const std::vector<reco::PFRecoTauChargedHadron>& signalTauChargedHadronCandidates =
162 tauRef_->signalTauChargedHadronCandidates();
163 size_t numChargedHadrons = signalTauChargedHadronCandidates.size();
164 for (
size_t iChargedHadron = 0; iChargedHadron < numChargedHadrons; ++iChargedHadron) {
166 std::cout <<
" chargedHadron #" << iChargedHadron <<
":" << std::endl;
169 const std::vector<reco::RecoTauPiZero>& signalPiZeroCandidates = tauRef_->signalPiZeroCandidates();
170 size_t numPiZeros = signalPiZeroCandidates.size();
171 std::cout <<
"signalPiZeroCandidates = " << numPiZeros << std::endl;
172 for (
size_t iPiZero = 0; iPiZero < numPiZeros; ++iPiZero) {
174 std::cout <<
" piZero #" << iPiZero <<
": Pt = " << piZero.
pt() <<
", eta = " << piZero.
eta()
175 <<
", phi = " << piZero.
phi() <<
", mass = " << piZero.
mass() << std::endl;
177 const auto& isolationCands = tauRef_->isolationCands();
178 size_t numCands = isolationCands.size();
179 std::cout <<
"isolationCands = " << numCands << std::endl;
180 for (
size_t iCand = 0; iCand < numCands; ++iCand) {
181 const auto&
cand = isolationCands.at(iCand);
182 std::cout <<
" pfCand #" << iCand <<
" (" <<
cand.id() <<
":" <<
cand.key() <<
"):" 183 <<
" Pt = " <<
cand->pt() <<
", eta = " <<
cand->eta() <<
", phi = " <<
cand->phi() << std::endl;
185 std::cout <<
" ranks = " << format_vT(ranks_) << std::endl;
186 std::cout <<
" tolerances = " << format_vT(tolerances_) << std::endl;
191 std::vector<float> ranks_;
192 std::vector<float> tolerances_;
195 bool isHigherRank(
const PFTauRankType*
tau1,
const PFTauRankType*
tau2) {
204 for (
size_t i = 0;
i <
tau1->N_; ++
i) {
205 const float& val1 =
tau1->ranks_[
i];
206 const float& val2 =
tau2->ranks_[
i];
207 double av = 0.5 * (val1 + val2);
209 if (val1 < (val2 -
thresh))
211 else if (val2 < (val1 -
thresh))
218 template <
typename Prod>
221 std::cout <<
"<RecoTauCleanerImpl::produce>:" << std::endl;
225 for (
typename CleanerList::iterator cleaner = cleaners_.begin(); cleaner != cleaners_.end(); ++cleaner) {
226 (*cleaner)->plugin_->setup(evt, es);
234 std::list<PFTauRankType*> rankedTaus;
235 size_t N = inputTaus->size();
238 PFTauRankType* rankedTau =
new PFTauRankType(inputRef);
239 rankedTau->N_ = cleaners_.size();
240 rankedTau->ranks_.reserve(rankedTau->N_);
241 rankedTau->tolerances_.reserve(rankedTau->N_);
242 for (
typename CleanerList::const_iterator cleaner = cleaners_.begin(); cleaner != cleaners_.end(); ++cleaner) {
243 rankedTau->ranks_.push_back((*(*cleaner)->plugin_)(inputRef));
244 rankedTau->tolerances_.push_back((*cleaner)->tolerance_);
247 std::ostringstream os;
248 os <<
"rankedTau #" <<
idx;
249 rankedTau->print(os.str());
251 rankedTaus.push_back(rankedTau);
253 rankedTaus.sort(isHigherRank);
256 typedef std::vector<reco::PFTauRef> PFTauRefs;
257 PFTauRefs dirty(inputTaus->size());
258 size_t idx_sorted = 0;
259 for (std::list<PFTauRankType*>::const_iterator rankedTau = rankedTaus.begin(); rankedTau != rankedTaus.end();
261 dirty[idx_sorted] = (*rankedTau)->tauRef_;
263 std::cout <<
"dirty[" << idx_sorted <<
"] = " << dirty[idx_sorted].id() <<
":" << dirty[idx_sorted].key()
271 PFTauRefs cleanTaus = reco::tau::cleanOverlaps<PFTauRefs, RemoveDuplicateJets>(dirty);
274 auto output = std::make_unique<Prod>();
278 for (PFTauRefs::const_iterator
tau = cleanTaus.begin();
tau != cleanTaus.end(); ++
tau) {
280 bool selected =
true;
281 if (outputSelector_.get() && !(*outputSelector_)(**tau)) {
285 output->push_back(convert<output_type>(*
tau));
305 vps_description_for_cleaners.
add<
double>(
"tolerance", 0);
310 vps_description_for_cleaners.
addOptional<
int>(
"passForCharge");
311 vps_description_for_cleaners.
addOptional<
double>(
"selectionFailValue");
312 vps_description_for_cleaners.
addOptional<std::vector<unsigned int>>(
"nprongs");
314 vps_description_for_cleaners.
addOptional<
double>(
"minTrackPt");
322 std::vector<edm::ParameterSet> default_cleaners;
323 default_cleaners.reserve(7);
329 cleaner_Charge.
addParameter<
double>(
"selectionFailValue", 0);
330 cleaner_Charge.
addParameter<std::vector<unsigned int>>(
"nprongs",
336 default_cleaners.push_back(cleaner_Charge);
344 default_cleaners.push_back(temp2);
352 default_cleaners.push_back(temp2);
359 default_cleaners.push_back(temp2);
367 temp2.
addParameter<
double>(
"selectionFailValue", 1000.0);
369 default_cleaners.push_back(temp2);
377 temp2.
addParameter<
double>(
"selectionFailValue", 1000.0);
379 default_cleaners.push_back(temp2);
386 "isolationPFChargedHadrCandsPtSum() + isolationPFGammaCandsEtSum()");
388 temp2.
addParameter<
double>(
"selectionFailValue", 1000.0);
390 default_cleaners.push_back(temp2);
393 desc.addVPSet(
"cleaners", vps_description_for_cleaners, default_cleaners);
396 desc.add<
int>(
"verbosity", 0);
398 descriptions.
add(
"RecoTauCleaner",
desc);
RecoTauCleanerImpl< reco::PFTauRefVector > RecoTauRefCleaner
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double pt() const final
transverse momentum
std::vector< std::unique_ptr< CleanerEntryType > > CleanerList
bool getByToken(EDGetToken token, Handle< PROD > &result) const
RecoTauCleanerImpl< reco::PFTauCollection > RecoTauCleaner
edm::EDGetTokenT< reco::PFTauCollection > tau_token
Container::value_type value_type
Long64_t numEntries(TFile *hdl, std::string const &trname)
void addParameter(std::string const &name, T const &value)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
#define DEFINE_FWK_MODULE(type)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
def convert(infile, ofile)
bool operator()(const reco::PFTauRef &a, const reco::PFTauRef &b) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double mass() const final
mass
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
RecoTauCleanerImpl(const edm::ParameterSet &pset)
std::shared_ptr< Cleaner > plugin_
double eta() const final
momentum pseudorapidity