CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoLocalTracker/SiStripRecHitConverter/interface/SSEMatcher.h

Go to the documentation of this file.
00001 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00002 #include "TrackingTools/TransientTrackingRecHit/interface/HelpertRecHit2DLocalPos.h"
00003 
00004 namespace matcherDetails {  
00005   
00006   struct StereoInfo {
00007     mathSSE::Vec2D c1vec;
00008     const SiStripRecHit2D * secondHit;
00009     double sigmap22;
00010     double m10, m11;
00011   };
00012   
00013 }
00014 
00015 template<typename MonoIterator, typename StereoIterator,  typename CollectorHelper>
00016 void SiStripRecHitMatcher::doubleMatch(MonoIterator monoRHiter, MonoIterator monoRHend,
00017                                        StereoIterator seconditer, StereoIterator seconditerend,
00018                                        const GluedGeomDet* gluedDet,    LocalVector trdir, 
00019                                        CollectorHelper & collectorHelper) const{
00020   
00021   using  matcherDetails::StereoInfo;  
00022   using  mathSSE::Vec3F;
00023   using  mathSSE::Vec2D;
00024   using  mathSSE::Vec3D;
00025   using  mathSSE::Rot3F;
00026   typedef  GloballyPositioned<float> ToGlobal;
00027   typedef  typename GloballyPositioned<float>::ToLocal ToLocal;
00028   
00029   // hits in both mono and stero
00030   // match
00031   bool notk = trdir.mag2()<FLT_MIN;
00032   // FIXME we shall find a faster approximation for trdir: not useful to compute it each time for each strip
00033   
00034   // stripdet = mono
00035   // partnerstripdet = stereo
00036   const GeomDetUnit* stripdet = gluedDet->monoDet();
00037   const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
00038   const StripTopology& topol=(const StripTopology&)stripdet->topology();
00039   const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
00040   
00041   // toGlobal is fast,  toLocal is slow
00042   ToGlobal const & stripDetTrans =  stripdet->surface();
00043   ToGlobal const & partnerStripDetTrans = partnerstripdet->surface();
00044   ToLocal          gluedDetInvTrans(gluedDet->surface());
00045   
00046   
00047   
00048   StereoInfo cache[std::distance(seconditer,seconditerend)];
00049   //iterate on stereo rechits
00050   // fill cache with relevant info
00051   int  cacheSize=0;
00052   for (;seconditer!=seconditerend; ++seconditer){
00053     
00054     const SiStripRecHit2D & secondHit = CollectorHelper::stereoHit(seconditer);
00055     
00056     double sigmap22 =secondHit.sigmaPitch();
00057     if (sigmap22<0) {
00058       LocalError tmpError( secondHit.localPositionErrorFast());
00059       HelpertRecHit2DLocalPos::updateWithAPE(tmpError, *partnerstripdet);
00060       MeasurementError errorstereoRH=partnertopol.measurementError(secondHit.localPositionFast(),tmpError);
00061       
00062       double pitch=partnertopol.localPitch(secondHit.localPositionFast());
00063       secondHit.setSigmaPitch(sigmap22=errorstereoRH.uu()*pitch*pitch);
00064     }
00065     
00066     
00067     double STEREOpointX=partnertopol.measurementPosition( secondHit.localPositionFast()).x();
00068     MeasurementPoint STEREOpointini(STEREOpointX,-0.5);
00069     MeasurementPoint STEREOpointend(STEREOpointX,0.5);
00070     
00071     LocalPoint locp1 = partnertopol.localPosition(STEREOpointini);
00072     LocalPoint locp2 = partnertopol.localPosition(STEREOpointend);
00073     
00074     GlobalPoint globalpointini=partnerStripDetTrans.toGlobal(locp1);
00075     GlobalPoint globalpointend=partnerStripDetTrans.toGlobal(locp2);
00076     
00077     // position of the initial and final point of the strip in glued local coordinates
00078     LocalPoint positiononGluedini=gluedDetInvTrans.toLocal(globalpointini);
00079     LocalPoint positiononGluedend=gluedDetInvTrans.toLocal(globalpointend); 
00080     
00081    // in case of no track hypothesis assume a track from the origin through the center of the strip
00082     if(notk){
00083       LocalPoint lcenterofstrip=secondHit.localPositionFast();
00084       GlobalPoint gcenterofstrip= partnerStripDetTrans.toGlobal(lcenterofstrip);
00085       GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
00086       trdir=gluedDetInvTrans.toLocal(gtrackdirection);
00087     }
00088   
00089 
00090     Vec3F offset = trdir.basicVector().v * positiononGluedini.basicVector().v.get1<2>()/trdir.basicVector().v.get1<2>();
00091     
00092     
00093     Vec3F ret1 = positiononGluedini.basicVector().v - offset;
00094     Vec3F ret2 = positiononGluedend.basicVector().v - offset;
00095     
00096     double m10=-(ret2.arr[1] - ret1.arr[1]); 
00097     double m11=  ret2.arr[0] - ret1.arr[0];
00098     
00099     Vec2D c1vec; c1vec.set1(m11*ret1.arr[1] + m10 * ret1.arr[0]);
00100     
00101     // store
00102     StereoInfo info = {c1vec,&secondHit,sigmap22,m10,m11};
00103     cache[cacheSize++] = info;
00104   }
00105   
00106   
00107   
00108   for (;monoRHiter != monoRHend; ++monoRHiter) {
00109     
00110     SiStripRecHit2D const & monoRH = CollectorHelper::monoHit(monoRHiter);
00111     
00112     // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
00113     double RPHIpointX = topol.measurementPosition(monoRH.localPositionFast()).x();
00114     MeasurementPoint RPHIpointini(RPHIpointX,-0.5);
00115     MeasurementPoint RPHIpointend(RPHIpointX,0.5);
00116     
00117     // position of the initial and final point of the strip in local coordinates (mono det)
00118     //StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
00119     LocalPoint locp1o = topol.localPosition(RPHIpointini);
00120     LocalPoint locp2o = topol.localPosition(RPHIpointend);
00121     
00122     
00123     // in case of no track hypothesis assume a track from the origin through the center of the strip
00124     if(notk){
00125       LocalPoint lcenterofstrip=monoRH.localPositionFast();
00126       GlobalPoint gcenterofstrip= stripDetTrans.toGlobal(lcenterofstrip);
00127       GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
00128       trdir=gluedDetInvTrans.toLocal(gtrackdirection);
00129     }
00130     
00131     
00132     //project mono hit on glued det
00133     //StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
00134     
00135     
00136     GlobalPoint globalpointini=stripDetTrans.toGlobal(locp1o);
00137     GlobalPoint globalpointend=stripDetTrans.toGlobal(locp2o);
00138     
00139     // position of the initial and final point of the strip in glued local coordinates
00140     LocalPoint positiononGluedini=gluedDetInvTrans.toLocal(globalpointini);
00141     LocalPoint positiononGluedend=gluedDetInvTrans.toLocal(globalpointend); 
00142     
00143     Vec3F offset = trdir.basicVector().v * positiononGluedini.basicVector().v.get1<2>()/trdir.basicVector().v.get1<2>();
00144     
00145     
00146     Vec3F projini= positiononGluedini.basicVector().v - offset;
00147     Vec3F projend = positiononGluedend.basicVector().v -offset;
00148     
00149     // ret1o = ret1o + (trdir * (ret1o.getSimd(2) / trdirz));
00150     // ret2o = ret2o + (trdir * (ret2o.getSimd(2) / trdirz));
00151     
00152     double m00 = -(projend.arr[1] - projini.arr[1]);//-(projectedstripmono.second.y()-projectedstripmono.first.y()); 
00153     double m01 =  (projend.arr[0] - projini.arr[0]); // (projectedstripmono.second.x()-projectedstripmono.first.x());
00154     double c0  =  m01*projini.arr[1] + m00*projini.arr[0];//m01*projectedstripmono.first.y()   + m00*projectedstripmono.first.x();
00155     
00156     Vec2D c0vec(c0,c0);
00157     Vec2D minv00(-m01, m00);
00158     
00159     //error calculation (the part that depends on mono RH only)
00160     double c1 = -m00;
00161     double s1 = -m01;
00162     double l1 = 1./(c1*c1+s1*s1);
00163     
00164     // FIXME: here for test...
00165     double sigmap12 = monoRH.sigmaPitch();
00166     if (sigmap12<0) {
00167       
00168       LocalError tmpError(monoRH.localPositionErrorFast());
00169       HelpertRecHit2DLocalPos::updateWithAPE(tmpError,*stripdet);
00170       MeasurementError errormonoRH=topol.measurementError(monoRH.localPositionFast(),tmpError);
00171       
00172       double pitch=topol.localPitch(monoRH.localPositionFast());
00173       monoRH.setSigmaPitch(sigmap12=errormonoRH.uu()*pitch*pitch);
00174     }
00175 
00176     //float code
00177     float fc1(c1), fs1(s1);
00178     Vec3F scc1(fs1, fc1, fc1, 0.f);
00179     Vec3F ssc1(fs1, fs1, fc1, 0.f);
00180     Vec3F l1vec; l1vec.set1(l1);
00181     const Vec3F cslsimd = scc1 * ssc1 * l1vec;
00182     Vec3F sigmap12simd; sigmap12simd.set1(sigmap12);
00183     
00184     for (int i=0; i!=cacheSize; ++i) {
00185       StereoInfo const si = cache[i];
00186       
00187       // match 
00188       Vec2D minv10(si.m11, -si.m10);
00189       Vec2D mult; mult.set1(1./(m00*si.m11 - m01*si.m10));
00190       Vec2D resultmatmul = mult * (minv10 * c0vec + minv00 * si.c1vec);
00191       
00192       Local2DPoint position(resultmatmul.arr[0], resultmatmul.arr[1]);
00193       
00194       // LocalError tempError (100,0,100);
00195       if (!((gluedDet->surface()).bounds().inside(position,10.f*scale_))) continue;                                                       
00196       
00197       double c2 = -si.m10;
00198       double s2 = -si.m11;
00199       double l2 = 1./(c2*c2+s2*s2);
00200       
00201       double diff=(c1*s2-c2*s1);
00202       double invdet2 = 1./(diff*diff*l1*l2);
00203       
00204       float fc2(c2), fs2(s2), fid2(invdet2);    
00205       Vec3F invdet2simd(fid2, -fid2, fid2, 0.f);
00206       Vec3F ccssimd(fs2, fc2, fc2, 0.f);
00207       Vec3F csssimd(fs2, fs2, fc2, 0.f);
00208       Vec3F l2simd; l2simd.set1(l2);
00209       Vec3F sigmap22simd; sigmap22simd.set1(si.sigmap22);
00210       Vec3F result = invdet2simd * (sigmap22simd * cslsimd + sigmap12simd * ccssimd * csssimd * l2simd);
00211       
00212       
00213       LocalError error(result.arr[0], result.arr[1], result.arr[2]);
00214       
00215       
00216       if((gluedDet->surface()).bounds().inside(position,error,scale_)){ //if it is inside the gluedet bonds
00217         
00218         //Change NSigmaInside in the configuration file to accept more hits
00219         //...and add it to the Rechit collection 
00220         
00221         collectorHelper.collector()(SiStripMatchedRecHit2D(LocalPoint(position), error,gluedDet->geographicalId() ,
00222                                                            &monoRH,si.secondHit));
00223       }
00224       
00225     } // loop on cache info
00226     
00227     collectorHelper.closure(monoRHiter);
00228   } // loop on mono hit
00229   
00230 }