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