CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GSRecHitMatcher.cc
Go to the documentation of this file.
1 #include "GSRecHitMatcher.h"
2 
7 #include <cfloat>
8 
10  const SiTrackerGSRecHit2D *stereoRH,
11  const GluedGeomDet* gluedDet,
12  LocalVector& trackdirection) const
13 {
14 
15 
16  // stripdet = mono
17  // partnerstripdet = stereo
18  const GeomDetUnit* stripdet = gluedDet->monoDet();
19  const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
20  const StripTopology& topol=(const StripTopology&)stripdet->topology();
21 
23 
24  // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
25  MeasurementPoint RPHIpoint=topol.measurementPosition(monoRH->localPosition());
26  MeasurementPoint RPHIpointini=MeasurementPoint(RPHIpoint.x(),-0.5);
27  MeasurementPoint RPHIpointend=MeasurementPoint(RPHIpoint.x(),0.5);
28 
29  // position of the initial and final point of the strip in local coordinates (mono det)
30  StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
31 
32  if(trackdirection.mag2()<FLT_MIN){// in case of no track hypothesis assume a track from the origin through the center of the strip
33  LocalPoint lcenterofstrip=monoRH->localPosition();
34  GlobalPoint gcenterofstrip=(stripdet->surface()).toGlobal(lcenterofstrip);
35  GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
36  trackdirection=(gluedDet->surface()).toLocal(gtrackdirection);
37  }
38 
39  //project mono hit on glued det
40  StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
41  const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
42 
43  //error calculation (the part that depends on mono RH only)
44  LocalVector RPHIpositiononGluedendvector=projectedstripmono.second-projectedstripmono.first;
45  double c1=sin(RPHIpositiononGluedendvector.phi());
46  double s1=-cos(RPHIpositiononGluedendvector.phi());
47  MeasurementError errormonoRH=topol.measurementError(monoRH->localPosition(),monoRH->localPositionError());
48  double pitch=topol.localPitch(monoRH->localPosition());
49  double sigmap12=errormonoRH.uu()*pitch*pitch;
50 
51  // position of the initial and final point of the strip (STEREO cluster)
52  MeasurementPoint STEREOpoint=partnertopol.measurementPosition(stereoRH->localPosition());
53 
54  MeasurementPoint STEREOpointini=MeasurementPoint(STEREOpoint.x(),-0.5);
55  MeasurementPoint STEREOpointend=MeasurementPoint(STEREOpoint.x(),0.5);
56 
57  // position of the initial and final point of the strip in local coordinates (stereo det)
58  StripPosition stripstereo(partnertopol.localPosition(STEREOpointini),partnertopol.localPosition(STEREOpointend));
59 
60  //project stereo hit on glued det
61  StripPosition projectedstripstereo=project(partnerstripdet,gluedDet,stripstereo,trackdirection);
62 
63  //perform the matching
64  //(x2-x1)(y-y1)=(y2-y1)(x-x1)
66  m(0,0)=-(projectedstripmono.second.y()-projectedstripmono.first.y()); m(0,1)=(projectedstripmono.second.x()-projectedstripmono.first.x());
67  m(1,0)=-(projectedstripstereo.second.y()-projectedstripstereo.first.y()); m(1,1)=(projectedstripstereo.second.x()-projectedstripstereo.first.x());
68  c(0)=m(0,1)*projectedstripmono.first.y()+m(0,0)*projectedstripmono.first.x();
69  c(1)=m(1,1)*projectedstripstereo.first.y()+m(1,0)*projectedstripstereo.first.x();
70  m.Invert(); solution = m * c;
71  position=LocalPoint(solution(0),solution(1));
72 
73 
74  //
75  // temporary fix by tommaso
76  //
77 
78 
79  LocalError tempError (100,0,100);
80 
81  // calculate the error
82  LocalVector stereopositiononGluedendvector=projectedstripstereo.second-projectedstripstereo.first;
83  double c2=sin(stereopositiononGluedendvector.phi()); double s2=-cos(stereopositiononGluedendvector.phi());
84  MeasurementError errorstereoRH=partnertopol.measurementError(stereoRH->localPosition(), stereoRH->localPositionError());
85  pitch=partnertopol.localPitch(stereoRH->localPosition());
86  double sigmap22=errorstereoRH.uu()*pitch*pitch;
87  double diff=(c1*s2-c2*s1);
88  double invdet2=1/(diff*diff);
89  float xx=invdet2*(sigmap12*s2*s2+sigmap22*s1*s1);
90  float xy=-invdet2*(sigmap12*c2*s2+sigmap22*c1*s1);
91  float yy=invdet2*(sigmap12*c2*c2+sigmap22*c1*c1);
92  LocalError error=LocalError(xx,xy,yy);
93 
94  // if((gluedDet->surface()).bounds().inside(position,error,3)){
95 // std::cout<<" ERROR ok "<< std::endl;
96 // }
97 // else {
98 // std::cout<<" ERROR not ok " << std::endl;
99 // }
100 
101  //Added by DAO to make sure y positions are zero.
102  DetId det(monoRH->geographicalId());
103  if(det.subdetId() > 2) {
104  SiTrackerGSRecHit2D *adjustedMonoRH = new SiTrackerGSRecHit2D(LocalPoint(monoRH->localPosition().x(),0,0),
105  monoRH->localPositionError(),
106  *monoRH->det(),
107  monoRH->simhitId(),
108  monoRH->simtrackId(),
109  monoRH->eeId(),
110  monoRH->cluster(),
111  monoRH->simMultX(),
112  monoRH->simMultY()
113  );
114 
115  SiTrackerGSRecHit2D *adjustedStereoRH = new SiTrackerGSRecHit2D(LocalPoint(stereoRH->localPosition().x(),0,0),
116  stereoRH->localPositionError(),
117  *stereoRH->det(),
118  stereoRH->simhitId(),
119  stereoRH->simtrackId(),
120  stereoRH->eeId(),
121  stereoRH->cluster(),
122  stereoRH->simMultX(),
123  stereoRH->simMultY()
124  );
125 
126  SiTrackerGSMatchedRecHit2D *rV= new SiTrackerGSMatchedRecHit2D(position, error, *gluedDet, monoRH->simhitId(),
127  monoRH->simtrackId(), monoRH->eeId(), monoRH->cluster(),
128  monoRH->simMultX(), monoRH->simMultY(),
129  true, adjustedMonoRH, adjustedStereoRH);
130  delete adjustedMonoRH;
131  delete adjustedStereoRH;
132  return rV;
133  }
134 
135  else {
136  throw cms::Exception("GSRecHitMatcher") << "Matched Pixel!?";
137  }
138 }
139 
140 
143  const GluedGeomDet* glueddet,
144  const StripPosition& strip,
145  const LocalVector& trackdirection)const
146 {
147 
148  GlobalPoint globalpointini=(det->surface()).toGlobal(strip.first);
149  GlobalPoint globalpointend=(det->surface()).toGlobal(strip.second);
150 
151  // position of the initial and final point of the strip in glued local coordinates
152  LocalPoint positiononGluedini=(glueddet->surface()).toLocal(globalpointini);
153  LocalPoint positiononGluedend=(glueddet->surface()).toLocal(globalpointend);
154 
155  //correct the position with the track direction
156 
157  float scale=-positiononGluedini.z()/trackdirection.z();
158 
159  LocalPoint projpositiononGluedini= positiononGluedini + scale*trackdirection;
160  LocalPoint projpositiononGluedend= positiononGluedend + scale*trackdirection;
161 
162  return StripPosition(projpositiononGluedini,projpositiononGluedend);
163 }
164 
165 
166 
168  const GeomDet * monoDet,
169  const GluedGeomDet* gluedDet,
170  LocalVector& ldir) const
171 {
172  LocalPoint position(monoRH->localPosition().x(), 0.,0.);
173  const BoundPlane& gluedPlane = gluedDet->surface();
174  const BoundPlane& hitPlane = monoDet->surface();
175 
176  double delta = gluedPlane.localZ( hitPlane.position());
177 
178  LocalPoint lhitPos = gluedPlane.toLocal( monoDet->surface().toGlobal(position ) );
179  LocalPoint projectedHitPos = lhitPos - ldir * delta/ldir.z();
180 
181  LocalVector hitXAxis = gluedPlane.toLocal( hitPlane.toGlobal( LocalVector(1,0,0)));
182  LocalError hitErr = monoRH->localPositionError();
183 
184  if (gluedPlane.normalVector().dot( hitPlane.normalVector()) < 0) {
185  // the two planes are inverted, and the correlation element must change sign
186  hitErr = LocalError( hitErr.xx(), -hitErr.xy(), hitErr.yy());
187  }
188  LocalError rotatedError = hitErr.rotate( hitXAxis.x(), hitXAxis.y());
189 
190 
191  const GeomDetUnit *gluedMonoDet = gluedDet->monoDet();
192  const GeomDetUnit *gluedStereoDet = gluedDet->stereoDet();
193  int isMono = 0;
194  int isStereo = 0;
195 
196  if(monoDet->geographicalId()==gluedMonoDet->geographicalId()) isMono = 1;
197  if(monoDet->geographicalId()==gluedStereoDet->geographicalId()) isStereo = 1;
198  //Added by DAO to make sure y positions are zero and correct Mono or stereo Det is filled.
199 
200  auto otherDet = isMono ? gluedDet->stereoDet() : gluedDet->monoDet();
201  //Good for debugging.
202  //std::cout << "The monoDet = " << monoDet->geographicalId() << ". The gluedMonoDet = " << gluedMonoDet->geographicalId() << ". The gluedStereoDet = " << gluedStereoDet->geographicalId()
203  // << ". isMono = " << isMono << ". isStereo = " << isStereo <<"." << std::endl;
204 
205  SiTrackerGSRecHit2D *adjustedRH = new SiTrackerGSRecHit2D(LocalPoint(monoRH->localPosition().x(),0,0),
206  monoRH->localPositionError(),
207  *monoRH->det(),
208  monoRH->simhitId(),
209  monoRH->simtrackId(),
210  monoRH->eeId(),
211  monoRH->cluster(),
212  monoRH->simMultX(),
213  monoRH->simMultY()
214  );
215 
216  //DAO: Not quite sure what to do about the cluster ref, so I will fill it with the monoRH for now...
217  SiTrackerGSRecHit2D *otherRH = new SiTrackerGSRecHit2D(LocalPoint(-10000,-10000,-10000), LocalError(0,0,0),*otherDet, 0,0,0,monoRH->cluster(),0,0);
218  if ((isMono && isStereo)||(!isMono&&!isStereo)) throw cms::Exception("GSRecHitMatcher") << "Something wrong with DetIds.";
219  else if (isMono) {
220  SiTrackerGSMatchedRecHit2D *rV= new SiTrackerGSMatchedRecHit2D(projectedHitPos, rotatedError, *gluedDet,
221  monoRH->simhitId(), monoRH->simtrackId(), monoRH->eeId(), monoRH->cluster(),
222  monoRH->simMultX(), monoRH->simMultY(), false, adjustedRH, otherRH);
223  delete adjustedRH;
224  delete otherRH;
225  return rV;
226  }
227 
228  else{
229  SiTrackerGSMatchedRecHit2D *rV=new SiTrackerGSMatchedRecHit2D(projectedHitPos, rotatedError, *gluedDet,
230  monoRH->simhitId(), monoRH->simtrackId(), monoRH->eeId(), monoRH->cluster(),
231  monoRH->simMultX(), monoRH->simMultY(), false, otherRH, adjustedRH);
232  delete adjustedRH;
233  delete otherRH;
234  return rV;
235  }
236 }
dbl * delta
Definition: mlp_gen.cc:36
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
float xx() const
Definition: LocalError.h:24
T mag2() const
Definition: PV3DBase.h:66
const int & simhitId() const
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
SiTrackerGSMatchedRecHit2D * match(const SiTrackerGSRecHit2D *monoRH, const SiTrackerGSRecHit2D *stereoRH, const GluedGeomDet *gluedDet, LocalVector &trackdirection) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepStd< double, 2, 2 > > AlgebraicMatrix22
tuple s2
Definition: indexGen.py:106
const int & simtrackId() const
virtual const Topology & topology() const =0
virtual float localPitch(const LocalPoint &) const =0
float xy() const
Definition: LocalError.h:25
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
std::pair< LocalPoint, LocalPoint > StripPosition
virtual LocalError localPositionError() const GCC11_FINAL
virtual MeasurementError measurementError(const LocalPoint &, const LocalError &) const =0
float yy() const
Definition: LocalError.h:26
const GeomDet * det() const
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:72
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
const int & simMultX() const
Definition: DetId.h:18
const uint32_t & eeId() const
const int & simMultY() const
SiTrackerGSMatchedRecHit2D * projectOnly(const SiTrackerGSRecHit2D *monoRH, const GeomDet *monoDet, const GluedGeomDet *gluedDet, LocalVector &ldir) const
StripPosition project(const GeomDetUnit *det, const GluedGeomDet *glueddet, const StripPosition &strip, const LocalVector &trackdirection) const
ClusterRef const & cluster() const
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
virtual LocalPoint localPosition(float strip) const =0
DetId geographicalId() const
LocalError rotate(float x, float y) const
Return a new LocalError, rotated by an angle defined by the direction (x,y)
Definition: LocalError.h:39
T x() const
Definition: PV2DBase.h:45
virtual LocalPoint localPosition() const GCC11_FINAL
T x() const
Definition: PV3DBase.h:62
ROOT::Math::SVector< double, 2 > AlgebraicVector2
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21