CMS 3D CMS Logo

FastLineRecognition.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of TOTEM offline software.
4 * Authors:
5 * Jan Kašpar (jan.kaspar@gmail.com)
6 *
7 ****************************************************************************/
8 
10 
12 
14 
15 #include <map>
16 #include <cmath>
17 #include <cstdio>
18 #include <algorithm>
19 
20 //#define CTPPS_DEBUG 1
21 
22 using namespace std;
23 using namespace edm;
24 
25 //----------------------------------------------------------------------------------------------------
26 
27 const double FastLineRecognition::sigma0 = 66E-3 / sqrt(12.);
28 
29 //----------------------------------------------------------------------------------------------------
30 
31 void FastLineRecognition::Cluster::add(const Point *p1, const Point *p2, double a, double b, double w) {
32  // which points to be added to contents?
33  bool add1 = true, add2 = true;
34  for (vector<const Point *>::const_iterator it = contents.begin(); it != contents.end() && (add1 || add2); ++it) {
35  if ((*it)->hit == p1->hit)
36  add1 = false;
37 
38  if ((*it)->hit == p2->hit)
39  add2 = false;
40  }
41 
42  // add the points
43  if (add1)
44  contents.push_back(p1);
45  if (add2)
46  contents.push_back(p2);
47 
48  // update sums
49  Saw += a * w;
50  Sbw += b * w;
51  Sw += w;
52  S1 += 1.;
53 }
54 
55 //----------------------------------------------------------------------------------------------------
56 //----------------------------------------------------------------------------------------------------
57 
58 FastLineRecognition::FastLineRecognition(double cw_a, double cw_b)
59  : chw_a(cw_a / 2.), chw_b(cw_b / 2.), geometry(nullptr) {}
60 
61 //----------------------------------------------------------------------------------------------------
62 
64 
65 //----------------------------------------------------------------------------------------------------
66 
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 }
84 
85 //----------------------------------------------------------------------------------------------------
86 
88  double z0,
89  double threshold,
90  DetSet<TotemRPUVPattern> &patterns) {
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 }
171 
172 //----------------------------------------------------------------------------------------------------
173 
174 bool FastLineRecognition::getOneLine(const vector<FastLineRecognition::Point> &points,
175  double threshold,
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 }
TotemRPRecHit
Reconstructed hit in TOTEM RP.
Definition: TotemRPRecHit.h:17
FastLineRecognition::sigma0
static const double sigma0
the uncertainty of 1-hit cluster, in mm
Definition: FastLineRecognition.h:46
edm::DetSet::push_back
void push_back(const T &t)
Definition: DetSet.h:66
edm::DetSetVector< TotemRPRecHit >
w2
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
FastLineRecognition::chw_a
double chw_a
cluster half widths in a and b
Definition: FastLineRecognition.h:52
input
static const std::string input
Definition: EdmProvDump.cc:48
edm::DetSet::size
size_type size() const
Definition: DetSet.h:61
HLT_FULL_cff.points
points
Definition: HLT_FULL_cff.py:21469
edm::DetSet
Definition: DetSet.h:23
edm::DetSet::clear
void clear()
Definition: DetSet.h:71
edm
HLT enums.
Definition: AlignableModifier.h:19
FastLineRecognition::z0
double z0
"typical" z
Definition: FastLineRecognition.h:49
geometry
Definition: geometry.py:1
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:58
FastLineRecognition::getGeomData
GeomData getGeomData(unsigned int id)
expects raw detector id
Definition: FastLineRecognition.cc:66
FastLineRecognition::~FastLineRecognition
~FastLineRecognition()
Definition: FastLineRecognition.cc:62
TotemRPRecHit.h
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
FastLineRecognition::threshold
double threshold
weight threshold for accepting pattern candidates (clusters)
Definition: FastLineRecognition.h:55
testProducerWithPsetDescEmpty_cfi.z2
z2
Definition: testProducerWithPsetDescEmpty_cfi.py:41
relmon_rootfiles_spy.contents
contents
Definition: relmon_rootfiles_spy.py:129
CTPPSGeometry.h
Point
math::XYZPoint Point
Definition: TrackerDpgAnalysis.cc:106
h
w
const double w
Definition: UKUtility.cc:23
FastLineRecognition::chw_b
double chw_b
Definition: FastLineRecognition.h:52
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DDAxes::z
FastLineRecognition::FastLineRecognition
FastLineRecognition(double cw_a=0., double cw_b=0.)
Definition: FastLineRecognition.cc:57
p2
double p2[4]
Definition: TauolaWrapper.h:90
HLTMuonOfflineAnalyzer_cfi.z0
z0
Definition: HLTMuonOfflineAnalyzer_cfi.py:98
dqmdumpme.k
k
Definition: dqmdumpme.py:60
b
double b
Definition: hdecay.h:118
FastLineRecognition::Cluster
cluster of intersection points
Definition: FastLineRecognition.h:83
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
FastLineRecognition::Point
Definition: FastLineRecognition.h:71
FastLineRecognition::GeomData::s
double s
sensor's centre projected to its read-out direction
Definition: FastLineRecognition.h:62
TotemRPUVPattern
A linear pattern in U or V projection. The intercept b is taken at the middle of a RP: (geometry->Get...
Definition: TotemRPUVPattern.h:22
a
double a
Definition: hdecay.h:119
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
FastLineRecognition::GeomData::z
double z
z position of a sensor (wrt. IP)
Definition: FastLineRecognition.h:61
FastLineRecognition::Cluster::add
void add(const Point *p1, const Point *p2, double a, double b, double w)
Definition: FastLineRecognition.cc:30
FastLineRecognition::geometryMap
std::map< unsigned int, GeomData > geometryMap
map: raw detector id --> GeomData
Definition: FastLineRecognition.h:66
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
FastLineRecognition::getPatterns
void getPatterns(const edm::DetSetVector< TotemRPRecHit > &input, double _z0, double threshold, edm::DetSet< TotemRPUVPattern > &patterns)
Definition: FastLineRecognition.cc:86
p1
double p1[4]
Definition: TauolaWrapper.h:89
FastLineRecognition.h
std
Definition: JetResolutionObject.h:76
DetGeomDesc::Translation
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > Translation
Definition: DetGeomDesc.h:54
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
ztail.d
d
Definition: ztail.py:151
mps_fire.result
result
Definition: mps_fire.py:311
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:430
FastLineRecognition::GeomData
Definition: FastLineRecognition.h:60
FastLineRecognition::getOneLine
bool getOneLine(const std::vector< Point > &points, double threshold, Cluster &result)
Definition: FastLineRecognition.cc:173
TotemRPDetId
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:29
hit
Definition: SiStripHitEffFromCalibTree.cc:88
CTPPSGeometry::Vector
DetGeomDesc::Translation Vector
Definition: CTPPSGeometry.h:39