CMS 3D CMS Logo

SiStripRecHitMatcher.h
Go to the documentation of this file.
1 #ifndef RECOLOCALTRACKER_SISTRIPCLUSTERIZER_SISTRIPRECHITMATCH_H
2 #define RECOLOCALTRACKER_SISTRIPCLUSTERIZER_SISTRIPRECHITMATCH_H
3 
11 
13 
15 
17 
18 class GluedGeomDet;
19 
20 #include <cfloat>
21 #include <functional>
22 #include <memory>
23 
25 public:
26  // may become a template argument
28 
30  typedef std::vector<const SiStripRecHit2D*> SimpleHitCollection;
31  typedef SimpleHitCollection::const_iterator SimpleHitIterator;
32 
34 
35  typedef std::pair<LocalPoint, LocalPoint> StripPosition;
36 
38  SiStripRecHitMatcher(const double theScale);
39 
40  bool preFilter() const { return preFilter_; }
41 
42  inline static float sigmaPitch(LocalPoint const& pos, LocalError const& err, const StripTopology& topol) {
44  auto pitch = topol.localPitch(pos);
45  return error.uu() * pitch * pitch;
46  }
47 
48  // optimized matching iteration (the algo is the same, just recoded)
49  template <typename MonoIterator, typename StereoIterator, typename CollectorHelper>
50  void doubleMatch(MonoIterator monoRHiter,
51  MonoIterator monoRHend,
52  StereoIterator seconditer,
53  StereoIterator seconditerend,
54  const GluedGeomDet* gluedDet,
55  LocalVector trdir,
56  CollectorHelper& collectorHelper) const;
57 
58  //match a single hit
59  std::unique_ptr<SiStripMatchedRecHit2D> match(const SiStripRecHit2D* monoRH,
60  const SiStripRecHit2D* stereoRH,
61  const GluedGeomDet* gluedDet,
62  LocalVector trackdirection,
63  bool force) const;
64 
65  // this is the one used by the RecHitConverter
66  void match(const SiStripRecHit2D* monoRH,
67  RecHitIterator begin,
69  CollectorMatched& collector,
70  const GluedGeomDet* gluedDet,
71  LocalVector trackdirection) const;
72 
73  void match(const SiStripRecHit2D* monoRH,
74  SimpleHitIterator begin,
76  CollectorMatched& collector,
77  const GluedGeomDet* gluedDet,
78  LocalVector trackdirection) const;
79 
80  // project strip coordinates on Glueddet
81 
83  const GluedGeomDet* glueddet,
85  LocalVector trackdirection) const;
86 
87  // needed by the obsolete version still in use on some architectures
88  void match(const SiStripRecHit2D* monoRH,
89  SimpleHitIterator begin,
92  const GluedGeomDet* gluedDet,
93  LocalVector trackdirection) const;
94 
95  void match(const SiStripRecHit2D* monoRH,
96  SimpleHitIterator begin,
98  std::vector<SiStripMatchedRecHit2D*>& collector,
99  const GluedGeomDet* gluedDet,
100  LocalVector trackdirection) const;
101 
103  void match(const SiStripRecHit2D* monoRH,
104  SimpleHitIterator begin,
106  Collector& collector,
107  const GluedGeomDet* gluedDet,
108  LocalVector trackdirection) const;
109 
110  float scale_;
111  bool preFilter_ = false;
112 };
113 
115 #if defined(USE_SSEVECT) || defined(USE_EXTVECT)
116 #define DOUBLE_MATCH
117 #endif
118 
119 #ifdef DOUBLE_MATCH
120 
121 #if defined(USE_SSEVECT)
122 using mathSSE::Rot3F;
123 using mathSSE::Vec2D;
124 using mathSSE::Vec3D;
125 using mathSSE::Vec3F;
126 #endif
127 
130 
131 namespace matcherDetails {
132 
133  struct StereoInfo {
134  Vec2D c1vec;
135  const SiStripRecHit2D* secondHit;
136  float sigmap22;
137  double m10, m11;
138  };
139 
140 } // namespace matcherDetails
141 
142 template <typename MonoIterator, typename StereoIterator, typename CollectorHelper>
143 void SiStripRecHitMatcher::doubleMatch(MonoIterator monoRHiter,
144  MonoIterator monoRHend,
145  StereoIterator seconditer,
146  StereoIterator seconditerend,
147  const GluedGeomDet* gluedDet,
148  LocalVector trdir,
149  CollectorHelper& collectorHelper) const {
150  using matcherDetails::StereoInfo;
151 
152  typedef GloballyPositioned<float> ToGlobal;
153  typedef typename GloballyPositioned<float>::ToLocal ToLocal;
154 
155  // hits in both mono and stero
156  // match
157  bool notk = trdir.mag2() < float(FLT_MIN);
158  // FIXME we shall find a faster approximation for trdir: not useful to compute it each time for each strip
159 
160  // stripdet = mono
161  // partnerstripdet = stereo
162  const GeomDetUnit* stripdet = gluedDet->monoDet();
163  const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
164  const StripTopology& topol = (const StripTopology&)stripdet->topology();
165  const StripTopology& partnertopol = (const StripTopology&)partnerstripdet->topology();
166 
167  // toGlobal is fast, toLocal is slow
168  ToGlobal const& stripDetTrans = stripdet->surface();
169  ToGlobal const& partnerStripDetTrans = partnerstripdet->surface();
170  ToLocal gluedDetInvTrans(gluedDet->surface());
171 
172  std::vector<StereoInfo> cache(std::distance(seconditer, seconditerend));
173  //iterate on stereo rechits
174  // fill cache with relevant info
175  int cacheSize = 0;
176  for (; seconditer != seconditerend; ++seconditer) {
177  const SiStripRecHit2D& secondHit = CollectorHelper::stereoHit(seconditer);
178 
179  float sigmap22 = sigmaPitch(secondHit.localPosition(), secondHit.localPositionError(), partnertopol);
180  // assert (sigmap22>=0);
181 
182  auto STEREOpointX = partnertopol.measurementPosition(secondHit.localPositionFast()).x();
183  MeasurementPoint STEREOpointini(STEREOpointX, -0.5f);
184  MeasurementPoint STEREOpointend(STEREOpointX, 0.5f);
185 
186  LocalPoint locp1 = partnertopol.localPosition(STEREOpointini);
187  LocalPoint locp2 = partnertopol.localPosition(STEREOpointend);
188 
189  GlobalPoint globalpointini = partnerStripDetTrans.toGlobal(locp1);
190  GlobalPoint globalpointend = partnerStripDetTrans.toGlobal(locp2);
191 
192  // position of the initial and final point of the strip in glued local coordinates
193  LocalPoint positiononGluedini = gluedDetInvTrans.toLocal(globalpointini);
194  LocalPoint positiononGluedend = gluedDetInvTrans.toLocal(globalpointend);
195 
196  // in case of no track hypothesis assume a track from the origin through the center of the strip
197  if (notk) {
198  const LocalPoint& lcenterofstrip = secondHit.localPositionFast();
199  GlobalPoint gcenterofstrip = partnerStripDetTrans.toGlobal(lcenterofstrip);
200  GlobalVector gtrackdirection = gcenterofstrip - GlobalPoint(0, 0, 0);
201  trdir = gluedDetInvTrans.toLocal(gtrackdirection);
202  }
203 
204  Vec3F offset = trdir.basicVector().v * positiononGluedini.z() / trdir.z();
205 
206  Vec3F ret1 = positiononGluedini.basicVector().v - offset;
207  Vec3F ret2 = positiononGluedend.basicVector().v - offset;
208 
209  double m10 = -(ret2[1] - ret1[1]);
210  double m11 = ret2[0] - ret1[0];
211  double dd = m11 * ret1[1] + m10 * ret1[0];
212 
213  Vec2D c1vec{dd, dd};
214 
215  // store
216  StereoInfo info = {c1vec, &secondHit, sigmap22, m10, m11};
217  cache[cacheSize++] = info;
218  }
219 
220  for (; monoRHiter != monoRHend; ++monoRHiter) {
221  SiStripRecHit2D const& monoRH = CollectorHelper::monoHit(monoRHiter);
222 
223  // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
224  auto RPHIpointX = topol.measurementPosition(monoRH.localPositionFast()).x();
225  MeasurementPoint RPHIpointini(RPHIpointX, -0.5f);
226  MeasurementPoint RPHIpointend(RPHIpointX, 0.5f);
227 
228  // position of the initial and final point of the strip in local coordinates (mono det)
229  //StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
230  LocalPoint locp1o = topol.localPosition(RPHIpointini);
231  LocalPoint locp2o = topol.localPosition(RPHIpointend);
232 
233  // in case of no track hypothesis assume a track from the origin through the center of the strip
234  if (notk) {
235  const LocalPoint& lcenterofstrip = monoRH.localPositionFast();
236  GlobalPoint gcenterofstrip = stripDetTrans.toGlobal(lcenterofstrip);
237  GlobalVector gtrackdirection = gcenterofstrip - GlobalPoint(0, 0, 0);
238  trdir = gluedDetInvTrans.toLocal(gtrackdirection);
239  }
240 
241  //project mono hit on glued det
242  //StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
243 
244  GlobalPoint globalpointini = stripDetTrans.toGlobal(locp1o);
245  GlobalPoint globalpointend = stripDetTrans.toGlobal(locp2o);
246 
247  // position of the initial and final point of the strip in glued local coordinates
248  LocalPoint positiononGluedini = gluedDetInvTrans.toLocal(globalpointini);
249  LocalPoint positiononGluedend = gluedDetInvTrans.toLocal(globalpointend);
250 
251  Vec3F offset = trdir.basicVector().v * positiononGluedini.z() / trdir.z();
252 
253  Vec3F projini = positiononGluedini.basicVector().v - offset;
254  Vec3F projend = positiononGluedend.basicVector().v - offset;
255 
256  // ret1o = ret1o + (trdir * (ret1o.getSimd(2) / trdirz));
257  // ret2o = ret2o + (trdir * (ret2o.getSimd(2) / trdirz));
258 
259  double m00 = -(projend[1] - projini[1]); //-(projectedstripmono.second.y()-projectedstripmono.first.y());
260  double m01 = (projend[0] - projini[0]); // (projectedstripmono.second.x()-projectedstripmono.first.x());
261  double c0 =
262  m01 * projini[1] + m00 * projini[0]; //m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
263 
264  Vec2D c0vec{c0, c0};
265  Vec2D minv00{-m01, m00};
266 
267  //error calculation (the part that depends on mono RH only)
268  double c1 = -m00;
269  double s1 = -m01;
270  double l1 = 1. / (c1 * c1 + s1 * s1);
271 
272  float sigmap12 = sigmaPitch(monoRH.localPosition(), monoRH.localPositionError(), topol);
273  // float sigmap12 = monoRH.sigmaPitch();
274  // assert(sigmap12>=0);
275 
276  //float code
277  float fc1(c1), fs1(s1);
278  Vec3F scc1{fs1, fc1, fc1, 0.f};
279  Vec3F ssc1{fs1, fs1, fc1, 0.f};
280  const Vec3F cslsimd = scc1 * ssc1 * float(l1);
281 
282  for (int i = 0; i != cacheSize; ++i) {
283  StereoInfo const si = cache[i];
284 
285  // match
286  Vec2D minv10{si.m11, -si.m10};
287  double mult = 1. / (m00 * si.m11 - m01 * si.m10);
288  Vec2D resultmatmul = mult * (minv10 * c0vec + minv00 * si.c1vec);
289 
290  Local2DPoint position(resultmatmul[0], resultmatmul[1]);
291 
292  // LocalError tempError (100,0,100);
293  if (!((gluedDet->surface()).bounds().inside(position, 10.f * scale_)))
294  continue;
295 
296  double c2 = -si.m10;
297  double s2 = -si.m11;
298  double l2 = 1. / (c2 * c2 + s2 * s2);
299 
300  double diff = (c1 * s2 - c2 * s1);
301  double invdet2 = 1. / (diff * diff * l1 * l2);
302 
303  float fc2(c2), fs2(s2), fid2(invdet2);
304  Vec3F invdet2simd{fid2, -fid2, fid2, 0.f};
305  Vec3F ccssimd{fs2, fc2, fc2, 0.f};
306  Vec3F csssimd{fs2, fs2, fc2, 0.f};
307  Vec3F result = invdet2simd * (si.sigmap22 * cslsimd + sigmap12 * ccssimd * csssimd * float(l2));
308 
309  LocalError error(result[0], result[1], result[2]);
310 
311  if ((gluedDet->surface()).bounds().inside(position, error, scale_)) { //if it is inside the gluedet bonds
312 
313  //Change NSigmaInside in the configuration file to accept more hits
314  //...and add it to the Rechit collection
315 
316  collectorHelper.collector()(
317  SiStripMatchedRecHit2D(LocalPoint(position), error, *gluedDet, &monoRH, si.secondHit));
318  }
319 
320  } // loop on cache info
321 
322  collectorHelper.closure(monoRHiter);
323  } // loop on mono hit
324 }
325 
326 #endif //DOUBLE_MATCH
327 
328 #endif // RECOLOCALTRACKER_SISTRIPCLUSTERIZER_SISTRIPRECHITMATCH_H
Vector3DBase< float, LocalTag >
GloballyPositioned< float >
change_name.diff
diff
Definition: change_name.py:13
SiStripRecHitMatcher::SimpleHitIterator
SimpleHitCollection::const_iterator SimpleHitIterator
Definition: SiStripRecHitMatcher.h:31
Point2DBase
Definition: Point2DBase.h:9
cmsStageWithFailover.force
force
Definition: cmsStageWithFailover.py:19
SiStripRecHitMatcher::sigmaPitch
static float sigmaPitch(LocalPoint const &pos, LocalError const &err, const StripTopology &topol)
Definition: SiStripRecHitMatcher.h:42
mps_fire.i
i
Definition: mps_fire.py:428
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
SiStripRecHitMatcher::project
StripPosition project(const GeomDetUnit *det, const GluedGeomDet *glueddet, StripPosition strip, LocalVector trackdirection) const
Definition: SiStripRecHitMatcher.cc:217
GeomDet
Definition: GeomDet.h:27
SiStripRecHitMatcher::preFilter
bool preFilter() const
Definition: SiStripRecHitMatcher.h:40
AlgebraicObjects.h
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
SiStripMatchedRecHit2DCollection.h
Vec3F
Vec4< float > Vec3F
Definition: ExtVec.h:153
mathSSE::Vec2D
Vec2< double > Vec2D
Definition: SSEVec.h:483
StripTopology::localPosition
virtual LocalPoint localPosition(float strip) const =0
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
SiStripRecHitMatcher::Collector
std::function< void(SiStripMatchedRecHit2D const &)> Collector
Definition: SiStripRecHitMatcher.h:33
pos
Definition: PixelAliasList.h:18
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:197
Basic3DVector.h
GluedGeomDet::monoDet
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:19
GluedGeomDet.h
GeomDet::topology
virtual const Topology & topology() const
Definition: GeomDet.cc:67
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
SiStripRecHit2D
Definition: SiStripRecHit2D.h:7
DDAxes::x
indexGen.s2
s2
Definition: indexGen.py:107
StripTopology.h
align::LocalPoint
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
mathSSE::Vec3F
Vec4< float > Vec3F
Definition: SSEVec.h:482
PV3DBase::mag2
T mag2() const
Definition: PV3DBase.h:63
relativeConstraints.error
error
Definition: relativeConstraints.py:53
StripTopology::localPitch
virtual float localPitch(const LocalPoint &) const =0
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
MeasurementError
Definition: MeasurementError.h:8
mps_fire.end
end
Definition: mps_fire.py:242
mathSSE::Vec2< double >
Topology::measurementError
virtual MeasurementError measurementError(const LocalPoint &, const LocalError &) const =0
SiStripRecHitMatcher::StripPosition
std::pair< LocalPoint, LocalPoint > StripPosition
Definition: SiStripRecHitMatcher.h:35
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
SiStripRecHitMatcher::doubleMatch
void doubleMatch(MonoIterator monoRHiter, MonoIterator monoRHend, StereoIterator seconditer, StereoIterator seconditerend, const GluedGeomDet *gluedDet, LocalVector trdir, CollectorHelper &collectorHelper) const
Point3DBase< float, LocalTag >
createTree.dd
string dd
Definition: createTree.py:154
GluedGeomDet
Definition: GluedGeomDet.h:7
utilities.cache
def cache(function)
Definition: utilities.py:3
BaseTrackerRecHit::localPositionError
LocalError localPositionError() const override
Definition: BaseTrackerRecHit.h:61
mathSSE::Rot3F
Rot3< float > Rot3F
Definition: SSERot.h:71
edm::ParameterSet
Definition: ParameterSet.h:47
LocalError
Definition: LocalError.h:12
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
BaseTrackerRecHit::localPositionFast
const LocalPoint & localPositionFast() const
Definition: BaseTrackerRecHit.h:65
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
HelpertRecHit2DLocalPos.h
SiStripRecHit2DCollection.h
Topology::measurementPosition
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
Basic3DVector::v
Vec4< T > v
Definition: extBasic3DVector.h:217
SiStripRecHitMatcher::SiStripRecHitMatcher
SiStripRecHitMatcher(const edm::ParameterSet &conf)
Definition: SiStripRecHitMatcher.cc:15
PV3DBase::basicVector
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
SiStripRecHitMatcher::scale_
float scale_
Definition: SiStripRecHitMatcher.h:110
GluedGeomDet::stereoDet
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:20
mathSSE::Vec3D
Vec4< double > Vec3D
Definition: SSEVec.h:484
GeomDet.h
BaseTrackerRecHit::localPosition
LocalPoint localPosition() const override
Definition: BaseTrackerRecHit.h:56
SiStripRecHitMatcher::SimpleHitCollection
std::vector< const SiStripRecHit2D * > SimpleHitCollection
Definition: SiStripRecHitMatcher.h:30
SiStripMatchedRecHit2D
Definition: SiStripMatchedRecHit2D.h:8
DetId.h
SiStripRecHitMatcher::RecHitIterator
SiStripRecHit2DCollectionNew::DetSet::const_iterator RecHitIterator
Definition: SiStripRecHitMatcher.h:29
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
fftjetpileupestimator_calo_uncalib_cfi.c0
c0
Definition: fftjetpileupestimator_calo_uncalib_cfi.py:8
VarParsing.mult
mult
Definition: VarParsing.py:659
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
edmNew::DetSetVector::FastFiller
Definition: DetSetVectorNew.h:202
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
SiStripMatchedRecHit2D.h
SiStripRecHitMatcher
Definition: SiStripRecHitMatcher.h:24
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7799
SiStripRecHitMatcher::CollectorMatched
SiStripMatchedRecHit2DCollectionNew::FastFiller CollectorMatched
Definition: SiStripRecHitMatcher.h:27
SiStripRecHit2D.h
StripTopology
Definition: StripTopology.h:11
SiStripRecHitMatcher::preFilter_
bool preFilter_
Definition: SiStripRecHitMatcher.h:111
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:239