From 1f7cf8e9c6a46fd6f7ed575e4f55e67cd9694b99 Mon Sep 17 00:00:00 2001
From: Kenji Hamano <kenji.hamano@cern.ch>
Date: Wed, 8 Apr 2020 10:43:51 +0000
Subject: [PATCH] Met MT mon update

---
 .../python/TrigMETMonitorAlgorithm.py         | 39 ++++++---
 .../src/TrigMETMonitorAlgorithm.cxx           | 85 +++++++++++--------
 .../src/TrigMETMonitorAlgorithm.h             |  7 ++
 3 files changed, 84 insertions(+), 47 deletions(-)

diff --git a/Trigger/TrigMonitoring/TrigMETMonitoring/python/TrigMETMonitorAlgorithm.py b/Trigger/TrigMonitoring/TrigMETMonitoring/python/TrigMETMonitorAlgorithm.py
index 49e817950a8..a478e1d4e31 100644
--- a/Trigger/TrigMonitoring/TrigMETMonitoring/python/TrigMETMonitorAlgorithm.py
+++ b/Trigger/TrigMonitoring/TrigMETMonitoring/python/TrigMETMonitorAlgorithm.py
@@ -33,7 +33,7 @@ def TrigMETMonConfig(inputFlags):
 
     # You can actually make multiple instances of the same algorithm and give 
     # them different configurations
-    TrigMETMonChainAlg = helper.addAlgorithm(CompFactory.TrigMETMonitorAlgorithm,'TrigMETMonChainAlg')
+    TrigMETMonChain1Alg = helper.addAlgorithm(CompFactory.TrigMETMonitorAlgorithm,'TrigMETMonChain1Alg')
 
     # # If for some really obscure reason you need to instantiate an algorithm
     # # yourself, the AddAlgorithm method will still configure the base 
@@ -56,7 +56,7 @@ def TrigMETMonConfig(inputFlags):
     #    HLT_xe0noL1_l2fsperf_pufit_L1gXERHO50,HLT_xe0noL1_l2fsperf_pufit_L1gXEPUFIT50
     # without filters, all events are processed.
     #TrigMETMonAlg.TriggerChain = 'L1_XE10'
-    TrigMETMonChainAlg.TriggerChain = 'HLT_xe30_tcpufit_L1XE10'
+    TrigMETMonChain1Alg.TriggerChain = 'HLT_xe65_cell_L1XE50'
     
 
     ### use the follwoing if you run on Run2 AOD
@@ -69,6 +69,13 @@ def TrigMETMonConfig(inputFlags):
     #TrigMETMonAlg.hlt_tcpufit_key = 'HLT_MET_tcPufit'
     #TrigMETMonAlg.hlt_trkmht_key = 'HLT_MET_mht'
        
+    ### set chain names
+    ### These are the active chains as of 01 April 2020 for testing 
+    #TrigMETMonAlg.L1Chain1 = 'L1_XE10'
+    #TrigMETMonAlg.HLTChain1 = 'HLT_xe65_cell_L1XE50'
+    #TrigMETMonAlg.HLTChain2 = 'HLT_xe100_tcpufit_L1XE50'
+    TrigMETMonAlg.HLTChain2 = 'HLT_xe100_trkmht_L1XE50'
+    #TrigMETMonAlg.HLTChain2 = 'HLT_xe100_pfsum_L1XE50'
 
 
     ### STEP 4 ###
@@ -89,7 +96,7 @@ def TrigMETMonConfig(inputFlags):
     metGroup = helper.addGroup(TrigMETMonAlg,'TrigMETMonitor','HLT/METMon/')
 
     # Add a GMT for the other example monitor algorithm
-    metChainGroup = helper.addGroup(TrigMETMonChainAlg,'TrigMETMonitor','HLT/METMon/Chain/')
+    metChain1Group = helper.addGroup(TrigMETMonChain1Alg,'TrigMETMonitor','HLT/METMon/HLT_xe65_cell_L1XE50/')
 
     ### STEP 5 ###
     # Configure histograms
@@ -120,6 +127,14 @@ def TrigMETMonConfig(inputFlags):
     eff_min=-13.5
     eff_max=401.5
     # Histograms
+    metGroup.defineHistogram('offline_Ex',title='Offline Missing E_{x};E_{x} [GeV];Events',
+                             path='Expert/Offline',xbins=ec_bins,xmin=ec_min,xmax=ec_max)
+    metGroup.defineHistogram('offline_Ey',title='Offline Missing E_{y};E_{y} [GeV];Events',
+                             path='Expert/Offline',xbins=ec_bins,xmin=ec_min,xmax=ec_max)
+    metGroup.defineHistogram('offline_Et',title='Offline Missing E_{T};E_{T} [GeV];Events',                            
+                             path='Expert/Offline',xbins=et_bins,xmin=et_min,xmax=et_max)
+    metGroup.defineHistogram('offline_sumEt',title='Offline sumE_{T};sumE_{T} [GeV];Events',
+                             path='Expert/Offline',xbins=sumet_bins,xmin=sumet_min,xmax=sumet_max)
     metGroup.defineHistogram('L1_Ex',title='L1 Missing E_{x};E_{x} [GeV];Events',
                              path='Shifter/L1',xbins=ec_bins,xmin=ec_min,xmax=ec_max)
     metGroup.defineHistogram('L1_Ey',title='L1 Missing E_{y};E_{y} [GeV];Events',
@@ -160,7 +175,11 @@ def TrigMETMonConfig(inputFlags):
     metGroup.defineHistogram('tcpufit_eta,tcpufit_phi;tcpufit_eta_phi', type='TH2F', title='tcpufit #eta - #phi;#eta;#phi',
                              path='Shifter/tcpufit',
                              xbins=eta_bins_2d,xmin=eta_min,xmax=eta_max,ybins=phi_bins_2d,ymin=phi_min,ymax=phi_max)
-    metGroup.defineHistogram('L1_Et,pass_HLT1;L1_eff', type='TProfile',title='L1 efficiency;E_{T} [GeV];Efficiency',
+    metGroup.defineHistogram('offline_Et,pass_L11;L11_eff', type='TProfile',title='L1 efficiency;offline E_{T} [GeV];Efficiency',
+                             path='Shifter/eff',xbins=eff_bins,xmin=eff_min,xmax=eff_max)
+    metGroup.defineHistogram('offline_Et,pass_HLT1;HLT1_eff', type='TProfile',title='HLT1 efficiency;offline E_{T} [GeV];Efficiency',
+                             path='Shifter/eff',xbins=eff_bins,xmin=eff_min,xmax=eff_max)
+    metGroup.defineHistogram('offline_Et,pass_HLT2;HLT2_eff', type='TProfile',title='HLT2 efficiency;offline E_{T} [GeV];Efficiency',
                              path='Shifter/eff',xbins=eff_bins,xmin=eff_min,xmax=eff_max)
     metGroup.defineHistogram('mht_Ex',title='mht Missing E_{x};E_{x} [GeV];Events',
                              path='Expert/mht',xbins=ec_bins,xmin=ec_min,xmax=ec_max)
@@ -174,12 +193,12 @@ def TrigMETMonConfig(inputFlags):
                              path='Expert/tc',xbins=ec_bins,xmin=ec_min,xmax=ec_max)
     metGroup.defineHistogram('tc_Et', title='tc E_{T};E_{T} [GeV];Events',
                              path='Expert/tc',xbins=et_bins,xmin=et_min,xmax=et_max)
-    metChainGroup.defineHistogram('tcpufit_Ex',title='tcpufit Missing E_{x};E_{x} [GeV];Events',
-                                  path='HLT_xe30_tcpufit_L1XE10/tcpufit',xbins=ec_bins,xmin=ec_min,xmax=ec_max)
-    metChainGroup.defineHistogram('tcpufit_Ey',title='tcpufit Missing E_{y};E_{y} [GeV];Events',
-                                  path='HLT_xe30_tcpufit_L1XE10/tcpufit',xbins=ec_bins,xmin=ec_min,xmax=ec_max)
-    metChainGroup.defineHistogram('tcpufit_Et',title='tcpufit Missing E_{T};E_{T} [GeV];Events',
-                                  path='HLT_xe30_tcpufit_L1XE10/tcpufit',xbins=et_bins,xmin=et_min,xmax=et_max)
+    metChain1Group.defineHistogram('cell_Ex',title='cell Missing E_{x};E_{x} [GeV];Events',
+                                  path='cell',xbins=ec_bins,xmin=ec_min,xmax=ec_max)
+    metChain1Group.defineHistogram('cell_Ey',title='cell Missing E_{y};E_{y} [GeV];Events',
+                                  path='cell',xbins=ec_bins,xmin=ec_min,xmax=ec_max)
+    metChain1Group.defineHistogram('cell_Et',title='cell Missing E_{T};E_{T} [GeV];Events',
+                                  path='cell',xbins=et_bins,xmin=et_min,xmax=et_max)
     
     ### STEP 6 ###
     # Finalize. The return value should be a tuple of the ComponentAccumulator
diff --git a/Trigger/TrigMonitoring/TrigMETMonitoring/src/TrigMETMonitorAlgorithm.cxx b/Trigger/TrigMonitoring/TrigMETMonitoring/src/TrigMETMonitorAlgorithm.cxx
index 7d4729da0e9..7e133180a33 100644
--- a/Trigger/TrigMonitoring/TrigMETMonitoring/src/TrigMETMonitorAlgorithm.cxx
+++ b/Trigger/TrigMonitoring/TrigMETMonitoring/src/TrigMETMonitorAlgorithm.cxx
@@ -7,6 +7,7 @@
 
 TrigMETMonitorAlgorithm::TrigMETMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
   : AthMonitorAlgorithm(name,pSvcLocator)
+  , m_offline_met_key("MET_EMTopo")
   , m_lvl1_roi_key("LVL1EnergySumRoI")
   , m_hlt_cell_met_key("HLT_MET_cell")
   , m_hlt_mht_met_key("HLT_MET_mht")
@@ -15,12 +16,17 @@ TrigMETMonitorAlgorithm::TrigMETMonitorAlgorithm( const std::string& name, ISvcL
   , m_hlt_trkmht_met_key("HLT_MET_trkmht")
   , m_trigDecTool("Trig::TrigDecisionTool/TrigDecisionTool")
 {
+  declareProperty("offline_met_key", m_offline_met_key);
   declareProperty("l1_roi_key", m_lvl1_roi_key);
   declareProperty("hlt_cell_key", m_hlt_cell_met_key);
   declareProperty("hlt_mht_key", m_hlt_mht_met_key);
   declareProperty("hlt_tc_key", m_hlt_tc_met_key);
   declareProperty("hlt_tcpufit_key", m_hlt_tcpufit_met_key);
   declareProperty("hlt_trkmht_key", m_hlt_trkmht_met_key);
+
+  declareProperty("L1Chain1", m_L1Chain1="L1_XE50");
+  declareProperty("HLTChain1", m_HLTChain1="HLT_xe65_cell_L1XE50");
+  declareProperty("HLTChain2", m_HLTChain2="HLT_xe100_tcpuft_L1XE50");
 }
 
 
@@ -28,6 +34,7 @@ TrigMETMonitorAlgorithm::~TrigMETMonitorAlgorithm() {}
 
 
 StatusCode TrigMETMonitorAlgorithm::initialize() {
+    ATH_CHECK( m_offline_met_key.initialize() );
     ATH_CHECK( m_lvl1_roi_key.initialize() );
     ATH_CHECK( m_hlt_cell_met_key.initialize() );
     ATH_CHECK( m_hlt_mht_met_key.initialize() );
@@ -45,6 +52,11 @@ StatusCode TrigMETMonitorAlgorithm::fillHistograms( const EventContext& ctx ) co
     using namespace Monitored;
 
     // access met containers
+    SG::ReadHandle<xAOD::MissingETContainer> offline_met_cont(m_offline_met_key, ctx);
+    if (offline_met_cont->size()==0 || ! offline_met_cont.isValid() ) {
+      ATH_MSG_DEBUG("Container "<< m_offline_met_key << " does not exist or is empty");
+    }
+
     SG::ReadHandle<xAOD::EnergySumRoI> l1_roi_cont(m_lvl1_roi_key, ctx);
     if (! l1_roi_cont.isValid() ) {     
       ATH_MSG_DEBUG("Container "<< m_lvl1_roi_key << " does not exist or is empty");
@@ -75,10 +87,18 @@ StatusCode TrigMETMonitorAlgorithm::fillHistograms( const EventContext& ctx ) co
 	ATH_MSG_DEBUG("Container "<< m_hlt_trkmht_met_key << " does not exist or is empty");
     }
    
+
+    // define offline MissingET object
+    const xAOD::MissingET *offline_met = 0;
+
     // define TrigMissingET object
     const xAOD::TrigMissingET *hlt_met = 0;
 
     // define variables
+    auto offline_Ex = Monitored::Scalar<float>("offline_Ex",0.0);
+    auto offline_Ey = Monitored::Scalar<float>("offline_Ey",0.0);
+    auto offline_Et = Monitored::Scalar<float>("offline_Et",0.0);
+    auto offline_sumEt = Monitored::Scalar<float>("offline_sumEt",0.0);
     auto L1_Ex = Monitored::Scalar<float>("L1_Ex",0.0);
     auto L1_Ey = Monitored::Scalar<float>("L1_Ey",0.0);
     auto L1_Et = Monitored::Scalar<float>("L1_Et",0.0);
@@ -102,7 +122,18 @@ StatusCode TrigMETMonitorAlgorithm::fillHistograms( const EventContext& ctx ) co
     auto tcpufit_sumE = Monitored::Scalar<float>("tcpufit_sumE",0.0);
     auto tcpufit_eta = Monitored::Scalar<float>("tcpufit_eta",0.0);
     auto tcpufit_phi = Monitored::Scalar<float>("tcpufit_phi",0.0);
+    auto pass_L11 = Monitored::Scalar<float>("pass_L11",0.0);
     auto pass_HLT1 = Monitored::Scalar<float>("pass_HLT1",0.0);
+    auto pass_HLT2 = Monitored::Scalar<float>("pass_HLT2",0.0);
+
+    // access offline MET values
+    if ( offline_met_cont->size() > 0 && offline_met_cont.isValid() ) {
+      offline_met = offline_met_cont->at(0);
+      offline_Ex = - (offline_met->mpx())/1000.;
+      offline_Ey = - (offline_met->mpy())/1000.;
+      offline_sumEt = (offline_met->sumet())/1000.;
+      offline_Et = sqrt(offline_Ex*offline_Ex + offline_Ey*offline_Ey);
+    }
 
     // access L1 MET values
     if ( l1_roi_cont.isValid() ) {
@@ -161,34 +192,13 @@ StatusCode TrigMETMonitorAlgorithm::fillHistograms( const EventContext& ctx ) co
     }
 
     // efficiency plots
-    // temporary fake trigger decision
-    if (L1_Et > 150.) pass_HLT1 = 1.0; 
-    ATH_MSG_DEBUG("pass_HLT1 = " << pass_HLT1);
-    // will be replaced by below
-    //if (m_trigDecTool->isPassed("HLT_xe30_cell_L1XE10")) pass_HLT1 = 1.0;
-
-    // TDT test
-    ATH_MSG_DEBUG("MetMon: TST test");
-    if (m_trigDecTool->isPassed("L1_XE10")) {
-      ATH_MSG_DEBUG("passed L1_XE10");
-    } else {
-      ATH_MSG_DEBUG("not passed L1_XE10");
-    }
-    if (m_trigDecTool->isPassed("HLT_xe30_cell_L1XE10")) {
-      ATH_MSG_DEBUG("passed HLT_xe30_cell_L1XE10");
-    } else {
-      ATH_MSG_DEBUG("not passed HLT_xe30_cell_L1XE10");
-    }
-    if (m_trigDecTool->isPassed("HLT_xe30_tcpufit_L1XE10")) {
-      ATH_MSG_DEBUG("passed HLT_xe30_tcpufit_L1XE10");
-    } else {
-      ATH_MSG_DEBUG("not passed HLT_xe30_tcpufit_L1XE10");
-    }
-    if (m_trigDecTool->isPassed("HLT_xe30_cell_xe30_tcpufit_L1XE10")) {
-      ATH_MSG_DEBUG("passed HLT_xe30_cell_xe30_tcpufit_L1XE10");
-    } else {
-      ATH_MSG_DEBUG("not passed HLT_xe30_cell_xe30_tcpufit_L1XE10");
-    }
+    if (m_trigDecTool->isPassed(m_L1Chain1)) pass_L11 = 1.0;
+    if (m_trigDecTool->isPassed(m_HLTChain1)) pass_HLT1 = 1.0;
+    if (m_trigDecTool->isPassed(m_HLTChain2)) pass_HLT2 = 1.0;
+    ATH_MSG_DEBUG("pass " << m_L1Chain1 << " = " << pass_L11);
+    ATH_MSG_DEBUG("pass " << m_HLTChain1 << " = " << pass_HLT1);
+    ATH_MSG_DEBUG("pass " << m_HLTChain2 << " = " << pass_HLT2);
+
 
     // check active triggers
     // This does not work for now
@@ -204,17 +214,18 @@ StatusCode TrigMETMonitorAlgorithm::fillHistograms( const EventContext& ctx ) co
 
     // Fill. First argument is the tool (GMT) name as defined in the py file, 
     // all others are the variables to be saved.
-    fill("TrigMETMonitor",L1_Ex,L1_Ey,L1_Et);
-
+    //fill("TrigMETMonitor",L1_Ex,L1_Ey,L1_Et,pass_HLT1);
     // Alternative fill method. Get the group yourself, and pass it to the fill function.
     auto tool = getGroup("TrigMETMonitor");
-    fill(tool,cell_Ex,cell_Ey,cell_Et);
-    fill(tool,mht_Ex,mht_Ey,mht_Et);
-    fill(tool,tc_Ex,tc_Ey,tc_Et);
-    fill(tool,trkmht_Ex,trkmht_Ey,trkmht_Et);
-    fill(tool,tcpufit_Ex,tcpufit_Ey,tcpufit_Ez,tcpufit_Et,tcpufit_sumEt,tcpufit_sumE);
-    fill(tool,tcpufit_eta,tcpufit_phi);
-    fill(tool,pass_HLT1);
+    fill(tool,offline_Ex,offline_Ey,offline_Et,offline_sumEt,
+         L1_Ex,L1_Ey,L1_Et,
+         pass_L11,pass_HLT1,pass_HLT2,
+         cell_Ex,cell_Ey,cell_Et,
+         mht_Ex,mht_Ey,mht_Et,
+         tc_Ex,tc_Ey,tc_Et,
+         trkmht_Ex,trkmht_Ey,trkmht_Et,
+         tcpufit_Ex,tcpufit_Ey,tcpufit_Ez,tcpufit_Et,
+         tcpufit_sumEt,tcpufit_sumE,tcpufit_eta,tcpufit_phi);
 
     return StatusCode::SUCCESS;
 }
diff --git a/Trigger/TrigMonitoring/TrigMETMonitoring/src/TrigMETMonitorAlgorithm.h b/Trigger/TrigMonitoring/TrigMETMonitoring/src/TrigMETMonitorAlgorithm.h
index 919f9d3ce91..f0d1cb5b602 100644
--- a/Trigger/TrigMonitoring/TrigMETMonitoring/src/TrigMETMonitorAlgorithm.h
+++ b/Trigger/TrigMonitoring/TrigMETMonitoring/src/TrigMETMonitorAlgorithm.h
@@ -9,6 +9,7 @@
 #include "AthenaMonitoringKernel/Monitored.h"
 
 #include "StoreGate/ReadHandleKey.h"
+#include "xAODMissingET/MissingETContainer.h"
 #include "xAODTrigger/EnergySumRoI.h" 
 #include "xAODTrigMissingET/TrigMissingETContainer.h" 
 #include "xAODTrigMissingET/TrigMissingETAuxContainer.h" 
@@ -23,6 +24,8 @@ class TrigMETMonitorAlgorithm : public AthMonitorAlgorithm {
   virtual StatusCode fillHistograms( const EventContext& ctx ) const override;
 
  private:
+  SG::ReadHandleKey<xAOD::MissingETContainer> m_offline_met_key;
+
   SG::ReadHandleKey<xAOD::EnergySumRoI> m_lvl1_roi_key;
 
   SG::ReadHandleKey<xAOD::TrigMissingETContainer> m_hlt_cell_met_key;
@@ -31,6 +34,10 @@ class TrigMETMonitorAlgorithm : public AthMonitorAlgorithm {
   SG::ReadHandleKey<xAOD::TrigMissingETContainer> m_hlt_tcpufit_met_key;
   SG::ReadHandleKey<xAOD::TrigMissingETContainer> m_hlt_trkmht_met_key;
 
+  std::string m_L1Chain1;
+  std::string m_HLTChain1;
+  std::string m_HLTChain2;
+
   ToolHandle<Trig::ITrigDecisionTool> m_trigDecTool;
   
 
-- 
GitLab