15 #include <dataharvester/Writer.h>
21 void sortTracksByPt(std::vector<reco::TransientTrack>&
cont) {
26 for (
auto const& tk :
cont) {
28 pt2[
i++] = tk.impactPointState().globalMomentum().perp2();
32 std::sort(ind, ind +
s, [p_pt2](
int i,
int j) {
return p_pt2[
i] > p_pt2[
j]; });
33 std::vector<reco::TransientTrack>
tmp;
35 for (
auto i = 0
U;
i <
s; ++
i)
45 const float initialError = 10000;
47 ret(0, 0) = initialError;
48 ret(1, 1) = initialError;
49 ret(2, 2) = initialError;
66 GlobalError const linPointError = initLinePointError();
68 void sortByDistanceToRefPoint(std::vector<RefCountedVertexTrack>&
cont,
const GlobalPoint ref) {
73 for (
auto const& tk :
cont) {
75 d2[
i++] = (tk->linearizedTrack()->track().initialFreeState().position() - ref).
mag2();
79 std::sort(ind, ind +
s, [p_d2](
int i,
int j) {
return p_d2[
i] < p_d2[
j]; });
80 std::vector<RefCountedVertexTrack>
tmp;
82 for (
auto i = 0
U;
i <
s; ++
i)
89 map<RefCountedLinearizedTrackState, int> ids;
92 int getId(
const RefCountedLinearizedTrackState&
r) {
94 if (ids.count(
r) == 0) {
109 theLinP(linP.
clone()),
111 theSmoother(smoother.
clone()),
112 theAssProbComputer(ann.
clone()),
113 theComp(crit.
clone()),
114 theLinTrkFactory(ltsf.
clone()),
115 gsfIntermediarySmoothing_(
false) {
122 : theMaxShift(
o.theMaxShift),
123 theMaxLPShift(
o.theMaxLPShift),
124 theMaxStep(
o.theMaxStep),
125 theWeightThreshold(
o.theWeightThreshold),
127 theLinP(
o.theLinP->
clone()),
128 theUpdator(
o.theUpdator->
clone()),
129 theSmoother(
o.theSmoother->
clone()),
130 theAssProbComputer(
o.theAssProbComputer->
clone()),
131 theComp(
o.theComp->
clone()),
132 theLinTrkFactory(
o.theLinTrkFactory->
clone()),
133 gsfIntermediarySmoothing_(
o.gsfIntermediarySmoothing_) {}
153 s.getParameter<
double>(
"maxlpshift"),
154 s.getParameter<
int>(
"maxstep"),
155 s.getParameter<
double>(
"weightthreshold"));
159 if (unstracks.size() < 2) {
160 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied fewer than two tracks. Vertex is invalid.";
163 vector<reco::TransientTrack>
tracks = unstracks;
172 return fit(vtContainer,
seed,
false);
177 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied fewer than two tracks. Vertex is invalid.";
189 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied no tracks. Vertex is invalid.";
202 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied fewer than two tracks. Vertex is invalid.";
209 return fit(vtContainer, fitseed,
false);
218 if (unstracks.empty()) {
219 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied no tracks. Vertex is invalid.";
224 vector<RefCountedVertexTrack> vtContainer;
226 vector<reco::TransientTrack>
tracks = unstracks;
239 return fit(vtContainer, beamSpotState,
true);
253 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied no tracks. Vertex is invalid.";
258 return fit(vtContainer,
seed,
true);
269 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied no tracks. Vertex is invalid.";
286 vector<RefCountedLinearizedTrackState> lTracks;
287 for (vector<reco::TransientTrack>::const_iterator
i =
tracks.begin();
i !=
tracks.end(); ++
i) {
290 lTracks.push_back(lTrData);
292 LogInfo(
"RecoVertex/AdaptiveVertexFitter") <<
"Exception " <<
e.what() <<
" in ::linearizeTracks."
293 <<
"Your future vertex has just lost a track.";
308 vector<RefCountedLinearizedTrackState> lTracks;
309 for (vector<RefCountedVertexTrack>::const_iterator
i =
tracks.begin();
i !=
tracks.end();
i++) {
317 lTracks.push_back(lTrData);
319 LogInfo(
"RecoVertex/AdaptiveVertexFitter") <<
"Exception " <<
e.what() <<
" in ::relinearizeTracks. "
320 <<
"Will not relinearize this track.";
321 lTracks.push_back((**i).linearizedTrack());
333 LogInfo(
"RecoVertex/AdaptiveVertexFitter") <<
"Weight " <<
weight <<
" > 1.0!";
351 vector<RefCountedVertexTrack> finalTracks;
356 for (vector<RefCountedLinearizedTrackState>::const_iterator
i = lTracks.begin();
i != lTracks.end();
i++) {
359 pair<bool, double> chi2Res(
false, 0.);
365 if (!chi2Res.first) {
367 LogInfo(
"AdaptiveVertexFitter") <<
"When reweighting, chi2<0. Will add this track with w=0.";
376 map<string, dataharvester::MultiType>
m;
381 m[
"pos"] =
"reweight";
386 finalTracks.push_back(vTrData);
394 const vector<RefCountedLinearizedTrackState>& lTracks,
const VertexState&
seed)
const {
401 vector<RefCountedVertexTrack> finalTracks;
406 for (vector<RefCountedLinearizedTrackState>::const_iterator
i = lTracks.begin();
i != lTracks.end();
i++) {
409 if (!chi2Res.first) {
411 LogInfo(
"AdaptiveVertexFitter") <<
"When weighting a track, chi2 calculation failed;"
412 <<
" will add with w=0.";
418 map<string, dataharvester::MultiType>
m;
427 finalTracks.push_back(vTrData);
439 vector<RefCountedLinearizedTrackState> lTracks;
440 for (vector<RefCountedVertexTrack>::const_iterator
i =
tracks.begin();
i !=
tracks.end();
i++) {
441 lTracks.push_back((**i).linearizedTrack());
453 bool withPrior)
const {
457 vector<RefCountedVertexTrack> initialTracks;
461 CachingVertex<5> returnVertex(priorVertexPosition, priorVertexError, initialTracks, 0);
464 priorVertexPosition, priorVertexError, priorVertexPosition, priorVertexError, initialTracks, 0);
467 std::vector<RefCountedVertexTrack> globalVTracks =
tracks;
469 sortByDistanceToRefPoint(globalVTracks, priorSeed.
position());
494 if ((previousPosition - newPosition).transverse() >
theMaxLPShift) {
512 for (vector<RefCountedVertexTrack>::const_iterator
i = globalVTracks.begin();
i != globalVTracks.end();
i++) {
513 if ((**i).weight() > 0.)
521 if (fabs(
nVertex.position().z()) > 10000. ||
nVertex.position().perp() > 120.) {
523 LogInfo(
"AdaptiveVertexFitter")
524 <<
"Vertex candidate just took off to " <<
nVertex.position() <<
"! Will discard this update!";
536 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
537 <<
"The updator returned an invalid vertex when adding track " <<
i - globalVTracks.begin()
538 <<
".\n Your vertex might just have lost one good track.";
541 previousPosition = newPosition;
543 returnVertex = fVertex;
557 <<
" Fitted vertex is invalid.";
562 map<string, dataharvester::MultiType>
m;