CMS 3D CMS Logo

MultiVertexReconstructor.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
5 namespace {
6  typedef MultiVertexFitter::TrackAndWeight TrackAndWeight;
7 
8  int verbose()
9  {
10  return 0;
11  }
12 
13 #ifndef __clang__
14  inline void remove ( vector < TransientVertex > & vtces,
15  const vector < reco::TransientTrack > & trks )
16  {
17  cout << "[MultiVertexReconstructor] fixme remove not yet implemented" << endl;
18  // remove trks from vtces
19  }
20 #endif
21 
22  vector < vector < TrackAndWeight > > recover (
23  const vector < TransientVertex > & vtces, const vector < reco::TransientTrack > & trks )
24  {
25  set < reco::TransientTrack > st;
26  for ( vector< reco::TransientTrack >::const_iterator i=trks.begin();
27  i!=trks.end() ; ++i )
28  {
29  st.insert ( *i );
30  }
31 
32  vector < vector < TrackAndWeight > > bundles;
33  for ( vector< TransientVertex >::const_iterator vtx=vtces.begin();
34  vtx!=vtces.end() ; ++vtx )
35  {
36  vector < reco::TransientTrack > trks = vtx->originalTracks();
37  vector < TrackAndWeight > tnws;
38  for ( vector< reco::TransientTrack >::const_iterator trk=trks.begin();
39  trk!=trks.end() ; ++trk )
40  {
41  float w = vtx->trackWeight ( *trk );
42  if ( w > 1e-5 )
43  {
44  TrackAndWeight tmp ( *trk, w );
45  set < reco::TransientTrack >::iterator pos = st.find( *trk );
46  if ( pos != st.end() )
47  {
48  st.erase ( pos );
49  }
50  tnws.push_back ( tmp );
51  };
52  };
53  bundles.push_back ( tnws );
54  };
55 
56  if ( bundles.empty() ) return bundles;
57 
58  // now add not-yet assigned tracks
59  for ( set < reco::TransientTrack >::const_iterator i=st.begin();
60  i!=st.end() ; ++i )
61  {
62  // cout << "[MultiVertexReconstructor] recovering " << i->id() << endl;
63  TrackAndWeight tmp ( *i, 0. );
64  bundles[0].push_back ( tmp );
65  }
66  return bundles;
67  }
68 }
69 
71  const VertexReconstructor & o, const AnnealingSchedule & s, float revive ) :
72  theOldReconstructor ( o.clone() ), theFitter (
74 {
75 }
76 
78 {
79  delete theOldReconstructor;
80 }
81 
83 {
84  return new MultiVertexReconstructor ( * this );
85 }
86 
88  const MultiVertexReconstructor & o ) :
90  theFitter ( o.theFitter )
91 {}
92 
93 vector < TransientVertex > MultiVertexReconstructor::vertices (
94  const vector < reco::TransientTrack > & trks,
95  const reco::BeamSpot & s ) const
96 {
97  return vertices ( trks );
98 }
99 
100 vector < TransientVertex > MultiVertexReconstructor::vertices (
101  const vector < reco::TransientTrack > & trks,
102  const vector < reco::TransientTrack > & primaries,
103  const reco::BeamSpot & s ) const
104 {
105  return vertices ( trks, primaries );
106 }
107 
108 
109 vector < TransientVertex > MultiVertexReconstructor::vertices (
110  const vector < reco::TransientTrack > & trks ) const
111 {
112  /*
113  cout << "[MultiVertexReconstructor] input trks: ";
114  for ( vector< reco::TransientTrack >::const_iterator i=trks.begin();
115  i!=trks.end() ; ++i )
116  {
117  cout << i->id() << " ";
118  }
119  cout << endl;*/
120  vector < TransientVertex > tmp = theOldReconstructor->vertices ( trks );
121  if ( verbose() )
122  {
123  cout << "[MultiVertexReconstructor] non-freezing seeder found " << tmp.size()
124  << " vertices from " << trks.size() << " tracks." << endl;
125  }
126  vector < vector < TrackAndWeight > > rc = recover ( tmp, trks );
127  vector < CachingVertex<5> > cvts = theFitter.vertices ( rc );
128  vector < TransientVertex > ret;
129  for ( vector< CachingVertex<5> >::const_iterator i=cvts.begin();
130  i!=cvts.end() ; ++i )
131  {
132  ret.push_back ( *i );
133  };
134 
135  if ( verbose() )
136  {
137  cout << "[MultiVertexReconstructor] input " << tmp.size()
138  << " vertices, output " << ret.size() << " vertices."
139  << endl;
140  };
141  return ret;
142 }
143 
144 vector < TransientVertex > MultiVertexReconstructor::vertices (
145  const vector < reco::TransientTrack > & trks,
146  const vector < reco::TransientTrack > & primaries ) const
147 {
148  /*
149  cout << "[MultiVertexReconstructor] with " << primaries.size()
150  << " primaries!" << endl;
151  */
152 
153  map < reco::TransientTrack, bool > st;
154 
155  vector < reco::TransientTrack > total = trks;
156  for ( vector< reco::TransientTrack >::const_iterator i=trks.begin();
157  i!=trks.end() ; ++i )
158  {
159  st[(*i)]=true;
160  }
161 
162  // cout << "[MultiVertexReconstructor] FIXME dont just add up tracks. superpose" << endl;
163  for ( vector< reco::TransientTrack >::const_iterator i=primaries.begin();
164  i!=primaries.end() ; ++i )
165  {
166  if (!(st[(*i)]))
167  {
168  total.push_back ( *i );
169  }
170  }
171 
172  vector < TransientVertex > tmp = theOldReconstructor->vertices ( total );
173 
174  if ( verbose() )
175  {
176  cout << "[MultiVertexReconstructor] freezing seeder found " << tmp.size()
177  << " vertices from " << total.size() << " tracks." << endl;
178  }
179  vector < vector < TrackAndWeight > > rc = recover ( tmp, trks );
180  vector < CachingVertex<5> > cvts = theFitter.vertices ( rc, primaries );
181 
182  vector < TransientVertex > ret;
183  for ( vector< CachingVertex<5> >::const_iterator i=cvts.begin();
184  i!=cvts.end() ; ++i )
185  {
186  ret.push_back ( *i );
187  };
188  if ( verbose() )
189  {
190  cout << "[MultiVertexReconstructor] input " << tmp.size()
191  << " vertices, output " << ret.size() << " vertices."
192  << endl;
193  };
194  return ret;
195 }
196 
198 {
199  return theOldReconstructor;
200 }
std::vector< CachingVertex< 5 > > vertices(const std::vector< std::vector< reco::TransientTrack > > &, const std::vector< reco::TransientTrack > &primaries=std::vector< reco::TransientTrack >())
MultiVertexReconstructor * clone() const override
std::pair< reco::TransientTrack, float > TrackAndWeight
const double w
Definition: UKUtility.cc:23
VertexReconstructor * reconstructor() const
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &, const reco::BeamSpot &) const override
VertexReconstructor * theOldReconstructor
static int verbose
virtual std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &) const =0
MultiVertexReconstructor(const VertexReconstructor &, const AnnealingSchedule &s=DefaultMVFAnnealing(), float revive=-1.)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100