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