From 1309cb81bf022df1a1ab50653e6e214b408218d2 Mon Sep 17 00:00:00 2001
From: Jannik Geisen <jannik.geisen@cern.ch>
Date: Fri, 30 Oct 2020 14:54:25 +0100
Subject: [PATCH 1/4] removing commented out lines

---
 .../TrigMonitoring/TrigJetMonitoring/src/HLTJetMonTool.cxx    | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/Trigger/TrigMonitoring/TrigJetMonitoring/src/HLTJetMonTool.cxx b/Trigger/TrigMonitoring/TrigJetMonitoring/src/HLTJetMonTool.cxx
index 2f13237adef7..0ae9e41f7144 100755
--- a/Trigger/TrigMonitoring/TrigJetMonitoring/src/HLTJetMonTool.cxx
+++ b/Trigger/TrigMonitoring/TrigJetMonitoring/src/HLTJetMonTool.cxx
@@ -1966,10 +1966,6 @@ void HLTJetMonTool::fillBasicHLTforChain( const std::string& theChain, double th
           {
             hecfrac = j->getAttribute<float>(xAOD::JetAttribute::HECFrac); 
           }
-
-          //v_thisjet.SetPtEtaPhiE(j->pt()/Gaudi::Units::GeV,j->eta(), j->phi(),j->e()/Gaudi::Units::GeV);
-          //m_v_HLTjet.push_back(v_thisjet);
-          //m_n_index++;
            
           if((h  = hist("HLTJet_Et")))            h->Fill(et,      m_lumi_weight);
           if((h  = hist("HLTJet_HighEt")))        h->Fill(et,      m_lumi_weight);
-- 
GitLab


From 1a4ab12012d07e107a8945090e3ad2e6c4e7f1e9 Mon Sep 17 00:00:00 2001
From: Jannik Geisen <jannik.geisen@cern.ch>
Date: Mon, 18 Jan 2021 08:59:35 +0100
Subject: [PATCH 2/4] Requiring at least any one jet chain to fire in online
 monitoring

---
 .../TrigJetMonitoring/python/TrigJetMonitorAlgorithm.py   | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/Trigger/TrigMonitoring/TrigJetMonitoring/python/TrigJetMonitorAlgorithm.py b/Trigger/TrigMonitoring/TrigJetMonitoring/python/TrigJetMonitorAlgorithm.py
index 8ae8fb4aae1b..674460fff5a3 100644
--- a/Trigger/TrigMonitoring/TrigJetMonitoring/python/TrigJetMonitorAlgorithm.py
+++ b/Trigger/TrigMonitoring/TrigJetMonitoring/python/TrigJetMonitorAlgorithm.py
@@ -1,5 +1,5 @@
 #
-#  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+#  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 #
 
 '''@file MTMonitoring.py
@@ -236,7 +236,7 @@ def basicJetMonAlgSpec(jetcoll,isOnline,athenaMT):
   jetcollFolder = jetcoll
   if jetcoll in JetCollRemapping.JetCollRun2ToRun3 and not athenaMT:
     jetcollFolder = JetCollRemapping.JetCollRun2ToRun3[jetcoll]
-  Conf = JetMonAlgSpec(jetcoll+"Mon",JetContainerName = jetcoll, defaultPath = path, topLevelDir=TopLevelDir, bottomLevelDir=jetcollFolder, failureOnMissingContainer=False)
+  Conf = JetMonAlgSpec(jetcoll+"Mon",JetContainerName = jetcoll, defaultPath = path, TriggerChain="HLT_[1-9]?0?j[0-9]+.*", topLevelDir=TopLevelDir, bottomLevelDir=jetcollFolder, failureOnMissingContainer=False)
 
   # Now start filling the histo spec list    
   Conf.appendHistos(
@@ -270,7 +270,9 @@ def basicJetMonAlgSpec(jetcoll,isOnline,athenaMT):
     SelectSpec( 'forward', '3.2<|eta|', path, FillerTools = ["pt","et","m"] ),
     SelectSpec( 'lowmu', 'avgMu<30', path, isEventVariable=True, FillerTools = ["pt","et","m","phi","eta"]),
     SelectSpec( 'highmu', '30<avgMu', path, isEventVariable=True, FillerTools = ["pt","et","m","phi","eta"]),
-
+    # To select on multiple variables simultaneously, simply combine the selection strings via &
+    # Example below to select on ET > 100 GeV and |eta| > 3.2:
+    # SelectSpec( 'ETeta', '100<et:GeV&|eta|<3.2', path, FillerTools = ["pt","et","m","eta"] )
     EventHistoSpec('njets', (25,0,25), title='NJets;NJets;Entries' ),
     EventHistoSpec('njetsPt20', (25,0,25), title='NJetsPt20;NJetsPt20;Entries' ),
     EventHistoSpec('njetsPt50', (25,0,25), title='NJetsPt50;NJetsPt50;Entries' ),
-- 
GitLab


From 632e079c4af39d83e3901e6956ea5d5ce7052e87 Mon Sep 17 00:00:00 2001
From: Jannik Geisen <jannik.geisen@cern.ch>
Date: Thu, 4 Feb 2021 14:52:10 +0100
Subject: [PATCH 3/4] Fix efficiency curves for smc chains in MT offline
 JetMonitoring

---
 .../JetMonitoring/JetHistoTriggEfficiency.h   |  2 +-
 .../src/JetHistoTriggEfficiency.cxx           | 24 +++++++++++++++----
 .../python/TrigJetMonitorAlgorithm.py         | 16 +++++++------
 3 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetHistoTriggEfficiency.h b/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetHistoTriggEfficiency.h
index 246f83b0b3c0..349507fafb8e 100644
--- a/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetHistoTriggEfficiency.h
+++ b/Reconstruction/Jet/JetMonitoring/JetMonitoring/JetHistoTriggEfficiency.h
@@ -31,9 +31,9 @@ private:
   Gaudi::Property<std::string> m_group {this,"Group", "undefined"};
   Gaudi::Property<std::string> m_probeTrigChain {this, "ProbeTrigChain", "_undefined_"};
   Gaudi::Property<size_t> m_jetIndex {this, "Index",0};
+  Gaudi::Property<bool> m_sortJets {this,"SortJets", false};
   ToolHandle<IJetSelector> m_selectTool;
   ToolHandle<IJetHistoVarTool> m_jetVar;
-
   
   
 };
diff --git a/Reconstruction/Jet/JetMonitoring/src/JetHistoTriggEfficiency.cxx b/Reconstruction/Jet/JetMonitoring/src/JetHistoTriggEfficiency.cxx
index fc8c173bd866..f372f87e2c28 100644
--- a/Reconstruction/Jet/JetMonitoring/src/JetHistoTriggEfficiency.cxx
+++ b/Reconstruction/Jet/JetMonitoring/src/JetHistoTriggEfficiency.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 #include "AthenaMonitoringKernel/GenericMonitoringTool.h"
 #include "JetMonitoring/JetHistoTriggEfficiency.h"
@@ -58,10 +58,24 @@ StatusCode JetHistoTriggEfficiency::processJetContainer(const JetMonitoringAlg&
   const xAOD::Jet* probeJet = nullptr;
   size_t npassed=0;
   bool doJetSelect = m_selectTool.isEnabled();
-  for(const xAOD::Jet* j: jets){
-    if( doJetSelect && !m_selectTool->keep(*j) ) continue;
-    if(npassed==m_jetIndex) {probeJet = j; break; } // found ! 
-    npassed++;
+  if (!m_sortJets) {
+    for(const xAOD::Jet* j: jets){
+      if( doJetSelect && !m_selectTool->keep(*j) ) continue;
+      if(npassed==m_jetIndex) {probeJet = j; break; } // found ! 
+      npassed++;
+    }
+  } else { //first sort jets according to variable passed, then select the nth jet from the sorted container
+    std::list<const xAOD::Jet*> tmpList;
+    for(const xAOD::Jet* j: jets){
+      if( doJetSelect && !m_selectTool->keep(*j) ) continue;
+      tmpList.push_back(j);
+    }
+    auto sort = [this] (const xAOD::Jet * j1, const xAOD::Jet * j2) {return m_jetVar->value(*j1) > m_jetVar->value(*j2); } ;
+    tmpList.sort( sort );
+    for(const xAOD::Jet* j : tmpList ) {
+      if(npassed==m_jetIndex) {probeJet = j; break; } // found ! 
+      npassed++;
+    }
   }
 
   if(probeJet ==nullptr) return StatusCode::SUCCESS;
diff --git a/Trigger/TrigMonitoring/TrigJetMonitoring/python/TrigJetMonitorAlgorithm.py b/Trigger/TrigMonitoring/TrigJetMonitoring/python/TrigJetMonitorAlgorithm.py
index a4768d9d8390..639d406ba6f0 100644
--- a/Trigger/TrigMonitoring/TrigJetMonitoring/python/TrigJetMonitorAlgorithm.py
+++ b/Trigger/TrigMonitoring/TrigJetMonitoring/python/TrigJetMonitorAlgorithm.py
@@ -467,9 +467,10 @@ def jetEfficiencyMonitoringConfig(inputFlags,onlinejetcoll,offlinejetcoll,chain,
    def defineHistoForJetTrigg(conf, parentAlg, monhelper , path):
        # create a monitoring group with the histo path starting from the parentAlg
        group = monhelper.addGroup(parentAlg, conf.Group, conf.topLevelDir+jetcollFolder+'/')
-       # define the histogram
-       group.defineHistogram('trigPassed,jetVar',title='titletrig', type="TEfficiency", path=chainFolder, xbins=10000 , xmin=0, xmax=800000. ,)
-
+       # define the histogram, give them individual names so they don't overwrite each other
+       append = "offlineCut_"+conf.name.split("_")[-1] if "offlineCut" in conf.name else "noOfflineCut"
+       histname = "trigEff_vs_"+conf.Var.Name+"_"+append
+       group.defineHistogram('trigPassed,jetVar;'+histname,title='titletrig', type="TEfficiency", path=chainFolder, xbins=10000 , xmin=0, xmax=800000. ,)
    # Get jet index and eta selection for offline jets
    parts        = chain.split('j')
    multiplicity = parts[0].split('_')[1]
@@ -502,17 +503,18 @@ def jetEfficiencyMonitoringConfig(inputFlags,onlinejetcoll,offlinejetcoll,chain,
 
    if 'smc' in chain:
      trigConf.appendHistos(
-             SelectSpec( 'm50', '50<m', chainFolder, FillerTools = [
-               ToolSpec('JetHistoTriggEfficiency', chain+'_m50',
+             SelectSpec( 'm50', '50<m:GeV&{}<|eta|<{}'.format(etaMin,etaMax), chainFolder, SelectedIndex=index, FillerTools = [
+               ToolSpec('JetHistoTriggEfficiency', chain+'_offlineCut_m50',
                  Group='jetTrigGroup_'+chain+'_m50',
                  Var=retrieveVarToolConf("pt"), # In this context we can not just pass a str alias to describe a histo variable
                  ProbeTrigChain=chain,defineHistoFunc=defineHistoForJetTrigg
                ),
              ] ),
-             SelectSpec( 'et500', '500<et', chainFolder, FillerTools = [
-               ToolSpec('JetHistoTriggEfficiency', chain+'_et500',
+             SelectSpec( 'et500', '500<et:GeV&{}<|eta|<{}'.format(etaMin,etaMax), chainFolder, SelectedIndex=index, FillerTools = [
+               ToolSpec('JetHistoTriggEfficiency', chain+'_offlineCut_et500',
                  Group='jetTrigGroup_'+chain+'_et500',
                  Var=retrieveVarToolConf("m"), # In this context we can not just pass a str alias to describe a histo variable
+                 SortJets=True,
                  ProbeTrigChain=chain,defineHistoFunc=defineHistoForJetTrigg
                ),
              ] ),
-- 
GitLab


From 8859243c0ba00cc2d22eb8477d5a4f8f3b279cf6 Mon Sep 17 00:00:00 2001
From: Jannik Geisen <jannik.geisen@cern.ch>
Date: Thu, 11 Feb 2021 11:55:55 +0100
Subject: [PATCH 4/4] Adopting new a10t JetCollection name for AthenaMT samples
 in Legacy JetMonitoring Tool

---
 .../TrigJetMonitoring/src/HLTJetMonTool.cxx            | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/Trigger/TrigMonitoring/TrigJetMonitoring/src/HLTJetMonTool.cxx b/Trigger/TrigMonitoring/TrigJetMonitoring/src/HLTJetMonTool.cxx
index 2f3eb8ca93da..6e29c5c3c08a 100755
--- a/Trigger/TrigMonitoring/TrigJetMonitoring/src/HLTJetMonTool.cxx
+++ b/Trigger/TrigMonitoring/TrigJetMonitoring/src/HLTJetMonTool.cxx
@@ -1796,7 +1796,7 @@ void HLTJetMonTool::fillBasicHLTforChain( const std::string& theChain, double th
   double count=0;
   std::string chain = Form("HLT_%s",theChain.c_str());
   ATH_MSG_DEBUG("fillBasicHLTforChain CHAIN: " << chain << " passed TDT: " << getTDT()->isPassed(chain));
-  
+
   if (getTDT()->isPassed(chain)) {
 
     if((h  = hist("HLTSigma_vs_LB"))){
@@ -1990,7 +1990,7 @@ void HLTJetMonTool::fillBasicHLTforChain( const std::string& theChain, double th
     } // TriggerElement or TrigComposite
 
     if((h  = hist("HLTJet_n")))            h->Fill(count,      m_lumi_weight);
-     
+
   }// if chain passed
 
   m_v_HLTindex.push_back(m_n_index);
@@ -2011,11 +2011,9 @@ void HLTJetMonTool::fillBasicL1forChain(const std::string& theChain, double thrE
 
   TLorentzVector v_thisjet; //create a 4vector for the single jets in the event
 
-  
 
   if (getTDT()->isPassed(theChain.c_str())){
 
-    
 
     if((h  = hist("L1Sigma_vs_LB"))){
       //   h->GetXaxis()->SetRangeUser(*std::min_element(m_v_lbn.begin(),m_v_lbn.end())-1,*std::max_element(m_v_lbn.begin(),m_v_lbn.end())+1);
@@ -2094,7 +2092,7 @@ void HLTJetMonTool::fillBasicL1forChain(const std::string& theChain, double thrE
     } // l2It
 
     if((h  = hist("L1Jet_n")))           h->Fill(count,m_lumi_weight);
-    
+
   } // L2 chain isPassed
 
   m_v_L1index.push_back(m_n_index);
@@ -3373,7 +3371,7 @@ int HLTJetMonTool::basicKineVar(const std::string& hist, std::vector<std::string
 // ------------------------------------------------------------------------------------
 std::string HLTJetMonTool::GetJetCollectionName(const std::string& theChain) {
   std::string jetcoll = "HLT_AntiKt4EMTopoJets_subjesIS"; //default small-R EMTopo jets
-  if (theChain.find("a10t") != std::string::npos) jetcoll = "HLT_AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets_jes";
+  if (theChain.find("a10t") != std::string::npos) jetcoll = "HLT_AntiKt10LCTopoTrimmedPtFrac4SmallR20Jets_jes";
   else if(theChain.find("a10r") != std::string::npos) jetcoll = "HLT_AntiKt10JetRCJets_subjesIS";
   else if(theChain.find("a10") != std::string::npos) jetcoll = "HLT_AntiKt10LCTopoJets_subjes"; //default large-R jets
   else if(theChain.find("ftf") != std::string::npos) { //EMPFlow jets
-- 
GitLab