CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/FastSimulation/TrackingRecHitProducer/src/GSRecHitMatcher.cc

Go to the documentation of this file.
00001 #include "FastSimulation/TrackingRecHitProducer/interface/GSRecHitMatcher.h"
00002 
00003 #include "DataFormats/DetId/interface/DetId.h"
00004 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00005 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00006 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00007 #include <cfloat>
00008 
00009 SiTrackerGSMatchedRecHit2D * GSRecHitMatcher::match(const SiTrackerGSRecHit2D *monoRH,
00010                                                     const SiTrackerGSRecHit2D *stereoRH,
00011                                                     const GluedGeomDet* gluedDet,
00012                                                     LocalVector& trackdirection) const
00013 {
00014 
00015 
00016   // stripdet = mono
00017   // partnerstripdet = stereo
00018   const GeomDetUnit* stripdet = gluedDet->monoDet();
00019   const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
00020   const StripTopology& topol=(const StripTopology&)stripdet->topology();
00021 
00022   LocalPoint position;    
00023 
00024   // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
00025   MeasurementPoint RPHIpoint=topol.measurementPosition(monoRH->localPosition());
00026   MeasurementPoint RPHIpointini=MeasurementPoint(RPHIpoint.x(),-0.5);
00027   MeasurementPoint RPHIpointend=MeasurementPoint(RPHIpoint.x(),0.5);
00028   
00029   // position of the initial and final point of the strip in local coordinates (mono det)
00030   StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
00031 
00032   if(trackdirection.mag2()<FLT_MIN){// in case of no track hypothesis assume a track from the origin through the center of the strip
00033     LocalPoint lcenterofstrip=monoRH->localPosition();
00034     GlobalPoint gcenterofstrip=(stripdet->surface()).toGlobal(lcenterofstrip);
00035     GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
00036     trackdirection=(gluedDet->surface()).toLocal(gtrackdirection);
00037   }
00038  
00039   //project mono hit on glued det
00040   StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
00041   const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
00042 
00043   //error calculation (the part that depends on mono RH only)
00044   LocalVector  RPHIpositiononGluedendvector=projectedstripmono.second-projectedstripmono.first;
00045   double c1=sin(RPHIpositiononGluedendvector.phi()); 
00046   double s1=-cos(RPHIpositiononGluedendvector.phi());
00047   MeasurementError errormonoRH=topol.measurementError(monoRH->localPosition(),monoRH->localPositionError());
00048   double pitch=topol.localPitch(monoRH->localPosition());
00049   double sigmap12=errormonoRH.uu()*pitch*pitch;
00050 
00051   // position of the initial and final point of the strip (STEREO cluster)
00052   MeasurementPoint STEREOpoint=partnertopol.measurementPosition(stereoRH->localPosition());
00053 
00054   MeasurementPoint STEREOpointini=MeasurementPoint(STEREOpoint.x(),-0.5);
00055   MeasurementPoint STEREOpointend=MeasurementPoint(STEREOpoint.x(),0.5);
00056 
00057   // position of the initial and final point of the strip in local coordinates (stereo det)
00058   StripPosition stripstereo(partnertopol.localPosition(STEREOpointini),partnertopol.localPosition(STEREOpointend));
00059 
00060   //project stereo hit on glued det
00061   StripPosition projectedstripstereo=project(partnerstripdet,gluedDet,stripstereo,trackdirection);
00062 
00063   //perform the matching
00064   //(x2-x1)(y-y1)=(y2-y1)(x-x1)
00065   AlgebraicMatrix22 m; AlgebraicVector2 c, solution;
00066   m(0,0)=-(projectedstripmono.second.y()-projectedstripmono.first.y()); m(0,1)=(projectedstripmono.second.x()-projectedstripmono.first.x());
00067   m(1,0)=-(projectedstripstereo.second.y()-projectedstripstereo.first.y()); m(1,1)=(projectedstripstereo.second.x()-projectedstripstereo.first.x());
00068   c(0)=m(0,1)*projectedstripmono.first.y()+m(0,0)*projectedstripmono.first.x();
00069   c(1)=m(1,1)*projectedstripstereo.first.y()+m(1,0)*projectedstripstereo.first.x();
00070   m.Invert(); solution = m * c;
00071   position=LocalPoint(solution(0),solution(1));
00072 
00073 
00074   //
00075   // temporary fix by tommaso
00076   //
00077 
00078 
00079   LocalError tempError (100,0,100);
00080 
00081   // calculate the error
00082   LocalVector  stereopositiononGluedendvector=projectedstripstereo.second-projectedstripstereo.first;
00083   double c2=sin(stereopositiononGluedendvector.phi()); double s2=-cos(stereopositiononGluedendvector.phi());
00084   MeasurementError errorstereoRH=partnertopol.measurementError(stereoRH->localPosition(), stereoRH->localPositionError());
00085   pitch=partnertopol.localPitch(stereoRH->localPosition());
00086   double sigmap22=errorstereoRH.uu()*pitch*pitch;
00087   double diff=(c1*s2-c2*s1);
00088   double invdet2=1/(diff*diff);
00089   float xx=invdet2*(sigmap12*s2*s2+sigmap22*s1*s1);
00090   float xy=-invdet2*(sigmap12*c2*s2+sigmap22*c1*s1);
00091   float yy=invdet2*(sigmap12*c2*c2+sigmap22*c1*c1);
00092   LocalError error=LocalError(xx,xy,yy);
00093 
00094  //  if((gluedDet->surface()).bounds().inside(position,error,3)){
00095 //     std::cout<<"  ERROR ok "<< std::endl;
00096 //   }
00097 //   else {
00098 //     std::cout<<" ERROR not ok " << std::endl;
00099 //   }
00100   
00101   //Added by DAO to make sure y positions are zero.
00102   DetId det(monoRH->geographicalId());
00103   if(det.subdetId() > 2) {
00104     SiTrackerGSRecHit2D *adjustedMonoRH = new SiTrackerGSRecHit2D(LocalPoint(monoRH->localPosition().x(),0,0),
00105                                                                   monoRH->localPositionError(),
00106                                                                   monoRH->geographicalId(),
00107                                                                   monoRH->simhitId(),
00108                                                                   monoRH->simtrackId(),
00109                                                                   monoRH->eeId(),
00110                                                                   monoRH->cluster(),
00111                                                                   monoRH->simMultX(),
00112                                                                   monoRH->simMultY()
00113                                                                   );
00114     
00115     SiTrackerGSRecHit2D *adjustedStereoRH = new SiTrackerGSRecHit2D(LocalPoint(stereoRH->localPosition().x(),0,0),
00116                                                                     stereoRH->localPositionError(),
00117                                                                     stereoRH->geographicalId(),
00118                                                                     stereoRH->simhitId(),
00119                                                                     stereoRH->simtrackId(),
00120                                                                     stereoRH->eeId(),
00121                                                                     stereoRH->cluster(),
00122                                                                     stereoRH->simMultX(),
00123                                                                     stereoRH->simMultY()
00124                                                                     );
00125     
00126     SiTrackerGSMatchedRecHit2D *rV= new SiTrackerGSMatchedRecHit2D(position, error,gluedDet->geographicalId(), monoRH->simhitId(), 
00127                                                                    monoRH->simtrackId(), monoRH->eeId(), monoRH->cluster(), 
00128                                                                    monoRH->simMultX(), monoRH->simMultY(), 
00129                                                                    true, adjustedMonoRH, adjustedStereoRH);
00130     delete adjustedMonoRH;
00131     delete adjustedStereoRH;
00132     return rV;
00133   }
00134   
00135   else {
00136     throw cms::Exception("GSRecHitMatcher") << "Matched Pixel!?";
00137   }
00138 }
00139 
00140 
00141 GSRecHitMatcher::StripPosition 
00142 GSRecHitMatcher::project(const GeomDetUnit *det,
00143                          const GluedGeomDet* glueddet,
00144                          const StripPosition& strip,
00145                          const LocalVector& trackdirection)const
00146 {
00147 
00148   GlobalPoint globalpointini=(det->surface()).toGlobal(strip.first);
00149   GlobalPoint globalpointend=(det->surface()).toGlobal(strip.second);
00150 
00151   // position of the initial and final point of the strip in glued local coordinates
00152   LocalPoint positiononGluedini=(glueddet->surface()).toLocal(globalpointini);
00153   LocalPoint positiononGluedend=(glueddet->surface()).toLocal(globalpointend);
00154 
00155   //correct the position with the track direction
00156 
00157   float scale=-positiononGluedini.z()/trackdirection.z();
00158 
00159   LocalPoint projpositiononGluedini= positiononGluedini + scale*trackdirection;
00160   LocalPoint projpositiononGluedend= positiononGluedend + scale*trackdirection;
00161 
00162   return StripPosition(projpositiononGluedini,projpositiononGluedend);
00163 }
00164 
00165 
00166 
00167 SiTrackerGSMatchedRecHit2D * GSRecHitMatcher::projectOnly( const SiTrackerGSRecHit2D *monoRH,
00168                                                     const GeomDet * monoDet,
00169                                                     const GluedGeomDet* gluedDet,
00170                                                     LocalVector& ldir) const
00171 {
00172   LocalPoint position(monoRH->localPosition().x(), 0.,0.);
00173   const BoundPlane& gluedPlane = gluedDet->surface();
00174   const BoundPlane& hitPlane = monoDet->surface();
00175 
00176   double delta = gluedPlane.localZ( hitPlane.position());
00177 
00178   LocalPoint lhitPos = gluedPlane.toLocal( monoDet->surface().toGlobal(position ) );
00179   LocalPoint projectedHitPos = lhitPos - ldir * delta/ldir.z();
00180 
00181   LocalVector hitXAxis = gluedPlane.toLocal( hitPlane.toGlobal( LocalVector(1,0,0)));
00182   LocalError hitErr = monoRH->localPositionError();
00183 
00184   if (gluedPlane.normalVector().dot( hitPlane.normalVector()) < 0) {
00185     // the two planes are inverted, and the correlation element must change sign
00186     hitErr = LocalError( hitErr.xx(), -hitErr.xy(), hitErr.yy());
00187   }
00188   LocalError rotatedError = hitErr.rotate( hitXAxis.x(), hitXAxis.y());
00189   
00190   
00191   const GeomDetUnit *gluedMonoDet = gluedDet->monoDet();
00192   const GeomDetUnit *gluedStereoDet = gluedDet->stereoDet();
00193   int isMono = 0;
00194   int isStereo = 0;
00195   
00196   if(monoDet->geographicalId()==gluedMonoDet->geographicalId()) isMono = 1;
00197   if(monoDet->geographicalId()==gluedStereoDet->geographicalId()) isStereo = 1;
00198   //Added by DAO to make sure y positions are zero and correct Mono or stereo Det is filled.
00199   
00200   //Good for debugging.
00201   //std::cout << "The monoDet = " << monoDet->geographicalId() << ". The gluedMonoDet = " << gluedMonoDet->geographicalId() << ". The gluedStereoDet = " << gluedStereoDet->geographicalId()
00202   //    << ". isMono = " << isMono << ". isStereo = " << isStereo <<"." << std::endl;
00203 
00204   SiTrackerGSRecHit2D *adjustedRH = new SiTrackerGSRecHit2D(LocalPoint(monoRH->localPosition().x(),0,0),
00205                                                             monoRH->localPositionError(),
00206                                                             monoRH->geographicalId(),
00207                                                             monoRH->simhitId(),
00208                                                             monoRH->simtrackId(),
00209                                                             monoRH->eeId(),
00210                                                             monoRH->cluster(),
00211                                                             monoRH->simMultX(),
00212                                                             monoRH->simMultY()
00213                                                             );
00214   
00215   //DAO: Not quite sure what to do about the cluster ref, so I will fill it with the monoRH for now...
00216   SiTrackerGSRecHit2D *otherRH = new SiTrackerGSRecHit2D(LocalPoint(-10000,-10000,-10000), LocalError(0,0,0),DetId(000000000), 0,0,0,monoRH->cluster(),0,0);
00217   if ((isMono && isStereo)||(!isMono&&!isStereo)) throw cms::Exception("GSRecHitMatcher") << "Something wrong with DetIds.";
00218   else if (isMono) {
00219     SiTrackerGSMatchedRecHit2D *rV= new SiTrackerGSMatchedRecHit2D(projectedHitPos, rotatedError, gluedDet->geographicalId(), 
00220                                                                    monoRH->simhitId(),  monoRH->simtrackId(), monoRH->eeId(), monoRH->cluster(),
00221                                                                    monoRH->simMultX(), monoRH->simMultY(), false, adjustedRH, otherRH);
00222     delete adjustedRH;
00223     delete otherRH;
00224     return rV;
00225   }
00226   
00227   else{
00228     SiTrackerGSMatchedRecHit2D *rV=new SiTrackerGSMatchedRecHit2D(projectedHitPos, rotatedError, gluedDet->geographicalId(), 
00229                                                                  monoRH->simhitId(),  monoRH->simtrackId(), monoRH->eeId(), monoRH->cluster(),
00230                                                                  monoRH->simMultX(), monoRH->simMultY(), false, otherRH, adjustedRH);
00231     delete adjustedRH;
00232     delete otherRH;
00233     return rV;
00234   }
00235 }