20 ATH_MSG_INFO(
"Initializing JetVertexFractionTool " << name());
24 ATH_MSG_ERROR(
"JetVertexFractionTool needs to have its input jet container name configured!");
25 return StatusCode::FAILURE;
41#ifndef XAOD_STANDALONE
58 return StatusCode::SUCCESS;
65 if (!vertexContainer.isValid()){
68 return StatusCode::FAILURE;
70 const auto *vertices = vertexContainer.cptr();
77 if (!tracksContainer.isValid()){
78 ATH_MSG_ERROR(
"Could not retrieve the TrackParticleContainer: "
80 return StatusCode::FAILURE;
82 const auto *tracksCont = tracksContainer.cptr();
84 ATH_MSG_DEBUG(
"Successfully retrieved TrackParticleContainer: "
89 if (!tvaContainer.isValid()){
90 ATH_MSG_ERROR(
"Could not retrieve the TrackVertexAssociation: "
92 return StatusCode::FAILURE;
94 const auto *tva = tvaContainer.cptr();
96 ATH_MSG_DEBUG(
"Successfully retrieved TrackVertexAssociation: "
99 if (vertices->empty() ) {
101 return StatusCode::SUCCESS;
119 std::unique_ptr<SG::WriteDecorHandle<xAOD::JetContainer, ElementLink<xAOD::VertexContainer> > > maxJvfVtxHandle;
121 maxJvfVtxHandle = std::make_unique<SG::WriteDecorHandle<xAOD::JetContainer, ElementLink<xAOD::VertexContainer> > >(
m_maxJvfVtxKey);
130 ATH_MSG_ERROR(
"OriginVertex was requested, but the jet does not contain an OriginVertex");
131 return StatusCode::FAILURE;
134 ATH_MSG_VERBOSE(
"JetVertexFractionTool " << name() <<
" is using OriginVertex at index: " << HSvertex->
index());
140 std::vector<const xAOD::TrackParticle*> tracks;
148 std::vector<float> vsumpttrk = sumPtTrkHandle(*
jet);
149 float sumpttrk_all = tracksums.first;
150 float sumpttrk_nonPV = tracksums.second;
151 float sumpttrk_PV = vsumpttrk[HSvertex->
index() - (*vertices)[0]->index()];
154 std::vector<float> jvf(vertices->size());
155 for(
size_t vtxi=0; vtxi<vertices->size(); ++vtxi) {
156 jvf[vtxi] = sumpttrk_all > 1e-9 ? vsumpttrk[vtxi] / sumpttrk_all : -1;
158 jvfHandle(*
jet) = jvf;
166 float jvfcorr = -999.;
167 if(sumpttrk_PV + sumpttrk_nonPV > 0) {
168 jvfcorr = sumpttrk_PV / (sumpttrk_PV + ( sumpttrk_nonPV / (
m_kcorrJVF * std::max(n_putracks_local, 1) ) ) );
172 jvfCorrHandle(*
jet) = jvfcorr;
176 std::vector<float> jvfCorrVtx;
178 auto jvfCorrVtxHandle = std::make_unique<SG::WriteDecorHandle<xAOD::JetContainer, std::vector<float> > >(
m_jvfCorrVtxHandleKey);
182 std::vector<float> vsumpttrk = sumPtTrkHandle(*
jet);
191 std::vector<const xAOD::TrackParticle*> tracks;
202 float sumpttrk_PV = vsumpttrk[pv->index()];
203 float sumpttrk_nonPV = tracksums.second;
204 float jvfcorr = -999.;
205 float kcorrJVF = 0.01;
206 if(sumpttrk_PV + sumpttrk_nonPV > 0) {
207 jvfcorr = sumpttrk_PV / (sumpttrk_PV + ( sumpttrk_nonPV / (kcorrJVF * std::max(n_putracks, 1) ) ) );
211 jvfCorrVtx.push_back(jvfcorr);
214 (*jvfCorrVtxHandle)(*jet) = jvfCorrVtx;
219 return StatusCode::SUCCESS;
226 const std::vector<float>& jvf)
const {
229 for (
size_t iVertex = 0; iVertex < jvf.size(); ++iVertex ) {
230 if ( jvf.at(iVertex) > maxVal ) {
232 maxVal = jvf.at(iVertex);
243 const std::vector<const xAOD::TrackParticle*>& tracks,
245 float sumTrackAll = 0;
246 float sumTracknotPV = 0;
248 unsigned int nkeep = 0;
249 unsigned int nskip = 0;
250 for (
size_t iTrack = 0; iTrack < tracks.size(); ++iTrack) {
252 if ( notsel ||
m_htsel->accept(*track) ) {
253 sumTrackAll += track->pt();
256 if( ptvtx !=
nullptr ) {
258 if ( ptvtx->
index() != vertex->index() ) {sumTracknotPV += track->pt(); }
265 <<
": nsel=" << nkeep
266 <<
", nrej=" << nskip );
268 return std::make_pair(sumTrackAll,sumTracknotPV);
279 int n_pileuptrackcount = 0;
281 unsigned int nkeep = 0;
282 unsigned int nskip = 0;
284 for(
size_t iTrack = 0; iTrack < tracksCont->
size(); ++iTrack)
287 if ( notsel ||
m_htsel->accept(*track) ) {
291 if ( ptvtx !=
nullptr ) {
292 if ( (ptvtx->
index() != vertex->index() ) && (track->pt() <
m_PUtrkptcut) ) ++n_pileuptrackcount;
299 const int n_pileuptracks = n_pileuptrackcount;
302 <<
": nsel=" << nkeep
303 <<
", nrej=" << nskip
304 <<
", total " << tracksCont->
size() );
306 <<
": n_PUtracks=" << n_pileuptracks
307 <<
", total=" << tot_count );
309 return n_pileuptracks;
320 ATH_MSG_VERBOSE(
"JetVertexFractionTool " << name() <<
" Found HS vertex.");
324 if (primvert ==
nullptr ) {
325 ATH_MSG_VERBOSE(
"There is no vertex of type PriVx. Taking default vertex.");
326 primvert = *(vertices->
begin());
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
const T * at(size_type n) const
Access an element, as an rvalue.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
ElementLink implementation for ROOT usage.
size_t index() const
Return the index of this element within its container.
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
Class to hold N-to-one aassociations between tracks and vertices.
const xAOD::Vertex * associatedVertex(const xAOD::TrackParticle *trk) const
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Jet_v1 Jet
Definition of the current "jet version".
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".