CMS 3D CMS Logo

SiStripRecHitMatcher.cc
Go to the documentation of this file.
1 // File: SiStripRecHitMatcher.cc
2 // Description: Matches into rechits
3 // Author: C.Genta
9 
11 #include <functional>
12 
14 
16  : scale_(conf.getParameter<double>("NSigmaInside")),
17  preFilter_(conf.existsAs<bool>("PreFilter") ? conf.getParameter<bool>("PreFilter") : false) {}
18 
19 SiStripRecHitMatcher::SiStripRecHitMatcher(const double theScale) : scale_(theScale) {}
20 
21 namespace {
22  // FIXME for c++0X
23  inline void pb1(std::vector<SiStripMatchedRecHit2D*>& v, SiStripMatchedRecHit2D* h) { v.push_back(h); }
24  inline void pb2(SiStripRecHitMatcher::CollectorMatched& v, const SiStripMatchedRecHit2D& h) { v.push_back(h); }
25 
26 } // namespace
27 
28 // needed by the obsolete version still in use on some architectures
30  SimpleHitIterator begin,
32  std::vector<std::unique_ptr<SiStripMatchedRecHit2D>>& collector,
33  const GluedGeomDet* gluedDet,
34  LocalVector trackdirection) const {
35  std::vector<SiStripMatchedRecHit2D*> result;
36  result.reserve(end - begin);
37  match(monoRH, begin, end, result, gluedDet, trackdirection);
38  for (std::vector<SiStripMatchedRecHit2D*>::iterator p = result.begin(); p != result.end(); p++)
39  collector.emplace_back(*p);
40 }
41 
43  SimpleHitIterator begin,
45  std::vector<SiStripMatchedRecHit2D*>& collector,
46  const GluedGeomDet* gluedDet,
47  LocalVector trackdirection) const {
49  std::bind(&pb1, std::ref(collector), std::bind(&SiStripMatchedRecHit2D::clone, std::placeholders::_1)));
50  match(monoRH, begin, end, result, gluedDet, trackdirection);
51 }
52 
54  SimpleHitIterator begin,
56  CollectorMatched& collector,
57  const GluedGeomDet* gluedDet,
58  LocalVector trackdirection) const {
59  Collector result(std::bind(pb2, std::ref(collector), std::placeholders::_1));
60  match(monoRH, begin, end, result, gluedDet, trackdirection);
61 }
62 
63 // this is the one used by the RecHitConverter
65  RecHitIterator begin,
67  CollectorMatched& collector,
68  const GluedGeomDet* gluedDet,
69  LocalVector trackdirection) const {
70  // is this really needed now????
71  SimpleHitCollection stereoHits;
72  stereoHits.reserve(end - begin);
73  for (RecHitIterator i = begin; i != end; ++i)
74  stereoHits.push_back(&(*i)); // convert to simple pointer
75 
76  return match(monoRH, stereoHits.begin(), stereoHits.end(), collector, gluedDet, trackdirection);
77 }
78 
79 // the "real implementation"
81  SimpleHitIterator begin,
83  Collector& collector,
84  const GluedGeomDet* gluedDet,
85  LocalVector trackdirection) const {
86  // stripdet = mono
87  // partnerstripdet = stereo
88  const GeomDetUnit* stripdet = gluedDet->monoDet();
89  const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
90  const StripTopology& topol = (const StripTopology&)stripdet->topology();
91 
92  // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
93  double RPHIpointX = topol.measurementPosition(monoRH->localPositionFast()).x();
94  MeasurementPoint RPHIpointini(RPHIpointX, -0.5);
95  MeasurementPoint RPHIpointend(RPHIpointX, 0.5);
96 
97  // position of the initial and final point of the strip in local coordinates (mono det)
98  StripPosition stripmono = StripPosition(topol.localPosition(RPHIpointini), topol.localPosition(RPHIpointend));
99 
100  // in case of no track hypothesis assume a track from the origin through the center of the strip
101  if (trackdirection.mag2() < FLT_MIN) {
102  const LocalPoint& lcenterofstrip = monoRH->localPositionFast();
103  GlobalPoint gcenterofstrip = (stripdet->surface()).toGlobal(lcenterofstrip);
104  GlobalVector gtrackdirection = gcenterofstrip - GlobalPoint(0, 0, 0);
105  trackdirection = (gluedDet->surface()).toLocal(gtrackdirection);
106  }
107 
108  //project mono hit on glued det
109  StripPosition projectedstripmono = project(stripdet, gluedDet, stripmono, trackdirection);
110  const StripTopology& partnertopol = (const StripTopology&)partnerstripdet->topology();
111 
112  double m00 = -(projectedstripmono.second.y() - projectedstripmono.first.y());
113  double m01 = (projectedstripmono.second.x() - projectedstripmono.first.x());
114  double c0 = m01 * projectedstripmono.first.y() + m00 * projectedstripmono.first.x();
115 
116  //error calculation (the part that depends on mono RH only)
117  // LocalVector RPHIpositiononGluedendvector=projectedstripmono.second-projectedstripmono.first;
118  /*
119  double l1 = 1./RPHIpositiononGluedendvector.perp2();
120  double c1 = RPHIpositiononGluedendvector.y();
121  double s1 =-RPHIpositiononGluedendvector.x();
122  */
123  double c1 = -m00;
124  double s1 = -m01;
125  double l1 = 1. / (c1 * c1 + s1 * s1);
126 
127  double sigmap12 = sigmaPitch(monoRH->localPosition(), monoRH->localPositionError(), topol);
128  // auto sigmap12 = monoRH->sigmaPitch();
129  // assert(sigmap12>=0);
130 
131  SimpleHitIterator seconditer;
132 
133  for (seconditer = begin; seconditer != end; ++seconditer) { //iterate on stereo rechits
134 
135  // position of the initial and final point of the strip (STEREO cluster)
136  double STEREOpointX = partnertopol.measurementPosition((*seconditer)->localPositionFast()).x();
137  MeasurementPoint STEREOpointini(STEREOpointX, -0.5);
138  MeasurementPoint STEREOpointend(STEREOpointX, 0.5);
139 
140  // position of the initial and final point of the strip in local coordinates (stereo det)
141  StripPosition stripstereo(partnertopol.localPosition(STEREOpointini), partnertopol.localPosition(STEREOpointend));
142 
143  //project stereo hit on glued det
144  StripPosition projectedstripstereo = project(partnerstripdet, gluedDet, stripstereo, trackdirection);
145 
146  double m10 = -(projectedstripstereo.second.y() - projectedstripstereo.first.y());
147  double m11 = (projectedstripstereo.second.x() - projectedstripstereo.first.x());
148 
149  //perform the matching
150  //(x2-x1)(y-y1)=(y2-y1)(x-x1)
152  AlgebraicVector2 c; // FIXME understand why moving this initializer out of the loop changes the output!
153  m(0, 0) = m00;
154  m(0, 1) = m01;
155  m(1, 0) = m10;
156  m(1, 1) = m11;
157  c(0) = c0;
158  c(1) = m11 * projectedstripstereo.first.y() + m10 * projectedstripstereo.first.x();
159  m.Invert();
160  AlgebraicVector2 solution = m * c;
161  LocalPoint position(solution(0), solution(1));
162 
163  /*
164  {
165  double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y());
166  double m01 = (projectedstripmono.second.x()-projectedstripmono.first.x());
167  double m10 = -(projectedstripstereo.second.y()-projectedstripstereo.first.y());
168  double m11 = (projectedstripstereo.second.x()-projectedstripstereo.first.x());
169  double c0 = m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
170  double c1 = m11*projectedstripstereo.first.y() + m10*projectedstripstereo.first.x();
171 
172  double invDet = 1./(m00*m11-m10*m01);
173  }
174  */
175 
176  //
177  // temporary fix by tommaso
178  //
179 
180  LocalError tempError(100, 0, 100);
181  if (!((gluedDet->surface()).bounds().inside(position, tempError, scale_)))
182  continue;
183 
184  // then calculate the error
185  /*
186  LocalVector stereopositiononGluedendvector=projectedstripstereo.second-projectedstripstereo.first;
187  double l2 = 1./stereopositiononGluedendvector.perp2();
188  double c2 = stereopositiononGluedendvector.y();
189  double s2 =-stereopositiononGluedendvector.x();
190  */
191 
192  double c2 = -m10;
193  double s2 = -m11;
194  double l2 = 1. / (c2 * c2 + s2 * s2);
195 
196  double sigmap22 = sigmaPitch((*seconditer)->localPosition(), (*seconditer)->localPositionError(), partnertopol);
197  // auto sigmap22 = (*seconditer)->sigmaPitch();
198  // assert(sigmap22>=0);
199 
200  double diff = (c1 * s2 - c2 * s1);
201  double invdet2 = 1 / (diff * diff * l1 * l2);
202  float xx = invdet2 * (sigmap12 * s2 * s2 * l2 + sigmap22 * s1 * s1 * l1);
203  float xy = -invdet2 * (sigmap12 * c2 * s2 * l2 + sigmap22 * c1 * s1 * l1);
204  float yy = invdet2 * (sigmap12 * c2 * c2 * l2 + sigmap22 * c1 * c1 * l1);
205  LocalError error(xx, xy, yy);
206 
207  if ((gluedDet->surface()).bounds().inside(position, error, scale_)) { //if it is inside the gluedet bonds
208  //Change NSigmaInside in the configuration file to accept more hits
209  //...and add it to the Rechit collection
210 
211  const SiStripRecHit2D* secondHit = *seconditer;
212  collector(SiStripMatchedRecHit2D(position, error, *gluedDet, monoRH, secondHit));
213  }
214  }
215 }
216 
218  const GluedGeomDet* glueddet,
220  LocalVector trackdirection) const {
221  GlobalPoint globalpointini = (det->surface()).toGlobal(strip.first);
222  GlobalPoint globalpointend = (det->surface()).toGlobal(strip.second);
223 
224  // position of the initial and final point of the strip in glued local coordinates
225  LocalPoint positiononGluedini = (glueddet->surface()).toLocal(globalpointini);
226  LocalPoint positiononGluedend = (glueddet->surface()).toLocal(globalpointend);
227 
228  //correct the position with the track direction
229 
230  float scale = -positiononGluedini.z() / trackdirection.z();
231 
232  LocalPoint projpositiononGluedini = positiononGluedini + scale * trackdirection;
233  LocalPoint projpositiononGluedend = positiononGluedend + scale * trackdirection;
234 
235  return StripPosition(projpositiononGluedini, projpositiononGluedend);
236 }
237 
238 //match a single hit
239 std::unique_ptr<SiStripMatchedRecHit2D> SiStripRecHitMatcher::match(const SiStripRecHit2D* monoRH,
240  const SiStripRecHit2D* stereoRH,
241  const GluedGeomDet* gluedDet,
242  LocalVector trackdirection,
243  bool force) const {
244  // stripdet = mono
245  // partnerstripdet = stereo
246  const GeomDetUnit* stripdet = gluedDet->monoDet();
247  const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
248  const StripTopology& topol = (const StripTopology&)stripdet->topology();
249 
250  // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
251  auto RPHIpointX = topol.measurementPosition(monoRH->localPositionFast()).x();
252  MeasurementPoint RPHIpointini(RPHIpointX, -0.5f);
253  MeasurementPoint RPHIpointend(RPHIpointX, 0.5f);
254 
255  // position of the initial and final point of the strip in local coordinates (mono det)
256  StripPosition stripmono = StripPosition(topol.localPosition(RPHIpointini), topol.localPosition(RPHIpointend));
257 
258  // in case of no track hypothesis assume a track from the origin through the center of the strip
259  if (trackdirection.mag2() < FLT_MIN) {
260  const LocalPoint& lcenterofstrip = monoRH->localPositionFast();
261  GlobalPoint gcenterofstrip = (stripdet->surface()).toGlobal(lcenterofstrip);
262  GlobalVector gtrackdirection = gcenterofstrip - GlobalPoint(0, 0, 0);
263  trackdirection = (gluedDet->surface()).toLocal(gtrackdirection);
264  }
265 
266  //project mono hit on glued det
267  StripPosition projectedstripmono = project(stripdet, gluedDet, stripmono, trackdirection);
268  const StripTopology& partnertopol = (const StripTopology&)partnerstripdet->topology();
269 
270  double m00 = -(projectedstripmono.second.y() - projectedstripmono.first.y());
271  double m01 = (projectedstripmono.second.x() - projectedstripmono.first.x());
272  double c0 = m01 * projectedstripmono.first.y() + m00 * projectedstripmono.first.x();
273 
274  //error calculation (the part that depends on mono RH only)
275  // LocalVector RPHIpositiononGluedendvector=projectedstripmono.second-projectedstripmono.first;
276  /*
277  double l1 = 1./RPHIpositiononGluedendvector.perp2();
278  double c1 = RPHIpositiononGluedendvector.y();
279  double s1 =-RPHIpositiononGluedendvector.x();
280  */
281  double c1 = -m00;
282  double s1 = -m01;
283  double l1 = 1. / (c1 * c1 + s1 * s1);
284 
285  double sigmap12 = sigmaPitch(monoRH->localPosition(), monoRH->localPositionError(), topol);
286  // auto sigmap12 = monoRH->sigmaPitch();
287  // assert(sigmap12>=0);
288 
289  // position of the initial and final point of the strip (STEREO cluster)
290  auto STEREOpointX = partnertopol.measurementPosition(stereoRH->localPositionFast()).x();
291  MeasurementPoint STEREOpointini(STEREOpointX, -0.5f);
292  MeasurementPoint STEREOpointend(STEREOpointX, 0.5f);
293 
294  // position of the initial and final point of the strip in local coordinates (stereo det)
295  StripPosition stripstereo(partnertopol.localPosition(STEREOpointini), partnertopol.localPosition(STEREOpointend));
296 
297  //project stereo hit on glued det
298  StripPosition projectedstripstereo = project(partnerstripdet, gluedDet, stripstereo, trackdirection);
299 
300  double m10 = -(projectedstripstereo.second.y() - projectedstripstereo.first.y());
301  double m11 = (projectedstripstereo.second.x() - projectedstripstereo.first.x());
302 
303  //perform the matching
304  //(x2-x1)(y-y1)=(y2-y1)(x-x1)
305  AlgebraicMatrix22 m(ROOT::Math::SMatrixNoInit{});
306  AlgebraicVector2 c(c0, m11 * projectedstripstereo.first.y() + m10 * projectedstripstereo.first.x());
307  m(0, 0) = m00;
308  m(0, 1) = m01;
309  m(1, 0) = m10;
310  m(1, 1) = m11;
311  m.Invert();
312  AlgebraicVector2 solution = m * c;
313  Local2DPoint position(solution(0), solution(1));
314 
315  if ((!force) && (!((gluedDet->surface()).bounds().inside(position, 10.f * scale_))))
316  return std::unique_ptr<SiStripMatchedRecHit2D>(nullptr);
317 
318  double c2 = -m10;
319  double s2 = -m11;
320  double l2 = 1. / (c2 * c2 + s2 * s2);
321 
322  double sigmap22 = sigmaPitch(stereoRH->localPosition(), stereoRH->localPositionError(), partnertopol);
323  // auto sigmap22 = stereoRH->sigmaPitch();
324  // assert (sigmap22>0);
325 
326  double diff = (c1 * s2 - c2 * s1);
327  double invdet2 = 1 / (diff * diff * l1 * l2);
328  float xx = invdet2 * (sigmap12 * s2 * s2 * l2 + sigmap22 * s1 * s1 * l1);
329  float xy = -invdet2 * (sigmap12 * c2 * s2 * l2 + sigmap22 * c1 * s1 * l1);
330  float yy = invdet2 * (sigmap12 * c2 * c2 * l2 + sigmap22 * c1 * c1 * l1);
331  LocalError error(xx, xy, yy);
332 
333  //if it is inside the gluedet bonds
334  //Change NSigmaInside in the configuration file to accept more hits
335  if (force || (gluedDet->surface()).bounds().inside(position, error, scale_))
336  return std::make_unique<SiStripMatchedRecHit2D>(LocalPoint(position), error, *gluedDet, monoRH, stereoRH);
337  return std::unique_ptr<SiStripMatchedRecHit2D>(nullptr);
338 }
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
T z() const
Definition: PV3DBase.h:61
virtual const Topology & topology() const
Definition: GeomDet.cc:67
std::unique_ptr< SiStripMatchedRecHit2D > match(const SiStripRecHit2D *monoRH, const SiStripRecHit2D *stereoRH, const GluedGeomDet *gluedDet, LocalVector trackdirection, bool force) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::function< void(SiStripMatchedRecHit2D const &)> Collector
std::pair< LocalPoint, LocalPoint > StripPosition
static float sigmaPitch(LocalPoint const &pos, LocalError const &err, const StripTopology &topol)
T mag2() const
Definition: PV3DBase.h:63
ROOT::Math::SVector< double, 2 > AlgebraicVector2
SiStripMatchedRecHit2D * clone() const override
SiStripRecHitMatcher(const edm::ParameterSet &conf)
double f[11][100]
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
const LocalPoint & localPositionFast() const
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:19
LocalError localPositionError() const override
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
std::vector< const SiStripRecHit2D * > SimpleHitCollection
SiStripRecHit2DCollectionNew::DetSet::const_iterator RecHitIterator
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:20
SimpleHitCollection::const_iterator SimpleHitIterator
LocalPoint localPosition() const override
static int position[264][3]
Definition: ReadPGInfo.cc:289
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepStd< double, 2, 2 > > AlgebraicMatrix22
virtual LocalPoint localPosition(float strip) const =0
StripPosition project(const GeomDetUnit *det, const GluedGeomDet *glueddet, StripPosition strip, LocalVector trackdirection) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4