4 #include <boost/foreach.hpp> 15 namespace reco {
namespace tau {
21 if (pfCandPtr !=
nullptr) {
22 if ( pfCandPtr->trackRef().isNonnull() )
return pfCandPtr->trackRef().get();
23 else if ( pfCandPtr->gsfTrackRef().isNonnull() )
return pfCandPtr->gsfTrackRef().get();
38 if (pfCandPtr !=
nullptr) {
39 if ( pfCandPtr->trackRef().isNonnull() )
return reco::TrackBaseRef(pfCandPtr->trackRef());
40 else if ( pfCandPtr->gsfTrackRef().isNonnull() )
return reco::TrackBaseRef(pfCandPtr->gsfTrackRef());
52 std::vector<CandidatePtr> chargedPFCands =
pfChargedCands(jet,
true);
54 std::cout <<
"<RecoTauVertexAssociator::getLeadTrack>:" << std::endl;
55 std::cout <<
" jet: Pt = " << jet.
pt() <<
", eta = " << jet.
eta() <<
", phi = " << jet.
phi() << std::endl;
56 std::cout <<
" num. chargedPFCands = " << chargedPFCands.size() << std::endl;
60 if ( chargedPFCands.empty() ) {
64 std::vector<CandidatePtr> selectedPFCands;
68 selectedPFCands = chargedPFCands;
71 std::cout <<
" num. selectedPFCands = " << selectedPFCands.size() << std::endl;
75 if ( !selectedPFCands.empty() ) {
79 for ( std::vector<CandidatePtr>::const_iterator pfCand = selectedPFCands.begin();
80 pfCand != selectedPFCands.end(); ++pfCand ) {
82 double actualTrackPt = 0. , actualTrackPtError = 0.;
83 if ( track !=
nullptr ) {
84 actualTrackPt = track->
pt();
85 actualTrackPtError = track->
ptError();
89 trackPt = actualTrackPt - 2.*actualTrackPtError;
91 trackPt = (*pfCand)->pt();
93 trackPt =
std::min(actualTrackPt, (
double)(*pfCand)->pt());
95 if ( trackPt > leadTrackPt ) {
102 if ( leadCand.
isNull() ) {
104 leadCand = chargedPFCands[0];
110 std::cout <<
"leadCand: Pt = " << leadCand->pt() <<
", eta = " << leadCand->eta() <<
", phi = " << leadCand->phi() << std::endl;
117 if(
leadCand.isNull())
return nullptr;
133 if ( !trk || !vtx ) {
141 if ( !trk || !vtx ) {
144 return vtx->trackWeight(trk);
159 if ( !pset.
exists(
"primaryVertexSrc") || !pset.
exists(
"pvFindingAlgo") ) {
161 <<
"The PSet passed to the RecoTauVertexAssociator was incorrectly configured." 162 <<
" The vertex will be taken as the highest Pt vertex from the 'offlinePrimaryVertices' collection." 169 if ( pset.
exists(
"vxAssocQualityCuts") ) {
179 if ( !pset.
exists(
"vertexTrackFiltering") && pset.
exists(
"vxAssocQualityCuts") ) {
181 <<
"The PSet passed to the RecoTauVertexAssociator was incorrectly configured." 182 <<
" Please define vertexTrackFiltering in config file." 183 <<
" No filtering of tracks to vertices will be applied." 187 pset.
getParameter<
bool>(
"vertexTrackFiltering") :
false;
189 if ( pset.
exists(
"vertexSelection") ) {
191 if ( !vertexSelection.empty() ) {
198 }
else if (
algorithm_ ==
"closestInDeltaZ" ) {
200 }
else if (
algorithm_ ==
"highestWeightForLeadTrack" ) {
206 <<
"Invalid Configuration parameter 'algorithm' " <<
algorithm_ <<
"." 207 <<
" Valid options are: 'highestPtInEvent', 'closestInDeltaZ', 'highestWeightForLeadTrack' and 'combined'.\n";
221 <<
"Invalid Configuration parameter 'leadingTrkOrPFCandOption' " << leadingTrkOrPFCandOption_string <<
"." 222 <<
" Valid options are: 'leadTrack', 'leadPFCand', 'firstTrack'.\n";
241 for (
size_t idxVertex = 0; idxVertex < vertices->size(); ++idxVertex ) {
263 if (track !=
nullptr)
284 double closestDistance = 1.e+6;
287 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
289 double dZ = dzToTrack(*selectedVertex, track);
291 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
292 <<
" --> dZ = " << dZ << std::endl;
294 if ( dZ < closestDistance ) {
295 trkVertex = (*selectedVertex);
296 closestDistance = dZ;
304 std::cout <<
"--> returning vertex: x = " << trkVertex->position().x() <<
", y = " << trkVertex->position().y() <<
", z = " << trkVertex->position().z() << std::endl;
319 double largestWeight = -1.;
322 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
324 double weight = trackWeightInVertex(*selectedVertex, track);
326 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
327 <<
" --> weight = " << weight << std::endl;
329 if ( weight > largestWeight ) {
330 trkVertex = (*selectedVertex);
338 std::cout <<
"No vertex had positive weight! Trying dZ instead... " << std::endl;
340 double closestDistance = 1.e+6;
343 for ( std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
345 double dZ = dzToTrack(*selectedVertex, track.
get());
347 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x() <<
", y = " << (*selectedVertex)->position().y() <<
", z = " << (*selectedVertex)->position().z()
348 <<
" --> dZ = " << dZ << std::endl;
350 if ( dZ < closestDistance ) {
351 trkVertex = (*selectedVertex);
352 closestDistance = dZ;
361 std::cout <<
"--> returning vertex: x = " << trkVertex->position().x() <<
", y = " << trkVertex->position().y() <<
", z = " << trkVertex->position().z() << std::endl;
371 std::cout <<
"<RecoTauVertexAssociator::associatedVertex>:" << std::endl;
372 std::cout <<
" jet: Pt = " << jet.
pt() <<
", eta = " << jet.
eta() <<
", phi = " << jet.
phi() << std::endl;
386 jetVertex = vertexPtr->second;
395 if ( leadTrack !=
nullptr )
std::cout <<
"leadTrack: Pt = " << leadTrack->
pt() <<
", eta = " << leadTrack->
eta() <<
", phi = " << leadTrack->
phi() << std::endl;
396 else std::cout <<
"leadTrack: N/A" << std::endl;
398 if ( leadTrack !=
nullptr ) {
406 if ( leadTrack.
isNonnull() )
std::cout <<
"leadTrack: Pt = " << leadTrack->
pt() <<
", eta = " << leadTrack->
eta() <<
", phi = " << leadTrack->
phi() << std::endl;
407 else std::cout <<
"leadTrack: N/A" << std::endl;
418 std::cout <<
"--> returning vertex: x = " << jetVertex->position().x() <<
", y = " << jetVertex->position().y() <<
", z = " << jetVertex->position().z() << std::endl;
value_type const * get() const
T getParameter(std::string const &) const
EventNumber_t event() const
const TrackBaseRef getLeadTrackRef(const Jet &) const
double eta() const final
momentum pseudorapidity
Coll filterCandRefs(const Coll &refcoll, bool invert=false) const
Filter a ref vector of Candidates.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const Track * getLeadTrack(const 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.
std::vector< CandidatePtr > pfChargedCands(const Jet &jet, bool sort=true)
Extract all non-neutral candidates from a PFJet.
InputIterator leadCand(InputIterator begin, InputIterator end)
virtual ~RecoTauVertexAssociator()
std::vector< reco::VertexRef > selectedVertices_
const CandidatePtr getLeadCand(const Jet &) const
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.
const CandidatePtr & leadChargedHadrCand() const
double pt() const
track transverse momentum
const JetBaseRef & jetRef() const
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)
virtual const reco::Track & pseudoTrack() const
StringCutObjectSelector< reco::Vertex > * vertexSelector_
bool isNonnull() const
Checks for non-null.
RecoTauVertexAssociator(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
std::map< const reco::Jet *, reco::VertexRef > * jetToVertexAssociation_
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
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
ParameterSet const & getParameterSet(std::string const &) const
edm::EDGetTokenT< reco::VertexCollection > vxToken_
bool isNull() const
Checks for null.
reco::VertexRef associatedVertex(const Jet &jet) const
double phi() const final
momentum azimuthal angle
int leadingTrkOrPFCandOption_
edm::EventNumber_t lastEvent_