CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TkStripMeasurementDet.cc
Go to the documentation of this file.
10 
11 #include <typeinfo>
14 #include <cassert>
15 
17  : MeasurementDet(gdet), index_(-1), theDetConditions(&conditions) {
18  if (dynamic_cast<const StripGeomDetUnit*>(gdet) == nullptr) {
19  throw MeasurementDetException("TkStripMeasurementDet constructed with a GeomDet which is not a StripGeomDetUnit");
20  }
21 }
22 
23 // fast check if the det contains any useful cluster
25  if UNLIKELY ((!isActive(data)) || isEmpty(data.stripData()))
26  return true;
27 
28  const detset& detSet = data.stripData().detSet(index());
29  for (auto ci = detSet.begin(); ci != detSet.end(); ++ci) {
30  if (isMasked(*ci))
31  continue;
32  SiStripClusterRef cluster = detSet.makeRefTo(data.stripData().handle(), ci);
33  if (accept(cluster, data.stripClustersToSkip()))
34  return false;
35  }
36  return true;
37 }
38 
40  const MeasurementTrackerEvent& data) const {
42  if UNLIKELY ((!isActive(data)) || isEmpty(data.stripData()))
43  return result;
44  const detset& detSet = data.stripData().detSet(index());
45  result.reserve(detSet.size());
46  for (new_const_iterator ci = detSet.begin(); ci != detSet.end(); ++ci) {
47  if (isMasked(*ci))
48  continue;
49  // for ( ClusterIterator ci=theClusterRange.first; ci != theClusterRange.second; ci++) {
50  SiStripClusterRef cluster = detSet.makeRefTo(data.stripData().handle(), ci);
51  if (accept(cluster, data.stripClustersToSkip()))
52  result.push_back(buildRecHit(cluster, ts));
53  else
54  LogDebug("TkStripMeasurementDet") << "skipping this str from last iteration on" << rawId()
55  << " key: " << cluster.key();
56  }
57  return result;
58 }
59 
60 // FIXME need to be merged with simpleRecHits
62  const TrajectoryStateOnSurface& stateOnThisDet,
63  const MeasurementEstimator& est,
64  const MeasurementTrackerEvent& data) const {
65  if UNLIKELY ((!isActive(data)) || isEmpty(data.stripData()))
66  return false;
67  auto oldSize = result.size();
68 
69  int utraj = specificGeomDet().specificTopology().measurementPosition(stateOnThisDet.localPosition()).x();
70  const detset& detSet = data.stripData().detSet(index());
71  auto const& cpepar = cpe()->getAlgoParam(specificGeomDet(), stateOnThisDet.localParameters());
72 
73  auto rightCluster = std::find_if(
74  detSet.begin(), detSet.end(), [utraj](const SiStripCluster& hit) { return hit.firstStrip() > utraj; });
75 
76  std::vector<SiStripRecHit2D> tmp;
77  if (rightCluster != detSet.begin()) {
78  // there are hits on the left of the utraj
79  auto leftCluster = rightCluster;
80  while (--leftCluster >= detSet.begin()) {
81  SiStripClusterRef clusterref = detSet.makeRefTo(data.stripData().handle(), leftCluster);
82  bool isCompatible = filteredRecHits(clusterref, cpepar, stateOnThisDet, est, data.stripClustersToSkip(), tmp);
83  if (!isCompatible)
84  break; // exit loop on first incompatible hit
85  for (auto&& h : tmp)
86  result.push_back(new SiStripRecHit2D(h));
87  tmp.clear();
88  }
89  }
90  for (; rightCluster != detSet.end(); rightCluster++) {
91  SiStripClusterRef clusterref = detSet.makeRefTo(data.stripData().handle(), rightCluster);
92  bool isCompatible = filteredRecHits(clusterref, cpepar, stateOnThisDet, est, data.stripClustersToSkip(), tmp);
93  if (!isCompatible)
94  break; // exit loop on first incompatible hit
95  for (auto&& h : tmp)
96  result.push_back(new SiStripRecHit2D(h));
97  tmp.clear();
98  }
99 
100  return result.size() > oldSize;
101 }
102 
104  const MeasurementEstimator& est,
106  std::vector<SiStripRecHit2D>& result) const {
107  if UNLIKELY ((!isActive(data)) || isEmpty(data.stripData()))
108  return false;
109 
110  auto oldSize = result.size();
111 
112  int utraj = specificGeomDet().specificTopology().measurementPosition(stateOnThisDet.localPosition()).x();
113  const detset& detSet = data.stripData().detSet(index());
114  auto const& cpepar = cpe()->getAlgoParam(specificGeomDet(), stateOnThisDet.localParameters());
115 
116  auto rightCluster = std::find_if(
117  detSet.begin(), detSet.end(), [utraj](const SiStripCluster& hit) { return hit.firstStrip() > utraj; });
118 
119  if (rightCluster != detSet.begin()) {
120  // there are hits on the left of the utraj
121  auto leftCluster = rightCluster;
122  while (--leftCluster >= detSet.begin()) {
123  SiStripClusterRef clusterref = detSet.makeRefTo(data.stripData().handle(), leftCluster);
124  bool isCompatible = filteredRecHits(clusterref, cpepar, stateOnThisDet, est, data.stripClustersToSkip(), result);
125  if (!isCompatible)
126  break; // exit loop on first incompatible hit
127  }
128  }
129  for (; rightCluster != detSet.end(); rightCluster++) {
130  SiStripClusterRef clusterref = detSet.makeRefTo(data.stripData().handle(), rightCluster);
131  bool isCompatible = filteredRecHits(clusterref, cpepar, stateOnThisDet, est, data.stripClustersToSkip(), result);
132  if (!isCompatible)
133  break; // exit loop on first incompatible hit
134  }
135 
136  return result.size() > oldSize;
137 }
138 
140  const MeasurementEstimator& est,
143  std::vector<float>& diffs) const {
144  if UNLIKELY ((!isActive(data)) || isEmpty(data.stripData()))
145  return false;
146 
147  auto oldSize = result.size();
148  auto const& cpepar = cpe()->getAlgoParam(specificGeomDet(), stateOnThisDet.localParameters());
149 
150  int utraj = specificGeomDet().specificTopology().measurementPosition(stateOnThisDet.localPosition()).x();
151 
152  const detset& detSet = data.stripData().detSet(index());
153  auto rightCluster = std::find_if(
154  detSet.begin(), detSet.end(), [utraj](const SiStripCluster& hit) { return hit.firstStrip() > utraj; });
155 
156  if (rightCluster != detSet.begin()) {
157  // there are hits on the left of the utraj
158  auto leftCluster = rightCluster;
159  while (--leftCluster >= detSet.begin()) {
160  SiStripClusterRef clusterref = detSet.makeRefTo(data.stripData().handle(), leftCluster);
161  bool isCompatible =
162  filteredRecHits(clusterref, cpepar, stateOnThisDet, est, data.stripClustersToSkip(), result, diffs);
163  if (!isCompatible)
164  break; // exit loop on first incompatible hit
165  }
166  }
167  for (; rightCluster != detSet.end(); rightCluster++) {
168  SiStripClusterRef clusterref = detSet.makeRefTo(data.stripData().handle(), rightCluster);
169  bool isCompatible =
170  filteredRecHits(clusterref, cpepar, stateOnThisDet, est, data.stripClustersToSkip(), result, diffs);
171  if (!isCompatible)
172  break; // exit loop on first incompatible hit
173  }
174 
175  return result.size() > oldSize;
176 }
177 
179  const MeasurementEstimator& est,
181  TempMeasurements& result) const {
182  if (!isActive(data)) {
183  LogDebug("TkStripMeasurementDet") << " found an inactive module " << rawId();
184  result.add(theInactiveHit, 0.F);
185  return true;
186  }
187 
188  if (!isEmpty(data.stripData())) {
189  LogDebug("TkStripMeasurementDet") << " found hit on this module " << rawId();
191  std::vector<float> diffs;
192  if (recHits(stateOnThisDet, est, data, result.hits, result.distances))
193  return true;
194  }
195 
196  // create a TrajectoryMeasurement with an invalid RecHit and zero estimate
197 
198  if (!stateOnThisDet.hasError()) {
199  result.add(theMissingHit, 0.F);
200  return false;
201  }
202 
203  float utraj = specificGeomDet().specificTopology().measurementPosition(stateOnThisDet.localPosition()).x();
204  float uerr = sqrt(specificGeomDet()
205  .specificTopology()
206  .measurementError(stateOnThisDet.localPosition(), stateOnThisDet.localError().positionError())
207  .uu());
208  if (testStrips(utraj, uerr)) {
209  //LogDebug("TkStripMeasurementDet") << " DetID " << id_ << " empty after search, but active ";
210  result.add(theMissingHit, 0.F);
211  return false;
212  }
213 
214  //LogDebug("TkStripMeasurementDet") << " DetID " << id_ << " empty after search, and inactive ";
215  result.add(theInactiveHit, 0.F);
216  return true;
217 }
218 
221  std::vector<SiStripRecHit2D>& result) const {
222  if (isEmpty(data.stripData()) || !isActive(data))
223  return;
224 
225  const detset& detSet = data.stripData().detSet(index());
227  assert(clusters.empty());
228  for (auto const& ci : detSet) {
229  if (isMasked(ci))
230  continue;
231  if (accept(detSet.makeKeyOf(&ci), data.stripClustersToSkip()))
232  clusters.push_back(&ci);
233  else
234  LogDebug("TkStripMeasurementDet") << "skipping this str from last iteration on" << rawId()
235  << " key: " << detSet.makeKeyOf(&ci);
236  }
237  if (!clusters.empty())
238  buildSimpleRecHits(clusters, data, detSet, ts, result);
239 }
240 
241 std::tuple<TkStripRecHitIter, TkStripRecHitIter> TkStripMeasurementDet::hitRange(
242  const TrajectoryStateOnSurface& ts, const MeasurementTrackerEvent& data) const {
243  if (isEmpty(data.stripData()) || !isActive(data))
244  return std::tuple<TkStripRecHitIter, TkStripRecHitIter>();
245  const detset& detSet = data.stripData().detSet(index());
246  return std::make_tuple(TkStripRecHitIter(detSet.begin(), detSet.end(), *this, ts, data),
247  TkStripRecHitIter(detSet.end(), detSet.end(), *this, ts, data));
248 }
249 
251  while (!hi.empty()) {
252  auto ci = hi.clusterI;
253  auto const& data = *hi.data;
254  if (isMasked(*ci))
255  continue;
256  SiStripClusterRef cluster = edmNew::makeRefTo(data.stripData().handle(), ci);
257  if (accept(cluster, data.stripClustersToSkip()))
258  return;
259  ++hi.clusterI;
260  }
261 }
262 
264  const GeomDetUnit& gdu(specificGeomDet());
265  auto ci = hi.clusterI;
266  auto const& data = *hi.data;
267  auto const& ltp = *hi.tsos;
268 
269  SiStripClusterRef cluster = edmNew::makeRefTo(data.stripData().handle(), ci);
270  LocalValues lv = cpe()->localParameters(*cluster, gdu, ltp);
271  return SiStripRecHit2D(lv.first, lv.second, gdu, cluster);
272 }
273 
274 bool TkStripMeasurementDet::testStrips(float utraj, float uerr) const {
275  int16_t start = (int16_t)std::max<float>(utraj - 3.f * uerr, 0);
276  int16_t end = (int16_t)std::min<float>(utraj + 3.f * uerr, totalStrips());
277 
278  if (start >= end) { // which means either end <=0 or start >= totalStrips_
279  /* LogDebug("TkStripMeasurementDet") << "Testing module " << id_ <<","<<
280  " U = " << utraj << " +/- " << uerr <<
281  "; Range [" << (utraj - 3*uerr) << ", " << (utraj + 3*uerr) << "] " <<
282  ": YOU'RE COMPLETELY OFF THE MODULE."; */
283  //return false;
284  return true; // Wolfgang thinks this way is better
285  // and solves some problems with grouped ckf
286  }
287 
288  typedef std::vector<BadStripBlock>::const_iterator BSBIT;
289 
290  int16_t bad = 0, largestBadBlock = 0;
291  for (BSBIT bsbc = badStripBlocks().begin(), bsbe = badStripBlocks().end(); bsbc != bsbe; ++bsbc) {
292  if (bsbc->last < start)
293  continue;
294  if (bsbc->first > end)
295  break;
296  int16_t thisBad = std::min(bsbc->last, end) - std::max(bsbc->first, start);
297  if (thisBad > largestBadBlock)
298  largestBadBlock = thisBad;
299  bad += thisBad;
300  }
301 
302  bool ok = (bad < (end - start)) && (uint16_t(bad) <= badStripCuts().maxBad) &&
303  (uint16_t(largestBadBlock) <= badStripCuts().maxConsecutiveBad);
304 
305  // if (bad) {
306  // edm::LogWarning("TkStripMeasurementDet") << "Testing module " << id_ <<" (subdet: "<< SiStripDetId(id_).subdetId() << ")" <<
307  // " U = " << utraj << " +/- " << uerr <<
308  // "; Range [" << (utraj - 3*uerr) << ", " << (utraj + 3*uerr) << "] " <<
309  // "= [" << start << "," << end << "]" <<
310  // " total strips:" << (end-start) << ", good:" << (end-start-bad) << ", bad:" << bad << ", largestBadBlock: " << largestBadBlock <<
311  // ". " << (ok ? "OK" : "NO");
312  // }
313  return ok;
314 }
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)
bool filteredRecHits(const ClusterRefT &cluster, StripCPE::AlgoParam const &cpepar, const TrajectoryStateOnSurface &ltp, const MeasurementEstimator &est, const std::vector< bool > &skipClusters, RecHitContainer &result, std::vector< float > &diffs) const
bool isActive(const MeasurementTrackerEvent &data) const override
Is this module active in reconstruction? It must be both &#39;setActiveThisEvent&#39; and &#39;setActive&#39;...
const StripDetset & detSet(int i) const
const TrajectoryStateOnSurface * tsos
const LocalTrajectoryParameters & localParameters() const
std::tuple< TkStripRecHitIter, TkStripRecHitIter > hitRange(const TrajectoryStateOnSurface &, const MeasurementTrackerEvent &data) const
bool empty(const MeasurementTrackerEvent &data) const
StripClusterParameterEstimator::LocalValues LocalValues
TkStripMeasurementDet(const GeomDet *gdet, StMeasurementConditionSet &conditionSet)
BadStripCuts const & badStripCuts() const
void simpleRecHits(const TrajectoryStateOnSurface &ts, const MeasurementTrackerEvent &data, std::vector< SiStripRecHit2D > &result) const
RecHitContainer recHits(const TrajectoryStateOnSurface &, const MeasurementTrackerEvent &data) const override
key_type key() const
Accessor for product key.
Definition: Ref.h:250
bool accept(SiStripClusterRef const &r, const std::vector< bool > &skipClusters) const
const StMeasurementDetSet & stripData() const
assert(be >=bs)
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
const std::vector< bool > & stripClustersToSkip() const
LocalError positionError() const
bool measurements(const TrajectoryStateOnSurface &stateOnThisDet, const MeasurementEstimator &est, const MeasurementTrackerEvent &data, TempMeasurements &result) const override
bool isMasked(const SiStripCluster &cluster) const
SiStripRecHit2D hit(TkStripRecHitIter const &hi) const
tuple result
Definition: mps_fire.py:311
TrackingRecHit::ConstRecHitPointer theMissingHit
const MeasurementTrackerEvent * data
const StripCPE * cpe() const
T sqrt(T t)
Definition: SSEVec.h:19
void add(ConstRecHitPointer const &h, float d)
std::vector< BadStripBlock > const & badStripBlocks() const
#define unInitDynArray(T, n, x)
Definition: DynArray.h:88
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
T min(T a, T b)
Definition: MathUtil.h:58
const LocalTrajectoryError & localError() const
AlgoParam getAlgoParam(const GeomDetUnit &det, const LocalTrajectoryParameters &ltp) const
Definition: StripCPE.h:57
void advance(TkStripRecHitIter &hi) const
StripClusterParameterEstimator::LocalValues localParameters(const SiStripCluster &cl, const GeomDetUnit &) const override
Definition: StripCPE.cc:62
TrackingRecHit::RecHitPointer buildRecHit(const ClusterRefT &cluster, const TrajectoryStateOnSurface &ltp) const
TrackingRecHit::ConstRecHitPointer theInactiveHit
T value_type
Definition: DynArray.h:12
const StripGeomDetUnit & specificGeomDet() const
bool isEmpty(const StMeasurementDetSet &theDets) const
new_const_iterator clusterI
TrackingRecHit::ConstRecHitContainer RecHitContainer
const detset & detSet(const StMeasurementDetSet &theDets) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
iterator end()
Definition: DetSetNew.h:56
detset::const_iterator new_const_iterator
bool testStrips(float utraj, float uerr) const
return true if there are &#39;enough&#39; good strips in the utraj +/- 3 uerr range.
string end
Definition: dataset.py:937
unsigned int rawId() const
void buildSimpleRecHits(AClusters const &clusters, const MeasurementTrackerEvent &data, const detset &detSet, const TrajectoryStateOnSurface &ltp, std::vector< SiStripRecHit2D > &res) const
std::vector< BaseTrackerRecHit * > SimpleHitContainer
edm::Handle< edmNew::DetSetVector< SiStripCluster > > & handle()
#define UNLIKELY(x)
Definition: Likely.h:21
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(HandleT const &handle, const_iterator ci) const
Definition: DetSetNew.h:73
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
size_type size() const
Definition: DetSetNew.h:68
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
tmp
align.sh
Definition: createJobs.py:716
#define LogDebug(id)
iterator begin()
Definition: DetSetNew.h:54