CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected 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 ()
 

Protected Member Functions

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

Protected 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 Protected 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 65 of file FastLineRecognition.cc.

65  :
66  chw_a(cw_a/2.), chw_b(cw_b/2.), geometry(nullptr)
67 {
68 }
double chw_a
cluster half widths in a and b
const CTPPSGeometry * geometry
pointer to the geometry
FastLineRecognition::~FastLineRecognition ( )

Definition at line 72 of file FastLineRecognition.cc.

73 {
74 }

Member Function Documentation

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

expects raw detector id

Definition at line 78 of file FastLineRecognition.cc.

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

Referenced by getPatterns().

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

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

Definition at line 192 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<().

194 {
195 #if CTPPS_DEBUG > 0
196  printf("\tFastLineRecognition::getOneLine\n");
197 #endif
198 
199  if (points.size() < 2)
200  return false;
201 
202  vector<Cluster> clusters;
203 
204  // go through all the combinations of measured points
205  for (vector<Point>::const_iterator it1 = points.begin(); it1 != points.end(); ++it1)
206  {
207  if (!it1->usable)
208  continue;
209 
210  for (vector<Point>::const_iterator it2 = it1; it2 != points.end(); ++it2)
211  {
212  if (!it2->usable)
213  continue;
214 
215  const double &z1 = it1->z;
216  const double &z2 = it2->z;
217 
218  if (z1 == z2)
219  continue;
220 
221  const double &p1 = it1->h;
222  const double &p2 = it2->h;
223 
224  const double &w1 = it1->w;
225  const double &w2 = it2->w;
226 
227  // calculate intersection
228  double a = (p2 - p1) / (z2 - z1);
229  double b = p1 - z1 * a;
230  double w = w1 + w2;
231 
232 #if CTPPS_DEBUG > 0
233  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);
234 #endif
235 
236  // add it to the appropriate cluster
237  bool newCluster = true;
238  for (unsigned int k = 0; k < clusters.size(); k++)
239  {
240  Cluster &c = clusters[k];
241  if (c.S1 < 1. || c.Sw <= 0.)
242  continue;
243 
244 #if CTPPS_DEBUG > 0
245  if (k < 10)
246  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,
247  chw_a, chw_b,
248  (std::abs(a - c.Saw/c.Sw) < chw_a), (std::abs(b - c.Sbw/c.Sw) < chw_b));
249 #endif
250 
251  if ((std::abs(a - c.Saw/c.Sw) < chw_a) && (std::abs(b - c.Sbw/c.Sw) < chw_b))
252  {
253  newCluster = false;
254  clusters[k].add(& (*it1), & (*it2), a, b, w);
255 #if CTPPS_DEBUG > 0
256  printf("\t\t\t\t--> cluster %u\n", k);
257 #endif
258  break;
259  }
260  }
261 
262  // make new cluster
263  if (newCluster)
264  {
265 #if CTPPS_DEBUG > 0
266  printf("\t\t\t\t--> new cluster %lu\n", clusters.size());
267 #endif
268  clusters.push_back(Cluster());
269  clusters.back().add(& (*it1), & (*it2), a, b, w);
270  }
271  }
272  }
273 
274 #if CTPPS_DEBUG > 0
275  printf("\t\tclusters: %lu\n", clusters.size());
276 #endif
277 
278  // find the cluster with highest weight
279  unsigned int mk = 0;
280  double mw = -1.;
281  for (unsigned int k = 0; k < clusters.size(); k++)
282  {
283  double w = 0;
284  for (vector<const Point *>::iterator it = clusters[k].contents.begin(); it != clusters[k].contents.end(); ++it)
285  w += (*it)->w;
286  clusters[k].weight = w;
287 
288  if (w > mw)
289  {
290  mw = w;
291  mk = k;
292  }
293  }
294 
295 #if CTPPS_DEBUG > 0
296  printf("\t\tmw = %.1f, mk = %u\n", mw, mk);
297 #endif
298 
299  // rerturn result
300  if (mw >= threshold)
301  {
302  result = clusters[mk];
303 
304  return true;
305  } else
306  return false;
307 }
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 99 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().

101 {
102  // build collection of points in the global coordinate system
103  std::vector<Point> points;
104  for (auto &ds : input)
105  {
106  unsigned int detId = ds.detId();
107 
108  for (auto &h : ds)
109  {
110  const TotemRPRecHit *hit = &h;
111  const GeomData &gd = getGeomData(detId);
112 
113  double p = hit->getPosition() + gd.s;
114  double z = gd.z - z0;
115  double w = sigma0 / hit->getSigma();
116 
117  points.push_back(Point(detId, hit, p, z, w));
118  }
119  }
120 
121 #if CTPPS_DEBUG > 0
122  printf(">> FastLineRecognition::getPatterns(z0 = %E)\n", z0);
123  printf(">>>>>>>>>>>>>>>>>>>\n");
124 #endif
125 
126  // reset output
127  patterns.clear();
128 
129  Cluster c;
130  while (getOneLine(points, threshold, c))
131  {
132  // convert cluster to pattern and save it
134  pattern.setA(c.Saw/c.Sw);
135  pattern.setB(c.Sbw/c.Sw);
136  pattern.setW(c.weight);
137 
138 #if CTPPS_DEBUG > 0
139  printf("\tpoints of the selected cluster: %lu\n", c.contents.size());
140 #endif
141 
142  for (auto &pit : c.contents)
143  {
144 #if CTPPS_DEBUG > 0
145  printf("\t\t%.1f\n", pit->z);
146 #endif
147  pattern.addHit(pit->detId, *(pit->hit));
148  }
149 
150  patterns.push_back(pattern);
151 
152 #if CTPPS_DEBUG > 0
153  unsigned int u_points_b = 0;
154  for (vector<Point>::iterator dit = points.begin(); dit != points.end(); ++dit)
155  if (dit->usable)
156  u_points_b++;
157  printf("\tusable points before: %u\n", u_points_b);
158 #endif
159 
160  // remove points belonging to the recognized line
161  for (vector<const Point *>::iterator hit = c.contents.begin(); hit != c.contents.end(); ++hit)
162  {
163  for (vector<Point>::iterator dit = points.begin(); dit != points.end(); ++dit)
164  {
165  //printf("\t\t1: %.2f, %p vs. 2: %.2f, %p\n", (*hit)->z, (*hit)->hit, dit->z, dit->hit);
166  if ((*hit)->hit == dit->hit)
167  {
168  dit->usable = false;
169  //points.erase(dit);
170  break;
171  }
172  }
173  }
174 
175 #if CTPPS_DEBUG > 0
176  unsigned int u_points_a = 0;
177  for (vector<Point>::iterator dit = points.begin(); dit != points.end(); ++dit)
178  if (dit->usable)
179  u_points_a++;
180  printf("\tusable points after: %u\n", u_points_a);
181 #endif
182  }
183 
184 #if CTPPS_DEBUG > 0
185  printf("patterns at end: %lu\n", patterns.size());
186  printf("<<<<<<<<<<<<<<<<<<<\n");
187 #endif
188 }
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:69
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
protected

cluster half widths in a and b

Definition at line 49 of file FastLineRecognition.h.

Referenced by getOneLine().

double FastLineRecognition::chw_b
protected

Definition at line 49 of file FastLineRecognition.h.

Referenced by getOneLine().

const CTPPSGeometry* FastLineRecognition::geometry
protected

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
protected

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.)
staticprotected

the uncertainty of 1-hit cluster, in mm

Definition at line 43 of file FastLineRecognition.h.

Referenced by getPatterns().

double FastLineRecognition::threshold
protected

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
protected

"typical" z

Definition at line 46 of file FastLineRecognition.h.

Referenced by getPatterns().