Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VtxTools.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VtxTools.h
1 // ----------------------------------------------------------------------------
2 // 'VtxTools.h'
3 // Derek Anderson
4 // 12.30.2023
5 //
6 // Collection of frequent vertex-related methods utilized
7 // in the sPHENIX Cold QCD Energy-Energy Correlator analysis.
8 // ----------------------------------------------------------------------------
9 
10 #pragma once
11 
12 // c++ utilities
13 #include <array>
14 #include <cassert>
15 #include <utility>
16 #include <optional>
17 // root libraries
18 #include <Math/Vector3D.h>
19 // phool libraries
20 #include <phool/phool.h>
21 #include <phool/getClass.h>
22 #include <phool/PHIODataNode.h>
23 #include <phool/PHNodeIterator.h>
24 #include <phool/PHCompositeNode.h>
25 // vertex libraries
28 
29 // make common namespaces implicit
30 using namespace std;
31 using namespace findNode;
32 
33 
34 
35 namespace SColdQcdCorrelatorAnalysis {
36  namespace SCorrelatorUtilities {
37 
38  // event methods ----------------------------------------------------------
39 
41 
42  // get vertex map
43  GlobalVertexMap* mapVtx = getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
44 
45  // check if good
46  const bool isVtxMapGood = (mapVtx && !(mapVtx -> empty()));
47  if (!isVtxMapGood) {
48  cerr << PHWHERE
49  << "PANIC: GlobalVertexMap node is missing or empty!\n"
50  << " Please turn on the do_global flag in the main macro in order to reconstruct the global vertex!"
51  << endl;
52  assert(isVtxMapGood);
53  }
54  return mapVtx;
55 
56  } // end 'GetVertexMap(PHCompositeNode*)'
57 
58 
59 
60  GlobalVertex* GetGlobalVertex(PHCompositeNode* topNode, optional<int> iVtxToGrab = nullopt) {
61 
62  // get vertex map
63  GlobalVertexMap* mapVtx = GetVertexMap(topNode);
64 
65  // get specified vertex
66  GlobalVertex* vtx = NULL;
67  if (iVtxToGrab.has_value()) {
68  vtx = mapVtx -> get(iVtxToGrab.value());
69  } else {
70  vtx = mapVtx -> begin() -> second;
71  }
72 
73  // check if good
74  if (!vtx) {
75  cerr << PHWHERE
76  << "PANIC: no vertex!"
77  << endl;
78  assert(vtx);
79  }
80  return vtx;
81 
82  } // end 'GetGlobalVertex(PHCompositeNode*, optional<int>)'
83 
84 
85 
86  ROOT::Math::XYZVector GetRecoVtx(PHCompositeNode* topNode) {
87 
88  const GlobalVertex* vtx = GetGlobalVertex(topNode);
89  return ROOT::Math::XYZVector(vtx -> get_x(), vtx -> get_y(), vtx -> get_z());
90 
91  } // end 'GetRecoVtx(PHCompositeNode*)'
92 
93  } // end SCorrelatorUtilities namespace
94 } // end SColdQcdCorrealtorAnalysis namespace
95 
96 // end ------------------------------------------------------------------------
97