Commit 3467136b authored by Wouter Van Den Wollenberg's avatar Wouter Van Den Wollenberg Committed by Graeme Stewart
Browse files

Made small changes to MV-tagger to make them work with the new BTagging...

Made small changes to MV-tagger to make them work with the new BTagging configuration scheme. They now no longer use their instance name to look up calibration data. Tagged this version as the first with new configuration. (JetTagTools-01-00-18)

	* Modified MV-taggers to not retrieve configuration data from instance name, but from attribute.
	* Tagged as JetTagTools-01-00-18

2014-10-22  David Quarrie <David.Quarrie@cern.ch>
	* cmt/requirements
		 Specify the required ROOT components for cmake (transparent to CMT)
	* Tagged as JetTagTools-01-00-17
parent 06edfacd
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "AGILEPack"
#include <sstream>
namespace agile
{
class network_client
{
public:
network_client();
network_client(const std::string &filename);
// network_client(std::stringstream &s);
~network_client() = default;
void load(const std::string &filename);
void load(std::stringstream &s);
std::map<std::string, double> predict(const std::map<std::string, double> &x);
std::vector<std::string> inputs();
private:
agile::neural_net net;
};
network_client::network_client() {}
network_client::network_client(const std::string &filename)
{
net.from_yaml(filename);
}
inline void network_client::load(const std::string &filename)
{
net.from_yaml(filename);
}
inline void network_client::load(std::stringstream &s)
{
net.from_yaml(s);
}
inline std::map<std::string, double> network_client::predict(const std::map<std::string, double> &x)
{
return std::move(net.predict_map(x));
}
inline std::vector<std::string> network_client::inputs()
{
return net.get_inputs();
}
}
\ No newline at end of file
......@@ -16,97 +16,100 @@
c-jet or uds-jet for a single event.
@authors Dan Guest, Luke de Oliveira
********************************************************/
#include "AthenaBaseComps/AthAlgTool.h"
#include "GaudiKernel/ToolHandle.h"
#include "JetTagTools/IJetFitterClassifierTool.h"
#include "JetTagTools/ITagTool.h"
#include "xAODBTagging/BTagging.h"
#include <vector>
#include <string>
#include <map>
#include <string>
// class TList;
// #include <TString.h>
// class TTrainedNetwork;
// class TH1;
// namespace Trk
// {
// class NeuralNetworkToHistoTool;
// }
namespace JetTagger {
class NeuralNet;
// class declarations
namespace agile {
class network_client;
}
namespace Analysis {
class CalibrationBroker;
}
class IJetFitterTagInfo;
class CalibrationBroker;
static const InterfaceID
IID_GaiaNNTool("Analysis::GaiaNNTool", 1, 0);
class GaiaNNTool : public IJetFitterClassifierTool,
public AthAlgTool
{
public:
static const std::string SPECS;
static const std::string TRAINING;
static const InterfaceID& interfaceID() {
return IID_GaiaNNTool;
};
GaiaNNTool(const std::string& name,
const std::string& n, const IInterface* p);
~GaiaNNTool();
virtual StatusCode initialize();
virtual StatusCode finalize();
void fillLikelihoodValues(IJetFitterTagInfo & myTagInfo,
const std::string & jetauthor,
double jetpT,
double jeteta,
double IP3dlike=-5000);
namespace Analysis {
private:
// variable names used internally to pass jet pt / eta around
static const std::string JET_PT;
static const std::string JET_ETA;
// some input variables like IP3DNeg or SV1Flip need remapping
std::map<std::string, std::string> m_variable_remapping;
void loadCalibration(const std::string & jetauthor);
class GaiaNNTool : public AthAlgTool, virtual public ITagTool
{
public:
GaiaNNTool(const std::string& name,
const std::string& n,
const IInterface*);
virtual ~GaiaNNTool();
StatusCode initialize();
StatusCode finalize();
void setOrigin(const xAOD::Vertex* priVtx);
virtual StatusCode tagJet(xAOD::Jet& jetToTag, xAOD::BTagging* BTag);
void finalizeHistos() {};
// internal typdefs
private:
typedef std::map<std::string, agile::network_client*> nn_map;
typedef std::map<std::string, double> var_map;
// functions
private:
// load the calibration file from the COOL db
void load_calibration_file();
void cache_calibration(const std::string& jetauthor);
std::string get_calib_string(std::string jetauthor, std::string name="calib");
// load input variables from xAOD
void fill_ip3d(var_map& inputs, xAOD::BTagging* BTag);
void fill_jetfitter(var_map& inputs, xAOD::BTagging* BTag);
void fill_svp(var_map& inputs, xAOD::BTagging* BTag);
// data members
private:
// variables to load the Gaia calibration file
std::string m_calibrationDirectory;
std::string m_calibrationSubDirectory;
ToolHandle<CalibrationBroker> m_calibrationTool; // pointer to calibration in COOL
std::string m_xAODBaseName;
// container information
std::string m_ip3d_infosource;
std::string m_jftNN_infosource;
std::string m_sv1_infosource;
// map holding neural network calibrations ( jet_author -> NN )
nn_map m_networks;
// constants
double m_min_pt;
double m_max_abs_eta;
/** This switch is needed to indicate what to do. The algorithm can be run to produce
reference histograms from the given MC files (m_runModus=0) or to work in analysis mode
(m_runModus=1) where already made reference histograms are read.*/
std::string m_runModus; //!< 0=Do not read histos, 1=Read referece histos (analysis mode)
/** Storage for the primary vertex. Can be removed when JetTag provides origin(). */
// this pointer does not need to be deleted in the destructor (because it
// points to something in storegate)
const xAOD::Vertex* m_priVtx;
}; // end class
inline void GaiaNNTool::setOrigin(const xAOD::Vertex* priVtx) { m_priVtx = priVtx; }
void initializeCalibrationFile();
void registerHist(std::string name);
std::string getCalString(std::string jet_author, std::string name);
std::string getRemapping(const std::string&) const;
}// end Analysis namespace
std::string m_calibrationDirectory;
std::string m_calibrationSubDirectory;
ToolHandle<CalibrationBroker> m_calibrationTool;
#endif
std::map<std::string, JetTagger::NeuralNet*> m_networks;
double m_min_pt;
double m_max_abs_eta;
};
}//end Analysis namespace
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// -*-c++-*- header for IJetFitterVariablesFactory
#ifndef BTAGTOOL_IMSVVARIABLESFACTORY_C
#define BTAGTOOL_IMSVVARIABLESFACTORY_C
/******************************************************
@class MSVVariableFactory
Package : JetTagTools
Created : Sept 2014
DESCRIPTION:
This class is a "variable factory". It generates all
the variables per vertex in MSV.
********************************************************/
#include "GaudiKernel/IAlgTool.h"
#include "xAODJet/Jet.h"
#include "xAODBTagging/BTagging.h"
#include "xAODTracking/VertexContainer.h"
#include "xAODTracking/Vertex.h"
#include <string>
namespace Trk {
class VxSecVKalVertexInfo;
}
namespace Analysis {
static const InterfaceID IID_IMSVVariablesFactory
("Analysis::IMSVVariablesFactory", 1, 0);
class IMSVVariablesFactory : virtual public IAlgTool {
public:
virtual ~IMSVVariablesFactory(){};
virtual StatusCode initialize() = 0;
virtual StatusCode finalize() = 0;
//virtual void setOrigin(const xAOD::Vertex* priVtx) = 0;
virtual StatusCode fillMSVVariables(const xAOD::Jet &, xAOD::BTagging* BTag, const Trk::VxSecVKalVertexInfo* myInfoVKal, xAOD::VertexContainer* btagVertex, const xAOD::Vertex& PV, std::string basename)const = 0;
static const InterfaceID& interfaceID() { return IID_IMSVVariablesFactory; };
};
}//end Analysis namespace
#endif
// -*- c++ -*-
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef BTAGTOOL_MSVVARIABLESFACTORY_C
#define BTAGTOOL_MSVVARIABLESFACTORY_C
/******************************************************
@class MSVVariableFactory
********************************************************/
#include "AthenaBaseComps/AthAlgTool.h"
#include "JetTagTools/IMSVVariablesFactory.h"
#include <utility>
class StoreGateSvc;
namespace Analysis {
//static const InterfaceID IID_JetFitterVariablesFactory("Analysis::JetFitterVariablesFactory", 1, 0);
class MSVVariablesFactory : public AthAlgTool , virtual public IMSVVariablesFactory {
public:
MSVVariablesFactory(const std::string& name,
const std::string& n, const IInterface* p);
virtual ~MSVVariablesFactory();
virtual StatusCode initialize();
virtual StatusCode finalize();
virtual StatusCode fillMSVVariables(const xAOD::Jet &, xAOD::BTagging* BTag, const Trk::VxSecVKalVertexInfo* myInfoVKal, xAOD::VertexContainer* btagVertex, const xAOD::Vertex& PV, std::string basename) const ;
void setOrigin(const xAOD::Vertex* priVtx);
// static const InterfaceID& interfaceID() { return IID_JetFitterVariablesFactory; };
private:
double get3DSignificance(const xAOD::Vertex* priVertex,
std::vector<const xAOD::Vertex*>& secVertex,
const Amg::Vector3D jetDirection) const;
//const xAOD::Vertex* m_priVtx;
};
//inline void MSVVariablesFactory::setOrigin(const xAOD::Vertex* priVtx) { m_priVtx = priVtx; }
}//end Analysis namespace
#endif
......@@ -15,14 +15,19 @@
#include "GeoPrimitives/GeoPrimitives.h"
#include "xAODTracking/TrackParticle.h"
#include "xAODTracking/TrackParticleContainer.h"
#include <string>
#include <vector>
#include <map>
#include <list>
#include "TMVA/IMethod.h"
#include "TMVA/MethodBase.h"
namespace TMVA { class Reader; }
namespace Analysis { class CalibrationBroker; }
//namespace xAOD { class TrackParticle; class TrackParticleContainer; }
namespace Trk { class VxCandidate; class RecVertex;}
//namespace Trk { class VxCandidate; class RecVertex;}
//class Jet;
class StoreGateSvc;
//class StoreGateSvc;
namespace Analysis
{
......@@ -33,42 +38,63 @@ namespace Analysis
MultiSVTag(const std::string&,const std::string&,const IInterface*);
virtual ~MultiSVTag();
StatusCode initialize();
StatusCode finalize();
void tagJet(xAOD::Jet& jetToTag);
void setOrigin(const Trk::VxCandidate* priVtx);
StatusCode finalize();
StatusCode tagJet(xAOD::Jet& jetToTag, xAOD::BTagging * BTag);
void setOrigin(const xAOD::Vertex* priVtx);
void finalizeHistos();
private:
//GP: calculate the 3d significance on the fly
double get3DSignificance(const Trk::RecVertex & priVertex,
std::vector<const Trk::RecVertex*> & secVertex,
const Amg::Vector3D jetDirection);
std::string m_taggerName;
std::string m_taggerNameBase;
//
ToolHandle<CalibrationBroker> m_calibrationTool;
std::string m_MultiSV;
//
std::string m_runModus;
std::string m_refType;
const xAOD::Vertex* m_priVtx;
bool m_writeInfoBase; // writes a basic info for each tagger with Pb, Pu (SVInfoBase)
bool m_writeInfoPlus; // writes a detailed info
std::string m_infoPlusName; // key for the SVInfoPlus
/** information to persistify: */
std::string m_originalTPCollectionName;
const xAOD::TrackParticleContainer* m_originalTPCollection;
const Trk::VxCandidate* m_priVtx;
std::vector<std::string> m_jetCollectionList, m_jetWithInfoPlus;
//name of the VKalVrt secondary vertex in Jet instance
//(needed to retrieve the ISvxConstituent written
//out by the finder and attached to the ParticleJet)
std::vector<std::string> m_jetCollectionList;
std::vector<std::string> m_hypotheses;
bool m_doForcedCalib;
std::string m_ForcedCalibName;
std::string m_secVxFinderName;
std::string m_xAODBaseName;
//...
//variables for bb tag
float m_jetpt;
float m_nvtx;
float m_maxefrc;
float m_summass;
float m_totalntrk;
float m_diffntrkSV0;
float m_normDist;
//properties of vertex with maximum (and 2nd max) mass:
float m_mmax_mass ;
float m_mmax_efrc ;
float m_mmax_DRjet;
float m_mmax_dist ;
float m_mmx2_mass ;
float m_mmx2_efrc ;
float m_mmx2_DRjet;
float m_mmx2_dist ;
// distances: max mass vertex to PV, and mx2 to max vertex
float m_mx12_2d12 ;
float m_mx12_DR ;
float m_mx12_Angle;
//...
std::map<std::string, TMVA::Reader*> m_tmvaReaders;
std::map<std::string, TMVA::MethodBase*> m_tmvaMethod;
std::list<std::string> m_undefinedReaders;
std::string m_sv0_infosource;
}; // End class
inline void MultiSVTag::setOrigin(const Trk::VxCandidate* priVtx) {m_priVtx = priVtx;}
inline void MultiSVTag::setOrigin(const xAOD::Vertex* priVtx) { m_priVtx = priVtx; }
} // End namespace
......
......@@ -22,6 +22,9 @@ apply_tag ROOTMathLibs
end_private
use AtlasROOT AtlasROOT-* External
# Specify the required ROOT components for cmake (transparent to CMT)
apply_pattern cmake_add_command command="find_package(ROOT COMPONENTS TMVA)"
use SGTools SGTools-* Control
use JetTagInfo JetTagInfo-* PhysicsAnalysis/JetTagging
use TrkParameters TrkParameters-* Tracking/TrkEvent
......@@ -52,7 +55,7 @@ use TrkVertexFitterInterfaces TrkVertexFitterInterfaces-* Tracking/TrkVerte
#use TrkToolInterfaces TrkToolInterfaces-* Tracking/TrkTools
#use TrkParticleBase TrkParticleBase-* Tracking/TrkEvent
use TrkTrackLink TrkTrackLink-* Tracking/TrkEvent
use TrkLinks TrkLinks-* Tracking/TrkEvent
#use EventPrimitives EventPrimitives-* Event
......@@ -84,6 +87,9 @@ use VxJetVertex VxJetVertex-* Tracking/TrkEvent
# for GbbNN inputvariable calculation
use AtlasFastJet AtlasFastJet-* External
# for Gaia (re-enable once we actually have AGILEPack included...)
# use AGILEPack AGILEPack-*
end_private
......@@ -93,7 +99,7 @@ macro DOXYGEN_IMAGE_PATH "../doc/images"
#library JetTagTools *.cxx components/*.cxx
#library JetTagTools DummyTag.cxx components/*.cxx
#apply_pattern dual_use_library files="*.cxx"
apply_pattern dual_use_library files="DummyTag.cxx TrackSelector.cxx HistoHelperRoot.cxx NewLikelihoodTool.cxx BasicTrackGradeFactory.cxx DetailedTrackGradeFactory.cxx GradedTrack.cxx IPTag.cxx JetTagUtils.cxx SVForIPTool.cxx SVTag.cxx JetFitterTag.cxx JetFitterNtupleWriter.cxx JetFitterNNTool.cxx MV1Tag.cxx MV1cTag.cxx MV2Tag.cxx MVbTag.cxx JetFitterVariablesFactory.cxx"
apply_pattern dual_use_library files="DummyTag.cxx TrackSelector.cxx HistoHelperRoot.cxx NewLikelihoodTool.cxx BasicTrackGradeFactory.cxx DetailedTrackGradeFactory.cxx GradedTrack.cxx IPTag.cxx JetTagUtils.cxx SVForIPTool.cxx SVTag.cxx JetFitterTag.cxx JetFitterNtupleWriter.cxx JetFitterNNTool.cxx MV1Tag.cxx MV1cTag.cxx MV2Tag.cxx MVbTag.cxx JetFitterVariablesFactory.cxx MSVVariablesFactory.cxx MultiSVTag.cxx"
#apply_pattern declare_joboptions files="*.py"
apply_pattern declare_runtime files="-s=../share *.root *.txt"
......
......@@ -251,7 +251,8 @@ namespace Analysis {
/** book calibration histograms if needed */
if( m_runModus == "reference" ) {
/* FF: comment out reference mode running for now
//FF: comment out reference mode running for now
ATH_MSG_INFO("#BTAG# running IPTag in reference mode");
for(uint j=0;j<m_jetCollectionList.size();j++) {
//int nbGrades=trackFactoryGradesDefinition.numberOfGrades();
......@@ -289,7 +290,7 @@ namespace Analysis {
}
} // endloop on partitions
}*/
}
// ms m_histoHelper->print();
}
/* ms
......@@ -341,45 +342,50 @@ namespace Analysis {
}
/** for the reference mode we need the true label: */
std::string label = "N/A";
int label = -1;
//std::string label = "N/A";
std::string pref = "";
// FF: Disable reference mode running for now
// if( m_runModus == "reference" ) {
// // here we require a jet selection:
// if( jetToTag.pt()>m_jetPtMinRef && fabs(jetToTag.eta())<2.5 ) {
// // and also a truth match:
// const TruthInfo* mcinfo = jetToTag.tagInfo<TruthInfo>("TruthInfo");
// double deltaRmin(0.);
// if( mcinfo ) {
// label = mcinfo->jetTruthLabel();
// // for purification: require no b or c quark closer than dR=m_purificationDeltaR
// double deltaRtoClosestB = mcinfo->deltaRMinTo("B");
// double deltaRtoClosestC = mcinfo->deltaRMinTo("C");
// deltaRmin = deltaRtoClosestB < deltaRtoClosestC ? deltaRtoClosestB : deltaRtoClosestC;
// double deltaRtoClosestT = mcinfo->deltaRMinTo("T");
// deltaRmin = deltaRtoClosestT < deltaRmin ? deltaRtoClosestT : deltaRmin;
// } else {
// ATH_MSG_ERROR("#BTAG# No TruthInfo ! Cannot run on reference mode !");
// return StatusCode::FAILURE;
// }
// if ( ( "B"==m_referenceType && "B"==label ) || // b-jets
// ( "UDSG"==m_referenceType && "N/A"==label ) || // light jets
// ( "ALL"==m_referenceType && // all jets: b + purified light jets
// ( "B"==label || "C"==label || ( "N/A"==label && deltaRmin > m_purificationDeltaR ) ) )
// ) {
// if ("B"==label) {
// pref = m_hypotheses[0];
// m_nbjet++;
// } else if ("N/A"==label) {
// pref = m_hypotheses[1];
// m_nljet++;
// } else if ("C"==label && m_useCHypo) {
// pref = m_hypotheses[2];
// m_ncjet++;
// }
// }
// }
// }
if( m_runModus == "reference" ) {
// here we require a jet selection:
if( jetToTag.pt()>m_jetPtMinRef && fabs(jetToTag.eta())<2.5 ) {
// and also a truth match:
//const TruthInfo* mcinfo = jetToTag.tagInfo<TruthInfo>("TruthInfo");
double deltaRmin(0.);
if(jetToTag.getAttribute("TruthLabelID",label)) {
//label = mcinfo->jetTruthLabel();
// for purification: require no b or c quark closer than dR=m_purificationDeltaR
double deltaRtoClosestB, deltaRtoClosestC, deltaRtoClosestT;
jetToTag.getAttribute("TruthLabelDeltaR_B",deltaRtoClosestB);
jetToTag.getAttribute("TruthLabelDeltaR_C",deltaRtoClosestC);
jetToTag.getAttribute("TruthLabelDeltaR_T",deltaRtoClosestT);
//double deltaRtoClosestB = mcinfo->deltaRMinTo("B");
//double deltaRtoClosestC = mcinfo->deltaRMinTo("C");
deltaRmin = deltaRtoClosestB < deltaRtoClosestC ? deltaRtoClosestB : deltaRtoClosestC;
//double deltaRtoClosestT = mcinfo->deltaRMinTo("T");
deltaRmin = deltaRtoClosestT < deltaRmin ? deltaRtoClosestT : deltaRmin;
} else {
ATH_MSG_ERROR("#BTAG# No TruthInfo ! Cannot run on reference mode !");
return StatusCode::FAILURE;
}
if ( ( "B"==m_referenceType && 5==label ) || // b-jets