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
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
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 
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 
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
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 pb(std::vector<SiStripMatchedRecHit2D*> & v, SiStripMatchedRecHit2D* h) {
114  v.push_back(h);
115  }
116 }
117 
118 void
121  std::vector<SiStripMatchedRecHit2D*> & collector,
122  const GluedGeomDet* gluedDet,
123  LocalVector trackdirection) const {
124  Collector result(boost::bind(&pb,boost::ref(collector),
125  boost::bind(&SiStripMatchedRecHit2D::clone,_1)));
126  match(monoRH,begin,end,result,gluedDet,trackdirection);
127 }
128 
129 
130 // this is the one used by the RecHitConverter
131 void
134  CollectorMatched & collector,
135  const GluedGeomDet* gluedDet,
136  LocalVector trackdirection) const {
137 
138  // is this really needed now????
139  SimpleHitCollection stereoHits;
140  stereoHits.reserve(end-begin);
141  for (RecHitIterator i=begin; i != end; ++i)
142  stereoHits.push_back( &(*i)); // convert to simple pointer
143 
144  return match( monoRH,
145  stereoHits.begin(), stereoHits.end(),
146  collector,
147  gluedDet,trackdirection);
148 }
149 
150 void
153  CollectorMatched & collector,
154  const GluedGeomDet* gluedDet,
155  LocalVector trackdirection) const {
156 
157  Collector result(boost::bind(&CollectorMatched::push_back,boost::ref(collector),_1));
158  match(monoRH,begin,end,result,gluedDet,trackdirection);
159 
160 }
161 
162 
163 // the "real implementation"
164 void
167  Collector & collector,
168  const GluedGeomDet* gluedDet,
169  LocalVector trackdirection) const {
170  // stripdet = mono
171  // partnerstripdet = stereo
172  const GeomDetUnit* stripdet = gluedDet->monoDet();
173  const GeomDetUnit* partnerstripdet = gluedDet->stereoDet();
174  const StripTopology& topol=(const StripTopology&)stripdet->topology();
175 
176  // position of the initial and final point of the strip (RPHI cluster) in local strip coordinates
177  double RPHIpointX = topol.measurementPosition(monoRH->localPositionFast()).x();
178  MeasurementPoint RPHIpointini(RPHIpointX,-0.5);
179  MeasurementPoint RPHIpointend(RPHIpointX,0.5);
180 
181  // position of the initial and final point of the strip in local coordinates (mono det)
182  StripPosition stripmono=StripPosition(topol.localPosition(RPHIpointini),topol.localPosition(RPHIpointend));
183 
184  if(trackdirection.mag2()<FLT_MIN){// in case of no track hypothesis assume a track from the origin through the center of the strip
185  LocalPoint lcenterofstrip=monoRH->localPositionFast();
186  GlobalPoint gcenterofstrip=(stripdet->surface()).toGlobal(lcenterofstrip);
187  GlobalVector gtrackdirection=gcenterofstrip-GlobalPoint(0,0,0);
188  trackdirection=(gluedDet->surface()).toLocal(gtrackdirection);
189  }
190 
191  //project mono hit on glued det
192  StripPosition projectedstripmono=project(stripdet,gluedDet,stripmono,trackdirection);
193  const StripTopology& partnertopol=(const StripTopology&)partnerstripdet->topology();
194 
195  double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y());
196  double m01 = (projectedstripmono.second.x()-projectedstripmono.first.x());
197  double c0 = m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
198 
199  //error calculation (the part that depends on mono RH only)
200  // LocalVector RPHIpositiononGluedendvector=projectedstripmono.second-projectedstripmono.first;
201  /*
202  double l1 = 1./RPHIpositiononGluedendvector.perp2();
203  double c1 = RPHIpositiononGluedendvector.y();
204  double s1 =-RPHIpositiononGluedendvector.x();
205  */
206  double c1 = -m00;
207  double s1 = -m01;
208  double l1 = 1./(c1*c1+s1*s1);
209 
210 
211  // FIXME: here for test...
212  double sigmap12 = monoRH->sigmaPitch();
213  if (sigmap12<0) {
214  //AlgebraicSymMatrix tmpMatrix = monoRH->parametersError();
215  /*
216  std::cout << "DEBUG START" << std::endl;
217  std::cout << "APE mono,stereo,glued : "
218  << stripdet->alignmentPositionError()->globalError().cxx() << " , "
219  << partnerstripdet->alignmentPositionError()->globalError().cxx() << " , "
220  << gluedDet->alignmentPositionError()->globalError().cxx() << std::endl;
221  */
222  LocalError tmpError(monoRH->localPositionErrorFast());
223  HelpertRecHit2DLocalPos::updateWithAPE(tmpError,*stripdet);
224  MeasurementError errormonoRH=topol.measurementError(monoRH->localPositionFast(),tmpError);
225  /*
226  std::cout << "localPosError.xx(), helper.xx(), param.xx(): "
227  << monoRH->localPositionError().xx() << " , "
228  << monoRH->parametersError()[0][0] << " , "
229  << tmpMatrix[0][0] << std::endl;
230  */
231  //MeasurementError errormonoRH=topol.measurementError(monoRH->localPosition(),monoRH->localPositionError());
232  double pitch=topol.localPitch(monoRH->localPositionFast());
233  monoRH->setSigmaPitch(sigmap12=errormonoRH.uu()*pitch*pitch);
234  }
235 
236  SimpleHitIterator seconditer;
237 
238  for(seconditer=begin;seconditer!=end;++seconditer){//iterate on stereo rechits
239 
240  // position of the initial and final point of the strip (STEREO cluster)
241  double STEREOpointX=partnertopol.measurementPosition((*seconditer)->localPositionFast()).x();
242  MeasurementPoint STEREOpointini(STEREOpointX,-0.5);
243  MeasurementPoint STEREOpointend(STEREOpointX,0.5);
244 
245  // position of the initial and final point of the strip in local coordinates (stereo det)
246  StripPosition stripstereo(partnertopol.localPosition(STEREOpointini),partnertopol.localPosition(STEREOpointend));
247 
248  //project stereo hit on glued det
249  StripPosition projectedstripstereo=project(partnerstripdet,gluedDet,stripstereo,trackdirection);
250 
251 
252  double m10=-(projectedstripstereo.second.y()-projectedstripstereo.first.y());
253  double m11=(projectedstripstereo.second.x()-projectedstripstereo.first.x());
254 
255  //perform the matching
256  //(x2-x1)(y-y1)=(y2-y1)(x-x1)
257  AlgebraicMatrix22 m; AlgebraicVector2 c; // FIXME understand why moving this initializer out of the loop changes the output!
258  m(0,0)=m00;
259  m(0,1)=m01;
260  m(1,0)=m10;
261  m(1,1)=m11;
262  c(0)=c0;
263  c(1)=m11*projectedstripstereo.first.y()+m10*projectedstripstereo.first.x();
264  m.Invert();
265  AlgebraicVector2 solution = m * c;
266  LocalPoint position(solution(0),solution(1));
267 
268  /*
269  {
270  double m00 = -(projectedstripmono.second.y()-projectedstripmono.first.y());
271  double m01 = (projectedstripmono.second.x()-projectedstripmono.first.x());
272  double m10 = -(projectedstripstereo.second.y()-projectedstripstereo.first.y());
273  double m11 = (projectedstripstereo.second.x()-projectedstripstereo.first.x());
274  double c0 = m01*projectedstripmono.first.y() + m00*projectedstripmono.first.x();
275  double c1 = m11*projectedstripstereo.first.y() + m10*projectedstripstereo.first.x();
276 
277  double invDet = 1./(m00*m11-m10*m01);
278  }
279  */
280 
281  //
282  // temporary fix by tommaso
283  //
284 
285 
286  LocalError tempError (100,0,100);
287  if (!((gluedDet->surface()).bounds().inside(position,tempError,scale_))) continue;
288 
289  // then calculate the error
290  /*
291  LocalVector stereopositiononGluedendvector=projectedstripstereo.second-projectedstripstereo.first;
292  double l2 = 1./stereopositiononGluedendvector.perp2();
293  double c2 = stereopositiononGluedendvector.y();
294  double s2 =-stereopositiononGluedendvector.x();
295  */
296 
297  double c2 = -m10;
298  double s2 = -m11;
299  double l2 = 1./(c2*c2+s2*s2);
300 
301 
302  // FIXME: here for test...
303  double sigmap22 = (*seconditer)->sigmaPitch();
304  if (sigmap22<0) {
305  //AlgebraicSymMatrix tmpMatrix = (*seconditer)->parametersError();
306  LocalError tmpError((*seconditer)->localPositionErrorFast());
307  HelpertRecHit2DLocalPos::updateWithAPE(tmpError, *partnerstripdet);
308  MeasurementError errorstereoRH=partnertopol.measurementError((*seconditer)->localPositionFast(),tmpError);
309  //MeasurementError errorstereoRH=partnertopol.measurementError((*seconditer)->localPosition(),(*seconditer)->localPositionError());
310  double pitch=partnertopol.localPitch((*seconditer)->localPositionFast());
311  (*seconditer)->setSigmaPitch(sigmap22=errorstereoRH.uu()*pitch*pitch);
312  }
313 
314  double diff=(c1*s2-c2*s1);
315  double invdet2=1/(diff*diff*l1*l2);
316  float xx= invdet2*(sigmap12*s2*s2*l2+sigmap22*s1*s1*l1);
317  float xy=-invdet2*(sigmap12*c2*s2*l2+sigmap22*c1*s1*l1);
318  float yy= invdet2*(sigmap12*c2*c2*l2+sigmap22*c1*c1*l1);
319  LocalError error(xx,xy,yy);
320 
321  if((gluedDet->surface()).bounds().inside(position,error,scale_)){ //if it is inside the gluedet bonds
322  //Change NSigmaInside in the configuration file to accept more hits
323  //...and add it to the Rechit collection
324 
325  const SiStripRecHit2D* secondHit = *seconditer;
326  collector(SiStripMatchedRecHit2D(position, error,gluedDet->geographicalId() ,
327  monoRH,secondHit));
328  }
329  }
330 }
331 
332 
334 {
335 
336  GlobalPoint globalpointini=(det->surface()).toGlobal(strip.first);
337  GlobalPoint globalpointend=(det->surface()).toGlobal(strip.second);
338 
339  // position of the initial and final point of the strip in glued local coordinates
340  LocalPoint positiononGluedini=(glueddet->surface()).toLocal(globalpointini);
341  LocalPoint positiononGluedend=(glueddet->surface()).toLocal(globalpointend);
342 
343  //correct the position with the track direction
344 
345  float scale=-positiononGluedini.z()/trackdirection.z();
346 
347  LocalPoint projpositiononGluedini= positiononGluedini + scale*trackdirection;
348  LocalPoint projpositiononGluedend= positiononGluedend + scale*trackdirection;
349 
350  return StripPosition(projpositiononGluedini,projpositiononGluedend);
351 }
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:65
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
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
void setSigmaPitch(double sigmap) 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)
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:63
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:38
tuple conf
Definition: dbtoconf.py:185
const LocalError & localPositionErrorFast() const
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:31
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
SimpleHitCollection::const_iterator SimpleHitIterator
static int position[264][3]
Definition: ReadPGInfo.cc:509
virtual LocalPoint localPosition(float strip) const =0
const LocalPoint & localPositionFast() const
boost::function< void(SiStripMatchedRecHit2D const &)> Collector
x
Definition: VDTMath.h:216
double sigmaPitch() const
virtual SiStripMatchedRecHit2D * clone() const
ROOT::Math::SVector< double, 2 > AlgebraicVector2
mathSSE::Vec4< T > v
void reserve(size_t)
Definition: OwnVector.h:267
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21