diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/CTTDecorCheckInTool.h b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/CTTDecorCheckInTool.h index 4ba32a41f095365974a3a1622ae0b05c44fc4999..6b47153a8e903c71419f6a89de761561796987c1 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/CTTDecorCheckInTool.h +++ b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/CTTDecorCheckInTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ // // CTTDecorCheck.h - Description @@ -16,37 +16,26 @@ #include <vector> #include "AthenaBaseComps/AthAlgorithm.h" -//#include "AthenaBaseComps/AthReentrantAlgorithm.h" #include "GaudiKernel/ToolHandle.h" -#include "StoreGate/DataHandle.h" #include "StoreGate/ReadDecorHandle.h" #include "StoreGate/ReadHandle.h" - #include "xAODJet/JetContainer.h" #include "xAODTracking/VertexContainer.h" #include "xAODTracking/TrackParticleContainer.h" #include "JetTagTools/ClassifiedTrackTaggerTool.h" - - -class TLorentzVector; - - - - class CTTDecorCheckInTool : public AthAlgorithm +class CTTDecorCheckInTool : public AthAlgorithm { public: /* Constructor */ CTTDecorCheckInTool(const std::string& type, ISvcLocator* pSvcLocator); /* Destructor */ - virtual ~CTTDecorCheckInTool(); - + virtual ~CTTDecorCheckInTool() = default; virtual StatusCode initialize() override; virtual StatusCode execute() override; - virtual StatusCode finalize() override; //------------------------------------------------------------------------------------------------------------------ // Private data and functions @@ -64,11 +53,7 @@ class TLorentzVector; SG::ReadHandleKey<xAOD::VertexContainer> m_verticesKey { this, "VertexContainer", "PrimaryVertices"}; SG::ReadDecorHandleKey<xAOD::JetContainer> m_jetReadDecorKey{this,"JetDecorKey","AntiKt4EMPFlowJets.CTTScore","ReadDecorHandleKey for adding CTT score to Jets"}; - - - }; - - +}; #endif diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/ClassifiedTrackTaggerTool.h b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/ClassifiedTrackTaggerTool.h index c7c8207ad4db08f7499650c8c338ae151aaba1eb..baa61c943047e941a069247584cb97e04f3c905c 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/ClassifiedTrackTaggerTool.h +++ b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/ClassifiedTrackTaggerTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ // // ClassifiedTrackTaggerTool.h - Description @@ -22,7 +22,6 @@ #include <vector> #include "AthenaBaseComps/AthAlgTool.h" #include "GaudiKernel/ToolHandle.h" -#include "xAODTracking/TrackParticleContainer.h" #include "xAODJet/JetContainer.h" //Interface of InDetTrkInJetType (inside .h file of InDetTrkInJetType class) #include "InDetVKalVxInJetTool/InDetTrkInJetType.h" @@ -58,8 +57,7 @@ namespace Analysis { /* Constructor */ ClassifiedTrackTaggerTool(const std::string& type, const std::string& name, const IInterface* parent); /* Destructor */ - virtual ~ClassifiedTrackTaggerTool(); - + virtual ~ClassifiedTrackTaggerTool() = default; virtual StatusCode initialize() override; virtual StatusCode finalize() override; @@ -75,9 +73,7 @@ namespace Analysis { private: //debugging - IChronoStatSvc* m_timingProfile{}; - //variable to check: before public method bJetWgts can be executed, check that initialize() has been run! - int m_initialised{}; + IChronoStatSvc* m_timingProfile{}; //variables for retrieving the CTT classification score given the TCT weights std::unique_ptr<MVAUtils::BDT> m_CTTBDT; diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/src/CTTDecorCheckInTool.cxx b/PhysicsAnalysis/JetTagging/JetTagTools/src/CTTDecorCheckInTool.cxx index 430b48c1a487b3c352adf8edd940910bcc25180a..d2e9f89169519b0233559e40f22e4f60a67ed925 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/src/CTTDecorCheckInTool.cxx +++ b/PhysicsAnalysis/JetTagging/JetTagTools/src/CTTDecorCheckInTool.cxx @@ -1,14 +1,9 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ -#include "PathResolver/PathResolver.h" -#include "TLorentzVector.h" -//#include "StoreGate/ReadDecorHandle.h" - #include <cassert> #include "TestTools/FLOATassert.h" -#include <iostream> #include "JetTagTools/CTTDecorCheckInTool.h" // @@ -21,109 +16,83 @@ CTTDecorCheckInTool::CTTDecorCheckInTool( const std::string& name, m_classifiedTrackTagger("Analysis::ClassifiedTrackTaggerTool",this), m_jetCollection("AntiKt4EMPFlowJets") { - declareProperty("ClassifiedTrackTaggerTool", m_classifiedTrackTagger); - declareProperty("JetCollection",m_jetCollection); + declareProperty("ClassifiedTrackTaggerTool", m_classifiedTrackTagger); + declareProperty("JetCollection",m_jetCollection); } -//Destructor--------------------------------------------------------------- - CTTDecorCheckInTool::~CTTDecorCheckInTool(){ - ATH_MSG_DEBUG("ClassifiedTrackTaggerTool destructor called"); +//Initialize--------------------------------------------------------------- +StatusCode CTTDecorCheckInTool::initialize(){ + + ATH_CHECK( m_particlesKey.initialize() ); + ATH_CHECK( m_verticesKey.initialize() ); + ATH_CHECK( m_jetsKey.initialize() ); + + if(m_jetCollection.empty()){ + ATH_MSG_FATAL("No JetCollection specified! "); + } else { + m_jetReadDecorKey = m_jetCollection+".CTTScore"; + ATH_CHECK( m_jetReadDecorKey.initialize()); } -//Initialize--------------------------------------------------------------- - StatusCode CTTDecorCheckInTool::initialize(){ - - - ATH_CHECK( m_particlesKey.initialize() ); - ATH_CHECK( m_verticesKey.initialize() ); - ATH_CHECK( m_jetsKey.initialize() ); - - if(m_jetCollection!="") - { - m_jetReadDecorKey = m_jetCollection+".CTTScore"; - ATH_CHECK( m_jetReadDecorKey.initialize()); - } - - //------- - //check that the ClassifiedTrackTaggerTool can be accessed - if (m_classifiedTrackTagger.retrieve().isFailure()) { - ATH_MSG_DEBUG("Could not find Analysis::ClassifiedTrackTaggerTool"); - return StatusCode::SUCCESS; - } else { - ATH_MSG_DEBUG("Analysis::ClassifiedTrackTaggerTool found"); - } - - return StatusCode::SUCCESS; - } - - StatusCode CTTDecorCheckInTool::finalize() - { - ATH_MSG_DEBUG("CTTDecorCheckInTool finalize()"); - return StatusCode::SUCCESS; - } - - StatusCode CTTDecorCheckInTool::execute() - { - ATH_MSG_DEBUG( "Executing..." ); - if(m_jetCollection=="") {ATH_MSG_FATAL("No JetCollection specified! ");} - - SG::ReadDecorHandle< xAOD::JetContainer, float > jetReadDecorHandle (m_jetReadDecorKey); - - // Retrieve the track particles: - SG::ReadHandle<xAOD::TrackParticleContainer> trackTES(m_particlesKey); - if ( !trackTES.isValid() ) { - ATH_MSG_WARNING( "No TrackParticle container found in TDS" ); - return StatusCode::SUCCESS; } - ATH_MSG_DEBUG( "TrackParticleContainer successfully retrieved" ); - - SG::ReadHandle<xAOD::VertexContainer> pvTES(m_verticesKey); - if ( !pvTES.isValid() ) { - ATH_MSG_WARNING( "No Primary Vertices container found in TDS" ); - return StatusCode::SUCCESS; } - ATH_MSG_DEBUG( "Primary Vertices container successfully retrieved" ); - const xAOD::Vertex *primVertex=*(pvTES->begin()); - - - - //========================================================================== - SG::ReadHandle<xAOD::JetContainer> jetTES(m_jetsKey); - if ( !jetTES.isValid() ) { - ATH_MSG_WARNING( "No AntiKt4EMPflow jet container found in TDS" ); - return StatusCode::SUCCESS; } - ATH_MSG_DEBUG( "AntiKt4EMPflow jet container successfully retrieved" ); - - //save all TrackParticles in an std::vector (needed as input to the CTT tool) - xAOD::TrackParticleContainer::const_iterator trackItr = trackTES->begin(); - xAOD::TrackParticleContainer::const_iterator trackItrE = trackTES->end(); - std::vector<const xAOD::TrackParticle*> trkparticles(0); - - // Loop over all track particles: - for( ; trackItr != trackItrE; ++trackItr ) { - const xAOD::TrackParticle* trackParticle = ( *trackItr ); - trkparticles.push_back(trackParticle); - } - //first decorate all jets with the CTT method - m_classifiedTrackTagger->decorateJets(trkparticles,*primVertex,*jetTES); - - xAOD::JetContainer::const_iterator jetItr = jetTES->begin(); - xAOD::JetContainer::const_iterator jetItrE = jetTES->end(); - - for(jetItr = jetTES->begin(); jetItr != jetItrE; ++jetItr) { - /// this Jet - const xAOD::Jet* curjet = ( *jetItr ); - ATH_MSG_DEBUG( " Jet pt: " << curjet->pt()<<" eta: "<<curjet->eta()<<" phi: "<< curjet->phi() ); - float CTTScore = m_classifiedTrackTagger->bJetWgts(trkparticles, *primVertex, curjet->p4()); - ATH_MSG_DEBUG ("Retrieved CTT score from CTT tool: " << CTTScore); - ATH_MSG_DEBUG("CTT score of decorated xAOD::Jet : " << jetReadDecorHandle(*curjet)); - assert(Athena_test::isEqual(CTTScore,jetReadDecorHandle(*curjet))); - - } - - /** - for (const xAOD::Jet* & decoJet : *jetReadDecorHandle) { // Access the container. - ATH_MSG_INFO("CTT score of decorated xAOD::Jet : " << jetReadDecorHandle (decoJet); ) // Access the decoration. - }**/ - - return StatusCode::SUCCESS; + //------- + //check that the ClassifiedTrackTaggerTool can be accessed + if (m_classifiedTrackTagger.retrieve().isFailure()) { + ATH_MSG_DEBUG("Could not find Analysis::ClassifiedTrackTaggerTool"); + return StatusCode::SUCCESS; + } else { + ATH_MSG_DEBUG("Analysis::ClassifiedTrackTaggerTool found"); + } + + return StatusCode::SUCCESS; +} + +StatusCode CTTDecorCheckInTool::execute() +{ + ATH_MSG_DEBUG( "Executing..." ); + + SG::ReadDecorHandle< xAOD::JetContainer, float > jetReadDecorHandle (m_jetReadDecorKey); + + // Retrieve the track particles: + SG::ReadHandle<xAOD::TrackParticleContainer> trackTES(m_particlesKey); + if ( !trackTES.isValid() ) { + ATH_MSG_WARNING( "No TrackParticle container found in TDS" ); + return StatusCode::SUCCESS; } + ATH_MSG_DEBUG( "TrackParticleContainer successfully retrieved" ); + + SG::ReadHandle<xAOD::VertexContainer> pvTES(m_verticesKey); + if ( !pvTES.isValid() ) { + ATH_MSG_WARNING( "No Primary Vertices container found in TDS" ); + return StatusCode::SUCCESS; + } + ATH_MSG_DEBUG( "Primary Vertices container successfully retrieved" ); + const xAOD::Vertex *primVertex=*(pvTES->begin()); + + //========================================================================== + SG::ReadHandle<xAOD::JetContainer> jetTES(m_jetsKey); + if ( !jetTES.isValid() ) { + ATH_MSG_WARNING( "No AntiKt4EMPflow jet container found in TDS" ); + return StatusCode::SUCCESS; + } + ATH_MSG_DEBUG( "AntiKt4EMPflow jet container successfully retrieved" ); + + //save all TrackParticles in an std::vector (needed as input to the CTT tool) + std::vector<const xAOD::TrackParticle*> trkparticles(0); + for(const auto& trkPart : *trackTES){ + trkparticles.emplace_back(trkPart); + } + + //first decorate all jets with the CTT method + m_classifiedTrackTagger->decorateJets(trkparticles, *primVertex, *jetTES); + + for(const auto& curjet : *jetTES){ + ATH_MSG_DEBUG( " Jet pt: " << curjet->pt()<<" eta: "<<curjet->eta()<<" phi: "<< curjet->phi() ); + float CTTScore = m_classifiedTrackTagger->bJetWgts(trkparticles, *primVertex, curjet->p4()); + ATH_MSG_DEBUG ("Retrieved CTT score from CTT tool: " << CTTScore); + ATH_MSG_DEBUG("CTT score of decorated xAOD::Jet : " << jetReadDecorHandle(*curjet)); + assert(Athena_test::isEqual(CTTScore,jetReadDecorHandle(*curjet))); + } + + return StatusCode::SUCCESS; +} diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/src/ClassifiedTrackTaggerTool.cxx b/PhysicsAnalysis/JetTagging/JetTagTools/src/ClassifiedTrackTaggerTool.cxx index 7e4c9f6bfe91bae1cea9560db581b94337a14491..bab59adbf2e4dd9664596ea2baee1f5a032d04a0 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/src/ClassifiedTrackTaggerTool.cxx +++ b/PhysicsAnalysis/JetTagging/JetTagTools/src/ClassifiedTrackTaggerTool.cxx @@ -1,11 +1,10 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "JetTagTools/ClassifiedTrackTaggerTool.h" #include "PathResolver/PathResolver.h" #include "TLorentzVector.h" -//#include "TrkVKalVrtFitter/TrkVKalVrtFitter.h" #include "MVAUtils/BDT.h" #include "TFile.h" @@ -16,39 +15,30 @@ namespace Analysis { // //Constructor-------------------------------------------------------------- -ClassifiedTrackTaggerTool::ClassifiedTrackTaggerTool(const std::string& type, - const std::string& name, - const IInterface* parent): - base_class(type,name,parent), - m_trackClassificator("InDet::InDetTrkInJetType/TrackClassificationTool",this), - m_deltaRConeSize(0.4), - m_useFivePtJetBinTCT(false), - m_calibFileName("CTT_calib_v00.root"), - m_jetCollection("AntiKt4EMPFlowJets") + ClassifiedTrackTaggerTool::ClassifiedTrackTaggerTool(const std::string& type, + const std::string& name, + const IInterface* parent): + base_class(type,name,parent), + m_trackClassificator("InDet::InDetTrkInJetType/TrackClassificationTool",this), + m_deltaRConeSize(0.4), + m_useFivePtJetBinTCT(false), + m_calibFileName("CTT_calib_v00.root"), + m_jetCollection("AntiKt4EMPFlowJets") { - declareProperty("TrackClassificationTool", m_trackClassificator); - declareProperty("deltaRConeSize", m_deltaRConeSize); - declareProperty("useFivePtJetBinTCT",m_useFivePtJetBinTCT); - declareProperty("JetCollection",m_jetCollection); - m_timingProfile=nullptr; - } - -//Destructor--------------------------------------------------------------- - ClassifiedTrackTaggerTool::~ClassifiedTrackTaggerTool(){ - ATH_MSG_DEBUG("ClassifiedTrackTaggerTool destructor called"); + declareProperty("TrackClassificationTool", m_trackClassificator); + declareProperty("deltaRConeSize", m_deltaRConeSize); + declareProperty("useFivePtJetBinTCT",m_useFivePtJetBinTCT); + declareProperty("JetCollection",m_jetCollection); + m_timingProfile=nullptr; } //Initialize--------------------------------------------------------------- - StatusCode ClassifiedTrackTaggerTool::initialize(){ - m_initialised = 0; -// - //retrieve calibration file and initialize the m_trkClassBDT - std::string fullPathToFile = PathResolverFindCalibFile("BTagging/20221012track/"+m_calibFileName); + StatusCode ClassifiedTrackTaggerTool::initialize(){ + //retrieve calibration file and initialize the m_trkClassBDT + std::string fullPathToFile = PathResolverFindCalibFile("BTagging/20221012track/"+m_calibFileName); - - std::string strBDTName=""; - if(m_useFivePtJetBinTCT) {strBDTName="CTTtrainedWithRetrainedTCT"; } - else {strBDTName="CTTtrainedWithDefaultTCT"; } + std::string strBDTName = m_useFivePtJetBinTCT ? + "CTTtrainedWithRetrainedTCT" : "CTTtrainedWithDefaultTCT"; std::unique_ptr<TFile> rootFile(TFile::Open(fullPathToFile.c_str(), "READ")); if (!rootFile) { @@ -57,71 +47,73 @@ ClassifiedTrackTaggerTool::ClassifiedTrackTaggerTool(const std::string& type, } std::unique_ptr<TTree> training( (TTree*)rootFile->Get(strBDTName.c_str()) ); m_CTTBDT = std::make_unique<MVAUtils::BDT>(training.get()); + + //------- + //check that the TrackClassificationTool can be accessed-> InDetTrkInJetType to get TCT weights per TrackParticle + if (m_trackClassificator.retrieve().isFailure()) { + ATH_MSG_DEBUG("Could not find InDet::InDetTrkInJetType - TrackClassificationTool"); + return StatusCode::FAILURE; + } else { + ATH_MSG_DEBUG("InDet::InDetTrkInJetType - TrackClassificationTool found"); + } - - //------- - //check that the TrackClassificationTool can be accessed-> InDetTrkInJetType to get TCT weights per TrackParticle - if (m_trackClassificator.retrieve().isFailure()) { - ATH_MSG_DEBUG("Could not find InDet::InDetTrkInJetType - TrackClassificationTool"); - return StatusCode::SUCCESS; - } else { - ATH_MSG_DEBUG("InDet::InDetTrkInJetType - TrackClassificationTool found"); - } - - //check that the fivePtJetBinTCT is actually used, if CTT is configured to do so - if(m_useFivePtJetBinTCT && !m_trackClassificator->usesFivePtJetBinVersion()) {ATH_MSG_ERROR("FivePtJetBin TCT tool is not used, but required by CTT!"); } - if(!m_useFivePtJetBinTCT && m_trackClassificator->usesFivePtJetBinVersion()) {ATH_MSG_ERROR("FivePtJetBin TCT tool is used, but default version required by CTT!"); } - if(m_useFivePtJetBinTCT) {ATH_MSG_DEBUG("FivePtJetBin version of TCT is used"); } - else {ATH_MSG_DEBUG("Default version of TCT is used"); } - - //SG::WriteDecorHandleKey for CTT jet decoration - if(m_jetCollection!="") - { - m_jetWriteDecorKey = m_jetCollection +".CTTScore"; - ATH_CHECK( m_jetWriteDecorKey.initialize()); - } - + //check that the fivePtJetBinTCT is actually used, if CTT is configured to do so + if(m_useFivePtJetBinTCT){ + ATH_MSG_DEBUG("FivePtJetBin version of TCT is used"); + if(!m_trackClassificator->usesFivePtJetBinVersion()) + ATH_MSG_ERROR("FivePtJetBin TCT tool is not used, but required by CTT!"); + } + else{ + ATH_MSG_DEBUG("Default version of TCT is used"); + if(m_trackClassificator->usesFivePtJetBinVersion()) + ATH_MSG_ERROR("FivePtJetBin TCT tool is used, but default version required by CTT!"); + } - m_initialised = 1; // Tool is initialised successfully. -//----- - if(msgLvl(MSG::DEBUG)) ATH_CHECK(service("ChronoStatSvc", m_timingProfile)); + //SG::WriteDecorHandleKey for CTT jet decoration + if(m_jetCollection.empty()) {ATH_MSG_FATAL("No JetCollection specified! ");} + else { + m_jetWriteDecorKey = m_jetCollection +".CTTScore"; + ATH_CHECK( m_jetWriteDecorKey.initialize()); + } + + if(msgLvl(MSG::DEBUG)) ATH_CHECK(service("ChronoStatSvc", m_timingProfile)); //----- - return StatusCode::SUCCESS; - } + return StatusCode::SUCCESS; + } - StatusCode ClassifiedTrackTaggerTool::finalize() - { + StatusCode ClassifiedTrackTaggerTool::finalize() + { if(m_timingProfile)m_timingProfile->chronoPrint("ClassifiedTrackTaggerTool"); ATH_MSG_DEBUG("ClassifiedTrackTaggerTool finalize()"); return StatusCode::SUCCESS; - } + } - float ClassifiedTrackTaggerTool::bJetWgts(const std::vector<const xAOD::TrackParticle*> & InpTrk, const xAOD::Vertex & PV, const TLorentzVector & Jet) const - { - if( !m_initialised ) return -999; - std::vector<std::vector<float>> TCTweights; - //for each track inside a cone of deltaR around the jet direction save the TCT output (wgtB, wgtL,wgtG) - //if it was not rejected by the TCT track quality cuts - for (auto itrk : InpTrk) { - if((itrk->p4()).DeltaR(Jet)<=m_deltaRConeSize) - { - std::vector<float> v_tctScore = m_trackClassificator->trkTypeWgts(itrk,PV,Jet); - bool b_zeroTCTScore = std::all_of(v_tctScore.begin(), v_tctScore.end(), [](float i) { return i==0; }); - if(!b_zeroTCTScore) { TCTweights.push_back(v_tctScore); } - } - } + float ClassifiedTrackTaggerTool::bJetWgts(const std::vector<const xAOD::TrackParticle*> & InpTrk, const xAOD::Vertex & PV, const TLorentzVector & Jet) const + { + std::vector<std::vector<float>> TCTweights; + //for each track inside a cone of deltaR around the jet direction save the TCT output (wgtB, wgtL,wgtG) + //if it was not rejected by the TCT track quality cuts + for (const auto &itrk : InpTrk) { + if((itrk->p4()).DeltaR(Jet)<=m_deltaRConeSize) { + std::vector<float> v_tctScore = m_trackClassificator->trkTypeWgts(itrk, PV, Jet); + bool b_zeroTCTScore = std::all_of(v_tctScore.begin(), v_tctScore.end(), [](float i) { return i==0; }); + if(!b_zeroTCTScore) { TCTweights.push_back(v_tctScore); } + } + } - ATH_MSG_DEBUG("[ClassifiedTrackTagger]: retrieved TCT score"); - int ntrk = TCTweights.size(); - if(ntrk< 3) {return -5; } //if less than three tracks passing quality cuts of TCT -> return default value of -5 - //get sorted indices w.r.t. wgtB (highest wgtB track -> first index in sorted_indices) - std::vector<int> sorted_indices = GetSortedIndices(TCTweights); - ATH_MSG_DEBUG("[ClassifiedTrackTagger]: ntrk = " << ntrk << " in jet"); - - float ptjet = Jet.Pt(); - float trackMultiplicity = ( ((float)ntrk) / ptjet) * 1.e3; -//--- + ATH_MSG_DEBUG("[ClassifiedTrackTagger]: retrieved TCT score"); + int ntrk = TCTweights.size(); + if(ntrk< 3) {return -5; } //if less than three tracks passing quality cuts of TCT -> return default value of -5 + + //get sorted indices w.r.t. wgtB (highest wgtB track -> first index in sorted_indices) + std::vector<int> sorted_indices = GetSortedIndices(TCTweights); + ATH_MSG_DEBUG("[ClassifiedTrackTagger]: ntrk = " << ntrk << " in jet"); + + float ptjet = Jet.Pt(); + float trackMultiplicity = ( ((float)ntrk) / ptjet) * 1.e3; + if(m_timingProfile)m_timingProfile->chronoStart("ClassifiedTrackTaggerTool"); + //-----Use MVAUtils to save CPU //order in which variables are given to the BDT wgtB_0,wgtG_0,wgtL_0,wgtB_1,wgtG_1,wgtL_1,wgtB_2,wgtG_2,wgtL_2, (ntrk/ptjet * 1.e3) // (0: track with highest wgtB), (1: track with 2nd highest wgtB), (2: track with 3rd highest wgtB) @@ -129,51 +121,42 @@ ClassifiedTrackTaggerTool::ClassifiedTrackTaggerTool(const std::string& type, ATH_MSG_DEBUG("[ClassifiedTrackTagger]: ordered signal TCT weights = " << TCTweights[sorted_indices[0]][iwgtB] << "," << TCTweights[sorted_indices[1]][iwgtB] << "," << TCTweights[sorted_indices[2]][iwgtB]); //change input variable ordering when final BDT model is chosen! - std::vector<float> bdt_vars={TCTweights[sorted_indices[0]][iwgtB],TCTweights[sorted_indices[0]][iwgtG],TCTweights[sorted_indices[0]][iwgtL], - TCTweights[sorted_indices[1]][iwgtB],TCTweights[sorted_indices[1]][iwgtG],TCTweights[sorted_indices[1]][iwgtL], - TCTweights[sorted_indices[2]][iwgtB],TCTweights[sorted_indices[2]][iwgtG],TCTweights[sorted_indices[2]][iwgtL], - trackMultiplicity}; + std::vector<float> bdt_vars = { + TCTweights[sorted_indices[0]][iwgtB], TCTweights[sorted_indices[0]][iwgtG], TCTweights[sorted_indices[0]][iwgtL], + TCTweights[sorted_indices[1]][iwgtB], TCTweights[sorted_indices[1]][iwgtG], TCTweights[sorted_indices[1]][iwgtL], + TCTweights[sorted_indices[2]][iwgtB], TCTweights[sorted_indices[2]][iwgtG], TCTweights[sorted_indices[2]][iwgtL], + trackMultiplicity}; float score=m_CTTBDT->GetGradBoostMVA(bdt_vars); ATH_MSG_DEBUG("[ClassifiedTrackTagger]: CTT classification score = " << score); - //----- if(m_timingProfile)m_timingProfile->chronoStop("ClassifiedTrackTaggerTool"); return score; } -void ClassifiedTrackTaggerTool::decorateJets(const std::vector<const xAOD::TrackParticle*> & InpTrk, const xAOD::Vertex & primVertex, const xAOD::JetContainer & jets) const -{ - if(m_jetCollection=="") {ATH_MSG_FATAL("No JetCollection specified! ");} - SG::WriteDecorHandle< xAOD::JetContainer, float > jetWriteDecorHandle (m_jetWriteDecorKey); - xAOD::JetContainer::const_iterator jetItr = jets.begin(); - xAOD::JetContainer::const_iterator jetItrE = jets.end(); - - for(jetItr = jets.begin(); jetItr != jetItrE; ++jetItr) { - /// this Jet - const xAOD::Jet* curjet = ( *jetItr ); - ATH_MSG_DEBUG( " Jet pt: " << curjet->pt()<<" eta: "<<curjet->eta()<<" phi: "<< curjet->phi() ); - float CTTScore = bJetWgts(InpTrk, primVertex, curjet->p4()); - jetWriteDecorHandle(*curjet) = CTTScore; - } - //return StatusCode::SUCCESS; -} - -std::vector<int> ClassifiedTrackTaggerTool::GetSortedIndices(std::vector<std::vector<float>> unordered_vec) const -{ - //from https://stackoverflow.com/questions/1577475/c-sorting-and-keeping-track-of-indexes - int ntrk = unordered_vec.size(); - std::vector<int> indices; - indices.clear(); - for(int i=0; i < ntrk; i++) + void ClassifiedTrackTaggerTool::decorateJets(const std::vector<const xAOD::TrackParticle*> & InpTrk, const xAOD::Vertex & primVertex, const xAOD::JetContainer & jets) const { - indices.push_back(i); + SG::WriteDecorHandle< xAOD::JetContainer, float > jetWriteDecorHandle (m_jetWriteDecorKey); + for(const auto& curjet : jets){ + ATH_MSG_DEBUG( " Jet pt: " << curjet->pt()<<" eta: "<<curjet->eta()<<" phi: "<< curjet->phi() ); + float CTTScore = bJetWgts(InpTrk, primVertex, curjet->p4()); + jetWriteDecorHandle(*curjet) = CTTScore; + } } - //sort the vector of indices, such that the index corresponding to the highest wgtB stands first, with the lowest last (unordered_vec[itrk][iwgt], wgtB-> iwgt=0) - std::sort(std::begin(indices), std::end(indices),[&unordered_vec](size_t itrk1, size_t itrk2) {return unordered_vec[itrk1][0] > unordered_vec[itrk2][0];}); - return indices; -} + std::vector<int> ClassifiedTrackTaggerTool::GetSortedIndices(std::vector<std::vector<float>> unordered_vec) const + { + //from https://stackoverflow.com/questions/1577475/c-sorting-and-keeping-track-of-indexes + int ntrk = unordered_vec.size(); + std::vector<int> indices; + indices.clear(); + for(int i=0; i < ntrk; i++) indices.push_back(i); + + //sort the vector of indices, such that the index corresponding to the highest wgtB stands first, with the lowest last (unordered_vec[itrk][iwgt], wgtB-> iwgt=0) + std::sort(std::begin(indices), std::end(indices),[&unordered_vec](size_t itrk1, size_t itrk2) {return unordered_vec[itrk1][0] > unordered_vec[itrk2][0];}); + + return indices; + } }// close namespace