CMS 3D CMS Logo

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