CMS 3D CMS Logo

SequentialVertexFitter.cc
Go to the documentation of this file.
4 
5 #include <algorithm>
6 using namespace std;
7 using namespace reco;
8 
9 namespace {
10  // FIXME
11  // hard-coded tracker bounds
12  // workaround while waiting for Geometry service
13  const float TrackerBoundsRadius = 112;
14  const float TrackerBoundsHalfLength = 273.5;
15  bool insideTrackerBounds(const GlobalPoint& point) {
16  return ((point.transverse() < TrackerBoundsRadius) && (abs(point.z()) < TrackerBoundsHalfLength));
17  }
18 } // namespace
19 
20 template <unsigned int N>
23  const VertexSmoother<N>& smoother,
24  const AbstractLTSFactory<N>& ltsf)
25  : theLinP(linP.clone()),
26  theUpdator(updator.clone()),
27  theSmoother(smoother.clone()),
28  theLTrackFactory(ltsf.clone()) {
30 }
31 
32 template <unsigned int N>
34  const LinearizationPointFinder& linP,
36  const VertexSmoother<N>& smoother,
37  const AbstractLTSFactory<N>& ltsf)
38  : thePSet(pSet),
39  theLinP(linP.clone()),
40  theUpdator(updator.clone()),
41  theSmoother(smoother.clone()),
42  theLTrackFactory(ltsf.clone()) {
44 }
45 
46 template <unsigned int N>
48  thePSet = original.parameterSet();
49  theLinP = original.linearizationPointFinder()->clone();
50  theUpdator = original.vertexUpdator()->clone();
51  theSmoother = original.vertexSmoother()->clone();
52  theMaxShift = original.maxShift();
53  theMaxStep = original.maxStep();
54  theLTrackFactory = original.linearizedTrackStateFactory()->clone();
55 }
56 
57 template <unsigned int N>
59  delete theLinP;
60  delete theUpdator;
61  delete theSmoother;
62  delete theLTrackFactory;
63 }
64 
65 template <unsigned int N>
67  theMaxShift = thePSet.getParameter<double>("maxDistance"); //0.01
68  theMaxStep = thePSet.getParameter<int>("maxNbrOfIterations"); //10
69 }
70 
71 template <unsigned int N>
73  thePSet.addParameter<double>("maxDistance", 0.01);
74  thePSet.addParameter<int>("maxNbrOfIterations", 10); //10
75  readParameters();
76 }
77 
78 template <unsigned int N>
79 CachingVertex<N> SequentialVertexFitter<N>::vertex(const std::vector<reco::TransientTrack>& tracks) const {
80  // Linearization Point
81  GlobalPoint linP = theLinP->getLinearizationPoint(tracks);
82  if (!insideTrackerBounds(linP))
83  linP = GlobalPoint(0, 0, 0);
84 
85  // Initial vertex state, with a very large error matrix
86  ROOT::Math::SMatrixIdentity id;
87  AlgebraicSymMatrix33 we(id);
88  GlobalError error(we * 10000);
89  VertexState state(linP, error);
90  std::vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, state);
91  return fit(vtContainer, state, false);
92 }
93 
94 template <unsigned int N>
95 CachingVertex<N> SequentialVertexFitter<N>::vertex(const std::vector<RefCountedVertexTrack>& tracks,
96  const reco::BeamSpot& spot) const {
97  VertexState state(spot);
98  return fit(tracks, state, true);
99 }
100 
101 template <unsigned int N>
102 CachingVertex<N> SequentialVertexFitter<N>::vertex(const std::vector<RefCountedVertexTrack>& tracks) const {
103  // Initial vertex state, with a very small weight matrix
104  GlobalPoint linP = tracks[0]->linearizedTrack()->linearizationPoint();
105  ROOT::Math::SMatrixIdentity id;
106  AlgebraicSymMatrix33 we(id);
107  GlobalError error(we * 10000);
108  VertexState state(linP, error);
109  return fit(tracks, state, false);
110 }
111 
112 // Fit vertex out of a set of RecTracks.
113 // Uses the specified linearization point.
114 //
115 template <unsigned int N>
116 CachingVertex<N> SequentialVertexFitter<N>::vertex(const std::vector<reco::TransientTrack>& tracks,
117  const GlobalPoint& linPoint) const {
118  // Initial vertex state, with a very large error matrix
119  ROOT::Math::SMatrixIdentity id;
120  AlgebraicSymMatrix33 we(id);
121  GlobalError error(we * 10000);
122  VertexState state(linPoint, error);
123  std::vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, state);
124  return fit(vtContainer, state, false);
125 }
126 
131 template <unsigned int N>
132 CachingVertex<N> SequentialVertexFitter<N>::vertex(const std::vector<reco::TransientTrack>& tracks,
133  const BeamSpot& beamSpot) const {
134  VertexState beamSpotState(beamSpot);
135  std::vector<RefCountedVertexTrack> vtContainer;
136 
137  if (tracks.size() > 1) {
138  // Linearization Point search if there are more than 1 track
139  GlobalPoint linP = theLinP->getLinearizationPoint(tracks);
140  if (!insideTrackerBounds(linP))
141  linP = GlobalPoint(0, 0, 0);
142  ROOT::Math::SMatrixIdentity id;
143  AlgebraicSymMatrix33 we(id);
144  GlobalError error(we * 10000);
145  VertexState lpState(linP, error);
146  vtContainer = linearizeTracks(tracks, lpState);
147  } else {
148  // otherwise take the beamspot position.
149  vtContainer = linearizeTracks(tracks, beamSpotState);
150  }
151 
152  return fit(vtContainer, beamSpotState, true);
153 }
154 
155 // Fit vertex out of a set of RecTracks.
156 // Uses the position as both the linearization point AND as prior
157 // estimate of the vertex position. The error is used for the
158 // weight of the prior estimate.
159 //
160 template <unsigned int N>
161 CachingVertex<N> SequentialVertexFitter<N>::vertex(const std::vector<reco::TransientTrack>& tracks,
162  const GlobalPoint& priorPos,
163  const GlobalError& priorError) const {
164  VertexState state(priorPos, priorError);
165  std::vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, state);
166  return fit(vtContainer, state, true);
167 }
168 
169 // Fit vertex out of a set of VertexTracks
170 // Uses the position and error for the prior estimate of the vertex.
171 // This position is not used to relinearize the tracks.
172 //
173 template <unsigned int N>
174 CachingVertex<N> SequentialVertexFitter<N>::vertex(const std::vector<RefCountedVertexTrack>& tracks,
175  const GlobalPoint& priorPos,
176  const GlobalError& priorError) const {
177  VertexState state(priorPos, priorError);
178  return fit(tracks, state, true);
179 }
180 
181 // Construct a container of VertexTrack from a set of RecTracks.
182 //
183 template <unsigned int N>
184 vector<typename SequentialVertexFitter<N>::RefCountedVertexTrack> SequentialVertexFitter<N>::linearizeTracks(
185  const std::vector<reco::TransientTrack>& tracks, const VertexState state) const {
186  GlobalPoint linP = state.position();
187  std::vector<RefCountedVertexTrack> finalTracks;
188  finalTracks.reserve(tracks.size());
189  for (vector<reco::TransientTrack>::const_iterator i = tracks.begin(); i != tracks.end(); i++) {
190  RefCountedLinearizedTrackState lTrData = theLTrackFactory->linearizedTrackState(linP, *i);
191  RefCountedVertexTrack vTrData = theVTrackFactory.vertexTrack(lTrData, state);
192  finalTracks.push_back(vTrData);
193  }
194  return finalTracks;
195 }
196 
197 // Construct new a container of VertexTrack with a new linearization point
198 // and vertex state, from an existing set of VertexTrack, from which only the
199 // recTracks will be used.
200 //
201 template <unsigned int N>
202 vector<typename SequentialVertexFitter<N>::RefCountedVertexTrack> SequentialVertexFitter<N>::reLinearizeTracks(
203  const std::vector<RefCountedVertexTrack>& tracks, const VertexState state) const {
204  GlobalPoint linP = state.position();
205  std::vector<RefCountedVertexTrack> finalTracks;
206  finalTracks.reserve(tracks.size());
207  for (typename std::vector<RefCountedVertexTrack>::const_iterator i = tracks.begin(); i != tracks.end(); i++) {
208  RefCountedLinearizedTrackState lTrData = (**i).linearizedTrack()->stateWithNewLinearizationPoint(linP);
209  // RefCountedLinearizedTrackState lTrData =
210  // theLTrackFactory->linearizedTrackState(linP,
211  // (**i).linearizedTrack()->track());
212  RefCountedVertexTrack vTrData = theVTrackFactory.vertexTrack(lTrData, state, (**i).weight());
213  finalTracks.push_back(vTrData);
214  }
215  return finalTracks;
216 }
217 
218 // The method where the vertex fit is actually done!
219 //
220 template <unsigned int N>
221 CachingVertex<N> SequentialVertexFitter<N>::fit(const std::vector<RefCountedVertexTrack>& tracks,
222  const VertexState priorVertex,
223  bool withPrior) const {
224  std::vector<RefCountedVertexTrack> initialTracks;
225  GlobalPoint priorVertexPosition = priorVertex.position();
226  GlobalError priorVertexError = priorVertex.error();
227 
228  CachingVertex<N> returnVertex(priorVertexPosition, priorVertexError, initialTracks, 0);
229  if (withPrior) {
230  returnVertex = CachingVertex<N>(
231  priorVertexPosition, priorVertexError, priorVertexPosition, priorVertexError, initialTracks, 0);
232  }
233  CachingVertex<N> initialVertex = returnVertex;
234  std::vector<RefCountedVertexTrack> globalVTracks = tracks;
235 
236  // main loop through all the VTracks
237  bool validVertex = true;
238  int step = 0;
239  GlobalPoint newPosition = priorVertexPosition;
240  GlobalPoint previousPosition;
241  do {
242  CachingVertex<N> fVertex = initialVertex;
243  // make new linearized and vertex tracks for the next iteration
244  if (step != 0)
245  globalVTracks = reLinearizeTracks(tracks, returnVertex.vertexState());
246 
247  // update sequentially the vertex estimate
248  for (typename std::vector<RefCountedVertexTrack>::const_iterator i = globalVTracks.begin();
249  i != globalVTracks.end();
250  i++) {
251  fVertex = theUpdator->add(fVertex, *i);
252  if (!fVertex.isValid())
253  break;
254  }
255 
256  validVertex = fVertex.isValid();
257  // check tracker bounds and NaN in position
258  if (validVertex && hasNan(fVertex.position())) {
259  LogDebug("RecoVertex/SequentialVertexFitter") << "Fitted position is NaN.\n";
260  validVertex = false;
261  }
262 
263  if (validVertex && !insideTrackerBounds(fVertex.position())) {
264  LogDebug("RecoVertex/SequentialVertexFitter") << "Fitted position is out of tracker bounds.\n";
265  validVertex = false;
266  }
267 
268  if (!validVertex) {
269  // reset initial vertex position to (0,0,0) and force new iteration
270  // if number of steps not exceeded
271  ROOT::Math::SMatrixIdentity id;
272  AlgebraicSymMatrix33 we(id);
273  GlobalError error(we * 10000);
274  fVertex = CachingVertex<N>(GlobalPoint(0, 0, 0), error, initialTracks, 0);
275  }
276 
277  previousPosition = newPosition;
278  newPosition = fVertex.position();
279 
280  returnVertex = fVertex;
281  globalVTracks.clear();
282  step++;
283  } while ((step != theMaxStep) && (((previousPosition - newPosition).transverse() > theMaxShift) || (!validVertex)));
284 
285  if (!validVertex) {
286  LogDebug("RecoVertex/SequentialVertexFitter")
287  << "Fitted position is invalid (out of tracker bounds or has NaN). Returned vertex is invalid\n";
288  return CachingVertex<N>(); // return invalid vertex
289  }
290 
291  if (step >= theMaxStep) {
292  LogDebug("RecoVertex/SequentialVertexFitter")
293  << "The maximum number of steps has been exceeded. Returned vertex is invalid\n";
294  return CachingVertex<N>(); // return invalid vertex
295  }
296 
297  // smoothing
298  returnVertex = theSmoother->smooth(returnVertex);
299 
300  return returnVertex;
301 }
302 
303 template class SequentialVertexFitter<5>;
304 template class SequentialVertexFitter<6>;
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
AlgebraicSymMatrix33
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
Definition: AlgebraicROOTObjects.h:21
VertexUpdator
Definition: VertexUpdator.h:12
mps_fire.i
i
Definition: mps_fire.py:428
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
SequentialVertexFitter::SequentialVertexFitter
SequentialVertexFitter()
Definition: SequentialVertexFitter.h:172
MessageLogger.h
step
step
Definition: StallMonitor.cc:94
CachingVertex
Definition: CachingVertex.h:22
CachingVertex::vertexState
const VertexState & vertexState() const
Definition: CachingVertex.h:137
L1TowerCalibrationProducer_cfi.fit
fit
Definition: L1TowerCalibrationProducer_cfi.py:36
ReferenceCountingPointer< LinearizedTrackState< N > >
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
SequentialVertexFitter::linearizeTracks
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &tracks, const VertexState state) const
Definition: SequentialVertexFitter.cc:184
relativeConstraints.error
error
Definition: relativeConstraints.py:53
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
LinearizationPointFinder
Definition: LinearizationPointFinder.h:12
reco::BeamSpot
Definition: BeamSpot.h:21
SequentialVertexFitter
Definition: SequentialVertexFitter.h:34
VertexState::error
GlobalError error() const
Definition: VertexState.h:64
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
SequentialVertexFitter::fit
CachingVertex< N > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState priorVertex, bool withPrior) const
Definition: SequentialVertexFitter.cc:221
SequentialVertexFitter::readParameters
void readParameters()
Definition: SequentialVertexFitter.cc:66
SequentialVertexFitter::setDefaultParameters
void setDefaultParameters()
Definition: SequentialVertexFitter.cc:72
HLT_FULL_cff.updator
updator
Definition: HLT_FULL_cff.py:123
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
CachingVertex::position
GlobalPoint position() const
Definition: CachingVertex.cc:308
definitions.original
original
Definition: definitions.py:57
transverse
T transverse() const
Another name for perp()
Definition: Basic3DVectorLD.h:136
SequentialVertexFitter::reLinearizeTracks
std::vector< RefCountedVertexTrack > reLinearizeTracks(const std::vector< RefCountedVertexTrack > &tracks, const VertexState state) const
Definition: SequentialVertexFitter.cc:202
GlobalError.h
GlobalErrorBase< double, ErrorMatrixTag >
SequentialVertexFitter::~SequentialVertexFitter
~SequentialVertexFitter() override
Definition: SequentialVertexFitter.cc:58
SequentialVertexFitter.h
std
Definition: JetResolutionObject.h:76
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
VertexState
Definition: VertexState.h:13
CachingVertex::isValid
bool isValid() const
Definition: CachingVertex.h:154
VertexState::position
GlobalPoint position() const
Definition: VertexState.h:62
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
SequentialVertexFitter::vertex
CachingVertex< N > vertex(const std::vector< reco::TransientTrack > &tracks) const override
Definition: SequentialVertexFitter.cc:79
point
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
AbstractLTSFactory
Definition: AbstractLTSFactory.h:12
VertexSmoother
Definition: VertexSmoother.h:13