27 #include "CLHEP/Vector/LorentzVector.h"
39 const std::string&
n,
const IInterface*
p):
41 m_addNegativeTracksToPrimaryVertex(false),
42 m_usePtCorrectedEnergy(false),
43 m_useSingleTracksAlsoForMass(false)
48 declareInterface<IJetFitterVariablesFactory>(
this);
58 ATH_MSG_INFO(
" Initialization of JetFitterVariablesFactory succesfull");
59 return StatusCode::SUCCESS;
63 ATH_MSG_INFO(
" Finalization of JetFitterVariablesFactory succesfull");
64 return StatusCode::SUCCESS;
70 bool nastyVsRevertPosToNeg = (
basename.find(
"Flip")!=std::string::npos);
74 float energyFraction(0);
77 float significance3d(0);
82 float deltaRFlightDir(0.);
84 std::vector<Trk::VxJetCandidate*> myVertices;
86 if (myJetFitterInfo) myVertices = myJetFitterInfo->
verticesJF();
87 if(myVertices.size() == 0){
88 ATH_MSG_DEBUG(
"#BTAG# Trk::VxJetCandidate not found for jet fitter ");
89 fill(
BTag,
basename, mass_uncorr, nVTX, nSingleTracks, nTracksAtVtx,
mass, energyFraction, significance3d, deltaeta, deltaphi,
chi2,
ndof, deltaRFlightDir);
90 return StatusCode::SUCCESS;
92 if(myVertices.size() > 0) myVxJetCandidate=
dynamic_cast<Trk::VxJetCandidate*
>(myVertices[0]);
93 if (myVxJetCandidate==0) {
94 ATH_MSG_WARNING(
"#BTAG# No correct VxJetCandidate could be retrieved." );
95 fill(
BTag,
basename, mass_uncorr, nVTX, nSingleTracks, nTracksAtVtx,
mass, energyFraction, significance3d, deltaeta, deltaphi,
chi2,
ndof, deltaRFlightDir);
96 return StatusCode::SUCCESS;
107 const double s_pion=139.57018;
109 double energyFromPrimary=0.;
110 double energyFromSecondary=0.;
118 if (mySelectedTracksInJet!=0)
120 ATH_MSG_DEBUG(
" Adding the tracks from primary vertex information ");
121 const std::vector<const Trk::ITrackLink*> & myPrimaryLinks=mySelectedTracksInJet->
getPrimaryTrackLinks();
123 std::vector<const Trk::ITrackLink*>::const_iterator myPrimaryLinksBegin=myPrimaryLinks.begin();
124 std::vector<const Trk::ITrackLink*>::const_iterator myPrimaryLinksEnd=myPrimaryLinks.end();
126 for(std::vector<const Trk::ITrackLink*>::const_iterator myPrimaryLinksIter=myPrimaryLinksBegin;
127 myPrimaryLinksIter!=myPrimaryLinksEnd;
128 ++myPrimaryLinksIter)
133 energyFromPrimary+=std::sqrt(s_pion*s_pion+myParameters->
momentum().mag2());
137 ATH_MSG_WARNING(
" no perigee in track for energy computation. Skipping primary track...");
142 ATH_MSG_DEBUG(
" No information about further primary tracks available. Normal in JetFitter vs. 1");
162 const std::vector<Trk::VxTrackAtVertex*>::const_iterator TracksAtPrimaryBegin=TracksAtPrimary.begin();
163 const std::vector<Trk::VxTrackAtVertex*>::const_iterator TracksAtPrimaryEnd=TracksAtPrimary.end();
165 for (std::vector<Trk::VxTrackAtVertex*>::const_iterator TracksAtPrimaryIter=TracksAtPrimaryBegin;
166 TracksAtPrimaryIter!=TracksAtPrimaryEnd;
167 ++TracksAtPrimaryIter) {
170 if (
dynamic_cast<const Trk::Perigee*
>((*TracksAtPrimaryIter)->perigeeAtVertex())!=0)
174 std::sqrt(s_pion*s_pion+
175 (*TracksAtPrimaryIter)->perigeeAtVertex()->momentum().mag2());
179 ATH_MSG_ERROR(
" FIXME: VERTEX DOESN'T SUPPORT NEUTRAL PERIGEE, commented out in line 163");
180 ATH_MSG_ERROR(
" Track is not a normal track neither a KS. This is an ERROR (ask developer to fix it). Skipping track... ");
188 CLHEP::HepLorentzVector massVector(0,0,0,0);
192 double inverrordist(0.);
201 for (std::vector<Trk::VxVertexOnJetAxis*>::const_iterator vectorOfClustersOfTrackIter=vectorOfClustersOfTrackBegin;
202 vectorOfClustersOfTrackIter!=vectorOfClustersOfTrackEnd;
203 ++vectorOfClustersOfTrackIter) {
205 const std::vector<Trk::VxTrackAtVertex*> & tracksOfVertex=(*vectorOfClustersOfTrackIter)->getTracksAtVertex();
207 int vertexSize=tracksOfVertex.size();
208 int ntrack=(*vectorOfClustersOfTrackIter)->getNumVertex()+5;
209 if (!nastyVsRevertPosToNeg)
211 if (vertexPosition[ntrack]>0) {
214 nTracksAtVtx+=vertexSize;
222 if (vertexPosition[ntrack]<=0) {
225 nTracksAtVtx+=vertexSize;
233 for (std::vector<Trk::VxVertexOnJetAxis*>::const_iterator vectorOfClustersOfTrackIter=vectorOfClustersOfTrackBegin;
234 vectorOfClustersOfTrackIter!=vectorOfClustersOfTrackEnd;
235 ++vectorOfClustersOfTrackIter) {
237 const std::vector<Trk::VxTrackAtVertex*> & tracksOfVertex=(*vectorOfClustersOfTrackIter)->getTracksAtVertex();
238 std::vector<Trk::VxTrackAtVertex*>::const_iterator clustersOfTrackBegin=tracksOfVertex.begin();
239 std::vector<Trk::VxTrackAtVertex*>::const_iterator clustersOfTrackEnd=tracksOfVertex.end();
241 int vertexSize=tracksOfVertex.size();
243 int ntrack=(*vectorOfClustersOfTrackIter)->getNumVertex()+5;
247 if ((vertexPosition[ntrack]<0 && (!nastyVsRevertPosToNeg))||(vertexPosition[ntrack]>=0 && nastyVsRevertPosToNeg)) {
250 for (std::vector<Trk::VxTrackAtVertex*>::const_iterator clustersOfTrackIter=clustersOfTrackBegin;
251 clustersOfTrackIter!=clustersOfTrackEnd;++clustersOfTrackIter) {
254 std::hypot(s_pion, (*clustersOfTrackIter)->perigeeAtVertex()->momentum().mag());
259 if ( (nVTX>0 && vertexSize>1) || nVTX==0 ) {
260 dist+=std::abs(vertexPosition[ntrack])/vertexCovMatrix(ntrack,ntrack);
261 if (vertexCovMatrix(ntrack,ntrack)>0)
263 inverrordist+=1./vertexCovMatrix(ntrack,ntrack);
267 ATH_MSG_WARNING(
"The diagonal element of the vertex cov matrix ("<<ntrack<<
","<<ntrack<<
") is "<<vertexCovMatrix(ntrack,ntrack)<<
". It should be positive... Ignoring vertex when computing L/sigma(L)");
272 CLHEP::HepLorentzVector massThisCluster(0.,0.,0.,0.);
276 for (std::vector<Trk::VxTrackAtVertex*>::const_iterator clustersOfTrackIter=clustersOfTrackBegin;
277 clustersOfTrackIter!=clustersOfTrackEnd;
278 ++clustersOfTrackIter) {
286 if (
dynamic_cast<const Trk::Perigee*
>((*clustersOfTrackIter)->perigeeAtVertex())!=0)
288 massThisCluster+=CLHEP::HepLorentzVector(mytrack.x(), mytrack.y(), mytrack.z(), std::hypot(s_pion, mytrack.mag()));
292 ATH_MSG_ERROR(
"Neutral parameter has been taken out until Vertex has been rewritten to support neutral perigee again. ");
293 ATH_MSG_ERROR(
" Track is not a normal track neither a KS. This is an ERROR (ask developer to fix it). Skipping track... ");
298 sumPAllVertices+=sumP;
299 double ptadd=sumP.perp(flightAxis.unit());
300 double masswithneutrals=std::sqrt(massThisCluster.mag2()+ptadd*ptadd)+ptadd;
304 massVector+=massThisCluster;
308 if ( (nVTX>0 && vertexSize>1) || nVTX==0 ) {
309 massVector+=massThisCluster;
317 energyFromSecondary+=std::sqrt(masswithneutrals*masswithneutrals+sumP.mag2());
321 energyFromSecondary+=std::sqrt(massThisCluster.mag2()+sumP.mag2());
330 if (energyFromSecondary+energyFromPrimary>0) {
331 energyFraction=energyFromSecondary/(energyFromSecondary+energyFromPrimary);
334 if (massVector.mag()>0) {
335 mass=std::sqrt(massVector.mag2()+sumPtAdd*sumPtAdd)+sumPtAdd;
336 mass_uncorr=massVector.mag();
342 if (mass_uncorr>5000.) {
348 if (inverrordist!=0) {
349 significance3d=dist/std::sqrt(inverrordist);
354 if (std::abs(sumPAllVertices.mag())>1
e-7) {
355 deltaphi=sumPAllVertices.eta()-JetVector.Eta();
356 deltaeta=sumPAllVertices.deltaPhi(
Amg::Vector3D(JetVector.Px(), JetVector.Py(), JetVector.Pz()));
357 deltaRFlightDir = std::hypot(sumPAllVertices.deltaPhi(flightAxis), sumPAllVertices.eta()-flightAxis.eta());
361 deltaRFlightDir = -10;
365 fill(
BTag,
basename, mass_uncorr, nVTX, nSingleTracks, nTracksAtVtx,
mass, energyFraction, significance3d, deltaeta, deltaphi,
chi2,
ndof, deltaRFlightDir);
367 return StatusCode::SUCCESS;
374 int nVTX,
int nSingleTracks,
int nTracksAtVtx,
float mass,
float energyFraction,
375 float significance3d,
float deltaeta,
float deltaphi,
float chi2,
int ndof,
float deltaRFlightDir)
const {
377 BTag->setVariable<
float>(
basename,
"massUncorr", mass_uncorr);
380 BTag->setVariable<
float>(
basename,
"dRFlightDir", deltaRFlightDir);
393 BTag->setVariable<
int>(
basename,
"nSingleTracks", nSingleTracks);
394 BTag->setVariable<
int>(
basename,
"nTracksAtVtx", nTracksAtVtx);
396 BTag->setVariable<
float>(
basename,
"energyFraction", energyFraction);
397 BTag->setVariable<
float>(
basename,
"significance3d", significance3d);
398 BTag->setVariable<
float>(
basename,
"deltaeta", deltaeta);
399 BTag->setVariable<
float>(
basename,
"deltaphi", deltaphi);