CMS 3D CMS Logo

FastTrackerRecHitMaskProducer.cc
Go to the documentation of this file.
1 // system includes
2 #include <memory>
3 
4 // framework stuff
11 
12 // data formats
18 
19 // other
21 
23 public:
25 
27 
28  void produce(edm::Event&, const edm::EventSetup&) override;
29 
30 private:
31  // an alias
32  using QualityMaskCollection = std::vector<unsigned char>;
33 
34  // tokens
37 
40 
42 
44 };
45 
47  : minNumberOfLayersWithMeasBeforeFiltering_(iConfig.getParameter<int>("minNumberOfLayersWithMeasBeforeFiltering")),
48  trackQuality_(reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"))),
49  trajectories_(iConfig.getParameter<edm::InputTag>("trajectories"), consumesCollector()),
50  recHits_(consumes<FastTrackerRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHits"))) {
51  produces<std::vector<bool> >();
52 
53  auto const& classifier = iConfig.getParameter<edm::InputTag>("trackClassifier");
54  if (!classifier.label().empty())
55  srcQuals = consumes<QualityMaskCollection>(classifier);
56 
57  auto const& oldHitRemovalInfo = iConfig.getParameter<edm::InputTag>("oldHitRemovalInfo");
58  if (!oldHitRemovalInfo.label().empty()) {
59  oldHitMaskToken_ = consumes<std::vector<bool> >(oldHitRemovalInfo);
60  }
61 }
62 
64  // the product
65 
66  std::unique_ptr<std::vector<bool> > collectedHits(new std::vector<bool>());
67 
68  // input
69 
71  iEvent.getByToken(recHits_, recHits);
72 
74  edm::Handle<std::vector<bool> > oldHitMasks;
75  iEvent.getByToken(oldHitMaskToken_, oldHitMasks);
76  collectedHits->insert(collectedHits->begin(), oldHitMasks->begin(), oldHitMasks->end());
77  }
78  collectedHits->resize(recHits->size(), false);
79 
80  auto const& tracks = trajectories_.tracks(iEvent);
81 
82  QualityMaskCollection const* pquals = nullptr;
83  if (!srcQuals.isUninitialized()) {
85  iEvent.getByToken(srcQuals, hqual);
86  pquals = hqual.product();
87  }
88 
89  // required quality
90  unsigned char qualMask = ~0;
92  qualMask = 1 << trackQuality_;
93 
94  // loop over tracks and mask hits of selected tracks
95  for (auto i = 0U; i < tracks.size(); ++i) {
96  const reco::Track& track = tracks[i];
97  bool goodTk = (pquals) ? (*pquals)[i] & qualMask : track.quality(trackQuality_);
98  if (!goodTk)
99  continue;
101  continue;
102  for (auto hitIt = track.recHitsBegin(); hitIt != track.recHitsEnd(); ++hitIt) {
103  if (!(*hitIt)->isValid())
104  continue;
105  const FastTrackerRecHit& hit = static_cast<const FastTrackerRecHit&>(*(*hitIt));
106  // note: for matched hits nIds() returns 2, otherwise 1
107  for (unsigned id_index = 0; id_index < hit.nIds(); id_index++) {
108  (*collectedHits)[unsigned(hit.id(id_index))] = true;
109  }
110  }
111  }
112 
113  iEvent.put(std::move(collectedHits));
114 }
115 
T getParameter(std::string const &) const
std::vector< unsigned char > QualityMaskCollection
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
virtual size_t nIds() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
TrackQuality
track quality
Definition: TrackBase.h:150
size_type size() const
Definition: OwnVector.h:300
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:513
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
FastTrackerRecHitMaskProducer(const edm::ParameterSet &)
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
reco::TrackCollection const & tracks(edm::Event &evt) const
const reco::TrackBase::TrackQuality trackQuality_
void produce(edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: Handle.h:69
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:483
edm::EDGetTokenT< QualityMaskCollection > srcQuals
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:531
fixed size matrix
HLT enums.
const TrackCollectionTokens trajectories_
edm::EDGetTokenT< FastTrackerRecHitCollection > recHits_
virtual int32_t id(size_t i=0) const
bool isUninitialized() const
Definition: EDGetToken.h:70
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< std::vector< bool > > oldHitMaskToken_
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91