CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AdaptiveVertexReconstructor.cc
Go to the documentation of this file.
7 #include <algorithm>
8 
9 using namespace std;
10 
12 {
13  vector < reco::TransientTrack > trks = old.originalTracks();
14  vector < reco::TransientTrack > newtrks;
16  static const float minweight = 1.e-8; // discard all tracks with lower weight
17  for ( vector< reco::TransientTrack >::const_iterator i=trks.begin();
18  i!=trks.end() ; ++i )
19  {
20  if ( old.trackWeight ( *i ) > minweight )
21  {
22  newtrks.push_back ( *i );
23  mp[*i]=old.trackWeight ( *i );
24  }
25  }
26 
28 
29  if ( old.hasPrior() )
30  {
31  VertexState priorstate ( old.priorPosition(), old.priorError() );
32  ret=TransientVertex ( priorstate, old.vertexState(), newtrks,
33  old.totalChiSquared(), old.degreesOfFreedom() );
34  } else {
35  ret=TransientVertex ( old.vertexState(), newtrks,
36  old.totalChiSquared(), old.degreesOfFreedom() );
37  }
38  ret.weightMap ( mp ); // set weight map
39 
40  if ( old.hasRefittedTracks() )
41  {
42  // we have refitted tracks -- copy them!
43  vector < reco::TransientTrack > newrfs;
44  vector < reco::TransientTrack > oldrfs=old.refittedTracks();
45  vector < reco::TransientTrack >::const_iterator origtrkiter=trks.begin();
46  for ( vector< reco::TransientTrack >::const_iterator i=oldrfs.begin(); i!=oldrfs.end() ; ++i )
47  {
48  if ( old.trackWeight ( *origtrkiter ) > minweight )
49  {
50  newrfs.push_back ( *i );
51  }
52  origtrkiter++;
53  }
54  if ( newrfs.size() ) ret.refittedTracks ( newrfs ); // copy refitted tracks
55  }
56 
57  if ( ret.refittedTracks().size() > ret.originalTracks().size() )
58  {
59  edm::LogError("AdaptiveVertexReconstructor" )
60  << "More refitted tracks than original tracks!";
61  }
62 
63  return ret;
64 }
65 
67  const TransientVertex & newvtx,
68  set < reco::TransientTrack > & remainingtrks,
69  float w ) const
70 {
71  /*
72  * Erase tracks that are in newvtx from remainingtrks
73  * But erase only if trackweight > w
74  */
75  const vector < reco::TransientTrack > & origtrks = newvtx.originalTracks();
76  for ( vector< reco::TransientTrack >::const_iterator i=origtrks.begin();
77  i!=origtrks.end(); ++i )
78  {
79  double weight = newvtx.trackWeight ( *i );
80  if ( weight > w )
81  {
82  remainingtrks.erase ( *i );
83  };
84  };
85 }
86 
88  float primcut, float seccut, float min_weight, bool smoothing ) :
89  thePrimaryFitter ( 0 ), theSecondaryFitter ( 0 ),
90  theMinWeight( min_weight ), theWeightThreshold ( 0.001 )
91 {
92  setupFitters ( primcut, 256., 0.25, seccut, 256., 0.25, smoothing );
93 }
94 
96 {
97  if ( thePrimaryFitter ) delete thePrimaryFitter;
99 }
100 
102  float primT, float primr, float seccut, float secT,
103  float secr, bool smoothing )
104 {
105  VertexSmoother<5> * smoother ;
106  if ( smoothing )
107  {
108  smoother = new KalmanVertexSmoother();
109  } else {
110  smoother = new DummyVertexSmoother<5>();
111  }
112 
113  if ( thePrimaryFitter ) delete thePrimaryFitter;
115 
116  /*
117  edm::LogError ("AdaptiveVertexReconstructor" )
118  << "Tini and r are hardcoded now!";
119  */
123  // if the primary fails, sth is wrong, so here we set a threshold on the weight.
128  // need to set it or else we have
129  // unwanted exceptions to deal with.
130  // cleanup can come later!
131  delete smoother;
132 }
133 
135  : thePrimaryFitter(0), theSecondaryFitter(0), theMinWeight(0.5), theWeightThreshold ( 0.001 )
136 {
137  float primcut = 2.0;
138  float seccut = 6.0;
139  bool smoothing=false;
140  // float primT = 4096.;
141  // float primr = 0.125;
142  float primT = 256.;
143  float primr = 0.25;
144  float secT = 256.;
145  float secr = 0.25;
146 
147  try {
148  primcut = m.getParameter<double>("primcut");
149  primT = m.getParameter<double>("primT");
150  primr = m.getParameter<double>("primr");
151  seccut = m.getParameter<double>("seccut");
152  secT = m.getParameter<double>("secT");
153  secr = m.getParameter<double>("secr");
154  theMinWeight = m.getParameter<double>("minweight");
155  theWeightThreshold = m.getParameter<double>("weightthreshold");
156  smoothing = m.getParameter<bool>("smoothing");
157  } catch ( edm::Exception & e ) {
158  edm::LogError ("AdaptiveVertexReconstructor") << e.what();
159  }
160 
161  setupFitters ( primcut, primT, primr, seccut, secT, secr, smoothing );
162 }
163 
164 vector<TransientVertex>
165  AdaptiveVertexReconstructor::vertices(const vector<reco::TransientTrack> & t,
166  const reco::BeamSpot & s ) const
167 {
168  return vertices ( vector<reco::TransientTrack>(), t, s, false, true );
169 }
170 
171 vector<TransientVertex>
172  AdaptiveVertexReconstructor::vertices(const vector<reco::TransientTrack> & primaries,
173  const vector<reco::TransientTrack > & tracks, const reco::BeamSpot & s ) const
174 {
175  return vertices ( primaries, tracks, s, true, true );
176 }
177 
178 
179 vector<TransientVertex> AdaptiveVertexReconstructor::vertices (
180  const vector<reco::TransientTrack> & tracks ) const
181 {
182  return vertices ( vector<reco::TransientTrack>(), tracks, reco::BeamSpot(),
183  false, false );
184 }
185 
186 vector<TransientVertex> AdaptiveVertexReconstructor::vertices (
187  const vector<reco::TransientTrack> & primaries,
188  const vector<reco::TransientTrack> & tracks,
189  const reco::BeamSpot & s, bool has_primaries, bool usespot ) const
190 {
191  vector < TransientVertex > ret;
192  set < reco::TransientTrack > remainingtrks;
193 
194  copy(tracks.begin(), tracks.end(),
195  inserter(remainingtrks, remainingtrks.begin()));
196 
197  int ctr=0;
198  unsigned int n_tracks = remainingtrks.size();
199 
200  // cout << "[AdaptiveVertexReconstructor] DEBUG ::vertices!!" << endl;
201  try {
202  while ( remainingtrks.size() > 1 )
203  {
204  /*
205  cout << "[AdaptiveVertexReconstructor] next round: "
206  << remainingtrks.size() << endl;
207  */
208  ctr++;
209  const AdaptiveVertexFitter * fitter = theSecondaryFitter;
210  if ( ret.size() == 0 )
211  {
212  fitter = thePrimaryFitter;
213  };
214  vector < reco::TransientTrack > fittrks;
215  fittrks.reserve ( remainingtrks.size() );
216 
217  copy(remainingtrks.begin(), remainingtrks.end(), back_inserter(fittrks));
218 
219  TransientVertex tmpvtx;
220  if ( (ret.size() == 0) && has_primaries )
221  {
222  // add the primaries to the fitted tracks.
223  copy ( primaries.begin(), primaries.end(), back_inserter(fittrks) );
224  }
225  if ( (ret.size() == 0) && usespot )
226  {
227  tmpvtx=fitter->vertex ( fittrks, s );
228  } else {
229  tmpvtx=fitter->vertex ( fittrks );
230  }
231  TransientVertex newvtx = cleanUp ( tmpvtx );
232  ret.push_back ( newvtx );
233  erase ( newvtx, remainingtrks, theMinWeight );
234  if ( n_tracks == remainingtrks.size() )
235  {
236  if ( usespot )
237  {
238  // try once more without beamspot constraint!
239  usespot=false;
240  LogDebug("AdaptiveVertexReconstructor")
241  << "no tracks in vertex. trying again without beamspot constraint!";
242  continue;
243  }
244  LogDebug("AdaptiveVertexReconstructor") << "all tracks (" << n_tracks
245  << ") would be recycled for next fit. Trying with low threshold!";
246  erase ( newvtx, remainingtrks, 1.e-5 );
247  if ( n_tracks == remainingtrks.size() )
248  {
249  LogDebug("AdaptiveVertexReconstructor") << "low threshold didnt help! "
250  << "Discontinue procedure!";
251  break;
252  }
253  };
254 
255  // cout << "[AdaptiveVertexReconstructor] erased" << endl;
256  n_tracks = remainingtrks.size();
257  };
258  } catch ( VertexException & v ) {
259  // Will catch all (not enough significant tracks exceptions.
260  // in this case, the iteration can safely terminate.
261  };
262 
263  return cleanUpVertices ( ret );
264 }
265 
267  const vector < TransientVertex > & old ) const
268 {
269  vector < TransientVertex > ret;
270  for ( vector< TransientVertex >::const_iterator i=old.begin(); i!=old.end() ; ++i )
271  {
272  if (!(i->hasTrackWeight()))
273  { // if we dont have track weights, we take the vtx
274  ret.push_back ( *i );
275  continue;
276  }
277 
278  // maybe this should be replaced with asking for the ndf ...
279  // e.g. if ( ndf > - 1. )
280  int nsig=0; // number of significant tracks.
282  for ( TransientVertex::TransientTrackToFloatMap::const_iterator w=wm.begin(); w!=wm.end() ; ++w )
283  {
284  if (w->second > theWeightThreshold) nsig++;
285  }
286  if ( nsig > 1 ) ret.push_back ( *i );
287  }
288 
289  return ret;
290 }
#define LogDebug(id)
virtual char const * what() const
Definition: Exception.cc:141
AdaptiveVertexReconstructor(float primcut=2.0, float seccut=6.0, float minweight=0.5, bool smoothing=false)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
tuple ret
prodAgent to be discontinued
GlobalError priorError() const
const double w
Definition: UKUtility.cc:23
TransientVertex cleanUp(const TransientVertex &old) const
Common base class.
float totalChiSquared() const
std::map< reco::TransientTrack, float > TransientTrackToFloatMap
bool hasRefittedTracks() const
void setupFitters(float primcut, float primT, float primr, float seccut, float secT, float secr, bool smoothing)
std::vector< reco::TransientTrack > const & originalTracks() const
float degreesOfFreedom() const
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &v) const
bool hasPrior() const
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const
std::vector< TransientVertex > cleanUpVertices(const std::vector< TransientVertex > &) const
AdaptiveVertexFitter * theSecondaryFitter
float trackWeight(const reco::TransientTrack &track) const
tuple tracks
Definition: testEve_cfg.py:39
GlobalPoint priorPosition() const
std::vector< reco::TransientTrack > const & refittedTracks() const
int weight
Definition: histoStyle.py:50
void erase(const TransientVertex &newvtx, std::set< reco::TransientTrack > &remainingtrks, float w) const
VertexState const & vertexState() const
TransientTrackToFloatMap weightMap() const