CMS 3D CMS Logo

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 
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)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< std::vector< pat::IsolatedTrack > > tracks_
StringCutObjectSelector< pat::IsolatedTrack > cut_
HLT enums.
def move(src, dest)
Definition: eostools.py:511
std::vector< edm::EDGetTokenT< reco::CandidateView > > leptons_