140 edm::LogPrint(
"PFRecoTauChHProducer")<<
"<PFRecoTauChargedHadronProducer::produce>:" ;
146 builder.setup(evt, es);
157 std::unique_ptr<reco::PFJetChargedHadronAssociation> pfJetChargedHadronAssociations;
160 if ( pfJets.
size() ) {
162 evt.
get(pfJets.
id(), pfJetCollectionHandle);
163 pfJetChargedHadronAssociations = std::make_unique<reco::PFJetChargedHadronAssociation>(
reco::PFJetRefProd(pfJetCollectionHandle));
165 pfJetChargedHadronAssociations = std::make_unique<reco::PFJetChargedHadronAssociation>();
182 edm::LogPrint(
"PFRecoTauChHProducer")<<
"result of builder = " << builder.name() <<
":" ;
185 uncleanedChargedHadrons.transfer(uncleanedChargedHadrons.end(),
result);
188 <<
"Exception caught in builder plugin " << builder.name()
189 <<
", rethrowing" << std::endl;
198 std::vector<reco::PFRecoTauChargedHadron> cleanedChargedHadrons;
201 typedef std::pair<double, double> etaPhiPair;
202 std::list<etaPhiPair> tracksInCleanCollection;
203 std::set<reco::PFCandidatePtr> neutralPFCandsInCleanCollection;
205 while ( uncleanedChargedHadrons.size() >= 1 ) {
208 std::auto_ptr<reco::PFRecoTauChargedHadron> nextChargedHadron(uncleanedChargedHadrons.pop_front().release());
210 edm::LogPrint(
"PFRecoTauChHProducer")<<
"processing nextChargedHadron:" ;
211 edm::LogPrint(
"PFRecoTauChHProducer")<< (*nextChargedHadron);
218 if ( nextChargedHadron->getChargedPFCandidate().isNonnull() ) {
220 if ( chargedPFCand->trackRef().
isNonnull() ) track = chargedPFCand->trackRef().
get();
221 else if ( chargedPFCand->muonRef().
isNonnull() && chargedPFCand->muonRef()->innerTrack().
isNonnull() ) track = chargedPFCand->muonRef()->innerTrack().
get();
222 else if ( chargedPFCand->muonRef().
isNonnull() && chargedPFCand->muonRef()->globalTrack().
isNonnull() ) track = chargedPFCand->muonRef()->globalTrack().
get();
223 else if ( chargedPFCand->muonRef().
isNonnull() && chargedPFCand->muonRef()->outerTrack().
isNonnull() ) track = chargedPFCand->muonRef()->outerTrack().
get();
224 else if ( chargedPFCand->gsfTrackRef().
isNonnull() ) track = chargedPFCand->gsfTrackRef().
get();
226 if ( nextChargedHadron->getTrack().isNonnull() && !
track ) {
227 track = nextChargedHadron->getTrack().get();
231 bool isTrack_overlap =
false;
233 double track_eta = track->
eta();
234 double track_phi = track->
phi();
235 for ( std::list<etaPhiPair>::const_iterator trackInCleanCollection = tracksInCleanCollection.begin();
236 trackInCleanCollection != tracksInCleanCollection.end(); ++trackInCleanCollection ) {
237 double dR =
deltaR(track_eta, track_phi, trackInCleanCollection->first, trackInCleanCollection->second);
238 if ( dR < 1.
e-4 ) isTrack_overlap =
true;
242 edm::LogPrint(
"PFRecoTauChHProducer")<<
"isTrack_overlap = " << isTrack_overlap ;
244 if ( isTrack_overlap )
continue;
247 bool isNeutralPFCand_overlap =
false;
249 for ( std::set<reco::PFCandidatePtr>::const_iterator neutralPFCandInCleanCollection = neutralPFCandsInCleanCollection.begin();
250 neutralPFCandInCleanCollection != neutralPFCandsInCleanCollection.end(); ++neutralPFCandInCleanCollection ) {
251 if ( (*neutralPFCandInCleanCollection) == nextChargedHadron->getChargedPFCandidate() ) isNeutralPFCand_overlap =
true;
255 edm::LogPrint(
"PFRecoTauChHProducer")<<
"isNeutralPFCand_overlap = " << isNeutralPFCand_overlap ;
257 if ( isNeutralPFCand_overlap )
continue;
260 std::vector<reco::PFCandidatePtr> uniqueNeutralPFCands;
261 std::set_difference(nextChargedHadron->getNeutralPFCandidates().begin(),
262 nextChargedHadron->getNeutralPFCandidates().end(),
263 neutralPFCandsInCleanCollection.begin(),
264 neutralPFCandsInCleanCollection.end(),
265 std::back_inserter(uniqueNeutralPFCands));
267 if ( uniqueNeutralPFCands.size() == nextChargedHadron->getNeutralPFCandidates().size() ) {
268 if ( track ) tracksInCleanCollection.push_back(std::make_pair(track->
eta(), track->
phi()));
269 neutralPFCandsInCleanCollection.insert(nextChargedHadron->getNeutralPFCandidates().begin(), nextChargedHadron->getNeutralPFCandidates().end());
271 edm::LogPrint(
"PFRecoTauChHProducer")<<
"--> adding nextChargedHadron to output collection." ;
273 cleanedChargedHadrons.push_back(*nextChargedHadron);
275 nextChargedHadron->neutralPFCandidates_.clear();
277 nextChargedHadron->neutralPFCandidates_.push_back(neutralPFCand);
283 ChargedHadronList::iterator insertionPoint = std::lower_bound(uncleanedChargedHadrons.begin(), uncleanedChargedHadrons.end(), *nextChargedHadron, *
predicate_);
285 edm::LogPrint(
"PFRecoTauChHProducer")<<
"--> removing non-unique neutral PFCandidates and reinserting nextChargedHadron in uncleaned collection." ;
287 uncleanedChargedHadrons.insert(insertionPoint, nextChargedHadron);
292 print(cleanedChargedHadrons);
296 pfJetChargedHadronAssociations->setValue(pfJet.
key(), cleanedChargedHadrons);
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
T const * get() const
Returns C++ pointer to the item.
double phi() const
azimuthal angle of momentum vector
key_type key() const
Accessor for product key.
edm::EDGetTokenT< reco::CandidateView > Jets_token
void print(const T &chargedHadrons)
double eta() const
pseudorapidity of momentum vector
reco::tau::PFRecoTauChargedHadronBuilderPlugin Builder
ProductID id() const
Accessor for product ID.
boost::ptr_vector< reco::PFRecoTauChargedHadron > ChargedHadronVector
std::auto_ptr< ChargedHadronPredicate > predicate_
Abs< T >::type abs(const T &t)
bool get(ProductID const &oid, Handle< PROD > &result) const
edm::RefProd< PFJetCollection > PFJetRefProd
bool isNonnull() const
Checks for non-null.
double deltaR(double eta1, double eta2, double phi1, double phi2)
std::auto_ptr< StringCutObjectSelector< reco::PFRecoTauChargedHadron > > outputSelector_
boost::ptr_list< reco::PFRecoTauChargedHadron > ChargedHadronList
size_type size() const
Size of the RefVector.
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)