CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetSignalVertexCompatibilityAlgo.cc
Go to the documentation of this file.
1 #include <functional>
2 #include <cmath>
3 #include <map>
4 
9 
15 
17 
19 
20 using namespace reco;
21 
22 // helper
23 template<typename T>
24 inline bool
26  const edm::RefToBase<T> &r1, const edm::RefToBase<T> &r2) const
27 { return r1.id() < r2.id() || (r1.id() == r2.id() && r1.key() < r2.key()); }
28 
29 
31  double cut, double temperature) :
32  cut(cut), temperature(temperature)
33 {}
34 
36 {}
37 
39  const Vertex &vtx, const TransientTrack &track)
40 {
44  extrap.extrapolate(track.impactPointState(), point1);
45 
46  if (!tsos.isValid())
47  return 1.0e6;
48 
49  GlobalPoint point2 = tsos.globalPosition();
50  ROOT::Math::SVector<double, 3> dir(point1.x() - point2.x(),
51  point1.y() - point2.y(),
52  point1.z() - point2.z());
54  tsos.cartesianError().position();
55 
56  return ROOT::Math::Mag2(dir) /
57  std::sqrt(ROOT::Math::Similarity(cov.matrix_new(), dir));
58 }
59 
60 const TransientTrack&
62 {
63  TransientTrackMap::iterator pos = trackMap.lower_bound(track);
64  if (pos != trackMap.end() && pos->first == track)
65  return pos->second;
66 
67  // the castTo will only work with regular, i.e. no GsfTracks
68  // the interface is not intrinsically polymorph...
69  return trackMap.insert(pos,
70  std::make_pair(track, trackBuilder->build(
71  track.castTo<TrackRef>())))->second;
72 }
73 
75 {
76  return 1. / (std::exp((compat - cut) / temperature) + 1.);
77 }
78 
79 std::vector<float>
81  const reco::VertexCollection &vertices,
82  const reco::TrackRefVector &tracks) const
83 {
84  std::vector<float> result(vertices.size(), 0.);
85  float sum = 0.;
86 
87  for(TrackRefVector::const_iterator track = tracks.begin();
88  track != tracks.end(); ++track) {
89  const TransientTrack &transientTrack =
90  convert(TrackBaseRef(*track));
91 
92  for(unsigned int i = 0; i < vertices.size(); i++) {
93  double compat =
94  trackVertexCompat(vertices[i], transientTrack);
95  double contribution =
96  activation(compat) * (*track)->pt();
97 
98  result[i] += contribution;
99  sum += contribution;
100  }
101  }
102 
103  if (sum < 1.0e-9) {
104  for(unsigned int i = 0; i < result.size(); i++)
105  result[i] = 1.0 / result.size();
106  } else {
107  for(unsigned int i = 0; i < result.size(); i++)
108  result[i] /= sum;
109  }
110 
111  return result;
112 }
113 
115  const TransientTrackBuilder *builder)
116 {
117  trackMap.clear();
118  trackBuilder = builder;
119 }
120 
reco::Vertex::Point convertPos(const GlobalPoint &p)
std::vector< float > compatibility(const reco::VertexCollection &vertices, const reco::TrackRefVector &tracks) const
int i
Definition: DBlmapReader.cc:9
reco::Vertex::Error convertError(const GlobalError &ge)
Definition: ConvertError.h:8
reco::TransientTrack build(const reco::Track *p) const
GlobalPoint globalPosition() const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const MagneticField * field() const
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:123
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
const Point & position() const
position
Definition: Vertex.h:106
ProductID id() const
Definition: RefToBase.h:221
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
static double trackVertexCompat(const reco::Vertex &vtx, const TransientTrack &track)
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:31
size_t key() const
Definition: RefToBase.h:229
T sqrt(T t)
Definition: SSEVec.h:48
void resetEvent(const TransientTrackBuilder *trackBuilder)
tuple result
Definition: query.py:137
tuple tracks
Definition: testEve_cfg.py:39
REF castTo() const
cast to a concrete type
Definition: RefToBase.h:242
JetSignalVertexCompatibilityAlgo(double cut, double temperature)
const TransientTrack & convert(const reco::TrackBaseRef &track) const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
Definition: Point3D.h:17
TrajectoryStateOnSurface impactPointState() const
bool operator()(const edm::RefToBase< T > &r1, const edm::RefToBase< T > &r2) const
dbl *** dir
Definition: mlp_gen.cc:35