File indexing completed on 2024-04-06 12:26:29
0001
0002
0003
0004 #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
0005 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0006 #include "Geometry/CommonDetUnit/interface/GluedGeomDet.h"
0007 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0008 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
0009
0010 #include "TrackingTools/TransientTrackingRecHit/interface/HelpertRecHit2DLocalPos.h"
0011 #include <functional>
0012
0013 #include <DataFormats/GeometryCommonDetAlgo/interface/AlignmentPositionError.h>
0014
0015 SiStripRecHitMatcher::SiStripRecHitMatcher(const edm::ParameterSet& conf)
0016 : scale_(conf.getParameter<double>("NSigmaInside")),
0017 preFilter_(conf.existsAs<bool>("PreFilter") ? conf.getParameter<bool>("PreFilter") : false) {}
0018
0019 SiStripRecHitMatcher::SiStripRecHitMatcher(const double theScale) : scale_(theScale) {}
0020
0021 namespace {
0022
0023 inline void pb1(std::vector<SiStripMatchedRecHit2D*>& v, SiStripMatchedRecHit2D* h) { v.push_back(h); }
0024 inline void pb2(SiStripRecHitMatcher::CollectorMatched& v, const SiStripMatchedRecHit2D& h) { v.push_back(h); }
0025
0026 }
0027
0028
0029 void SiStripRecHitMatcher::match(const SiStripRecHit2D* monoRH,
0030 SimpleHitIterator begin,
0031 SimpleHitIterator end,
0032 std::vector<std::unique_ptr<SiStripMatchedRecHit2D>>& collector,
0033 const GluedGeomDet* gluedDet,
0034 LocalVector trackdirection) const {
0035 std::vector<SiStripMatchedRecHit2D*> result;
0036 result.reserve(end - begin);
0037 match(monoRH, begin, end, result, gluedDet, trackdirection);
0038 for (std::vector<SiStripMatchedRecHit2D*>::iterator p = result.begin(); p != result.end(); p++)
0039 collector.emplace_back(*p);
0040 }
0041
0042 void SiStripRecHitMatcher::match(const SiStripRecHit2D* monoRH,
0043 SimpleHitIterator begin,
0044 SimpleHitIterator end,
0045 std::vector<SiStripMatchedRecHit2D*>& collector,
0046 const GluedGeomDet* gluedDet,
0047 LocalVector trackdirection) const {
0048 Collector result(
0049 std::bind(&pb1, std::ref(collector), std::bind(&SiStripMatchedRecHit2D::clone, std::placeholders::_1)));
0050 match(monoRH, begin, end, result, gluedDet, trackdirection);
0051 }
0052
0053 void SiStripRecHitMatcher::match(const SiStripRecHit2D* monoRH,
0054 SimpleHitIterator begin,
0055 SimpleHitIterator end,
0056 CollectorMatched& collector,
0057 const GluedGeomDet* gluedDet,
0058 LocalVector trackdirection) const {
0059 Collector result(std::bind(pb2, std::ref(collector), std::placeholders::_1));
0060 match(monoRH, begin, end, result, gluedDet, trackdirection);
0061 }
0062
0063
0064 void SiStripRecHitMatcher::match(const SiStripRecHit2D* monoRH,
0065 RecHitIterator begin,
0066 RecHitIterator end,
0067 CollectorMatched& collector,
0068 const GluedGeomDet* gluedDet,
0069 LocalVector trackdirection) const {
0070
0071 SimpleHitCollection stereoHits;
0072 stereoHits.reserve(end - begin);
0073 for (RecHitIterator i = begin; i != end; ++i)
0074 stereoHits.push_back(&(*i));
0075
0076 return match(monoRH, stereoHits.begin(), stereoHits.end(), collector, gluedDet, trackdirection);
0077 }
0078
0079
0080 void SiStripRecHitMatcher::match(const SiStripRecHit2D* monoRH,
0081 SimpleHitIterator begin,
0082 SimpleHitIterator end,
0083 Collector& collector,
0084 const GluedGeomDet* gluedDet,
0085 LocalVector trackdirection) const {
0086
0087
0088 const GeomDetUnit* stripdet = gluedDet->monoDet();
0089 const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
0090 const StripTopology& topol = (const StripTopology&)stripdet->topology();
0091
0092
0093 double RPHIpointX = topol.measurementPosition(monoRH->localPositionFast()).x();
0094 MeasurementPoint RPHIpointini(RPHIpointX, -0.5);
0095 MeasurementPoint RPHIpointend(RPHIpointX, 0.5);
0096
0097
0098 StripPosition stripmono = StripPosition(topol.localPosition(RPHIpointini), topol.localPosition(RPHIpointend));
0099
0100
0101 if (trackdirection.mag2() < FLT_MIN) {
0102 const LocalPoint& lcenterofstrip = monoRH->localPositionFast();
0103 GlobalPoint gcenterofstrip = (stripdet->surface()).toGlobal(lcenterofstrip);
0104 GlobalVector gtrackdirection = gcenterofstrip - GlobalPoint(0, 0, 0);
0105 trackdirection = (gluedDet->surface()).toLocal(gtrackdirection);
0106 }
0107
0108
0109 StripPosition projectedstripmono = project(stripdet, gluedDet, stripmono, trackdirection);
0110 const StripTopology& partnertopol = (const StripTopology&)partnerstripdet->topology();
0111
0112 double m00 = -(projectedstripmono.second.y() - projectedstripmono.first.y());
0113 double m01 = (projectedstripmono.second.x() - projectedstripmono.first.x());
0114 double c0 = m01 * projectedstripmono.first.y() + m00 * projectedstripmono.first.x();
0115
0116
0117
0118
0119
0120
0121
0122
0123 double c1 = -m00;
0124 double s1 = -m01;
0125 double l1 = 1. / (c1 * c1 + s1 * s1);
0126
0127 double sigmap12 = sigmaPitch(monoRH->localPosition(), monoRH->localPositionError(), topol);
0128
0129
0130
0131 SimpleHitIterator seconditer;
0132
0133 for (seconditer = begin; seconditer != end; ++seconditer) {
0134
0135
0136 double STEREOpointX = partnertopol.measurementPosition((*seconditer)->localPositionFast()).x();
0137 MeasurementPoint STEREOpointini(STEREOpointX, -0.5);
0138 MeasurementPoint STEREOpointend(STEREOpointX, 0.5);
0139
0140
0141 StripPosition stripstereo(partnertopol.localPosition(STEREOpointini), partnertopol.localPosition(STEREOpointend));
0142
0143
0144 StripPosition projectedstripstereo = project(partnerstripdet, gluedDet, stripstereo, trackdirection);
0145
0146 double m10 = -(projectedstripstereo.second.y() - projectedstripstereo.first.y());
0147 double m11 = (projectedstripstereo.second.x() - projectedstripstereo.first.x());
0148
0149
0150
0151 AlgebraicMatrix22 m;
0152 AlgebraicVector2 c;
0153 m(0, 0) = m00;
0154 m(0, 1) = m01;
0155 m(1, 0) = m10;
0156 m(1, 1) = m11;
0157 c(0) = c0;
0158 c(1) = m11 * projectedstripstereo.first.y() + m10 * projectedstripstereo.first.x();
0159 m.Invert();
0160 AlgebraicVector2 solution = m * c;
0161 LocalPoint position(solution(0), solution(1));
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180 LocalError tempError(100, 0, 100);
0181 if (!((gluedDet->surface()).bounds().inside(position, tempError, scale_)))
0182 continue;
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192 double c2 = -m10;
0193 double s2 = -m11;
0194 double l2 = 1. / (c2 * c2 + s2 * s2);
0195
0196 double sigmap22 = sigmaPitch((*seconditer)->localPosition(), (*seconditer)->localPositionError(), partnertopol);
0197
0198
0199
0200 double diff = (c1 * s2 - c2 * s1);
0201 double invdet2 = 1 / (diff * diff * l1 * l2);
0202 float xx = invdet2 * (sigmap12 * s2 * s2 * l2 + sigmap22 * s1 * s1 * l1);
0203 float xy = -invdet2 * (sigmap12 * c2 * s2 * l2 + sigmap22 * c1 * s1 * l1);
0204 float yy = invdet2 * (sigmap12 * c2 * c2 * l2 + sigmap22 * c1 * c1 * l1);
0205 LocalError error(xx, xy, yy);
0206
0207 if ((gluedDet->surface()).bounds().inside(position, error, scale_)) {
0208
0209
0210
0211 const SiStripRecHit2D* secondHit = *seconditer;
0212 collector(SiStripMatchedRecHit2D(position, error, *gluedDet, monoRH, secondHit));
0213 }
0214 }
0215 }
0216
0217 SiStripRecHitMatcher::StripPosition SiStripRecHitMatcher::project(const GeomDetUnit* det,
0218 const GluedGeomDet* glueddet,
0219 StripPosition strip,
0220 LocalVector trackdirection) const {
0221 GlobalPoint globalpointini = (det->surface()).toGlobal(strip.first);
0222 GlobalPoint globalpointend = (det->surface()).toGlobal(strip.second);
0223
0224
0225 LocalPoint positiononGluedini = (glueddet->surface()).toLocal(globalpointini);
0226 LocalPoint positiononGluedend = (glueddet->surface()).toLocal(globalpointend);
0227
0228
0229
0230 float scale = -positiononGluedini.z() / trackdirection.z();
0231
0232 LocalPoint projpositiononGluedini = positiononGluedini + scale * trackdirection;
0233 LocalPoint projpositiononGluedend = positiononGluedend + scale * trackdirection;
0234
0235 return StripPosition(projpositiononGluedini, projpositiononGluedend);
0236 }
0237
0238
0239 std::unique_ptr<SiStripMatchedRecHit2D> SiStripRecHitMatcher::match(const SiStripRecHit2D* monoRH,
0240 const SiStripRecHit2D* stereoRH,
0241 const GluedGeomDet* gluedDet,
0242 LocalVector trackdirection,
0243 bool force) const {
0244
0245
0246 const GeomDetUnit* stripdet = gluedDet->monoDet();
0247 const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
0248 const StripTopology& topol = (const StripTopology&)stripdet->topology();
0249
0250
0251 auto RPHIpointX = topol.measurementPosition(monoRH->localPositionFast()).x();
0252 MeasurementPoint RPHIpointini(RPHIpointX, -0.5f);
0253 MeasurementPoint RPHIpointend(RPHIpointX, 0.5f);
0254
0255
0256 StripPosition stripmono = StripPosition(topol.localPosition(RPHIpointini), topol.localPosition(RPHIpointend));
0257
0258
0259 if (trackdirection.mag2() < FLT_MIN) {
0260 const LocalPoint& lcenterofstrip = monoRH->localPositionFast();
0261 GlobalPoint gcenterofstrip = (stripdet->surface()).toGlobal(lcenterofstrip);
0262 GlobalVector gtrackdirection = gcenterofstrip - GlobalPoint(0, 0, 0);
0263 trackdirection = (gluedDet->surface()).toLocal(gtrackdirection);
0264 }
0265
0266
0267 StripPosition projectedstripmono = project(stripdet, gluedDet, stripmono, trackdirection);
0268 const StripTopology& partnertopol = (const StripTopology&)partnerstripdet->topology();
0269
0270 double m00 = -(projectedstripmono.second.y() - projectedstripmono.first.y());
0271 double m01 = (projectedstripmono.second.x() - projectedstripmono.first.x());
0272 double c0 = m01 * projectedstripmono.first.y() + m00 * projectedstripmono.first.x();
0273
0274
0275
0276
0277
0278
0279
0280
0281 double c1 = -m00;
0282 double s1 = -m01;
0283 double l1 = 1. / (c1 * c1 + s1 * s1);
0284
0285 double sigmap12 = sigmaPitch(monoRH->localPosition(), monoRH->localPositionError(), topol);
0286
0287
0288
0289
0290 auto STEREOpointX = partnertopol.measurementPosition(stereoRH->localPositionFast()).x();
0291 MeasurementPoint STEREOpointini(STEREOpointX, -0.5f);
0292 MeasurementPoint STEREOpointend(STEREOpointX, 0.5f);
0293
0294
0295 StripPosition stripstereo(partnertopol.localPosition(STEREOpointini), partnertopol.localPosition(STEREOpointend));
0296
0297
0298 StripPosition projectedstripstereo = project(partnerstripdet, gluedDet, stripstereo, trackdirection);
0299
0300 double m10 = -(projectedstripstereo.second.y() - projectedstripstereo.first.y());
0301 double m11 = (projectedstripstereo.second.x() - projectedstripstereo.first.x());
0302
0303
0304
0305 AlgebraicMatrix22 m(ROOT::Math::SMatrixNoInit{});
0306 AlgebraicVector2 c(c0, m11 * projectedstripstereo.first.y() + m10 * projectedstripstereo.first.x());
0307 m(0, 0) = m00;
0308 m(0, 1) = m01;
0309 m(1, 0) = m10;
0310 m(1, 1) = m11;
0311 m.Invert();
0312 AlgebraicVector2 solution = m * c;
0313 Local2DPoint position(solution(0), solution(1));
0314
0315 if ((!force) && (!((gluedDet->surface()).bounds().inside(position, 10.f * scale_))))
0316 return std::unique_ptr<SiStripMatchedRecHit2D>(nullptr);
0317
0318 double c2 = -m10;
0319 double s2 = -m11;
0320 double l2 = 1. / (c2 * c2 + s2 * s2);
0321
0322 double sigmap22 = sigmaPitch(stereoRH->localPosition(), stereoRH->localPositionError(), partnertopol);
0323
0324
0325
0326 double diff = (c1 * s2 - c2 * s1);
0327 double invdet2 = 1 / (diff * diff * l1 * l2);
0328 float xx = invdet2 * (sigmap12 * s2 * s2 * l2 + sigmap22 * s1 * s1 * l1);
0329 float xy = -invdet2 * (sigmap12 * c2 * s2 * l2 + sigmap22 * c1 * s1 * l1);
0330 float yy = invdet2 * (sigmap12 * c2 * c2 * l2 + sigmap22 * c1 * c1 * l1);
0331 LocalError error(xx, xy, yy);
0332
0333
0334
0335 if (force || (gluedDet->surface()).bounds().inside(position, error, scale_))
0336 return std::make_unique<SiStripMatchedRecHit2D>(LocalPoint(position), error, *gluedDet, monoRH, stereoRH);
0337 return std::unique_ptr<SiStripMatchedRecHit2D>(nullptr);
0338 }