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.
6 #include <algorithm>
7 
8 using namespace std;
9 using namespace reco;
10 
11 TransientVertex::TransientVertex() : theVertexState(), theOriginalTracks(),
12  theChi2(0), theNDF(0), vertexValid(false), withPrior(false),
13  theWeightMapIsAvailable(false), theCovMapAvailable(false),
14  withRefittedTracks(false)
15 {}
16 
17 
19  const std::vector<TransientTrack> & tracks, float chi2) :
20  theVertexState(pos, posError), theOriginalTracks(tracks),
21  theChi2(chi2), theNDF(0), vertexValid(true), withPrior(false),
22  theWeightMapIsAvailable(false), theCovMapAvailable(false),
23  withRefittedTracks(false)
24 {
25  theNDF = 2.*theOriginalTracks.size() - 3.;
26  // addTracks(tracks);
27 }
28 
29 
31  const std::vector<TransientTrack> & tracks, float chi2, float ndf) :
32  theVertexState(pos, posError), theOriginalTracks(tracks),
33  theChi2(chi2), theNDF(ndf), vertexValid(true), withPrior(false),
34  theWeightMapIsAvailable(false), theCovMapAvailable(false),
35  withRefittedTracks(false)
36 {
37  // addTracks(tracks);
38 }
39 
40 
41 TransientVertex::TransientVertex(const GlobalPoint & priorPos, const GlobalError & priorErr,
42  const GlobalPoint & pos, const GlobalError & posError,
43  const std::vector<TransientTrack> & tracks, float chi2) :
44  thePriorVertexState(priorPos, priorErr), theVertexState(pos, posError),
45  theOriginalTracks(tracks), theChi2(chi2), theNDF(0), vertexValid(true),
46  withPrior(true), theWeightMapIsAvailable(false), theCovMapAvailable(false),
47  withRefittedTracks(false)
48 {
49  theNDF = 2.*theOriginalTracks.size();
50  // addTracks(tracks);
51 }
52 
53 
54 TransientVertex::TransientVertex(const GlobalPoint & priorPos, const GlobalError & priorErr,
55  const GlobalPoint & pos, const GlobalError & posError,
56  const std::vector<TransientTrack> & tracks, float chi2, float ndf) :
57  thePriorVertexState(priorPos, priorErr), theVertexState(pos, posError),
58  theOriginalTracks(tracks), theChi2(chi2), theNDF(ndf), vertexValid(true),
59  withPrior(true), theWeightMapIsAvailable(false), theCovMapAvailable(false),
60  withRefittedTracks(false)
61 {
62  // addTracks(tracks);
63 }
64 
65 
67  const std::vector<TransientTrack> & tracks, float chi2) :
68  theVertexState(state), theOriginalTracks(tracks),
69  theChi2(chi2), theNDF(0), vertexValid(true), withPrior(false),
70  theWeightMapIsAvailable(false), theCovMapAvailable(false),
71  withRefittedTracks(false)
72 {
73  theNDF = 2.*theOriginalTracks.size() - 3.;
74 }
75 
76 
78  const std::vector<TransientTrack> & tracks, float chi2, float ndf) :
79  theVertexState(state), theOriginalTracks(tracks),
80  theChi2(chi2), theNDF(ndf), vertexValid(true), withPrior(false),
81  theWeightMapIsAvailable(false), theCovMapAvailable(false),
82  withRefittedTracks(false)
83 {
84  // addTracks(tracks);
85 }
86 
87 
89  const VertexState & state,
90  const std::vector<TransientTrack> & tracks,
91  float chi2) :
92  thePriorVertexState(prior), theVertexState(state),
93  theOriginalTracks(tracks), theChi2(chi2), theNDF(0), vertexValid(true),
94  withPrior(true), theWeightMapIsAvailable(false), theCovMapAvailable(false),
95  withRefittedTracks(false)
96 {
97  theNDF = 2.*theOriginalTracks.size();
98  // addTracks(tracks);
99 }
100 
101 
103  const VertexState & state,
104  const std::vector<TransientTrack> & tracks,
105  float chi2, float ndf) :
106  thePriorVertexState(prior), theVertexState(state),
107  theOriginalTracks(tracks), theChi2(chi2), theNDF(ndf), vertexValid(true),
108  withPrior(true), theWeightMapIsAvailable(false),
109  theCovMapAvailable(false), withRefittedTracks(false)
110 {
111  // addTracks(tracks);
112 }
113 
115 {
116  theWeightMap = theMap;
118 // removeTracks(); // remove trackrefs from reco::Vertex
119 // addTracks( theOriginalTracks );
120 }
121 
123  const std::vector<reco::TransientTrack> & refittedTracks)
124 {
125  if (refittedTracks.empty())
126  throw VertexException("TransientVertex::refittedTracks: No refitted tracks stored in input container");
128  withRefittedTracks = true;
129 }
130 
131 
133 {
134  theCovMap = covMap;
135  theCovMapAvailable = true;
136 }
137 
138 float TransientVertex::trackWeight(const TransientTrack & track) const {
140  std::vector<TransientTrack>::const_iterator foundTrack = find(theOriginalTracks.begin(),
141  theOriginalTracks.end(), track);
142  return ((foundTrack != theOriginalTracks.end()) ? 1. : 0.);
143  }
144  TransientTrackToFloatMap::const_iterator it = theWeightMap.find(track);
145  if (it != theWeightMap.end()) {
146  return(it->second);
147  }
148  return 0.;
149 
150 }
151 
154 {
155  if (!theCovMapAvailable) {
156  throw VertexException("TransientVertex::Track-to-track covariance matrices not available");
157  }
158  const TransientTrack* tr1;
159  const TransientTrack* tr2;
160  if (t1<t2) {
161  tr1 = &t1;
162  tr2 = &t2;
163  } else {
164  tr1 = &t2;
165  tr2 = &t1;
166  }
167  TTtoTTmap::const_iterator it = theCovMap.find(*tr1);
168  if (it != theCovMap.end()) {
169  const TTmap & tm = it->second;
170  TTmap::const_iterator nit = tm.find(*tr2);
171  if (nit != tm.end()) {
172  return( nit->second);
173  }
174  else {
175  throw VertexException("TransientVertex::requested Track-to-track covariance matrix does not exist");
176  }
177  }
178  else {
179  throw VertexException("TransientVertex::requested Track-to-track covariance matrix does not exist");
180  }
181 }
182 
183 
185 {
186  if (theRefittedTracks.empty())
187  throw VertexException("No refitted tracks stored in vertex");
188  std::vector<TransientTrack>::const_iterator it =
189  find(theRefittedTracks.begin(), theRefittedTracks.end(), refTrack);
190  if (it==theRefittedTracks.end())
191  throw VertexException("Refitted track not found in list");
192  size_t pos = it - theRefittedTracks.begin();
193  return theOriginalTracks[pos];
194 }
195 
197 {
198  if (theRefittedTracks.empty())
199  throw VertexException("No refitted tracks stored in vertex");
200  std::vector<TransientTrack>::const_iterator it =
201  find(theOriginalTracks.begin(), theOriginalTracks.end(), track);
202  if (it==theOriginalTracks.end())
203  throw VertexException("Track not found in list");
204  size_t pos = it - theOriginalTracks.begin();
205  return theRefittedTracks[pos];
206 }
207 
209 {
210  //If the vertex is invalid, return an invalid TV !
211  if (!isValid()) return Vertex();
212 
213  Vertex vertex(Vertex::Point(theVertexState.position()),
214 // RecoVertex::convertError(theVertexState.error()),
215  theVertexState.error().matrix_new(),
216  totalChiSquared(), degreesOfFreedom(), theOriginalTracks.size() );
217  for (std::vector<TransientTrack>::const_iterator i = theOriginalTracks.begin();
218  i != theOriginalTracks.end(); ++i) {
219 // const TrackTransientTrack* ttt = dynamic_cast<const TrackTransientTrack*>((*i).basicTransientTrack());
220 // if ((ttt!=0) && (ttt->persistentTrackRef().isNonnull()))
221 // {
222 // TrackRef tr = ttt->persistentTrackRef();
223 // TrackBaseRef tbr(tr);
224  if (withRefittedTracks) {
225 
226  vertex.add((*i).trackBaseRef(), refittedTrack(*i).track(), trackWeight ( *i ) );
227  } else {
228  vertex.add((*i).trackBaseRef(), trackWeight ( *i ) );
229  }
230  //}
231  }
232  return vertex;
233 }
234 
236 {
237 using namespace reco;
238  if (!isValid()) return VertexCompositePtrCandidate();
239 
240  VertexCompositePtrCandidate vtxCompPtrCand;
241 
242  vtxCompPtrCand.setCovariance(vertexState().error().matrix_new());
243  vtxCompPtrCand.setChi2AndNdof(totalChiSquared(), degreesOfFreedom());
244  vtxCompPtrCand.setVertex(Candidate::Point(position().x(),position().y(),position().z()));
245 
247  for(std::vector<reco::TransientTrack>::const_iterator tt = theOriginalTracks.begin(); tt != theOriginalTracks.end(); ++tt)
248  {
249  if (trackWeight(*tt) < 0.5)
250  continue;
251 
252  const CandidatePtrTransientTrack* cptt = dynamic_cast<const CandidatePtrTransientTrack*>(tt->basicTransientTrack());
253  if ( cptt==0 )
254  edm::LogError("DynamicCastingFailed") << "Casting of TransientTrack to CandidatePtrTransientTrack failed!";
255  else
256  {
257  p4 += cptt->candidate()->p4();
258  vtxCompPtrCand.addDaughter(cptt->candidate());
259  }
260  }
261 
262  //TODO: if has refitted tracks we should scale the candidate p4 to the refitted one
263  vtxCompPtrCand.setP4(p4);
264  return vtxCompPtrCand;
265 }
266 
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
T x() const
Cartesian x coordinate.
reco::TransientTrack refittedTrack(const reco::TransientTrack &track) const
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:16
operator reco::Vertex() const
TransientTrackToFloatMap theWeightMap
double p4[4]
Definition: TauolaWrapper.h:92
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
std::vector< reco::TransientTrack > theOriginalTracks
float trackWeight(const reco::TransientTrack &track) const
void add(const TrackBaseRef &r, float w=1.0)
add a reference to a Track
float trackWeight(const reco::Vertex &sv, const reco::TransientTrack &track)
reco::TransientTrack originalTrack(const reco::TransientTrack &refTrack) const
tuple tracks
Definition: testEve_cfg.py:39
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
dictionary prior
static int position[264][3]
Definition: ReadPGInfo.cc:509
void setCovariance(const CovarianceMatrix &m)
set covariance matrix
math::XYZPoint Point
point in the space
Definition: Candidate.h:41
std::vector< reco::TransientTrack > const & refittedTracks() const
volatile std::atomic< bool > shutdown_flag false
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