CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SSEMatcher.h
Go to the documentation of this file.
3 
4 namespace matcherDetails {
5 
6  struct StereoInfo {
8  const SiStripRecHit2D * secondHit;
9  double sigmap22;
10  double m10, m11;
11  };
12 
13 }
14 
15 template<typename MonoIterator, typename StereoIterator, typename CollectorHelper>
16 void SiStripRecHitMatcher::doubleMatch(MonoIterator monoRHiter, MonoIterator monoRHend,
17  StereoIterator seconditer, StereoIterator seconditerend,
18  const GluedGeomDet* gluedDet, LocalVector trdir,
19  CollectorHelper & collectorHelper) const{
20 
22  using mathSSE::Vec3F;
23  using mathSSE::Vec2D;
24  using mathSSE::Vec3D;
25  using mathSSE::Rot3F;
26  typedef GloballyPositioned<float> ToGlobal;
27  typedef typename GloballyPositioned<float>::ToLocal ToLocal;
28 
29  // hits in both mono and stero
30  // match
31  bool notk = trdir.mag2()<FLT_MIN;
32  // FIXME we shall find a faster approximation for trdir: not useful to compute it each time for each strip
33 
34  // stripdet = mono
35  // partnerstripdet = stereo
36  const GeomDetUnit* stripdet = gluedDet->monoDet();
37  const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
38  const StripTopology& topol=(const StripTopology&)stripdet->topology();
39  const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
40 
41  // toGlobal is fast, toLocal is slow
42  ToGlobal const & stripDetTrans = stripdet->surface();
43  ToGlobal const & partnerStripDetTrans = partnerstripdet->surface();
44  ToLocal gluedDetInvTrans(gluedDet->surface());
45 
46 
47 
48  StereoInfo cache[std::distance(seconditer,seconditerend)];
49  //iterate on stereo rechits
50  // fill cache with relevant info
51  int cacheSize=0;
52  for (;seconditer!=seconditerend; ++seconditer){
53 
54  const SiStripRecHit2D & secondHit = CollectorHelper::stereoHit(seconditer);
55 
56  double sigmap22 =secondHit.sigmaPitch();
57  if (sigmap22<0) {
58  LocalError tmpError( secondHit.localPositionErrorFast());
59  HelpertRecHit2DLocalPos::updateWithAPE(tmpError, *partnerstripdet);
60  MeasurementError errorstereoRH=partnertopol.measurementError(secondHit.localPositionFast(),tmpError);
61 
62  double pitch=partnertopol.localPitch(secondHit.localPositionFast());
63  secondHit.setSigmaPitch(sigmap22=errorstereoRH.uu()*pitch*pitch);
64  }
65 
66 
67  double STEREOpointX=partnertopol.measurementPosition( secondHit.localPositionFast()).x();
68  MeasurementPoint STEREOpointini(STEREOpointX,-0.5);
69  MeasurementPoint STEREOpointend(STEREOpointX,0.5);
70 
71  LocalPoint locp1 = partnertopol.localPosition(STEREOpointini);
72  LocalPoint locp2 = partnertopol.localPosition(STEREOpointend);
73 
74  GlobalPoint globalpointini=partnerStripDetTrans.toGlobal(locp1);
75  GlobalPoint globalpointend=partnerStripDetTrans.toGlobal(locp2);
76 
77  // position of the initial and final point of the strip in glued local coordinates
78  LocalPoint positiononGluedini=gluedDetInvTrans.toLocal(globalpointini);
79  LocalPoint positiononGluedend=gluedDetInvTrans.toLocal(globalpointend);
80 
81  // in case of no track hypothesis assume a track from the origin through the center of the strip
82  if(notk){
83  LocalPoint lcenterofstrip=secondHit.localPositionFast();
84  GlobalPoint gcenterofstrip= partnerStripDetTrans.toGlobal(lcenterofstrip);
85  GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
86  trdir=gluedDetInvTrans.toLocal(gtrackdirection);
87  }
88 
89 
90  Vec3F offset = trdir.basicVector().v * positiononGluedini.basicVector().v.get1<2>()/trdir.basicVector().v.get1<2>();
91 
92 
93  Vec3F ret1 = positiononGluedini.basicVector().v - offset;
94  Vec3F ret2 = positiononGluedend.basicVector().v - offset;
95 
96  double m10=-(ret2.arr[1] - ret1.arr[1]);
97  double m11= ret2.arr[0] - ret1.arr[0];
98 
99  Vec2D c1vec; c1vec.set1(m11*ret1.arr[1] + m10 * ret1.arr[0]);
100 
101  // store
102  StereoInfo info = {c1vec,&secondHit,sigmap22,m10,m11};
103  cache[cacheSize++] = info;
104  }
105 
106 
107 
108  for (;monoRHiter != monoRHend; ++monoRHiter) {
109 
110  SiStripRecHit2D const & monoRH = CollectorHelper::monoHit(monoRHiter);
111 
112  // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
113  double RPHIpointX = topol.measurementPosition(monoRH.localPositionFast()).x();
114  MeasurementPoint RPHIpointini(RPHIpointX,-0.5);
115  MeasurementPoint RPHIpointend(RPHIpointX,0.5);
116 
117  // position of the initial and final point of the strip in local coordinates (mono det)
118  //StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
119  LocalPoint locp1o = topol.localPosition(RPHIpointini);
120  LocalPoint locp2o = topol.localPosition(RPHIpointend);
121 
122 
123  // in case of no track hypothesis assume a track from the origin through the center of the strip
124  if(notk){
125  LocalPoint lcenterofstrip=monoRH.localPositionFast();
126  GlobalPoint gcenterofstrip= stripDetTrans.toGlobal(lcenterofstrip);
127  GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
128  trdir=gluedDetInvTrans.toLocal(gtrackdirection);
129  }
130 
131 
132  //project mono hit on glued det
133  //StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
134 
135 
136  GlobalPoint globalpointini=stripDetTrans.toGlobal(locp1o);
137  GlobalPoint globalpointend=stripDetTrans.toGlobal(locp2o);
138 
139  // position of the initial and final point of the strip in glued local coordinates
140  LocalPoint positiononGluedini=gluedDetInvTrans.toLocal(globalpointini);
141  LocalPoint positiononGluedend=gluedDetInvTrans.toLocal(globalpointend);
142 
143  Vec3F offset = trdir.basicVector().v * positiononGluedini.basicVector().v.get1<2>()/trdir.basicVector().v.get1<2>();
144 
145 
146  Vec3F projini= positiononGluedini.basicVector().v - offset;
147  Vec3F projend = positiononGluedend.basicVector().v -offset;
148 
149  // ret1o = ret1o + (trdir * (ret1o.getSimd(2) / trdirz));
150  // ret2o = ret2o + (trdir * (ret2o.getSimd(2) / trdirz));
151 
152  double m00 = -(projend.arr[1] - projini.arr[1]);//-(projectedstripmono.second.y()-projectedstripmono.first.y());
153  double m01 = (projend.arr[0] - projini.arr[0]); // (projectedstripmono.second.x()-projectedstripmono.first.x());
154  double c0 = m01*projini.arr[1] + m00*projini.arr[0];//m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
155 
156  Vec2D c0vec(c0,c0);
157  Vec2D minv00(-m01, m00);
158 
159  //error calculation (the part that depends on mono RH only)
160  double c1 = -m00;
161  double s1 = -m01;
162  double l1 = 1./(c1*c1+s1*s1);
163 
164  // FIXME: here for test...
165  double sigmap12 = monoRH.sigmaPitch();
166  if (sigmap12<0) {
167 
168  LocalError tmpError(monoRH.localPositionErrorFast());
169  HelpertRecHit2DLocalPos::updateWithAPE(tmpError,*stripdet);
170  MeasurementError errormonoRH=topol.measurementError(monoRH.localPositionFast(),tmpError);
171 
172  double pitch=topol.localPitch(monoRH.localPositionFast());
173  monoRH.setSigmaPitch(sigmap12=errormonoRH.uu()*pitch*pitch);
174  }
175 
176  //float code
177  float fc1(c1), fs1(s1);
178  Vec3F scc1(fs1, fc1, fc1, 0.f);
179  Vec3F ssc1(fs1, fs1, fc1, 0.f);
180  Vec3F l1vec; l1vec.set1(l1);
181  const Vec3F cslsimd = scc1 * ssc1 * l1vec;
182  Vec3F sigmap12simd; sigmap12simd.set1(sigmap12);
183 
184  for (int i=0; i!=cacheSize; ++i) {
185  StereoInfo const si = cache[i];
186 
187  // match
188  Vec2D minv10(si.m11, -si.m10);
189  Vec2D mult; mult.set1(1./(m00*si.m11 - m01*si.m10));
190  Vec2D resultmatmul = mult * (minv10 * c0vec + minv00 * si.c1vec);
191 
192  Local2DPoint position(resultmatmul.arr[0], resultmatmul.arr[1]);
193 
194  // LocalError tempError (100,0,100);
195  if (!((gluedDet->surface()).bounds().inside(position,10.f*scale_))) continue;
196 
197  double c2 = -si.m10;
198  double s2 = -si.m11;
199  double l2 = 1./(c2*c2+s2*s2);
200 
201  double diff=(c1*s2-c2*s1);
202  double invdet2 = 1./(diff*diff*l1*l2);
203 
204  float fc2(c2), fs2(s2), fid2(invdet2);
205  Vec3F invdet2simd(fid2, -fid2, fid2, 0.f);
206  Vec3F ccssimd(fs2, fc2, fc2, 0.f);
207  Vec3F csssimd(fs2, fs2, fc2, 0.f);
208  Vec3F l2simd; l2simd.set1(l2);
209  Vec3F sigmap22simd; sigmap22simd.set1(si.sigmap22);
210  Vec3F result = invdet2simd * (sigmap22simd * cslsimd + sigmap12simd * ccssimd * csssimd * l2simd);
211 
212 
213  LocalError error(result.arr[0], result.arr[1], result.arr[2]);
214 
215 
216  if((gluedDet->surface()).bounds().inside(position,error,scale_)){ //if it is inside the gluedet bonds
217 
218  //Change NSigmaInside in the configuration file to accept more hits
219  //...and add it to the Rechit collection
220 
221  collectorHelper.collector()(SiStripMatchedRecHit2D(LocalPoint(position), error,gluedDet->geographicalId() ,
222  &monoRH,si.secondHit));
223  }
224 
225  } // loop on cache info
226 
227  collectorHelper.closure(monoRHiter);
228  } // loop on mono hit
229 
230 }
Vec4 get1() const
Definition: SSEVec.h:209
int i
Definition: DBlmapReader.cc:9
T mag2() const
Definition: PV3DBase.h:66
static const TGPicture * info(bool iBackgroundIsBlack)
Vec4< float > Vec3F
Definition: SSEVec.h:531
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
mathSSE::Vec2D c1vec
Definition: SSEMatcher.h:7
T arr[2]
Definition: SSEVec.h:188
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
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
Vec4< double > Vec3D
Definition: SSEVec.h:533
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
Definition: SSEMatcher.h:16
const SiStripRecHit2D * secondHit
Definition: SSEMatcher.h:8
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
virtual LocalPoint localPosition(float strip) const =0
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:532