23 return StatusCode::SUCCESS;
28 const EventContext& ctx)
const
36 const EventContext& ctx,
43 if (!vertexInHandle.
isValid()) {
44 ATH_MSG_ERROR (
"Could not retrieve HiveDataObj with key " << vertexInHandle.
key());
45 return StatusCode::FAILURE;
47 vxContainer = vertexInHandle.
cptr();
50 if (vertexContainer !=
nullptr) {
51 vxContainer = vertexContainer;
55 return StatusCode::FAILURE;
60 if (vxContainer->
empty())
return StatusCode::SUCCESS;
65 primaryVertex = (*vxContainer)[0];
68 for (
const auto* vertex : *vxContainer) {
70 primaryVertex = vertex;
77 if (primaryVertex) pTau.
setVertex(vxContainer, primaryVertex);
80 if (!
m_useTJVA)
return StatusCode::SUCCESS;
85 return StatusCode::FAILURE;
89 ATH_MSG_DEBUG(
"TJVA enabled -> try to find new PV for the tau candidate");
93 if (newPrimaryVertexLink.
isValid()) {
105 return StatusCode::SUCCESS;
115 std::vector<const xAOD::TrackParticle*> tracksForTJVA;
119 std::vector<const xAOD::TrackParticle*> assocTracks;
128 float sumTrackAll = 0.0;
129 for (
auto xTrack : assocTracks ) {
132 tracksForTJVA.push_back(xTrack);
137 ATH_MSG_WARNING(
"Original ERM track link is not available, skipping track");
140 auto original_id_track_link = acc_originalTrack(*xTrack);
141 if (!original_id_track_link.isValid()) {
142 ATH_MSG_WARNING(
"Original ERM track link is not valid, skipping track");
145 tracksForTJVA.push_back(*original_id_track_link);
147 sumTrackAll += xTrack->pt();
151 if (this->msgLevel() <= MSG::DEBUG){
152 ATH_MSG_DEBUG(
"tracksForTJVA # = " << tracksForTJVA.size() <<
", sum pT = " << sumTrackAll);
154 for (
uint i = 0; i < tracksForTJVA.size(); i++){
155 ATH_MSG_DEBUG(
"tracksForTJVA[" << i <<
"].pt = " << tracksForTJVA[i]->pt());
162 std::vector<const xAOD::Vertex*> vertVec;
164 vertVec.push_back(vert);
167 if (this->msgLevel() <= MSG::DEBUG){
169 for (
uint i = 0; i < vertVec.size(); i++){
177 if (this->msgLevel() <= MSG::DEBUG){
178 for (
const auto& [vtx, trks] : trktovxmap){
179 std::stringstream
ss;
180 for (
auto ass_trk : trks){
181 for (
uint i=0; i < tracksForTJVA.size(); i++){
182 if (ass_trk->p4() == tracksForTJVA[i]->p4()) {
188 ATH_MSG_DEBUG(
"Vtx[" << vtx->index() <<
"] associated with trks [" <<
ss.str() <<
"]");
196 std::vector<float> sumDz;
197 std::vector<float> v_jvf;
201 std::vector<const xAOD::TrackParticle*> tracks = trktovxmap[vert];
204 jvf = (sumTrackAll!=0. ? spair.first/sumTrackAll : 0.);
205 v_jvf.push_back(jvf);
206 sumDz.push_back(spair.second);
210 maxIndex = vert->index();
215 ATH_MSG_DEBUG(
"TJVA vtx found at z: " << vertices.
at(maxIndex)->
z() <<
" i_vtx = " << maxIndex <<
"jvf = " << maxJVF);
218 float min_sumDz = 99999999.;
220 ATH_MSG_DEBUG(
"i_vtx=" << vert->index() <<
", z=" << vert->z() <<
", JVF=" << v_jvf[vert->index()] <<
", sumDz=" << sumDz[vert->index()]);
221 if ( v_jvf[vert->index()] == maxJVF ){
223 if (sumDz[vert->index()] < min_sumDz){
224 min_sumDz = sumDz[vert->index()];
225 maxIndex = vert->index();
232 ATH_MSG_DEBUG(
"TJVA vtx found at z: " << vertices.
at(maxIndex)->
z() <<
" i_vtx = " << maxIndex);
241 float sumTrackPV = 0.;
242 float sumDeltaZ = 0.;
243 for (
const auto* trk : tracks){
244 sumTrackPV += trk->pt();
245 sumDeltaZ += std::abs(trk->z0() - vx_z + trk->vz());
248 return std::make_pair(sumTrackPV, sumDeltaZ);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
ElementLink implementation for ROOT usage.
bool isValid() const
Check if the element can be found.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
ElementLink< xAOD::VertexContainer > getPV_TJVA(const xAOD::TauJet &tauJet, const xAOD::VertexContainer &vertices, float &maxJVF) const
TauVertexFinder(const std::string &name)
Constructor and Destructor.
StatusCode executeTool(xAOD::TauJet &pTau, const EventContext &ctx) const override
Execute - called for each tau candidate.
StatusCode initialize() override
Tool functions.
std::pair< float, float > getVertexScores(const std::vector< const xAOD::TrackParticle * > &tracks, float vx_z) const
ToolHandle< CP::ITrackVertexAssociationTool > m_trkVertexAssocTool
Gaudi::Property< std::string > m_assocTracksName
Gaudi::Property< double > m_dDeltaRMax
Gaudi::Property< bool > m_useTJVA
ToolHandle< InDet::IInDetTrackSelectionTool > m_TrackSelectionToolForTJVA
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexInputContainer
virtual FourMom_t p4() const
The full 4-momentum of the particle.
std::vector< const T * > getAssociatedObjects(const std::string &name) const
get associated objects as a vector<object> this compact form throws an exception if the object is not...
void setVertexLink(const VertexLink_t &vertexLink)
void setDetail(TauJetParameters::Detail detail, int value)
void setVertex(const xAOD::VertexContainer *cont, const xAOD::Vertex *vertex)
float z() const
Returns the z position.
@ TauJetVtxFraction
@Tau Jet Vertex Fraction
Jet_v1 Jet
Definition of the current "jet version".
std::map< const xAOD::Vertex *, xAOD::TrackVertexAssociationList > TrackVertexAssociationMap
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TauJet_v3 TauJet
Definition of the current "tau version".