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;
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);
124 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;
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);
222 ATH_MSG_DEBUG(
"Factory PVX x = " << priVtx->
x() <<
" y = " << priVtx->
y() <<
" z = " << priVtx->
z());
226 ATH_MSG_WARNING(
"#BTAG# Tagging requested, but no primary vertex supplied.");
230 vertex->setTrackParticleLinks(myTrackLinks);
234 MSVVertexLinks.push_back(linkBTagVertex);
237 BTag->setVariable<std::vector<ElementLink<xAOD::VertexContainer> > >(
basename,
"vertices", MSVVertexLinks);
243 ATH_MSG_WARNING(
"#BTAG# Tagging requested, but no primary vertex supplied.");
246 nvsec = vecVertices.size();
248 BTag->setVariable<
float>(
basename,
"normdist", distnrm);
250 return StatusCode::SUCCESS;
256 std::vector<const xAOD::Vertex*>& secVertex,
259 if(!secVertex.size())
return 0;
260 std::vector<Amg::Vector3D> positions;
264 sumWeights.setZero();
266 for (
const auto&
vertex : secVertex) {
267 positions.push_back(
vertex->position());
268 weightMatrices.push_back(
vertex->covariancePosition().inverse());
269 weightTimesPosition += weightMatrices.back() * positions.back();
270 sumWeights += weightMatrices.back();
275 meanCovariance.setZero();
276 sumWeights.computeInverseWithCheck(meanCovariance, invertible);
281 Amg::Vector3D meanPosition = meanCovariance * weightTimesPosition;
282 AmgSymMatrix(3) covariance = meanCovariance + priVertex->covariancePosition();
284 double Lx = meanPosition[0]-priVertex->
position().x();
285 double Ly = meanPosition[1]-priVertex->
position().y();
286 double Lz = meanPosition[2]-priVertex->
position().z();
288 const double decaylength = sqrt(Lx*Lx + Ly*Ly + Lz*Lz);
289 const double inv_decaylength = 1. / decaylength;
290 double dLdLx = Lx * inv_decaylength;
291 double dLdLy = Ly * inv_decaylength;
292 double dLdLz = Lz * inv_decaylength;
293 double decaylength_err = sqrt(dLdLx*dLdLx*covariance(0,0) +
294 dLdLy*dLdLy*covariance(1,1) +
295 dLdLz*dLdLz*covariance(2,2) +
296 2.*dLdLx*dLdLy*covariance(0,1) +
297 2.*dLdLx*dLdLz*covariance(0,2) +
298 2.*dLdLy*dLdLz*covariance(1,2));
300 double decaylength_significance = 0.;
301 if (decaylength_err != 0.) decaylength_significance = decaylength/decaylength_err;
302 double L_proj_jetDir = jetDirection.x()*Lx + jetDirection.y()*Ly + jetDirection.z()*Lz;
303 if (L_proj_jetDir < 0.) decaylength_significance *= -1.;
305 return decaylength_significance;