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_) {
67  iEvent.emplace(outputMaskToken_, std::move(mask));
68  }
69  }
70 
71  const bool produceCollection_;
72  const bool produceMask_;
77 };
78 
ConfigurationDescriptions.h
edm::StreamID
Definition: StreamID.h:30
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
TrackSelectorByRegion::outputMaskToken_
const edm::EDPutTokenT< std::vector< bool > > outputMaskToken_
Definition: TrackSelectorByRegion.cc:76
edm::EDGetTokenT< reco::TrackCollection >
TrackSelectorByRegion::inputTrkRegionToken_
const edm::EDGetTokenT< edm::OwnVector< TrackingRegion > > inputTrkRegionToken_
Definition: TrackSelectorByRegion.cc:74
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EDPutTokenT< reco::TrackCollection >
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:85964
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
TrackSelectorByRegion
Definition: TrackSelectorByRegion.cc:17
TrackSelectorByRegion::tracksToken_
const edm::EDGetTokenT< reco::TrackCollection > tracksToken_
Definition: TrackSelectorByRegion.cc:73
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
MakerMacros.h
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
TrackSelectorByRegion::outputTracksToken_
const edm::EDPutTokenT< reco::TrackCollection > outputTracksToken_
Definition: TrackSelectorByRegion.cc:75
TrackSelectorByRegion::produceCollection_
const bool produceCollection_
Definition: TrackSelectorByRegion.cc:71
ParameterSetDescription.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
TrackSelectorByRegion::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TrackSelectorByRegion.cc:28
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
TrackSelectorByRegion::MaskCollection
std::vector< bool > MaskCollection
Definition: TrackSelectorByRegion.cc:38
TrackSelectorByRegion::produce
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &) const override
Definition: TrackSelectorByRegion.cc:40
HLT_FULL_cff.region
region
Definition: HLT_FULL_cff.py:84949
ModuleDef.h
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:57
TrackSelectorByRegion::TrackSelectorByRegion
TrackSelectorByRegion(const edm::ParameterSet &conf)
Definition: TrackSelectorByRegion.cc:19
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
edm::ProductRegistryHelper::produces
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
Definition: ProductRegistryHelper.h:108
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
TrackingRegion
Definition: TrackingRegion.h:41
AlignmentPI::regions
regions
Definition: AlignmentPayloadInspectorHelper.h:76
TrackingRegion.h
ParameterSet.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:153
OwnVector.h
EDProducer.h
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
TrackSelectorByRegion::produceMask_
const bool produceMask_
Definition: TrackSelectorByRegion.cc:72
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443