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