CMS 3D CMS Logo

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