CMS 3D CMS Logo

SiStripRecHitConverterAlgorithm.cc
Go to the documentation of this file.
4 
7 
10 
15 
16 #include <vector>
17 
20  : useQuality(conf.getParameter<bool>("useSiStripQuality")),
21  maskBad128StripBlocks(conf.getParameter<bool>("MaskBadAPVFibers")),
22  doMatching(conf.getParameter<bool>("doMatching")),
25  conf.getParameter<edm::ESInputTag>("StripCPE"))) {
26  if (doMatching) {
28  }
29  if (useQuality) {
30  qualityToken =
31  iC.esConsumes<SiStripQuality, SiStripQualityRcd>(conf.getParameter<edm::ESInputTag>("siStripQualityLabel"));
32  }
33 }
34 
36  desc.add<bool>("useSiStripQuality", false);
37  desc.add<bool>("MaskBadAPVFibers", false);
38  desc.add<bool>("doMatching", true);
39  desc.add<edm::ESInputTag>("StripCPE", edm::ESInputTag("StripCPEfromTrackAngleESProducer", "StripCPEfromTrackAngle"));
40  desc.add<edm::ESInputTag>("Matcher", edm::ESInputTag("SiStripRecHitMatcherESProducer", "StandardMatcher"));
41  desc.add<edm::ESInputTag>("siStripQualityLabel", edm::ESInputTag());
42 }
43 
47  if (doMatching) {
49  }
50  if (useQuality) {
52  }
53 }
54 
56  run(input, output, LocalVector(0., 0., 0.));
57 }
58 
61  LocalVector trackdirection) {
62  for (auto const& DS : *inputhandle) {
63  auto id = DS.id();
64  if (!useModule(id))
65  continue;
66 
67  Collector collector = StripSubdetector(id).stereo() ? Collector(*output.stereo, id) : Collector(*output.rphi, id);
68 
69  bool bad128StripBlocks[6];
70  fillBad128StripBlocks(id, bad128StripBlocks);
71 
72  GeomDetUnit const& du = *(tracker->idToDetUnit(id));
73  for (auto const& cluster : DS) {
74  if (isMasked(cluster, bad128StripBlocks))
75  continue;
76 
78  collector.push_back(
79  SiStripRecHit2D(parameters.first, parameters.second, du, DS.makeRefTo(inputhandle, &cluster)));
80  }
81 
82  if (collector.empty())
83  collector.abort();
84  }
85  if (doMatching) {
86  match(output, trackdirection);
87  }
88 }
89 
90 namespace {
91 
92  struct CollectorHelper {
93  size_t nmatch;
94 
95  using CollectorMatched = std::vector<std::unique_ptr<SiStripMatchedRecHit2D>>;
97 
98  Collector& m_collector;
99  CollectorMatched& m_collectorMatched;
100  SiStripRecHit2DCollection::FastFiller& m_fillerRphiUnm;
101  std::vector<SiStripRecHit2D::ClusterRef::key_type>& m_matchedSteroClusters;
102 
103  static inline SiStripRecHit2D const& stereoHit(edmNew::DetSet<SiStripRecHit2D>::const_iterator iter) {
104  return *iter;
105  }
106 
107  static inline SiStripRecHit2D const& monoHit(edmNew::DetSet<SiStripRecHit2D>::const_iterator iter) { return *iter; }
108 
109  CollectorHelper& collector() { return *this; }
110 
111  void operator()(SiStripMatchedRecHit2D const& rh) { m_collectorMatched.emplace_back(rh.clone()); }
112 
113  CollectorHelper(Collector& i_collector,
114  CollectorMatched& i_collectorMatched,
115  SiStripRecHit2DCollection::FastFiller& i_fillerRphiUnm,
116  std::vector<SiStripRecHit2D::ClusterRef::key_type>& i_matchedSteroClusters)
117  : nmatch(0),
118  m_collector(i_collector),
119  m_collectorMatched(i_collectorMatched),
120  m_fillerRphiUnm(i_fillerRphiUnm),
121  m_matchedSteroClusters(i_matchedSteroClusters) {}
122 
124  if (!m_collectorMatched.empty()) {
125  nmatch += m_collectorMatched.size();
126  for (auto const& itm : m_collectorMatched) {
127  m_collector.push_back(*itm);
128  // mark the stereo hit cluster as used, so that the hit won't go in the unmatched stereo ones
129  m_matchedSteroClusters.push_back(itm->stereoClusterRef().key());
130  }
131  m_collectorMatched.clear();
132  } else {
133  // store a copy of this rphi hit as an unmatched rphi hit
134  m_fillerRphiUnm.push_back(*it);
135  }
136  }
137  };
138 } // namespace
139 
141  int nmatch = 0;
142  std::vector<std::unique_ptr<SiStripMatchedRecHit2D>> collectorMatched;
143 
144  // Remember the ends of the collections, as we will use them a lot
145  SiStripRecHit2DCollection::const_iterator edStereoDet = output.stereo->end();
146  SiStripRecHit2DCollection::const_iterator edRPhiDet = output.rphi->end();
147 
148  // two work vectors for bookeeping clusters used by the stereo part of the matched hits
149  std::vector<SiStripRecHit2D::ClusterRef::key_type> matchedSteroClusters;
150 
151  for (SiStripRecHit2DCollection::const_iterator itRPhiDet = output.rphi->begin(); itRPhiDet != edRPhiDet;
152  ++itRPhiDet) {
153  edmNew::DetSet<SiStripRecHit2D> rphiHits = *itRPhiDet;
154  StripSubdetector specDetId(rphiHits.detId());
155  uint32_t partnerId = specDetId.partnerDetId();
156 
157  // if not part of a glued pair
158  if (partnerId == 0) {
159  // I must copy these as unmatched
160  if (!rphiHits.empty()) {
161  SiStripRecHit2DCollection::FastFiller filler(*output.rphiUnmatched, rphiHits.detId());
162  filler.resize(rphiHits.size());
163  std::copy(rphiHits.begin(), rphiHits.end(), filler.begin());
164  }
165  continue;
166  }
167 
168  SiStripRecHit2DCollection::const_iterator itStereoDet = output.stereo->find(partnerId);
169 
170  // if the partner is not found (which probably can happen if it's empty)
171  if (itStereoDet == edStereoDet) {
172  // I must copy these as unmatched
173  if (!rphiHits.empty()) {
174  SiStripRecHit2DCollection::FastFiller filler(*output.rphiUnmatched, rphiHits.detId());
175  filler.resize(rphiHits.size());
176  std::copy(rphiHits.begin(), rphiHits.end(), filler.begin());
177  }
178  continue;
179  }
180 
181  edmNew::DetSet<SiStripRecHit2D> stereoHits = *itStereoDet;
182 
183  // Get ready for making glued hits
184  const GluedGeomDet* gluedDet = (const GluedGeomDet*)tracker->idToDet(DetId(specDetId.glued()));
186  Collector collector(*output.matched, specDetId.glued());
187 
188  // Prepare also the list for unmatched rphi hits
189  SiStripRecHit2DCollection::FastFiller fillerRphiUnm(*output.rphiUnmatched, rphiHits.detId());
190 
191  // a list of clusters used by the matched part of the stereo hits in this detector
192  matchedSteroClusters.clear(); // at the beginning, empty
193 
194 #ifdef DOUBLE_MATCH
195  CollectorHelper chelper(collector, collectorMatched, fillerRphiUnm, matchedSteroClusters);
197  rphiHits.begin(), rphiHits.end(), stereoHits.begin(), stereoHits.end(), gluedDet, trackdirection, chelper);
198  nmatch += chelper.nmatch;
199 #else
200  // Make simple collection of this (gp:FIXME: why do we need it?)
202  // gp:FIXME: use std::transform
203  stereoSimpleHits.reserve(stereoHits.size());
204  for (edmNew::DetSet<SiStripRecHit2D>::const_iterator it = stereoHits.begin(), ed = stereoHits.end(); it != ed;
205  ++it) {
206  stereoSimpleHits.push_back(&*it);
207  }
208 
209  for (edmNew::DetSet<SiStripRecHit2D>::const_iterator it = rphiHits.begin(), ed = rphiHits.end(); it != ed; ++it) {
210  matcher->match(
211  &(*it), stereoSimpleHits.begin(), stereoSimpleHits.end(), collectorMatched, gluedDet, trackdirection);
212  if (collectorMatched.size() > 0) {
213  nmatch += collectorMatched.size();
214  for (auto const& itm : collectorMatched) {
215  collector.push_back(*itm);
216  // mark the stereo hit cluster as used, so that the hit won't go in the unmatched stereo ones
217  matchedSteroClusters.push_back(itm->stereoClusterRef().key());
218  }
219  collectorMatched.clear();
220  } else {
221  // store a copy of this rphi hit as an unmatched rphi hit
222  fillerRphiUnm.push_back(*it);
223  }
224  }
225 
226 #endif
227 
228  // discard matched hits if the collection is empty
229  if (collector.empty())
230  collector.abort();
231 
232  // discard unmatched rphi hits if there are none
233  if (fillerRphiUnm.empty())
234  fillerRphiUnm.abort();
235 
236  // now look for unmatched stereo hits
237  SiStripRecHit2DCollection::FastFiller fillerStereoUnm(*output.stereoUnmatched, stereoHits.detId());
238  std::sort(matchedSteroClusters.begin(), matchedSteroClusters.end());
239  for (edmNew::DetSet<SiStripRecHit2D>::const_iterator it = stereoHits.begin(), ed = stereoHits.end(); it != ed;
240  ++it) {
241  if (!std::binary_search(matchedSteroClusters.begin(), matchedSteroClusters.end(), it->cluster().key())) {
242  fillerStereoUnm.push_back(*it);
243  }
244  }
245  if (fillerStereoUnm.empty())
246  fillerStereoUnm.abort();
247  }
248 
249  for (SiStripRecHit2DCollection::const_iterator itStereoDet = output.stereo->begin(); itStereoDet != edStereoDet;
250  ++itStereoDet) {
251  edmNew::DetSet<SiStripRecHit2D> stereoHits = *itStereoDet;
252  StripSubdetector specDetId(stereoHits.detId());
253  uint32_t partnerId = specDetId.partnerDetId();
254  if (partnerId == 0)
255  continue;
256  SiStripRecHit2DCollection::const_iterator itRPhiDet = output.rphi->find(partnerId);
257  if (itRPhiDet == edRPhiDet) {
258  if (!stereoHits.empty()) {
259  SiStripRecHit2DCollection::FastFiller filler(*output.stereoUnmatched, stereoHits.detId());
260  filler.resize(stereoHits.size());
261  std::copy(stereoHits.begin(), stereoHits.end(), filler.begin());
262  }
263  }
264  }
265 
266  edm::LogInfo("SiStripRecHitConverter") << "found\n" << nmatch << " matched RecHits\n";
267 }
268 
269 void SiStripRecHitConverterAlgorithm::fillBad128StripBlocks(const uint32_t detid, bool bad128StripBlocks[6]) const {
270  if (maskBad128StripBlocks) {
271  short badApvs = quality->getBadApvs(detid);
272  short badFibers = quality->getBadFibers(detid);
273  for (int j = 0; j < 6; j++) {
274  bad128StripBlocks[j] = (badApvs & (1 << j));
275  }
276  for (int j = 0; j < 3; j++) {
277  if (badFibers & (1 << j)) {
278  bad128StripBlocks[2 * j + 0] = true;
279  bad128StripBlocks[2 * j + 1] = true;
280  }
281  }
282  }
283 }
284 
285 inline bool SiStripRecHitConverterAlgorithm::isMasked(const SiStripCluster& cluster, bool bad128StripBlocks[6]) const {
286  if (maskBad128StripBlocks) {
287  if (bad128StripBlocks[cluster.firstStrip() >> 7]) {
288  if (bad128StripBlocks[(cluster.firstStrip() + cluster.amplitudes().size()) >> 7] ||
289  bad128StripBlocks[static_cast<int32_t>(cluster.barycenter() - 0.499999) >> 7]) {
290  return true;
291  }
292  } else {
293  if (bad128StripBlocks[(cluster.firstStrip() + cluster.amplitudes().size()) >> 7] &&
294  bad128StripBlocks[static_cast<int32_t>(cluster.barycenter() - 0.499999) >> 7]) {
295  return true;
296  }
297  }
298  }
299  return false;
300 }
301 
302 inline bool SiStripRecHitConverterAlgorithm::useModule(const uint32_t id) const {
303  const StripGeomDetUnit* stripdet = (const StripGeomDetUnit*)tracker->idToDetUnit(id);
304  if (stripdet == nullptr)
305  edm::LogWarning("SiStripRecHitConverter") << "Detid=" << id << " not found";
306  return stripdet != nullptr && (!useQuality || quality->IsModuleUsable(id));
307 }
std::pair< LocalPoint, LocalError > LocalValues
unsigned int partnerDetId() const
void push_back(data_type const &d)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::ESGetToken< SiStripRecHitMatcher, TkStripCPERecord > matcherToken
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
uint16_t firstStrip() const
Local3DVector LocalVector
Definition: LocalVector.h:12
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
unsigned int stereo() const
stereo
virtual void localParameters(AClusters const &clusters, ALocalValues &retValues, const GeomDetUnit &gd, const LocalTrajectoryParameters &ltp) const
short getBadFibers(uint32_t detid) const
void run(edm::Handle< edmNew::DetSetVector< SiStripCluster > > input, products &output)
edm::ESGetToken< StripClusterParameterEstimator, TkStripCPERecord > cpeToken
std::unique_ptr< SiStripMatchedRecHit2D > match(const SiStripRecHit2D *monoRH, const SiStripRecHit2D *stereoRH, const GluedGeomDet *gluedDet, LocalVector trackdirection, bool force) const
SiStripRecHitConverterAlgorithm(const edm::ParameterSet &, edm::ConsumesCollector)
data_type const * const_iterator
Definition: DetSetNew.h:31
bool isMasked(const SiStripCluster &cluster, bool bad128StripBlocks[6]) const
bool empty() const
Definition: DetSetNew.h:67
id_type detId() const
Definition: DetSetNew.h:63
static std::string const input
Definition: EdmProvDump.cc:50
const StripClusterParameterEstimator * parameterestimator
edm::ESGetToken< SiStripQuality, SiStripQualityRcd > qualityToken
SiStripCluster const & amplitudes() const
auto size() const
SiStripMatchedRecHit2D * clone() const override
void fillBad128StripBlocks(const uint32_t detid, bool bad128StripBlocks[6]) const
const TrackerGeomDet * idToDet(DetId) const override
Log< level::Info, false > LogInfo
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
void match(products &output, LocalVector trackdirection) const
std::vector< const SiStripRecHit2D * > SimpleHitCollection
SiStripRecHit2DCollection::FastFiller Collector
size_type size() const
Definition: DetSetNew.h:65
void doubleMatch(MonoIterator monoRHiter, MonoIterator monoRHend, StereoIterator seconditer, StereoIterator seconditerend, const GluedGeomDet *gluedDet, LocalVector trdir, CollectorHelper &collectorHelper) const
HLT enums.
iterator end()
Definition: DetSetNew.h:53
float barycenter() const
Definition: output.py:1
Log< level::Warning, false > LogWarning
static void fillPSetDescription(edm::ParameterSetDescription &desc)
bool IsModuleUsable(uint32_t detid) const
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerToken
short getBadApvs(uint32_t detid) const
iterator begin()
Definition: DetSetNew.h:51