CMS 3D CMS Logo

MultiVertexBSeeder.cc
Go to the documentation of this file.
2 // #include "RecoVertex/AdaptiveVertexFit/interface/AdaptiveVertexFitter.h"
4 // #include "RecoVertex/VertexTools/interface/BeamSpot.h"
8 // #include "CommonTools/Clustering1D/interface/MultiClusterizer1D.h"
12 
13 // #define MVBS_DEBUG
14 #ifdef MVBS_DEBUG
15 #include <map>
16 #include "RecoVertex/MultiVertexFit/interface/DebuggingHarvester.h"
17 #endif
18 
19 using namespace std;
20 
21 namespace {
22  vector<reco::TransientTrack> convert(const vector<const reco::TransientTrack*>& ptrs) {
23  vector<reco::TransientTrack> ret;
24  for (vector<const reco::TransientTrack*>::const_iterator i = ptrs.begin(); i != ptrs.end(); ++i) {
25  ret.push_back(**i);
26  }
27  return ret;
28  }
29 
30 #ifndef __clang__
31  inline GlobalPoint& operator+=(GlobalPoint& a, const GlobalPoint& b) {
32  a = GlobalPoint(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
33  return a;
34  }
35 #endif
36 
37  inline GlobalPoint& operator/=(GlobalPoint& a, float b) {
38  a = GlobalPoint(a.x() / b, a.y() / b, a.z() / b);
39  return a;
40  }
41 
42 #ifndef __clang__
43  inline bool element(const reco::TransientTrack& rt, const TransientVertex& rv) {
44  const vector<reco::TransientTrack> trks = rv.originalTracks();
45  for (vector<reco::TransientTrack>::const_iterator i = trks.begin(); i != trks.end(); ++i) {
46  if (rt == (*i))
47  return true;
48  };
49  return false;
50  }
51 #endif
52 
53  GlobalPoint toPoint(const GlobalVector& v) { return GlobalPoint(v.x(), v.y(), v.z()); }
54 
55  GlobalVector toVector(const GlobalPoint& v) { return GlobalVector(v.x(), v.y(), v.z()); }
56 
57  GlobalPoint computeJetOrigin(const vector<reco::TransientTrack>& trks) {
59  vector<ModeFinder3d::PointAndDistance> input;
60  for (vector<reco::TransientTrack>::const_iterator i = trks.begin(); i != trks.end(); ++i) {
61  input.push_back(ModeFinder3d::PointAndDistance(i->impactPointState().globalPosition(), 1.));
62  }
63  return f(input);
64  }
65 
66  GlobalVector computeJetDirection(const vector<reco::TransientTrack>& trks) {
68  vector<ModeFinder3d::PointAndDistance> input;
69  for (vector<reco::TransientTrack>::const_iterator i = trks.begin(); i != trks.end(); ++i) {
70  input.push_back(ModeFinder3d::PointAndDistance(toPoint(i->impactPointState().globalMomentum()), 1.));
71  }
73  pt /= pt.mag();
74  return toVector(pt);
75  }
76 
77  GlobalTrajectoryParameters computeJetTrajectory(const vector<reco::TransientTrack>& trks) {
84  if (trks.empty())
86 
87  GlobalVector mom = computeJetDirection(trks);
88  GlobalPoint pos = computeJetOrigin(trks);
89 
90  GlobalTrajectoryParameters ret(pos, mom, 0, &(trks[0].impactPointState().globalParameters().magneticField()));
91 #ifdef MVBS_DEBUG
92  DebuggingHarvester("out.txt").save(ret, "p<sub>tot</sub>");
93 #endif
94  return ret;
95  }
96 
97  vector<Cluster1D<reco::TransientTrack> > computeIPs(const vector<reco::TransientTrack>& trks) {
98  GlobalTrajectoryParameters jet = computeJetTrajectory(trks);
101  vector<Cluster1D<reco::TransientTrack> > pts;
102  for (vector<reco::TransientTrack>::const_iterator i = trks.begin(); i != trks.end(); ++i) {
103  bool status = ttmd.calculate(axis, *(i->impactPointState().freeState()));
104  if (status) {
105  pair<GlobalPoint, GlobalPoint> pt = ttmd.points();
106  double d = (pt.first - pt.second).mag();
107  double w = 1. / (0.002 + d); // hard coded weights
108  double s = (pt.first - axis.position()).mag();
109  Measurement1D ms(s, 1.0);
110  vector<const reco::TransientTrack*> trk;
111  trk.push_back(&(*i));
112  pts.push_back(Cluster1D<reco::TransientTrack>(ms, trk, w));
113  }
114  }
115  /*
116  #ifdef MVBS_DEBUG
117  map < string, harvest::MultiType > attrs;
118  attrs["point:mag"]=0.5;
119  attrs["point:color"]="khaki";
120  DebuggingHarvester("out.txt").save ( pts, jet, attrs, "ip" );
121  #endif
122  */
123  return pts;
124  }
125 
126 #ifndef __clang__
127  inline GlobalPoint computePos(const GlobalTrajectoryParameters& jet, double s) {
128  GlobalPoint ret = jet.position();
129  ret += s * jet.momentum();
130  return ret;
131  }
132 #endif
133 
134  TransientVertex pseudoVertexFit(const Cluster1D<reco::TransientTrack>& src,
135  bool ascending = false,
136  bool kalmanfit = false) {
137  // cout << "[MultiVertexBSeeder] debug: pseudoVertexFit with " << flush;
138  vector<const reco::TransientTrack*> trkptrs = src.tracks();
139  vector<reco::TransientTrack> trks = convert(trkptrs);
140  // cout << trks.size() << " tracks.";
141  GlobalPoint gp;
142  GlobalError ge;
143  if (kalmanfit) {
145  gp = v.position();
146  }
147  TransientVertex ret = TransientVertex(gp, ge, trks, -1.);
149  float w = 1.0;
150  float r = 0.5;
151  if (ascending) {
152  w = pow((float)0.5, (int)(trks.size() - 1));
153  r = 2.0;
154  };
155  for (vector<reco::TransientTrack>::const_iterator i = trks.begin(); i != trks.end(); ++i) {
156  mp[*i] = w;
157  w *= r;
158  }
159  ret.weightMap(mp);
160  // cout << "[MultiVertexBSeeder] debug: return pseudoVertexFit with " << endl;
161  return ret;
162  }
163 
164  /* TransientVertex kalmanVertexFit ( const Cluster1D < reco::TransientTrack > & src )
165  {
166  KalmanVertexFitter fitter;
167  vector < const reco::TransientTrack * > trkptrs=src.tracks();
168  vector < reco::TransientTrack > trks = convert ( trkptrs );
169  return fitter.vertex ( trks );
170  return TransientVertex();
171  }*/
172 } // namespace
173 
175 
177 
178 vector<TransientVertex> MultiVertexBSeeder::vertices(const vector<reco::TransientTrack>& trks,
179  const reco::BeamSpot& s) const {
180  return vertices(trks);
181 }
182 
183 vector<TransientVertex> MultiVertexBSeeder::vertices(const vector<reco::TransientTrack>& trks) const {
184  vector<Cluster1D<reco::TransientTrack> > ips = computeIPs(trks);
185  /*
186  FsmwClusterizer1D < reco::TransientTrack > fsmw ( .4, theNSigma );
187  MultiClusterizer1D<reco::TransientTrack> finder ( fsmw );
188  */
190 
191  pair<vector<Cluster1D<reco::TransientTrack> >, vector<const reco::TransientTrack*> > res;
192  res = finder(ips);
193 #ifdef MVBS_DEBUG
194  // need to compute jet trajectory again :-(
195  GlobalTrajectoryParameters jet = computeJetTrajectory(trks);
196  map<string, harvest::MultiType> attrs;
197  attrs["point:mag"] = 0.75;
198  attrs["point:color"] = "blue";
199  attrs["point:name"] = "mode";
200  DebuggingHarvester("out.txt").save(res.first, jet, attrs, "mode");
201 #endif
202 
203  vector<TransientVertex> ret;
204  for (vector<Cluster1D<reco::TransientTrack> >::const_iterator i = res.first.begin(); i != res.first.end(); ++i) {
205  ret.push_back(pseudoVertexFit(*i,
206  i != res.first.begin(),
207  /* kalman fit*/ true));
208  }
209  return ret;
210 }
211 
212 #ifdef MVBS_DEBUG
213 #undef MVBS_DEBUG
214 #endif
T w() const
ret
prodAgent to be discontinued
std::map< reco::TransientTrack, float > TransientTrackToFloatMap
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< T > toVector(pybind11::list &l)
Definition: Electron.h:6
static std::string const input
Definition: EdmProvDump.cc:50
bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb) override
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
static const double pts[33]
Definition: Constants.h:30
std::vector< reco::TransientTrack > const & originalTracks() const
double f[11][100]
std::pair< GlobalPoint, GlobalPoint > points() const override
def convert(infile, ofile)
d
Definition: ztail.py:151
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
std::pair< GlobalPoint, float > PointAndDistance
Definition: ModeFinder3d.h:16
double b
Definition: hdecay.h:120
MultiVertexBSeeder * clone() const override
double a
Definition: hdecay.h:121
MultiVertexBSeeder(double nsigma=50.)
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &) const override
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
Basic3DVector & operator+=(const Basic3DVector< U > &p)
Global3DVector GlobalVector
Definition: GlobalVector.h:10