CMS 3D CMS Logo

IsolatedTrackCleaner.cc
Go to the documentation of this file.
9 
10 #include <vector>
11 
12 
14  public:
16  tracks_(consumes<std::vector<pat::IsolatedTrack>>(params.getParameter<edm::InputTag>("tracks"))),
17  cut_(params.getParameter<std::string>("cut"))
18  {
19  for (const edm::InputTag & tag : params.getParameter<std::vector<edm::InputTag>>("finalLeptons")) {
20  leptons_.push_back(consumes<reco::CandidateView>(tag));
21  }
22  produces<std::vector<pat::IsolatedTrack>>();
23  }
24 
25  ~IsolatedTrackCleaner() override {}
26 
27  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override {
28  auto out = std::make_unique<std::vector<pat::IsolatedTrack>>();
29 
30  std::vector<reco::CandidatePtr> leptonPfCands;
32  for (const auto & token : leptons_) {
33  iEvent.getByToken(token, leptons);
34  for (const auto & lep : *leptons) {
35  for (unsigned int i = 0, n = lep.numberOfSourceCandidatePtrs(); i < n; ++i) {
36  auto ptr = lep.sourceCandidatePtr(i);
37  if (ptr.isNonnull()) leptonPfCands.push_back(ptr);
38  }
39  }
40  }
41  std::sort(leptonPfCands.begin(), leptonPfCands.end());
42 
44  iEvent.getByToken(tracks_, tracks);
45  for (const auto & track : *tracks) {
46  if (!cut_(track)) 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 
67 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
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:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< std::vector< pat::IsolatedTrack > > tracks_
StringCutObjectSelector< pat::IsolatedTrack > cut_
HLT enums.
def move(src, dest)
Definition: eostools.py:510
std::vector< edm::EDGetTokenT< reco::CandidateView > > leptons_