10#include "TMVA/Config.h"
43 ATH_MSG_DEBUG(
"Initializing DecoratePromptLeptonImproved...");
74 m_vars = std::make_unique<Prompt::VarHolder>();
95 return StatusCode::FAILURE;
117 return StatusCode::SUCCESS;
136 return StatusCode::SUCCESS;
157 <<
"\n\t\t\t Size of vertex container: " << vertices ->
size()
158 <<
"\n\t\t\t Size of track jet container: " << trackJets->size()
159 <<
"\n-----------------------------------------------------------------");
168 primaryVertex = vertex;
173 std::vector<decoratorFloatH_t> floatDecors;
176 floatDecors.emplace_back (k, ctx);
179 std::vector<decoratorShortH_t> shortDecors;
182 shortDecors.emplace_back (k, ctx);
193 decorateElec(*elec, *trackJets, *clusters, primaryVertex, floatDecors, shortDecors);
203 decorateMuon(*muon, *trackJets, primaryVertex, floatDecors, shortDecors);
208 return StatusCode::FAILURE;
211 return StatusCode::SUCCESS;
223 for(
unsigned i = 0; i <
m_allVars.size(); ++i) {
239 ATH_MSG_INFO(
"TMVA configuration file: " + fullPathToFile);
245 if(fullPathToFile ==
"") {
260 std::string inputContName;
269 "; must be either Electrons or Muons");
270 return StatusCode::FAILURE;
278 ATH_MSG_ERROR(
"Failed to create key for variable name=" << vvar);
279 return StatusCode::FAILURE;
282 vetoedVars.try_emplace (vkey, 0);
288 ATH_MSG_ERROR(
"Failed to create key for variable name=" << vvar);
289 return StatusCode::FAILURE;
292 vetoedVars.try_emplace (vkey, 0);
299 if (!vetoedVars.contains (var)) {
310 if (!vetoedVars.contains (var)) {
328 ATH_MSG_ERROR(
"Failed to create key for variable name=" << evar);
329 return StatusCode::FAILURE;
332 if (!vetoedVars.contains (ekey)) {
342 ATH_MSG_ERROR(
"Failed to create key for variable name=" << evar);
343 return StatusCode::FAILURE;
346 if (!vetoedVars.contains (ekey)) {
362 return StatusCode::FAILURE;
373 return StatusCode::SUCCESS;
405 std::vector<decoratorFloatH_t>& floatDecors,
406 std::vector<decoratorShortH_t>& shortDecors
455 std::vector<decoratorFloatH_t>& floatDecors,
456 std::vector<decoratorShortH_t>& shortDecors
510 double sumCoreEt_large = 0.0, CaloClusterSumEtRel = 0.0;
517 const double deta = elec_calEta - cluster->eta();
518 const double dphi = TVector2::Phi_mpi_pi(elec_calPhi - cluster->phi());
519 const double dr = std::sqrt(deta*deta + dphi*dphi);
522 sumCoreEt_large += cluster->pt();
527 if(elec.
pt() > 0.0) CaloClusterSumEtRel = sumCoreEt_large/elec.
pt();
534 const double Topoetcone30rel =
accessIsolation(accessCalIsolation30, elec);
535 const double Ptvarcone30rel =
accessIsolation(accessTrackIsolation30, elec);
543 std::vector<double> goodVertexNdistLong;
546 std::vector<ElementLink<xAOD::VertexContainer> > vtxLinks = (*m_accessDeepSecondaryVertex)(elec);
549 if(!vtxLink.isValid()) {
569 goodVertexNdistLong.push_back(vertex_ndist_long);
576 double best_vertex_ndist_long = 0.0;
578 if(goodVertexNdistLong.size() > 0) {
579 std::sort(goodVertexNdistLong.begin(), goodVertexNdistLong.end());
580 best_vertex_ndist_long = goodVertexNdistLong.back();
597 double calE = -99.0, peloss = -99.0, caloClusterERel = -99.0;
600 if(accessMuonCalE.isAvailable(*cluster) && accessMuonParamEnergyLoss.isAvailable(muon)) {
601 calE = accessMuonCalE(*cluster);
602 peloss = accessMuonParamEnergyLoss(muon);
604 caloClusterERel = calE/peloss;
607 ATH_MSG_WARNING(
"Muon calE or ParamEnergyLoss not found in auxiliary store");
616 const double Topoetcone30rel =
accessIsolation(accessCalIsolation30, muon);
617 const double ptvarcone30TightTTVAPt500rel =
accessIsolation(accessTrackIsolation30TTVA, muon);
625 std::vector<double> goodVertexNdistLong;
628 std::vector<ElementLink<xAOD::VertexContainer> > vtxLinks = (*m_accessDeepSecondaryVertex)(muon);
629 goodVertexNdistLong.reserve(vtxLinks.size());
632 if(!vtxLink.isValid()) {
644 goodVertexNdistLong.push_back(vertex_ndist_long);
652 double best_vertex_ndist_long = 0.0;
654 if(goodVertexNdistLong.size() > 0) {
655 std::sort(goodVertexNdistLong.begin(), goodVertexNdistLong.end());
656 best_vertex_ndist_long = goodVertexNdistLong.back();
674 double PtFrac = -99.;
677 if(particle.pt() > 0.0 && track_jet.
pt() > 0.0) {
680 PtFrac = track->pt()/track_jet.
pt();
683 const double angle = particle.p4().Vect().Angle(track_jet.
p4().Vect());
685 PtRel = particle.pt() * std::sin(
angle);
700 if(acc.second.isAvailable(particle)) {
701 vars.
addVar(acc.first, acc.second(particle));
704 ATH_MSG_WARNING(
"LeptonTagger RNN not found in auxiliary store for variable=" << vars.
asStr(acc.first));
711 const double lepPt = particle.pt();
721 else if (!(lepPt <
xmax)) {
724 else if (!(lepPt >
xmin)) {
731 ATH_MSG_DEBUG(
"getMutualVariables - lepPt = " << lepPt <<
", MVAXBin = " << curr_bin);
739 double isolation = -99., isolationrel = -99.;
742 isolation = isoAccessor(particle);
748 if(particle.pt() > 0.0) {
749 isolationrel = isolation / particle.pt();
761 for(
unsigned i = 0; i <
m_allVars.size(); ++i) {
789 vars.
addVar(dec.first, -99.0);
793 vars.
addVar(dec.first, -99.0);
801 std::vector<decoratorFloatH_t>& floatDecors,
802 std::vector<decoratorShortH_t>& shortDecors
811 if(vars.
getVar(dec.first, val)) {
812 shortDecors.at(dec.second)(particle) =
static_cast<short>(val);
827 if(vars.
getVar(dec.first, val)) {
828 floatDecors.at(dec.second)(particle) = val;
847 std::pair<double, const xAOD::Jet*>
match(mindr, minjet);
850 const double dr = part.p4().DeltaR(
jet->p4());
852 if(!minjet || dr < mindr) {
855 match = std::make_pair(mindr, minjet);
865 return std::make_pair(10., minjet);
878 if(!secondaryVertex || !primaryVertex) {
879 ATH_MSG_WARNING(
"getVertexLongitudinalNormDist - invalid pointer of lepton/secondaryVertex/primaryVertex");
884 float normDist_SVPV = 0.0;
887 ATH_MSG_WARNING(
"getVertexLongitudinalNormDist - missing \"normDistToPriVtx\"");
892 return normDist_SVPV*cos_theta;
903 if(!secondaryVertex || !primaryVertex) {
904 ATH_MSG_WARNING(
"GetVertexThetaWithLepDir - invalid pointer of lepton/secondaryVertex/primaryVertex");
910 const TVector3 sv_to_pv_t3 = TVector3(sv_to_pv_v3.x(), sv_to_pv_v3.y(), sv_to_pv_v3.z());
911 const TVector3 lepton_dirt = lepton.
p4().Vect();
913 const double cos_theta = sv_to_pv_t3.Unit()*lepton_dirt.Unit();
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
size_t size() const
Number of registered mappings.
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ElementLink implementation for ROOT usage.
DecorMap_t m_shortDecorMap
std::pair< double, const xAOD::Jet * > findTrackJet(const T &part, const xAOD::JetContainer &jets)
Gaudi::Property< double > m_maxLepTrackJetDR
Gaudi::Property< std::string > m_configFileVersion
Gaudi::Property< double > m_vertexMinThetaEcapElec
StatusCode initializeDecorators()
Gaudi::Property< std::vector< double > > m_leptonPtBinsVector
Gaudi::Property< std::vector< std::string > > m_vetoDecoratorShortVars
Gaudi::Property< std::string > m_leptonsName
virtual StatusCode initialize() override
Gaudi::Property< double > m_elecMinCalErelConeSize
void getMutualVariables(const xAOD::IParticle &particle, const xAOD::Jet &track_jet, const xAOD::TrackParticle *track, Prompt::VarHolder &vars) const
SG::ReadHandleKey< xAOD::VertexContainer > m_primaryVertexKey
Gaudi::Property< double > m_vertexBarrEcapAbsEtaAt
Gaudi::Property< bool > m_printTime
SG::WriteDecorHandleKeyArray< xAOD::IParticleContainer > m_shortDecorHandleKeys
std::vector< Prompt::Def::Var > m_floatVars
void initializeConstAccessors()
Gaudi::Property< std::vector< std::string > > m_stringFloatVars
Gaudi::Property< std::string > m_vertexLinkName
std::unordered_map< Def::Var, size_t > DecorMap_t
Gaudi::Property< double > m_vertexMinThetaBarrElec
std::vector< Prompt::Def::Var > m_allVars
Gaudi::Property< std::vector< std::string > > m_extraDecoratorShortVars
DecorMap_t m_floatDecorMap
SG::WriteDecorHandleKeyArray< xAOD::IParticleContainer > m_floatDecorHandleKeys
floatAccessorMap m_accessRNNMap
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
double getVertexCosThetaWithLepDir(const xAOD::IParticle &lepton, const xAOD::Vertex *secondaryVertex, const xAOD::Vertex *primaryVertex) const
Gaudi::Property< std::string > m_BDTName
void fillVarDefault(Prompt::VarHolder &vars) const
std::unique_ptr< TH1D > m_leptonPtBinHist
Gaudi::Property< std::string > m_methodTitleMVA
Gaudi::Property< std::string > m_inputVarDecoratePrefix
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronsKey
void decorateElec(const xAOD::Electron &electron, const xAOD::JetContainer &trackJets, const xAOD::CaloClusterContainer &clusters, const xAOD::Vertex *primaryVertex, std::vector< decoratorFloatH_t > &floatDecors, std::vector< decoratorShortH_t > &shortDecors)
DecoratePromptLeptonImproved(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< Float_t > m_varTMVA
void getMuonAnpVariables(const xAOD::Muon &muon, Prompt::VarHolder &vars, const xAOD::Vertex *primaryVertex) const
Gaudi::Property< std::vector< std::string > > m_extraDecoratorFloatVars
void getElectronAnpVariables(const xAOD::Electron &elec, const xAOD::CaloClusterContainer &clusters, Prompt::VarHolder &vars, const xAOD::Vertex *primaryVertex)
void addVarsToTMVA(Prompt::VarHolder &vars)
Gaudi::Property< std::vector< std::string > > m_accessorRNNVars
double getVertexLongitudinalNormDist(const xAOD::IParticle &lepton, const xAOD::Vertex *secondaryVertex, const xAOD::Vertex *primaryVertex) const
Prompt::Def::Var m_BDTVarKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsKey
void decorateAuxLepton(const xAOD::IParticle &particle, Prompt::VarHolder &vars, std::vector< decoratorFloatH_t > &floatDecors, std::vector< decoratorShortH_t > &shortDecors) const
Gaudi::Property< double > m_vertexMinChiSquaredProb
std::unique_ptr< Prompt::VarHolder > m_vars
Gaudi::Property< std::vector< std::string > > m_vetoDecoratorFloatVars
bool initializeTMVAReader()
std::unique_ptr< TMVA::Reader > m_TMVAReader
virtual StatusCode finalize() override
std::vector< Prompt::Def::Var > m_intVars
std::optional< AccessVertex > m_accessDeepSecondaryVertex
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Gaudi::Property< std::string > m_configPathOverride
SG::ConstAccessor< float > AccessFloat
Gaudi::Property< std::vector< std::string > > m_stringIntVars
float accessIsolation(const SG::ConstAccessor< float > &isoAccessor, const xAOD::IParticle &particle) const
SG::ReadHandleKey< xAOD::JetContainer > m_trackJetsKey
void decorateMuon(const xAOD::Muon &muon, const xAOD::JetContainer &trackJets, const xAOD::Vertex *primaryVertex, std::vector< decoratorFloatH_t > &floatDecors, std::vector< decoratorShortH_t > &shortDecors)
double getVar(const unsigned key) const
std::string asStr(const uint32_t key, const double val)
bool addVar(unsigned key, double value)
Adds a variable to the VarHolder.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
const xAOD::CaloCluster * caloCluster(size_t index=0) const
Pointer to the xAOD::CaloCluster/s that define the electron candidate.
Class providing the definition of the 4-vector interface.
virtual FourMom_t p4() const =0
The full 4-momentum of the particle.
size_t size() const
number of constituents
virtual FourMom_t p4() const
The full 4-momentum of the particle.
JetConstituentVector getConstituents() const
Return a vector of consituents. The object behaves like vector<const IParticle*>. See JetConstituentV...
virtual double pt() const
The transverse momentum ( ) of the particle.
const Amg::Vector3D & position() const
Returns the 3-pos.
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Eigen::Matrix< double, 3, 1 > Vector3D
@ CandVertex_normDistToPriVtxLongitudinalBest_ThetaCutVtx
@ Ptvarcone30_TightTTVA_pt500rel
@ CandVertex_normDistToPriVtxLongitudinalBest
bool GetAuxVar(const T1 &obj, T2 &value, const std::string &var_name)
std::string PrintResetStopWatch(TStopwatch &watch)
double getVertexFitProb(const xAOD::Vertex *vtx)
std::string makeContDecorKey(const std::string &cont, const std::string &decor)
Make a StoreGate key from container and decoration name.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Jet_v1 Jet
Definition of the current "jet version".
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
Muon_v1 Muon
Reference the current persistent version:
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Electron_v1 Electron
Definition of the current "egamma version".