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.size() == 0 ) {
34 std::vector<PFCandidatePtr> selectedPFCands;
38 selectedPFCands = chargedPFCands;
41 std::cout <<
" num. selectedPFCands = " << selectedPFCands.size() << std::endl;
45 if ( selectedPFCands.size() >= 1 ) {
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_);
130 : vertexSelector_(0),
132 jetToVertexAssociation_(0),
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 ) {
251 std::cout <<
"<RecoTauVertexAssociator::associatedVertex>:" << std::endl;
252 std::cout <<
" jet: Pt = " << jet.
pt() <<
", eta = " << jet.
eta() <<
", phi = " << jet.
phi() << std::endl;
266 jetVertex = vertexPtr->second;
275 if ( leadTrack.
isNonnull() )
std::cout <<
"leadTrack: Pt = " << leadTrack->
pt() <<
", eta = " << leadTrack->
eta() <<
", phi = " << leadTrack->
phi() << std::endl;
276 else std::cout <<
"leadTrack: N/A" << std::endl;
279 double closestDistance = 1.e+6;
280 DZtoTrack dzComputer(leadTrack);
283 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
285 double dZ = dzComputer(*selectedVertex);
287 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
288 <<
" --> dZ = " << dZ << std::endl;
290 if ( dZ < closestDistance ) {
291 jetVertex = (*selectedVertex);
292 closestDistance = dZ;
300 if ( leadTrack.
isNonnull() )
std::cout <<
"leadTrack: Pt = " << leadTrack->
pt() <<
", eta = " << leadTrack->
eta() <<
", phi = " << leadTrack->
phi() << std::endl;
301 else std::cout <<
"leadTrack: N/A" << std::endl;
304 double largestWeight = -1.;
306 TrackWeightInVertex weightComputer(leadTrack);
308 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
310 double weight = weightComputer(*selectedVertex);
312 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
313 <<
" --> weight = " << weight << std::endl;
315 if ( weight > largestWeight ) {
316 jetVertex = (*selectedVertex);
324 std::cout <<
"No vertex had positive weight! Trying dZ instead... " << std::endl;
326 double closestDistance = 1.e+6;
327 DZtoTrack dzComputer(leadTrack);
330 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
332 double dZ = dzComputer(*selectedVertex);
334 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
335 <<
" --> dZ = " << dZ << std::endl;
337 if ( dZ < closestDistance ) {
338 jetVertex = (*selectedVertex);
339 closestDistance = dZ;
351 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
unsigned long long EventNumber_t
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.
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.
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)
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_
int leadingTrkOrPFCandOption_
std::map< const reco::PFJet *, reco::VertexRef > * jetToVertexAssociation_
edm::EventNumber_t lastEvent_