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 
139 #ifdef USE_SSEVECT
140 #define DOUBLE_MATCH
141 #endif
142 
143 #ifdef DOUBLE_MATCH
146 
147 namespace matcherDetails {
148 
149  struct StereoInfo {
150  mathSSE::Vec2D c1vec;
151  const SiStripRecHit2D * secondHit;
152  double sigmap22;
153  double m10, m11;
154  };
155 
156 }
157 
158 template<typename MonoIterator, typename StereoIterator, typename CollectorHelper>
159 void SiStripRecHitMatcher::doubleMatch(MonoIterator monoRHiter, MonoIterator monoRHend,
160  StereoIterator seconditer, StereoIterator seconditerend,
161  const GluedGeomDet* gluedDet, LocalVector trdir,
162  CollectorHelper & collectorHelper) const{
163 
164  using matcherDetails::StereoInfo;
165  using mathSSE::Vec3F;
166  using mathSSE::Vec2D;
167  using mathSSE::Vec3D;
168  using mathSSE::Rot3F;
169  typedef GloballyPositioned<float> ToGlobal;
170  typedef typename GloballyPositioned<float>::ToLocal ToLocal;
171 
172  // hits in both mono and stero
173  // match
174  bool notk = trdir.mag2()<FLT_MIN;
175  // FIXME we shall find a faster approximation for trdir: not useful to compute it each time for each strip
176 
177  // stripdet = mono
178  // partnerstripdet = stereo
179  const GeomDetUnit* stripdet = gluedDet->monoDet();
180  const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
181  const StripTopology& topol=(const StripTopology&)stripdet->topology();
182  const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
183 
184  // toGlobal is fast, toLocal is slow
185  ToGlobal const & stripDetTrans = stripdet->surface();
186  ToGlobal const & partnerStripDetTrans = partnerstripdet->surface();
187  ToLocal gluedDetInvTrans(gluedDet->surface());
188 
189 
190 
191  StereoInfo cache[std::distance(seconditer,seconditerend)];
192  //iterate on stereo rechits
193  // fill cache with relevant info
194  int cacheSize=0;
195  for (;seconditer!=seconditerend; ++seconditer){
196 
197  const SiStripRecHit2D & secondHit = CollectorHelper::stereoHit(seconditer);
198 
199  double sigmap22 =secondHit.sigmaPitch();
200  if (sigmap22<0) {
201  LocalError tmpError( secondHit.localPositionErrorFast());
202  HelpertRecHit2DLocalPos::updateWithAPE(tmpError, *partnerstripdet);
203  MeasurementError errorstereoRH=partnertopol.measurementError(secondHit.localPositionFast(),tmpError);
204 
205  double pitch=partnertopol.localPitch(secondHit.localPositionFast());
206  secondHit.setSigmaPitch(sigmap22=errorstereoRH.uu()*pitch*pitch);
207  }
208 
209 
210  double STEREOpointX=partnertopol.measurementPosition( secondHit.localPositionFast()).x();
211  MeasurementPoint STEREOpointini(STEREOpointX,-0.5);
212  MeasurementPoint STEREOpointend(STEREOpointX,0.5);
213 
214  LocalPoint locp1 = partnertopol.localPosition(STEREOpointini);
215  LocalPoint locp2 = partnertopol.localPosition(STEREOpointend);
216 
217  GlobalPoint globalpointini=partnerStripDetTrans.toGlobal(locp1);
218  GlobalPoint globalpointend=partnerStripDetTrans.toGlobal(locp2);
219 
220  // position of the initial and final point of the strip in glued local coordinates
221  LocalPoint positiononGluedini=gluedDetInvTrans.toLocal(globalpointini);
222  LocalPoint positiononGluedend=gluedDetInvTrans.toLocal(globalpointend);
223 
224  // in case of no track hypothesis assume a track from the origin through the center of the strip
225  if(notk){
226  LocalPoint lcenterofstrip=secondHit.localPositionFast();
227  GlobalPoint gcenterofstrip= partnerStripDetTrans.toGlobal(lcenterofstrip);
228  GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
229  trdir=gluedDetInvTrans.toLocal(gtrackdirection);
230  }
231 
232 
233  Vec3F offset = trdir.basicVector().v * positiononGluedini.basicVector().v.get1<2>()/trdir.basicVector().v.get1<2>();
234 
235 
236  Vec3F ret1 = positiononGluedini.basicVector().v - offset;
237  Vec3F ret2 = positiononGluedend.basicVector().v - offset;
238 
239  double m10=-(ret2.arr[1] - ret1.arr[1]);
240  double m11= ret2.arr[0] - ret1.arr[0];
241 
242  Vec2D c1vec; c1vec.set1(m11*ret1.arr[1] + m10 * ret1.arr[0]);
243 
244  // store
245  StereoInfo info = {c1vec,&secondHit,sigmap22,m10,m11};
246  cache[cacheSize++] = info;
247  }
248 
249 
250 
251  for (;monoRHiter != monoRHend; ++monoRHiter) {
252 
253  SiStripRecHit2D const & monoRH = CollectorHelper::monoHit(monoRHiter);
254 
255  // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
256  double RPHIpointX = topol.measurementPosition(monoRH.localPositionFast()).x();
257  MeasurementPoint RPHIpointini(RPHIpointX,-0.5);
258  MeasurementPoint RPHIpointend(RPHIpointX,0.5);
259 
260  // position of the initial and final point of the strip in local coordinates (mono det)
261  //StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
262  LocalPoint locp1o = topol.localPosition(RPHIpointini);
263  LocalPoint locp2o = topol.localPosition(RPHIpointend);
264 
265 
266  // in case of no track hypothesis assume a track from the origin through the center of the strip
267  if(notk){
268  LocalPoint lcenterofstrip=monoRH.localPositionFast();
269  GlobalPoint gcenterofstrip= stripDetTrans.toGlobal(lcenterofstrip);
270  GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
271  trdir=gluedDetInvTrans.toLocal(gtrackdirection);
272  }
273 
274 
275  //project mono hit on glued det
276  //StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
277 
278 
279  GlobalPoint globalpointini=stripDetTrans.toGlobal(locp1o);
280  GlobalPoint globalpointend=stripDetTrans.toGlobal(locp2o);
281 
282  // position of the initial and final point of the strip in glued local coordinates
283  LocalPoint positiononGluedini=gluedDetInvTrans.toLocal(globalpointini);
284  LocalPoint positiononGluedend=gluedDetInvTrans.toLocal(globalpointend);
285 
286  Vec3F offset = trdir.basicVector().v * positiononGluedini.basicVector().v.get1<2>()/trdir.basicVector().v.get1<2>();
287 
288 
289  Vec3F projini= positiononGluedini.basicVector().v - offset;
290  Vec3F projend = positiononGluedend.basicVector().v -offset;
291 
292  // ret1o = ret1o + (trdir * (ret1o.getSimd(2) / trdirz));
293  // ret2o = ret2o + (trdir * (ret2o.getSimd(2) / trdirz));
294 
295  double m00 = -(projend.arr[1] - projini.arr[1]);//-(projectedstripmono.second.y()-projectedstripmono.first.y());
296  double m01 = (projend.arr[0] - projini.arr[0]); // (projectedstripmono.second.x()-projectedstripmono.first.x());
297  double c0 = m01*projini.arr[1] + m00*projini.arr[0];//m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
298 
299  Vec2D c0vec(c0,c0);
300  Vec2D minv00(-m01, m00);
301 
302  //error calculation (the part that depends on mono RH only)
303  double c1 = -m00;
304  double s1 = -m01;
305  double l1 = 1./(c1*c1+s1*s1);
306 
307  // FIXME: here for test...
308  double sigmap12 = monoRH.sigmaPitch();
309  if (sigmap12<0) {
310 
311  LocalError tmpError(monoRH.localPositionErrorFast());
312  HelpertRecHit2DLocalPos::updateWithAPE(tmpError,*stripdet);
313  MeasurementError errormonoRH=topol.measurementError(monoRH.localPositionFast(),tmpError);
314 
315  double pitch=topol.localPitch(monoRH.localPositionFast());
316  monoRH.setSigmaPitch(sigmap12=errormonoRH.uu()*pitch*pitch);
317  }
318 
319  //float code
320  float fc1(c1), fs1(s1);
321  Vec3F scc1(fs1, fc1, fc1, 0.f);
322  Vec3F ssc1(fs1, fs1, fc1, 0.f);
323  Vec3F l1vec; l1vec.set1(l1);
324  const Vec3F cslsimd = scc1 * ssc1 * l1vec;
325  Vec3F sigmap12simd; sigmap12simd.set1(sigmap12);
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  Vec2D mult; mult.set1(1./(m00*si.m11 - m01*si.m10));
333  Vec2D resultmatmul = mult * (minv10 * c0vec + minv00 * si.c1vec);
334 
335  Local2DPoint position(resultmatmul.arr[0], resultmatmul.arr[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 l2simd; l2simd.set1(l2);
352  Vec3F sigmap22simd; sigmap22simd.set1(si.sigmap22);
353  Vec3F result = invdet2simd * (sigmap22simd * cslsimd + sigmap12simd * ccssimd * csssimd * l2simd);
354 
355 
356  LocalError error(result.arr[0], result.arr[1], result.arr[2]);
357 
358 
359  if((gluedDet->surface()).bounds().inside(position,error,scale_)){ //if it is inside the gluedet bonds
360 
361  //Change NSigmaInside in the configuration file to accept more hits
362  //...and add it to the Rechit collection
363 
364  collectorHelper.collector()(SiStripMatchedRecHit2D(LocalPoint(position), error,gluedDet->geographicalId() ,
365  &monoRH,si.secondHit));
366  }
367 
368  } // loop on cache info
369 
370  collectorHelper.closure(monoRHiter);
371  } // loop on mono hit
372 
373 }
374 
375 #endif //DOUBLE_MATCH
376 
377 
378 
379 #endif // RECOLOCALTRACKER_SISTRIPCLUSTERIZER_SISTRIPRECHITMATCH_H
380 
381 
382 
Vec4 get1() const
Definition: SSEVec.h:242
int i
Definition: DBlmapReader.cc:9
void set1(float f1)
Definition: SSEVec.h:238
T mag2() const
Definition: PV3DBase.h:65
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Local3DVector LocalVector
Definition: LocalVector.h:12
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
Vec4< float > Vec3F
Definition: SSEVec.h:564
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
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
static void updateWithAPE(LocalError &le, const GeomDet &det)
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)
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]
mathSSE::Vec4< T > v
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
Vec4< double > Vec3D
Definition: SSEVec.h:566
#define end
Definition: vmac.h:38
Rot3< float > Rot3F
Definition: SSERot.h:73
unsigned int offset(bool)
void doubleMatch(MonoIterator monoRHiter, MonoIterator monoRHend, StereoIterator seconditer, StereoIterator seconditerend, const GluedGeomDet *gluedDet, LocalVector trdir, CollectorHelper &collectorHelper) const
tuple conf
Definition: dbtoconf.py:185
SiStripMatchedRecHit2DCollectionNew::FastFiller CollectorMatched
std::vector< const SiStripRecHit2D * > SimpleHitCollection
SiStripRecHit2DCollectionNew::DetSet::const_iterator RecHitIterator
#define begin
Definition: vmac.h:31
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
SimpleHitCollection::const_iterator SimpleHitIterator
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
Vec2< double > Vec2D
Definition: SSEVec.h:565