CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>{}),
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_) {
67  iEvent.emplace(outputMaskToken_, std::move(mask));
68  }
69  }
70 
71  const bool produceCollection_;
72  const bool produceMask_;
77 };
78 
const edm::EDPutTokenT< std::vector< bool > > outputMaskToken_
TrackSelectorByRegion(const edm::ParameterSet &conf)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const edm::EDPutTokenT< reco::TrackCollection > outputTracksToken_
auto const & tracks
cannot be loose
outputMaskToken_(produceMask_?produces< std::vector< bool >>():edm::EDPutTokenT< std::vector< bool >>{})
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< edm::OwnVector< TrackingRegion > > inputTrkRegionToken_
def move
Definition: eostools.py:511
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &) const override
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:433
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< reco::TrackCollection > tracksToken_
std::vector< bool > MaskCollection
tuple size
Write out results.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)