40 #include <boost/ptr_container/ptr_vector.hpp>
41 #include <boost/ptr_container/ptr_list.hpp>
42 #include <boost/foreach.hpp>
62 void print(
const T& chargedHadrons);
85 std::auto_ptr<StringCutObjectSelector<reco::PFRecoTauChargedHadron> >
outputSelector_;
101 for ( edm::VParameterSet::const_iterator pset = psets_builders.begin();
102 pset != psets_builders.end(); ++pset ) {
111 for ( edm::VParameterSet::const_iterator pset = psets_rankers.begin();
112 pset != psets_rankers.end(); ++pset ) {
123 if ( cfg.
exists(
"outputSelection") ) {
125 if ( selection !=
"" ) {
130 produces<reco::PFJetChargedHadronAssociation>();
136 edm::LogPrint(
"PFRecoTauChHProducer")<<
"<PFRecoTauChargedHadronProducer::produce>:" ;
142 builder.
setup(evt, es);
153 std::auto_ptr<reco::PFJetChargedHadronAssociation> pfJetChargedHadronAssociations;
156 if ( pfJets.
size() ) {
158 evt.
get(pfJets.
id(), pfJetCollectionHandle);
175 edm::LogPrint(
"PFRecoTauChHProducer")<<
"result of builder = " << builder.
name() <<
":" ;
178 uncleanedChargedHadrons.transfer(uncleanedChargedHadrons.end(),
result);
181 <<
"Exception caught in builder plugin " << builder.
name()
182 <<
", rethrowing" << std::endl;
191 std::vector<reco::PFRecoTauChargedHadron> cleanedChargedHadrons;
194 typedef std::pair<double, double> etaPhiPair;
195 std::list<etaPhiPair> tracksInCleanCollection;
196 std::set<reco::PFCandidatePtr> neutralPFCandsInCleanCollection;
198 while ( uncleanedChargedHadrons.size() >= 1 ) {
201 std::auto_ptr<reco::PFRecoTauChargedHadron> nextChargedHadron(uncleanedChargedHadrons.pop_front().release());
203 edm::LogPrint(
"PFRecoTauChHProducer")<<
"processing nextChargedHadron:" ;
204 edm::LogPrint(
"PFRecoTauChHProducer")<< (*nextChargedHadron);
211 if ( nextChargedHadron->getChargedPFCandidate().isNonnull() ) {
213 if ( chargedPFCand->trackRef().
isNonnull() ) track = chargedPFCand->trackRef().
get();
214 else if ( chargedPFCand->muonRef().
isNonnull() && chargedPFCand->muonRef()->innerTrack().
isNonnull() ) track = chargedPFCand->muonRef()->innerTrack().
get();
215 else if ( chargedPFCand->muonRef().
isNonnull() && chargedPFCand->muonRef()->globalTrack().
isNonnull() ) track = chargedPFCand->muonRef()->globalTrack().
get();
216 else if ( chargedPFCand->muonRef().
isNonnull() && chargedPFCand->muonRef()->outerTrack().
isNonnull() ) track = chargedPFCand->muonRef()->outerTrack().
get();
217 else if ( chargedPFCand->gsfTrackRef().
isNonnull() ) track = chargedPFCand->gsfTrackRef().
get();
219 if ( nextChargedHadron->getTrack().isNonnull() && !track ) {
220 track = nextChargedHadron->getTrack().get();
224 bool isTrack_overlap =
false;
226 double track_eta = track->
eta();
227 double track_phi = track->
phi();
228 for ( std::list<etaPhiPair>::const_iterator trackInCleanCollection = tracksInCleanCollection.begin();
229 trackInCleanCollection != tracksInCleanCollection.end(); ++trackInCleanCollection ) {
230 double dR =
deltaR(track_eta, track_phi, trackInCleanCollection->first, trackInCleanCollection->second);
231 if ( dR < 1.
e-4 ) isTrack_overlap =
true;
235 edm::LogPrint(
"PFRecoTauChHProducer")<<
"isTrack_overlap = " << isTrack_overlap ;
237 if ( isTrack_overlap )
continue;
240 bool isNeutralPFCand_overlap =
false;
242 for ( std::set<reco::PFCandidatePtr>::const_iterator neutralPFCandInCleanCollection = neutralPFCandsInCleanCollection.begin();
243 neutralPFCandInCleanCollection != neutralPFCandsInCleanCollection.end(); ++neutralPFCandInCleanCollection ) {
244 if ( (*neutralPFCandInCleanCollection) == nextChargedHadron->getChargedPFCandidate() ) isNeutralPFCand_overlap =
true;
248 edm::LogPrint(
"PFRecoTauChHProducer")<<
"isNeutralPFCand_overlap = " << isNeutralPFCand_overlap ;
250 if ( isNeutralPFCand_overlap )
continue;
253 std::vector<reco::PFCandidatePtr> uniqueNeutralPFCands;
254 std::set_difference(nextChargedHadron->getNeutralPFCandidates().begin(),
255 nextChargedHadron->getNeutralPFCandidates().end(),
256 neutralPFCandsInCleanCollection.begin(),
257 neutralPFCandsInCleanCollection.end(),
258 std::back_inserter(uniqueNeutralPFCands));
260 if ( uniqueNeutralPFCands.size() == nextChargedHadron->getNeutralPFCandidates().size() ) {
261 if ( track ) tracksInCleanCollection.push_back(std::make_pair(track->
eta(), track->
phi()));
262 neutralPFCandsInCleanCollection.insert(nextChargedHadron->getNeutralPFCandidates().begin(), nextChargedHadron->getNeutralPFCandidates().end());
264 edm::LogPrint(
"PFRecoTauChHProducer")<<
"--> adding nextChargedHadron to output collection." ;
266 cleanedChargedHadrons.push_back(*nextChargedHadron);
268 nextChargedHadron->neutralPFCandidates_.clear();
270 nextChargedHadron->neutralPFCandidates_.push_back(neutralPFCand);
276 ChargedHadronList::iterator insertionPoint = std::lower_bound(uncleanedChargedHadrons.begin(), uncleanedChargedHadrons.end(), *nextChargedHadron, *
predicate_);
278 edm::LogPrint(
"PFRecoTauChHProducer")<<
"--> removing non-unique neutral PFCandidates and reinserting nextChargedHadron in uncleaned collection." ;
280 uncleanedChargedHadrons.insert(insertionPoint, nextChargedHadron);
285 print(cleanedChargedHadrons);
289 pfJetChargedHadronAssociations->setValue(pfJet.
key(), cleanedChargedHadrons);
292 evt.
put(pfJetChargedHadronAssociations);
295 template <
typename T>
298 for (
typename T::const_iterator chargedHadron = chargedHadrons.begin();
299 chargedHadron != chargedHadrons.end(); ++chargedHadron ) {
302 for ( rankerList::const_iterator ranker =
rankers_.begin();
303 ranker !=
rankers_.end(); ++ranker) {
304 const unsigned width = 25;
305 edm::LogPrint(
"PFRecoTauChHProducer") <<
" " << std::setiosflags(std::ios::left) << std::setw(width) << ranker->name()
306 <<
" " << std::resetiosflags(std::ios::left) << std::setprecision(3) << (*ranker)(*chargedHadron) << std::endl;
T getParameter(std::string const &) const
reco::tau::RecoTauLexicographicalRanking< rankerList, reco::PFRecoTauChargedHadron > ChargedHadronPredicate
boost::ptr_vector< Ranker > rankerList
void produce(edm::Event &evt, const edm::EventSetup &es)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
PFRecoTauChargedHadronProducer(const edm::ParameterSet &cfg)
#define DEFINE_FWK_MODULE(type)
std::vector< ParameterSet > VParameterSet
T const * get() const
Returns C++ pointer to the item.
bool exists(std::string const ¶meterName) const
checks if a parameter exists
double phi() const
azimuthal angle of momentum vector
~PFRecoTauChargedHadronProducer()
key_type key() const
Accessor for product key.
edm::EDGetTokenT< reco::CandidateView > Jets_token
void setup(edm::Event &, const edm::EventSetup &)
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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::auto_ptr< ChargedHadronPredicate > predicate_
void addParameter(std::string const &name, T const &value)
bool get(ProductID const &oid, Handle< PROD > &result) const
boost::ptr_vector< Builder > builderList
bool isNonnull() const
Checks for non-null.
double deltaR(double eta1, double eta2, double phi1, double phi2)
reco::tau::PFRecoTauChargedHadronQualityPlugin Ranker
std::auto_ptr< StringCutObjectSelector< reco::PFRecoTauChargedHadron > > outputSelector_
boost::ptr_list< reco::PFRecoTauChargedHadron > ChargedHadronList
size_type size() const
Size of the RefVector.
const std::string & name() const
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)
T get(const Candidate &c)