141 edm::LogPrint(
"PFRecoTauChHProducer")<<
"<PFRecoTauChargedHadronProducer::produce>:" ;
147 builder.setup(evt, es);
156 size_t nElements = jets->
size();
157 for (
size_t i = 0;
i < nElements; ++
i) {
162 std::unique_ptr<reco::PFJetChargedHadronAssociation> pfJetChargedHadronAssociations;
165 if ( !pfJets.
empty() ) {
166 pfJetChargedHadronAssociations = std::make_unique<reco::PFJetChargedHadronAssociation>(
reco::JetRefBaseProd(jets));
168 pfJetChargedHadronAssociations = std::make_unique<reco::PFJetChargedHadronAssociation>();
172 for(
const auto& pfJet : pfJets ) {
181 for(
auto const& builder : builders_ ) {
185 edm::LogPrint(
"PFRecoTauChHProducer")<<
"result of builder = " << builder.name() <<
":" ;
188 uncleanedChargedHadrons.transfer(uncleanedChargedHadrons.end(),
result);
191 <<
"Exception caught in builder plugin " << builder.name()
192 <<
", rethrowing" << std::endl;
201 std::vector<reco::PFRecoTauChargedHadron> cleanedChargedHadrons;
204 typedef std::pair<double, double> etaPhiPair;
205 std::list<etaPhiPair> tracksInCleanCollection;
206 std::set<reco::CandidatePtr> neutralPFCandsInCleanCollection;
208 while ( !uncleanedChargedHadrons.empty() ) {
211 std::auto_ptr<reco::PFRecoTauChargedHadron> nextChargedHadron(uncleanedChargedHadrons.pop_front().release());
213 edm::LogPrint(
"PFRecoTauChHProducer")<<
"processing nextChargedHadron:" ;
214 edm::LogPrint(
"PFRecoTauChHProducer")<< (*nextChargedHadron);
221 if ( nextChargedHadron->getChargedPFCandidate().isNonnull() ) {
231 if ( nextChargedHadron->getTrack().isNonnull() && !
track ) {
232 track = nextChargedHadron->getTrack().get();
236 bool isTrack_overlap =
false;
238 double track_eta = track->
eta();
239 double track_phi = track->
phi();
240 for ( std::list<etaPhiPair>::const_iterator trackInCleanCollection = tracksInCleanCollection.begin();
241 trackInCleanCollection != tracksInCleanCollection.end(); ++trackInCleanCollection ) {
242 double dR =
deltaR(track_eta, track_phi, trackInCleanCollection->first, trackInCleanCollection->second);
243 if ( dR < 1.
e-4 ) isTrack_overlap =
true;
247 edm::LogPrint(
"PFRecoTauChHProducer")<<
"isTrack_overlap = " << isTrack_overlap ;
249 if ( isTrack_overlap )
continue;
252 bool isNeutralPFCand_overlap =
false;
254 for ( std::set<reco::CandidatePtr>::const_iterator neutralPFCandInCleanCollection = neutralPFCandsInCleanCollection.begin();
255 neutralPFCandInCleanCollection != neutralPFCandsInCleanCollection.end(); ++neutralPFCandInCleanCollection ) {
256 if ( (*neutralPFCandInCleanCollection) == nextChargedHadron->getChargedPFCandidate() ) isNeutralPFCand_overlap =
true;
261 edm::LogPrint(
"PFRecoTauChHProducer")<<
"isNeutralPFCand_overlap = " << isNeutralPFCand_overlap ;
263 if ( isNeutralPFCand_overlap )
continue;
266 std::vector<reco::CandidatePtr> uniqueNeutralPFCands;
267 std::set_difference(nextChargedHadron->getNeutralPFCandidates().begin(),
268 nextChargedHadron->getNeutralPFCandidates().end(),
269 neutralPFCandsInCleanCollection.begin(),
270 neutralPFCandsInCleanCollection.end(),
271 std::back_inserter(uniqueNeutralPFCands));
273 if ( uniqueNeutralPFCands.size() == nextChargedHadron->getNeutralPFCandidates().size() ) {
274 if ( track ) tracksInCleanCollection.push_back(std::make_pair(track->
eta(), track->
phi()));
275 neutralPFCandsInCleanCollection.insert(nextChargedHadron->getNeutralPFCandidates().begin(), nextChargedHadron->getNeutralPFCandidates().end());
277 edm::LogPrint(
"PFRecoTauChHProducer")<<
"--> adding nextChargedHadron to output collection." ;
279 cleanedChargedHadrons.push_back(*nextChargedHadron);
281 nextChargedHadron->neutralPFCandidates_.clear();
282 for(
auto const& neutralPFCand : uniqueNeutralPFCands ) {
283 nextChargedHadron->neutralPFCandidates_.push_back(neutralPFCand);
289 ChargedHadronList::iterator insertionPoint =
std::lower_bound(uncleanedChargedHadrons.begin(), uncleanedChargedHadrons.end(), *nextChargedHadron, *
predicate_);
291 edm::LogPrint(
"PFRecoTauChHProducer")<<
"--> removing non-unique neutral PFCandidates and reinserting nextChargedHadron in uncleaned collection." ;
293 uncleanedChargedHadrons.insert(insertionPoint, nextChargedHadron);
298 print(cleanedChargedHadrons);
302 pfJetChargedHadronAssociations->setValue(pfJet.key(), cleanedChargedHadrons);
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::EDGetTokenT< reco::JetView > Jets_token
bool isNonnull() const
Checks for non-null.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double phi() const
azimuthal angle of momentum vector
reco::TrackRef trackRef() const
RefToBase< value_type > refAt(size_type i) const
edm::RefToBaseProd< reco::Jet > JetRefBaseProd
void print(const T &chargedHadrons)
double eta() const
pseudorapidity of momentum vector
boost::ptr_vector< reco::PFRecoTauChargedHadron > ChargedHadronVector
std::auto_ptr< ChargedHadronPredicate > predicate_
Abs< T >::type abs(const T &t)
T const * get() const
Returns C++ pointer to the item.
reco::MuonRef muonRef() const
std::auto_ptr< StringCutObjectSelector< reco::PFRecoTauChargedHadron > > outputSelector_
boost::ptr_list< reco::PFRecoTauChargedHadron > ChargedHadronList
Particle reconstructed by the particle flow algorithm.
reco::GsfTrackRef gsfTrackRef() const
void push_back(const RefToBase< T > &)
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)