ATLAS Offline Software
BPhysPVTools.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "TVector3.h"
12 
13 #include <limits>
14 #include <iostream>
15 #include <cmath>
16 using namespace std;
17 
19  AthMessaging("BPhysPVTools"),
20  m_v0Tools(v0Tools), m_EvtData(nullptr), m_PV_minNTracks(0),
21  m_3dCalc(false)
22 {
23 }
24 
26  AthMessaging("BPhysPVTools"),
27  m_v0Tools(v0Tools), m_EvtData(eventInfo), m_PV_minNTracks(0),
28  m_3dCalc(false)
29 {
30 }
31 
33  const xAOD::Vertex* PV, const xAOD::VertexContainer* PvContainer,
34  xAOD::BPhysHelper::pv_type pvtype, int refitCode) const {
35 
36  BPHYS_CHECK( vtx.setPv ( PV, PvContainer, pvtype ) );
37 
38  // cout << "BPhysPVTools::FillBPhysHelper for pvtype = " << pvtype << endl;
39 
40  // set variables calculated from PV
41  if(m_3dCalc){
42  BPHYS_CHECK( vtx.setLxyz ( m_v0Tools->lxyz (vtx.vtx(), PV), pvtype ) );
43  BPHYS_CHECK( vtx.setLxyzErr ( m_v0Tools->lxyzError (vtx.vtx(), PV), pvtype ) );
44  }
45  BPHYS_CHECK( vtx.setLxy ( m_v0Tools->lxy (vtx.vtx(), PV), pvtype ) );
46  BPHYS_CHECK( vtx.setLxyErr ( m_v0Tools->lxyError (vtx.vtx(), PV), pvtype ) );
47  BPHYS_CHECK( vtx.setA0 ( m_v0Tools->a0 (vtx.vtx(), PV), pvtype ) );
48  BPHYS_CHECK( vtx.setA0Err ( m_v0Tools->a0Error (vtx.vtx(), PV), pvtype ) );
49  BPHYS_CHECK( vtx.setA0xy ( m_v0Tools->a0xy (vtx.vtx(), PV), pvtype ) );
50  BPHYS_CHECK( vtx.setA0xyErr( m_v0Tools->a0xyError (vtx.vtx(), PV), pvtype ) );
51  BPHYS_CHECK( vtx.setZ0 ( m_v0Tools->a0z (vtx.vtx(), PV), pvtype ) );
52  BPHYS_CHECK( vtx.setZ0Err ( m_v0Tools->a0zError (vtx.vtx(), PV), pvtype ) );
53  BPHYS_CHECK( vtx.setRefitPVStatus ( refitCode, pvtype ) );
54 
55 }
56 
58  const xAOD::VertexContainer* PvContainer,
59  xAOD::BPhysHelper::pv_type pvtype, bool do3d) const {
60 
61  const xAOD::Vertex* PV = nullptr;
62  BPHYS_CHECK( vtx.setPv ( PV, PvContainer, pvtype ) );
63  constexpr float errConst = std::numeric_limits<float>::lowest();
64  // set variables claculated from PV
65  if(do3d){
66  BPHYS_CHECK( vtx.setLxyz ( errConst, pvtype ) );
67  BPHYS_CHECK( vtx.setLxyzErr ( errConst, pvtype ) );
68  }
69  BPHYS_CHECK( vtx.setLxy ( errConst, pvtype ) );
70  BPHYS_CHECK( vtx.setLxyErr ( errConst, pvtype ) );
71  BPHYS_CHECK( vtx.setA0 ( errConst, pvtype ) );
72  BPHYS_CHECK( vtx.setA0Err ( errConst, pvtype ) );
73  BPHYS_CHECK( vtx.setA0xy ( errConst, pvtype ) );
74  BPHYS_CHECK( vtx.setA0xyErr( errConst, pvtype ) );
75  BPHYS_CHECK( vtx.setZ0 ( errConst, pvtype ) );
76  BPHYS_CHECK( vtx.setZ0Err ( errConst, pvtype ) );
77  BPHYS_CHECK( vtx.setRefitPVStatus ( 0, pvtype ) );
78 }
79 
81  const std::vector<const xAOD::Vertex*> &PVlist,
82  const size_t PV_minNTracks) const {
83  size_t lowZ = 0;
84  if(PVlist.empty()) {
86  return lowZ;
87  }
88  size_t size = PVlist.size();
89  double lowA0zcalc = fabs(m_v0Tools->a0z (Obj.vtx(), PVlist[0]));
90  for(size_t i =1; i<size; i++) {
91  if ( PVlist[i]->nTrackParticles() >= PV_minNTracks ) {
92  double a0z = fabs(m_v0Tools->a0z(Obj.vtx(), PVlist[i]));
93  if(a0z < lowA0zcalc) {
94  lowA0zcalc = a0z;
95  lowZ =i;
96  }
97  }
98  }
99  return lowZ;
100 }
101 
103  const xAOD::VertexContainer* pvContainer, const xAOD::Vertex* Dummy,
104  int DoVertexType, const bool SetOrignal) const {
105  const bool doPt = (DoVertexType & 1) != 0;
106  const bool doA0 = (DoVertexType & 2) != 0;
107  const bool doZ0 = (DoVertexType & 4) != 0;
108  const bool doZ0BA = (DoVertexType & 8) != 0;
109 
110  xAOD::VertexContainer::iterator vtxItr = vtxContainer->begin();
111  for(; vtxItr!=vtxContainer->end(); ++vtxItr) {
112  xAOD::BPhysHelper vtx(*vtxItr);
113 
114  // 1) pT error
115  double ptErr = m_v0Tools->pTError( vtx.vtx() );
116  BPHYS_CHECK( vtx.setPtErr(ptErr) );
117  if(doPt) {
118  // 2.a) the first PV with the largest sum pT.
119  FillBPhysHelper(vtx, Dummy, pvContainer, xAOD::BPhysHelper::PV_MAX_SUM_PT2, 0);
120  if(SetOrignal) vtx.setOrigPv(Dummy, pvContainer, xAOD::BPhysHelper::PV_MAX_SUM_PT2);
121  }
122 
123  if(doA0) {
124  // 2.b) the closest in 3D:
125  FillBPhysHelper(vtx, Dummy, pvContainer, xAOD::BPhysHelper::PV_MIN_A0, 0);
126  if(SetOrignal) vtx.setOrigPv(Dummy, pvContainer, xAOD::BPhysHelper::PV_MIN_A0);
127  }
128 
129  if(doZ0) {
130  FillBPhysHelper(vtx, Dummy, pvContainer, xAOD::BPhysHelper::PV_MIN_Z0, 0);
131  if(SetOrignal) vtx.setOrigPv(Dummy, pvContainer, xAOD::BPhysHelper::PV_MIN_Z0);
132  }
133 
134  if(doZ0BA) {
135  FillBPhysHelper(vtx, Dummy, pvContainer, xAOD::BPhysHelper::PV_MIN_Z0_BA, 0);
136  if(SetOrignal) vtx.setOrigPv(Dummy, pvContainer, xAOD::BPhysHelper::PV_MIN_Z0_BA);
137  }
138  }
139 }
140 
142  const xAOD::VertexContainer* pvContainer, int DoVertexType) const {
143  const bool doPt = (DoVertexType & 1) != 0;
144  const bool doA0 = (DoVertexType & 2) != 0;
145  const bool doZ0 = (DoVertexType & 4) != 0;
146  const bool doZ0BA = (DoVertexType & 8) != 0;
147  xAOD::VertexContainer::iterator vtxItr = vtxContainer->begin();
148  for(; vtxItr!=vtxContainer->end(); ++vtxItr) {
149  xAOD::BPhysHelper vtx(*vtxItr);
150 
151  // 1) pT error
152  double ptErr = m_v0Tools->pTError( vtx.vtx() );
153  BPHYS_CHECK( vtx.setPtErr(ptErr) );
154  if(doPt) {
155  // 2.a) the first PV with the largest sum pT.
156  FillBPhysHelperNULL(vtx, pvContainer, xAOD::BPhysHelper::PV_MAX_SUM_PT2, m_3dCalc);
157  }
158 
159  if(doA0) {
160  // 2.b) the closest in 3D:
161  FillBPhysHelperNULL(vtx, pvContainer, xAOD::BPhysHelper::PV_MIN_A0, m_3dCalc);
162  }
163 
164  if(doZ0) {
165  FillBPhysHelperNULL(vtx, pvContainer, xAOD::BPhysHelper::PV_MIN_Z0, m_3dCalc);
166  }
167  if(doZ0BA) {
168  FillBPhysHelperNULL(vtx, pvContainer, xAOD::BPhysHelper::PV_MIN_Z0_BA, m_3dCalc);
169  }
170  }
171 }
172 
174  const xAOD::VertexContainer* pvContainer, int DoVertexType) {
175 
176 
177 
178  //----------------------------------------------------
179  // decorate the vertex
180  //----------------------------------------------------
181  // loop over candidates -- Don't apply PV_minNTracks requirement here
182  // because it may result in exclusion of the high-pt PV.
183  const std::vector<const xAOD::Vertex*> GoodPVs = GetGoodPV(pvContainer);
184 
185 
186  if(GoodPVs.empty() == false) {
187 
188  const bool doPt = (DoVertexType & 1) != 0;
189  const bool doA0 = (DoVertexType & 2) != 0;
190  const bool doZ0 = (DoVertexType & 4) != 0;
191  const bool doZ0BA = (DoVertexType & 8) != 0;
192 
193  xAOD::VertexContainer::iterator vtxItr = vtxContainer->begin();
194  for(; vtxItr!=vtxContainer->end(); ++vtxItr) {
195  xAOD::BPhysHelper vtx(*vtxItr);
196 
197  // 1) pT error
198  double ptErr = m_v0Tools->pTError( vtx.vtx() );
199  BPHYS_CHECK( vtx.setPtErr(ptErr) );
200 
201  // 2) refit the primary vertex and set the related decorations.
202  if(doPt) {
203  size_t highPtindex = FindHighPtIndex(GoodPVs); //Should be 0 in PV ordering
204  // 2.a) the first PV with the largest sum pT.
205  FillBPhysHelper(vtx, GoodPVs[highPtindex], pvContainer, xAOD::BPhysHelper::PV_MAX_SUM_PT2, 0);
206  }
207 
208  if(doA0) {
209  // 2.b) the closest in 3D:
210  size_t lowA0 = FindLowA0Index(vtx, GoodPVs, m_PV_minNTracks);
211  FillBPhysHelper(vtx, GoodPVs[lowA0], pvContainer, xAOD::BPhysHelper::PV_MIN_A0, 0);
212  }
213 
214  if(doZ0) {
215  size_t lowZ = FindLowZIndex(vtx, GoodPVs, m_PV_minNTracks);
216  FillBPhysHelper(vtx, GoodPVs[lowZ], pvContainer, xAOD::BPhysHelper::PV_MIN_Z0, 0);
217  }
218 
219  if(doZ0BA) {
220  size_t lowZBA = FindLowZ0BAIndex(vtx, GoodPVs, m_PV_minNTracks);
221  if ( lowZBA < GoodPVs.size() ) { // safety against vector index out-of-bounds
222  FillBPhysHelper(vtx, GoodPVs[lowZBA], pvContainer, xAOD::BPhysHelper::PV_MIN_Z0_BA, 0);
223  } else {
224  // nothing found -- fill nullptr
225  FillBPhysHelperNULL(vtx, pvContainer, xAOD::BPhysHelper::PV_MIN_Z0_BA, m_3dCalc);
226  }
227  }
228 
229  }// end of loop over vertices
230  } //end of check for vertices
231  else {
232  // cout << "Warning: DerivationFramework::BPhysPVTools::FillCandExistingVertices No Primary Vertices Found trying to decorate wilth dummy \n";
233  if(pvContainer->empty()) return StatusCode::FAILURE;
234  const xAOD::Vertex* dummy = pvContainer->at(0); //No good vertices so last vertex must be dummy
235  DecorateWithDummyVertex(vtxContainer, pvContainer, dummy, DoVertexType, false);
236  }
237  return StatusCode::SUCCESS;
238 }
239 
240 
242  const xAOD::VertexContainer* pvContainer, xAOD::VertexContainer* refPvContainer,
243  const Analysis::PrimaryVertexRefitter *pvRefitter, size_t in_PV_max, int DoVertexType) {
244 
245 
246  //----------------------------------------------------
247  // decorate the vertex
248  //----------------------------------------------------
249  // loop over candidates -- Don't apply PV_minNTracks requirement here
250  // because it may result in exclusion of the high-pt PV.
251  std::vector<const xAOD::Vertex*> goodPrimaryVertices = GetGoodPV(pvContainer);
252 
253  /*
254  cout << "BPhysPVTools::FillCandwithRefittedVertices: #PVs: all: "
255  << pvContainer->size() << " ref: " << refPvContainer->size()
256  << " good: " << goodPrimaryVertices.size()
257  << " PV_minNTracks: " << m_PV_minNTracks << endl;
258  */
259  if(goodPrimaryVertices.empty() == false) {
260 
261  size_t pVmax =std::min(in_PV_max, goodPrimaryVertices.size());
262  std::vector<const xAOD::Vertex*> refPVvertexes;
263  std::vector<xAOD::Vertex*> refPVvertexes_toDelete;
264  std::vector<int> exitCode;
265  refPVvertexes.reserve(pVmax);
266  refPVvertexes_toDelete.reserve(pVmax);
267  exitCode.reserve(pVmax);
268 
269  bool doPt = (DoVertexType & 1) != 0;
270  bool doA0 = (DoVertexType & 2) != 0;
271  bool doZ0 = (DoVertexType & 4) != 0;
272  bool doZ0BA = (DoVertexType & 8) != 0;
273 
274  xAOD::VertexContainer::iterator vtxItr = vtxContainer->begin();
275  for(; vtxItr!=vtxContainer->end(); ++vtxItr) {
276  xAOD::BPhysHelper vtx(*vtxItr);
277 
278  // 1) pT error
279  double ptErr = m_v0Tools->pTError( vtx.vtx() );
280  BPHYS_CHECK( vtx.setPtErr(ptErr) );
281 
282  for(size_t i =0; i < pVmax ; i++) {
283  const xAOD::Vertex* oldPV = goodPrimaryVertices.at(i);
284  //when set to false this will return nullptr when a new vertex is not required
285  int exit =0;
286  xAOD::Vertex* refPV = pvRefitter->refitVertex(oldPV, vtx.vtx(), false, &exit);
287  exitCode.push_back(exit);
288  //I want positioning to match the goodPrimaryVertices
289  if(refPV == nullptr){
290  refPVvertexes.push_back(oldPV);
291  refPVvertexes_toDelete.push_back(nullptr);
292  }else{
293  refPVvertexes.push_back(refPV);
294  refPVvertexes_toDelete.push_back(refPV);
295  }
296  }
297 
298  // 2) refit the primary vertex and set the related decorations.
299 
300  size_t highPtindex = doPt ? FindHighPtIndex(refPVvertexes) : 9999999; //Should be 0 in PV ordering
301  size_t lowA0 = doA0 ?
302  FindLowA0Index(vtx, refPVvertexes, m_PV_minNTracks) : 9999998;
303  size_t lowZ = doZ0 ?
304  FindLowZIndex(vtx, refPVvertexes, m_PV_minNTracks) : 9999997;
305  size_t lowZBA = doZ0BA ?
306  FindLowZ0BAIndex(vtx, refPVvertexes, m_PV_minNTracks) : 9999996;
307  /*
308  cout << "BPhysPVTools::FillCandwithRefittedVertices: in_PV_max/pVMax = "
309  << in_PV_max << ", " << pVmax << endl;
310  cout << "BPhysPVTools::FillCandwithRefittedVertices: m_PV_minNTracks = "
311  << m_PV_minNTracks << endl;
312  cout << "BPhysPVTools::FillCandwithRefittedVertices: hPt,lowA0/Z/ZBA = "
313  << highPtindex << ", "
314  << lowA0 << ", " << lowZ << ", " << lowZBA << " "
315  << (lowA0 != lowZ ? "1!" : " ")
316  << (lowA0 != lowZBA ? "2!" : " ")
317  << (lowZ != lowZBA ? "3!" : " ")
318  << (highPtindex != lowA0 ? "4!" : " ")
319  << (highPtindex != lowZ ? "5!" : " ")
320  << (highPtindex != lowZBA ? "6!" : " ")
321  << endl;
322  */
323  if(doPt) {
324  //Choose old PV container if not refitted
325  const xAOD::VertexContainer* ParentContainer =
326  (refPVvertexes_toDelete.at(highPtindex)) ? refPvContainer : pvContainer;
327  if(ParentContainer == refPvContainer) //if refitted add to refitted container
328  refPvContainer->push_back(refPVvertexes_toDelete.at(highPtindex)); // store the new vertex
329 
330  FillBPhysHelper(vtx, refPVvertexes[highPtindex],
331  ParentContainer, xAOD::BPhysHelper::PV_MAX_SUM_PT2, exitCode[highPtindex]);
332  vtx.setOrigPv(goodPrimaryVertices[highPtindex], pvContainer, xAOD::BPhysHelper::PV_MAX_SUM_PT2);
333  }
334 
335  if(doA0) {
336  const xAOD::VertexContainer* ParentContainer =
337  (refPVvertexes_toDelete.at(lowA0)) ? refPvContainer : pvContainer;
338  if(ParentContainer == refPvContainer && highPtindex!=lowA0)
339  refPvContainer->push_back(refPVvertexes_toDelete.at(lowA0)); // store the new vertex
340 
341  FillBPhysHelper(vtx, refPVvertexes[lowA0],
342  ParentContainer, xAOD::BPhysHelper::PV_MIN_A0, exitCode[lowA0]);
343  vtx.setOrigPv(goodPrimaryVertices[lowA0], pvContainer, xAOD::BPhysHelper::PV_MIN_A0);
344  }
345 
346 
347  // 2.c) the closest in Z:
348  if(doZ0) {
349 
350  const xAOD::VertexContainer* ParentContainer =
351  (refPVvertexes_toDelete.at(lowZ)) ? refPvContainer : pvContainer;
352  if(ParentContainer == refPvContainer && highPtindex!=lowZ && lowZ!=lowA0)
353  refPvContainer->push_back(refPVvertexes_toDelete.at(lowZ)); // store the new vertex
354 
355  FillBPhysHelper(vtx, refPVvertexes[lowZ],
356  ParentContainer, xAOD::BPhysHelper::PV_MIN_Z0, exitCode[lowZ]);
357  vtx.setOrigPv(goodPrimaryVertices[lowZ], pvContainer, xAOD::BPhysHelper::PV_MIN_Z0);
358  }
359 
360  // 2.d) the closest in Z (DOCA w.r.t. beam axis):
361  if (doZ0BA) {
362  if ( lowZBA < pVmax ) { // safety for vector indices
363  const xAOD::VertexContainer* ParentContainer =
364  (refPVvertexes_toDelete.at(lowZBA)) ?
365  refPvContainer : pvContainer;
366  if (ParentContainer == refPvContainer && highPtindex!=lowZBA
367  && lowZBA!=lowA0 && lowZBA != lowZ) {
368  // store the new vertex
369  refPvContainer->push_back(refPVvertexes_toDelete.at(lowZBA));
370  }
371  FillBPhysHelper(vtx, refPVvertexes[lowZBA],
372  ParentContainer, xAOD::BPhysHelper::PV_MIN_Z0_BA,
373  exitCode[lowZBA]);
374  vtx.setOrigPv(goodPrimaryVertices[lowZBA], pvContainer,
376  } else {
377  // nothing found -- fill nullptr
378  FillBPhysHelperNULL(vtx, pvContainer, xAOD::BPhysHelper::PV_MIN_Z0_BA, m_3dCalc);
379  // nothing found -- fill dummy vertex (type-0 vertex)
380  // if(pvContainer->empty()) return StatusCode::FAILURE;
381  // const xAOD::Vertex* dummy = pvContainer->at(pvContainer->size()-1); //No good vertices so last vertex must be dummy
382  // FillBPhysHelper(vtx, dummy, pvContainer, xAOD::BPhysHelper::PV_MIN_Z0_BA, 0);
383  // vtx.setOrigPv(Dummy, pvContainer, xAOD::BPhysHelper::PV_MIN_Z0_BA);
384  }
385  }
386 
387  //nullptrify ptrs we want to keep so these won't get deleted
388  //"delete nullptr" is valid in C++ and does nothing so this is quicker than a lot of if statements
389  if(doPt) refPVvertexes_toDelete[highPtindex] = nullptr;
390  if(doA0) refPVvertexes_toDelete[lowA0] = nullptr;
391  if(doZ0) refPVvertexes_toDelete[lowZ] = nullptr;
392  if(doZ0BA && lowZBA < pVmax) refPVvertexes_toDelete[lowZBA] = nullptr;
393  //Loop over toDELETE container, anything that is used or was not refitted is nullptr
394  //This cleans up all extra vertices that were created and not used
395  for(const xAOD::Vertex* ptr : refPVvertexes_toDelete) {
396  delete ptr;
397  }
398  refPVvertexes.clear();// Clear lists of now dangling ptrs
399  refPVvertexes_toDelete.clear();
400  exitCode.clear();
401  } // end of loop over vertices
402 
403  } else {
404 // cout << "Warning: DerivationFramework::BPhysPVTools::FillCandwithRefittedVertices No Primary Vertices Found trying to decorate wilth dummy \n";
405  if(pvContainer->empty()) return StatusCode::FAILURE;
406  const xAOD::Vertex* dummy = pvContainer->at(0); //No good vertices so last vertex must be dummy
407  DecorateWithDummyVertex(vtxContainer, pvContainer, dummy, DoVertexType, true);
408  }
409 
410  return StatusCode::SUCCESS;
411 }
412 
413 size_t DerivationFramework::BPhysPVTools::FindHighPtIndex(const std::vector<const xAOD::Vertex*> &PVlist) const {
414  // it SHOULD be the first one in the collection but it shouldn't take long to do a quick check
415  for(size_t i =0; i<PVlist.size(); i++) {
416  if(PVlist[i]->vertexType() == xAOD::VxType::PriVtx) return i;
417  }
418  ATH_MSG_ERROR("High Pt Primary vertex not found - this should not happen");
419  return std::numeric_limits<std::size_t>::max(); //This should not happen
420 }
421 
423  const std::vector<const xAOD::Vertex*> &PVlist,
424  const size_t PV_minNTracks) const {
425  size_t lowA0 = 0;
426  if(PVlist.empty()) {
428  return lowA0;
429  }
430  size_t size = PVlist.size();
431  double lowA0calc = m_v0Tools->a0(Obj.vtx(), PVlist[0]);
432  for(size_t i =1; i<size; i++) {
433  if ( PVlist[i]->nTrackParticles() >= PV_minNTracks ) {
434  double a0 = m_v0Tools->a0(Obj.vtx(), PVlist[i]);
435  if(a0 < lowA0calc) {
436  lowA0calc = a0;
437  lowA0 =i;
438  }
439  }
440  }
441  return lowA0;
442 }
443 
444 vector<const xAOD::Vertex*> DerivationFramework::BPhysPVTools::GetGoodPV(const xAOD::VertexContainer* pvContainer) {
447  VertexType Pileupvtx = xAOD::VxType::PileUp;
448  std::vector<const xAOD::Vertex*> goodPrimaryVertices;
449  goodPrimaryVertices.reserve(pvContainer->size());
450 
451  for (auto ptr = pvContainer->begin(); ptr!= pvContainer->end(); ++ptr) {
452  VertexType thistype = (*ptr)->vertexType();
453  if ( thistype == Pileupvtx || thistype == Pvtx ) {
454  goodPrimaryVertices.push_back(*ptr);
455  } else {
456 // cout << "vertex type " << thistype << endl;
457  }
458  }
459  return goodPrimaryVertices;
460 }
461 //-----------------------------------------------------------------------------
462 // added by WW:
463 //
465 {
466 
467  m_PV_minNTracks = PV_minNTracks;
468 }
469 //-----------------------------------------------------------------------------
470 // added by WW:
471 //
473 
474  if(m_EvtData) return Amg::Vector3D(m_EvtData->beamPosX(), m_EvtData->beamPosY(), m_EvtData->beamPosZ());
475  else {
476  static const Amg::Vector3D defaultBS(-10000.,-10000.,-10000.);
477  return defaultBS;
478  }
479 }
480 //-----------------------------------------------------------------------------
481 // added by WW:
482 //
484  const std::vector<const xAOD::Vertex*> &PVlist,
485  const size_t PV_minNTracks) const {
486 
487  size_t ilowZ0BA = std::numeric_limits<std::size_t>::max();
488  double lowZ0BAcalc = std::numeric_limits<double>::max();
489  for (size_t i = 0; i<PVlist.size(); ++i) {
490  if ( PVlist[i]->nTrackParticles() >= PV_minNTracks ) {
491  double z0BA = m_v0Tools->a0(obj.vtx(), PVlist[i]);
492  if (z0BA < lowZ0BAcalc) {
493  lowZ0BAcalc = z0BA;
494  ilowZ0BA = i;
495  }
496  }
497  }
498  return ilowZ0BA;
499 }
500 //-----------------------------------------------------------------------------
501 // added by WW:
502 //
504 
505  Amg::Vector3D pv = vertex->position();
506  Amg::Vector3D xDOCA = DocaExtrapToBeamSpot(obj);
507  Amg::Vector3D vec = pv - xDOCA;
508  return vec.z();
509 }
510 //-----------------------------------------------------------------------------
511 // added by WW:
512 //
514 
515  Amg::Vector3D xDOCA(-99999., -99999., -99999.);
516  TVector3 totP(obj.totalP());
517  Amg::Vector3D pSV(totP.X(), totP.Y(), totP.Z());
518  Amg::Vector3D pT(pSV.x(), pSV.y(), 0.);
519  if ( pT.mag2() > 0 ) {
520  Amg::Vector3D xBS = GetBeamSpot();
521  Amg::Vector3D xSV = m_v0Tools->vtx(obj.vtx());
522  Amg::Vector3D xT(xSV.x()-xBS.x(), xSV.y()-xBS.y(), 0.);
523  xDOCA = xSV - pSV*pT.dot(xT)/pT.mag2();
524  } else {
525  ATH_MSG_WARNING("DocaExtrapToBeamSpot: pT == 0.");
526  }
527  return xDOCA;
528 }
529 
531  const xAOD::TrackParticleContainer* importedTrackCollection)
532 {
533  std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
534  const auto &trkprtl = theResult->trackParticleLinks();
535  for(unsigned int i=0; i< trkprtl.size(); i++)
536  {
537  ElementLink<DataVector<xAOD::TrackParticle> > mylink=trkprtl[i]; //makes a copy (non-const)
538  mylink.setStorableObject(*importedTrackCollection, true);
539  newLinkVector.push_back( mylink );
540  }
541  theResult->clearTracks();
542  theResult->setTrackParticleLinks( newLinkVector );
543 }
544 
545 
546 //-----------------------------------------------------------------------------
BPhysPVTools.h
DerivationFramework::BPhysPVTools::DocaExtrapToBeamSpot
Amg::Vector3D DocaExtrapToBeamSpot(xAOD::BPhysHelper &obj) const
Point of DOCA w.r.t.
Definition: BPhysPVTools.cxx:513
V0Tools.h
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
xAOD::BPhysHelper::setA0xyErr
float setA0xyErr(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
transverse impact parameter error
Definition: BPhysHelper.cxx:1056
xAOD::BPhysHelper
Definition: BPhysHelper.h:71
DerivationFramework::BPhysPVTools::DecorateWithDummyVertex
void DecorateWithDummyVertex(xAOD::VertexContainer *vtxContainer, const xAOD::VertexContainer *pvContainer, const xAOD::Vertex *Dummy, int DoVertexType, bool SetOrignal) const
Definition: BPhysPVTools.cxx:102
DerivationFramework::BPhysPVTools::FillCandwithRefittedVertices
StatusCode FillCandwithRefittedVertices(xAOD::VertexContainer *vtxContainer, const xAOD::VertexContainer *pvContainer, xAOD::VertexContainer *refPvContainer, const Analysis::PrimaryVertexRefitter *, size_t in_PV_max, int DoVertexType)
Definition: BPhysPVTools.cxx:241
xAOD::BPhysHelper::setRefitPVStatus
bool setRefitPVStatus(int code, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Set the exitCode of the refitter for vertex of type pv_type.
Definition: BPhysHelper.cxx:844
DerivationFramework::BPhysPVTools::GetGoodPV
static std::vector< const xAOD::Vertex * > GetGoodPV(const xAOD::VertexContainer *pvContainer)
Static method call with DerivationFramework::BPhysDerHelpers::GetGoodPV Returns a std::vector contain...
Definition: BPhysPVTools.cxx:444
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
xAOD::Vertex_v1::trackParticleLinks
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
DerivationFramework::BPhysPVTools::FillCandExistingVertices
StatusCode FillCandExistingVertices(xAOD::VertexContainer *vtxContainer, const xAOD::VertexContainer *pvContainer, int DoVertexType)
Definition: BPhysPVTools.cxx:173
xAOD::BPhysHelper::PV_MIN_Z0
@ PV_MIN_Z0
Definition: BPhysHelper.h:475
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
PrimaryVertexRefitter.h
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
DerivationFramework::BPhysPVTools::FillBPhysHelperNULL
void FillBPhysHelperNULL(xAOD::BPhysHelper &vtx, const xAOD::VertexContainer *PvContainer, xAOD::BPhysHelper::pv_type pvtype, bool do3d=false) const
Definition: BPhysPVTools.cxx:57
DerivationFramework::BPhysPVTools::FillBPhysHelper
void FillBPhysHelper(xAOD::BPhysHelper &vtx, const xAOD::Vertex *refPV, const xAOD::VertexContainer *refPvContainer, xAOD::BPhysHelper::pv_type pvtype, int) const
Fills the BPhysHelper object with the standard parameters.
Definition: BPhysPVTools.cxx:32
DerivationFramework::BPhysPVTools::FindLowZ0BAIndex
size_t FindLowZ0BAIndex(xAOD::BPhysHelper &obj, const std::vector< const xAOD::Vertex * > &PVlist, const size_t PV_minNTracks=0) const
Find the index for the PV with the lowest distance in z of the SV's DOCA point w.r....
Definition: BPhysPVTools.cxx:483
Analysis::PrimaryVertexRefitter::refitVertex
xAOD::Vertex * refitVertex(const xAOD::Vertex *vertex, const xAOD::Vertex *excludeVertex, bool ReturnCopy=true, int *exitcode=nullptr) const
Definition: PrimaryVertexRefitter.cxx:40
xAOD::BPhysHelper::setPtErr
bool setPtErr(const float val)
Set pT error.
Definition: BPhysHelper.cxx:436
xAOD::VxType::VertexType
VertexType
Vertex types.
Definition: TrackingPrimitives.h:569
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
DerivationFramework::BPhysPVTools::BPhysPVTools
BPhysPVTools(const Trk::V0Tools *v0Tools)
Definition: BPhysPVTools.cxx:18
DerivationFramework::BPhysPVTools::FindLowZIndex
size_t FindLowZIndex(const xAOD::BPhysHelper &Obj, const std::vector< const xAOD::Vertex * > &PVlist, const size_t PV_minNTracks=0) const
Returns the index integer of the vertex with the lowest Z in relation to the given vertex.
Definition: BPhysPVTools.cxx:80
BPHYS_CHECK
#define BPHYS_CHECK(EXP)
Useful CHECK macro.
Definition: BPhysHelper.h:738
xAOD::BPhysHelper::pv_type
pv_type
: Enum type of the PV
Definition: BPhysHelper.h:475
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Analysis::PrimaryVertexRefitter
Definition: PrimaryVertexRefitter.h:26
xAOD::BPhysHelper::setA0xy
float setA0xy(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
transverse impact parameter
Definition: BPhysHelper.cxx:1045
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::BPhysHelper::setZ0Err
float setZ0Err(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
longitudinal impact parameter error
Definition: BPhysHelper.cxx:1078
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
xAOD::Vertex_v1::setTrackParticleLinks
void setTrackParticleLinks(const TrackParticleLinks_t &trackParticles)
Set all track particle links at once.
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
xAOD::BPhysHelper::PV_MIN_A0
@ PV_MIN_A0
Definition: BPhysHelper.h:475
python.xAODType.dummy
dummy
Definition: xAODType.py:4
DerivationFramework::BPhysPVTools::PrepareVertexLinks
static void PrepareVertexLinks(xAOD::Vertex *theResult, const xAOD::TrackParticleContainer *importedTrackCollection)
Definition: BPhysPVTools.cxx:530
xAOD::BPhysHelper::setA0Err
float setA0Err(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
3D impact parameter error
Definition: BPhysHelper.cxx:1034
xAOD::Vertex_v1::clearTracks
void clearTracks()
Remove all tracks from the vertex.
Definition: Vertex_v1.cxx:331
DerivationFramework::BPhysPVTools::SetMinNTracksInPV
void SetMinNTracksInPV(size_t PV_minNTracks)
Set the minimum number of tracks required for primary vertices to be considered for primary vertex as...
Definition: BPhysPVTools.cxx:464
a0
double a0
Definition: globals.cxx:27
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
calibdata.exit
exit
Definition: calibdata.py:236
DerivationFramework::BPhysPVTools::DistInZtoDOCA
double DistInZtoDOCA(xAOD::BPhysHelper &obj, const xAOD::Vertex *vertex) const
Calculate the distance along z axis between the PV and SV's DOCA point w.r.t.
Definition: BPhysPVTools.cxx:503
xAOD::BPhysHelper::setLxy
bool setLxy(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Set the transverse decay distance and its error measured between the refitted primary vertex of type ...
Definition: BPhysHelper.cxx:888
DerivationFramework::BPhysPVTools::FindLowA0Index
size_t FindLowA0Index(const xAOD::BPhysHelper &Obj, const std::vector< const xAOD::Vertex * > &PVlist, const size_t PV_minNTracks=0) const
Returns the index integer of the vertex with the lowest A0 in relation to the given vertex.
Definition: BPhysPVTools.cxx:422
xAOD::BPhysHelper::setPv
bool setPv(const xAOD::Vertex *pv, const xAOD::VertexContainer *vertexContainer, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Set the refitted collision vertex of type pv_type.
Definition: BPhysHelper.cxx:831
xAOD::VxType::PileUp
@ PileUp
Pile-up vertex.
Definition: TrackingPrimitives.h:573
DerivationFramework::BPhysPVTools::GetBeamSpot
Amg::Vector3D GetBeamSpot() const
Get the current beamspot position either from cache or from BeamCondSvc.
Definition: BPhysPVTools.cxx:472
xAOD::BPhysHelper::vtx
const xAOD::Vertex * vtx() const
Getter method for the cached xAOD::Vertex.
Definition: BPhysHelper.h:108
xAOD::BPhysHelper::PV_MAX_SUM_PT2
@ PV_MAX_SUM_PT2
Definition: BPhysHelper.h:475
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::vertexType
vertexType
Definition: Vertex_v1.cxx:166
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
EventInfo.h
xAOD::BPhysHelper::setLxyErr
bool setLxyErr(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
its error
Definition: BPhysHelper.cxx:899
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
BPhysHelper.h
: B-physics xAOD helpers.
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::BPhysHelper::setOrigPv
bool setOrigPv(const xAOD::Vertex *pv, const xAOD::VertexContainer *vertexContainer, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Set the original collision vertex of type pv_type.
Definition: BPhysHelper.cxx:818
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
Trk::V0Tools
Definition: V0Tools.h:36
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.changerun.pv
pv
Definition: changerun.py:81
xAOD::BPhysHelper::setLxyzErr
bool setLxyzErr(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
its error
Definition: BPhysHelper.cxx:945
xAOD::BPhysHelper::setA0
float setA0(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
Set the 3D and transverse impact parameters and their error.
Definition: BPhysHelper.cxx:1023
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
xAOD::BPhysHelper::setZ0
float setZ0(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
longitudinal impact parameter
Definition: BPhysHelper.cxx:1067
python.PyAthena.obj
obj
Definition: PyAthena.py:132
DerivationFramework::BPhysPVTools::DecorateWithNULL
void DecorateWithNULL(xAOD::VertexContainer *vtxContainer, const xAOD::VertexContainer *pvContainer, int DoVertexType) const
Definition: BPhysPVTools.cxx:141
xAOD::BPhysHelper::setLxyz
bool setLxyz(const float val, const pv_type vertexType=BPhysHelper::PV_MIN_A0)
decay distance
Definition: BPhysHelper.cxx:934
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DerivationFramework::BPhysPVTools::FindHighPtIndex
size_t FindHighPtIndex(const std::vector< const xAOD::Vertex * > &PVlist) const
Definition: BPhysPVTools.cxx:413
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
xAOD::BPhysHelper::PV_MIN_Z0_BA
@ PV_MIN_Z0_BA
Definition: BPhysHelper.h:475
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.