4 #include <boost/foreach.hpp>
14 namespace reco {
namespace tau {
20 std::vector<PFCandidatePtr> chargedPFCands =
pfChargedCands(jet,
true);
22 std::cout <<
"<RecoTauVertexAssociator::getLeadTrack>:" << std::endl;
23 std::cout <<
" jet: Pt = " << jet.
pt() <<
", eta = " << jet.
eta() <<
", phi = " << jet.
phi() << std::endl;
24 std::cout <<
" num. chargedPFCands = " << chargedPFCands.size() << std::endl;
28 if ( chargedPFCands.size() == 0 ) {
32 std::vector<PFCandidatePtr> selectedPFCands;
36 selectedPFCands = chargedPFCands;
39 std::cout <<
" num. selectedPFCands = " << selectedPFCands.size() << std::endl;
43 if ( selectedPFCands.size() >= 1 ) {
44 double leadTrackPt = 0.;
48 for ( std::vector<PFCandidatePtr>::const_iterator pfCand = selectedPFCands.begin();
49 pfCand != selectedPFCands.end(); ++pfCand ) {
51 if ( (*pfCand)->trackRef().isNonnull() ) track = (*pfCand)->trackRef().get();
52 else if ( (*pfCand)->gsfTrackRef().isNonnull() ) track = (*pfCand)->gsfTrackRef().get();
53 if ( !track )
continue;
57 trackPt = track->
pt() - 2.*track->
ptError();
59 trackPt = (*pfCand)->pt();
61 if ( trackPt > leadTrackPt ) {
62 leadPFCand = (*pfCand);
68 if ( leadPFCand.
isNull() ) {
70 leadPFCand = chargedPFCands[0];
76 std::cout <<
"leadPFCand: Pt = " << leadPFCand->pt() <<
", eta = " << leadPFCand->eta() <<
", phi = " << leadPFCand->phi() << std::endl;
79 if ( leadPFCand->trackRef().
isNonnull() ) {
81 }
else if ( leadPFCand->gsfTrackRef().
isNonnull() ) {
90 class DZtoTrack :
public std::unary_function<double, reco::VertexRef>
98 if ( !
trk_ || !vtx ) {
107 class TrackWeightInVertex :
public std::unary_function<double, reco::VertexRef>
115 if ( !
trk_ || !vtx ) {
118 return vtx->trackWeight(
trk_);
126 : vertexSelector_(0),
128 jetToVertexAssociation_(0),
136 if ( !pset.
exists(
"primaryVertexSrc") || !pset.
exists(
"pvFindingAlgo") ) {
138 <<
"The PSet passed to the RecoTauVertexAssociator was incorrectly configured."
139 <<
" The vertex will be taken as the highest Pt vertex from the 'offlinePrimaryVertices' collection."
146 if ( pset.
exists(
"vxAssocQualityCuts") ) {
156 if ( !pset.
exists(
"vertexTrackFiltering") && pset.
exists(
"vxAssocQualityCuts") ) {
158 <<
"The PSet passed to the RecoTauVertexAssociator was incorrectly configured."
159 <<
" Please define vertexTrackFiltering in config file."
160 <<
" No filtering of tracks to vertices will be applied."
164 pset.
getParameter<
bool>(
"vertexTrackFiltering") :
false;
166 if ( pset.
exists(
"vertexSelection") ) {
168 if ( vertexSelection !=
"" ) {
175 }
else if (
algorithm_ ==
"closestInDeltaZ" ) {
177 }
else if (
algorithm_ ==
"highestWeightForLeadTrack" ) {
183 <<
"Invalid Configuration parameter 'algorithm' " <<
algorithm_ <<
"."
184 <<
" Valid options are: 'highestPtInEvent', 'closestInDeltaZ', 'highestWeightForLeadTrack' and 'combined'.\n";
197 <<
"Invalid Configuration parameter 'leadingTrkOrPFCandOption' " << leadingTrkOrPFCandOption_string <<
"."
198 <<
" Valid options are: 'leadTrack', 'leadPFCand', 'firstTrack'.\n";
217 for (
size_t idxVertex = 0; idxVertex < vertices->size(); ++idxVertex ) {
225 int currentEvent = evt.
id().
event();
246 std::cout <<
"<RecoTauVertexAssociator::associatedVertex>:" << std::endl;
247 std::cout <<
" jet: Pt = " << jet.
pt() <<
", eta = " << jet.
eta() <<
", phi = " << jet.
phi() << std::endl;
261 jetVertex = vertexPtr->second;
270 if ( leadTrack.
isNonnull() )
std::cout <<
"leadTrack: Pt = " << leadTrack->
pt() <<
", eta = " << leadTrack->
eta() <<
", phi = " << leadTrack->
phi() << std::endl;
271 else std::cout <<
"leadTrack: N/A" << std::endl;
274 double closestDistance = 1.e+6;
275 DZtoTrack dzComputer(leadTrack);
278 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
280 double dZ = dzComputer(*selectedVertex);
282 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
283 <<
" --> dZ = " << dZ << std::endl;
285 if ( dZ < closestDistance ) {
286 jetVertex = (*selectedVertex);
287 closestDistance = dZ;
295 if ( leadTrack.
isNonnull() )
std::cout <<
"leadTrack: Pt = " << leadTrack->
pt() <<
", eta = " << leadTrack->
eta() <<
", phi = " << leadTrack->
phi() << std::endl;
296 else std::cout <<
"leadTrack: N/A" << std::endl;
299 double largestWeight = -1.;
301 TrackWeightInVertex weightComputer(leadTrack);
303 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
305 double weight = weightComputer(*selectedVertex);
307 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
308 <<
" --> weight = " << weight << std::endl;
310 if ( weight > largestWeight ) {
311 jetVertex = (*selectedVertex);
319 std::cout <<
"No vertex had positive weight! Trying dZ instead... " << std::endl;
321 double closestDistance = 1.e+6;
322 DZtoTrack dzComputer(leadTrack);
325 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
327 double dZ = dzComputer(*selectedVertex);
329 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
330 <<
" --> dZ = " << dZ << std::endl;
332 if ( dZ < closestDistance ) {
333 jetVertex = (*selectedVertex);
334 closestDistance = dZ;
346 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
virtual float pt() const
transverse momentum
Coll filterCandRefs(const Coll &refcoll, bool invert=false) const
Filter a ref vector of PFCandidates.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual float phi() const
momentum azimuthal angle
reco::VertexRef associatedVertex(const PFJet &jet) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
double phi() const
azimuthal angle of momentum vector
std::vector< Vertex > VertexCollection
collection of Vertex objects
void setEvent(const edm::Event &evt)
Load the vertices from the event.
reco::TrackBaseRef getLeadTrack(const PFJet &jet) const
Jets made from PFObjects.
virtual ~RecoTauVertexAssociator()
std::vector< reco::VertexRef > selectedVertices_
bool isNonnull() const
Checks for non-null.
bool isNull() const
Checks for null.
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.
virtual float eta() const
momentum pseudorapidity
double pt() const
track transverse momentum
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Abs< T >::type abs(const T &t)
InputIterator leadPFCand(InputIterator begin, InputIterator end)
StringCutObjectSelector< reco::Vertex > * vertexSelector_
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_
bool isNull() const
Checks for null.
std::vector< PFCandidatePtr > pfChargedCands(const PFJet &jet, bool sort=true)
Extract all non-neutral candidates from a PFJet.
const reco::TrackBaseRef trk_
bool isNonnull() const
Checks for non-null.
int leadingTrkOrPFCandOption_
std::map< const reco::PFJet *, reco::VertexRef > * jetToVertexAssociation_