140 edm::LogPrint(
"PFRecoTauChHProducer") <<
"<PFRecoTauChargedHadronProducer::produce>:";
146 builder.setup(evt, es);
155 size_t nElements =
jets->size();
156 for (
size_t i = 0;
i < nElements; ++
i) {
161 std::unique_ptr<reco::PFJetChargedHadronAssociation> pfJetChargedHadronAssociations;
166 pfJetChargedHadronAssociations = std::make_unique<reco::PFJetChargedHadronAssociation>();
170 for (
const auto& pfJet :
pfJets) {
184 edm::LogPrint(
"PFRecoTauChHProducer") <<
"result of builder = " << builder.name() <<
":";
187 uncleanedChargedHadrons.transfer(uncleanedChargedHadrons.end(),
result);
190 <<
"Exception caught in builder plugin " << builder.name() <<
", rethrowing" << std::endl;
199 std::vector<reco::PFRecoTauChargedHadron> cleanedChargedHadrons;
202 typedef std::pair<double, double> etaPhiPair;
203 std::list<etaPhiPair> tracksInCleanCollection;
204 std::set<reco::CandidatePtr> neutralPFCandsInCleanCollection;
206 while (!uncleanedChargedHadrons.empty()) {
208 std::unique_ptr<reco::PFRecoTauChargedHadron> nextChargedHadron(uncleanedChargedHadrons.pop_front().release());
210 edm::LogPrint(
"PFRecoTauChHProducer") <<
"processing nextChargedHadron:";
211 edm::LogPrint(
"PFRecoTauChHProducer") << (*nextChargedHadron);
219 if (nextChargedHadron->getChargedPFCandidate().isNonnull()) {
221 dynamic_cast<const reco::PFCandidate*>(&*nextChargedHadron->getChargedPFCandidate());
235 if (nextChargedHadron->getTrack().isNonnull() && !
track) {
236 track = nextChargedHadron->getTrack().get();
240 bool isTrack_overlap =
false;
242 double track_eta =
track->eta();
243 double track_phi =
track->phi();
244 for (std::list<etaPhiPair>::const_iterator trackInCleanCollection = tracksInCleanCollection.begin();
245 trackInCleanCollection != tracksInCleanCollection.end();
246 ++trackInCleanCollection) {
247 double dR =
deltaR(track_eta, track_phi, trackInCleanCollection->first, trackInCleanCollection->second);
249 isTrack_overlap =
true;
253 edm::LogPrint(
"PFRecoTauChHProducer") <<
"isTrack_overlap = " << isTrack_overlap;
259 bool isNeutralPFCand_overlap =
false;
261 for (std::set<reco::CandidatePtr>::const_iterator neutralPFCandInCleanCollection =
262 neutralPFCandsInCleanCollection.begin();
263 neutralPFCandInCleanCollection != neutralPFCandsInCleanCollection.end();
264 ++neutralPFCandInCleanCollection) {
265 if ((*neutralPFCandInCleanCollection) == nextChargedHadron->getChargedPFCandidate())
266 isNeutralPFCand_overlap =
true;
270 edm::LogPrint(
"PFRecoTauChHProducer") <<
"isNeutralPFCand_overlap = " << isNeutralPFCand_overlap;
272 if (isNeutralPFCand_overlap)
276 std::vector<reco::CandidatePtr> uniqueNeutralPFCands;
277 std::set_difference(nextChargedHadron->getNeutralPFCandidates().begin(),
278 nextChargedHadron->getNeutralPFCandidates().end(),
279 neutralPFCandsInCleanCollection.begin(),
280 neutralPFCandsInCleanCollection.end(),
281 std::back_inserter(uniqueNeutralPFCands));
283 if (uniqueNeutralPFCands.size() ==
284 nextChargedHadron->getNeutralPFCandidates()
287 tracksInCleanCollection.push_back(std::make_pair(
track->eta(),
track->phi()));
288 neutralPFCandsInCleanCollection.insert(nextChargedHadron->getNeutralPFCandidates().begin(),
289 nextChargedHadron->getNeutralPFCandidates().end());
291 edm::LogPrint(
"PFRecoTauChHProducer") <<
"--> adding nextChargedHadron to output collection.";
293 cleanedChargedHadrons.push_back(*nextChargedHadron);
295 nextChargedHadron->neutralPFCandidates_.clear();
296 for (
auto const& neutralPFCand : uniqueNeutralPFCands) {
297 nextChargedHadron->neutralPFCandidates_.push_back(neutralPFCand);
304 uncleanedChargedHadrons.begin(), uncleanedChargedHadrons.end(), *nextChargedHadron, *
predicate_);
306 edm::LogPrint(
"PFRecoTauChHProducer") <<
"--> removing non-unique neutral PFCandidates and reinserting "
307 "nextChargedHadron in uncleaned collection.";
309 uncleanedChargedHadrons.insert(insertionPoint,
std::move(nextChargedHadron));
314 print(cleanedChargedHadrons);
318 pfJetChargedHadronAssociations->setValue(pfJet.key(), cleanedChargedHadrons);