ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFramework::HITrackParticleThinningTool Class Reference

#include <HITrackParticleThinningTool.h>

Inheritance diagram for DerivationFramework::HITrackParticleThinningTool:
Collaboration diagram for DerivationFramework::HITrackParticleThinningTool:

Public Member Functions

 HITrackParticleThinningTool (const std::string &t, const std::string &n, const IInterface *p)
 ~HITrackParticleThinningTool ()
StatusCode initialize () override
StatusCode finalize () override
virtual StatusCode doThinning () const override

Private Attributes

StringProperty m_streamName { this, "StreamName", "", "Name of the stream being thinned" }
SG::ThinningHandleKey< xAOD::TrackParticleContainerm_inDetSGKey { this, "InDetTrackParticlesKey", "InDetTrackParticles", "" }
std::string m_vertex_key
std::string m_vertex_scheme
ToolHandle< InDet::IInDetTrackSelectionToolm_trkSelTool
 track selection tool which can be optionally used for N_trk and sum pt cuts
std::atomic< unsigned int > m_ntot
std::atomic< unsigned int > m_npass

Detailed Description

Definition at line 32 of file HITrackParticleThinningTool.h.

Constructor & Destructor Documentation

◆ HITrackParticleThinningTool()

DerivationFramework::HITrackParticleThinningTool::HITrackParticleThinningTool ( const std::string & t,
const std::string & n,
const IInterface * p )

Definition at line 23 of file HITrackParticleThinningTool.cxx.

25 :
26
27 base_class(t,n,p),
28 m_ntot(0),
29 m_npass(0)
30 {
31 //declareProperty("InDetTrackParticlesKey", m_TP_key="InDetTrackParticles");
32 declareProperty("PrimaryVertexKey", m_vertex_key="PrimaryVertices");
33 declareProperty("PrimaryVertexSelection", m_vertex_scheme="SumPt2");
34 declareProperty("TrackSelectionTool", m_trkSelTool, "Track selection tool" );
35 }
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool
track selection tool which can be optionally used for N_trk and sum pt cuts

◆ ~HITrackParticleThinningTool()

DerivationFramework::HITrackParticleThinningTool::~HITrackParticleThinningTool ( )

Definition at line 38 of file HITrackParticleThinningTool.cxx.

38 {
39 }

Member Function Documentation

◆ doThinning()

StatusCode DerivationFramework::HITrackParticleThinningTool::doThinning ( ) const
overridevirtual

Definition at line 66 of file HITrackParticleThinningTool.cxx.

67 {
68 // Get the current event context
69 const EventContext& ctx = Gaudi::Hive::currentContext();
70
71 // Get the track container
72 SG::ThinningHandle<xAOD::TrackParticleContainer> tracks (m_inDetSGKey, ctx);
73
74 m_ntot+=tracks->size();
75
76 //Define a primary vertex
77 const xAOD::Vertex *primary_vertex(nullptr);
78
79 // Retrieve vertex container
80 const xAOD::VertexContainer* vtxC(nullptr);
81 if (evtStore()->retrieve(vtxC, m_vertex_key).isFailure()) {
82 ATH_MSG_ERROR("Failed to retrieve VertexContainer with key: " << m_vertex_key);
83 return StatusCode::FAILURE;
84 }
85
86 // Variables to track the best vertex based on the scheme
87 float ptmax = 0.;
88 size_t ntrkmax = 0;
89
90 // Iterate through the vertices to find the primary vertex
91 for (auto vertex : *vtxC) {
92 if (!vertex || vertex->vertexType() != xAOD::VxType::PriVtx) {
93 continue;
94 }
95
96 if (m_vertex_scheme.compare("sumPt2") == 0) {
97 // Define the accessor for the sumPt2 variable
98 SG::ConstAccessor<float> sumPt2Acc("sumPt2");
99
100 // Check if the sumPt2 variable is available for the vertex
101 if (sumPt2Acc.isAvailable(*vertex)) {
102 float sumPT = sumPt2Acc(*vertex); // Access the sumPt2 variable
103 if (sumPT > ptmax) {
104 ptmax = sumPT;
105 primary_vertex = vertex;
106 }
107 }
108 } else {
109 size_t ntp = vertex->nTrackParticles();
110 if (ntp > ntrkmax) {
111 ntrkmax = ntp;
112 primary_vertex = vertex;
113 }
114 }
115 }
116
117 // Warn if not primary vertex is found
118 if (!primary_vertex) {
119 ATH_MSG_DEBUG("No primary vertex found.");
120 }
121
122 // Loop over tracks, see if they pass, set mask
123 std::vector<bool> mask;
124 mask.reserve(tracks->size());
125
126 for (auto tp : *tracks) {
127 if (tp) {
128 const xAOD::Vertex* vert_trk = primary_vertex;
129
130 asg::AcceptData acceptData = m_trkSelTool->accept(*tp, vert_trk);
131 mask.push_back(static_cast<bool>(acceptData));
132 } else {
133 mask.push_back(false);
134 }
135 }
136
137 tracks.keep (mask);
138
139 return StatusCode::SUCCESS;
140 }
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
double ptmax
retrieve(aClass, aKey=None)
Definition PyKernel.py:110
@ PriVtx
Primary vertex.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.

◆ finalize()

StatusCode DerivationFramework::HITrackParticleThinningTool::finalize ( )
override

Definition at line 59 of file HITrackParticleThinningTool.cxx.

60 {
61 ATH_CHECK(m_trkSelTool->finalize());
62 return StatusCode::SUCCESS;
63 }
#define ATH_CHECK
Evaluate an expression and check for errors.

◆ initialize()

StatusCode DerivationFramework::HITrackParticleThinningTool::initialize ( )
override

Definition at line 42 of file HITrackParticleThinningTool.cxx.

42 {
43 if(!m_trkSelTool)
44 {
45 ATH_MSG_ERROR("InDetTrackSelectionTool not set. Cannot initialize.");
46 return StatusCode::FAILURE;
47 }
48
49 // Validate m_vertex_scheme
50 if (m_vertex_scheme != "sumPt2" && m_vertex_scheme != "nTracks") {
51 ATH_MSG_ERROR("Invalid PrimaryVertexSelection: " << m_vertex_scheme);
52 return StatusCode::FAILURE;
53 }
54
55 ATH_CHECK( m_inDetSGKey.initialize(m_streamName) );
56 return StatusCode::SUCCESS;
57 }

Member Data Documentation

◆ m_inDetSGKey

SG::ThinningHandleKey<xAOD::TrackParticleContainer> DerivationFramework::HITrackParticleThinningTool::m_inDetSGKey { this, "InDetTrackParticlesKey", "InDetTrackParticles", "" }
private

Definition at line 51 of file HITrackParticleThinningTool.h.

52{ this, "InDetTrackParticlesKey", "InDetTrackParticles", "" };

◆ m_npass

std::atomic<unsigned int> DerivationFramework::HITrackParticleThinningTool::m_npass
mutableprivate

Definition at line 59 of file HITrackParticleThinningTool.h.

◆ m_ntot

std::atomic<unsigned int> DerivationFramework::HITrackParticleThinningTool::m_ntot
mutableprivate

Definition at line 58 of file HITrackParticleThinningTool.h.

◆ m_streamName

StringProperty DerivationFramework::HITrackParticleThinningTool::m_streamName { this, "StreamName", "", "Name of the stream being thinned" }
private

Definition at line 49 of file HITrackParticleThinningTool.h.

50{ this, "StreamName", "", "Name of the stream being thinned" };

◆ m_trkSelTool

ToolHandle< InDet::IInDetTrackSelectionTool > DerivationFramework::HITrackParticleThinningTool::m_trkSelTool
private

track selection tool which can be optionally used for N_trk and sum pt cuts

Definition at line 56 of file HITrackParticleThinningTool.h.

◆ m_vertex_key

std::string DerivationFramework::HITrackParticleThinningTool::m_vertex_key
private

Definition at line 54 of file HITrackParticleThinningTool.h.

◆ m_vertex_scheme

std::string DerivationFramework::HITrackParticleThinningTool::m_vertex_scheme
private

Definition at line 55 of file HITrackParticleThinningTool.h.


The documentation for this class was generated from the following files: