CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripRecHitConverterAlgorithm.cc
Go to the documentation of this file.
4 
7 
11 
16 
17 
19  useQuality(conf.getParameter<bool>("useSiStripQuality")),
20  maskBad128StripBlocks( conf.existsAs<bool>("MaskBadAPVFibers") && conf.getParameter<bool>("MaskBadAPVFibers")),
21  tracker_cache_id(0),
22  cpe_cache_id(0),
23  quality_cache_id(0),
24  cpeTag(conf.getParameter<edm::ESInputTag>("StripCPE")),
25  matcherTag(conf.getParameter<edm::ESInputTag>("Matcher")),
26  qualityTag(conf.getParameter<edm::ESInputTag>("siStripQualityLabel"))
27 {}
28 
31 {
32  uint32_t tk_cache_id = es.get<TrackerDigiGeometryRecord>().cacheIdentifier();
33  uint32_t c_cache_id = es.get<TkStripCPERecord>().cacheIdentifier();
34  uint32_t q_cache_id = es.get<SiStripQualityRcd>().cacheIdentifier();
35 
36  if(tk_cache_id != tracker_cache_id) {
38  tracker_cache_id = tk_cache_id;
39  }
40  if(c_cache_id != cpe_cache_id) {
43  cpe_cache_id = c_cache_id;
44  }
45  if( useQuality && q_cache_id!=quality_cache_id) {
47  quality_cache_id = q_cache_id;
48  }
49 }
50 
53 { run(input, output, LocalVector(0.,0.,0.)); }
54 
57 {
59  DS = inputhandle->begin(); DS != inputhandle->end(); DS++ ) { if(!useModule(DS->id())) continue;
60 
61  Collector collector = StripSubdetector(DS->id()).stereo()
62  ? Collector(*output.stereo, DS->id())
63  : Collector(*output.rphi, DS->id());
64  bool bad128StripBlocks[6]; fillBad128StripBlocks( DS->id(), bad128StripBlocks);
65 
66 
68  cluster = DS->begin(); cluster != DS->end(); ++cluster ) { if(isMasked(*cluster,bad128StripBlocks)) continue;
69 
70  StripClusterParameterEstimator::LocalValues parameters = parameterestimator->localParameters(*cluster,*(tracker->idToDetUnit(DS->id())));
71  collector.push_back(SiStripRecHit2D( parameters.first, parameters.second, DS->id(), edmNew::makeRefTo(inputhandle,cluster) ));
72  }
73 
74  if (collector.empty()) collector.abort();
75  }
76  match(output,trackdirection);
77 }
78 
81  edm::Handle<edm::LazyGetter<SiStripCluster> > lazyGetterhandle,
83 {
84  bool bad128StripBlocks[6];
85  bool goodDet=true;
86  DetId lastId(0);
87  std::auto_ptr<Collector> collector(new Collector(*output.stereo, lastId));
88 
89  edm::RefGetter<SiStripCluster>::const_iterator iregion = refGetterhandle->begin();
90  for(;iregion!=refGetterhandle->end();++iregion) {
91  const edm::RegionIndex<SiStripCluster>& region = *iregion;
92  const uint32_t start = region.start();
93  const uint32_t finish = region.finish();
94  for (uint32_t i = start; i < finish; i++) {
95  edm::RegionIndex<SiStripCluster>::const_iterator icluster = region.begin()+(i-start);
96 
97  DetId detId(icluster->geographicalId());
98  if(detId != lastId) {
99  if(collector->empty()) collector->abort();
100  lastId = detId;
101  goodDet = useModule(detId);
102  if(goodDet) {
103  fillBad128StripBlocks(detId, bad128StripBlocks);
104  collector = StripSubdetector(detId).stereo()
105  ? std::auto_ptr<Collector>(new Collector(*output.stereo, detId))
106  : std::auto_ptr<Collector>(new Collector(*output.rphi, detId));
107  }
108  }
109  if( !goodDet || isMasked(*icluster, bad128StripBlocks)) continue;
110 
111  StripClusterParameterEstimator::LocalValues parameters = parameterestimator->localParameters(*icluster,*(tracker->idToDetUnit(detId)));
112  collector->push_back(SiStripRecHit2D( parameters.first, parameters.second, detId, makeRefToLazyGetter(lazyGetterhandle,i) ));
113  }
114  if(collector->empty()) collector->abort();
115  }
116  match(output,LocalVector(0.,0.,0.));
117 }
118 
119 
120 namespace {
121 
122  struct CollectorHelper {
123  bool regional;
124  size_t nmatch;
125 
126 
127  typedef edm::OwnVector<SiStripMatchedRecHit2D> CollectorMatched;
129 
130  Collector & m_collector;
131  CollectorMatched & m_collectorMatched;
132  SiStripRecHit2DCollection::FastFiller & m_fillerRphiUnm;
133  std::vector<SiStripRecHit2D::ClusterRef::key_type> & m_matchedSteroClusters;
134  std::vector<SiStripRecHit2D::ClusterRegionalRef::key_type> & m_matchedSteroClustersRegional;
135 
136  static inline SiStripRecHit2D const & stereoHit(edmNew::DetSet<SiStripRecHit2D>::const_iterator iter) {
137  return *iter;
138  }
139 
140  static inline SiStripRecHit2D const & monoHit(edmNew::DetSet<SiStripRecHit2D>::const_iterator iter) {
141  return *iter;
142  }
143 
144  struct Add {
145  Add(CollectorHelper& ih) : h(ih){}
146  CollectorHelper& h;
147  void operator()(SiStripMatchedRecHit2D const & rh) { h.m_collectorMatched.push_back(rh);}
148  };
149 
150  CollectorHelper & collector() {
151  return *this;
152  }
153 
154  void operator()(SiStripMatchedRecHit2D const & rh) {m_collectorMatched.push_back(rh);}
155 
156 
157  CollectorHelper(
158  Collector & i_collector,
159  CollectorMatched & i_collectorMatched,
160  SiStripRecHit2DCollection::FastFiller & i_fillerRphiUnm,
161  std::vector<SiStripRecHit2D::ClusterRef::key_type> & i_matchedSteroClusters,
162  std::vector<SiStripRecHit2D::ClusterRegionalRef::key_type> & i_matchedSteroClustersRegional
163  ) : regional(false), nmatch(0),
164  m_collector(i_collector),
165  m_collectorMatched(i_collectorMatched),
166  m_fillerRphiUnm(i_fillerRphiUnm),
167  m_matchedSteroClusters(i_matchedSteroClusters),
168  m_matchedSteroClustersRegional(i_matchedSteroClustersRegional)
169  {}
170 
172  if (!m_collectorMatched.empty()){
173  nmatch+=m_collectorMatched.size();
174  for (edm::OwnVector<SiStripMatchedRecHit2D>::const_iterator itm = m_collectorMatched.begin(),
175  edm = m_collectorMatched.end();
176  itm != edm;
177  ++itm) {
178  m_collector.push_back(*itm);
179  // mark the stereo hit cluster as used, so that the hit won't go in the unmatched stereo ones
180  if (itm->stereoHit()->cluster().isNonnull()) {
181  m_matchedSteroClusters.push_back(itm->stereoHit()->cluster().key());
182  } else {
183  m_matchedSteroClustersRegional.push_back(itm->stereoHit()->cluster_regional().key());
184  regional = true;
185  }
186  }
187  m_collectorMatched.clear();
188  } else {
189  // store a copy of this rphi hit as an unmatched rphi hit
190  m_fillerRphiUnm.push_back(*it);
191  }
192  }
193  };
194 }
195 
196 
198 match(products& output, LocalVector trackdirection) const
199 {
200  int nmatch=0;
201  edm::OwnVector<SiStripMatchedRecHit2D> collectorMatched; // gp/FIXME: avoid this
202 
203  // Remember the ends of the collections, as we will use them a lot
204  SiStripRecHit2DCollection::const_iterator edStereoDet = output.stereo->end();
205  SiStripRecHit2DCollection::const_iterator edRPhiDet = output.rphi->end();
206 
207  // two work vectors for bookeeping clusters used by the stereo part of the matched hits
208  std::vector<SiStripRecHit2D::ClusterRef::key_type> matchedSteroClusters;
209  std::vector<SiStripRecHit2D::ClusterRegionalRef::key_type> matchedSteroClustersRegional;
210 
211  for (SiStripRecHit2DCollection::const_iterator itRPhiDet = output.rphi->begin(); itRPhiDet != edRPhiDet; ++itRPhiDet) {
212  edmNew::DetSet<SiStripRecHit2D> rphiHits = *itRPhiDet;
213  StripSubdetector specDetId(rphiHits.detId());
214  uint32_t partnerId = specDetId.partnerDetId();
215 
216  // if not part of a glued pair
217  if (partnerId == 0) {
218  // I must copy these as unmatched
219  if (!rphiHits.empty()) {
220  SiStripRecHit2DCollection::FastFiller filler(*output.rphiUnmatched, rphiHits.detId());
221  filler.resize(rphiHits.size());
222  std::copy(rphiHits.begin(), rphiHits.end(), filler.begin());
223  }
224  continue;
225  }
226 
227  SiStripRecHit2DCollection::const_iterator itStereoDet = output.stereo->find(partnerId);
228 
229  // if the partner is not found (which probably can happen if it's empty)
230  if (itStereoDet == edStereoDet) {
231  // I must copy these as unmatched
232  if (!rphiHits.empty()) {
233  SiStripRecHit2DCollection::FastFiller filler(*output.rphiUnmatched, rphiHits.detId());
234  filler.resize(rphiHits.size());
235  std::copy(rphiHits.begin(), rphiHits.end(), filler.begin());
236  }
237  continue;
238  }
239 
240  edmNew::DetSet<SiStripRecHit2D> stereoHits = *itStereoDet;
241 
242 
243  // Get ready for making glued hits
244  const GluedGeomDet* gluedDet = (const GluedGeomDet*)tracker->idToDet(DetId(specDetId.glued()));
246  Collector collector(*output.matched, specDetId.glued());
247 
248  // Prepare also the list for unmatched rphi hits
249  SiStripRecHit2DCollection::FastFiller fillerRphiUnm(*output.rphiUnmatched, rphiHits.detId());
250 
251  // a list of clusters used by the matched part of the stereo hits in this detector
252  matchedSteroClusters.clear(); // at the beginning, empty
253  matchedSteroClustersRegional.clear(); // I need two because the refs can be different
254  bool regional = false; // I also want to remember if they come from standard or HLT reco
255 
256 #ifdef DOUBLE_MATCH
257  CollectorHelper chelper(collector, collectorMatched,
258  fillerRphiUnm,
259  matchedSteroClusters,matchedSteroClustersRegional
260  );
261  matcher->doubleMatch(rphiHits.begin(), rphiHits.end(),
262  stereoHits.begin(),stereoHits.end(),gluedDet,trackdirection,chelper);
263  regional = chelper.regional;
264  nmatch+=chelper.nmatch;
265 #else
266  // Make simple collection of this (gp:FIXME: why do we need it?)
268  // gp:FIXME: use std::transform
269  stereoSimpleHits.reserve(stereoHits.size());
270  for (edmNew::DetSet<SiStripRecHit2D>::const_iterator it = stereoHits.begin(), ed = stereoHits.end(); it != ed; ++it) {
271  stereoSimpleHits.push_back(&*it);
272  }
273 
274  for (edmNew::DetSet<SiStripRecHit2D>::const_iterator it = rphiHits.begin(), ed = rphiHits.end(); it != ed; ++it) {
275  matcher->match(&(*it),stereoSimpleHits.begin(),stereoSimpleHits.end(),collectorMatched,gluedDet,trackdirection);
276  if (collectorMatched.size()>0){
277  nmatch+=collectorMatched.size();
279  edm = collectorMatched.end();
280  itm != edm;
281  ++itm) {
282  collector.push_back(*itm);
283  // mark the stereo hit cluster as used, so that the hit won't go in the unmatched stereo ones
284  if (itm->stereoHit()->cluster().isNonnull()) {
285  matchedSteroClusters.push_back(itm->stereoHit()->cluster().key());
286  } else {
287  matchedSteroClustersRegional.push_back(itm->stereoHit()->cluster_regional().key());
288  regional = true;
289  }
290  }
291  collectorMatched.clear();
292  } else {
293  // store a copy of this rphi hit as an unmatched rphi hit
294  fillerRphiUnm.push_back(*it);
295  }
296  }
297 
298 #endif
299 
300 
301  // discard matched hits if the collection is empty
302  if (collector.empty()) collector.abort();
303 
304  // discard unmatched rphi hits if there are none
305  if (fillerRphiUnm.empty()) fillerRphiUnm.abort();
306 
307  // now look for unmatched stereo hits
308  SiStripRecHit2DCollection::FastFiller fillerStereoUnm(*output.stereoUnmatched, stereoHits.detId());
309  if (!regional) {
310  std::sort(matchedSteroClusters.begin(), matchedSteroClusters.end());
311  for (edmNew::DetSet<SiStripRecHit2D>::const_iterator it = stereoHits.begin(), ed = stereoHits.end(); it != ed; ++it) {
312  if (!std::binary_search(matchedSteroClusters.begin(), matchedSteroClusters.end(), it->cluster().key())) {
313  fillerStereoUnm.push_back(*it);
314  }
315  }
316  } else {
317  std::sort(matchedSteroClustersRegional.begin(), matchedSteroClustersRegional.end());
318  for (edmNew::DetSet<SiStripRecHit2D>::const_iterator it = stereoHits.begin(), ed = stereoHits.end(); it != ed; ++it) {
319  if (!std::binary_search(matchedSteroClustersRegional.begin(), matchedSteroClustersRegional.end(), it->cluster_regional().key())) {
320  fillerStereoUnm.push_back(*it);
321  }
322  }
323  }
324  if (fillerStereoUnm.empty()) fillerStereoUnm.abort();
325 
326 
327  }
328 
329  for (SiStripRecHit2DCollection::const_iterator itStereoDet = output.stereo->begin(); itStereoDet != edStereoDet; ++itStereoDet) {
330  edmNew::DetSet<SiStripRecHit2D> stereoHits = *itStereoDet;
331  StripSubdetector specDetId(stereoHits.detId());
332  uint32_t partnerId = specDetId.partnerDetId();
333  if (partnerId == 0) continue;
334  SiStripRecHit2DCollection::const_iterator itRPhiDet = output.rphi->find(partnerId);
335  if (itRPhiDet == edRPhiDet) {
336  if (!stereoHits.empty()) {
337  SiStripRecHit2DCollection::FastFiller filler(*output.stereoUnmatched, stereoHits.detId());
338  filler.resize(stereoHits.size());
339  std::copy(stereoHits.begin(), stereoHits.end(), filler.begin());
340  }
341  }
342  }
343 
344  edm::LogInfo("SiStripRecHitConverter")
345  << "found\n"
346  << nmatch
347  << " matched RecHits\n";
348 }
349 
351 fillBad128StripBlocks(const uint32_t detid, bool bad128StripBlocks[6] ) const
352 {
354  short badApvs = quality->getBadApvs(detid);
355  short badFibers = quality->getBadFibers(detid);
356  for (int j = 0; j < 6; j++) {
357  bad128StripBlocks[j] = (badApvs & (1 << j));
358  }
359  for (int j = 0; j < 3; j++) {
360  if (badFibers & (1 << j)) {
361  bad128StripBlocks[2*j+0] = true;
362  bad128StripBlocks[2*j+1] = true;
363  }
364  }
365  }
366 }
367 
368 inline
370 isMasked(const SiStripCluster &cluster, bool bad128StripBlocks[6]) const
371 {
373  if ( bad128StripBlocks[cluster.firstStrip() >> 7] ) {
374  if ( bad128StripBlocks[(cluster.firstStrip()+cluster.amplitudes().size()) >> 7] ||
375  bad128StripBlocks[static_cast<int32_t>(cluster.barycenter()-0.499999) >> 7] ) {
376  return true;
377  }
378  } else {
379  if ( bad128StripBlocks[(cluster.firstStrip()+cluster.amplitudes().size()) >> 7] &&
380  bad128StripBlocks[static_cast<int32_t>(cluster.barycenter()-0.499999) >> 7] ) {
381  return true;
382  }
383  }
384  }
385  return false;
386 }
387 
388 inline
390 useModule(const uint32_t id) const
391 {
392  const StripGeomDetUnit * stripdet=(const StripGeomDetUnit*)tracker->idToDetUnit(id);
393  if(stripdet==0) edm::LogWarning("SiStripRecHitConverter") << "Detid=" << id << " not found";
394  return stripdet!=0 && (!useQuality || quality->IsModuleUsable(id));
395 }
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, typename HandleT::element_type::value_type::const_iterator itIter)
int i
Definition: DBlmapReader.cc:9
void push_back(data_type const &d)
dictionary parameters
Definition: Parameters.py:2
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Local3DVector LocalVector
Definition: LocalVector.h:12
void run(edm::Handle< edmNew::DetSetVector< SiStripCluster > > input, products &output)
std::auto_ptr< SiStripRecHit2DCollection > rphiUnmatched
edm::ESHandle< SiStripRecHitMatcher > matcher
edm::ESHandle< TrackerGeometry > tracker
size_type size() const
Definition: OwnVector.h:262
const_iterator end() const
Return the off-the-end iterator.
Definition: RefGetter.h:162
uint16_t firstStrip() const
data_type const * const_iterator
Definition: DetSetNew.h:25
SiStripRecHitConverterAlgorithm(const edm::ParameterSet &)
void fillBad128StripBlocks(const uint32_t detid, bool bad128StripBlocks[6]) const
unsigned int partnerDetId() const
std::pair< LocalPoint, LocalError > LocalValues
iterator begin()
Definition: OwnVector.h:236
bool empty() const
Definition: DetSetNew.h:78
void clear()
Definition: OwnVector.h:399
void match(products &output, LocalVector trackdirection) const
Ref< LazyGetter< T >, T, FindValue< T > > makeRefToLazyGetter(const Handle< LazyGetter< T > > &handle, const uint32_t index)
Definition: LazyGetter.h:532
int j
Definition: DBlmapReader.cc:9
float barycenter() const
uint32_t finish() const
Get off-the-end finish index.
Definition: LazyGetter.h:140
std::auto_ptr< SiStripRecHit2DCollection > stereoUnmatched
std::auto_ptr< SiStripRecHit2DCollection > rphi
const_iterator begin() const
Get begin iterator.
Definition: LazyGetter.h:180
tuple conf
Definition: dbtoconf.py:185
tuple input
Definition: collect_tpl.py:10
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:97
Definition: DetId.h:20
unsigned int stereo() const
stereo
iterator end()
Definition: OwnVector.h:243
std::vector< T >::const_iterator const_iterator
Definition: LazyGetter.h:46
boost::indirect_iterator< typename collection_type::const_iterator > const_iterator
Definition: RefGetter.h:25
std::vector< const SiStripRecHit2D * > SimpleHitCollection
const T & get() const
Definition: EventSetup.h:55
SiStripRecHit2DCollection::FastFiller Collector
id_type detId() const
Definition: DetSetNew.h:72
uint32_t start() const
Get start index.
Definition: LazyGetter.h:133
iterator end()
Definition: DetSetNew.h:59
edm::ESHandle< StripClusterParameterEstimator > parameterestimator
size_type size() const
Definition: DetSetNew.h:75
std::auto_ptr< SiStripMatchedRecHit2DCollection > matched
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
const std::vector< uint8_t > & amplitudes() const
std::auto_ptr< SiStripRecHit2DCollection > stereo
bool isMasked(const SiStripCluster &cluster, bool bad128StripBlocks[6]) const
edm::ESHandle< SiStripQuality > quality
iterator begin()
Definition: DetSetNew.h:56