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