-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert TrackFromPVSelector from legacy producer to global producer #17472
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,78 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Includes | ||
//////////////////////////////////////////////////////////////////////////////// | ||
#include "FWCore/Framework/interface/EDProducer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/Framework/interface/global/EDProducer.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/Utilities/interface/InputTag.h" | ||
|
||
#include "CommonTools/Utils/interface/StringCutObjectSelector.h" | ||
|
||
#include "DataFormats/TrackReco/interface/Track.h" | ||
#include "DataFormats/TrackReco/interface/TrackFwd.h" | ||
|
||
#include "DataFormats/VertexReco/interface/Vertex.h" | ||
#include "DataFormats/VertexReco/interface/VertexFwd.h" | ||
|
||
#include <algorithm> | ||
#include <memory> | ||
#include <vector> | ||
#include <sstream> | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// class definition | ||
//////////////////////////////////////////////////////////////////////////////// | ||
class TrackFromPVSelector : public edm::EDProducer | ||
{ | ||
class TrackFromPVSelector : public edm::global::EDProducer<> { | ||
public: | ||
// construction/destruction | ||
TrackFromPVSelector(const edm::ParameterSet& iConfig); | ||
virtual ~TrackFromPVSelector(); | ||
|
||
// member functions | ||
void produce(edm::Event& iEvent,const edm::EventSetup& iSetup) override; | ||
|
||
private: | ||
// member data | ||
double max_dxy_ ; | ||
double max_dz_ ; | ||
edm::EDGetTokenT< std::vector<reco::Vertex> > v_recoVertexToken_ ; | ||
edm::EDGetTokenT< std::vector<reco::Track> > v_recoTrackToken_ ; | ||
}; | ||
|
||
explicit TrackFromPVSelector(edm::ParameterSet const& iConfig); | ||
|
||
void produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const override; | ||
|
||
private: | ||
|
||
double max_dxy_; | ||
double max_dz_; | ||
edm::EDGetTokenT<std::vector<reco::Vertex>> v_recoVertexToken_; | ||
edm::EDGetTokenT<std::vector<reco::Track>> v_recoTrackToken_; | ||
}; | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// construction/destruction | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
//______________________________________________________________________________ | ||
TrackFromPVSelector::TrackFromPVSelector(const edm::ParameterSet& iConfig) | ||
: max_dxy_ ( iConfig.getParameter<double>( "max_dxy" ) ) | ||
, max_dz_ ( iConfig.getParameter<double>( "max_dz" ) ) | ||
, v_recoVertexToken_( consumes< std::vector<reco::Vertex> >( iConfig.getParameter<edm::InputTag>( "srcVertex" ) ) ) | ||
, v_recoTrackToken_ ( consumes< std::vector<reco::Track> >( iConfig.getParameter<edm::InputTag>( "srcTrack" ) ) ) | ||
TrackFromPVSelector::TrackFromPVSelector(edm::ParameterSet const& iConfig) | ||
: max_dxy_{iConfig.getParameter<double>("max_dxy")} | ||
, max_dz_{iConfig.getParameter<double>("max_dz")} | ||
, v_recoVertexToken_{consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("srcVertex"))} | ||
, v_recoTrackToken_{consumes<std::vector<reco::Track>>(iConfig.getParameter<edm::InputTag>("srcTrack"))} | ||
{ | ||
produces<std::vector<reco::Track> >(); | ||
produces<std::vector<reco::Track>>(); | ||
} | ||
|
||
|
||
//______________________________________________________________________________ | ||
TrackFromPVSelector::~TrackFromPVSelector(){} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// implementation of member functions | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
//______________________________________________________________________________ | ||
void TrackFromPVSelector::produce(edm::Event& iEvent,const edm::EventSetup& iSetup) | ||
{ | ||
std::unique_ptr<std::vector<reco::Track> > goodTracks(new std::vector<reco::Track >); | ||
|
||
edm::Handle< std::vector<reco::Vertex> > VertexHandle; | ||
iEvent.getByToken( v_recoVertexToken_, VertexHandle ); | ||
|
||
edm::Handle< std::vector<reco::Track> > TrackHandle; | ||
iEvent.getByToken( v_recoTrackToken_, TrackHandle ); | ||
|
||
if( (VertexHandle->size() == 0) || (TrackHandle->size() == 0) ) | ||
{ | ||
iEvent.put(std::move(goodTracks)); | ||
return ; | ||
} | ||
|
||
reco::Vertex PV = VertexHandle->front(); | ||
//typename std::vector<reco::Track>::const_iterator TrackIt ; | ||
std::vector<reco::Track>::const_iterator TrackIt ; | ||
|
||
for (TrackIt = TrackHandle->begin(); TrackIt != TrackHandle->end(); ++TrackIt) { | ||
if ( fabs(TrackIt->dxy(PV.position())) < max_dxy_ && | ||
fabs(TrackIt->dz(PV.position())) < max_dz_ ){ | ||
goodTracks -> push_back(*TrackIt) ; | ||
void TrackFromPVSelector::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const | ||
{ | ||
auto goodTracks = std::make_unique<std::vector<reco::Track>>(); | ||
|
||
edm::Handle<std::vector<reco::Vertex>> vertices; | ||
edm::Handle<std::vector<reco::Track>> tracks; | ||
if (iEvent.getByToken(v_recoVertexToken_, vertices) && !vertices->empty() && | ||
iEvent.getByToken(v_recoTrackToken_, tracks) && !tracks->empty()) | ||
{ | ||
auto const& vtxPos = vertices->front().position(); | ||
std::copy_if(std::cbegin(*tracks), std::cend(*tracks), std::back_inserter(*goodTracks), | ||
[this, &vtxPos](auto const& track) { | ||
return fabs(track.dxy(vtxPos)) < max_dxy_ && fabs(track.dz(vtxPos)) < max_dz_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you switch to using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. |
||
}); | ||
} | ||
} | ||
|
||
iEvent.put(std::move(goodTracks)); | ||
|
||
} | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
DEFINE_FWK_MODULE(TrackFromPVSelector); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the same logic. Previously if the data product was missing we'd throw an exception at the
VertexHandle->
orTrackHandle->
call. Now you will put in an empty container. Please remove the check on return value ofgetByToken
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack. Good catch. Yes I'll make the change.