23 #include "CLHEP/Vector/LorentzVector.h"
44 declareInterface<IMSVVariablesFactory>(
this);
48 ATH_MSG_DEBUG(
" Initialization of MSVVariablesFactory succesfull");
49 return StatusCode::SUCCESS;
53 ATH_MSG_DEBUG(
" Finalization of MSVVariablesFactory succesfull");
54 return StatusCode::SUCCESS;
64 std::vector< ElementLink< xAOD::VertexContainer > > MSVVertexLinks;
65 const std::vector<xAOD::Vertex*> myVertices = myVertexInfoVKal->
vertices();
66 if(myVertices.empty()){
67 ATH_MSG_DEBUG(
"#BTAG# no MSV vertices...fill default values only... ");
77 return StatusCode::SUCCESS;
82 for (
const auto& vertex : myVertexInfoVKal->
vertices()){
89 const std::vector<ElementLink<xAOD::TrackParticleContainer> > myTrackLinks = vertex->trackParticleLinks();
90 if (myTrackLinks.empty()) {
91 ATH_MSG_WARNING(
"#BTAG# No Track Links attached to the track at the sec vertex... ");
94 const std::vector<Trk::VxTrackAtVertex> myTracks=vertex->vxTrackAtVertex();
95 if (!myTracks.empty()) {
96 npsec=myTracks.size();
97 for (
const auto& track : myTracks) {
100 sumpx += perigee->momentum().x();
101 sumpy += perigee->momentum().y();
102 sumpz += perigee->momentum().z();
103 sume += std::hypot(perigee->momentum().mag(), 139.5702);
110 CLHEP::HepLorentzVector vtxp4(sumpx,sumpy,sumpz,sume);
111 float efrac = (jetenergy>0) ? vtxp4.e()/jetenergy : 0;
120 double localdistnrm = 0;
121 std::vector<const xAOD::Vertex*> vecVtxHolder;
122 vecVtxHolder.push_back(vertex);
125 ATH_MSG_DEBUG(
"Factory PVX x = " << priVtx->
x() <<
" y = " << priVtx->
y() <<
" z = " << priVtx->
z());
128 ATH_MSG_WARNING(
"#BTAG# Tagging requested, but no primary vertex supplied.");
132 vertex->setTrackParticleLinks(myTrackLinks);
136 return StatusCode::SUCCESS;
147 float jetenergy = 0.;
151 std::vector< ElementLink< xAOD::VertexContainer > > MSVVertexLinks;
152 const std::vector<xAOD::Vertex*> myVertices = myVertexInfoVKal->
vertices();
153 if(myVertices.empty()){
154 ATH_MSG_DEBUG(
"#BTAG# no MSV vertices...fill default values only... ");
156 BTag->setVariable<
float>(
basename,
"energyTrkInJet", jetenergy);
158 BTag->setVariable<
float>(
basename,
"normdist", distnrm);
159 BTag->setVariable<std::vector<ElementLink<xAOD::VertexContainer> > >(
basename,
"vertices", MSVVertexLinks);
170 return StatusCode::SUCCESS;
176 BTag->setVariable<
float>(
basename,
"energyTrkInJet", jetenergy);
178 std::vector<const xAOD::Vertex*> vecVertices;
179 for (
const auto& vertex : myVertexInfoVKal->
vertices()) {
182 vecVertices.push_back(vertex);
187 const std::vector<ElementLink<xAOD::TrackParticleContainer> > myTrackLinks = vertex->trackParticleLinks();
188 if (myTrackLinks.empty()) {
189 ATH_MSG_WARNING(
"#BTAG# No Track Links attached to the track at the sec vertex... ");
192 const std::vector<Trk::VxTrackAtVertex> myTracks=vertex->vxTrackAtVertex();
193 if (!myTracks.empty()) {
194 npsec=myTracks.size();
195 for (
const auto& track : myTracks) {
198 sumpx += perigee->momentum().x();
199 sumpy += perigee->momentum().y();
200 sumpz += perigee->momentum().z();
201 sume += std::hypot(perigee->momentum().mag(), 139.5702);
208 CLHEP::HepLorentzVector vtxp4(sumpx,sumpy,sumpz,sume);
209 float efrac = (jetenergy>0) ? vtxp4.e()/jetenergy : 0;
218 double localdistnrm = 0;
219 std::vector<const xAOD::Vertex*> vecVtxHolder;
220 vecVtxHolder.push_back(vertex);
224 ATH_MSG_DEBUG(
"Factory PVX x = " << priVtx->
x() <<
" y = " << priVtx->
y() <<
" z = " << priVtx->
z());
227 ATH_MSG_WARNING(
"#BTAG# Tagging requested, but no primary vertex supplied.");
231 vertex->setTrackParticleLinks(myTrackLinks);
235 MSVVertexLinks.push_back(linkBTagVertex);
238 BTag->setVariable<std::vector<ElementLink<xAOD::VertexContainer> > >(
basename,
"vertices", MSVVertexLinks);
244 ATH_MSG_WARNING(
"#BTAG# Tagging requested, but no primary vertex supplied.");
247 nvsec = vecVertices.size();
249 BTag->setVariable<
float>(
basename,
"normdist", distnrm);
251 return StatusCode::SUCCESS;
257 std::vector<const xAOD::Vertex*>& secVertex,
260 if(!secVertex.size())
return 0;
261 std::vector<Amg::Vector3D> positions;
265 sumWeights.setZero();
267 for (
const auto& vertex : secVertex) {
268 positions.push_back(vertex->position());
269 weightMatrices.push_back(vertex->covariancePosition().inverse());
270 weightTimesPosition += weightMatrices.back() * positions.back();
271 sumWeights += weightMatrices.back();
276 meanCovariance.setZero();
277 sumWeights.computeInverseWithCheck(meanCovariance, invertible);
282 Amg::Vector3D meanPosition = meanCovariance * weightTimesPosition;
283 AmgSymMatrix(3) covariance = meanCovariance + priVertex->covariancePosition();
285 double Lx = meanPosition[0]-priVertex->
position().x();
286 double Ly = meanPosition[1]-priVertex->
position().y();
287 double Lz = meanPosition[2]-priVertex->
position().z();
289 const double decaylength = sqrt(Lx*Lx + Ly*Ly + Lz*Lz);
290 const double inv_decaylength = 1. / decaylength;
291 double dLdLx = Lx * inv_decaylength;
292 double dLdLy = Ly * inv_decaylength;
293 double dLdLz = Lz * inv_decaylength;
294 double decaylength_err = sqrt(dLdLx*dLdLx*covariance(0,0) +
295 dLdLy*dLdLy*covariance(1,1) +
296 dLdLz*dLdLz*covariance(2,2) +
297 2.*dLdLx*dLdLy*covariance(0,1) +
298 2.*dLdLx*dLdLz*covariance(0,2) +
299 2.*dLdLy*dLdLz*covariance(1,2));
301 double decaylength_significance = 0.;
302 if (decaylength_err != 0.) decaylength_significance = decaylength/decaylength_err;
303 double L_proj_jetDir = jetDirection.x()*Lx + jetDirection.y()*Ly + jetDirection.z()*Lz;
304 if (L_proj_jetDir < 0.) decaylength_significance *= -1.;
306 return decaylength_significance;