CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TkStripMeasurementDet.cc
Go to the documentation of this file.
6 #include "StripClusterAboveU.h"
11 
12 #include <typeinfo>
13 // #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h"
16 
18  StMeasurementDetSet & dets
19  ) :
20  MeasurementDet (gdet),theDets_(&dets), index_(-1)
21  {
22  if (dynamic_cast<const StripGeomDetUnit*>(gdet) == 0) {
23  throw MeasurementDetException( "TkStripMeasurementDet constructed with a GeomDet which is not a StripGeomDetUnit");
24  }
25  }
26 
27 
28 std::vector<TrajectoryMeasurement>
31  const TrajectoryStateOnSurface& startingState,
32  const Propagator&,
33  const MeasurementEstimator& est) const
34 {
35  std::vector<TrajectoryMeasurement> result;
36 
37  if (!isActive()) {
38  LogDebug("TkStripMeasurementDet")<<" found an inactive module "<<rawId();
39  result.push_back( TrajectoryMeasurement( stateOnThisDet,
41  0.F));
42  return result;
43  }
44 
45  float utraj = specificGeomDet().specificTopology().measurementPosition( stateOnThisDet.localPosition()).x();
46  float uerr;
47  // if (theClusterRange.first == theClusterRange.second) { // empty
48  if (isEmpty()){
49  LogDebug("TkStripMeasurementDet") << " DetID " << rawId() << " empty ";
50  if (stateOnThisDet.hasError()){
51  uerr= sqrt(specificGeomDet().specificTopology().measurementError(stateOnThisDet.localPosition(),stateOnThisDet.localError().positionError()).uu());
52  if (testStrips(utraj,uerr)) {
54  } else {
56  }
57  }else{
59  }
60  return result;
61  }
62 
63  if(!isRegional()){//old implemetation with DetSet
64  auto rightCluster =
65  std::find_if( detSet().begin(), detSet().end(), StripClusterAboveU( utraj)); //FIXME
66 
67  if ( rightCluster != detSet().begin()) {
68  // there are hits on the left of the utraj
69  new_const_iterator leftCluster = rightCluster;
70  while ( --leftCluster >= detSet().begin()) {
71  if (isMasked(*leftCluster)) continue;
72  SiStripClusterRef clusterref = edmNew::makeRefTo( handle(), leftCluster );
73  if (accept(clusterref)){
74  RecHitContainer recHits = buildRecHits(clusterref,stateOnThisDet);
75  bool isCompatible(false);
76  for(RecHitContainer::const_iterator recHit=recHits.begin();recHit!=recHits.end();++recHit){
77  std::pair<bool,double> diffEst = est.estimate(stateOnThisDet, **recHit);
78  if ( diffEst.first ) {
79  result.push_back( TrajectoryMeasurement( stateOnThisDet, *recHit,
80  diffEst.second));
81  isCompatible = true;
82  }
83  }
84  if(!isCompatible) break; // exit loop on first incompatible hit
85  }
86  else LogDebug("TkStripMeasurementDet")<<"skipping this str from last iteration on"<<rawId()<<" key: "<<clusterref.key();
87  }
88  }
89 
90 
91  for ( ; rightCluster != detSet().end(); rightCluster++) {
92  if (isMasked(*rightCluster)) continue;
93  SiStripClusterRef clusterref = edmNew::makeRefTo( handle(), rightCluster );
94  if (accept(clusterref)){
95  RecHitContainer recHits = buildRecHits(clusterref,stateOnThisDet);
96  bool isCompatible(false);
97  for(RecHitContainer::const_iterator recHit=recHits.begin();recHit!=recHits.end();++recHit){
98  std::pair<bool,double> diffEst = est.estimate(stateOnThisDet, **recHit);
99  if ( diffEst.first ) {
100  result.push_back( TrajectoryMeasurement( stateOnThisDet, *recHit,
101  diffEst.second));
102  isCompatible = true;
103  }
104  }
105  if(!isCompatible) break; // exit loop on first incompatible hit
106  }
107  else LogDebug("TkStripMeasurementDet")<<"skipping this str from last iteration on" << rawId()<<" key: "<<clusterref.key();
108  }
109  }// end block with DetSet
110  else{
111  LogDebug("TkStripMeasurementDet")<<" finding left/ right";
112  result.reserve(size());
113  unsigned int rightCluster = beginClusterI();
114  for (; rightCluster!= endClusterI();++rightCluster){
116  if (clusterref->barycenter() > utraj) break;
117  }
118 
119  unsigned int leftCluster = 1;
120  for (unsigned int iReadBackWard=1; iReadBackWard<=(rightCluster-beginClusterI()) ; ++iReadBackWard){
121  leftCluster=rightCluster-iReadBackWard;
123  if (isMasked(*clusterref)) continue;
124  if (accept(clusterref)){
125  RecHitContainer recHits = buildRecHits(clusterref,stateOnThisDet);
126  bool isCompatible(false);
127  for(RecHitContainer::const_iterator recHit=recHits.begin();recHit!=recHits.end();++recHit){
128  std::pair<bool,double> diffEst = est.estimate(stateOnThisDet, **recHit);
129  if ( diffEst.first ) {
130  result.push_back( TrajectoryMeasurement( stateOnThisDet, *recHit,
131  diffEst.second));
132  isCompatible = true;
133  }
134  }
135  if(!isCompatible) break; // exit loop on first incompatible hit
136  }
137  else LogDebug("TkStripMeasurementDet")<<"skipping this reg str from last iteration on"<<rawId()<<" key: "<<clusterref.key();
138  }
139 
140 
141  for ( ; rightCluster != endClusterI(); ++rightCluster) {
143  if (isMasked(*clusterref)) continue;
144  if (accept(clusterref)){
145  RecHitContainer recHits = buildRecHits(clusterref,stateOnThisDet);
146  bool isCompatible(false);
147  for(RecHitContainer::const_iterator recHit=recHits.begin();recHit!=recHits.end();++recHit){
148  std::pair<bool,double> diffEst = est.estimate(stateOnThisDet, **recHit);
149  if ( diffEst.first ) {
150  result.push_back( TrajectoryMeasurement( stateOnThisDet, *recHit,
151  diffEst.second));
152  isCompatible = true;
153  }
154  }
155  if(!isCompatible) break; // exit loop on first incompatible hit
156  }
157  else LogDebug("TkStripMeasurementDet")<<"skipping this reg str from last iteration on"<<rawId()<<" key: "<<clusterref.key();
158  }
159  }
160 
161 
162  if ( result.empty()) {
163  // create a TrajectoryMeasurement with an invalid RecHit and zero estimate
164  if (stateOnThisDet.hasError()){
165  uerr= sqrt(specificGeomDet().specificTopology().measurementError(stateOnThisDet.localPosition(),stateOnThisDet.localError().positionError()).uu());
166  if (testStrips(utraj,uerr)) {
167  //LogDebug("TkStripMeasurementDet") << " DetID " << id_ << " empty after search, but active ";
168  result.push_back( TrajectoryMeasurement( stateOnThisDet, InvalidTransientRecHit::build(&fastGeomDet(), TrackingRecHit::missing), 0.F));
169  } else {
170  //LogDebug("TkStripMeasurementDet") << " DetID " << id_ << " empty after search, and inactive ";
172  }
173  }else{
174  result.push_back( TrajectoryMeasurement( stateOnThisDet, InvalidTransientRecHit::build(&fastGeomDet(), TrackingRecHit::missing), 0.F));
175  }
176  }
177  else {
178  //LogDebug("TkStripMeasurementDet") << " DetID " << id_ << " full: " << (result.size()) << " compatible hits";
179  // sort results according to estimator value
180  if ( result.size() > 1) {
181  std::sort( result.begin(), result.end(), TrajMeasLessEstim());
182  }
183  }
184  return result;
185 }
186 
187 
190  const TrajectoryStateOnSurface& ltp) const
191 {
192  const GeomDetUnit& gdu( specificGeomDet());
193  LocalValues lv = cpe()->localParameters( *cluster, gdu, ltp);
194  return TSiStripRecHit2DLocalPos::build( lv.first, lv.second, &fastGeomDet(), cluster, cpe());
195 }
196 
199  const TrajectoryStateOnSurface& ltp) const
200 {
201  const GeomDetUnit& gdu( specificGeomDet());
202  LocalValues lv = cpe()->localParameters( *cluster, gdu, ltp);
203  return TSiStripRecHit2DLocalPos::build( lv.first, lv.second, &fastGeomDet(), cluster, cpe());
204 }
205 
206 
207 
210  const TrajectoryStateOnSurface& ltp) const
211 {
212  const GeomDetUnit& gdu( specificGeomDet());
213  VLocalValues vlv = cpe()->localParametersV( *cluster, gdu, ltp);
214  RecHitContainer res;
215  for(VLocalValues::const_iterator it=vlv.begin();it!=vlv.end();++it){
216  res.push_back(TSiStripRecHit2DLocalPos::build( it->first, it->second, &fastGeomDet(), cluster, cpe()));
217  }
218  return res;
219 }
220 
221 
224  const TrajectoryStateOnSurface& ltp) const
225 {
226  const GeomDetUnit& gdu( specificGeomDet());
227  VLocalValues vlv = cpe()->localParametersV( *cluster, gdu, ltp);
228  RecHitContainer res;
229  for(VLocalValues::const_iterator it=vlv.begin();it!=vlv.end();++it){
230  res.push_back(TSiStripRecHit2DLocalPos::build( it->first, it->second, &fastGeomDet(), cluster, cpe()));
231  }
232  return res;
233 }
234 
235 
236 
239 {
241  if (isEmpty() == true) return result;
242  if (isActive() == false) return result; // GIO
243 
244  if(!isRegional()){//old implemetation with DetSet
245  result.reserve(detSet().size());
246  for ( new_const_iterator ci = detSet().begin(); ci != detSet().end(); ++ ci ) {
247  if (isMasked(*ci)) continue;
248  // for ( ClusterIterator ci=theClusterRange.first; ci != theClusterRange.second; ci++) {
249  SiStripClusterRef cluster = edmNew::makeRefTo( handle(), ci );
250  if (accept(cluster))
251  result.push_back( buildRecHit( cluster, ts));
252  else LogDebug("TkStripMeasurementDet")<<"skipping this str from last iteration on"<<rawId()<<" key: "<<cluster.key();
253  }
254  }else{
255  result.reserve(size());
256  for (unsigned int ci = beginClusterI() ; ci!= endClusterI();++ci){
258  if (isMasked(*clusterRef)) continue;
259  if (accept(clusterRef))
260  result.push_back( buildRecHit( clusterRef, ts));
261  else LogDebug("TkStripMeasurementDet")<<"skipping this reg str from last iteration on"<<rawId()<<" key: "<<clusterRef.key();
262  }
263  }
264  return result;
265 
266 }
267 
268 template<class ClusterRefT>
269 void
270 TkStripMeasurementDet::buildSimpleRecHit( const ClusterRefT& cluster,
271  const TrajectoryStateOnSurface& ltp,
272  std::vector<SiStripRecHit2D>& res ) const
273 {
274  const GeomDetUnit& gdu( specificGeomDet());
275  VLocalValues vlv = cpe()->localParametersV( *cluster, gdu, ltp);
276  for(VLocalValues::const_iterator it=vlv.begin();it!=vlv.end();++it){
277  res.push_back(SiStripRecHit2D( it->first, it->second, rawId(), cluster));
278  }
279 }
280 
281 
282 void
283 TkStripMeasurementDet::simpleRecHits( const TrajectoryStateOnSurface& ts, std::vector<SiStripRecHit2D> &result) const
284 {
285  if (isEmpty() || !isActive()) return;
286 
287  if(!isRegional()){//old implemetation with DetSet
288  result.reserve(detSet().size());
289  for ( new_const_iterator ci = detSet().begin(); ci != detSet().end(); ++ ci ) {
290  if (isMasked(*ci)) continue;
291  // for ( ClusterIterator ci=theClusterRange.first; ci != theClusterRange.second; ci++) {
292  SiStripClusterRef cluster = edmNew::makeRefTo( handle(), ci );
293  if (accept(cluster))
294  buildSimpleRecHit( cluster, ts,result);
295  else LogDebug("TkStripMeasurementDet")<<"skipping this str from last iteration on"<<rawId()<<" key: "<<cluster.key();
296  }
297  }else{
298  result.reserve(size());
299  for (unsigned int ci = beginClusterI() ; ci!= endClusterI();++ci){
301  if (isMasked(*clusterRef)) continue;
302  if (accept(clusterRef))
303  buildSimpleRecHit( clusterRef, ts,result);
304  else LogDebug("TkStripMeasurementDet")<<"skipping this reg str from last iteration on"<<rawId()<<" key: "<<clusterRef.key();
305  }
306  }
307 }
308 
309 
310 
311 bool
312 TkStripMeasurementDet::testStrips(float utraj, float uerr) const {
313  int16_t start = (int16_t) std::max<float>(utraj - 3.f*uerr, 0);
314  int16_t end = (int16_t) std::min<float>(utraj + 3.f*uerr, totalStrips());
315 
316  if (start >= end) { // which means either end <=0 or start >= totalStrips_
317  /* LogDebug("TkStripMeasurementDet") << "Testing module " << id_ <<","<<
318  " U = " << utraj << " +/- " << uerr <<
319  "; Range [" << (utraj - 3*uerr) << ", " << (utraj + 3*uerr) << "] " <<
320  ": YOU'RE COMPLETELY OFF THE MODULE."; */
321  //return false;
322  return true; // Wolfgang thinks this way is better
323  // and solves some problems with grouped ckf
324  }
325 
326  typedef std::vector<BadStripBlock>::const_iterator BSBIT;
327 
328  int16_t bad = 0, largestBadBlock = 0;
329  for (BSBIT bsbc = badStripBlocks().begin(), bsbe = badStripBlocks().end(); bsbc != bsbe; ++bsbc) {
330  if (bsbc->last < start) continue;
331  if (bsbc->first > end) break;
332  int16_t thisBad = std::min(bsbc->last, end) - std::max(bsbc->first, start);
333  if (thisBad > largestBadBlock) largestBadBlock = thisBad;
334  bad += thisBad;
335  }
336 
337  bool ok = (bad < (end-start)) &&
338  (uint16_t(bad) <= badStripCuts().maxBad) &&
339  (uint16_t(largestBadBlock) <= badStripCuts().maxConsecutiveBad);
340 
341 // if (bad) {
342 // edm::LogWarning("TkStripMeasurementDet") << "Testing module " << id_ <<" (subdet: "<< SiStripDetId(id_).subdetId() << ")" <<
343 // " U = " << utraj << " +/- " << uerr <<
344 // "; Range [" << (utraj - 3*uerr) << ", " << (utraj + 3*uerr) << "] " <<
345 // "= [" << start << "," << end << "]" <<
346 // " total strips:" << (end-start) << ", good:" << (end-start-bad) << ", bad:" << bad << ", largestBadBlock: " << largestBadBlock <<
347 // ". " << (ok ? "OK" : "NO");
348 // }
349  return ok;
350 }
351 
#define LogDebug(id)
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)
TkStripMeasurementDet(const GeomDet *gdet, StMeasurementDetSet &dets)
void buildSimpleRecHit(const ClusterRefT &cluster, const TrajectoryStateOnSurface &ltp, std::vector< SiStripRecHit2D > &res) const
edm::Handle< edmNew::DetSetVector< SiStripCluster > > const & handle() const
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TransientTrackingRecHit &hit) const =0
StripClusterParameterEstimator::VLocalValues VLocalValues
StripClusterParameterEstimator::LocalValues LocalValues
TransientTrackingRecHit::ConstRecHitContainer RecHitContainer
virtual const GeomDet & geomDet() const
BadStripCuts const & badStripCuts() const
#define min(a, b)
Definition: mlp_lapack.h:161
virtual RecHitContainer recHits(const TrajectoryStateOnSurface &) const
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
TransientTrackingRecHit::RecHitPointer buildRecHit(const SiStripClusterRef &, const TrajectoryStateOnSurface &ltp) const
LocalError positionError() const
bool isMasked(const SiStripCluster &cluster) const
int bad(Items const &cont)
const GeomDet & fastGeomDet() const
unsigned int beginClusterI() const
edm::Handle< edm::LazyGetter< SiStripCluster > > const & regionalHandle() const
virtual LocalValues localParameters(const T &, const GeomDetUnit &) const =0
virtual VLocalValues localParametersV(const T &cluster, const GeomDetUnit &gd) const
unsigned int endClusterI() const
virtual std::vector< TrajectoryMeasurement > fastMeasurements(const TrajectoryStateOnSurface &stateOnThisDet, const TrajectoryStateOnSurface &startingState, const Propagator &, const MeasurementEstimator &) const
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:46
std::vector< BadStripBlock > const & badStripBlocks() const
tuple result
Definition: query.py:137
Ref< LazyGetter< T >, T, FindValue< T > > makeRefToLazyGetter(const Handle< LazyGetter< T > > &handle, const uint32_t index)
Definition: LazyGetter.h:532
TkStripMeasurementDet::RecHitContainer buildRecHits(const SiStripClusterRef &, const TrajectoryStateOnSurface &ltp) const
double f[11][100]
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
#define end
Definition: vmac.h:38
const LocalTrajectoryError & localError() const
bool accept(SiStripClusterRef &r) const
key_type key() const
Accessor for product key.
Definition: Ref.h:266
const StripGeomDetUnit & specificGeomDet() const
const detset & detSet() const
const StripClusterParameterEstimator * cpe() const
SiStripRecHit2D::ClusterRef SiStripClusterRef
#define begin
Definition: vmac.h:31
iterator end()
Definition: DetSetNew.h:59
void simpleRecHits(const TrajectoryStateOnSurface &ts, std::vector< SiStripRecHit2D > &result) const
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.
bool isActive() const
Is this module active in reconstruction? It must be both &#39;setActiveThisEvent&#39; and &#39;setActive&#39;...
unsigned int rawId() const
Definition: DDAxes.h:10
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281