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