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 }
21 
23  scale_=theScale;
24 }
25 
26 
27 //match a single hit
28 SiStripMatchedRecHit2D * SiStripRecHitMatcher::match(const SiStripRecHit2D *monoRH,
29  const SiStripRecHit2D *stereoRH,
30  const GluedGeomDet* gluedDet,
31  LocalVector trackdirection) const{
32  SimpleHitCollection stereoHits(1,stereoRH);
33  std::vector<SiStripMatchedRecHit2D*> collection;
34  match( monoRH,
35  stereoHits.begin(), stereoHits.end(),
36  collection,
37  gluedDet,trackdirection);
38 
39  return collection.empty() ? (SiStripMatchedRecHit2D*)(0) : collection.front();
40 }
41 
42 //repeat matching for an already a single hit
43 SiStripMatchedRecHit2D* SiStripRecHitMatcher::match(const SiStripMatchedRecHit2D *origRH,
44  const GluedGeomDet* gluedDet,
45  LocalVector trackdirection) const{
46 
47  throw "SiStripRecHitMatcher::match(const SiStripMatchedRecHit2D *,..) is obsoltete since 5.2.0";
48 
49  /*
50  const SiStripRecHit2D* theMonoRH = origRH->monoHit();
51  // const SiStripRecHit2D* theStereoRH = origRH->stereoHit();
52  SimpleHitCollection theStereoHits(1, origRH->stereoHit());
53  // theStereoHits.push_back(theStereoRH);
54 
55  std::vector<SiStripMatchedRecHit2D*> collection;
56  match( theMonoRH,
57  theStereoHits.begin(), theStereoHits.end(),
58  collection,
59  gluedDet,trackdirection);
60 
61  return collection.empty() ? (SiStripMatchedRecHit2D*)(0) : collection.front();
62  */
63 
64  return nullptr;
65 }
66 
67 
69 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
71  const GluedGeomDet* gluedDet,
72  LocalVector trackdirection) const
73 {
74  SimpleHitCollection stereoHits;
75  stereoHits.reserve(end-begin);
76 
77  for (RecHitIterator i=begin; i != end; ++i) {
78  stereoHits.push_back( &(*i)); // convert to simple pointer
79  }
80  return match( monoRH,
81  stereoHits.begin(), stereoHits.end(),
82  gluedDet,trackdirection);
83 }
84 
86 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
88  const GluedGeomDet* gluedDet,
89  LocalVector trackdirection) const {
91  collector.reserve(end-begin); // a resonable estimate of its size...
92  match(monoRH,begin,end,collector,gluedDet,trackdirection);
93  return collector;
94 }
95 
96 
97 void
98 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
101  const GluedGeomDet* gluedDet,
102  LocalVector trackdirection) const {
103 
104  std::vector<SiStripMatchedRecHit2D*> result;
105  result.reserve(end-begin);
106  match(monoRH,begin,end,result,gluedDet,trackdirection);
107  for (std::vector<SiStripMatchedRecHit2D*>::iterator p=result.begin(); p!=result.end();
108  p++) collector.push_back(*p);
109 }
110 
111 namespace {
112  // FIXME for c++0X
113  inline void pb1(std::vector<SiStripMatchedRecHit2D*> & v, SiStripMatchedRecHit2D* h) {
114  v.push_back(h);
115  }
116  inline void pb2(SiStripRecHitMatcher::CollectorMatched & v, const SiStripMatchedRecHit2D & h) {
117  v.push_back(h);
118  }
119 
120 }
121 
122 void
123 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
125  std::vector<SiStripMatchedRecHit2D*> & collector,
126  const GluedGeomDet* gluedDet,
127  LocalVector trackdirection) const {
128  Collector result(boost::bind(&pb1,boost::ref(collector),
129  boost::bind(&SiStripMatchedRecHit2D::clone,_1)));
130  match(monoRH,begin,end,result,gluedDet,trackdirection);
131 }
132 
133 
134 // this is the one used by the RecHitConverter
135 void
136 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
138  CollectorMatched & collector,
139  const GluedGeomDet* gluedDet,
140  LocalVector trackdirection) const {
141 
142  // is this really needed now????
143  SimpleHitCollection stereoHits;
144  stereoHits.reserve(end-begin);
145  for (RecHitIterator i=begin; i != end; ++i)
146  stereoHits.push_back( &(*i)); // convert to simple pointer
147 
148  return match( monoRH,
149  stereoHits.begin(), stereoHits.end(),
150  collector,
151  gluedDet,trackdirection);
152 }
153 
154 void
155 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
157  CollectorMatched & collector,
158  const GluedGeomDet* gluedDet,
159  LocalVector trackdirection) const {
160 
161  Collector result(boost::bind(pb2,boost::ref(collector),_1));
162  match(monoRH,begin,end,result,gluedDet,trackdirection);
163 
164 }
165 
166 
167 // the "real implementation"
168 void
169 SiStripRecHitMatcher::match( const SiStripRecHit2D *monoRH,
171  Collector & collector,
172  const GluedGeomDet* gluedDet,
173  LocalVector trackdirection) const {
174  // stripdet = mono
175  // partnerstripdet = stereo
176  const GeomDetUnit* stripdet = gluedDet->monoDet();
177  const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
178  const StripTopology& topol=(const StripTopology&)stripdet->topology();
179 
180  // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
181  double RPHIpointX = topol.measurementPosition(monoRH->localPositionFast()).x();
182  MeasurementPoint RPHIpointini(RPHIpointX,-0.5);
183  MeasurementPoint RPHIpointend(RPHIpointX,0.5);
184 
185  // position of the initial and final point of the strip in local coordinates (mono det)
186  StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
187 
188  if(trackdirection.mag2()<FLT_MIN){// in case of no track hypothesis assume a track from the origin through the center of the strip
189  LocalPoint lcenterofstrip=monoRH->localPositionFast();
190  GlobalPoint gcenterofstrip=(stripdet->surface()).toGlobal(lcenterofstrip);
191  GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
192  trackdirection=(gluedDet->surface()).toLocal(gtrackdirection);
193  }
194 
195  //project mono hit on glued det
196  StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
197  const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
198 
199  double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y());
200  double m01 = (projectedstripmono.second.x()-projectedstripmono.first.x());
201  double c0 = m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
202 
203  //error calculation (the part that depends on mono RH only)
204  // LocalVector RPHIpositiononGluedendvector=projectedstripmono.second-projectedstripmono.first;
205  /*
206  double l1 = 1./RPHIpositiononGluedendvector.perp2();
207  double c1 = RPHIpositiononGluedendvector.y();
208  double s1 =-RPHIpositiononGluedendvector.x();
209  */
210  double c1 = -m00;
211  double s1 = -m01;
212  double l1 = 1./(c1*c1+s1*s1);
213 
214 
215  // FIXME: here for test...
216  double sigmap12 = monoRH->sigmaPitch();
217  if (sigmap12<0) {
218  //AlgebraicSymMatrix tmpMatrix = monoRH->parametersError();
219  /*
220  std::cout << "DEBUG START" << std::endl;
221  std::cout << "APE mono,stereo,glued : "
222  << stripdet->alignmentPositionError()->globalError().cxx() << " , "
223  << partnerstripdet->alignmentPositionError()->globalError().cxx() << " , "
224  << gluedDet->alignmentPositionError()->globalError().cxx() << std::endl;
225  */
226  LocalError tmpError(monoRH->localPositionErrorFast());
227  HelpertRecHit2DLocalPos::updateWithAPE(tmpError,*stripdet);
228  MeasurementError errormonoRH=topol.measurementError(monoRH->localPositionFast(),tmpError);
229  /*
230  std::cout << "localPosError.xx(), helper.xx(), param.xx(): "
231  << monoRH->localPositionError().xx() << " , "
232  << monoRH->parametersError()[0][0] << " , "
233  << tmpMatrix[0][0] << std::endl;
234  */
235  //MeasurementError errormonoRH=topol.measurementError(monoRH->localPosition(),monoRH->localPositionError());
236  double pitch=topol.localPitch(monoRH->localPositionFast());
237  monoRH->setSigmaPitch(sigmap12=errormonoRH.uu()*pitch*pitch);
238  }
239 
240  SimpleHitIterator seconditer;
241 
242  for(seconditer=begin;seconditer!=end;++seconditer){//iterate on stereo rechits
243 
244  // position of the initial and final point of the strip (STEREO cluster)
245  double STEREOpointX=partnertopol.measurementPosition((*seconditer)->localPositionFast()).x();
246  MeasurementPoint STEREOpointini(STEREOpointX,-0.5);
247  MeasurementPoint STEREOpointend(STEREOpointX,0.5);
248 
249  // position of the initial and final point of the strip in local coordinates (stereo det)
250  StripPosition stripstereo(partnertopol.localPosition(STEREOpointini),partnertopol.localPosition(STEREOpointend));
251 
252  //project stereo hit on glued det
253  StripPosition projectedstripstereo=project(partnerstripdet,gluedDet,stripstereo,trackdirection);
254 
255 
256  double m10=-(projectedstripstereo.second.y()-projectedstripstereo.first.y());
257  double m11=(projectedstripstereo.second.x()-projectedstripstereo.first.x());
258 
259  //perform the matching
260  //(x2-x1)(y-y1)=(y2-y1)(x-x1)
261  AlgebraicMatrix22 m; AlgebraicVector2 c; // FIXME understand why moving this initializer out of the loop changes the output!
262  m(0,0)=m00;
263  m(0,1)=m01;
264  m(1,0)=m10;
265  m(1,1)=m11;
266  c(0)=c0;
267  c(1)=m11*projectedstripstereo.first.y()+m10*projectedstripstereo.first.x();
268  m.Invert();
269  AlgebraicVector2 solution = m * c;
270  LocalPoint position(solution(0),solution(1));
271 
272  /*
273  {
274  double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y());
275  double m01 = (projectedstripmono.second.x()-projectedstripmono.first.x());
276  double m10 = -(projectedstripstereo.second.y()-projectedstripstereo.first.y());
277  double m11 = (projectedstripstereo.second.x()-projectedstripstereo.first.x());
278  double c0 = m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
279  double c1 = m11*projectedstripstereo.first.y() + m10*projectedstripstereo.first.x();
280 
281  double invDet = 1./(m00*m11-m10*m01);
282  }
283  */
284 
285  //
286  // temporary fix by tommaso
287  //
288 
289 
290  LocalError tempError (100,0,100);
291  if (!((gluedDet->surface()).bounds().inside(position,tempError,scale_))) continue;
292 
293  // then calculate the error
294  /*
295  LocalVector stereopositiononGluedendvector=projectedstripstereo.second-projectedstripstereo.first;
296  double l2 = 1./stereopositiononGluedendvector.perp2();
297  double c2 = stereopositiononGluedendvector.y();
298  double s2 =-stereopositiononGluedendvector.x();
299  */
300 
301  double c2 = -m10;
302  double s2 = -m11;
303  double l2 = 1./(c2*c2+s2*s2);
304 
305 
306  // FIXME: here for test...
307  double sigmap22 = (*seconditer)->sigmaPitch();
308  if (sigmap22<0) {
309  //AlgebraicSymMatrix tmpMatrix = (*seconditer)->parametersError();
310  LocalError tmpError((*seconditer)->localPositionErrorFast());
311  HelpertRecHit2DLocalPos::updateWithAPE(tmpError, *partnerstripdet);
312  MeasurementError errorstereoRH=partnertopol.measurementError((*seconditer)->localPositionFast(),tmpError);
313  //MeasurementError errorstereoRH=partnertopol.measurementError((*seconditer)->localPosition(),(*seconditer)->localPositionError());
314  double pitch=partnertopol.localPitch((*seconditer)->localPositionFast());
315  (*seconditer)->setSigmaPitch(sigmap22=errorstereoRH.uu()*pitch*pitch);
316  }
317 
318  double diff=(c1*s2-c2*s1);
319  double invdet2=1/(diff*diff*l1*l2);
320  float xx= invdet2*(sigmap12*s2*s2*l2+sigmap22*s1*s1*l1);
321  float xy=-invdet2*(sigmap12*c2*s2*l2+sigmap22*c1*s1*l1);
322  float yy= invdet2*(sigmap12*c2*c2*l2+sigmap22*c1*c1*l1);
323  LocalError error(xx,xy,yy);
324 
325  if((gluedDet->surface()).bounds().inside(position,error,scale_)){ //if it is inside the gluedet bonds
326  //Change NSigmaInside in the configuration file to accept more hits
327  //...and add it to the Rechit collection
328 
329  const SiStripRecHit2D* secondHit = *seconditer;
330  collector(SiStripMatchedRecHit2D(position, error,gluedDet->geographicalId() ,
331  monoRH,secondHit));
332  }
333  }
334 }
335 
336 
338 {
339 
340  GlobalPoint globalpointini=(det->surface()).toGlobal(strip.first);
341  GlobalPoint globalpointend=(det->surface()).toGlobal(strip.second);
342 
343  // position of the initial and final point of the strip in glued local coordinates
344  LocalPoint positiononGluedini=(glueddet->surface()).toLocal(globalpointini);
345  LocalPoint positiononGluedend=(glueddet->surface()).toLocal(globalpointend);
346 
347  //correct the position with the track direction
348 
349  float scale=-positiononGluedini.z()/trackdirection.z();
350 
351  LocalPoint projpositiononGluedini= positiononGluedini + scale*trackdirection;
352  LocalPoint projpositiononGluedend= positiononGluedend + scale*trackdirection;
353 
354  return StripPosition(projpositiononGluedini,projpositiononGluedend);
355 }
T getParameter(std::string const &) const
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
SiStripMatchedRecHit2D * match(const SiStripRecHit2D *monoRH, const SiStripRecHit2D *stereoRH, const GluedGeomDet *gluedDet, LocalVector trackdirection) const
StripPosition project(const GeomDetUnit *det, const GluedGeomDet *glueddet, StripPosition strip, LocalVector trackdirection) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
static void updateWithAPE(LocalError &le, const GeomDet &det)
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
virtual float localPitch(const LocalPoint &) const =0
void push_back(D *&d)
Definition: OwnVector.h:273
virtual MeasurementError measurementError(const LocalPoint &, const LocalError &) const =0
std::pair< LocalPoint, LocalPoint > StripPosition
SiStripRecHitMatcher(const edm::ParameterSet &conf)
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
float uu() const
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:72
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
#define end
Definition: vmac.h:37
tuple conf
Definition: dbtoconf.py:185
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::vector< const SiStripRecHit2D * > SimpleHitCollection
SiStripRecHit2DCollectionNew::DetSet::const_iterator RecHitIterator
#define begin
Definition: vmac.h:30
SimpleHitCollection::const_iterator SimpleHitIterator
tuple clone
Definition: statics.py:58
virtual LocalPoint localPosition(float strip) const =0
boost::function< void(SiStripMatchedRecHit2D const &)> Collector
Definition: DDAxes.h:10
ROOT::Math::SVector< double, 2 > AlgebraicVector2
void reserve(size_t)
Definition: OwnVector.h:267
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21