CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SeedMatcher.cc
Go to the documentation of this file.
2 
11 
12 #include "iostream"
13 
15  const FastTrackerRecHitCombinationCollection & recHitCombinationCollection,
16  const edm::SimTrackContainer & simTrackCollection,
17  double maxMatchEstimator,
18  const Propagator & propagator,
20  const TrackerGeometry & trackerGeometry)
21 {
22 
23  // container for result
24  std::vector<int32_t> result;
25 
26  // seed state
28  DetId seedState_detId(ptod.detId());
29  const GeomDet * seedState_det = trackerGeometry.idToDet(seedState_detId);
30  const Surface * seedState_surface=&seedState_det->surface();
31  TrajectoryStateOnSurface seedState(trajectoryStateTransform::transientState(ptod,seedState_surface,&magneticField));
32 
33  // find matches
34  int nSimTracks = simTrackCollection.size();
35  for(unsigned recHitCombinationIndex = 0;recHitCombinationIndex < recHitCombinationCollection.size(); recHitCombinationIndex++)
36  {
37  const auto & recHitCombination = recHitCombinationCollection[recHitCombinationIndex];
38  int simTrackIndex = recHitCombination.back()->simTrackId(0);
39  if(simTrackIndex < 0 || simTrackIndex >= nSimTracks)
40  {
41  throw cms::Exception("SeedMatcher") << "SimTrack index out of range: " << simTrackIndex << std::endl;
42  }
43  const auto & simTrack = simTrackCollection[recHitCombination.back()->simTrackId(0)];
44  double matchEstimator = matchSimTrack(seedState,simTrack,propagator,magneticField);
45  if(matchEstimator < maxMatchEstimator)
46  {
47  result.push_back(recHitCombinationIndex);
48  }
49  }
50  return result;
51 }
52 
54  const SimTrack & simTrack,
55  const Propagator & propagator,
57 {
58 
59  // simtrack and simvertex at tracker surface
60  GlobalPoint simTrack_atTrackerSurface_position(simTrack.trackerSurfacePosition().x(),
61  simTrack.trackerSurfacePosition().y(),
62  simTrack.trackerSurfacePosition().z());
63  GlobalVector simTrack_atTrackerSurface_momentum(simTrack.trackerSurfaceMomentum().x(),
64  simTrack.trackerSurfaceMomentum().y(),
65  simTrack.trackerSurfaceMomentum().z());
66 
67  // no match if seedstate and simtrack in oposite direction
68  if ( simTrack_atTrackerSurface_position.basicVector().dot(simTrack_atTrackerSurface_momentum.basicVector() )
69  * seedState.globalPosition().basicVector().dot(seedState.globalMomentum().basicVector()) <0. )
70  {
71  return 9999.;
72  }
73 
74  // find simtrack state on surface of seed state
75  GlobalTrajectoryParameters simTrack_atTrackerSurface_parameters(simTrack_atTrackerSurface_position,
76  simTrack_atTrackerSurface_momentum,
77  simTrack.charge(),
78  &magneticField);
79  FreeTrajectoryState simtrack_atTrackerSurface_state(simTrack_atTrackerSurface_parameters);
80  TrajectoryStateOnSurface simtrack_atSeedStateSurface_state = propagator.propagate(simtrack_atTrackerSurface_state,seedState.surface());
81 
82  // simtrack does not propagate to surface of seed state
83  if (!simtrack_atSeedStateSurface_state.isValid())
84  {
85  return 9999.;
86  }
87 
88  // simtrack and seed state have opposite direction
89  if ( simtrack_atSeedStateSurface_state.globalPosition().basicVector().dot(simtrack_atSeedStateSurface_state.globalMomentum().basicVector())
90  * seedState.globalPosition().basicVector().dot(seedState.globalMomentum().basicVector()) <0. )
91  {
92  return 9999.;
93  }
94 
95  AlgebraicVector5 difference(seedState.localParameters().vector() - simtrack_atSeedStateSurface_state.localParameters().vector());
97  if(!error.Invert())
98  {
99  edm::LogWarning("FastSim SeedToSimTrackMatcher") <<"Cannot invert seed state error matrix => no match...";
100  return 9999.;
101  }
102 
103  return ROOT::Math::Similarity(difference,error);
104 }
const math::XYZVectorD & trackerSurfacePosition() const
Definition: SimTrack.h:36
tuple propagator
static std::vector< int > matchRecHitCombinations(const TrajectorySeed &seed, const FastTrackerRecHitCombinationCollection &recHitCombinationCollection, const std::vector< SimTrack > &simTrackCollection, double maxMatchEstimator, const Propagator &propagator, const MagneticField &magneticField, const TrackerGeometry &trackerGeometry)
Definition: SeedMatcher.cc:14
const LocalTrajectoryParameters & localParameters() const
GlobalPoint globalPosition() const
tuple magneticField
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
float charge() const
charge
Definition: CoreSimTrack.cc:18
tuple result
Definition: mps_fire.py:95
AlgebraicVector5 vector() const
const SurfaceType & surface() const
static double matchSimTrack(const TrajectoryStateOnSurface &seedState, const SimTrack &simTrack, const Propagator &propagator, const MagneticField &magneticField)
Definition: SeedMatcher.cc:53
unsigned int detId() const
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
Definition: DetId.h:18
PTrajectoryStateOnDet const & startingState() const
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
ROOT::Math::SVector< double, 5 > AlgebraicVector5
const math::XYZTLorentzVectorD & trackerSurfaceMomentum() const
Definition: SimTrack.h:38
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
GlobalVector globalMomentum() const
std::vector< FastTrackerRecHitCombination > FastTrackerRecHitCombinationCollection
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
std::vector< SimTrack > SimTrackContainer
virtual const TrackerGeomDet * idToDet(DetId) const
T dot(const Basic3DVector &rh) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.