CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TransientVertex.cc
Go to the documentation of this file.
4 #include <algorithm>
5 
6 using namespace std;
7 using namespace reco;
8 
9 TransientVertex::TransientVertex() : theVertexState(), theOriginalTracks(),
10  theChi2(0), theNDF(0), vertexValid(false), withPrior(false),
11  theWeightMapIsAvailable(false), theCovMapAvailable(false),
12  withRefittedTracks(false)
13 {}
14 
15 
17  const std::vector<TransientTrack> & tracks, float chi2) :
18  theVertexState(pos, posError), theOriginalTracks(tracks),
19  theChi2(chi2), theNDF(0), vertexValid(true), withPrior(false),
20  theWeightMapIsAvailable(false), theCovMapAvailable(false),
21  withRefittedTracks(false)
22 {
23  theNDF = 2.*theOriginalTracks.size() - 3.;
24  // addTracks(tracks);
25 }
26 
27 
29  const std::vector<TransientTrack> & tracks, float chi2, float ndf) :
30  theVertexState(pos, posError), theOriginalTracks(tracks),
31  theChi2(chi2), theNDF(ndf), vertexValid(true), withPrior(false),
32  theWeightMapIsAvailable(false), theCovMapAvailable(false),
33  withRefittedTracks(false)
34 {
35  // addTracks(tracks);
36 }
37 
38 
39 TransientVertex::TransientVertex(const GlobalPoint & priorPos, const GlobalError & priorErr,
40  const GlobalPoint & pos, const GlobalError & posError,
41  const std::vector<TransientTrack> & tracks, float chi2) :
42  thePriorVertexState(priorPos, priorErr), theVertexState(pos, posError),
43  theOriginalTracks(tracks), theChi2(chi2), theNDF(0), vertexValid(true),
44  withPrior(true), theWeightMapIsAvailable(false), theCovMapAvailable(false),
45  withRefittedTracks(false)
46 {
47  theNDF = 2.*theOriginalTracks.size();
48  // addTracks(tracks);
49 }
50 
51 
52 TransientVertex::TransientVertex(const GlobalPoint & priorPos, const GlobalError & priorErr,
53  const GlobalPoint & pos, const GlobalError & posError,
54  const std::vector<TransientTrack> & tracks, float chi2, float ndf) :
55  thePriorVertexState(priorPos, priorErr), theVertexState(pos, posError),
56  theOriginalTracks(tracks), theChi2(chi2), theNDF(ndf), vertexValid(true),
57  withPrior(true), theWeightMapIsAvailable(false), theCovMapAvailable(false),
58  withRefittedTracks(false)
59 {
60  // addTracks(tracks);
61 }
62 
63 
65  const std::vector<TransientTrack> & tracks, float chi2) :
66  theVertexState(state), theOriginalTracks(tracks),
67  theChi2(chi2), theNDF(0), vertexValid(true), withPrior(false),
68  theWeightMapIsAvailable(false), theCovMapAvailable(false),
69  withRefittedTracks(false)
70 {
71  theNDF = 2.*theOriginalTracks.size() - 3.;
72 }
73 
74 
76  const std::vector<TransientTrack> & tracks, float chi2, float ndf) :
77  theVertexState(state), theOriginalTracks(tracks),
78  theChi2(chi2), theNDF(ndf), vertexValid(true), withPrior(false),
79  theWeightMapIsAvailable(false), theCovMapAvailable(false),
80  withRefittedTracks(false)
81 {
82  // addTracks(tracks);
83 }
84 
85 
87  const VertexState & state,
88  const std::vector<TransientTrack> & tracks,
89  float chi2) :
90  thePriorVertexState(prior), theVertexState(state),
91  theOriginalTracks(tracks), theChi2(chi2), theNDF(0), vertexValid(true),
92  withPrior(true), theWeightMapIsAvailable(false), theCovMapAvailable(false),
93  withRefittedTracks(false)
94 {
95  theNDF = 2.*theOriginalTracks.size();
96  // addTracks(tracks);
97 }
98 
99 
101  const VertexState & state,
102  const std::vector<TransientTrack> & tracks,
103  float chi2, float ndf) :
104  thePriorVertexState(prior), theVertexState(state),
105  theOriginalTracks(tracks), theChi2(chi2), theNDF(ndf), vertexValid(true),
106  withPrior(true), theWeightMapIsAvailable(false),
107  theCovMapAvailable(false), withRefittedTracks(false)
108 {
109  // addTracks(tracks);
110 }
111 
113 {
114  theWeightMap = theMap;
116 // removeTracks(); // remove trackrefs from reco::Vertex
117 // addTracks( theOriginalTracks );
118 }
119 
121  const std::vector<reco::TransientTrack> & refittedTracks)
122 {
123  if (refittedTracks.empty())
124  throw VertexException("TransientVertex::refittedTracks: No refitted tracks stored in input container");
126  withRefittedTracks = true;
127 }
128 
129 
131 {
132  theCovMap = covMap;
133  theCovMapAvailable = true;
134 }
135 
136 float TransientVertex::trackWeight(const TransientTrack & track) const {
138  std::vector<TransientTrack>::const_iterator foundTrack = find(theOriginalTracks.begin(),
139  theOriginalTracks.end(), track);
140  return ((foundTrack != theOriginalTracks.end()) ? 1. : 0.);
141  }
142  TransientTrackToFloatMap::const_iterator it = theWeightMap.find(track);
143  if (it != theWeightMap.end()) {
144  return(it->second);
145  }
146  return 0.;
147 
148 }
149 
152 {
153  if (!theCovMapAvailable) {
154  throw VertexException("TransientVertex::Track-to-track covariance matrices not available");
155  }
156  const TransientTrack* tr1;
157  const TransientTrack* tr2;
158  if (t1<t2) {
159  tr1 = &t1;
160  tr2 = &t2;
161  } else {
162  tr1 = &t2;
163  tr2 = &t1;
164  }
165  TTtoTTmap::const_iterator it = theCovMap.find(*tr1);
166  if (it != theCovMap.end()) {
167  const TTmap & tm = it->second;
168  TTmap::const_iterator nit = tm.find(*tr2);
169  if (nit != tm.end()) {
170  return( nit->second);
171  }
172  else {
173  throw VertexException("TransientVertex::requested Track-to-track covariance matrix does not exist");
174  }
175  }
176  else {
177  throw VertexException("TransientVertex::requested Track-to-track covariance matrix does not exist");
178  }
179 }
180 
181 
183 {
184  if (theRefittedTracks.empty())
185  throw VertexException("No refitted tracks stored in vertex");
186  std::vector<TransientTrack>::const_iterator it =
187  find(theRefittedTracks.begin(), theRefittedTracks.end(), refTrack);
188  if (it==theRefittedTracks.end())
189  throw VertexException("Refitted track not found in list");
190  size_t pos = it - theRefittedTracks.begin();
191  return theOriginalTracks[pos];
192 }
193 
195 {
196  if (theRefittedTracks.empty())
197  throw VertexException("No refitted tracks stored in vertex");
198  std::vector<TransientTrack>::const_iterator it =
199  find(theOriginalTracks.begin(), theOriginalTracks.end(), track);
200  if (it==theOriginalTracks.end())
201  throw VertexException("Track not found in list");
202  size_t pos = it - theOriginalTracks.begin();
203  return theRefittedTracks[pos];
204 }
205 
207 {
208  //If the vertex is invalid, return an invalid TV !
209  if (!isValid()) return Vertex();
210 
211  Vertex vertex(Vertex::Point(theVertexState.position()),
212 // RecoVertex::convertError(theVertexState.error()),
213  theVertexState.error().matrix_new(),
214  totalChiSquared(), degreesOfFreedom(), theOriginalTracks.size() );
215  for (std::vector<TransientTrack>::const_iterator i = theOriginalTracks.begin();
216  i != theOriginalTracks.end(); ++i) {
217 // const TrackTransientTrack* ttt = dynamic_cast<const TrackTransientTrack*>((*i).basicTransientTrack());
218 // if ((ttt!=0) && (ttt->persistentTrackRef().isNonnull()))
219 // {
220 // TrackRef tr = ttt->persistentTrackRef();
221 // TrackBaseRef tbr(tr);
222  if (withRefittedTracks) {
223 
224  vertex.add((*i).trackBaseRef(), refittedTrack(*i).track(), trackWeight ( *i ) );
225  } else {
226  vertex.add((*i).trackBaseRef(), trackWeight ( *i ) );
227  }
228  //}
229  }
230  return vertex;
231 }
int i
Definition: DBlmapReader.cc:9
Common base class.
std::map< reco::TransientTrack, float > TransientTrackToFloatMap
std::map< reco::TransientTrack, TTmap > TTtoTTmap
Definition: TTtoTTmap.h:12
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::map< reco::TransientTrack, AlgebraicMatrix33 > TTmap
Definition: TTtoTTmap.h:11
reco::TransientTrack refittedTrack(const reco::TransientTrack &track) const
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:18
TransientTrackToFloatMap theWeightMap
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
std::vector< reco::TransientTrack > theOriginalTracks
float trackWeight(const reco::TransientTrack &track) const
std::vector< reco::TransientTrack > refittedTracks() const
void add(const TrackBaseRef &r, float w=1.0)
add a reference to a Track
reco::TransientTrack originalTrack(const reco::TransientTrack &refTrack) const
tuple tracks
Definition: testEve_cfg.py:39
char state
Definition: procUtils.cc:75
dictionary prior
std::vector< reco::TransientTrack > theRefittedTracks
AlgebraicMatrix33 tkToTkCovariance(const reco::TransientTrack &t1, const reco::TransientTrack &t2) const
TransientTrackToFloatMap weightMap() const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33