CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  void remove ( vector < TransientVertex > & vtces,
14  const vector < reco::TransientTrack > & trks )
15  {
16  cout << "[MultiVertexReconstructor] fixme remove not yet implemented" << endl;
17  // remove trks from vtces
18  }
19 
20  vector < vector < TrackAndWeight > > recover (
21  const vector < TransientVertex > & vtces, const vector < reco::TransientTrack > & trks )
22  {
23  set < reco::TransientTrack > st;
24  for ( vector< reco::TransientTrack >::const_iterator i=trks.begin();
25  i!=trks.end() ; ++i )
26  {
27  st.insert ( *i );
28  }
29 
30  vector < vector < TrackAndWeight > > bundles;
31  for ( vector< TransientVertex >::const_iterator vtx=vtces.begin();
32  vtx!=vtces.end() ; ++vtx )
33  {
34  vector < reco::TransientTrack > trks = vtx->originalTracks();
35  vector < TrackAndWeight > tnws;
36  for ( vector< reco::TransientTrack >::const_iterator trk=trks.begin();
37  trk!=trks.end() ; ++trk )
38  {
39  float w = vtx->trackWeight ( *trk );
40  if ( w > 1e-5 )
41  {
42  TrackAndWeight tmp ( *trk, w );
43  set < reco::TransientTrack >::iterator pos = st.find( *trk );
44  if ( pos != st.end() )
45  {
46  st.erase ( pos );
47  }
48  tnws.push_back ( tmp );
49  };
50  };
51  bundles.push_back ( tnws );
52  };
53 
54  if ( bundles.size() == 0 ) return bundles;
55 
56  // now add not-yet assigned tracks
57  for ( set < reco::TransientTrack >::const_iterator i=st.begin();
58  i!=st.end() ; ++i )
59  {
60  // cout << "[MultiVertexReconstructor] recovering " << i->id() << endl;
61  TrackAndWeight tmp ( *i, 0. );
62  bundles[0].push_back ( tmp );
63  }
64  return bundles;
65  }
66 }
67 
69  const VertexReconstructor & o, const AnnealingSchedule & s, float revive ) :
70  theOldReconstructor ( o.clone() ), theFitter (
72 {
73 }
74 
76 {
77  delete theOldReconstructor;
78 }
79 
81 {
82  return new MultiVertexReconstructor ( * this );
83 }
84 
86  const MultiVertexReconstructor & o ) :
87  theOldReconstructor ( o.theOldReconstructor->clone() ),
88  theFitter ( o.theFitter )
89 {}
90 
91 vector < TransientVertex > MultiVertexReconstructor::vertices (
92  const vector < reco::TransientTrack > & trks,
93  const reco::BeamSpot & s ) const
94 {
95  return vertices ( trks );
96 }
97 
98 vector < TransientVertex > MultiVertexReconstructor::vertices (
99  const vector < reco::TransientTrack > & trks,
100  const vector < reco::TransientTrack > & primaries,
101  const reco::BeamSpot & s ) const
102 {
103  return vertices ( trks, primaries );
104 }
105 
106 
107 vector < TransientVertex > MultiVertexReconstructor::vertices (
108  const vector < reco::TransientTrack > & trks ) const
109 {
110  /*
111  cout << "[MultiVertexReconstructor] input trks: ";
112  for ( vector< reco::TransientTrack >::const_iterator i=trks.begin();
113  i!=trks.end() ; ++i )
114  {
115  cout << i->id() << " ";
116  }
117  cout << endl;*/
118  vector < TransientVertex > tmp = theOldReconstructor->vertices ( trks );
119  if ( verbose() )
120  {
121  cout << "[MultiVertexReconstructor] non-freezing seeder found " << tmp.size()
122  << " vertices from " << trks.size() << " tracks." << endl;
123  }
124  vector < vector < TrackAndWeight > > rc = recover ( tmp, trks );
125  vector < CachingVertex<5> > cvts = theFitter.vertices ( rc );
126  vector < TransientVertex > ret;
127  for ( vector< CachingVertex<5> >::const_iterator i=cvts.begin();
128  i!=cvts.end() ; ++i )
129  {
130  ret.push_back ( *i );
131  };
132 
133  if ( verbose() )
134  {
135  cout << "[MultiVertexReconstructor] input " << tmp.size()
136  << " vertices, output " << ret.size() << " vertices."
137  << endl;
138  };
139  return ret;
140 }
141 
142 vector < TransientVertex > MultiVertexReconstructor::vertices (
143  const vector < reco::TransientTrack > & trks,
144  const vector < reco::TransientTrack > & primaries ) const
145 {
146  /*
147  cout << "[MultiVertexReconstructor] with " << primaries.size()
148  << " primaries!" << endl;
149  */
150 
151  map < reco::TransientTrack, bool > st;
152 
153  vector < reco::TransientTrack > total = trks;
154  for ( vector< reco::TransientTrack >::const_iterator i=trks.begin();
155  i!=trks.end() ; ++i )
156  {
157  st[(*i)]=true;
158  }
159 
160  // cout << "[MultiVertexReconstructor] FIXME dont just add up tracks. superpose" << endl;
161  for ( vector< reco::TransientTrack >::const_iterator i=primaries.begin();
162  i!=primaries.end() ; ++i )
163  {
164  if (!(st[(*i)]))
165  {
166  total.push_back ( *i );
167  }
168  }
169 
170  vector < TransientVertex > tmp = theOldReconstructor->vertices ( total );
171 
172  if ( verbose() )
173  {
174  cout << "[MultiVertexReconstructor] freezing seeder found " << tmp.size()
175  << " vertices from " << total.size() << " tracks." << endl;
176  }
177  vector < vector < TrackAndWeight > > rc = recover ( tmp, trks );
178  vector < CachingVertex<5> > cvts = theFitter.vertices ( rc, primaries );
179 
180  vector < TransientVertex > ret;
181  for ( vector< CachingVertex<5> >::const_iterator i=cvts.begin();
182  i!=cvts.end() ; ++i )
183  {
184  ret.push_back ( *i );
185  };
186  if ( verbose() )
187  {
188  cout << "[MultiVertexReconstructor] input " << tmp.size()
189  << " vertices, output " << ret.size() << " vertices."
190  << endl;
191  };
192  return ret;
193 }
194 
196 {
197  return theOldReconstructor;
198 }
std::vector< CachingVertex< 5 > > vertices(const std::vector< std::vector< reco::TransientTrack > > &, const std::vector< reco::TransientTrack > &primaries=std::vector< reco::TransientTrack >())
int i
Definition: DBlmapReader.cc:9
std::pair< reco::TransientTrack, float > TrackAndWeight
VertexReconstructor * reconstructor() const
virtual std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &) const =0
VertexReconstructor * theOldReconstructor
MultiVertexReconstructor * clone() const
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
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &, const reco::BeamSpot &) const
tuple cout
Definition: gather_cfg.py:121
T w() const