CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
FastLineRecognition Class Reference

Class performing optimized hough transform to recognize lines. More...

#include <FastLineRecognition.h>

Classes

struct  Cluster
 cluster of intersection points More...
 
struct  GeomData
 
struct  Point
 

Public Member Functions

 FastLineRecognition (double cw_a=0., double cw_b=0.)
 
void getPatterns (const edm::DetSetVector< TotemRPRecHit > &input, double _z0, double threshold, edm::DetSet< TotemRPUVPattern > &patterns)
 
void resetGeometry (const CTPPSGeometry *_g)
 
 ~FastLineRecognition ()
 

Private Member Functions

GeomData getGeomData (unsigned int id)
 expects raw detector id More...
 
bool getOneLine (const std::vector< Point > &points, double threshold, Cluster &result)
 

Private Attributes

double chw_a
 cluster half widths in a and b More...
 
double chw_b
 
const CTPPSGeometrygeometry
 pointer to the geometry More...
 
std::map< unsigned int, GeomDatageometryMap
 map: raw detector id –> GeomData More...
 
double threshold
 weight threshold for accepting pattern candidates (clusters) More...
 
double z0
 "typical" z More...
 

Static Private Attributes

static const double sigma0 = 66E-3/sqrt(12.)
 the uncertainty of 1-hit cluster, in mm More...
 

Detailed Description

Class performing optimized hough transform to recognize lines.

Definition at line 25 of file FastLineRecognition.h.

Constructor & Destructor Documentation

FastLineRecognition::FastLineRecognition ( double  cw_a = 0.,
double  cw_b = 0. 
)

Definition at line 60 of file FastLineRecognition.cc.

60  :
61  chw_a(cw_a/2.), chw_b(cw_b/2.), geometry(nullptr)
62 {
63 }
double chw_a
cluster half widths in a and b
const CTPPSGeometry * geometry
pointer to the geometry
FastLineRecognition::~FastLineRecognition ( )

Definition at line 67 of file FastLineRecognition.cc.

68 {
69 }

Member Function Documentation

FastLineRecognition::GeomData FastLineRecognition::getGeomData ( unsigned int  id)
private

expects raw detector id

Definition at line 73 of file FastLineRecognition.cc.

References EnergyCorrector::c, edmIntegrityCheck::d, geometryMap, triggerObjects_cff::id, FastLineRecognition::GeomData::s, and FastLineRecognition::GeomData::z.

Referenced by getPatterns().

74 {
75  // result already buffered?
76  map<unsigned int, GeomData>::iterator it = geometryMap.find(id);
77  if (it != geometryMap.end())
78  return it->second;
79 
80  // calculate it
81  CLHEP::Hep3Vector d = geometry->localToGlobalDirection(id, CLHEP::Hep3Vector(0., 1., 0.));
82  DetGeomDesc::Translation c = geometry->getSensor(TotemRPDetId(id))->translation();
83  GeomData gd;
84  gd.z = c.z();
85  gd.s = d.x()*c.x() + d.y()*c.y();
86 
87  geometryMap[id] = gd;
88 
89  return gd;
90 }
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >> Translation
Definition: DetGeomDesc.h:40
std::map< unsigned int, GeomData > geometryMap
map: raw detector id –> GeomData
bool FastLineRecognition::getOneLine ( const std::vector< Point > &  points,
double  threshold,
FastLineRecognition::Cluster result 
)
private

gets the most significant pattern in the (remaining) points returns true when a pattern was found

Definition at line 187 of file FastLineRecognition.cc.

References a, funct::abs(), b, EnergyCorrector::c, chw_a, chw_b, fastPrimaryVertexProducer_cfi::clusters, relmon_rootfiles_spy::contents, gen::k, p1, p2, FastLineRecognition::Cluster::S1, FastLineRecognition::Cluster::Saw, FastLineRecognition::Cluster::Sbw, FastLineRecognition::Cluster::Sw, w, and w2.

Referenced by getPatterns(), and FastLineRecognition::Cluster::operator<().

189 {
190 #if CTPPS_DEBUG > 0
191  printf("\tFastLineRecognition::getOneLine\n");
192 #endif
193 
194  if (points.size() < 2)
195  return false;
196 
197  vector<Cluster> clusters;
198 
199  // go through all the combinations of measured points
200  for (vector<Point>::const_iterator it1 = points.begin(); it1 != points.end(); ++it1)
201  {
202  if (!it1->usable)
203  continue;
204 
205  for (vector<Point>::const_iterator it2 = it1; it2 != points.end(); ++it2)
206  {
207  if (!it2->usable)
208  continue;
209 
210  const double &z1 = it1->z;
211  const double &z2 = it2->z;
212 
213  if (z1 == z2)
214  continue;
215 
216  const double &p1 = it1->h;
217  const double &p2 = it2->h;
218 
219  const double &w1 = it1->w;
220  const double &w2 = it2->w;
221 
222  // calculate intersection
223  double a = (p2 - p1) / (z2 - z1);
224  double b = p1 - z1 * a;
225  double w = w1 + w2;
226 
227 #if CTPPS_DEBUG > 0
228  printf("\t\t\tz: 1=%+5.1f, 2=%+5.1f | U/V: 1=%+6.3f, 2=%+6.3f | a=%+6.3f rad, b=%+6.3f mm, w=%.1f\n", z1, z2, p1, p2, a, b, w);
229 #endif
230 
231  // add it to the appropriate cluster
232  bool newCluster = true;
233  for (unsigned int k = 0; k < clusters.size(); k++)
234  {
235  Cluster &c = clusters[k];
236  if (c.S1 < 1. || c.Sw <= 0.)
237  continue;
238 
239 #if CTPPS_DEBUG > 0
240  if (k < 10)
241  printf("\t\t\t\ttest cluster %u at a=%+6.3f, b=%+6.3f : %+6.3f, %+6.3f : %i, %i\n", k, c.Saw/c.Sw, c.Sbw/c.Sw,
242  chw_a, chw_b,
243  (std::abs(a - c.Saw/c.Sw) < chw_a), (std::abs(b - c.Sbw/c.Sw) < chw_b));
244 #endif
245 
246  if ((std::abs(a - c.Saw/c.Sw) < chw_a) && (std::abs(b - c.Sbw/c.Sw) < chw_b))
247  {
248  newCluster = false;
249  clusters[k].add(& (*it1), & (*it2), a, b, w);
250 #if CTPPS_DEBUG > 0
251  printf("\t\t\t\t--> cluster %u\n", k);
252 #endif
253  break;
254  }
255  }
256 
257  // make new cluster
258  if (newCluster)
259  {
260 #if CTPPS_DEBUG > 0
261  printf("\t\t\t\t--> new cluster %lu\n", clusters.size());
262 #endif
263  clusters.push_back(Cluster());
264  clusters.back().add(& (*it1), & (*it2), a, b, w);
265  }
266  }
267  }
268 
269 #if CTPPS_DEBUG > 0
270  printf("\t\tclusters: %lu\n", clusters.size());
271 #endif
272 
273  // find the cluster with highest weight
274  unsigned int mk = 0;
275  double mw = -1.;
276  for (unsigned int k = 0; k < clusters.size(); k++)
277  {
278  double w = 0;
279  for (vector<const Point *>::iterator it = clusters[k].contents.begin(); it != clusters[k].contents.end(); ++it)
280  w += (*it)->w;
281  clusters[k].weight = w;
282 
283  if (w > mw)
284  {
285  mw = w;
286  mk = k;
287  }
288  }
289 
290 #if CTPPS_DEBUG > 0
291  printf("\t\tmw = %.1f, mk = %u\n", mw, mk);
292 #endif
293 
294  // rerturn result
295  if (mw >= threshold)
296  {
297  result = clusters[mk];
298 
299  return true;
300  } else
301  return false;
302 }
double chw_a
cluster half widths in a and b
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
const double w
Definition: UKUtility.cc:23
double threshold
weight threshold for accepting pattern candidates (clusters)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double p2[4]
Definition: TauolaWrapper.h:90
int k[5][pyjets_maxn]
double b
Definition: hdecay.h:120
double p1[4]
Definition: TauolaWrapper.h:89
double a
Definition: hdecay.h:121
void FastLineRecognition::getPatterns ( const edm::DetSetVector< TotemRPRecHit > &  input,
double  _z0,
double  threshold,
edm::DetSet< TotemRPUVPattern > &  patterns 
)

Definition at line 94 of file FastLineRecognition.cc.

References TotemRPUVPattern::addHit(), EnergyCorrector::c, edm::DetSet< T >::clear(), FastLineRecognition::Cluster::contents, getGeomData(), getOneLine(), TotemRPRecHit::getPosition(), TotemRPRecHit::getSigma(), h, AlCaHLTBitMon_ParallelJobs::p, listBenchmarks::pattern, hiPixelPairStep_cff::points, edm::DetSet< T >::push_back(), FastLineRecognition::GeomData::s, FastLineRecognition::Cluster::Saw, FastLineRecognition::Cluster::Sbw, TotemRPUVPattern::setA(), TotemRPUVPattern::setB(), TotemRPUVPattern::setW(), sigma0, edm::DetSet< T >::size(), FastLineRecognition::Cluster::Sw, w, FastLineRecognition::Cluster::weight, z, FastLineRecognition::GeomData::z, and z0.

Referenced by TotemRPUVPatternFinder::recognizeAndSelect(), and resetGeometry().

96 {
97  // build collection of points in the global coordinate system
98  std::vector<Point> points;
99  for (auto &ds : input)
100  {
101  unsigned int detId = ds.detId();
102 
103  for (auto &h : ds)
104  {
105  const TotemRPRecHit *hit = &h;
106  const GeomData &gd = getGeomData(detId);
107 
108  double p = hit->getPosition() + gd.s;
109  double z = gd.z - z0;
110  double w = sigma0 / hit->getSigma();
111 
112  points.push_back(Point(detId, hit, p, z, w));
113  }
114  }
115 
116 #if CTPPS_DEBUG > 0
117  printf(">> FastLineRecognition::getPatterns(z0 = %E)\n", z0);
118  printf(">>>>>>>>>>>>>>>>>>>\n");
119 #endif
120 
121  // reset output
122  patterns.clear();
123 
124  Cluster c;
125  while (getOneLine(points, threshold, c))
126  {
127  // convert cluster to pattern and save it
129  pattern.setA(c.Saw/c.Sw);
130  pattern.setB(c.Sbw/c.Sw);
131  pattern.setW(c.weight);
132 
133 #if CTPPS_DEBUG > 0
134  printf("\tpoints of the selected cluster: %lu\n", c.contents.size());
135 #endif
136 
137  for (auto &pit : c.contents)
138  {
139 #if CTPPS_DEBUG > 0
140  printf("\t\t%.1f\n", pit->z);
141 #endif
142  pattern.addHit(pit->detId, *(pit->hit));
143  }
144 
145  patterns.push_back(pattern);
146 
147 #if CTPPS_DEBUG > 0
148  unsigned int u_points_b = 0;
149  for (vector<Point>::iterator dit = points.begin(); dit != points.end(); ++dit)
150  if (dit->usable)
151  u_points_b++;
152  printf("\tusable points before: %u\n", u_points_b);
153 #endif
154 
155  // remove points belonging to the recognized line
156  for (vector<const Point *>::iterator hit = c.contents.begin(); hit != c.contents.end(); ++hit)
157  {
158  for (vector<Point>::iterator dit = points.begin(); dit != points.end(); ++dit)
159  {
160  //printf("\t\t1: %.2f, %p vs. 2: %.2f, %p\n", (*hit)->z, (*hit)->hit, dit->z, dit->hit);
161  if ((*hit)->hit == dit->hit)
162  {
163  dit->usable = false;
164  //points.erase(dit);
165  break;
166  }
167  }
168  }
169 
170 #if CTPPS_DEBUG > 0
171  unsigned int u_points_a = 0;
172  for (vector<Point>::iterator dit = points.begin(); dit != points.end(); ++dit)
173  if (dit->usable)
174  u_points_a++;
175  printf("\tusable points after: %u\n", u_points_a);
176 #endif
177  }
178 
179 #if CTPPS_DEBUG > 0
180  printf("patterns at end: %lu\n", patterns.size());
181  printf("<<<<<<<<<<<<<<<<<<<\n");
182 #endif
183 }
void addHit(edm::det_id_type detId, const TotemRPRecHit &hit)
void push_back(const T &t)
Definition: DetSet.h:68
double getSigma() const
Definition: TotemRPRecHit.h:28
const double w
Definition: UKUtility.cc:23
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::pair< double, double > Point
Definition: CaloEllipse.h:18
bool getOneLine(const std::vector< Point > &points, double threshold, Cluster &result)
size_type size() const
Definition: DetSet.h:63
double threshold
weight threshold for accepting pattern candidates (clusters)
double z0
"typical" z
Reconstructed hit in TOTEM RP.
Definition: TotemRPRecHit.h:18
void setW(double w_)
void setB(double b_)
A linear pattern in U or V projection. The intercept b is taken at the middle of a RP: (geometry->Get...
static const double sigma0
the uncertainty of 1-hit cluster, in mm
GeomData getGeomData(unsigned int id)
expects raw detector id
void clear()
Definition: DetSet.h:71
void setA(double a_)
double getPosition() const
Definition: TotemRPRecHit.h:25
void FastLineRecognition::resetGeometry ( const CTPPSGeometry _g)
inline

Definition at line 32 of file FastLineRecognition.h.

References geometryMap, getPatterns(), input, and threshold.

Referenced by TotemRPUVPatternFinder::produce().

33  {
34  geometry = _g;
35  geometryMap.clear();
36  }
std::map< unsigned int, GeomData > geometryMap
map: raw detector id –> GeomData

Member Data Documentation

double FastLineRecognition::chw_a
private

cluster half widths in a and b

Definition at line 49 of file FastLineRecognition.h.

Referenced by getOneLine().

double FastLineRecognition::chw_b
private

Definition at line 49 of file FastLineRecognition.h.

Referenced by getOneLine().

const CTPPSGeometry* FastLineRecognition::geometry
private

pointer to the geometry

Definition at line 55 of file FastLineRecognition.h.

Referenced by Vispa.Gui.ConnectableWidget.ConnectableWidget::leaveEvent().

std::map<unsigned int, GeomData> FastLineRecognition::geometryMap
private

map: raw detector id –> GeomData

Definition at line 64 of file FastLineRecognition.h.

Referenced by getGeomData(), and resetGeometry().

const double FastLineRecognition::sigma0 = 66E-3/sqrt(12.)
staticprivate

the uncertainty of 1-hit cluster, in mm

Definition at line 43 of file FastLineRecognition.h.

Referenced by getPatterns().

double FastLineRecognition::threshold
private

weight threshold for accepting pattern candidates (clusters)

Definition at line 52 of file FastLineRecognition.h.

Referenced by utils.StatisticalTest::get_status(), and resetGeometry().

double FastLineRecognition::z0
private

"typical" z

Definition at line 46 of file FastLineRecognition.h.

Referenced by getPatterns().