CMS 3D CMS Logo

GsfVertexUpdator.cc
Go to the documentation of this file.
4 #include <cfloat>
5 
6 GsfVertexUpdator::GsfVertexUpdator(bool limit, const GsfVertexMerger* merger) : limitComponents(limit) {
7  if (limitComponents)
8  theMerger = merger->clone();
9 }
10 
12  VSC prevVtxComponents = oldVertex.vertexState().components();
13 
14  // cout << "GsfVertexUpdator::Add new Track with "
15  // << track->linearizedTrack()->components().size() << " components to vertex of "
16  // << prevVtxComponents.size() << " components.\n";
17 
18  if (prevVtxComponents.empty()) {
19  throw VertexException("GsfVertexUpdator::(Previous) Vertex to update has no components");
20  }
21 
22  LTC ltComponents = track->linearizedTrack()->components();
23  if (ltComponents.empty()) {
24  throw VertexException("GsfVertexUpdator::Track to add to vertex has no components");
25  }
26 
27  if ((ltComponents.size() == 1) && (prevVtxComponents.size() == 1))
28  return kalmanVertexUpdator.add(oldVertex, track);
29 
30  float trackWeight = track->weight();
31 
32  std::vector<VertexComponent> newVertexComponents;
33  newVertexComponents.reserve(prevVtxComponents.size() * ltComponents.size());
34 
35  // for (LTC::iterator trackCompIter = ltComponents.begin();
36  // trackCompIter != ltComponents.end(); trackCompIter++ ) {
37  // cout <<(**trackCompIter).state().globalPosition()<<endl;
38  // }
39 
40  for (VSC::iterator vertexCompIter = prevVtxComponents.begin(); vertexCompIter != prevVtxComponents.end();
41  vertexCompIter++) {
42  for (LTC::iterator trackCompIter = ltComponents.begin(); trackCompIter != ltComponents.end(); trackCompIter++) {
43  newVertexComponents.push_back(createNewComponent(*vertexCompIter, *trackCompIter, trackWeight, +1));
44  // return invalid vertex in case one of the updated vertex-components is invalid
45  if (!newVertexComponents.back().first.isValid())
46  return CachingVertex<5>();
47  }
48  }
49  // cout << "updator components: "<<newVertexComponents.size()<<endl;
50 
51  // Update tracks vector
52 
53  std::vector<RefCountedVertexTrack> newVertexTracks = oldVertex.tracks();
54  newVertexTracks.push_back(track);
55  // cout << "a \n ";
56 
57  // Assemble VertexStates and compute Chi**2
58 
59  VertexChi2Pair vertexChi2Pair = assembleVertexComponents(newVertexComponents);
60  // cout << "b \n ";
61  VertexState newVertexState = vertexChi2Pair.first;
62  // cout << "c \n ";
63  double chi2 = oldVertex.totalChiSquared() + vertexChi2Pair.second;
64 
65  // Merge:
66  if (limitComponents)
67  newVertexState = theMerger->merge(newVertexState);
68 
69  if (oldVertex.hasPrior()) {
70  return CachingVertex<5>(oldVertex.priorPosition(),
71  oldVertex.priorError(),
72  newVertexState.weightTimesPosition(),
73  newVertexState.weight(),
74  newVertexTracks,
75  chi2);
76  } else {
77  return CachingVertex<5>(newVertexState, newVertexTracks, chi2);
78  }
79 }
80 
82  throw VertexException("GsfVertexUpdator::Remove Methode not yet done");
83  // return CachingVertex<5>();
84 }
85 
92  const RefCountedLinearizedTrackState linTrack,
93  float weight,
94  int sign) const {
95  if (abs(sign) != 1)
96  throw VertexException("GsfVertexUpdator::sign not equal to 1.");
97 
98  if (sign == -1)
99  throw VertexException("GsfVertexUpdator::sign of -1 not yet implemented.");
100 
101  // Weight of the component in the mixture (non-normalized)
102  double weightInMixture = theWeightCalculator.calculate(oldVertex, linTrack, 1.E9);
103  if (weightInMixture < 0.)
104  return VertexComponent(VertexState(), WeightChi2Pair(0., 0.));
105 
106  // position estimate of the component
107  VertexState newVertex = kalmanVertexUpdator.positionUpdate(oldVertex, linTrack, weight, sign);
108  if (!newVertex.isValid())
109  return VertexComponent(newVertex, WeightChi2Pair(0., 0.));
110 
111  //Chi**2 contribution of the component
112  std::pair<bool, double> chi2P = kalmanVertexUpdator.chi2Increment(oldVertex, newVertex, linTrack, weight);
113  if (!chi2P.first)
114  return VertexComponent(VertexState(), WeightChi2Pair(0., 0.));
115  // cout << "Update: "<<oldVertex.position()<<" "<<newVertex.position()<<" "<<chi2
116  // <<" "<<linTrack->weightInMixture()<<" "<<weightInMixture<<endl;
117 
118  return VertexComponent(newVertex, WeightChi2Pair(weightInMixture, chi2P.second));
119 }
120 
122  const std::vector<GsfVertexUpdator::VertexComponent>& newVertexComponents) const {
123  VSC vertexComponents;
124  vertexComponents.reserve(newVertexComponents.size());
125 
126  //renormalize weights
127  // cout << "assemble "<<newVertexComponents.size()<<endl;
128  double totalWeight = 0.;
129  double totalChi2 = 0.;
130 
131  for (std::vector<VertexComponent>::const_iterator iter = newVertexComponents.begin();
132  iter != newVertexComponents.end();
133  iter++) {
134  totalWeight += iter->second.first;
135  }
136  // cout << "totalWeight "<<totalWeight<<endl;
137  if (totalWeight < DBL_MIN) {
138  edm::LogWarning("GsfVertexUpdator") << "Updated Vertex has total weight of 0. "
139  << "The track is probably very far away.";
140  return VertexChi2Pair(VertexState(), 0.);
141  }
142 
143  for (std::vector<VertexComponent>::const_iterator iter = newVertexComponents.begin();
144  iter != newVertexComponents.end();
145  iter++) {
146  double weight = iter->second.first / totalWeight;
147  if (iter->second.first > DBL_MIN) {
148  vertexComponents.push_back(VertexState(iter->first.weightTimesPosition(), iter->first.weight(), weight));
149  totalChi2 += iter->second.second * weight;
150  }
151  }
152  // cout << "totalChi2 "<<totalChi2<<endl;
153  // cout << "vertexComponents "<<vertexComponents.size()<<endl;
154 
155  if (vertexComponents.empty()) {
156  edm::LogWarning("GsfVertexUpdator") << "No Vertex State left after reweighting.";
157  return VertexChi2Pair(VertexState(), 0.);
158  }
159 
160  return VertexChi2Pair(VertexState(new BasicMultiVertexState(vertexComponents)), totalChi2);
161 }
VertexState::isValid
bool isValid() const
Make the ReferenceCountingProxy method to check validity public.
Definition: VertexState.h:93
MessageLogger.h
BasicMultiVertexState.h
VertexException
Common base class.
Definition: VertexException.h:12
GsfVertexMerger::clone
GsfVertexMerger * clone() const
Definition: GsfVertexMerger.h:24
CachingVertex< 5 >
mps_merge.weight
weight
Definition: mps_merge.py:88
GsfVertexUpdator.h
generateEDF.totalWeight
totalWeight
Definition: generateEDF.py:688
GsfVertexUpdator::GsfVertexUpdator
GsfVertexUpdator(bool limit=false, const GsfVertexMerger *merger=nullptr)
Definition: GsfVertexUpdator.cc:6
CachingVertex::vertexState
const VertexState & vertexState() const
Definition: CachingVertex.h:137
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
CachingVertex::hasPrior
bool hasPrior() const
Definition: CachingVertex.h:153
ReferenceCountingPointer< LinearizedTrackState< N > >
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
GsfVertexUpdator::VertexChi2Pair
std::pair< VertexState, double > VertexChi2Pair
Definition: GsfVertexUpdator.h:45
KalmanVertexUpdator::add
CachingVertex< N > add(const CachingVertex< N > &oldVertex, const RefCountedVertexTrack track) const override
Definition: KalmanVertexUpdator.cc:56
GsfVertexUpdator::WeightChi2Pair
std::pair< double, double > WeightChi2Pair
Definition: GsfVertexUpdator.h:43
GsfVertexUpdator::theMerger
DeepCopyPointerByClone< GsfVertexMerger > theMerger
Definition: GsfVertexUpdator.h:55
GsfVertexUpdator::LTC
std::vector< RefCountedLinearizedTrackState > LTC
Definition: GsfVertexUpdator.h:42
CachingVertex::priorPosition
GlobalPoint priorPosition() const
Definition: CachingVertex.h:149
GsfVertexUpdator::createNewComponent
VertexComponent createNewComponent(const VertexState &oldVertex, const RefCountedLinearizedTrackState linTrack, float weight, int sign) const
Definition: GsfVertexUpdator.cc:91
CachingVertex::totalChiSquared
float totalChiSquared() const
Definition: CachingVertex.h:159
BasicMultiVertexState
Definition: BasicMultiVertexState.h:12
GsfVertexUpdator::add
CachingVertex< 5 > add(const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const override
Definition: GsfVertexUpdator.cc:11
edm::LogWarning
Definition: MessageLogger.h:141
GsfVertexUpdator::VSC
std::vector< VertexState > VSC
Definition: GsfVertexUpdator.h:41
KalmanVertexUpdator::chi2Increment
std::pair< bool, double > chi2Increment(const VertexState &oldVertex, const VertexState &newVertexState, const RefCountedLinearizedTrackState linearizedTrack, float weight) const
Definition: KalmanVertexUpdator.cc:129
GsfVertexUpdator::VertexComponent
std::pair< VertexState, WeightChi2Pair > VertexComponent
Definition: GsfVertexUpdator.h:44
VertexState::weight
GlobalWeight weight() const
Definition: VertexState.h:69
VertexState::components
std::vector< VertexState > components() const
Definition: VertexState.h:90
GsfVertexUpdator::remove
CachingVertex< 5 > remove(const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const override
Definition: GsfVertexUpdator.cc:81
GsfVertexUpdator::kalmanVertexUpdator
KalmanVertexUpdator< 5 > kalmanVertexUpdator
Definition: GsfVertexUpdator.h:56
CachingVertex::tracks
std::vector< RefCountedVertexTrack > tracks() const
Definition: CachingVertex.h:147
GsfVertexMerger
Definition: GsfVertexMerger.h:15
KalmanVertexUpdator::positionUpdate
VertexState positionUpdate(const VertexState &oldVertex, const RefCountedLinearizedTrackState linearizedTrack, const float weight, int sign) const
Definition: KalmanVertexUpdator.cc:70
VertexState::weightTimesPosition
AlgebraicVector3 weightTimesPosition() const
Definition: VertexState.h:77
GsfVertexUpdator::theWeightCalculator
GsfVertexWeightCalculator theWeightCalculator
Definition: GsfVertexUpdator.h:57
GsfVertexUpdator::assembleVertexComponents
VertexChi2Pair assembleVertexComponents(const std::vector< VertexComponent > &newVertexComponents) const
Definition: GsfVertexUpdator.cc:121
remoteMonitoring_LED_IterMethod_cfg.limit
limit
Definition: remoteMonitoring_LED_IterMethod_cfg.py:427
GsfVertexMerger::merge
CachingVertex< 5 > merge(const CachingVertex< 5 > &vertex) const
Definition: GsfVertexMerger.cc:47
VertexState
Definition: VertexState.h:13
GsfVertexUpdator::RefCountedVertexTrack
CachingVertex< 5 >::RefCountedVertexTrack RefCountedVertexTrack
Definition: GsfVertexUpdator.h:16
CachingVertex::priorError
GlobalError priorError() const
Definition: CachingVertex.h:151
GsfVertexUpdator::limitComponents
bool limitComponents
Definition: GsfVertexUpdator.h:54
trackWeight
float trackWeight(const reco::Vertex &sv, const reco::TransientTrack &track)
Definition: TrackVertexArbitration.h:122
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
GsfVertexWeightCalculator::calculate
double calculate(const VertexState &oldVertex, const RefCountedLinearizedTrackState track, double cov) const
Definition: GsfVertexWeightCalculator.cc:7
weight
Definition: weight.py:1