CMS 3D CMS Logo

TrackSelectorByRegion.cc
Go to the documentation of this file.
3 
8 
13 
14 #include <vector>
15 #include <memory>
16 
18 public:
20  : produceCollection_(conf.getParameter<bool>("produceTrackCollection")),
21  produceMask_(conf.getParameter<bool>("produceMask")),
22  tracksToken_(consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("tracks"))),
23  inputTrkRegionToken_(consumes<edm::OwnVector<TrackingRegion>>(conf.getParameter<edm::InputTag>("regions"))),
25  : edm::EDPutTokenT<reco::TrackCollection>{}),
26  outputMaskToken_(produceMask_ ? produces<std::vector<bool>>() : edm::EDPutTokenT<std::vector<bool>>{}) {}
27 
28  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
30  desc.add<edm::InputTag>("tracks", edm::InputTag("hltPixelTracks"));
31  desc.add<edm::InputTag>("regions", edm::InputTag(""));
32  desc.add<bool>("produceTrackCollection", true);
33  desc.add<bool>("produceMask", true);
34  descriptions.add("trackSelectorByRegion", desc);
35  }
36 
37 private:
38  using MaskCollection = std::vector<bool>;
39 
40  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const override {
41  if (not produceCollection_ and not produceMask_)
42  return;
43 
44  auto const& regions = iEvent.get(inputTrkRegionToken_);
45  auto const& tracks = iEvent.get(tracksToken_);
46  MaskCollection mask(tracks.size(), false); // output mask
47 
48  for (auto const& region : regions) {
49  region.checkTracks(tracks, mask);
50  }
51 
52  if (produceCollection_) {
53  reco::TrackCollection output_tracks; // output collection with a (shallow) copy of the selected tracks
54  size_t size = 0;
55  // count the number of selected tracks
56  for (size_t i = 0; i < mask.size(); i++) {
57  size += mask[i];
58  }
59  output_tracks.reserve(size);
60  for (size_t i = 0; i < mask.size(); i++) {
61  if (mask[i])
62  output_tracks.push_back(tracks[i]);
63  }
64  iEvent.emplace(outputTracksToken_, std::move(output_tracks));
65  }
66  if (produceMask_) {
68  }
69  }
70 
71  const bool produceCollection_;
72  const bool produceMask_;
77 };
78 
size
Write out results.
const edm::EDPutTokenT< std::vector< bool > > outputMaskToken_
TrackSelectorByRegion(const edm::ParameterSet &conf)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const edm::EDPutTokenT< reco::TrackCollection > outputTracksToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< edm::OwnVector< TrackingRegion > > inputTrkRegionToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &) const override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< reco::TrackCollection > tracksToken_
fixed size matrix
HLT enums.
std::vector< bool > MaskCollection
def move(src, dest)
Definition: eostools.py:511
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)