CMS 3D CMS Logo

TrackSelectorByRegion.cc
Go to the documentation of this file.
3 
8 
12 
13 #include <vector>
14 #include <memory>
15 
17 public:
19  : produceCollection_(conf.getParameter<bool>("produceTrackCollection")),
20  produceMask_(conf.getParameter<bool>("produceMask")),
21  tracksToken_(consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("tracks"))),
22  inputTrkRegionToken_(consumes(conf.getParameter<edm::InputTag>("regions"))),
24  : edm::EDPutTokenT<reco::TrackCollection>{}),
25  outputMaskToken_(produceMask_ ? produces<std::vector<bool>>() : edm::EDPutTokenT<std::vector<bool>>{}) {}
26 
27  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
29  desc.add<edm::InputTag>("tracks", edm::InputTag("hltPixelTracks"));
30  desc.add<edm::InputTag>("regions", edm::InputTag(""));
31  desc.add<bool>("produceTrackCollection", true);
32  desc.add<bool>("produceMask", true);
33  descriptions.add("trackSelectorByRegion", desc);
34  }
35 
36 private:
37  using MaskCollection = std::vector<bool>;
38 
39  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const override {
40  if (not produceCollection_ and not produceMask_)
41  return;
42 
43  auto const& regions = iEvent.get(inputTrkRegionToken_);
44  auto const& tracks = iEvent.get(tracksToken_);
45  MaskCollection mask(tracks.size(), false); // output mask
46 
47  for (auto const& region : regions) {
48  region->checkTracks(tracks, mask);
49  }
50 
51  if (produceCollection_) {
52  reco::TrackCollection output_tracks; // output collection with a (shallow) copy of the selected tracks
53  size_t size = 0;
54  // count the number of selected tracks
55  for (size_t i = 0; i < mask.size(); i++) {
56  size += mask[i];
57  }
58  output_tracks.reserve(size);
59  for (size_t i = 0; i < mask.size(); i++) {
60  if (mask[i])
61  output_tracks.push_back(tracks[i]);
62  }
63  iEvent.emplace(outputTracksToken_, std::move(output_tracks));
64  }
65  if (produceMask_) {
67  }
68  }
69 
70  const bool produceCollection_;
71  const bool produceMask_;
76 };
77 
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
#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
const edm::EDGetTokenT< std::vector< std::unique_ptr< TrackingRegion > > > inputTrkRegionToken_
def move(src, dest)
Definition: eostools.py:511
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)