CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IsolatedTrackCleaner.cc
Go to the documentation of this file.
9 
10 #include <vector>
11 
13 public:
15  : tracks_(consumes<std::vector<pat::IsolatedTrack>>(params.getParameter<edm::InputTag>("tracks"))),
16  cut_(params.getParameter<std::string>("cut")) {
17  for (const edm::InputTag& tag : params.getParameter<std::vector<edm::InputTag>>("finalLeptons")) {
18  leptons_.push_back(consumes<reco::CandidateView>(tag));
19  }
20  produces<std::vector<pat::IsolatedTrack>>();
21  }
22 
23  ~IsolatedTrackCleaner() override {}
24 
25  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override {
26  auto out = std::make_unique<std::vector<pat::IsolatedTrack>>();
27 
28  std::vector<reco::CandidatePtr> leptonPfCands;
30  for (const auto& token : leptons_) {
31  iEvent.getByToken(token, leptons);
32  for (const auto& lep : *leptons) {
33  for (unsigned int i = 0, n = lep.numberOfSourceCandidatePtrs(); i < n; ++i) {
34  auto ptr = lep.sourceCandidatePtr(i);
35  if (ptr.isNonnull())
36  leptonPfCands.push_back(ptr);
37  }
38  }
39  }
40  std::sort(leptonPfCands.begin(), leptonPfCands.end());
41 
43  iEvent.getByToken(tracks_, tracks);
44  for (const auto& track : *tracks) {
45  if (!cut_(track))
46  continue;
47  if (track.packedCandRef().isNonnull()) {
48  reco::CandidatePtr pfCand(edm::refToPtr(track.packedCandRef()));
49  if (std::binary_search(leptonPfCands.begin(), leptonPfCands.end(), pfCand)) {
50  continue;
51  }
52  }
53  out->push_back(track);
54  }
55 
56  iEvent.put(std::move(out));
57  }
58 
59 protected:
62  std::vector<edm::EDGetTokenT<reco::CandidateView>> leptons_;
63 };
64 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
IsolatedTrackCleaner(edm::ParameterSet const &params)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
auto const & tracks
cannot be loose
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
edm::EDGetTokenT< std::vector< pat::IsolatedTrack > > tracks_
StringCutObjectSelector< pat::IsolatedTrack > cut_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< edm::EDGetTokenT< reco::CandidateView > > leptons_