4 #include <boost/foreach.hpp> 16 namespace reco {
namespace tau {
22 std::vector<PFCandidatePtr> chargedPFCands =
pfChargedCands(jet,
true);
24 std::cout <<
"<RecoTauVertexAssociator::getLeadTrack>:" << std::endl;
25 std::cout <<
" jet: Pt = " << jet.
pt() <<
", eta = " << jet.
eta() <<
", phi = " << jet.
phi() << std::endl;
26 std::cout <<
" num. chargedPFCands = " << chargedPFCands.size() << std::endl;
30 if ( chargedPFCands.empty() ) {
34 std::vector<PFCandidatePtr> selectedPFCands;
38 selectedPFCands = chargedPFCands;
41 std::cout <<
" num. selectedPFCands = " << selectedPFCands.size() << std::endl;
45 if ( !selectedPFCands.empty() ) {
46 double leadTrackPt = 0.;
50 for ( std::vector<PFCandidatePtr>::const_iterator pfCand = selectedPFCands.begin();
51 pfCand != selectedPFCands.end(); ++pfCand ) {
53 if ( (*pfCand)->trackRef().isNonnull() ) track = (*pfCand)->trackRef().get();
54 else if ( (*pfCand)->gsfTrackRef().isNonnull() ) track = (*pfCand)->gsfTrackRef().get();
55 if ( !track )
continue;
59 trackPt = track->
pt() - 2.*track->
ptError();
61 trackPt = (*pfCand)->pt();
63 trackPt =
TMath::Min(track->
pt(), (double)(*pfCand)->pt());
65 if ( trackPt > leadTrackPt ) {
66 leadPFCand = (*pfCand);
72 if ( leadPFCand.
isNull() ) {
74 leadPFCand = chargedPFCands[0];
80 std::cout <<
"leadPFCand: Pt = " << leadPFCand->pt() <<
", eta = " << leadPFCand->eta() <<
", phi = " << leadPFCand->phi() << std::endl;
83 if ( leadPFCand->trackRef().
isNonnull() ) {
85 }
else if ( leadPFCand->gsfTrackRef().
isNonnull() ) {
94 class DZtoTrack :
public std::unary_function<double, reco::VertexRef>
102 if ( !
trk_ || !vtx ) {
111 class TrackWeightInVertex :
public std::unary_function<double, reco::VertexRef>
119 if ( !
trk_ || !vtx ) {
122 return vtx->trackWeight(
trk_);
140 if ( !pset.
exists(
"primaryVertexSrc") || !pset.
exists(
"pvFindingAlgo") ) {
142 <<
"The PSet passed to the RecoTauVertexAssociator was incorrectly configured." 143 <<
" The vertex will be taken as the highest Pt vertex from the 'offlinePrimaryVertices' collection." 150 if ( pset.
exists(
"vxAssocQualityCuts") ) {
160 if ( !pset.
exists(
"vertexTrackFiltering") && pset.
exists(
"vxAssocQualityCuts") ) {
162 <<
"The PSet passed to the RecoTauVertexAssociator was incorrectly configured." 163 <<
" Please define vertexTrackFiltering in config file." 164 <<
" No filtering of tracks to vertices will be applied." 168 pset.
getParameter<
bool>(
"vertexTrackFiltering") :
false;
170 if ( pset.
exists(
"vertexSelection") ) {
172 if ( vertexSelection !=
"" ) {
179 }
else if (
algorithm_ ==
"closestInDeltaZ" ) {
181 }
else if (
algorithm_ ==
"highestWeightForLeadTrack" ) {
187 <<
"Invalid Configuration parameter 'algorithm' " <<
algorithm_ <<
"." 188 <<
" Valid options are: 'highestPtInEvent', 'closestInDeltaZ', 'highestWeightForLeadTrack' and 'combined'.\n";
202 <<
"Invalid Configuration parameter 'leadingTrkOrPFCandOption' " << leadingTrkOrPFCandOption_string <<
"." 203 <<
" Valid options are: 'leadTrack', 'leadPFCand', 'firstTrack'.\n";
222 for (
size_t idxVertex = 0; idxVertex < vertices->size(); ++idxVertex ) {
267 double closestDistance = 1.e+6;
268 DZtoTrack dzComputer(track);
271 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
273 double dZ = dzComputer(*selectedVertex);
275 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
276 <<
" --> dZ = " << dZ << std::endl;
278 if ( dZ < closestDistance ) {
279 trkVertex = (*selectedVertex);
280 closestDistance = dZ;
287 double largestWeight = -1.;
289 TrackWeightInVertex weightComputer(track);
291 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
293 double weight = weightComputer(*selectedVertex);
295 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
296 <<
" --> weight = " << weight << std::endl;
298 if ( weight > largestWeight ) {
299 trkVertex = (*selectedVertex);
307 std::cout <<
"No vertex had positive weight! Trying dZ instead... " << std::endl;
309 double closestDistance = 1.e+6;
310 DZtoTrack dzComputer(track);
313 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
315 double dZ = dzComputer(*selectedVertex);
317 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
318 <<
" --> dZ = " << dZ << std::endl;
320 if ( dZ < closestDistance ) {
321 trkVertex = (*selectedVertex);
322 closestDistance = dZ;
331 std::cout <<
"--> returning vertex: x = " << trkVertex->position().x() <<
", y = " << trkVertex->position().y() <<
", z = " << trkVertex->position().z() << std::endl;
341 std::cout <<
"<RecoTauVertexAssociator::associatedVertex>:" << std::endl;
342 std::cout <<
" jet: Pt = " << jet.
pt() <<
", eta = " << jet.
eta() <<
", phi = " << jet.
phi() << std::endl;
356 jetVertex = vertexPtr->second;
367 if ( leadTrack.
isNonnull() )
std::cout <<
"leadTrack: Pt = " << leadTrack->
pt() <<
", eta = " << leadTrack->
eta() <<
", phi = " << leadTrack->
phi() << std::endl;
368 else std::cout <<
"leadTrack: N/A" << std::endl;
379 std::cout <<
"--> returning vertex: x = " << jetVertex->position().x() <<
", y = " << jetVertex->position().y() <<
", z = " << jetVertex->position().z() << std::endl;
T getParameter(std::string const &) const
EventNumber_t event() const
const PFJetRef & jetRef() const
double eta() const final
momentum pseudorapidity
const PFCandidatePtr & leadPFChargedHadrCand() const
Coll filterCandRefs(const Coll &refcoll, bool invert=false) const
Filter a ref vector of PFCandidates.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
reco::VertexRef associatedVertex(const PFJet &jet) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
unsigned long long EventNumber_t
double phi() const
azimuthal angle of momentum vector
double pt() const final
transverse momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
void setEvent(const edm::Event &evt)
Load the vertices from the event.
bool isNonnull() const
Checks for non-null.
reco::TrackBaseRef getLeadTrack(const PFJet &jet) const
Jets made from PFObjects.
virtual ~RecoTauVertexAssociator()
std::vector< reco::VertexRef > selectedVertices_
double eta() const
pseudorapidity of momentum vector
RecoTauQualityCuts * qcuts_
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
void setPV(const reco::VertexRef &vtx) const
Update the primary vertex.
double pt() const
track transverse momentum
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
bool isNull() const
Checks for null.
Abs< T >::type abs(const T &t)
bool isNull() const
Checks for null.
InputIterator leadPFCand(InputIterator begin, InputIterator end)
StringCutObjectSelector< reco::Vertex > * vertexSelector_
bool isNonnull() const
Checks for non-null.
RecoTauVertexAssociator(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
const PFTauTagInfoRef & pfTauTagInfoRef() const
ParameterSet const & getParameterSet(std::string const &) const
edm::EDGetTokenT< reco::VertexCollection > vxToken_
std::vector< PFCandidatePtr > pfChargedCands(const PFJet &jet, bool sort=true)
Extract all non-neutral candidates from a PFJet.
const reco::TrackBaseRef trk_
double phi() const final
momentum azimuthal angle
int leadingTrkOrPFCandOption_
std::map< const reco::PFJet *, reco::VertexRef > * jetToVertexAssociation_
edm::EventNumber_t lastEvent_