62 void print(
const T& chargedHadron);
88 std::unique_ptr<StringCutObjectSelector<reco::PFRecoTauChargedHadron>>
outputSelector_;
104 for (edm::VParameterSet::const_iterator
pset = psets_builders.begin();
pset != psets_builders.end(); ++
pset) {
114 for (edm::VParameterSet::const_iterator
pset = psets_rankers.begin();
pset != psets_rankers.end(); ++
pset) {
126 if (!selection.empty()) {
130 produces<reco::PFJetChargedHadronAssociation>();
135 edm::LogPrint(
"PFRecoTauChHProducer") <<
"<PFRecoTauChargedHadronProducer::produce>:";
141 builder->setup(evt, es);
150 size_t nElements = jets->size();
151 for (
size_t i = 0;
i < nElements; ++
i) {
156 std::unique_ptr<reco::PFJetChargedHadronAssociation> pfJetChargedHadronAssociations;
158 if (!pfJets.
empty()) {
159 pfJetChargedHadronAssociations = std::make_unique<reco::PFJetChargedHadronAssociation>(
reco::JetRefBaseProd(jets));
161 pfJetChargedHadronAssociations = std::make_unique<reco::PFJetChargedHadronAssociation>();
165 for (
const auto& pfJet : pfJets) {
175 for (
auto const& builder : builders_) {
179 edm::LogPrint(
"PFRecoTauChHProducer") <<
"result of builder = " << builder->name() <<
":";
180 for (
auto const& had : result) {
184 std::move(result.begin(), result.end(), std::back_inserter(uncleanedChargedHadrons));
187 <<
"Exception caught in builder plugin " << builder->name() <<
", rethrowing" << std::endl;
193 uncleanedChargedHadrons.sort([
this](
const auto&
a,
const auto&
b) {
return (*
predicate_)(*
a, *
b); });
196 std::vector<reco::PFRecoTauChargedHadron> cleanedChargedHadrons;
199 typedef std::pair<double, double> etaPhiPair;
200 std::list<etaPhiPair> tracksInCleanCollection;
201 std::set<reco::CandidatePtr> neutralPFCandsInCleanCollection;
203 while (!uncleanedChargedHadrons.empty()) {
205 std::unique_ptr<reco::PFRecoTauChargedHadron> nextChargedHadron =
std::move(uncleanedChargedHadrons.front());
206 uncleanedChargedHadrons.pop_front();
208 edm::LogPrint(
"PFRecoTauChHProducer") <<
"processing nextChargedHadron:";
209 edm::LogPrint(
"PFRecoTauChHProducer") << (*nextChargedHadron);
217 if (nextChargedHadron->getChargedPFCandidate().isNonnull()) {
219 dynamic_cast<const reco::PFCandidate*
>(&*nextChargedHadron->getChargedPFCandidate());
224 track = chargedPFCand->
muonRef()->innerTrack().
get();
226 track = chargedPFCand->
muonRef()->globalTrack().
get();
228 track = chargedPFCand->
muonRef()->outerTrack().
get();
232 track = nextChargedHadron->getChargedPFCandidate()->bestTrack();
235 if (track ==
nullptr) {
236 if (nextChargedHadron->getTrack().isNonnull()) {
237 track = nextChargedHadron->getTrack().get();
238 }
else if (nextChargedHadron->getLostTrackCandidate().isNonnull()) {
239 track = nextChargedHadron->getLostTrackCandidate()->bestTrack();
244 bool isTrack_overlap =
false;
246 double track_eta = track->
eta();
247 double track_phi = track->
phi();
248 for (std::list<etaPhiPair>::const_iterator trackInCleanCollection = tracksInCleanCollection.begin();
249 trackInCleanCollection != tracksInCleanCollection.end();
250 ++trackInCleanCollection) {
251 double dR =
deltaR(track_eta, track_phi, trackInCleanCollection->first, trackInCleanCollection->second);
253 isTrack_overlap =
true;
257 edm::LogPrint(
"PFRecoTauChHProducer") <<
"isTrack_overlap = " << isTrack_overlap;
263 bool isNeutralPFCand_overlap =
false;
265 for (std::set<reco::CandidatePtr>::const_iterator neutralPFCandInCleanCollection =
266 neutralPFCandsInCleanCollection.begin();
267 neutralPFCandInCleanCollection != neutralPFCandsInCleanCollection.end();
268 ++neutralPFCandInCleanCollection) {
269 if ((*neutralPFCandInCleanCollection) == nextChargedHadron->getChargedPFCandidate())
270 isNeutralPFCand_overlap =
true;
274 edm::LogPrint(
"PFRecoTauChHProducer") <<
"isNeutralPFCand_overlap = " << isNeutralPFCand_overlap;
276 if (isNeutralPFCand_overlap)
280 std::vector<reco::CandidatePtr> uniqueNeutralPFCands;
282 nextChargedHadron->getNeutralPFCandidates().end(),
283 neutralPFCandsInCleanCollection.begin(),
284 neutralPFCandsInCleanCollection.end(),
285 std::back_inserter(uniqueNeutralPFCands));
287 if (uniqueNeutralPFCands.size() ==
288 nextChargedHadron->getNeutralPFCandidates()
291 tracksInCleanCollection.push_back(std::make_pair(track->
eta(), track->
phi()));
292 neutralPFCandsInCleanCollection.insert(nextChargedHadron->getNeutralPFCandidates().begin(),
293 nextChargedHadron->getNeutralPFCandidates().end());
295 edm::LogPrint(
"PFRecoTauChHProducer") <<
"--> adding nextChargedHadron to output collection.";
297 cleanedChargedHadrons.push_back(*nextChargedHadron);
299 nextChargedHadron->neutralPFCandidates_.clear();
300 for (
auto const& neutralPFCand : uniqueNeutralPFCands) {
301 nextChargedHadron->neutralPFCandidates_.push_back(neutralPFCand);
308 uncleanedChargedHadrons.end(),
310 [
this](
const auto&
a,
const auto&
b) {
return (*
predicate_)(*
a,
b); });
312 edm::LogPrint(
"PFRecoTauChHProducer") <<
"--> removing non-unique neutral PFCandidates and reinserting "
313 "nextChargedHadron in uncleaned collection.";
315 uncleanedChargedHadrons.insert(insertionPoint,
std::move(nextChargedHadron));
320 for (
auto const& had : cleanedChargedHadrons) {
326 pfJetChargedHadronAssociations->setValue(pfJet.key(), cleanedChargedHadrons);
332 template <
typename T>
336 for (
auto const& ranker :
rankers_) {
337 constexpr
unsigned width = 25;
339 <<
" " << std::setiosflags(std::ios::left) << std::setw(width) << ranker->name() <<
" "
340 << std::resetiosflags(std::ios::left) << std::setprecision(3) << (*ranker)(chargedHadron) << std::endl;
350 desc_ranking.
add<
double>(
"selectionFailValue", 1000.0);
351 desc_ranking.
add<
std::string>(
"selection",
"algoIs(\"kChargedPFCandidate\")");
353 desc_ranking.
add<
std::string>(
"plugin",
"PFRecoTauChargedHadronStringQuality");
357 pset_ranking.addParameter<
double>(
"selectionFailValue", 1000.0);
358 pset_ranking.addParameter<
std::string>(
"selection",
"algoIs(\"kChargedPFCandidate\")");
359 pset_ranking.addParameter<
std::string>(
"name",
"ChargedPFCandidate");
360 pset_ranking.addParameter<
std::string>(
"plugin",
"PFRecoTauChargedHadronStringQuality");
361 std::vector<edm::ParameterSet> vpsd_ranking;
362 vpsd_ranking.push_back(pset_ranking);
364 desc.
addVPSet(
"ranking", desc_ranking, vpsd_ranking);
367 desc.
add<
int>(
"verbosity", 0);
368 desc.
add<
double>(
"maxJetAbsEta", 2.5);
370 desc.
add<
double>(
"minJetPt", 14.0);
375 desc_builders.
add<
double>(
"minMergeChargedHadronPt");
379 desc_builders.
addOptional<
bool>(
"dRconeLimitedToJetArea");
380 desc_builders.
addOptional<
double>(
"dRmergeNeutralHadron");
381 desc_builders.
addOptional<
double>(
"dRmergePhoton");
388 desc_builders.
add<
double>(
"minMergeGammaEt");
389 desc_builders.
add<
int>(
"verbosity", 0);
390 desc_builders.
add<
double>(
"minMergeNeutralHadronEt");
392 desc_builders.
addOptional<
double>(
"dRmergePhotonWrtChargedHadron");
393 desc_builders.
addOptional<
double>(
"dRmergePhotonWrtNeutralHadron");
394 desc_builders.
addOptional<
int>(
"maxUnmatchedBlockElementsNeutralHadron");
395 desc_builders.
addOptional<
double>(
"dRmergePhotonWrtElectron");
396 desc_builders.
addOptional<std::vector<int>>(
"chargedHadronCandidatesParticleIds");
397 desc_builders.
addOptional<
int>(
"minBlockElementMatchesPhoton");
398 desc_builders.
addOptional<
double>(
"dRmergeNeutralHadronWrtNeutralHadron");
399 desc_builders.
addOptional<
int>(
"maxUnmatchedBlockElementsPhoton");
400 desc_builders.
addOptional<
double>(
"dRmergeNeutralHadronWrtOther");
401 desc_builders.
addOptional<
double>(
"dRmergeNeutralHadronWrtElectron");
402 desc_builders.
addOptional<
int>(
"minBlockElementMatchesNeutralHadron");
403 desc_builders.
addOptional<
double>(
"dRmergePhotonWrtOther");
404 desc_builders.
addOptional<
double>(
"dRmergeNeutralHadronWrtChargedHadron");
408 pset_builders.addParameter<
std::string>(
"plugin",
"");
412 std::vector<edm::ParameterSet> vpsd_builders;
413 vpsd_builders.push_back(pset_builders);
415 desc.
addVPSet(
"builders", desc_builders, vpsd_builders);
418 descriptions.
add(
"pfRecoTauChargedHadronProducer", desc);
Builder::return_type ChargedHadronVector
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
edm::EDGetTokenT< reco::JetView > Jets_token
bool isNonnull() const
Checks for non-null.
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
static void fillDescriptions(edm::ParameterSetDescription &descriptions)
Declare all parameters read from python config file.
void print(const T &chargedHadron)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
ChargedHadronVector return_type
PFRecoTauChargedHadronProducer(const edm::ParameterSet &cfg)
#define DEFINE_FWK_MODULE(type)
std::vector< ParameterSet > VParameterSet
std::vector< std::unique_ptr< Builder > > builders_
double phi() const
azimuthal angle of momentum vector
void produce(edm::Event &evt, const edm::EventSetup &es) override
Log< level::Error, false > LogError
reco::TrackRef trackRef() const
edm::RefToBaseProd< reco::Jet > JetRefBaseProd
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double eta() const
pseudorapidity of momentum vector
reco::tau::PFRecoTauChargedHadronBuilderPlugin Builder
reco::tau::RecoTauLexicographicalRanking< RankerList, reco::PFRecoTauChargedHadron > ChargedHadronPredicate
void addParameter(std::string const &name, T const &value)
Abs< T >::type abs(const T &t)
T const * get() const
Returns C++ pointer to the item.
std::vector< std::unique_ptr< Ranker > > RankerList
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Warning, true > LogPrint
reco::MuonRef muonRef() const
reco::tau::PFRecoTauChargedHadronQualityPlugin Ranker
T getParameter(std::string const &) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::unique_ptr< ChargedHadronPredicate > predicate_
~PFRecoTauChargedHadronProducer() override
Particle reconstructed by the particle flow algorithm.
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
reco::GsfTrackRef gsfTrackRef() const
void push_back(const RefToBase< T > &)
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)
std::list< std::unique_ptr< reco::PFRecoTauChargedHadron > > ChargedHadronList
std::unique_ptr< StringCutObjectSelector< reco::PFRecoTauChargedHadron > > outputSelector_