From ded1e9155a8938a81f62b2b7cc8ca0dbaaaff7dd Mon Sep 17 00:00:00 2001
From: Fudong He <fuhe@cern.ch>
Date: Tue, 10 Mar 2020 20:29:41 +0100
Subject: [PATCH 1/4] rename the new tagger and only save the variables we need
 for elec or muon

---
 .../python/LeptonTaggersConfig.py             | 30 +++++++++----------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/python/LeptonTaggersConfig.py b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/python/LeptonTaggersConfig.py
index 427aabe6f2ce..de4d8b5bef65 100644
--- a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/python/LeptonTaggersConfig.py
+++ b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/python/LeptonTaggersConfig.py
@@ -43,14 +43,14 @@ def GetDecorateImprovedPromptLeptonAlgs(name="", addSpectators=False):
         algs += [DecorateReFitPrimaryVertex  ('Electrons')]
         algs += [DecorateNonPromptVertex     ('Electrons')]
         algs += [DecoratePromptLeptonRNN     ('PromptLeptonRNN',              'Electrons')]
-        algs += [DecoratePromptLeptonImproved('PromptLeptonVetoImprovedBARR', 'Electrons', 'AntiKt4PV0TrackJets')]
-        algs += [DecoratePromptLeptonImproved('PromptLeptonVetoImprovedECAP', 'Electrons', 'AntiKt4PV0TrackJets')]
+        algs += [DecoratePromptLeptonImproved('PromptLeptonImprovedVetoBARR', 'Electrons', 'AntiKt4PV0TrackJets')]
+        algs += [DecoratePromptLeptonImproved('PromptLeptonImprovedVetoECAP', 'Electrons', 'AntiKt4PV0TrackJets')]
 
     if name == "" or name == 'Muons':
         algs += [DecorateReFitPrimaryVertex  ('Muons')]
         algs += [DecorateNonPromptVertex     ('Muons')]
         algs += [DecoratePromptLeptonRNN     ('PromptLeptonRNN',          'Muons')]
-        algs += [DecoratePromptLeptonImproved('PromptLeptonVetoImproved', 'Muons', 'AntiKt4PV0TrackJets')]
+        algs += [DecoratePromptLeptonImproved('PromptLeptonImprovedVeto', 'Muons', 'AntiKt4PV0TrackJets')]
     
     return algs
 
@@ -108,21 +108,21 @@ def GetExtraImprovedPromptVariablesForDxAOD(name=''):
 
     prompt_lep_vars = []
 
-    prompt_vars  = "PromptLeptonImprovedInput_TrackJetNTrack.PromptLeptonImprovedInput_MVAXBin."
-    prompt_vars += "PromptLeptonImprovedInput_PtFrac.PromptLeptonImprovedInput_PtRel.PromptLeptonImprovedInput_DRlj."
+    prompt_vars  = "PromptLeptonImprovedInput_MVAXBin."
+    prompt_vars += "PromptLeptonImprovedInput_PtFrac.PromptLeptonImprovedInput_DRlj."
     prompt_vars += "PromptLeptonImprovedInput_topoetcone30rel.PromptLeptonImprovedInput_ptvarcone30rel."
 
     if name == "" or name == "Electrons":
-        # Add PromptLeptonTagger electron RNN and new inputs for PromptLeptonVetoImprovedBARR/PromptLeptonVetoImprovedECAP
+        # Add PromptLeptonTagger electron RNN and new inputs for PromptLeptonImprovedVetoBARR/PromptLeptonImprovedVetoECAP
         prompt_vars += "PromptLeptonRNN_prompt.PromptLeptonRNN_non_prompt_b.PromptLeptonRNN_non_prompt_c.PromptLeptonRNN_conversion."
-        prompt_vars += "PromptLeptonVetoImprovedBARR.PromptLeptonVetoImprovedECAP.PromptLeptonImprovedInput_CaloClusterSumEtRel.PromptLeptonImprovedInput_CandVertex_normDistToPriVtxLongitudinalBest_ThetaCutVtx."
+        prompt_vars += "PromptLeptonImprovedVetoBARR.PromptLeptonImprovedVetoECAP.PromptLeptonImprovedInput_TrackJetNTrack.PromptLeptonImprovedInput_PtRel.PromptLeptonImprovedInput_CaloClusterSumEtRel.PromptLeptonImprovedInput_CandVertex_normDistToPriVtxLongitudinalBest_ThetaCutVtx."
 
         prompt_lep_vars += ["Electrons.%s" %prompt_vars]
 
     if name == "" or name == "Muons":
-        # Add PromptLeptonTagger muon RNN and new inputs for PromptLeptonVetoImproved
+        # Add PromptLeptonTagger muon RNN and new inputs for PromptLeptonImprovedVeto
         prompt_vars += "PromptLeptonRNN_prompt.PromptLeptonRNN_non_prompt_b.PromptLeptonRNN_non_prompt_c."
-        prompt_vars += "PromptLeptonVetoImproved.PromptLeptonImprovedInput_ptvarcone30_TightTTVA_pt500rel.PromptLeptonImprovedInput_CaloClusterERel.PromptLeptonImprovedInput_CandVertex_normDistToPriVtxLongitudinalBest."
+        prompt_vars += "PromptLeptonImprovedVeto.PromptLeptonImprovedInput_ptvarcone30_TightTTVA_pt500rel.PromptLeptonImprovedInput_CaloClusterERel.PromptLeptonImprovedInput_CandVertex_normDistToPriVtxLongitudinalBest."
 
         prompt_lep_vars += ["Muons.%s" %prompt_vars]
 
@@ -416,11 +416,11 @@ def getStringIntVars(BDT_name):
     elif BDT_name == 'PromptTauIso':
         int_vars += ['TrackJetNTrack']
 
-    elif BDT_name == 'PromptLeptonVetoImproved':
+    elif BDT_name == 'PromptLeptonImprovedVeto':
         int_vars += ['MVAXBin']
 
-    elif BDT_name == 'PromptLeptonVetoImprovedBARR' or \
-         BDT_name == 'PromptLeptonVetoImprovedECAP':
+    elif BDT_name == 'PromptLeptonImprovedVetoBARR' or \
+         BDT_name == 'PromptLeptonImprovedVetoECAP':
         int_vars += ['MVAXBin',
                      'TrackJetNTrack']
     
@@ -460,7 +460,7 @@ def getStringFloatVars(BDT_name):
                        'LepJetPtFrac',
                        'DRlj']
 
-    elif BDT_name == 'PromptLeptonVetoImproved':
+    elif BDT_name == 'PromptLeptonImprovedVeto':
         float_vars += ['topoetcone30rel',
                        'ptvarcone30_TightTTVA_pt500rel',
                        'PromptLeptonRNN_prompt',
@@ -469,8 +469,8 @@ def getStringFloatVars(BDT_name):
                        'CaloClusterERel',
                        'CandVertex_normDistToPriVtxLongitudinalBest']
 
-    elif BDT_name == 'PromptLeptonVetoImprovedBARR' or \
-         BDT_name == 'PromptLeptonVetoImprovedECAP':
+    elif BDT_name == 'PromptLeptonImprovedVetoBARR' or \
+         BDT_name == 'PromptLeptonImprovedVetoECAP':
         float_vars += ['topoetcone30rel',
                        'ptvarcone30rel',
                        'PromptLeptonRNN_prompt',
-- 
GitLab


From 8952ec509a0c7bea243f7438cbd47783d85920f3 Mon Sep 17 00:00:00 2001
From: Fudong He <fuhe@cern.ch>
Date: Wed, 11 Mar 2020 11:12:59 +0100
Subject: [PATCH 2/4] Use the weight files from cvmfs

---
 .../python/LeptonTaggersConfig.py             | 13 ++++----
 .../LeptonTaggers/src/RNNTool.cxx             | 30 ++++++++++++++-----
 .../LeptonTaggers/src/RNNTool.h               |  5 ++++
 3 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/python/LeptonTaggersConfig.py b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/python/LeptonTaggersConfig.py
index de4d8b5bef65..61aec12c98f8 100644
--- a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/python/LeptonTaggersConfig.py
+++ b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/python/LeptonTaggersConfig.py
@@ -209,18 +209,18 @@ def DecoratePromptLeptonImproved(BDT_name, lepton_name, track_jet_name):
     alg.BDTName                    = BDT_name
     alg.InputVarDecoratePrefix     = 'PromptLeptonImprovedInput_'
     alg.PrintTime                  = False
-    alg.OutputLevel                = 2
+    alg.OutputLevel                = 3
 
     #
     # Read configuration from AFS for this initial merge request, will switch to cvmfs with second request 
     #
     if lepton_name == 'Electrons':
         alg.MethodTitleMVA     = 'BDT_Electron_%s' %(BDT_name)
-        alg.ConfigPathOverride = '/afs/cern.ch/user/f/fuhe/public/data/bdt/elec/%s/TMVAClassification_BDT_Electron_%s.weights.xml' %(BDT_name, BDT_name)
+        alg.ConfigFileVersion  = 'InputData-2020-02-25/BDT/Electron/%s' %(BDT_name)
         alg.accessorRNNVars    = ['PromptLeptonRNN_prompt']
     elif lepton_name == 'Muons': 
         alg.MethodTitleMVA     = 'BDT_Muon_%s' %(BDT_name)
-        alg.ConfigPathOverride = '/afs/cern.ch/user/f/fuhe/public/data/bdt/muon/%s/TMVAClassification_BDT_Muon_%s.weights.xml' %(BDT_name, BDT_name)
+        alg.ConfigFileVersion  = 'InputData-2020-02-25/BDT/Muon/%s' %(BDT_name)
         alg.accessorRNNVars    = ['PromptLeptonRNN_prompt']
     else:
         raise Exception('Decorate%s - unknown lepton type: "%s"' %(BDT_name, lepton_name))  
@@ -274,9 +274,12 @@ def DecoratePromptLeptonRNN(RNN_name, lepton_name):
     # Read configuration from AFS for this initial merge request, will switch to cvmfs with second request 
     #
     if lepton_name == 'Electrons':
-        alg.toolRNN.configPathRNN = "/afs/cern.ch/user/f/fuhe/public/data/rnn/elecs_feb20_fullrun2_linear_ptraw_ntk5_model_ndense10_nhidden50_nepoch10_nbatch256_use_weights_nn-config.json"
+        alg.toolRNN.configRNNVersion  = 'InputData-2020-02-25/RNN/Electron'
+        alg.toolRNN.configRNNJsonFile = 'elecs_feb20_fullrun2_linear_ptraw_ntk5_model_ndense10_nhidden50_nepoch10_nbatch256_use_weights_nn-config.json'
+
     elif lepton_name == 'Muons':
-        alg.toolRNN.configPathRNN = "/afs/cern.ch/user/f/fuhe/public/data/rnn/muons_feb19_fullrun2_linear_ptraw_ntk5_model_ndense10_nhidden50_nepoch10_nbatch256_use_weights_nn-config.json"
+        alg.toolRNN.configRNNVersion  = 'InputData-2020-02-25/RNN/Muon'
+        alg.toolRNN.configRNNJsonFile = 'muons_feb19_fullrun2_linear_ptraw_ntk5_model_ndense10_nhidden50_nepoch10_nbatch256_use_weights_nn-config.json'
     else:
         raise Exception('DecorateNonPromptVertex - unknown lepton type: "%s"' %lepton_name)
 
diff --git a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/RNNTool.cxx b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/RNNTool.cxx
index 36bd9c4277e5..c96c9d0244a4 100644
--- a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/RNNTool.cxx
+++ b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/RNNTool.cxx
@@ -18,23 +18,39 @@ Prompt::RNNTool::RNNTool(const std::string &name, const std::string &type, const
 {
   declareInterface<Prompt::IRNNTool>(this);
 
-  declareProperty("configPathRNN",     m_configPathRNN);  
-  declareProperty("debug",             m_debug);
+  declareProperty("configPathRNN",     m_configPathRNN,                    "Path of the local RNN json file you want o study/test, it will override the PathResolverFindCalibFile file");  
+  declareProperty("configRNNVersion",  m_configRNNVersion,                 "RNN version in cvmfs");  
+  declareProperty("configRNNJsonFile", m_configRNNJsonFile,                "Name of the RNN json file in cvmfs");  
+  declareProperty("debug",             m_debug,                            "Help to debug the RNNTool");
 
-  declareProperty("inputSequenceName", m_inputSequenceName = "Trk_inputs");
-  declareProperty("inputSequenceSize", m_inputSequenceSize = 5); 
+  declareProperty("inputSequenceName", m_inputSequenceName = "Trk_inputs", "Prefix of the variables used in the RNN json file");
+  declareProperty("inputSequenceSize", m_inputSequenceSize = 5,            "Number of tracks used in the RNN"); 
 }
 
 //=============================================================================
 StatusCode Prompt::RNNTool::initialize()
 {
-  ATH_MSG_INFO( "RNNTool::initialize..." << std::endl
-	     << "ConfigPathRNN: \"" << m_configPathRNN);
+  //
+  // Get path to xml training file
+  //
+  std::string fullPathToFile;
+
+  if(!m_configPathRNN.empty()) {
+    ATH_MSG_INFO("Override PathResolver to this path: " << m_configPathRNN);
+    fullPathToFile = m_configPathRNN;
+  }
+  else {
+    fullPathToFile = PathResolverFindCalibFile("JetTagNonPromptLepton/"
+                                               + m_configRNNVersion + "/"
+                                               + m_configRNNJsonFile);
+  }
+
+  ATH_MSG_INFO("initialize RNNTool - ConfigPathRNN: \"" << fullPathToFile);
 
   //
   // Configure RNN
   //
-  std::ifstream input_stream(m_configPathRNN);
+  std::ifstream input_stream(fullPathToFile);
   
   lwt::GraphConfig graph_config = lwt::parse_json_graph(input_stream);  
 
diff --git a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/RNNTool.h b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/RNNTool.h
index 40ef777a136a..766f780bc209 100644
--- a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/RNNTool.h
+++ b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/RNNTool.h
@@ -16,6 +16,9 @@
  * 
  **********************************************************************************/
 
+// Tools
+#include "PathResolver/PathResolver.h"
+
 // Local
 #include "IRNNTool.h"
 #include "VarHolder.h"
@@ -58,6 +61,8 @@ namespace Prompt
   private:    
 
     std::string                              m_configPathRNN;
+    std::string                              m_configRNNVersion;
+    std::string                              m_configRNNJsonFile;
     bool                                     m_debug;
     
     std::string                              m_inputSequenceName;
-- 
GitLab


From b0e035351a93f3e8bd27ffca5a4b6a645780f260 Mon Sep 17 00:00:00 2001
From: Fudong He <fuhe@cern.ch>
Date: Wed, 11 Mar 2020 17:28:44 +0100
Subject: [PATCH 3/4] Add PromptLeptonImprovedVeto to the HIGG3D1

---
 .../DerivationFrameworkHiggs/share/HIGG3D1.py                  | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG3D1.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG3D1.py
index e5d4e3e76547..1e57e866810a 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG3D1.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG3D1.py
@@ -267,7 +267,9 @@ addQGTaggerTool(jetalg="AntiKt4EMPFlow",sequence=higg3d1Seq,algname="QGTaggerToo
 #====================================================================
 # import the JetTagNonPromptLepton config and add to the private sequence
 import JetTagNonPromptLepton.JetTagNonPromptLeptonConfig as JetTagConfig
+import LeptonTaggers.LeptonTaggersConfig as LepTagConfig
 higg3d1Seq += JetTagConfig.GetDecoratePromptLeptonAlgs()
+higg3d1Seq += LepTagConfig.GetDecorateImprovedPromptLeptonAlgs()
 
 #====================================================================
 # Truth decoration tool
@@ -309,6 +311,7 @@ HIGG3D1SlimmingHelper.SmartCollections = ["Electrons",
 HIGG3D1SlimmingHelper.ExtraVariables = list(HIGG3D1ExtraVariables)
 HIGG3D1SlimmingHelper.AllVariables = list(HIGG3D1ExtraContainers)
 HIGG3D1SlimmingHelper.ExtraVariables += JetTagConfig.GetExtraPromptVariablesForDxAOD()
+HIGG3D1SlimmingHelper.ExtraVariables += LepTagConfig.GetExtraImprovedPromptVariablesForDxAOD() 
 
 # needed to calculate electron LH downstream
 from DerivationFrameworkEGamma.ElectronsCPDetailedContent import ElectronsCPDetailedContent, GSFTracksCPDetailedContent
-- 
GitLab


From 1a32e851dcb80d9b811e9127166b372294e1580b Mon Sep 17 00:00:00 2001
From: Fudong He <fuhe@cern.ch>
Date: Fri, 13 Mar 2020 11:25:22 +0100
Subject: [PATCH 4/4] Add new PromptLeptonTagger to HIGG8D1

---
 .../DerivationFrameworkHiggs/share/HIGG8D1.py                  | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG8D1.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG8D1.py
index 4d38f45003da..e77bc27514de 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG8D1.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG8D1.py
@@ -459,6 +459,7 @@ DerivationFrameworkJob += CfgMgr.DerivationFramework__DerivationKernel("HIGG8D1K
 # JetTagNonPromptLepton decorations
 #====================================================================
 import JetTagNonPromptLepton.JetTagNonPromptLeptonConfig as JetTagConfig
+import LeptonTaggers.LeptonTaggersConfig as LepTagConfig
 
 # Build AntiKt4PV0TrackJets and run b-tagging
 JetTagConfig.ConfigureAntiKt4PV0TrackJets(HIGG8D1Seq, 'HIGG8D1')
@@ -466,6 +467,7 @@ JetTagConfig.ConfigureAntiKt4PV0TrackJets(HIGG8D1Seq, 'HIGG8D1')
 # Add BDT decoration algs
 HIGG8D1Seq += JetTagConfig.GetDecoratePromptLeptonAlgs()
 HIGG8D1Seq += JetTagConfig.GetDecoratePromptTauAlgs()
+HIGG8D1Seq += LepTagConfig.GetDecorateImprovedPromptLeptonAlgs() 
 
 DerivationFrameworkJob += HIGG8D1Seq
 
@@ -521,6 +523,7 @@ if StoreAdditionalAmbiguityContent:
 
 HIGG8D1SlimmingHelper.ExtraVariables += JetTagConfig.GetExtraPromptVariablesForDxAOD()
 HIGG8D1SlimmingHelper.ExtraVariables += JetTagConfig.GetExtraPromptTauVariablesForDxAOD()
+HIGG8D1SlimmingHelper.ExtraVariables += LepTagConfig.GetExtraImprovedPromptVariablesForDxAOD() 
 
 ExtraContentTaus=[
         "TauJets."
-- 
GitLab