139 edm::LogPrint(
"PFRecoTauChHProducer")<<
"<PFRecoTauChargedHadronProducer::produce>:" ;
145 builder.setup(evt, es);
156 std::unique_ptr<reco::PFJetChargedHadronAssociation> pfJetChargedHadronAssociations;
159 if ( !pfJets.
empty() ) {
161 evt.
get(pfJets.
id(), pfJetCollectionHandle);
162 pfJetChargedHadronAssociations = std::make_unique<reco::PFJetChargedHadronAssociation>(
reco::PFJetRefProd(pfJetCollectionHandle));
164 pfJetChargedHadronAssociations = std::make_unique<reco::PFJetChargedHadronAssociation>();
168 for(
auto const& pfJet : pfJets ) {
177 for(
auto const& builder : builders_ ) {
181 edm::LogPrint(
"PFRecoTauChHProducer")<<
"result of builder = " << builder.name() <<
":" ;
184 uncleanedChargedHadrons.transfer(uncleanedChargedHadrons.end(),
result);
187 <<
"Exception caught in builder plugin " << builder.name()
188 <<
", rethrowing" << std::endl;
197 std::vector<reco::PFRecoTauChargedHadron> cleanedChargedHadrons;
200 typedef std::pair<double, double> etaPhiPair;
201 std::list<etaPhiPair> tracksInCleanCollection;
202 std::set<reco::PFCandidatePtr> neutralPFCandsInCleanCollection;
204 while ( !uncleanedChargedHadrons.empty() ) {
207 std::auto_ptr<reco::PFRecoTauChargedHadron> nextChargedHadron(uncleanedChargedHadrons.pop_front().release());
209 edm::LogPrint(
"PFRecoTauChHProducer")<<
"processing nextChargedHadron:" ;
210 edm::LogPrint(
"PFRecoTauChHProducer")<< (*nextChargedHadron);
217 if ( nextChargedHadron->getChargedPFCandidate().isNonnull() ) {
219 if ( chargedPFCand->trackRef().
isNonnull() ) track = chargedPFCand->trackRef().
get();
220 else if ( chargedPFCand->muonRef().
isNonnull() && chargedPFCand->muonRef()->innerTrack().
isNonnull() ) track = chargedPFCand->muonRef()->innerTrack().
get();
221 else if ( chargedPFCand->muonRef().
isNonnull() && chargedPFCand->muonRef()->globalTrack().
isNonnull() ) track = chargedPFCand->muonRef()->globalTrack().
get();
222 else if ( chargedPFCand->muonRef().
isNonnull() && chargedPFCand->muonRef()->outerTrack().
isNonnull() ) track = chargedPFCand->muonRef()->outerTrack().
get();
223 else if ( chargedPFCand->gsfTrackRef().
isNonnull() ) track = chargedPFCand->gsfTrackRef().
get();
225 if ( nextChargedHadron->getTrack().isNonnull() && !
track ) {
226 track = nextChargedHadron->getTrack().get();
230 bool isTrack_overlap =
false;
232 double track_eta = track->
eta();
233 double track_phi = track->
phi();
234 for ( std::list<etaPhiPair>::const_iterator trackInCleanCollection = tracksInCleanCollection.begin();
235 trackInCleanCollection != tracksInCleanCollection.end(); ++trackInCleanCollection ) {
236 double dR =
deltaR(track_eta, track_phi, trackInCleanCollection->first, trackInCleanCollection->second);
237 if ( dR < 1.
e-4 ) isTrack_overlap =
true;
241 edm::LogPrint(
"PFRecoTauChHProducer")<<
"isTrack_overlap = " << isTrack_overlap ;
243 if ( isTrack_overlap )
continue;
246 bool isNeutralPFCand_overlap =
false;
248 for ( std::set<reco::PFCandidatePtr>::const_iterator neutralPFCandInCleanCollection = neutralPFCandsInCleanCollection.begin();
249 neutralPFCandInCleanCollection != neutralPFCandsInCleanCollection.end(); ++neutralPFCandInCleanCollection ) {
250 if ( (*neutralPFCandInCleanCollection) == nextChargedHadron->getChargedPFCandidate() ) isNeutralPFCand_overlap =
true;
254 edm::LogPrint(
"PFRecoTauChHProducer")<<
"isNeutralPFCand_overlap = " << isNeutralPFCand_overlap ;
256 if ( isNeutralPFCand_overlap )
continue;
259 std::vector<reco::PFCandidatePtr> uniqueNeutralPFCands;
260 std::set_difference(nextChargedHadron->getNeutralPFCandidates().begin(),
261 nextChargedHadron->getNeutralPFCandidates().end(),
262 neutralPFCandsInCleanCollection.begin(),
263 neutralPFCandsInCleanCollection.end(),
264 std::back_inserter(uniqueNeutralPFCands));
266 if ( uniqueNeutralPFCands.size() == nextChargedHadron->getNeutralPFCandidates().size() ) {
267 if ( track ) tracksInCleanCollection.push_back(std::make_pair(track->
eta(), track->
phi()));
268 neutralPFCandsInCleanCollection.insert(nextChargedHadron->getNeutralPFCandidates().begin(), nextChargedHadron->getNeutralPFCandidates().end());
270 edm::LogPrint(
"PFRecoTauChHProducer")<<
"--> adding nextChargedHadron to output collection." ;
272 cleanedChargedHadrons.push_back(*nextChargedHadron);
274 nextChargedHadron->neutralPFCandidates_.clear();
275 for(
auto const& neutralPFCand : uniqueNeutralPFCands ) {
276 nextChargedHadron->neutralPFCandidates_.push_back(neutralPFCand);
282 ChargedHadronList::iterator insertionPoint = std::lower_bound(uncleanedChargedHadrons.begin(), uncleanedChargedHadrons.end(), *nextChargedHadron, *
predicate_);
284 edm::LogPrint(
"PFRecoTauChHProducer")<<
"--> removing non-unique neutral PFCandidates and reinserting nextChargedHadron in uncleaned collection." ;
286 uncleanedChargedHadrons.insert(insertionPoint, nextChargedHadron);
291 print(cleanedChargedHadrons);
295 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
bool empty() const
Is the RefVector empty.
edm::EDGetTokenT< reco::CandidateView > Jets_token
void print(const T &chargedHadrons)
double eta() const
pseudorapidity of momentum vector
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
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)