CMS 3D CMS Logo

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