00001
00002
00003
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 "TrackingTools/TransientTrackingRecHit/interface/HelpertRecHit2DLocalPos.h"
00011 #include<boost/bind.hpp>
00012
00013 #include <DataFormats/TrackingRecHit/interface/AlignmentPositionError.h>
00014
00015
00016
00017
00018 SiStripRecHitMatcher::SiStripRecHitMatcher(const edm::ParameterSet& conf){
00019 scale_=conf.getParameter<double>("NSigmaInside");
00020 }
00021
00022 SiStripRecHitMatcher::SiStripRecHitMatcher(const double theScale){
00023 scale_=theScale;
00024 }
00025
00026
00027
00028 SiStripMatchedRecHit2D * SiStripRecHitMatcher::match(const SiStripRecHit2D *monoRH,
00029 const SiStripRecHit2D *stereoRH,
00030 const GluedGeomDet* gluedDet,
00031 LocalVector trackdirection) const{
00032 SimpleHitCollection stereoHits(1,stereoRH);
00033 std::vector<SiStripMatchedRecHit2D*> collection;
00034 match( monoRH,
00035 stereoHits.begin(), stereoHits.end(),
00036 collection,
00037 gluedDet,trackdirection);
00038
00039 return collection.empty() ? (SiStripMatchedRecHit2D*)(0) : collection.front();
00040 }
00041
00042
00043 SiStripMatchedRecHit2D* SiStripRecHitMatcher::match(const SiStripMatchedRecHit2D *origRH,
00044 const GluedGeomDet* gluedDet,
00045 LocalVector trackdirection) const{
00046
00047 const SiStripRecHit2D* theMonoRH = origRH->monoHit();
00048
00049 SimpleHitCollection theStereoHits(1, origRH->stereoHit());
00050
00051
00052 std::vector<SiStripMatchedRecHit2D*> collection;
00053 match( theMonoRH,
00054 theStereoHits.begin(), theStereoHits.end(),
00055 collection,
00056 gluedDet,trackdirection);
00057
00058 return collection.empty() ? (SiStripMatchedRecHit2D*)(0) : collection.front();
00059
00060 }
00061
00062
00063 edm::OwnVector<SiStripMatchedRecHit2D>
00064 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00065 RecHitIterator begin, RecHitIterator end,
00066 const GluedGeomDet* gluedDet,
00067 LocalVector trackdirection) const
00068 {
00069 SimpleHitCollection stereoHits;
00070 stereoHits.reserve(end-begin);
00071
00072 for (RecHitIterator i=begin; i != end; ++i) {
00073 stereoHits.push_back( &(*i));
00074 }
00075 return match( monoRH,
00076 stereoHits.begin(), stereoHits.end(),
00077 gluedDet,trackdirection);
00078 }
00079
00080 edm::OwnVector<SiStripMatchedRecHit2D>
00081 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00082 SimpleHitIterator begin, SimpleHitIterator end,
00083 const GluedGeomDet* gluedDet,
00084 LocalVector trackdirection) const {
00085 edm::OwnVector<SiStripMatchedRecHit2D> collector;
00086 collector.reserve(end-begin);
00087 match(monoRH,begin,end,collector,gluedDet,trackdirection);
00088 return collector;
00089 }
00090
00091
00092 void
00093 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00094 SimpleHitIterator begin, SimpleHitIterator end,
00095 edm::OwnVector<SiStripMatchedRecHit2D> & collector,
00096 const GluedGeomDet* gluedDet,
00097 LocalVector trackdirection) const {
00098
00099 std::vector<SiStripMatchedRecHit2D*> result;
00100 result.reserve(end-begin);
00101 match(monoRH,begin,end,result,gluedDet,trackdirection);
00102 for (std::vector<SiStripMatchedRecHit2D*>::iterator p=result.begin(); p!=result.end();
00103 p++) collector.push_back(*p);
00104 }
00105
00106 namespace {
00107
00108 inline void pb(std::vector<SiStripMatchedRecHit2D*> & v, SiStripMatchedRecHit2D* h) {
00109 v.push_back(h);
00110 }
00111 }
00112
00113 void
00114 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00115 SimpleHitIterator begin, SimpleHitIterator end,
00116 std::vector<SiStripMatchedRecHit2D*> & collector,
00117 const GluedGeomDet* gluedDet,
00118 LocalVector trackdirection) const {
00119 Collector result(boost::bind(&pb,boost::ref(collector),
00120 boost::bind(&SiStripMatchedRecHit2D::clone,_1)));
00121 match(monoRH,begin,end,result,gluedDet,trackdirection);
00122 }
00123
00124
00125
00126 void
00127 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00128 RecHitIterator begin, RecHitIterator end,
00129 CollectorMatched & collector,
00130 const GluedGeomDet* gluedDet,
00131 LocalVector trackdirection) const {
00132
00133
00134 SimpleHitCollection stereoHits;
00135 stereoHits.reserve(end-begin);
00136 for (RecHitIterator i=begin; i != end; ++i)
00137 stereoHits.push_back( &(*i));
00138
00139 return match( monoRH,
00140 stereoHits.begin(), stereoHits.end(),
00141 collector,
00142 gluedDet,trackdirection);
00143 }
00144
00145 void
00146 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00147 SimpleHitIterator begin, SimpleHitIterator end,
00148 CollectorMatched & collector,
00149 const GluedGeomDet* gluedDet,
00150 LocalVector trackdirection) const {
00151
00152 Collector result(boost::bind(&CollectorMatched::push_back,boost::ref(collector),_1));
00153 match(monoRH,begin,end,result,gluedDet,trackdirection);
00154
00155 }
00156
00157
00158
00159 void
00160 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
00161 SimpleHitIterator begin, SimpleHitIterator end,
00162 Collector & collector,
00163 const GluedGeomDet* gluedDet,
00164 LocalVector trackdirection) const {
00165
00166
00167 const GeomDetUnit* stripdet = gluedDet->monoDet();
00168 const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
00169 const StripTopology& topol=(const StripTopology&)stripdet->topology();
00170
00171
00172 double RPHIpointX = topol.measurementPosition(monoRH->localPositionFast()).x();
00173 MeasurementPoint RPHIpointini(RPHIpointX,-0.5);
00174 MeasurementPoint RPHIpointend(RPHIpointX,0.5);
00175
00176
00177 StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
00178
00179 if(trackdirection.mag2()<FLT_MIN){
00180 LocalPoint lcenterofstrip=monoRH->localPositionFast();
00181 GlobalPoint gcenterofstrip=(stripdet->surface()).toGlobal(lcenterofstrip);
00182 GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
00183 trackdirection=(gluedDet->surface()).toLocal(gtrackdirection);
00184 }
00185
00186
00187 StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
00188 const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
00189
00190 double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y());
00191 double m01 = (projectedstripmono.second.x()-projectedstripmono.first.x());
00192 double c0 = m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
00193
00194
00195
00196
00197
00198
00199
00200
00201 double c1 = -m00;
00202 double s1 = -m01;
00203 double l1 = 1./(c1*c1+s1*s1);
00204
00205
00206
00207 double sigmap12 = monoRH->sigmaPitch();
00208 if (sigmap12<0) {
00209
00210
00211
00212
00213
00214
00215
00216
00217 LocalError tmpError(monoRH->localPositionErrorFast());
00218 HelpertRecHit2DLocalPos::updateWithAPE(tmpError,*stripdet);
00219 MeasurementError errormonoRH=topol.measurementError(monoRH->localPositionFast(),tmpError);
00220
00221
00222
00223
00224
00225
00226
00227 double pitch=topol.localPitch(monoRH->localPositionFast());
00228 monoRH->setSigmaPitch(sigmap12=errormonoRH.uu()*pitch*pitch);
00229 }
00230
00231 SimpleHitIterator seconditer;
00232
00233 for(seconditer=begin;seconditer!=end;++seconditer){
00234
00235
00236 double STEREOpointX=partnertopol.measurementPosition((*seconditer)->localPositionFast()).x();
00237 MeasurementPoint STEREOpointini(STEREOpointX,-0.5);
00238 MeasurementPoint STEREOpointend(STEREOpointX,0.5);
00239
00240
00241 StripPosition stripstereo(partnertopol.localPosition(STEREOpointini),partnertopol.localPosition(STEREOpointend));
00242
00243
00244 StripPosition projectedstripstereo=project(partnerstripdet,gluedDet,stripstereo,trackdirection);
00245
00246
00247 double m10=-(projectedstripstereo.second.y()-projectedstripstereo.first.y());
00248 double m11=(projectedstripstereo.second.x()-projectedstripstereo.first.x());
00249
00250
00251
00252 AlgebraicMatrix22 m; AlgebraicVector2 c;
00253 m(0,0)=m00;
00254 m(0,1)=m01;
00255 m(1,0)=m10;
00256 m(1,1)=m11;
00257 c(0)=c0;
00258 c(1)=m11*projectedstripstereo.first.y()+m10*projectedstripstereo.first.x();
00259 m.Invert();
00260 AlgebraicVector2 solution = m * c;
00261 LocalPoint position(solution(0),solution(1));
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 LocalError tempError (100,0,100);
00282 if (!((gluedDet->surface()).bounds().inside(position,tempError,scale_))) continue;
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 double c2 = -m10;
00293 double s2 = -m11;
00294 double l2 = 1./(c2*c2+s2*s2);
00295
00296
00297
00298 double sigmap22 = (*seconditer)->sigmaPitch();
00299 if (sigmap22<0) {
00300
00301 LocalError tmpError((*seconditer)->localPositionErrorFast());
00302 HelpertRecHit2DLocalPos::updateWithAPE(tmpError, *partnerstripdet);
00303 MeasurementError errorstereoRH=partnertopol.measurementError((*seconditer)->localPositionFast(),tmpError);
00304
00305 double pitch=partnertopol.localPitch((*seconditer)->localPositionFast());
00306 (*seconditer)->setSigmaPitch(sigmap22=errorstereoRH.uu()*pitch*pitch);
00307 }
00308
00309 double diff=(c1*s2-c2*s1);
00310 double invdet2=1/(diff*diff*l1*l2);
00311 float xx= invdet2*(sigmap12*s2*s2*l2+sigmap22*s1*s1*l1);
00312 float xy=-invdet2*(sigmap12*c2*s2*l2+sigmap22*c1*s1*l1);
00313 float yy= invdet2*(sigmap12*c2*c2*l2+sigmap22*c1*c1*l1);
00314 LocalError error(xx,xy,yy);
00315
00316 if((gluedDet->surface()).bounds().inside(position,error,scale_)){
00317
00318
00319
00320 const SiStripRecHit2D* secondHit = *seconditer;
00321 collector(SiStripMatchedRecHit2D(position, error,gluedDet->geographicalId() ,
00322 monoRH,secondHit));
00323 }
00324 }
00325 }
00326
00327
00328 SiStripRecHitMatcher::StripPosition SiStripRecHitMatcher::project(const GeomDetUnit *det,const GluedGeomDet* glueddet,StripPosition strip,LocalVector trackdirection)const
00329 {
00330
00331 GlobalPoint globalpointini=(det->surface()).toGlobal(strip.first);
00332 GlobalPoint globalpointend=(det->surface()).toGlobal(strip.second);
00333
00334
00335 LocalPoint positiononGluedini=(glueddet->surface()).toLocal(globalpointini);
00336 LocalPoint positiononGluedend=(glueddet->surface()).toLocal(globalpointend);
00337
00338
00339
00340 float scale=-positiononGluedini.z()/trackdirection.z();
00341
00342 LocalPoint projpositiononGluedini= positiononGluedini + scale*trackdirection;
00343 LocalPoint projpositiononGluedend= positiononGluedend + scale*trackdirection;
00344
00345 return StripPosition(projpositiononGluedini,projpositiononGluedend);
00346 }