CMS 3D CMS Logo

SiStripRecHitMatcher.cc

Go to the documentation of this file.
00001 // File: SiStripRecHitMatcher.cc
00002 // Description:  Matches into rechits
00003 // Author:  C.Genta
00004 #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
00005 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00006 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00007 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00008 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
00009 
00010 #include<boost/bind.hpp>
00011 
00012 
00013 
00014 SiStripRecHitMatcher::SiStripRecHitMatcher(const edm::ParameterSet& conf){   
00015   scale_=conf.getParameter<double>("NSigmaInside");  
00016 }
00017 
00018 SiStripRecHitMatcher::SiStripRecHitMatcher(const double theScale){   
00019   scale_=theScale;  
00020 }
00021 
00022 
00023 //match a single hit
00024 SiStripMatchedRecHit2D * SiStripRecHitMatcher::match(const SiStripRecHit2D *monoRH, 
00025                                                      const SiStripRecHit2D *stereoRH,
00026                                                      const GluedGeomDet* gluedDet,
00027                                                      LocalVector trackdirection) const{
00028   SimpleHitCollection stereoHits(1,stereoRH);
00029   std::vector<SiStripMatchedRecHit2D*>  collection;
00030   match( monoRH,
00031          stereoHits.begin(), stereoHits.end(),
00032          collection,
00033          gluedDet,trackdirection);
00034   
00035   return collection.empty() ? (SiStripMatchedRecHit2D*)(0) : collection.front();
00036 }
00037 
00038 //repeat matching for an already  a single hit
00039 SiStripMatchedRecHit2D* SiStripRecHitMatcher::match(const SiStripMatchedRecHit2D *origRH, 
00040                                                     const GluedGeomDet* gluedDet,
00041                                                     LocalVector trackdirection) const{
00042   
00043   const SiStripRecHit2D* theMonoRH   = origRH->monoHit();
00044   // const SiStripRecHit2D* theStereoRH = origRH->stereoHit();
00045   SimpleHitCollection theStereoHits(1, origRH->stereoHit());
00046   // theStereoHits.push_back(theStereoRH);
00047   
00048   std::vector<SiStripMatchedRecHit2D*>  collection;
00049   match( theMonoRH,
00050          theStereoHits.begin(), theStereoHits.end(),
00051          collection,
00052          gluedDet,trackdirection);
00053   
00054   return collection.empty() ? (SiStripMatchedRecHit2D*)(0) : collection.front();
00055   
00056 }
00057 
00058 
00059 edm::OwnVector<SiStripMatchedRecHit2D> 
00060 SiStripRecHitMatcher::match( const  SiStripRecHit2D *monoRH,
00061                              RecHitIterator begin, RecHitIterator end, 
00062                              const GluedGeomDet* gluedDet,
00063                              LocalVector trackdirection) const
00064 {
00065   SimpleHitCollection stereoHits;
00066   stereoHits.reserve(end-begin);
00067 
00068   for (RecHitIterator i=begin; i != end; ++i) {
00069     stereoHits.push_back( &(*i)); // convert to simple pointer
00070   }
00071   return match( monoRH,
00072                 stereoHits.begin(), stereoHits.end(), 
00073                 gluedDet,trackdirection);
00074 }
00075 
00076 edm::OwnVector<SiStripMatchedRecHit2D> 
00077 SiStripRecHitMatcher::match( const  SiStripRecHit2D *monoRH,
00078                              SimpleHitIterator begin, SimpleHitIterator end,
00079                              const GluedGeomDet* gluedDet,
00080                              LocalVector trackdirection) const {
00081   edm::OwnVector<SiStripMatchedRecHit2D> collector;
00082   collector.reserve(end-begin); // a resonable estimate of its size... 
00083   match(monoRH,begin,end,collector,gluedDet,trackdirection);
00084   return collector;
00085 }
00086 
00087 
00088 void
00089 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00090                              SimpleHitIterator begin, SimpleHitIterator end,
00091                              edm::OwnVector<SiStripMatchedRecHit2D> & collector, 
00092                              const GluedGeomDet* gluedDet,
00093                              LocalVector trackdirection) const {
00094 
00095   std::vector<SiStripMatchedRecHit2D*> result;
00096   result.reserve(end-begin);
00097   match(monoRH,begin,end,result,gluedDet,trackdirection);
00098   for (std::vector<SiStripMatchedRecHit2D*>::iterator p=result.begin(); p!=result.end();
00099        p++) collector.push_back(*p);
00100 }
00101 
00102 void
00103 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00104                              SimpleHitIterator begin, SimpleHitIterator end,
00105                              std::vector<SiStripMatchedRecHit2D*> & collector, 
00106                              const GluedGeomDet* gluedDet,
00107                              LocalVector trackdirection) const {
00108   Collector result(boost::bind(&std::vector<SiStripMatchedRecHit2D*>::push_back,boost::ref(collector),
00109                              boost::bind(&SiStripMatchedRecHit2D::clone,_1)));
00110   match(monoRH,begin,end,result,gluedDet,trackdirection);
00111 }
00112 
00113 
00114 // this is the one used by the RecHitConverter
00115 void
00116 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00117                              RecHitIterator begin, RecHitIterator end,
00118                              CollectorMatched & collector,
00119                              const GluedGeomDet* gluedDet,
00120                              LocalVector trackdirection) const {
00121   
00122   // is this really needed now????
00123   SimpleHitCollection stereoHits;
00124   stereoHits.reserve(end-begin);
00125   for (RecHitIterator i=begin; i != end; ++i) 
00126     stereoHits.push_back( &(*i)); // convert to simple pointer
00127   
00128   return match( monoRH,
00129                 stereoHits.begin(), stereoHits.end(),
00130                 collector,
00131                 gluedDet,trackdirection);
00132 }
00133 
00134 void
00135 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00136                              SimpleHitIterator begin, SimpleHitIterator end,
00137                              CollectorMatched & collector,
00138                              const GluedGeomDet* gluedDet,
00139                              LocalVector trackdirection) const {
00140 
00141   Collector result(boost::bind(&CollectorMatched::push_back,boost::ref(collector),_1));
00142   match(monoRH,begin,end,result,gluedDet,trackdirection);
00143   
00144 }
00145 
00146 
00147 // the "real implementation"
00148 void
00149 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00150                              SimpleHitIterator begin, SimpleHitIterator end,
00151                              Collector & collector, 
00152                              const GluedGeomDet* gluedDet,
00153                              LocalVector trackdirection) const {
00154   // stripdet = mono
00155   // partnerstripdet = stereo
00156   const GeomDetUnit* stripdet = gluedDet->monoDet();
00157   const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
00158   const StripTopology& topol=(const StripTopology&)stripdet->topology();
00159 
00160   // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
00161   double RPHIpointX = topol.measurementPosition(monoRH->localPosition()).x();
00162   MeasurementPoint RPHIpointini(RPHIpointX,-0.5);
00163   MeasurementPoint RPHIpointend(RPHIpointX,0.5);
00164 
00165   // position of the initial and final point of the strip in local coordinates (mono det)
00166   StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
00167 
00168   if(trackdirection.mag2()<FLT_MIN){// in case of no track hypothesis assume a track from the origin through the center of the strip
00169     LocalPoint lcenterofstrip=monoRH->localPosition();
00170     GlobalPoint gcenterofstrip=(stripdet->surface()).toGlobal(lcenterofstrip);
00171     GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
00172     trackdirection=(gluedDet->surface()).toLocal(gtrackdirection);
00173   }
00174 
00175   //project mono hit on glued det
00176   StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
00177   const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
00178 
00179   double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y()); 
00180   double m01 =  (projectedstripmono.second.x()-projectedstripmono.first.x());
00181   double c0  =  m01*projectedstripmono.first.y()   + m00*projectedstripmono.first.x();
00182  
00183   //error calculation (the part that depends on mono RH only)
00184   //  LocalVector  RPHIpositiononGluedendvector=projectedstripmono.second-projectedstripmono.first;
00185   /*
00186   double l1 = 1./RPHIpositiononGluedendvector.perp2();
00187   double c1 = RPHIpositiononGluedendvector.y();
00188   double s1 =-RPHIpositiononGluedendvector.x();
00189   */
00190   double c1 = -m00;
00191   double s1 = -m01;
00192   double l1 = 1./(c1*c1+s1*s1);
00193 
00194  
00195   // FIXME: here for test...
00196   double sigmap12 = monoRH->sigmaPitch();
00197   if (sigmap12<0) {
00198     MeasurementError errormonoRH=topol.measurementError(monoRH->localPosition(),monoRH->localPositionError());
00199     double pitch=topol.localPitch(monoRH->localPosition());
00200     monoRH->setSigmaPitch(sigmap12=errormonoRH.uu()*pitch*pitch);
00201   }
00202 
00203   SimpleHitIterator seconditer;  
00204 
00205   for(seconditer=begin;seconditer!=end;++seconditer){//iterate on stereo rechits
00206 
00207     // position of the initial and final point of the strip (STEREO cluster)
00208     double STEREOpointX=partnertopol.measurementPosition((*seconditer)->localPosition()).x();
00209     MeasurementPoint STEREOpointini(STEREOpointX,-0.5);
00210     MeasurementPoint STEREOpointend(STEREOpointX,0.5);
00211 
00212     // position of the initial and final point of the strip in local coordinates (stereo det)
00213     StripPosition stripstereo(partnertopol.localPosition(STEREOpointini),partnertopol.localPosition(STEREOpointend));
00214  
00215     //project stereo hit on glued det
00216     StripPosition projectedstripstereo=project(partnerstripdet,gluedDet,stripstereo,trackdirection);
00217 
00218  
00219     double m10=-(projectedstripstereo.second.y()-projectedstripstereo.first.y()); 
00220     double m11=(projectedstripstereo.second.x()-projectedstripstereo.first.x());
00221 
00222    //perform the matching
00223    //(x2-x1)(y-y1)=(y2-y1)(x-x1)
00224     AlgebraicMatrix22 m; AlgebraicVector2 c;
00225     m(0,0)=m00; 
00226     m(0,1)=m01;
00227     m(1,0)=m10;
00228     m(1,1)=m11;
00229     c(0)=c0;
00230     c(1)=m11*projectedstripstereo.first.y()+m10*projectedstripstereo.first.x();
00231     m.Invert(); 
00232     AlgebraicVector2 solution = m * c;
00233     LocalPoint position(solution(0),solution(1));
00234 
00235     /*
00236     {
00237       double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y()); 
00238       double m01 =  (projectedstripmono.second.x()-projectedstripmono.first.x());
00239       double m10 = -(projectedstripstereo.second.y()-projectedstripstereo.first.y()); 
00240       double m11 =  (projectedstripstereo.second.x()-projectedstripstereo.first.x());
00241       double c0  =  m01*projectedstripmono.first.y()   + m00*projectedstripmono.first.x();
00242       double c1  =  m11*projectedstripstereo.first.y() + m10*projectedstripstereo.first.x();
00243       
00244       double invDet = 1./(m00*m11-m10*m01);
00245     }
00246     */
00247 
00248     //
00249     // temporary fix by tommaso
00250     //
00251 
00252 
00253     LocalError tempError (100,0,100);
00254     if (!((gluedDet->surface()).bounds().inside(position,tempError,scale_))) continue;                                                       
00255 
00256     // then calculate the error
00257     /*
00258     LocalVector  stereopositiononGluedendvector=projectedstripstereo.second-projectedstripstereo.first;
00259     double l2 = 1./stereopositiononGluedendvector.perp2();
00260     double c2 = stereopositiononGluedendvector.y(); 
00261     double s2 =-stereopositiononGluedendvector.x();
00262     */
00263 
00264     double c2 = -m10;
00265     double s2 = -m11;
00266     double l2 = 1./(c2*c2+s2*s2);
00267 
00268 
00269     // FIXME: here for test...
00270     double sigmap22 = (*seconditer)->sigmaPitch();
00271     if (sigmap22<0) {
00272       MeasurementError errorstereoRH=partnertopol.measurementError((*seconditer)->localPosition(),(*seconditer)->localPositionError());
00273       double pitch=partnertopol.localPitch((*seconditer)->localPosition());
00274       (*seconditer)->setSigmaPitch(sigmap22=errorstereoRH.uu()*pitch*pitch);
00275     }
00276 
00277     double diff=(c1*s2-c2*s1);
00278     double invdet2=1/(diff*diff*l1*l2);
00279     float xx=invdet2*(sigmap12*s2*s2*l2+sigmap22*s1*s1*l1);
00280     float xy=-invdet2*(sigmap12*c2*s2*l2+sigmap22*c1*s1*l1);
00281     float yy=invdet2*(sigmap12*c2*c2*l2+sigmap22*c1*c1*l1);
00282     LocalError error(xx,xy,yy);
00283 
00284     if((gluedDet->surface()).bounds().inside(position,error,scale_)){ //if it is inside the gluedet bonds
00285       //Change NSigmaInside in the configuration file to accept more hits
00286       //...and add it to the Rechit collection 
00287 
00288       const SiStripRecHit2D* secondHit = *seconditer;
00289       collector(SiStripMatchedRecHit2D(position, error,gluedDet->geographicalId() ,
00290                                        monoRH,secondHit));
00291     }
00292   }
00293 }
00294 
00295 
00296 SiStripRecHitMatcher::StripPosition SiStripRecHitMatcher::project(const GeomDetUnit *det,const GluedGeomDet* glueddet,StripPosition strip,LocalVector trackdirection)const
00297 {
00298 
00299   GlobalPoint globalpointini=(det->surface()).toGlobal(strip.first);
00300   GlobalPoint globalpointend=(det->surface()).toGlobal(strip.second);
00301 
00302   // position of the initial and final point of the strip in glued local coordinates
00303   LocalPoint positiononGluedini=(glueddet->surface()).toLocal(globalpointini);
00304   LocalPoint positiononGluedend=(glueddet->surface()).toLocal(globalpointend);
00305 
00306   //correct the position with the track direction
00307 
00308   float scale=-positiononGluedini.z()/trackdirection.z();
00309 
00310   LocalPoint projpositiononGluedini= positiononGluedini + scale*trackdirection;
00311   LocalPoint projpositiononGluedend= positiononGluedend + scale*trackdirection;
00312 
00313   return StripPosition(projpositiononGluedini,projpositiononGluedend);
00314 }

Generated on Tue Jun 9 17:44:01 2009 for CMSSW by  doxygen 1.5.4