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());
234 track = nextChargedHadron->getChargedPFCandidate()->bestTrack();
237 if (
track ==
nullptr) {
238 if (nextChargedHadron->getTrack().isNonnull()) {
239 track = nextChargedHadron->getTrack().get();
240 }
else if (nextChargedHadron->getLostTrackCandidate().isNonnull()) {
241 track = nextChargedHadron->getLostTrackCandidate()->bestTrack();
246 bool isTrack_overlap =
false;
248 double track_eta =
track->eta();
249 double track_phi =
track->phi();
250 for (std::list<etaPhiPair>::const_iterator trackInCleanCollection = tracksInCleanCollection.begin();
251 trackInCleanCollection != tracksInCleanCollection.end();
252 ++trackInCleanCollection) {
253 double dR =
deltaR(track_eta, track_phi, trackInCleanCollection->first, trackInCleanCollection->second);
255 isTrack_overlap =
true;
259 edm::LogPrint(
"PFRecoTauChHProducer") <<
"isTrack_overlap = " << isTrack_overlap;
265 bool isNeutralPFCand_overlap =
false;
267 for (std::set<reco::CandidatePtr>::const_iterator neutralPFCandInCleanCollection =
268 neutralPFCandsInCleanCollection.begin();
269 neutralPFCandInCleanCollection != neutralPFCandsInCleanCollection.end();
270 ++neutralPFCandInCleanCollection) {
271 if ((*neutralPFCandInCleanCollection) == nextChargedHadron->getChargedPFCandidate())
272 isNeutralPFCand_overlap =
true;
276 edm::LogPrint(
"PFRecoTauChHProducer") <<
"isNeutralPFCand_overlap = " << isNeutralPFCand_overlap;
278 if (isNeutralPFCand_overlap)
282 std::vector<reco::CandidatePtr> uniqueNeutralPFCands;
283 std::set_difference(nextChargedHadron->getNeutralPFCandidates().begin(),
284 nextChargedHadron->getNeutralPFCandidates().end(),
285 neutralPFCandsInCleanCollection.begin(),
286 neutralPFCandsInCleanCollection.end(),
287 std::back_inserter(uniqueNeutralPFCands));
289 if (uniqueNeutralPFCands.size() ==
290 nextChargedHadron->getNeutralPFCandidates()
293 tracksInCleanCollection.push_back(std::make_pair(
track->eta(),
track->phi()));
294 neutralPFCandsInCleanCollection.insert(nextChargedHadron->getNeutralPFCandidates().begin(),
295 nextChargedHadron->getNeutralPFCandidates().end());
297 edm::LogPrint(
"PFRecoTauChHProducer") <<
"--> adding nextChargedHadron to output collection.";
299 cleanedChargedHadrons.push_back(*nextChargedHadron);
301 nextChargedHadron->neutralPFCandidates_.clear();
302 for (
auto const& neutralPFCand : uniqueNeutralPFCands) {
303 nextChargedHadron->neutralPFCandidates_.push_back(neutralPFCand);
310 uncleanedChargedHadrons.begin(), uncleanedChargedHadrons.end(), *nextChargedHadron, *
predicate_);
312 edm::LogPrint(
"PFRecoTauChHProducer") <<
"--> removing non-unique neutral PFCandidates and reinserting "
313 "nextChargedHadron in uncleaned collection.";
315 uncleanedChargedHadrons.insert(insertionPoint,
std::move(nextChargedHadron));
320 print(cleanedChargedHadrons);
324 pfJetChargedHadronAssociations->setValue(pfJet.key(), cleanedChargedHadrons);