20 const PFCandidate* pfCandPtr =
dynamic_cast<const PFCandidate*
>(&cand);
21 if (pfCandPtr !=
nullptr) {
22 if (pfCandPtr->trackRef().isNonnull())
23 return pfCandPtr->trackRef().get();
24 else if (pfCandPtr->gsfTrackRef().isNonnull())
25 return pfCandPtr->gsfTrackRef().get();
39 const PFCandidate* pfCandPtr =
dynamic_cast<const PFCandidate*
>(&cand);
40 if (pfCandPtr !=
nullptr) {
41 if (pfCandPtr->trackRef().isNonnull())
43 else if (pfCandPtr->gsfTrackRef().isNonnull())
56 std::vector<CandidatePtr> chargedPFCands =
pfChargedCands(jet,
true);
58 std::cout <<
"<RecoTauVertexAssociator::getLeadTrack>:" << std::endl;
59 std::cout <<
" jet: Pt = " << jet.
pt() <<
", eta = " << jet.
eta() <<
", phi = " << jet.
phi() << std::endl;
60 std::cout <<
" num. chargedPFCands = " << chargedPFCands.size() << std::endl;
64 if (chargedPFCands.empty()) {
68 std::vector<CandidatePtr> selectedPFCands;
72 selectedPFCands = chargedPFCands;
75 std::cout <<
" num. selectedPFCands = " << selectedPFCands.size() << std::endl;
79 if (!selectedPFCands.empty()) {
80 double leadTrackPt = 0.;
82 leadCand = selectedPFCands[0];
84 for (std::vector<CandidatePtr>::const_iterator pfCand = selectedPFCands.begin();
85 pfCand != selectedPFCands.end();
88 double actualTrackPt = 0., actualTrackPtError = 0.;
89 if (track !=
nullptr) {
90 actualTrackPt = track->
pt();
91 actualTrackPtError = track->
ptError();
95 trackPt = actualTrackPt - 2. * actualTrackPtError;
97 trackPt = (*pfCand)->pt();
99 trackPt =
std::min(actualTrackPt, (
double)(*pfCand)->pt());
102 if (trackPt > leadTrackPt) {
103 leadCand = (*pfCand);
111 leadCand = chargedPFCands[0];
117 std::cout <<
"leadCand: Pt = " << leadCand->pt() <<
", eta = " << leadCand->eta()
118 <<
", phi = " << leadCand->phi() << std::endl;
152 return vtx->trackWeight(trk);
157 : vertexSelector_(nullptr), qcuts_(nullptr), jetToVertexAssociation_(nullptr), lastEvent_(0) {
163 if (!pset.
exists(
"primaryVertexSrc") || !pset.
exists(
"pvFindingAlgo")) {
165 <<
"The PSet passed to the RecoTauVertexAssociator was incorrectly configured."
166 <<
" The vertex will be taken as the highest Pt vertex from the 'offlinePrimaryVertices' collection."
173 if (pset.
exists(
"vxAssocQualityCuts")) {
183 if (!pset.
exists(
"vertexTrackFiltering") && pset.
exists(
"vxAssocQualityCuts")) {
185 <<
"The PSet passed to the RecoTauVertexAssociator was incorrectly configured."
186 <<
" Please define vertexTrackFiltering in config file."
187 <<
" No filtering of tracks to vertices will be applied." << std::endl;
191 if (pset.
exists(
"vertexSelection")) {
193 if (!vertexSelection.empty()) {
202 }
else if (
algorithm_ ==
"highestWeightForLeadTrack") {
208 <<
"Invalid Configuration parameter 'algorithm' " <<
algorithm_ <<
"."
209 <<
" Valid options are: 'highestPtInEvent', 'closestInDeltaZ', 'highestWeightForLeadTrack' and "
217 std::string leadingTrkOrPFCandOption_string = pset.
exists(
"leadingTrkOrPFCandOption")
220 if (leadingTrkOrPFCandOption_string ==
"leadTrack")
222 else if (leadingTrkOrPFCandOption_string ==
"leadPFCand")
224 else if (leadingTrkOrPFCandOption_string ==
"minLeadTrackOrPFCand")
226 else if (leadingTrkOrPFCandOption_string ==
"firstTrack")
230 <<
"Invalid Configuration parameter 'leadingTrkOrPFCandOption' " << leadingTrkOrPFCandOption_string <<
"."
231 <<
" Valid options are: 'leadTrack', 'leadPFCand', 'firstTrack'.\n";
247 for (
size_t idxVertex = 0; idxVertex < vertices->size(); ++idxVertex) {
270 if (track !=
nullptr)
291 double closestDistance = 1.e+6;
294 for (std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
297 double dZ = dzToTrack(*selectedVertex, track);
299 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x()
300 <<
", y = " << (*selectedVertex)->position().y()
301 <<
", z = " << (*selectedVertex)->position().z() <<
" --> dZ = " << dZ << std::endl;
303 if (dZ < closestDistance) {
304 trkVertex = (*selectedVertex);
305 closestDistance = dZ;
313 std::cout <<
"--> returning vertex: x = " << trkVertex->position().x() <<
", y = " << trkVertex->position().y()
314 <<
", z = " << trkVertex->position().z() << std::endl;
325 double largestWeight = -1.;
328 for (std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
331 double weight = trackWeightInVertex(*selectedVertex, track);
333 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x()
334 <<
", y = " << (*selectedVertex)->position().y()
335 <<
", z = " << (*selectedVertex)->position().z() <<
" --> weight = " << weight << std::endl;
337 if (weight > largestWeight) {
338 trkVertex = (*selectedVertex);
346 std::cout <<
"No vertex had positive weight! Trying dZ instead... " << std::endl;
348 double closestDistance = 1.e+6;
351 for (std::vector<reco::VertexRef>::const_iterator selectedVertex =
selectedVertices_.begin();
354 double dZ = dzToTrack(*selectedVertex, track.
get());
356 std::cout <<
"vertex #" << idxVertex <<
": x = " << (*selectedVertex)->position().x()
357 <<
", y = " << (*selectedVertex)->position().y()
358 <<
", z = " << (*selectedVertex)->position().z() <<
" --> dZ = " << dZ << std::endl;
360 if (dZ < closestDistance) {
361 trkVertex = (*selectedVertex);
362 closestDistance = dZ;
371 std::cout <<
"--> returning vertex: x = " << trkVertex->position().x() <<
", y = " << trkVertex->position().y()
372 <<
", z = " << trkVertex->position().z() << std::endl;
380 std::cout <<
"<RecoTauVertexAssociator::associatedVertex>:" << std::endl;
381 std::cout <<
" jet: Pt = " << jet.
pt() <<
", eta = " << jet.
eta() <<
", phi = " << jet.
phi() << std::endl;
395 jetVertex = vertexPtr->second;
405 if (leadTrack !=
nullptr)
406 std::cout <<
"leadTrack: Pt = " << leadTrack->
pt() <<
", eta = " << leadTrack->
eta()
407 <<
", phi = " << leadTrack->
phi() << std::endl;
409 std::cout <<
"leadTrack: N/A" << std::endl;
411 if (leadTrack !=
nullptr) {
419 std::cout <<
"leadTrack: Pt = " << leadTrack->
pt() <<
", eta = " << leadTrack->
eta()
420 <<
", phi = " << leadTrack->
phi() << std::endl;
422 std::cout <<
"leadTrack: N/A" << std::endl;
433 std::cout <<
"--> returning vertex: x = " << jetVertex->position().x() <<
", y = " << jetVertex->position().y()
434 <<
", z = " << jetVertex->position().z() << std::endl;
value_type const * get() const
EventNumber_t event() const
const TrackBaseRef getLeadTrackRef(const Jet &) const
double pt() const final
transverse momentum
Coll filterCandRefs(const Coll &refcoll, bool invert=false) const
Filter a ref vector of Candidates.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Base class for all types of Jets.
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
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
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.
T getParameter(std::string const &) const
reco::VertexRef associatedVertex(const Jet &jet) const
Log< level::Warning, false > LogWarning
double phi() const final
momentum azimuthal angle
void setPV(const reco::VertexRef &vtx)
Update the primary vertex.
int leadingTrkOrPFCandOption_
edm::EventNumber_t lastEvent_
double eta() const final
momentum pseudorapidity