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 24 of file FastLineRecognition.h.

Constructor & Destructor Documentation

◆ FastLineRecognition()

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

Definition at line 58 of file FastLineRecognition.cc.

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

◆ ~FastLineRecognition()

FastLineRecognition::~FastLineRecognition ( )

Definition at line 63 of file FastLineRecognition.cc.

63 {}

Member Function Documentation

◆ getGeomData()

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

expects raw detector id

Definition at line 67 of file FastLineRecognition.cc.

References HltBtagPostValidation_cff::c, ztail::d, geometryMap, l1ctLayer2EG_cff::id, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, FastLineRecognition::GeomData::s, and FastLineRecognition::GeomData::z.

Referenced by getPatterns().

67  {
68  // result already buffered?
69  map<unsigned int, GeomData>::iterator it = geometryMap.find(id);
70  if (it != geometryMap.end())
71  return it->second;
72 
73  // calculate it
74  const auto &d = geometry->localToGlobalDirection(id, CTPPSGeometry::Vector(0., 1., 0.));
75  DetGeomDesc::Translation c = geometry->sensor(TotemRPDetId(id))->translation();
76  GeomData gd;
77  gd.z = c.z();
78  gd.s = d.x() * c.x() + d.y() * c.y();
79 
80  geometryMap[id] = gd;
81 
82  return gd;
83 }
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
DetGeomDesc::Translation Vector
Definition: CTPPSGeometry.h:36
std::map< unsigned int, GeomData > geometryMap
map: raw detector id –> GeomData
d
Definition: ztail.py:151
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > Translation
Definition: DetGeomDesc.h:55

◆ getOneLine()

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

References a, funct::abs(), b, HltBtagPostValidation_cff::c, chw_a, chw_b, bsc_activity_cfg::clusters, relmon_rootfiles_spy::contents, ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets::if(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, dqmdumpme::k, LaserDQM_cfg::p1, SiStripOfflineCRack_cfg::p2, mps_fire::result, threshold, w(), w2, and testProducerWithPsetDescEmpty_cfi::z2.

Referenced by getPatterns().

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

◆ getPatterns()

void FastLineRecognition::getPatterns ( const edm::DetSetVector< TotemRPRecHit > &  input,
double  _z0,
double  threshold,
edm::DetSet< TotemRPUVPattern > &  patterns 
)

Definition at line 87 of file FastLineRecognition.cc.

References HltBtagPostValidation_cff::c, edm::DetSet< T >::clear(), hcalRecHitTable_cff::detId, getGeomData(), getOneLine(), h, input, AlCaHLTBitMon_ParallelJobs::p, topSingleLeptonDQM_PU_cfi::pattern, edm::DetSet< T >::push_back(), FastLineRecognition::GeomData::s, sigma0, edm::DetSet< T >::size(), threshold, w(), z, FastLineRecognition::GeomData::z, and z0.

Referenced by TotemRPUVPatternFinder::recognizeAndSelect().

90  {
91  // build collection of points in the global coordinate system
92  std::vector<Point> points;
93  for (auto &ds : input) {
94  unsigned int detId = ds.detId();
95 
96  for (auto &h : ds) {
97  const TotemRPRecHit *hit = &h;
98  const GeomData &gd = getGeomData(detId);
99 
100  double p = hit->position() + gd.s;
101  double z = gd.z - z0;
102  double w = sigma0 / hit->sigma();
103 
104  points.push_back(Point(detId, hit, p, z, w));
105  }
106  }
107 
108 #if CTPPS_DEBUG > 0
109  printf(">> FastLineRecognition::getPatterns(z0 = %E)\n", z0);
110  printf(">>>>>>>>>>>>>>>>>>>\n");
111 #endif
112 
113  // reset output
114  patterns.clear();
115 
116  Cluster c;
117  while (getOneLine(points, threshold, c)) {
118  // convert cluster to pattern and save it
120  pattern.setA(c.Saw / c.Sw);
121  pattern.setB(c.Sbw / c.Sw);
122  pattern.setW(c.weight);
123 
124 #if CTPPS_DEBUG > 0
125  printf("\tpoints of the selected cluster: %lu\n", c.contents.size());
126 #endif
127 
128  for (auto &pit : c.contents) {
129 #if CTPPS_DEBUG > 0
130  printf("\t\t%.1f\n", pit->z);
131 #endif
132  pattern.addHit(pit->detId, *(pit->hit));
133  }
134 
135  patterns.push_back(pattern);
136 
137 #if CTPPS_DEBUG > 0
138  unsigned int u_points_b = 0;
139  for (vector<Point>::iterator dit = points.begin(); dit != points.end(); ++dit)
140  if (dit->usable)
141  u_points_b++;
142  printf("\tusable points before: %u\n", u_points_b);
143 #endif
144 
145  // remove points belonging to the recognized line
146  for (vector<const Point *>::iterator hit = c.contents.begin(); hit != c.contents.end(); ++hit) {
147  for (vector<Point>::iterator dit = points.begin(); dit != points.end(); ++dit) {
148  //printf("\t\t1: %.2f, %p vs. 2: %.2f, %p\n", (*hit)->z, (*hit)->hit, dit->z, dit->hit);
149  if ((*hit)->hit == dit->hit) {
150  dit->usable = false;
151  //points.erase(dit);
152  break;
153  }
154  }
155  }
156 
157 #if CTPPS_DEBUG > 0
158  unsigned int u_points_a = 0;
159  for (vector<Point>::iterator dit = points.begin(); dit != points.end(); ++dit)
160  if (dit->usable)
161  u_points_a++;
162  printf("\tusable points after: %u\n", u_points_a);
163 #endif
164  }
165 
166 #if CTPPS_DEBUG > 0
167  printf("patterns at end: %lu\n", patterns.size());
168  printf("<<<<<<<<<<<<<<<<<<<\n");
169 #endif
170 }
void push_back(const T &t)
Definition: DetSet.h:66
T w() const
static std::string const input
Definition: EdmProvDump.cc:50
bool getOneLine(const std::vector< Point > &points, double threshold, Cluster &result)
double threshold
weight threshold for accepting pattern candidates (clusters)
double z0
"typical" z
math::XYZPoint Point
Reconstructed hit in TOTEM RP.
Definition: TotemRPRecHit.h:18
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
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
size_type size() const
Definition: DetSet.h:61

◆ resetGeometry()

void FastLineRecognition::resetGeometry ( const CTPPSGeometry _g)
inline

Definition at line 30 of file FastLineRecognition.h.

References geometryMap.

Referenced by TotemRPUVPatternFinder::produce().

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

Member Data Documentation

◆ chw_a

double FastLineRecognition::chw_a
private

cluster half widths in a and b

Definition at line 48 of file FastLineRecognition.h.

Referenced by getOneLine().

◆ chw_b

double FastLineRecognition::chw_b
private

Definition at line 48 of file FastLineRecognition.h.

Referenced by getOneLine().

◆ geometry

const CTPPSGeometry* FastLineRecognition::geometry
private

pointer to the geometry

Definition at line 54 of file FastLineRecognition.h.

◆ geometryMap

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

map: raw detector id –> GeomData

Definition at line 62 of file FastLineRecognition.h.

Referenced by getGeomData(), and resetGeometry().

◆ sigma0

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

the uncertainty of 1-hit cluster, in mm

Definition at line 42 of file FastLineRecognition.h.

Referenced by getPatterns().

◆ threshold

double FastLineRecognition::threshold
private

weight threshold for accepting pattern candidates (clusters)

Definition at line 51 of file FastLineRecognition.h.

Referenced by utils.StatisticalTest::get_status(), getOneLine(), and getPatterns().

◆ z0

double FastLineRecognition::z0
private

"typical" z

Definition at line 45 of file FastLineRecognition.h.

Referenced by getPatterns().