11 #include "GaudiKernel/ITHistSvc.h"
25 SVTag::SVTag(
const std::string&
t,
const std::string&
n,
const IInterface*
p)
27 m_likelihoodTool(
"Analysis::NewLikelihoodTool", this),
29 m_secVxFinderName(
"SV1"),
41 declareProperty(
"ForcedCalibrationName", m_ForcedCalibName =
"Cone4H1Tower");
69 ITHistSvc* myHistoSvc;
70 if( service(
"THistSvc", myHistoSvc ).isSuccess() ) {
80 return StatusCode::FAILURE;
97 std::vector<double>
xb;
98 double xbi[10] = {1., 2., 3., 4., 5., 6., 8., 10., 20., 50.};
103 std::string hDir =
"/RefFile/SV1/"+jetColl+
"/"+
m_hypotheses[ih]+
"/";
107 m_histoHelper->
bookHisto(hDir+
"BidimME",
"(E fraction)**0.7 vs Mass/(Mass+1)" ,50,0.218261406,1.,50,0.,1.);
110 std::string hDir =
"/RefFile/SV2/"+jetColl+
"/"+
m_hypotheses[ih]+
"/";
114 if(
m_usePtSV2)
m_histoHelper->
bookHisto(hDir+
"TridimMENPt",
"ln(Pt) vs (E fraction)**0.7 vs Mass/(Mass+1)",20,0.,1.,20,0.,1.,6,0.,4.8);
115 else m_histoHelper->
bookHisto(hDir+
"TridimMEN2T",
" ln(N) vs (E fraction)**0.7 vs Mass/(Mass+1)",20,0.,1.,20,0.,1.,7,0.,3.8);
118 hDir =
"/RefFile/SV2/"+jetColl+
"/controlSV/";
130 std::string iname( this->
name().substr(8) );
131 std::string::size_type
pos = iname.find(
"Flip");
132 if (
pos!=std::string::npos ) {
134 ATH_MSG_INFO(
"#BTAG# This instance of tagger has a flipped configuration. DRJPVSV computation will be adjusted.");
145 return StatusCode::SUCCESS;
152 ATH_MSG_INFO(
"#BTAG# Number of jets used for calibration for reference "
156 return StatusCode::SUCCESS;
162 const std::string &jetName)
const
166 std::string
author = jetName;
172 double jeteta = jetToTag.
eta(), jetphi = jetToTag.
phi(), jetpt = jetToTag.
pt();
174 <<
" phi = " << jetphi <<
" pT = " <<jetpt/
m_c_mom);
178 if (std::abs(jeteta) <= 2.5) {
187 float ambtot = -1., xratio = -1., distnrm = 0., drJPVSV = 0., Lxy = -100., L3d = -100.;
189 float distnrmCorr=0.;
193 std::vector< ElementLink< xAOD::VertexContainer > > myVertices;
195 BTag.variable<std::vector<ElementLink<xAOD::VertexContainer> > >(
m_secVxFinderName,
"vertices", myVertices);
197 if (!myVertices.empty()) {
217 position.y() - PVposition.y(),
218 position.z() - PVposition.z() );
224 ATH_MSG_VERBOSE(
"#BTAG# DRJPVSV regular="<<drJPVSV_1<<
" flipped="<<drJPVSV_2<<
" chosen="<<drJPVSV);
226 Lxy = std::hypot(PvSvDir(0,0), PvSvDir(1,0));
227 L3d = std::hypot(PvSvDir(0,0), PvSvDir(1,0), PvSvDir(2,0));
232 std::vector<const xAOD::Vertex*> vecVertices;
233 for (
const auto& link : myVertices) {
234 if (!link.isValid()) {
235 ATH_MSG_WARNING(
"#BTAG# Secondary vertex from InDetVKalVxInJetFinder has zero pointer. Skipping... ");
238 vecVertices.push_back(*link);
247 ATH_MSG_VERBOSE(
"#BTAG# No vertex. Cannot calculate normalized distance.");
252 ATH_MSG_VERBOSE(
"#BTAG# Svx Mass = "<< ambtot <<
" Svx E frac = " << xratio <<
" NGood2TrackVertices = " << NSVPair);
262 std::string iname(
name().substr(8));
263 std::string instanceName(iname);
264 std::string::size_type
pos = iname.find(
"Tag");
265 if (
pos != std::string::npos) {
266 std::string
prefix = iname.substr(0,
pos);
267 std::string posfix = iname.substr(
pos+3);
269 instanceName += posfix;
281 BTag.setSV0_significance3D(distnrm);
310 float ambtotp = ambtot > 0. ? ambtot/(1.+ambtot) : 0.;
312 float trfJetPt =
log(jetToTag.
pt()/20000.);
313 if(trfJetPt<0.) trfJetPt=0.01;
314 if(trfJetPt>4.8) trfJetPt=4.79;
315 std::string pref =
"";
317 if (jetpt >=
m_pTjetmin && std::abs(jeteta) <= 2.5) {
319 double deltaRtoClosestB = 999.;
320 if (jetToTag.
getAttribute(
"TruthLabelDeltaR_B",deltaRtoClosestB)) {
323 double deltaRtoClosestC;
324 jetToTag.
getAttribute(
"TruthLabelDeltaR_C", deltaRtoClosestC);
325 double deltaRmin = deltaRtoClosestB < deltaRtoClosestC ? deltaRtoClosestB : deltaRtoClosestC;
335 }
else if (0==
label) {
344 if (pref ==
"B" || pref ==
"C" || pref ==
"U") {
348 if (NSVPair > 0 && ambtot > 0.) {
349 if (xratiop == 1.) xratiop = 0.999999;
364 ATH_MSG_ERROR(
"#BTAG# No TruthInfo ! Cannot run in reference mode !");
365 return StatusCode::FAILURE;
369 std::vector<double> probi;
377 ATH_MSG_DEBUG(
"#BTAG# EFF b,u,c= " << effb <<
" " << effu <<
" " << effc);
378 if (NSVPair>0 && ambtot > 0.) {
381 AtomicProperty atom3(xratiop,
"SecVtx Transformed Energy Fraction");
384 std::string compoName(
author+
"#");
387 compo1.
atoms.push_back(atom1);
388 compo2.
atoms.push_back(atom2);
389 compo2.
atoms.push_back(atom3);
394 AtomicProperty atom4(drJPVSV,
"DeltaR between jet axis and (PV,SV) axis");
396 compo3.
atoms.push_back(atom4);
401 std::string compoName(
author+
"#");
405 Composite compo(compoName+
"TridimMENPt");
406 compo.
atoms.push_back(atom2);
407 compo.
atoms.push_back(atom3);
408 compo.
atoms.push_back(atom1);
411 compo1.
atoms.push_back(atom4);
416 Composite compo(compoName+
"TridimMEN2T");
417 compo.
atoms.push_back(atom2);
418 compo.
atoms.push_back(atom3);
419 compo.
atoms.push_back(atom1);
426 << probi[0] <<
" " << probi[1] <<
" " << probi[2]);
427 if (probi.size() >= 2) {
434 ATH_MSG_ERROR(
"#BTAG# Missing number in jet probabilities ! "<<probi.size());
439 probi.push_back((1.-effb));
440 probi.push_back((1.-effu));
442 probi.push_back((1.-effc));
445 if (probi.size()>=2){
463 return StatusCode::SUCCESS;
474 std::vector<const xAOD::Vertex*>& secVertex,
477 std::vector<Amg::Vector3D> positions;
483 sumWeights.setZero();
485 for (
const auto& vtx : secVertex) {
486 positions.push_back(vtx->position());
487 weightMatrices.push_back(vtx->covariancePosition().inverse());
488 weightTimesPosition += weightMatrices.back()*positions.back();
489 sumWeights += weightMatrices.back();
495 meanCovariance.setZero();
496 sumWeights.computeInverseWithCheck(meanCovariance, invertible);
503 Amg::Vector3D meanPosition = meanCovariance*weightTimesPosition;
507 AmgSymMatrix(3) covariance = meanCovariance + priVertex.covariancePosition();
513 double Lx = meanPosition[0]-priVertex.
position().x();
514 double Ly = meanPosition[1]-priVertex.
position().y();
515 double Lz = meanPosition[2]-priVertex.
position().z();
517 const double decaylength = sqrt(Lx*Lx + Ly*Ly + Lz*Lz);
518 if(decaylength==0.)
return 0.;
519 const double inv_decaylength = 1. / decaylength;
521 double dLdLx = Lx * inv_decaylength;
522 double dLdLy = Ly * inv_decaylength;
523 double dLdLz = Lz * inv_decaylength;
524 double decaylength_err2 = (dLdLx*dLdLx*covariance(0,0) +
525 dLdLy*dLdLy*covariance(1,1) +
526 dLdLz*dLdLz*covariance(2,2) +
527 2.*dLdLx*dLdLy*covariance(0,1) +
528 2.*dLdLx*dLdLz*covariance(0,2) +
529 2.*dLdLy*dLdLz*covariance(1,2));
530 if(decaylength_err2<=0.)
return 0.;
531 double decaylength_err = sqrt(decaylength_err2);
533 double decaylength_significance = 0.;
534 if (decaylength_err != 0.) decaylength_significance = decaylength/decaylength_err;
537 double L_proj_jetDir = jetDirection.x()*Lx + jetDirection.y()*Ly + jetDirection.z()*Lz;
538 if (L_proj_jetDir < 0.) decaylength_significance *= -1.;
540 return decaylength_significance;
544 std::vector<const xAOD::Vertex*>& secVertex,
547 std::vector<double> Sig3D(0);
551 for (
const auto & svrt : secVertex)
554 AmgSymMatrix(3) SVmPVCov = svrt->covariancePosition()+priVertex.covariancePosition();
555 SVmPVCov.computeInverseWithCheck(Wgt, success);
556 if( !success || Wgt(0,0)<=0. || Wgt(1,1)<=0. || Wgt(2,2)<=0. )
continue;
557 double significance = SVmPV.transpose()*Wgt*SVmPV;
558 if(significance <= 0.)
continue;
559 significance = std::sqrt(significance);
560 if(SVmPV.dot(jetDirection)<0.) significance *= -1.;
561 Sig3D.push_back(significance);
564 if(Sig3D.size()==0)
return 0.;
566 return *std::max_element(Sig3D.begin(),Sig3D.end());