CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripRecHitMatcher.cc
Go to the documentation of this file.
1 // File: SiStripRecHitMatcher.cc
2 // Description: Matches into rechits
3 // Author: C.Genta
9 
11 #include<boost/bind.hpp>
12 
14 
15 
16 
17 
19  scale_(conf.getParameter<double>("NSigmaInside")),
20  preFilter_(conf.existsAs<bool>("PreFilter") ? conf.getParameter<bool>("PreFilter") : false)
21  {}
22 
24  scale_(theScale){}
25 
26 
27 
28 namespace {
29  // FIXME for c++0X
30  inline void pb1(std::vector<SiStripMatchedRecHit2D*> & v, SiStripMatchedRecHit2D* h) {
31  v.push_back(h);
32  }
33  inline void pb2(SiStripRecHitMatcher::CollectorMatched & v, const SiStripMatchedRecHit2D & h) {
34  v.push_back(h);
35  }
36 
37 }
38 
39 
40 // needed by the obsolete version still in use on some architectures
41 void
42 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
45  const GluedGeomDet* gluedDet,
46  LocalVector trackdirection) const {
47 
48  std::vector<SiStripMatchedRecHit2D*> result;
49  result.reserve(end-begin);
50  match(monoRH,begin,end,result,gluedDet,trackdirection);
51  for (std::vector<SiStripMatchedRecHit2D*>::iterator p=result.begin(); p!=result.end();
52  p++) collector.push_back(*p);
53 }
54 
55 
56 void
57 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
59  std::vector<SiStripMatchedRecHit2D*> & collector,
60  const GluedGeomDet* gluedDet,
61  LocalVector trackdirection) const {
62  Collector result(boost::bind(&pb1,boost::ref(collector),
63  boost::bind(&SiStripMatchedRecHit2D::clone,_1)));
64  match(monoRH,begin,end,result,gluedDet,trackdirection);
65 }
66 
67 void
68 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
70  CollectorMatched & collector,
71  const GluedGeomDet* gluedDet,
72  LocalVector trackdirection) const {
73 
74  Collector result(boost::bind(pb2,boost::ref(collector),_1));
75  match(monoRH,begin,end,result,gluedDet,trackdirection);
76 
77 }
78 
79 
80 
81 // this is the one used by the RecHitConverter
82 void
83 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
85  CollectorMatched & collector,
86  const GluedGeomDet* gluedDet,
87  LocalVector trackdirection) const {
88 
89  // is this really needed now????
90  SimpleHitCollection stereoHits;
91  stereoHits.reserve(end-begin);
92  for (RecHitIterator i=begin; i != end; ++i)
93  stereoHits.push_back( &(*i)); // convert to simple pointer
94 
95  return match( monoRH,
96  stereoHits.begin(), stereoHits.end(),
97  collector,
98  gluedDet,trackdirection);
99 }
100 
101 
102 
103 // the "real implementation"
104 void
105 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
107  Collector & collector,
108  const GluedGeomDet* gluedDet,
109  LocalVector trackdirection) const {
110  // stripdet = mono
111  // partnerstripdet = stereo
112  const GeomDetUnit* stripdet = gluedDet->monoDet();
113  const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
114  const StripTopology& topol=(const StripTopology&)stripdet->topology();
115 
116  // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
117  double RPHIpointX = topol.measurementPosition(monoRH->localPositionFast()).x();
118  MeasurementPoint RPHIpointini(RPHIpointX,-0.5);
119  MeasurementPoint RPHIpointend(RPHIpointX,0.5);
120 
121  // position of the initial and final point of the strip in local coordinates (mono det)
122  StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
123 
124  if(trackdirection.mag2()<FLT_MIN){// in case of no track hypothesis assume a track from the origin through the center of the strip
125  LocalPoint lcenterofstrip=monoRH->localPositionFast();
126  GlobalPoint gcenterofstrip=(stripdet->surface()).toGlobal(lcenterofstrip);
127  GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
128  trackdirection=(gluedDet->surface()).toLocal(gtrackdirection);
129  }
130 
131  //project mono hit on glued det
132  StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
133  const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
134 
135  double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y());
136  double m01 = (projectedstripmono.second.x()-projectedstripmono.first.x());
137  double c0 = m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
138 
139  //error calculation (the part that depends on mono RH only)
140  // LocalVector RPHIpositiononGluedendvector=projectedstripmono.second-projectedstripmono.first;
141  /*
142  double l1 = 1./RPHIpositiononGluedendvector.perp2();
143  double c1 = RPHIpositiononGluedendvector.y();
144  double s1 =-RPHIpositiononGluedendvector.x();
145  */
146  double c1 = -m00;
147  double s1 = -m01;
148  double l1 = 1./(c1*c1+s1*s1);
149 
150 
151  float sigmap12 = sigmaPitch(monoRH->localPosition(), monoRH->localPositionError(),topol);
152  // auto sigmap12 = monoRH->sigmaPitch();
153  // assert(sigmap12>=0);
154 
155 
156  SimpleHitIterator seconditer;
157 
158  for(seconditer=begin;seconditer!=end;++seconditer){//iterate on stereo rechits
159 
160  // position of the initial and final point of the strip (STEREO cluster)
161  double STEREOpointX=partnertopol.measurementPosition((*seconditer)->localPositionFast()).x();
162  MeasurementPoint STEREOpointini(STEREOpointX,-0.5);
163  MeasurementPoint STEREOpointend(STEREOpointX,0.5);
164 
165  // position of the initial and final point of the strip in local coordinates (stereo det)
166  StripPosition stripstereo(partnertopol.localPosition(STEREOpointini),partnertopol.localPosition(STEREOpointend));
167 
168  //project stereo hit on glued det
169  StripPosition projectedstripstereo=project(partnerstripdet,gluedDet,stripstereo,trackdirection);
170 
171 
172  double m10=-(projectedstripstereo.second.y()-projectedstripstereo.first.y());
173  double m11=(projectedstripstereo.second.x()-projectedstripstereo.first.x());
174 
175  //perform the matching
176  //(x2-x1)(y-y1)=(y2-y1)(x-x1)
177  AlgebraicMatrix22 m; AlgebraicVector2 c; // FIXME understand why moving this initializer out of the loop changes the output!
178  m(0,0)=m00;
179  m(0,1)=m01;
180  m(1,0)=m10;
181  m(1,1)=m11;
182  c(0)=c0;
183  c(1)=m11*projectedstripstereo.first.y()+m10*projectedstripstereo.first.x();
184  m.Invert();
185  AlgebraicVector2 solution = m * c;
186  LocalPoint position(solution(0),solution(1));
187 
188  /*
189  {
190  double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y());
191  double m01 = (projectedstripmono.second.x()-projectedstripmono.first.x());
192  double m10 = -(projectedstripstereo.second.y()-projectedstripstereo.first.y());
193  double m11 = (projectedstripstereo.second.x()-projectedstripstereo.first.x());
194  double c0 = m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
195  double c1 = m11*projectedstripstereo.first.y() + m10*projectedstripstereo.first.x();
196 
197  double invDet = 1./(m00*m11-m10*m01);
198  }
199  */
200 
201  //
202  // temporary fix by tommaso
203  //
204 
205 
206  LocalError tempError (100,0,100);
207  if (!((gluedDet->surface()).bounds().inside(position,tempError,scale_))) continue;
208 
209  // then calculate the error
210  /*
211  LocalVector stereopositiononGluedendvector=projectedstripstereo.second-projectedstripstereo.first;
212  double l2 = 1./stereopositiononGluedendvector.perp2();
213  double c2 = stereopositiononGluedendvector.y();
214  double s2 =-stereopositiononGluedendvector.x();
215  */
216 
217  double c2 = -m10;
218  double s2 = -m11;
219  double l2 = 1./(c2*c2+s2*s2);
220 
221  float sigmap22 = sigmaPitch((*seconditer)->localPosition(),(*seconditer)->localPositionError(),partnertopol);
222  // auto sigmap22 = (*seconditer)->sigmaPitch();
223  // assert(sigmap22>=0);
224 
225  double diff=(c1*s2-c2*s1);
226  double invdet2=1/(diff*diff*l1*l2);
227  float xx= invdet2*(sigmap12*s2*s2*l2+sigmap22*s1*s1*l1);
228  float xy=-invdet2*(sigmap12*c2*s2*l2+sigmap22*c1*s1*l1);
229  float yy= invdet2*(sigmap12*c2*c2*l2+sigmap22*c1*c1*l1);
230  LocalError error(xx,xy,yy);
231 
232  if((gluedDet->surface()).bounds().inside(position,error,scale_)){ //if it is inside the gluedet bonds
233  //Change NSigmaInside in the configuration file to accept more hits
234  //...and add it to the Rechit collection
235 
236  const SiStripRecHit2D* secondHit = *seconditer;
237  collector(SiStripMatchedRecHit2D(position, error,*gluedDet,
238  monoRH,secondHit));
239  }
240  }
241 }
242 
243 
246  StripPosition strip,LocalVector trackdirection) const {
247 
248  GlobalPoint globalpointini=(det->surface()).toGlobal(strip.first);
249  GlobalPoint globalpointend=(det->surface()).toGlobal(strip.second);
250 
251  // position of the initial and final point of the strip in glued local coordinates
252  LocalPoint positiononGluedini=(glueddet->surface()).toLocal(globalpointini);
253  LocalPoint positiononGluedend=(glueddet->surface()).toLocal(globalpointend);
254 
255  //correct the position with the track direction
256 
257  float scale=-positiononGluedini.z()/trackdirection.z();
258 
259  LocalPoint projpositiononGluedini= positiononGluedini + scale*trackdirection;
260  LocalPoint projpositiononGluedend= positiononGluedend + scale*trackdirection;
261 
262  return StripPosition(projpositiononGluedini,projpositiononGluedend);
263 }
264 
265 
266 
267 //match a single hit
268 std::unique_ptr<SiStripMatchedRecHit2D>
269 SiStripRecHitMatcher::match(const SiStripRecHit2D *monoRH,
270  const SiStripRecHit2D *stereoRH,
271  const GluedGeomDet* gluedDet,
272  LocalVector trackdirection, bool force) const {
273  // stripdet = mono
274  // partnerstripdet = stereo
275  const GeomDetUnit* stripdet = gluedDet->monoDet();
276  const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
277  const StripTopology& topol=(const StripTopology&)stripdet->topology();
278 
279  // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
280  auto RPHIpointX = topol.measurementPosition(monoRH->localPositionFast()).x();
281  MeasurementPoint RPHIpointini(RPHIpointX,-0.5f);
282  MeasurementPoint RPHIpointend(RPHIpointX,0.5f);
283 
284  // position of the initial and final point of the strip in local coordinates (mono det)
285  StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
286 
287  if(trackdirection.mag2()<float(FLT_MIN)){// in case of no track hypothesis assume a track from the origin through the center of the strip
288  LocalPoint lcenterofstrip=monoRH->localPositionFast();
289  GlobalPoint gcenterofstrip=(stripdet->surface()).toGlobal(lcenterofstrip);
290  GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
291  trackdirection=(gluedDet->surface()).toLocal(gtrackdirection);
292  }
293 
294  //project mono hit on glued det
295  StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
296  const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
297 
298  double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y());
299  double m01 = (projectedstripmono.second.x()-projectedstripmono.first.x());
300  double c0 = m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
301 
302  //error calculation (the part that depends on mono RH only)
303  // LocalVector RPHIpositiononGluedendvector=projectedstripmono.second-projectedstripmono.first;
304  /*
305  double l1 = 1./RPHIpositiononGluedendvector.perp2();
306  double c1 = RPHIpositiononGluedendvector.y();
307  double s1 =-RPHIpositiononGluedendvector.x();
308  */
309  double c1 = -m00;
310  double s1 = -m01;
311  double l1 = 1./(c1*c1+s1*s1);
312 
313 
314  float sigmap12 = sigmaPitch(monoRH->localPosition(), monoRH->localPositionError(),topol);
315  // auto sigmap12 = monoRH->sigmaPitch();
316  // assert(sigmap12>=0);
317 
318 
319 
320 
321  // position of the initial and final point of the strip (STEREO cluster)
322  auto STEREOpointX=partnertopol.measurementPosition(stereoRH->localPositionFast()).x();
323  MeasurementPoint STEREOpointini(STEREOpointX,-0.5f);
324  MeasurementPoint STEREOpointend(STEREOpointX,0.5f);
325 
326  // position of the initial and final point of the strip in local coordinates (stereo det)
327  StripPosition stripstereo(partnertopol.localPosition(STEREOpointini),partnertopol.localPosition(STEREOpointend));
328 
329  //project stereo hit on glued det
330  StripPosition projectedstripstereo=project(partnerstripdet,gluedDet,stripstereo,trackdirection);
331 
332 
333  double m10=-(projectedstripstereo.second.y()-projectedstripstereo.first.y());
334  double m11=(projectedstripstereo.second.x()-projectedstripstereo.first.x());
335 
336  //perform the matching
337  //(x2-x1)(y-y1)=(y2-y1)(x-x1)
339  m(0,0)=m00;
340  m(0,1)=m01;
341  m(1,0)=m10;
342  m(1,1)=m11;
343  c(0)=c0;
344  c(1)=m11*projectedstripstereo.first.y()+m10*projectedstripstereo.first.x();
345  m.Invert();
346  AlgebraicVector2 solution = m * c;
347  Local2DPoint position(solution(0),solution(1));
348 
349 
350  if ((!force) && (!((gluedDet->surface()).bounds().inside(position,10.f*scale_))) ) return std::unique_ptr<SiStripMatchedRecHit2D>(nullptr);
351 
352  double c2 = -m10;
353  double s2 = -m11;
354  double l2 = 1./(c2*c2+s2*s2);
355 
356 
357  float sigmap22 = sigmaPitch(stereoRH->localPosition(),stereoRH->localPositionError(),partnertopol);
358  // auto sigmap22 = stereoRH->sigmaPitch();
359  // assert (sigmap22>0);
360 
361  double diff=(c1*s2-c2*s1);
362  double invdet2=1/(diff*diff*l1*l2);
363  float xx= invdet2*(sigmap12*s2*s2*l2+sigmap22*s1*s1*l1);
364  float xy=-invdet2*(sigmap12*c2*s2*l2+sigmap22*c1*s1*l1);
365  float yy= invdet2*(sigmap12*c2*c2*l2+sigmap22*c1*c1*l1);
366  LocalError error(xx,xy,yy);
367 
368 
369  //if it is inside the gluedet bonds
370  //Change NSigmaInside in the configuration file to accept more hits
371  if(force || (gluedDet->surface()).bounds().inside(position,error,scale_))
372  return std::unique_ptr<SiStripMatchedRecHit2D> (new SiStripMatchedRecHit2D(LocalPoint(position), error, *gluedDet, monoRH,stereoRH));
373  return std::unique_ptr<SiStripMatchedRecHit2D>(nullptr);
374 }
375 
int i
Definition: DBlmapReader.cc:9
void push_back(data_type const &d)
T mag2() const
Definition: PV3DBase.h:66
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
StripPosition project(const GeomDetUnit *det, const GluedGeomDet *glueddet, StripPosition strip, LocalVector trackdirection) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
static float sigmaPitch(LocalPoint const &pos, LocalError const &err, const StripTopology &topol)
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
virtual const Topology & topology() const =0
void push_back(D *&d)
Definition: OwnVector.h:274
std::pair< LocalPoint, LocalPoint > StripPosition
SiStripRecHitMatcher(const edm::ParameterSet &conf)
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
double f[11][100]
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
#define end
Definition: vmac.h:37
tuple conf
Definition: dbtoconf.py:185
std::vector< const SiStripRecHit2D * > SimpleHitCollection
std::unique_ptr< SiStripMatchedRecHit2D > match(const SiStripRecHit2D *monoRH, const SiStripRecHit2D *stereoRH, const GluedGeomDet *gluedDet, LocalVector trackdirection, bool force=false) const
SiStripRecHit2DCollectionNew::DetSet::const_iterator RecHitIterator
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
#define begin
Definition: vmac.h:30
SimpleHitCollection::const_iterator SimpleHitIterator
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
virtual LocalPoint localPosition(float strip) const =0
boost::function< void(SiStripMatchedRecHit2D const &)> Collector
volatile std::atomic< bool > shutdown_flag false
Definition: DDAxes.h:10
ROOT::Math::SVector< double, 2 > AlgebraicVector2
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21