test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CachingVertex.cc
Go to the documentation of this file.
6 #include <map>
7 
8 //to be removed
9 template <unsigned int N>
11  const GlobalError & posErr,
12  const std::vector<RefCountedVertexTrack> & tks,
13  float totalChiSq)
14  : theVertexState(pos, posErr),
15  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
16  theTracks(tks), theCovMapAvailable(false), withPrior(false),
17  theValid(true)
18 
19 {}
20 
21 
22 //to be removed
23 template <unsigned int N>
25  const GlobalWeight & posWeight,
26  const std::vector<RefCountedVertexTrack> & tks,
27  float totalChiSq)
28  : theVertexState(pos, posWeight),
29  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
30  theTracks(tks), theCovMapAvailable(false), withPrior(false),
31  theValid(true)
32 {}
33 
34 
35 //to be removed
36 template <unsigned int N>
38  const GlobalWeight & posWeight,
39  const std::vector<RefCountedVertexTrack> & tks,
40  float totalChiSq)
41  : theVertexState(weightTimesPosition, posWeight),
42  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
43  theTracks(tks), theCovMapAvailable(false), withPrior(false),
44  theValid(true)
45 {}
46 
47 template <unsigned int N>
49  const std::vector<RefCountedVertexTrack> & tks,
50  float totalChiSq)
51  : theVertexState(aVertexState),
52  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
53  theTracks(tks), theCovMapAvailable(false), withPrior(false),
54  theValid(true)
55 {}
56 
57 
58 template <unsigned int N>
60  const std::vector<RefCountedVertexTrack> & tks,
61  float totalChiSq,
62  const TrackToTrackMap & covMap)
63  : theVertexState(aVertexState),
64  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
65  theTracks(tks), theCovMap(covMap), theCovMapAvailable(true),
66  withPrior(false), theValid(true)
67 {
68  if (theCovMap.empty()) theCovMapAvailable = false;
69 }
70 
71 template <unsigned int N>
72 CachingVertex<N>::CachingVertex(const VertexState & priorVertexState,
73  const VertexState & aVertexState,
74  const std::vector<RefCountedVertexTrack> & tks,
75  float totalChiSq)
76  : theVertexState(aVertexState), theChiSquared(totalChiSq),
77  theNDF(0), theNDFAvailable(false), theTracks(tks),
78  theCovMapAvailable(false), thePriorVertexState(priorVertexState),
79  withPrior(true), theValid(true)
80 {}
81 
82 //to be removed
83 template <unsigned int N>
85  const GlobalError & priorErr,
86  const GlobalPoint & pos,
87  const GlobalError & posErr,
88  const std::vector<RefCountedVertexTrack> & tks,
89  float totalChiSq)
90  : theVertexState(pos, posErr),
91  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
92  theTracks(tks), theCovMapAvailable(false),
93  thePriorVertexState(priorPos, priorErr), withPrior(true), theValid(true)
94 {}
95 
96 
97 //to be removed
98 template <unsigned int N>
100  const GlobalError & priorErr,
101  const GlobalPoint & pos,
102  const GlobalWeight & posWeight,
103  const std::vector<RefCountedVertexTrack> & tks,
104  float totalChiSq)
105  : theVertexState(pos, posWeight),
106  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
107  theTracks(tks), theCovMapAvailable(false),
108  thePriorVertexState(priorPos, priorErr), withPrior(true), theValid(true)
109 {}
110 
111 
112 //to be removed
113 template <unsigned int N>
115  const GlobalError & priorErr,
116  const AlgebraicVector3 & weightTimesPosition,
117  const GlobalWeight & posWeight,
118  const std::vector<RefCountedVertexTrack> & tks,
119  float totalChiSq)
120  : theVertexState(weightTimesPosition, posWeight),
121  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
122  theTracks(tks), theCovMapAvailable(false),
123  thePriorVertexState(priorPos, priorErr), withPrior(true), theValid(true)
124 {}
125 
126 
127 template <unsigned int N>
129  const VertexState & aVertexState,
130  const std::vector<RefCountedVertexTrack> & tks,
131  float totalChiSq,
132  const TrackToTrackMap & covMap)
133  : theVertexState(aVertexState), theChiSquared(totalChiSq),
134  theNDF(0), theNDFAvailable(false), theTracks(tks),
135  theCovMap(covMap), theCovMapAvailable(true),
136  thePriorVertexState(priorVertexState), withPrior(true), theValid(true)
137 {
138  if (theCovMap.empty()) theCovMapAvailable = false;
139 }
140 
141 template <unsigned int N>
143  : theChiSquared(-1), theNDF(0), theNDFAvailable(false), theTracks(),
144  theCovMapAvailable(false), withPrior(false),
145  theValid(false)
146 {}
147 
148 template <unsigned int N>
150 {
151  return theVertexState.position();
152 }
153 
154 
155 template <unsigned int N>
157 {
158  return theVertexState.error();
159 }
160 
161 
162 template <unsigned int N>
164 {
165  return theVertexState.weight();
166 }
167 
168 
169 template <unsigned int N>
171 {
172  return theVertexState.weightTimesPosition();
173 }
174 
175 
176 template <unsigned int N>
178 {
179  if (!theNDFAvailable) computeNDF();
180  return theNDF;
181 }
182 
183 
184 template <unsigned int N>
186 {
187  theNDF = 0;
188  for (typename std::vector<RefCountedVertexTrack>::const_iterator itk = theTracks.begin();
189  itk != theTracks.end(); ++itk) {
190  theNDF += (**itk).weight(); // adds up weights
191  }
192  theNDF *= 2.; // times 2df for each track
193  if (!withPrior) theNDF -= 3.; // 3 position coordinates fitted
194  theNDFAvailable = true;
195 }
196 
197 
198 template <unsigned int N>
201  const RefCountedVertexTrack t2) const
202 {
203  if (!tkToTkCovarianceIsAvailable()) {
204  throw VertexException("CachingVertex::TkTkCovariance requested before been calculated");
205  }
206  else {
209  bool transp = false;
210  if(t1 < t2) {
211  tr1 = t1;
212  tr2 = t2;
213  }
214  else {
215  tr1 = t2;
216  tr2 = t1;
217  transp = true;
218  }
219  typename TrackToTrackMap::const_iterator it = theCovMap.find(tr1);
220  if (it != theCovMap.end()) {
221  const TrackMap & tm = it->second;
222  typename TrackMap::const_iterator nit = tm.find(tr2);
223  if (nit != tm.end()) {
224  if (transp) return( ROOT::Math::Transpose(nit->second) );
225  else return( nit->second);
226  }
227  else {
228  throw VertexException("CachingVertex::requested TkTkCovariance does not exist");
229  }
230  }
231  else {
232  throw VertexException("CachingVertex::requested TkTkCovariance does not exist");
233  }
234  }
235 }
236 
237 template <unsigned int N>
239 {
240  //If the vertex is invalid, return an invalid TV !
241  if (!isValid()) return TransientVertex();
242 
243  typedef std::map<reco::TransientTrack, float> TransientTrackToFloatMap;
244 
245 // Construct Track vector
246  std::vector<reco::TransientTrack> ttVect;
247  ttVect.reserve(theTracks.size());
248  std::vector<reco::TransientTrack> refTTVect;
249  TransientTrackToFloatMap theWeightMap;
250  TTtoTTmap ttCovMap;
251  // float theMinWeight = 0.5;
252 
253  for (typename std::vector<RefCountedVertexTrack>::const_iterator i = theTracks.begin();
254  i != theTracks.end(); ++i) {
255  // discard tracks with too low weight
256  // if ((**i).weight() < theMinWeight) continue;
257 
258  reco::TransientTrack t1((**i).linearizedTrack()->track());
259  ttVect.push_back(t1);
260  //Fill in the weight map
261  theWeightMap[t1] = (**i).weight();
262 
263  //Fill in the tk-to-tk covariance map
264  if (theCovMapAvailable) {
265  for (typename std::vector<RefCountedVertexTrack>::const_iterator j = (i+1);
266  j != theTracks.end(); ++j) {
267  reco::TransientTrack t2((**j).linearizedTrack()->track());
268  ttCovMap[t1][t2] = tkToTkCovariance(*i, *j);
269  }
270  }
271  if ((**i).refittedStateAvailable()) {
272  refTTVect.push_back( (**i).refittedState()->transientTrack()) ;
273  }
274  }
275  TransientVertex tv;
276  if (withPrior) {
277  tv = TransientVertex(priorVertexState(), vertexState(), ttVect, totalChiSquared(), degreesOfFreedom());
278  } else {
279  tv = TransientVertex(vertexState(), ttVect, totalChiSquared(), degreesOfFreedom());
280  }
281  tv.weightMap(theWeightMap);
282  if (theCovMapAvailable) tv.tkToTkCovariance(ttCovMap);
283  if (!refTTVect.empty()) tv.refittedTracks(refTTVect);
284  return tv;
285 }
286 
287 
288 
289 template class CachingVertex<5>;
290 template class CachingVertex<6>;
int i
Definition: DBlmapReader.cc:9
bool theCovMapAvailable
void computeNDF() const
Common base class.
TrackToTrackMap theCovMap
std::map< reco::TransientTrack, TTmap > TTtoTTmap
Definition: TTtoTTmap.h:12
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:16
AlgebraicVector3 weightTimesPosition() const
GlobalWeight weight() const
ROOT::Math::SVector< double, 3 > AlgebraicVector3
int j
Definition: DBlmapReader.cc:9
std::map< RefCountedVertexTrack, AlgebraicMatrixMM > TrackMap
Definition: CachingVertex.h:32
float degreesOfFreedom() const
AlgebraicMatrixMM tkToTkCovariance(const RefCountedVertexTrack t1, const RefCountedVertexTrack t2) const
GlobalPoint position() const
ROOT::Math::SMatrix< double, N-2, N-2, ROOT::Math::MatRepStd< double, N-2, N-2 > > AlgebraicMatrixMM
Definition: CachingVertex.h:31
std::vector< reco::TransientTrack > const & refittedTracks() const
volatile std::atomic< bool > shutdown_flag false
GlobalError error() const
AlgebraicMatrix33 tkToTkCovariance(const reco::TransientTrack &t1, const reco::TransientTrack &t2) const
TransientTrackToFloatMap weightMap() const