CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelHitMatcher.cc
Go to the documentation of this file.
1 
15 #include "CLHEP/Units/GlobalPhysicalConstants.h"
17 
18 #include <typeinfo>
19 
20 using namespace reco ;
21 using namespace std ;
22 
24  ( float phi1min, float phi1max,
25  float phi2minB, float phi2maxB, float phi2minF, float phi2maxF,
26  float z2minB, float z2maxB, float r2minF, float r2maxF,
27  float rMinI, float rMaxI, bool searchInTIDTEC)
28  : //zmin1 and zmax1 are dummy at this moment, set from beamspot later
29  meas1stBLayer(phi1min,phi1max,0.,0.), meas2ndBLayer(phi2minB,phi2maxB,z2minB,z2maxB),
30  meas1stFLayer(phi1min,phi1max,0.,0.), meas2ndFLayer(phi2minF,phi2maxF,r2minF,r2maxF),
31  startLayers(),
32  prop1stLayer(0), prop2ndLayer(0),theGeometricSearchTracker(0),theLayerMeasurements(0),vertex_(0.),
33  searchInTIDTEC_(searchInTIDTEC), useRecoVertex_(false)
34  {
35  meas1stFLayer.setRRangeI(rMinI,rMaxI) ;
36  meas2ndFLayer.setRRangeI(rMinI,rMaxI) ;
37  }
38 
40  {
41  delete prop1stLayer ;
42  delete prop2ndLayer ;
43  delete theLayerMeasurements ;
44  }
45 
46 void PixelHitMatcher::set1stLayer( float dummyphi1min, float dummyphi1max )
47  {
48  meas1stBLayer.setPhiRange(dummyphi1min,dummyphi1max) ;
49  meas1stFLayer.setPhiRange(dummyphi1min,dummyphi1max) ;
50  }
51 
52 void PixelHitMatcher::set1stLayerZRange( float zmin1, float zmax1 )
53  {
54  meas1stBLayer.setZRange(zmin1,zmax1) ;
55  meas1stFLayer.setRRange(zmin1,zmax1) ;
56  }
57 
58 void PixelHitMatcher::set2ndLayer( float dummyphi2minB, float dummyphi2maxB, float dummyphi2minF, float dummyphi2maxF )
59  {
60  meas2ndBLayer.setPhiRange(dummyphi2minB,dummyphi2maxB) ;
61  meas2ndFLayer.setPhiRange(dummyphi2minF,dummyphi2maxF) ;
62  }
63 
65  { useRecoVertex_ = val ; }
66 
68  ( const MagneticField * magField,
69  const MeasurementTracker * theMeasurementTracker,
70  const TrackerGeometry * trackerGeometry )
71  {
72  if (theMeasurementTracker)
73  {
74  theGeometricSearchTracker=theMeasurementTracker->geometricSearchTracker() ;
75  startLayers.setup(theGeometricSearchTracker) ;
76  if (theLayerMeasurements ) delete theLayerMeasurements ;
77  theLayerMeasurements = new LayerMeasurements(theMeasurementTracker) ;
78  }
79 
80  theMagField = magField ;
81  theTrackerGeometry = trackerGeometry ;
82  float mass=.000511 ; // electron propagation
83  if (prop1stLayer) delete prop1stLayer ;
84  prop1stLayer = new PropagatorWithMaterial(oppositeToMomentum,mass,theMagField) ;
85  if (prop2ndLayer) delete prop2ndLayer ;
86  prop2ndLayer = new PropagatorWithMaterial(alongMomentum,mass,theMagField) ;
87  }
88 
89 vector<CLHEP::Hep3Vector> PixelHitMatcher::predicted1Hits()
90  { return pred1Meas ; }
91 
92 vector<CLHEP::Hep3Vector> PixelHitMatcher::predicted2Hits()
93  { return pred2Meas ; }
94 
96  { return vertex_ ; }
97 
98 //CLHEP::Hep3Vector point_to_vector( const GlobalPoint & p )
99 // { return CLHEP::Hep3Vector(p.x(),p.y(),p.z()) ; }
100 
101 std::vector<SeedWithInfo>
103  ( TrajectorySeedCollection * seeds, const GlobalPoint & xmeas,
104  const GlobalPoint & vprim, float energy, float fcharge )
105  {
106  int charge = int(fcharge) ;
107 
108  FreeTrajectoryState fts = myFTS(theMagField,xmeas, vprim, energy, charge);
110  TrajectoryStateOnSurface tsos(fts, *bpb(fts.position(), fts.momentum()));
111 
112  std::vector<SeedWithInfo> result ;
113  mapTsos_.clear() ;
114  mapTsos2_.clear() ;
115  mapTsos_.reserve(seeds->size()) ;
116  mapTsos2_.reserve(seeds->size()) ;
117 
118  for (unsigned int i=0;i<seeds->size();++i)
119  {
120  assert((*seeds)[i].nHits()<=8) ;
121  TrajectorySeed::range rhits=(*seeds)[i].recHits();
122 
123  // build all possible pairs
124  unsigned char rank1, rank2, hitsMask ;
126  for ( rank1=0, it1=rhits.first ; it1!=rhits.second ; rank1++, it1++ )
127  {
128  for ( rank2=rank1+1, it2=it1+1 ; it2!=rhits.second ; rank2++, it2++ )
129  {
130  //TrajectorySeed::range r(it1,it2) ;
131 
132  // first Hit
134  if (!(*it).isValid()) continue;
135  DetId id=(*it).geographicalId();
136  const GeomDet *geomdet=theTrackerGeometry->idToDet((*it).geographicalId());
137  LocalPoint lp=(*it).localPosition() ;
138  GlobalPoint hitPos=geomdet->surface().toGlobal(lp) ;
139 
141  bool found = false;
142  std::vector<std::pair<const GeomDet *, TrajectoryStateOnSurface> >::iterator itTsos ;
143  for (itTsos=mapTsos_.begin();itTsos!=mapTsos_.end();++itTsos)
144  {
145  if ((*itTsos).first==geomdet)
146  { found=true ; break ; }
147  }
148  if (!found)
149  {
150  tsos1 = prop1stLayer->propagate(tsos,geomdet->surface()) ;
151  mapTsos_.push_back(std::pair<const GeomDet *, TrajectoryStateOnSurface>(geomdet,tsos1));
152  }
153  else
154  { tsos1=(*itTsos).second ; }
155 
156  if (tsos1.isValid())
157  {
158  std::pair<bool,double> est;
159  if (id.subdetId()%2==1) est=meas1stBLayer.estimate(vprim, tsos1,hitPos);
160  else est=meas1stFLayer.estimate(vprim, tsos1,hitPos);
161  if (!est.first) continue ;
162 
163  if (std::abs(normalized_phi(hitPos.phi()-xmeas.phi()))>2.5) continue ;
164  EleRelPointPair pp1(hitPos,tsos1.globalParameters().position(),vprim) ;
165  int subDet1 = id.subdetId() ;
166  float dRz1 = (subDet1%2==1)?pp1.dZ():pp1.dPerp() ;
167  float dPhi1 = pp1.dPhi() ;
168 
169  // now second Hit
170  //CC@@
171  //it++;
172  it=it2 ;
173  if (!(*it).isValid()) continue ;
174 
175  DetId id2=(*it).geographicalId();
176  const GeomDet *geomdet2=theTrackerGeometry->idToDet((*it).geographicalId());
178 
179  double zVertex;
180  if (!useRecoVertex_) // we don't know the z vertex position, get it from linear extrapolation
181  {
182  // compute the z vertex from the cluster point and the found pixel hit
183  double pxHit1z = hitPos.z();
184  double pxHit1x = hitPos.x();
185  double pxHit1y = hitPos.y();
186  double r1diff = (pxHit1x-vprim.x())*(pxHit1x-vprim.x()) + (pxHit1y-vprim.y())*(pxHit1y-vprim.y()) ;
187  r1diff=sqrt(r1diff) ;
188  double r2diff = (xmeas.x()-pxHit1x)*(xmeas.x()-pxHit1x) + (xmeas.y()-pxHit1y)*(xmeas.y()-pxHit1y) ;
189  r2diff=sqrt(r2diff);
190  zVertex = pxHit1z - r1diff*(xmeas.z()-pxHit1z)/r2diff;
191  }
192  else // here use rather the reco vertex z position
193  { zVertex = vprim.z() ; }
194 
195  GlobalPoint vertex(vprim.x(),vprim.y(),zVertex) ;
196  FreeTrajectoryState fts2 = myFTS(theMagField,hitPos,vertex,energy, charge) ;
197 
198  found = false;
199  std::vector<std::pair< std::pair<const GeomDet *,GlobalPoint>, TrajectoryStateOnSurface> >::iterator itTsos2 ;
200  for (itTsos2=mapTsos2_.begin();itTsos2!=mapTsos2_.end();++itTsos2)
201  {
202  if (((*itTsos2).first).first==geomdet2 &&
203  (((*itTsos2).first).second).x()==hitPos.x() &&
204  (((*itTsos2).first).second).y()==hitPos.y() &&
205  (((*itTsos2).first).second).z()==hitPos.z() )
206  {
207  found=true;
208  break;
209  }
210  }
211  if (!found)
212  {
213  tsos2 = prop2ndLayer->propagate(fts2,geomdet2->surface()) ;
214  std::pair<const GeomDet *,GlobalPoint> pair(geomdet2,hitPos);
215  mapTsos2_.push_back(std::pair<std::pair<const GeomDet *,GlobalPoint>, TrajectoryStateOnSurface> (pair,tsos2));
216  }
217  else
218  { tsos2=(*itTsos2).second ; }
219 
220  if (tsos2.isValid())
221  {
222  LocalPoint lp2=(*it).localPosition() ;
223  GlobalPoint hitPos2=geomdet2->surface().toGlobal(lp2) ;
224  std::pair<bool,double> est2 ;
225  if (id2.subdetId()%2==1) est2=meas2ndBLayer.estimate(vertex, tsos2,hitPos2) ;
226  else est2=meas2ndFLayer.estimate(vertex, tsos2,hitPos2) ;
227  if (est2.first)
228  {
229  EleRelPointPair pp2(hitPos2,tsos2.globalParameters().position(),vertex) ;
230  int subDet2 = id2.subdetId() ;
231  float dRz2 = (subDet2%2==1)?pp2.dZ():pp2.dPerp() ;
232  float dPhi2 = pp2.dPhi() ;
233  hitsMask = (1<<rank1)|(1<<rank2) ;
234  result.push_back(SeedWithInfo((*seeds)[i],hitsMask,subDet2,dRz2,dPhi2,subDet1,dRz1,dPhi1)) ;
235  }
236  }
237  } // end tsos1 is valid
238  } // end loop on second seed hit
239  } // end loop on first seed hit
240  } // end loop on seeds
241 
242  mapTsos_.clear() ;
243  mapTsos2_.clear() ;
244 
245  return result ;
246  }
247 
248 //========================= OBSOLETE ? =========================
249 
250 vector< pair< RecHitWithDist, PixelHitMatcher::ConstRecHitPointer > >
252  ( const GlobalPoint & xmeas,
253  const GlobalPoint & vprim,
254  float energy, float fcharge )
255  {
256  float SCl_phi = xmeas.phi();
257 
258  int charge = int(fcharge);
259  // return all compatible RecHit pairs (vector< TSiPixelRecHit>)
260  vector<pair<RecHitWithDist, ConstRecHitPointer> > result;
261  LogDebug("") << "[PixelHitMatcher::compatibleHits] entering .. ";
262 
263  vector<TrajectoryMeasurement> validMeasurements;
264  vector<TrajectoryMeasurement> invalidMeasurements;
265 
266  typedef vector<TrajectoryMeasurement>::const_iterator aMeas;
267 
268  pred1Meas.clear();
269  pred2Meas.clear();
270 
271  typedef vector<BarrelDetLayer*>::const_iterator BarrelLayerIterator;
272  BarrelLayerIterator firstLayer = startLayers.firstBLayer();
273 
274  FreeTrajectoryState fts =myFTS(theMagField,xmeas, vprim,
275  energy, charge);
276 
278  TrajectoryStateOnSurface tsos(fts, *bpb(fts.position(), fts.momentum()));
279 
280  if (tsos.isValid()) {
281  vector<TrajectoryMeasurement> pixelMeasurements =
282  theLayerMeasurements->measurements(**firstLayer,tsos,
283  *prop1stLayer, meas1stBLayer);
284 
285  LogDebug("") <<"[PixelHitMatcher::compatibleHits] nbr of hits compatible with extrapolation to first layer: " << pixelMeasurements.size();
286  for (aMeas m=pixelMeasurements.begin(); m!=pixelMeasurements.end(); m++){
287  if (m->recHit()->isValid()) {
288  float localDphi = normalized_phi(SCl_phi-m->forwardPredictedState().globalPosition().phi()) ;
289  if(std::abs(localDphi)>2.5)continue;
290  CLHEP::Hep3Vector prediction(m->forwardPredictedState().globalPosition().x(),
291  m->forwardPredictedState().globalPosition().y(),
292  m->forwardPredictedState().globalPosition().z());
293  LogDebug("") << "[PixelHitMatcher::compatibleHits] compatible hit position " << m->recHit()->globalPosition();
294  LogDebug("") << "[PixelHitMatcher::compatibleHits] predicted position " << m->forwardPredictedState().globalPosition();
295  pred1Meas.push_back( prediction);
296 
297  validMeasurements.push_back(*m);
298 
299  LogDebug("") <<"[PixelHitMatcher::compatibleHits] Found a rechit in layer ";
300  const BarrelDetLayer *bdetl = dynamic_cast<const BarrelDetLayer *>(*firstLayer);
301  if (bdetl) {
302  LogDebug("") <<" with radius "<<bdetl->specificSurface().radius();
303  }
304  else LogDebug("") <<"Could not downcast!!";
305  }
306  }
307 
308 
309  // check if there are compatible 1st hits in the second layer
310  firstLayer++;
311 
312  vector<TrajectoryMeasurement> pixel2Measurements =
313  theLayerMeasurements->measurements(**firstLayer,tsos,
314  *prop1stLayer, meas1stBLayer);
315 
316  for (aMeas m=pixel2Measurements.begin(); m!=pixel2Measurements.end(); m++){
317  if (m->recHit()->isValid()) {
318  float localDphi = normalized_phi(SCl_phi-m->forwardPredictedState().globalPosition().phi()) ;
319  if(std::abs(localDphi)>2.5)continue;
320  CLHEP::Hep3Vector prediction(m->forwardPredictedState().globalPosition().x(),
321  m->forwardPredictedState().globalPosition().y(),
322  m->forwardPredictedState().globalPosition().z());
323  pred1Meas.push_back( prediction);
324  LogDebug("") << "[PixelHitMatcher::compatibleHits] compatible hit position " << m->recHit()->globalPosition() << endl;
325  LogDebug("") << "[PixelHitMatcher::compatibleHits] predicted position " << m->forwardPredictedState().globalPosition() << endl;
326 
327  validMeasurements.push_back(*m);
328  LogDebug("") <<"[PixelHitMatcher::compatibleHits] Found a rechit in layer ";
329  const BarrelDetLayer *bdetl = dynamic_cast<const BarrelDetLayer *>(*firstLayer);
330  if (bdetl) {
331  LogDebug("") <<" with radius "<<bdetl->specificSurface().radius();
332  }
333  else LogDebug("") <<"Could not downcast!!";
334  }
335 
336  }
337  }
338 
339 
340  // check if there are compatible 1st hits the forward disks
341  typedef vector<ForwardDetLayer*>::const_iterator ForwardLayerIterator;
342  ForwardLayerIterator flayer;
343 
344  TrajectoryStateOnSurface tsosfwd(fts, *bpb(fts.position(), fts.momentum()));
345  if (tsosfwd.isValid()) {
346 
347  for (int i=0; i<2; i++) {
348  i == 0 ? flayer = startLayers.pos1stFLayer() : flayer = startLayers.neg1stFLayer();
349 
350  if (i==0 && xmeas.z() < -100. ) continue;
351  if (i==1 && xmeas.z() > 100. ) continue;
352 
353  vector<TrajectoryMeasurement> pixelMeasurements =
354  theLayerMeasurements->measurements(**flayer, tsosfwd,
355  *prop1stLayer, meas1stFLayer);
356 
357  for (aMeas m=pixelMeasurements.begin(); m!=pixelMeasurements.end(); m++){
358  if (m->recHit()->isValid()) {
359  float localDphi = normalized_phi(SCl_phi-m->forwardPredictedState().globalPosition().phi());
360  if(std::abs(localDphi)>2.5)continue;
361  CLHEP::Hep3Vector prediction(m->forwardPredictedState().globalPosition().x(),
362  m->forwardPredictedState().globalPosition().y(),
363  m->forwardPredictedState().globalPosition().z());
364  pred1Meas.push_back( prediction);
365 
366  validMeasurements.push_back(*m);
367  }
368  }
369 
370  //check if there are compatible 1st hits the outer forward disks
371  if (searchInTIDTEC_) {
372  flayer++;
373 
374  vector<TrajectoryMeasurement> pixel2Measurements =
375  theLayerMeasurements->measurements(**flayer, tsosfwd,
376  *prop1stLayer, meas1stFLayer);
377 
378  for (aMeas m=pixel2Measurements.begin(); m!=pixel2Measurements.end(); m++){
379  if (m->recHit()->isValid()) {
380  float localDphi = normalized_phi(SCl_phi-m->forwardPredictedState().globalPosition().phi()) ;
381  if(std::abs(localDphi)>2.5)continue;
382  CLHEP::Hep3Vector prediction(m->forwardPredictedState().globalPosition().x(),
383  m->forwardPredictedState().globalPosition().y(),
384  m->forwardPredictedState().globalPosition().z());
385  pred1Meas.push_back( prediction);
386 
387  validMeasurements.push_back(*m);
388  }
389  // else{std::cout<<" hit non valid "<<std::endl; }
390  } //end 1st hit in outer f disk
391  }
392  }
393  }
394 
395  // now we have the vector of all valid measurements of the first point
396  for (unsigned i=0; i<validMeasurements.size(); i++){
397 
398  const DetLayer * newLayer = theGeometricSearchTracker->detLayer(validMeasurements[i].recHit()->det()->geographicalId());
399 
400  double zVertex ;
401  if (!useRecoVertex_)
402  {
403  // we don't know the z vertex position, get it from linear extrapolation
404  // compute the z vertex from the cluster point and the found pixel hit
405  double pxHit1z = validMeasurements[i].recHit()->det()->surface().toGlobal(
406  validMeasurements[i].recHit()->localPosition()).z();
407  double pxHit1x = validMeasurements[i].recHit()->det()->surface().toGlobal(
408  validMeasurements[i].recHit()->localPosition()).x();
409  double pxHit1y = validMeasurements[i].recHit()->det()->surface().toGlobal(
410  validMeasurements[i].recHit()->localPosition()).y();
411  double r1diff = (pxHit1x-vprim.x())*(pxHit1x-vprim.x()) + (pxHit1y-vprim.y())*(pxHit1y-vprim.y());
412  r1diff=sqrt(r1diff);
413  double r2diff = (xmeas.x()-pxHit1x)*(xmeas.x()-pxHit1x) + (xmeas.y()-pxHit1y)*(xmeas.y()-pxHit1y);
414  r2diff=sqrt(r2diff);
415  zVertex = pxHit1z - r1diff*(xmeas.z()-pxHit1z)/r2diff;
416  }
417  else
418  {
419  // here we use the reco vertex z position
420  zVertex = vprim.z();
421  }
422 
423  if (i==0)
424  { vertex_ = zVertex; }
425 
426  GlobalPoint vertexPred(vprim.x(),vprim.y(),zVertex) ;
427  GlobalPoint hitPos( validMeasurements[i].recHit()->det()->surface().toGlobal( validMeasurements[i].recHit()->localPosition() ) ) ;
428 
429  FreeTrajectoryState secondFTS=myFTS(theMagField,hitPos,vertexPred,energy, charge);
430 
431  PixelMatchNextLayers secondHit(theLayerMeasurements, newLayer, secondFTS,
432  prop2ndLayer, &meas2ndBLayer,&meas2ndFLayer,searchInTIDTEC_);
433  vector<CLHEP::Hep3Vector> predictions = secondHit.predictionInNextLayers();
434 
435  for (unsigned it = 0; it < predictions.size(); it++) pred2Meas.push_back(predictions[it]);
436 
437  // we may get more than one valid second measurements here even for single electrons:
438  // two hits from the same layer/disk (detector overlap) or from the loop over the
439  // next layers in EPMatchLoopNextLayers. Take only the 1st hit.
440 
441  if(!secondHit.measurementsInNextLayers().empty()){
442  for(unsigned int shit=0; shit<secondHit.measurementsInNextLayers().size(); shit++)
443  {
444  float dphi = normalized_phi(pred1Meas[i].phi()-validMeasurements[i].recHit()->globalPosition().phi()) ;
445  if (std::abs(dphi)<2.5)
446  {
447  ConstRecHitPointer pxrh = validMeasurements[i].recHit();
448  RecHitWithDist rh(pxrh,dphi);
449 
450  // pxrh = secondHit.measurementsInNextLayers()[0].recHit();
451  pxrh = secondHit.measurementsInNextLayers()[shit].recHit();
452 
453  pair<RecHitWithDist,ConstRecHitPointer> compatiblePair = pair<RecHitWithDist,ConstRecHitPointer>(rh,pxrh) ;
454  result.push_back(compatiblePair);
455  break;
456  }
457  }
458  }
459  }
460  return result;
461 }
462 
463 
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:78
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
int i
Definition: DBlmapReader.cc:9
std::vector< std::pair< RecHitWithDist, ConstRecHitPointer > > compatibleHits(const GlobalPoint &xmeas, const GlobalPoint &vprim, float energy, float charge)
void setES(const MagneticField *, const MeasurementTracker *theMeasurementTracker, const TrackerGeometry *trackerGeometry)
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
T y() const
Definition: PV3DBase.h:57
#define abs(x)
Definition: mlp_lapack.h:159
std::vector< CLHEP::Hep3Vector > predictionInNextLayers() const
double charge(const std::vector< uint8_t > &Ampls)
void set2ndLayer(float dummyphi2minB, float dummyphi2maxB, float dummyphi2minF, float dummyphi2maxF)
U second(std::pair< T, U > const &p)
void set1stLayerZRange(float zmin1, float zmax1)
PixelHitMatcher(float phi1min, float phi1max, float phi2minB, float phi2maxB, float phi2minF, float phi2maxF, float z2minB, float z2maxB, float r2minF, float r2maxF, float rMinI, float rMaxI, bool searchInTIDTEC)
Scalar radius() const
Radius of the cylinder.
Definition: Cylinder.h:55
std::vector< TrajectorySeed > TrajectorySeedCollection
recHitContainer::const_iterator const_iterator
RealType normalized_phi(RealType phi)
T sqrt(T t)
Definition: SSEVec.h:28
T z() const
Definition: PV3DBase.h:58
tuple result
Definition: query.py:137
std::pair< const_iterator, const_iterator > range
std::vector< CLHEP::Hep3Vector > predicted1Hits()
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
GlobalVector momentum() const
Definition: DetId.h:20
GlobalPoint position() const
std::vector< TrajectoryMeasurement > measurementsInNextLayers() const
const GlobalTrajectoryParameters & globalParameters() const
void set1stLayer(float dummyphi1min, float dummyphi1max)
virtual const BoundCylinder & specificSurface() const
Extension of the interface.
virtual ~PixelHitMatcher()
std::vector< SeedWithInfo > compatibleSeeds(TrajectorySeedCollection *seeds, const GlobalPoint &xmeas, const GlobalPoint &vprim, float energy, float charge)
std::vector< CLHEP::Hep3Vector > predicted2Hits()
T x() const
Definition: PV3DBase.h:56
void setUseRecoVertex(bool val)
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
Definition: DDAxes.h:10