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 
10 
12 
13 
18 
19 
21  useQuality(conf.getParameter<bool>("useSiStripQuality")),
22  maskBad128StripBlocks( conf.existsAs<bool>("MaskBadAPVFibers") && conf.getParameter<bool>("MaskBadAPVFibers")),
23  tracker_cache_id(0),
24  cpe_cache_id(0),
25  quality_cache_id(0),
26  cpeTag(conf.getParameter<edm::ESInputTag>("StripCPE")),
27  matcherTag(conf.getParameter<edm::ESInputTag>("Matcher")),
28  qualityTag(conf.getParameter<edm::ESInputTag>("siStripQualityLabel"))
29 {}
30 
33 {
34  uint32_t tk_cache_id = es.get<TrackerDigiGeometryRecord>().cacheIdentifier();
35  uint32_t c_cache_id = es.get<TkStripCPERecord>().cacheIdentifier();
36  uint32_t q_cache_id = es.get<SiStripQualityRcd>().cacheIdentifier();
37 
38  if(tk_cache_id != tracker_cache_id) {
40  tracker_cache_id = tk_cache_id;
41  }
42  if(c_cache_id != cpe_cache_id) {
45  cpe_cache_id = c_cache_id;
46  }
47  if( useQuality && q_cache_id!=quality_cache_id) {
49  quality_cache_id = q_cache_id;
50  }
51 }
52 
55 { run(input, output, LocalVector(0.,0.,0.)); }
56 
57 
58 /*
59 namespace {
60  float sigmaPitch(LocalPoint const& pos, LocalError err,
61  GeomDetUnit const & stripdet) {
62  const StripTopology& topol=(const StripTopology&)stripdet.topology();
63 
64  HelpertRecHit2DLocalPos::updateWithAPE(err,stripdet);
65  MeasurementError error=topol.measurementError(pos,err);
66  auto pitch=topol.localPitch(pos);
67  return error.uu()*pitch*pitch;
68  }
69 }
70 */
71 
74 {
75 
78  DS = inputhandle->begin(); DS != dse; ++DS ) {
79  edmNew::det_id_type id = (*DS).id();
80  if(!useModule(id)) continue;
81 
82  Collector collector = StripSubdetector(id).stereo()
83  ? Collector(*output.stereo, id)
84  : Collector(*output.rphi, id);
85 
86  bool bad128StripBlocks[6]; fillBad128StripBlocks( id, bad128StripBlocks);
87 
88  GeomDetUnit const & du = *(tracker->idToDetUnit(id));
91  cluster = (*DS).begin(); cluster != cle; ++cluster ) {
92 
93  if(isMasked(*cluster,bad128StripBlocks)) continue;
94 
96  collector.push_back(SiStripRecHit2D( parameters.first, parameters.second, du, edmNew::makeRefTo(inputhandle,cluster) ));
97  }
98 
99  if (collector.empty()) collector.abort();
100  }
101  match(output,trackdirection);
102 }
103 
104 
105 namespace {
106 
107  struct CollectorHelper {
108  size_t nmatch;
109 
110 
111  typedef edm::OwnVector<SiStripMatchedRecHit2D> CollectorMatched;
113 
114  Collector & m_collector;
115  CollectorMatched & m_collectorMatched;
116  SiStripRecHit2DCollection::FastFiller & m_fillerRphiUnm;
117  std::vector<SiStripRecHit2D::ClusterRef::key_type> & m_matchedSteroClusters;
118 
119  static inline SiStripRecHit2D const & stereoHit(edmNew::DetSet<SiStripRecHit2D>::const_iterator iter) {
120  return *iter;
121  }
122 
123  static inline SiStripRecHit2D const & monoHit(edmNew::DetSet<SiStripRecHit2D>::const_iterator iter) {
124  return *iter;
125  }
126 
127  struct Add {
128  Add(CollectorHelper& ih) : h(ih){}
129  CollectorHelper& h;
130  void operator()(SiStripMatchedRecHit2D const & rh) { h.m_collectorMatched.push_back(rh);}
131  };
132 
133  CollectorHelper & collector() {
134  return *this;
135  }
136 
137  void operator()(SiStripMatchedRecHit2D const & rh) {m_collectorMatched.push_back(rh);}
138 
139 
140  CollectorHelper(
141  Collector & i_collector,
142  CollectorMatched & i_collectorMatched,
143  SiStripRecHit2DCollection::FastFiller & i_fillerRphiUnm,
144  std::vector<SiStripRecHit2D::ClusterRef::key_type> & i_matchedSteroClusters
145  ) : nmatch(0),
146  m_collector(i_collector),
147  m_collectorMatched(i_collectorMatched),
148  m_fillerRphiUnm(i_fillerRphiUnm),
149  m_matchedSteroClusters(i_matchedSteroClusters) {}
150 
152  if (!m_collectorMatched.empty()){
153  nmatch+=m_collectorMatched.size();
154  for (edm::OwnVector<SiStripMatchedRecHit2D>::const_iterator itm = m_collectorMatched.begin(),
155  edm = m_collectorMatched.end();
156  itm != edm;
157  ++itm) {
158  m_collector.push_back(*itm);
159  // mark the stereo hit cluster as used, so that the hit won't go in the unmatched stereo ones
160  m_matchedSteroClusters.push_back(itm->stereoClusterRef().key());
161  }
162  m_collectorMatched.clear();
163  } else {
164  // store a copy of this rphi hit as an unmatched rphi hit
165  m_fillerRphiUnm.push_back(*it);
166  }
167  }
168  };
169 }
170 
171 
173 match(products& output, LocalVector trackdirection) const
174 {
175  int nmatch=0;
176  edm::OwnVector<SiStripMatchedRecHit2D> collectorMatched; // gp/FIXME: avoid this
177 
178  // Remember the ends of the collections, as we will use them a lot
179  SiStripRecHit2DCollection::const_iterator edStereoDet = output.stereo->end();
180  SiStripRecHit2DCollection::const_iterator edRPhiDet = output.rphi->end();
181 
182  // two work vectors for bookeeping clusters used by the stereo part of the matched hits
183  std::vector<SiStripRecHit2D::ClusterRef::key_type> matchedSteroClusters;
184 
185  for (SiStripRecHit2DCollection::const_iterator itRPhiDet = output.rphi->begin(); itRPhiDet != edRPhiDet; ++itRPhiDet) {
186  edmNew::DetSet<SiStripRecHit2D> rphiHits = *itRPhiDet;
187  StripSubdetector specDetId(rphiHits.detId());
188  uint32_t partnerId = specDetId.partnerDetId();
189 
190  // if not part of a glued pair
191  if (partnerId == 0) {
192  // I must copy these as unmatched
193  if (!rphiHits.empty()) {
194  SiStripRecHit2DCollection::FastFiller filler(*output.rphiUnmatched, rphiHits.detId());
195  filler.resize(rphiHits.size());
196  std::copy(rphiHits.begin(), rphiHits.end(), filler.begin());
197  }
198  continue;
199  }
200 
201  SiStripRecHit2DCollection::const_iterator itStereoDet = output.stereo->find(partnerId);
202 
203  // if the partner is not found (which probably can happen if it's empty)
204  if (itStereoDet == edStereoDet) {
205  // I must copy these as unmatched
206  if (!rphiHits.empty()) {
207  SiStripRecHit2DCollection::FastFiller filler(*output.rphiUnmatched, rphiHits.detId());
208  filler.resize(rphiHits.size());
209  std::copy(rphiHits.begin(), rphiHits.end(), filler.begin());
210  }
211  continue;
212  }
213 
214  edmNew::DetSet<SiStripRecHit2D> stereoHits = *itStereoDet;
215 
216 
217  // Get ready for making glued hits
218  const GluedGeomDet* gluedDet = (const GluedGeomDet*)tracker->idToDet(DetId(specDetId.glued()));
220  Collector collector(*output.matched, specDetId.glued());
221 
222  // Prepare also the list for unmatched rphi hits
223  SiStripRecHit2DCollection::FastFiller fillerRphiUnm(*output.rphiUnmatched, rphiHits.detId());
224 
225  // a list of clusters used by the matched part of the stereo hits in this detector
226  matchedSteroClusters.clear(); // at the beginning, empty
227 
228 #ifdef DOUBLE_MATCH
229  CollectorHelper chelper(collector, collectorMatched,
230  fillerRphiUnm,
231  matchedSteroClusters
232  );
233  matcher->doubleMatch(rphiHits.begin(), rphiHits.end(),
234  stereoHits.begin(),stereoHits.end(),gluedDet,trackdirection,chelper);
235  nmatch+=chelper.nmatch;
236 #else
237  // Make simple collection of this (gp:FIXME: why do we need it?)
239  // gp:FIXME: use std::transform
240  stereoSimpleHits.reserve(stereoHits.size());
241  for (edmNew::DetSet<SiStripRecHit2D>::const_iterator it = stereoHits.begin(), ed = stereoHits.end(); it != ed; ++it) {
242  stereoSimpleHits.push_back(&*it);
243  }
244 
245  for (edmNew::DetSet<SiStripRecHit2D>::const_iterator it = rphiHits.begin(), ed = rphiHits.end(); it != ed; ++it) {
246  matcher->match(&(*it),stereoSimpleHits.begin(),stereoSimpleHits.end(),collectorMatched,gluedDet,trackdirection);
247  if (collectorMatched.size()>0){
248  nmatch+=collectorMatched.size();
250  edm = collectorMatched.end();
251  itm != edm;
252  ++itm) {
253  collector.push_back(*itm);
254  // mark the stereo hit cluster as used, so that the hit won't go in the unmatched stereo ones
255  matchedSteroClusters.push_back(itm->stereoClusterRef().key());
256  }
257  collectorMatched.clear();
258  } else {
259  // store a copy of this rphi hit as an unmatched rphi hit
260  fillerRphiUnm.push_back(*it);
261  }
262  }
263 
264 #endif
265 
266 
267  // discard matched hits if the collection is empty
268  if (collector.empty()) collector.abort();
269 
270  // discard unmatched rphi hits if there are none
271  if (fillerRphiUnm.empty()) fillerRphiUnm.abort();
272 
273  // now look for unmatched stereo hits
274  SiStripRecHit2DCollection::FastFiller fillerStereoUnm(*output.stereoUnmatched, stereoHits.detId());
275  std::sort(matchedSteroClusters.begin(), matchedSteroClusters.end());
276  for (edmNew::DetSet<SiStripRecHit2D>::const_iterator it = stereoHits.begin(), ed = stereoHits.end(); it != ed; ++it) {
277  if (!std::binary_search(matchedSteroClusters.begin(), matchedSteroClusters.end(), it->cluster().key())) {
278  fillerStereoUnm.push_back(*it);
279  }
280  }
281  if (fillerStereoUnm.empty()) fillerStereoUnm.abort();
282 
283 
284  }
285 
286  for (SiStripRecHit2DCollection::const_iterator itStereoDet = output.stereo->begin(); itStereoDet != edStereoDet; ++itStereoDet) {
287  edmNew::DetSet<SiStripRecHit2D> stereoHits = *itStereoDet;
288  StripSubdetector specDetId(stereoHits.detId());
289  uint32_t partnerId = specDetId.partnerDetId();
290  if (partnerId == 0) continue;
291  SiStripRecHit2DCollection::const_iterator itRPhiDet = output.rphi->find(partnerId);
292  if (itRPhiDet == edRPhiDet) {
293  if (!stereoHits.empty()) {
294  SiStripRecHit2DCollection::FastFiller filler(*output.stereoUnmatched, stereoHits.detId());
295  filler.resize(stereoHits.size());
296  std::copy(stereoHits.begin(), stereoHits.end(), filler.begin());
297  }
298  }
299  }
300 
301  edm::LogInfo("SiStripRecHitConverter")
302  << "found\n"
303  << nmatch
304  << " matched RecHits\n";
305 }
306 
308 fillBad128StripBlocks(const uint32_t detid, bool bad128StripBlocks[6] ) const
309 {
311  short badApvs = quality->getBadApvs(detid);
312  short badFibers = quality->getBadFibers(detid);
313  for (int j = 0; j < 6; j++) {
314  bad128StripBlocks[j] = (badApvs & (1 << j));
315  }
316  for (int j = 0; j < 3; j++) {
317  if (badFibers & (1 << j)) {
318  bad128StripBlocks[2*j+0] = true;
319  bad128StripBlocks[2*j+1] = true;
320  }
321  }
322  }
323 }
324 
325 inline
327 isMasked(const SiStripCluster &cluster, bool bad128StripBlocks[6]) const
328 {
330  if ( bad128StripBlocks[cluster.firstStrip() >> 7] ) {
331  if ( bad128StripBlocks[(cluster.firstStrip()+cluster.amplitudes().size()) >> 7] ||
332  bad128StripBlocks[static_cast<int32_t>(cluster.barycenter()-0.499999) >> 7] ) {
333  return true;
334  }
335  } else {
336  if ( bad128StripBlocks[(cluster.firstStrip()+cluster.amplitudes().size()) >> 7] &&
337  bad128StripBlocks[static_cast<int32_t>(cluster.barycenter()-0.499999) >> 7] ) {
338  return true;
339  }
340  }
341  }
342  return false;
343 }
344 
345 inline
347 useModule(const uint32_t id) const
348 {
349  const StripGeomDetUnit * stripdet=(const StripGeomDetUnit*)tracker->idToDetUnit(id);
350  if(stripdet==0) edm::LogWarning("SiStripRecHitConverter") << "Detid=" << id << " not found";
351  return stripdet!=0 && (!useQuality || quality->IsModuleUsable(id));
352 }
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)
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)
unsigned int det_id_type
Definition: DetSetNew.h:10
std::auto_ptr< SiStripRecHit2DCollection > rphiUnmatched
edm::ESHandle< SiStripRecHitMatcher > matcher
edm::ESHandle< TrackerGeometry > tracker
size_type size() const
Definition: OwnVector.h:248
uint16_t firstStrip() const
data_type const * const_iterator
Definition: DetSetNew.h:30
SiStripRecHitConverterAlgorithm(const edm::ParameterSet &)
void fillBad128StripBlocks(const uint32_t detid, bool bad128StripBlocks[6]) const
unsigned int partnerDetId() const
static std::string const input
Definition: EdmProvDump.cc:44
iterator begin()
Definition: OwnVector.h:228
bool empty() const
Definition: DetSetNew.h:89
void clear()
Definition: OwnVector.h:371
void match(products &output, LocalVector trackdirection) const
int j
Definition: DBlmapReader.cc:9
float barycenter() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::auto_ptr< SiStripRecHit2DCollection > stereoUnmatched
std::auto_ptr< SiStripRecHit2DCollection > rphi
tuple conf
Definition: dbtoconf.py:185
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
Definition: DetId.h:18
unsigned int stereo() const
stereo
iterator end()
Definition: OwnVector.h:233
std::vector< const SiStripRecHit2D * > SimpleHitCollection
const T & get() const
Definition: EventSetup.h:55
SiStripRecHit2DCollection::FastFiller Collector
id_type detId() const
Definition: DetSetNew.h:83
std::pair< LocalPoint, LocalError > LocalValues
iterator end()
Definition: DetSetNew.h:70
edm::ESHandle< StripClusterParameterEstimator > parameterestimator
size_type size() const
Definition: DetSetNew.h:86
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:67