From da1204680ac779f7b9e638a5c42999e4297d9b52 Mon Sep 17 00:00:00 2001
From: Janik von Ahnen <janik.von.ahnen@cern.ch>
Date: Tue, 26 Jan 2021 00:26:14 +0100
Subject: [PATCH 1/8] Adding UFO calibration, new CDI, fixing Xbb cut

---
 XAMPPmonoH/Root/MonoHAnalysisConfig.cxx | 54 ++++++++++++-------------
 XAMPPmonoH/Root/MonoHJetSelector.cxx    | 31 +++++---------
 XAMPPmonoH/data/SUSYTools_MonoH.conf    | 31 ++++++++------
 XAMPPmonoH/share/MonoHToolSetup.py      | 29 +++++++++++--
 XAMPPmonoH/share/runMonoH.py            |  2 +-
 5 files changed, 83 insertions(+), 64 deletions(-)

diff --git a/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx b/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx
index f544451..5d64ed5 100644
--- a/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx
+++ b/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx
@@ -247,10 +247,31 @@ namespace XAMPP {
         if (!OneFatJet->initialize("N_Jets10", ">=1")) return StatusCode::FAILURE;
         SRMergedCutFlow.push_back(OneFatJet);
 
-        // At least one b-tagged associated track jet
+        // At least two associated track jets
+        Cut* N_associated_trkJets_geq2 = NewCut("N_associated_trkJets>=2", Cut::CutType::CutInt, m_doFullSkimming);
+        if (!N_associated_trkJets_geq2->initialize("N_associated_Jets02", ">=2")) return StatusCode::FAILURE;
+        // SRMergedCutFlow.push_back(N_associated_trkJets_geq2);
+
+        // The leading two track jet should pass the OR
+        Cut* TrackJet_1passOR = NewCut("TrackJet_1passOR = true", Cut::CutType::CutBool, m_doproduction);
+        if (!TrackJet_1passOR->initialize("TrackJet_1passOR", "== true")) return StatusCode::FAILURE;
+        Cut* TrackJet_2passOR = NewCut("TrackJet_2passOR = true", Cut::CutType::CutBool, m_doproduction);
+        if (!TrackJet_2passOR->initialize("TrackJet_2passOR", "== true")) return StatusCode::FAILURE;
+        Cut* TrackJet_passOR = TrackJet_1passOR->combine(TrackJet_2passOR, Cut::Combine::AND);
+        // SRMergedCutFlow.push_back(TrackJet_passOR);
+
+        // At least two b-tagged associated track jet OR large R jet passes loosest Xbb score for 25% anti topness
         Cut* NbtaggedTrkJets_geq2 = NewCut(">= 2 b-tagged track jets", Cut::CutType::CutInt, m_doproduction);
         if (!NbtaggedTrkJets_geq2->initialize("N_BTags_associated_02", ">= 2")) return StatusCode::FAILURE;
-        SRMergedCutFlow.push_back(NbtaggedTrkJets_geq2);
+
+        Cut* trkJet_cuts=N_associated_trkJets_geq2->combine(TrackJet_passOR, Cut::Combine::AND)->combine(NbtaggedTrkJets_geq2, Cut::Combine::AND);
+
+        Cut* largeR_Xbb_AT25_80WP = NewCut("Large R Xbb AT25 80WP tagged", Cut::CutType::CutFloat, m_doproduction);
+        if (!largeR_Xbb_AT25_80WP->initialize("NNXbb_CombScore_25", ">= 1.2")) return StatusCode::FAILURE;
+
+        Cut* largeR_btagging = trkJet_cuts->combine(largeR_Xbb_AT25_80WP, Cut::Combine::OR);
+
+        SRMergedCutFlow.push_back(largeR_btagging);
 
         // mJ > 40 GeV
         Cut* HiggsMassMerged = NewCut("mJ > 40", Cut::CutType::CutFloat, false);
@@ -291,19 +312,6 @@ namespace XAMPP {
 
         // common merged event selection cuts
 
-        // At least two associated track jets
-        Cut* N_associated_trkJets_geq2 = NewCut("N_associated_trkJets>=2", Cut::CutType::CutInt, m_doFullSkimming);
-        if (!N_associated_trkJets_geq2->initialize("N_associated_Jets02", ">=2")) return StatusCode::FAILURE;
-        SRMergedCutFlow.push_back(N_associated_trkJets_geq2);
-
-        // The leading two track jet should pass the OR
-        Cut* TrackJet_1passOR = NewCut("TrackJet_1passOR = true", Cut::CutType::CutBool, m_doFullSkimming);
-        if (!TrackJet_1passOR->initialize("TrackJet_1passOR", "== true")) return StatusCode::FAILURE;
-        Cut* TrackJet_2passOR = NewCut("TrackJet_2passOR = true", Cut::CutType::CutBool, m_doFullSkimming);
-        if (!TrackJet_2passOR->initialize("TrackJet_2passOR", "== true")) return StatusCode::FAILURE;
-        Cut* TrackJet_passOR = TrackJet_1passOR->combine(TrackJet_2passOR, Cut::Combine::AND);
-        SRMergedCutFlow.push_back(TrackJet_passOR);
-
         // common merged anti-QCD cuts
         SRMergedCutFlow.push_back(DeltaPhiMin);
 
@@ -437,15 +445,13 @@ namespace XAMPP {
         if (!MetTSTGreater500lepInvis->initialize("MetTSTlepInvis", ">500000.")) return StatusCode::FAILURE;
         CR1MergedCutFlow.push_back(MetTSTGreater500lepInvis);
         CR1MergedCutFlow.push_back(OneFatJet);
-        CR1MergedCutFlow.push_back(NbtaggedTrkJets_geq2);
+        CR1MergedCutFlow.push_back(largeR_btagging);
         CR1MergedCutFlow.push_back(HiggsMassMerged->combine(HiggsMassMergedCorr, Cut::Combine::OR));
 
         // non-skimming cuts
         // --------------------------------------------------------------------
 
         CR1MergedCutFlow.push_back(HiggsMassWindowMerged);
-        CR1MergedCutFlow.push_back(N_associated_trkJets_geq2);
-        CR1MergedCutFlow.push_back(TrackJet_passOR);
 
         // TODO: Check if we need that anti-QCD cut in the merged region
         CR1MergedCutFlow.push_back(DeltaPhiMin);
@@ -698,7 +704,7 @@ namespace XAMPP {
         CR2EleMergedCutFlow.push_back(MetTSTGreater500lepInvis);
         CR2EleMergedCutFlow.push_back(OneFatJet);
         // at least 1 b-tagged track jets
-        CR2EleMergedCutFlow.push_back(NbtaggedTrkJets_geq2);
+        CR2EleMergedCutFlow.push_back(largeR_btagging);
         CR2EleMergedCutFlow.push_back(HiggsMassMerged->combine(HiggsMassMergedCorr, Cut::Combine::OR));
 
         // non-skimming cuts
@@ -706,8 +712,6 @@ namespace XAMPP {
 
         CR2EleMergedCutFlow.push_back(HiggsMassWindowMerged);
 
-        CR2EleMergedCutFlow.push_back(N_associated_trkJets_geq2);
-        CR2EleMergedCutFlow.push_back(TrackJet_passOR);
 
         if (m_doCONFselection) {
             // ****************************************
@@ -747,7 +751,7 @@ namespace XAMPP {
         // METlepInvis > 500 GeV, i.e. MET with either mumu or ee pair set as invisible in MET calculation
         CR2MuoMergedCutFlow.push_back(MetTSTGreater500lepInvis);
         CR2MuoMergedCutFlow.push_back(OneFatJet);
-        CR2MuoMergedCutFlow.push_back(NbtaggedTrkJets_geq2);
+        CR2MuoMergedCutFlow.push_back(largeR_btagging);
         CR2MuoMergedCutFlow.push_back(HiggsMassMerged->combine(HiggsMassMergedCorr, Cut::Combine::OR));
 
         // non-skimming cuts
@@ -755,8 +759,6 @@ namespace XAMPP {
 
         CR2MuoMergedCutFlow.push_back(HiggsMassWindowMerged);
 
-        CR2MuoMergedCutFlow.push_back(N_associated_trkJets_geq2);
-        CR2MuoMergedCutFlow.push_back(TrackJet_passOR);
 
         if (m_doCONFselection) {
             // ****************************************
@@ -891,7 +893,7 @@ namespace XAMPP {
         // Same as above
         CREMuMergedCutFlow.push_back(MetTSTGreater500lepInvis->combine(MetTSTGreater500, Cut::Combine::OR));
         CREMuMergedCutFlow.push_back(OneFatJet);
-        CREMuMergedCutFlow.push_back(NbtaggedTrkJets_geq2);
+        CREMuMergedCutFlow.push_back(largeR_btagging);
         CREMuMergedCutFlow.push_back(HiggsMassMerged->combine(HiggsMassMergedCorr, Cut::Combine::OR));
 
         // non-skimming cuts
@@ -899,8 +901,6 @@ namespace XAMPP {
 
         // mass window used in fit
         CREMuMergedCutFlow.push_back(HiggsMassWindowMerged);
-        CREMuMergedCutFlow.push_back(N_associated_trkJets_geq2);
-        CREMuMergedCutFlow.push_back(TrackJet_passOR);
 
         if (m_doCONFselection) {
             // ****************************************
diff --git a/XAMPPmonoH/Root/MonoHJetSelector.cxx b/XAMPPmonoH/Root/MonoHJetSelector.cxx
index 03b61d2..b6c6bcf 100644
--- a/XAMPPmonoH/Root/MonoHJetSelector.cxx
+++ b/XAMPPmonoH/Root/MonoHJetSelector.cxx
@@ -20,10 +20,9 @@ namespace XAMPP {
         m_Kt04_ForwardJetMinEta(2.5),
         m_Kt04_ForwardJetMaxEta(4.5),
         m_Kt04_ForwardJetMinPt(30000.),  // MeV
-        m_R10name("AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets"),
-        // m_R10name("AntiKt10UFOCSSKSoftDropBeta100Zcut10"),
-        m_R02name("AntiKt2PV0TrackJets"),
-        m_R02linkname("GhostAntiKt2TrackJet"),
+        m_R10name(""),
+        m_R02name(""),
+        m_R02linkname(""),
         m_R10PreSelJets(nullptr),
         m_R10BaselineJets(nullptr),
         m_R02PreSelJets(nullptr),
@@ -41,6 +40,7 @@ namespace XAMPP {
         declareProperty("forwardJetMinEta", m_Kt04_ForwardJetMinEta);
         declareProperty("forwardJetMaxEta", m_Kt04_ForwardJetMaxEta);
         declareProperty("forwardJetMinPt", m_Kt04_ForwardJetMinPt);  // MeV
+        declareProperty("LargeRJetContainer", m_R10name);
         declareProperty("TrackJetContainer", m_R02name);
         declareProperty("AssociatedObjectsContainer", m_R02linkname);
         declareProperty("TrackJetBTagEfficiencyTool", m_TrkJet_bTagEffTool);
@@ -265,7 +265,7 @@ namespace XAMPP {
         }
 
         // decorate the fatjet with NN Xbb tagger scores
-        if (m_R02name == "AntiKtVR30Rmax4Rmin02TrackJets") { m_hbbTagTool->decorate(*m_R10BaselineJets); }
+        m_hbbTagTool->decorate(*m_R10BaselineJets);
 
         // decorate the scores and the tagging info to fatjets
         ATH_CHECK(FillBtaggingForFatJetWithNNXbb(m_R10BaselineJets));
@@ -283,21 +283,12 @@ namespace XAMPP {
             dec_n_matchedasstrkjets(*ijet) = 0;
             int n_matchedasstrkjets = 0;
             const xAOD::Jet* ParentJet = nullptr;
-            if (m_R02name == "AntiKt2PV0TrackJets") {
-                ParentJet = GetParentJet(ijet);
-                if (!ParentJet) continue;
-                if (!ParentJet->getAssociatedObjects<xAOD::Jet>(m_R02linkname, AssociatedTrackJets)) {
-                    ATH_MSG_ERROR("No ghost-matched track-jets found on parent jet.");
-                    return StatusCode::FAILURE;
-                }
-            }
-            if (m_R02name == "AntiKtVR30Rmax4Rmin02TrackJets") {
-                ParentJet = GetParentJet(ijet);
-                if (!ParentJet) continue;
-                if (!ParentJet->getAssociatedObjects<xAOD::Jet>(m_R02linkname, AssociatedTrackJets)) {
-                    ATH_MSG_ERROR("No ghost-matched track-jets found on parent jet.");
-                    return StatusCode::FAILURE;
-                }
+            ParentJet = GetParentJet(ijet);
+            if (!ParentJet)
+                continue;
+            if (!ParentJet->getAssociatedObjects<xAOD::Jet>(m_R02linkname, AssociatedTrackJets)) {
+                ATH_MSG_ERROR("No ghost-matched track-jets found on parent jet.");
+                return StatusCode::FAILURE;
             }
             for (const auto& tk02 : *m_R02BaselineJets) {
                 if (!PassBaseline(*tk02)) {
diff --git a/XAMPPmonoH/data/SUSYTools_MonoH.conf b/XAMPPmonoH/data/SUSYTools_MonoH.conf
index ca1380b..49adb38 100755
--- a/XAMPPmonoH/data/SUSYTools_MonoH.conf
+++ b/XAMPPmonoH/data/SUSYTools_MonoH.conf
@@ -57,20 +57,27 @@ Jet.Eta: 2.5
 Jet.InputType: 9 # EMTopo 1, PFlow: 9
 Jet.JvtWP: Tight
 Jet.JvtPtMax: 120.0e3
-Jet.UncertConfig: rel21/Fall2018/R4_CategoryReduction_SimpleJER.config
+Jet.UncertConfig: rel21/Summer2019/R4_CategoryReduction_SimpleJER.config # https://twiki.cern.ch/twiki/bin/view/AtlasProtected/JetUncertaintiesRel21Summer2018SmallR
+
 #
 FwdJet.doJVT: false
 FwdJet.JvtEtaMin: 2.5
 FwdJet.JvtPtMax: 50e3
 #
-Jet.LargeRcollection: AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets
-Jet.LargeRuncConfig: rel21/Spring2019/R10_CategoryReduction.config
-# Jet.LargeRcollection: AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets
-# Jet.LargeRuncConfig: rel21/Summer2019/R10_CategoryReduction.config # https://twiki.cern.ch/twiki/bin/view/AtlasProtected/JetUncertaintiesRel21Summer2019LargeR
-# Jet.JESConfigFat: JES_MC16recommendation_R10_UFO_CSSK_SoftDrop_JMS_01April2020.config
-# Jet.JESConfigFatData: None # Not yet available
-# Jet.CalibSeqFat: EtaJES_JMS
-# Jet.UncertCalibArea: 00-04-82/
+
+# Large R jets used in MonoH
+
+# Jet.LargeRcollection: AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets
+# Jet.LargeRuncConfig: rel21/Spring2019/R10_CategoryReduction.config
+
+# New UFO large R jets
+
+Jet.LargeRcollection: AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets
+Jet.LargeRuncConfig: None # UFO jets are not jet supported by the jet uncertainty tool. https://twiki.cern.ch/twiki/bin/view/AtlasProtected/JetUncertaintiesRel21Summer2019LargeR
+Jet.JESConfigFat: JES_MC16recommendation_R10_UFO_CSSK_SoftDrop_JMS_01April2020.config
+Jet.JESConfigFatData: None # Not yet available
+Jet.CalibSeqFat: EtaJES_JMS
+
 #Jet.LargeRuncVars: pT,mass,D2Beta1,Tau21WTA,Tau32WTA
 Jet.WtaggerConfig: None
 Jet.ZtaggerConfig: None
@@ -88,17 +95,17 @@ Btag.enable: true
 Btag.Tagger: DL1 # DL1, DL1mu, DL1rnn, MV2c10mu, MV2c10rnn, MC2cl100_MV2c100
 Btag.WP: FixedCutBEff_77
 Btag.SystStrategy: SFEigen
-Btag.TimeStamp: 201810
+Btag.TimeStamp: 201903 # 201810 (DL1) for old training (used in MonoHbb) and 201903 (DL1r) for new training
 Btag.MinPt: 20000. # not calibrated below 20 GeV
 # custom VHbb CDI file (fixed MC to MC SF)
 # XAMPPmonoH/CDI/boosted-CDI-20-02-2019.root
 # official file (potentially containing problematic MC to MC SF)
-Btag.CalibPath: xAODBTaggingEfficiency/13TeV/2019-21-13TeV-MC16-CDI-2019-10-07_v1.root
+Btag.CalibPath: xAODBTaggingEfficiency/13TeV/2020-21-13TeV-MC16-CDI-2020-12-02_v2.root
 #
 # option to set different tagger and WP for track jets
 BtagTrkJet.Tagger: DL1
 BtagTrkJet.WP: FixedCutBEff_77
-BtagTrkJet.TimeStamp: None # new training: 201903
+BtagTrkJet.TimeStamp: 201903 # 201810 (DL1) for old training (used in MonoHbb) and 201903 (DL1r) for new training
 BtagTrkJet.MinPt: 10000. # not calibrated below 10 GeV
 #
 # set the -999. to positive number to override default
diff --git a/XAMPPmonoH/share/MonoHToolSetup.py b/XAMPPmonoH/share/MonoHToolSetup.py
index 27cd71b..2079fd6 100644
--- a/XAMPPmonoH/share/MonoHToolSetup.py
+++ b/XAMPPmonoH/share/MonoHToolSetup.py
@@ -81,6 +81,19 @@ def SetupMetTriggerTool():
         ToolSvc += TriggerTool
     return getattr(ToolSvc, "MetTriggerSF")
 
+def SetupFatJetCalibTool():
+    from AthenaCommon.AppMgr import ToolSvc
+    from AthenaCommon import CfgMgr
+    toolName = "JetFatCalibTool_AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets"
+    if not hasattr(ToolSvc, toolName):
+        from JetCalibTools.JetCalibToolsConf import JetCalibrationTool
+        calibTool = CfgMgr.JetCalibrationTool(name=toolName)
+        calibTool.JetCollection="AntiKt10UFOCSSKSoftDropBeta100Zcut10"
+        calibTool.ConfigFile="JES_MC16recommendation_R10_UFO_CSSK_SoftDrop_JMS_01April2020.config" 
+        calibTool.CalibSequence="EtaJES_JMS"
+        calibTool.IsData=True
+        ToolSvc += calibTool
+    return getattr(ToolSvc, toolName)
 
 def SetupSMShapesWeightsTool0L():
     from AthenaCommon.AppMgr import ToolSvc
@@ -322,11 +335,10 @@ def ParseCommonMonoHOptions(STFile="XAMPPmonoH/SUSYTools_MonoH.conf"):
     except:
         recoLog.warning("Could not find the Jet.InputType")
 
-    SetupSUSYJetSelector().AntiKt4BTagContainer = "AntiKt4EMPFlowJets_BTagging201810"
     if JetType == 1:
-        JetCollectionName = "AntiKt4EMTopoJets_BTagging201810"
+        JetCollectionName = "AntiKt4EMTopoJets_BTagging" + str(GetPropertyFromConfFile(STFile, "Btag.TimeStamp"))
     elif JetType == 9:
-        JetCollectionName = "AntiKt4EMPFlowJets_BTagging201810"
+        JetCollectionName = "AntiKt4EMPFlowJets_BTagging" + str(GetPropertyFromConfFile(STFile, "Btag.TimeStamp"))
         #only when we use PFlow jets do the DFCommonCrackVeto
         SetupMonoHAnaConfig().doPFlowElecCleaning = True
         SetupMonoHAnalysisHelper().doPFlowCleaning = True
@@ -337,20 +349,24 @@ def ParseCommonMonoHOptions(STFile="XAMPPmonoH/SUSYTools_MonoH.conf"):
     else:
         recoLog.error("ERROR: I've no idea what JetCollection you're aiming for. But it will not work")
         exit(1)
+    SetupSUSYJetSelector().AntiKt4BTagContainer = JetCollectionName
 
     SetupMonoHJetSelector().AntiKt10_BaselinePt = 200.e3
     SetupMonoHJetSelector().AntiKt10_BaselineEta = 2.
     SetupMonoHJetSelector().AntiKt02_BaselinePt = 10.e3
     SetupMonoHJetSelector().AntiKt02_BaselineEta = 2.5
 
-    SetupMonoHJetSelector().TrackJetContainer = 'AntiKtVR30Rmax4Rmin02TrackJets'
+    SetupMonoHJetSelector().TrackJetContainer = str(GetPropertyFromConfFile(STFile, "TrackJet.Coll")) + "_BTagging" + str(GetPropertyFromConfFile(STFile, "BtagTrkJet.TimeStamp"))
     if SetupMonoHJetSelector().TrackJetContainer == 'AntiKtVR30Rmax4Rmin02TrackJets':
         SetupMonoHJetSelector().AssociatedObjectsContainer = 'GhostVR30Rmax4Rmin02TrackJet'
+    elif 'AntiKtVR30Rmax4Rmin02TrackJets_BTagging' in SetupMonoHJetSelector().TrackJetContainer:
+        SetupMonoHJetSelector().AssociatedObjectsContainer = "GhostVR30Rmax4Rmin02TrackJet_BTagging" + str(GetPropertyFromConfFile(STFile, "BtagTrkJet.TimeStamp"))
     elif SetupMonoHJetSelector().TrackJetContainer == 'AntiKt2PV0TrackJets':
         SetupMonoHJetSelector().AssociatedObjectsContainer = 'GhostAntiKt2TrackJet'
     else:
         print 'INFO: MonoHToolSetup.py - please provide a valid track-jet container!'
         exit(1)
+    SetupMonoHJetSelector().LargeRJetContainer = str(GetPropertyFromConfFile(STFile, "Jet.LargeRcollection"))
 
     # using same calib path and SF strategy for track jets and small-R jets
     CalibPath = str(GetPropertyFromConfFile(STFile, "Btag.CalibPath"))
@@ -386,6 +402,11 @@ def ParseCommonMonoHOptions(STFile="XAMPPmonoH/SUSYTools_MonoH.conf"):
     SetupSUSYTools().BTaggingEfficiencyTool = SetupMonoHJetSelector().BTagEfficiencyTool
     SetupSUSYTools().BTaggingEfficiencyTool_trkJet = SetupMonoHJetSelector().TrackJetBTagEfficiencyTool
 
+    # TODO: 22.01.2021 Janik: The following two lines are needed because the in-situ calibration for UFO jets is not yet available.
+    # This should be removed once the data calibration is ready.
+    if isData() and str(GetPropertyFromConfFile(STFile, "Jet.LargeRcollection")) == "AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets":
+        SetupSUSYTools().FatJetCalibTool = SetupFatJetCalibTool()
+
     #SetupSUSYJetSelector().SignalDecorator = 'signal_less_JVT'
     SetupSUSYJetSelector().bJetEtaCut = 2.5
     SetupSUSYJetSelector().SeparateSF = True
diff --git a/XAMPPmonoH/share/runMonoH.py b/XAMPPmonoH/share/runMonoH.py
index 0dbfed2..0cd368f 100644
--- a/XAMPPmonoH/share/runMonoH.py
+++ b/XAMPPmonoH/share/runMonoH.py
@@ -4,7 +4,7 @@ import os
 include("XAMPPmonoH/MonoHToolSetup.py")
 
 AssembleIO()
-SetupTransferAssociatedVRJetsAlg()
+# SetupTransferAssociatedVRJetsAlg()
 SetupMonoHAnalysisHelper()
 ParseCommonMonoHOptions()
 
-- 
GitLab


From 6aa9ba40990783ef237f23f113967a456c91a346 Mon Sep 17 00:00:00 2001
From: Janik von Ahnen <janik.von.ahnen@cern.ch>
Date: Tue, 26 Jan 2021 01:16:14 +0100
Subject: [PATCH 2/8] scaling back to Mono-H sample compatibility

---
 XAMPPmonoH/data/SUSYTools_MonoH.conf | 18 +++++++++---------
 XAMPPmonoH/share/MonoHToolSetup.py   |  5 +++--
 XAMPPmonoH/share/runMonoH.py         |  2 +-
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/XAMPPmonoH/data/SUSYTools_MonoH.conf b/XAMPPmonoH/data/SUSYTools_MonoH.conf
index 49adb38..04cdc53 100755
--- a/XAMPPmonoH/data/SUSYTools_MonoH.conf
+++ b/XAMPPmonoH/data/SUSYTools_MonoH.conf
@@ -67,16 +67,16 @@ FwdJet.JvtPtMax: 50e3
 
 # Large R jets used in MonoH
 
-# Jet.LargeRcollection: AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets
-# Jet.LargeRuncConfig: rel21/Spring2019/R10_CategoryReduction.config
+Jet.LargeRcollection: AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets
+Jet.LargeRuncConfig: rel21/Spring2019/R10_CategoryReduction.config
 
 # New UFO large R jets
 
-Jet.LargeRcollection: AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets
-Jet.LargeRuncConfig: None # UFO jets are not jet supported by the jet uncertainty tool. https://twiki.cern.ch/twiki/bin/view/AtlasProtected/JetUncertaintiesRel21Summer2019LargeR
-Jet.JESConfigFat: JES_MC16recommendation_R10_UFO_CSSK_SoftDrop_JMS_01April2020.config
-Jet.JESConfigFatData: None # Not yet available
-Jet.CalibSeqFat: EtaJES_JMS
+# Jet.LargeRcollection: AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets
+# Jet.LargeRuncConfig: None # UFO jets are not jet supported by the jet uncertainty tool. https://twiki.cern.ch/twiki/bin/view/AtlasProtected/JetUncertaintiesRel21Summer2019LargeR
+# Jet.JESConfigFat: JES_MC16recommendation_R10_UFO_CSSK_SoftDrop_JMS_01April2020.config
+# Jet.JESConfigFatData: None # Not yet available
+# Jet.CalibSeqFat: EtaJES_JMS
 
 #Jet.LargeRuncVars: pT,mass,D2Beta1,Tau21WTA,Tau32WTA
 Jet.WtaggerConfig: None
@@ -95,7 +95,7 @@ Btag.enable: true
 Btag.Tagger: DL1 # DL1, DL1mu, DL1rnn, MV2c10mu, MV2c10rnn, MC2cl100_MV2c100
 Btag.WP: FixedCutBEff_77
 Btag.SystStrategy: SFEigen
-Btag.TimeStamp: 201903 # 201810 (DL1) for old training (used in MonoHbb) and 201903 (DL1r) for new training
+Btag.TimeStamp: 201810 # 201810 (DL1) for old training (used in MonoHbb) and 201903 (DL1r) for new training
 Btag.MinPt: 20000. # not calibrated below 20 GeV
 # custom VHbb CDI file (fixed MC to MC SF)
 # XAMPPmonoH/CDI/boosted-CDI-20-02-2019.root
@@ -105,7 +105,7 @@ Btag.CalibPath: xAODBTaggingEfficiency/13TeV/2020-21-13TeV-MC16-CDI-2020-12-02_v
 # option to set different tagger and WP for track jets
 BtagTrkJet.Tagger: DL1
 BtagTrkJet.WP: FixedCutBEff_77
-BtagTrkJet.TimeStamp: 201903 # 201810 (DL1) for old training (used in MonoHbb) and 201903 (DL1r) for new training
+BtagTrkJet.TimeStamp: 201810 # 201810 (DL1) for old training (used in MonoHbb) and 201903 (DL1r) for new training
 BtagTrkJet.MinPt: 10000. # not calibrated below 10 GeV
 #
 # set the -999. to positive number to override default
diff --git a/XAMPPmonoH/share/MonoHToolSetup.py b/XAMPPmonoH/share/MonoHToolSetup.py
index 2079fd6..828c860 100644
--- a/XAMPPmonoH/share/MonoHToolSetup.py
+++ b/XAMPPmonoH/share/MonoHToolSetup.py
@@ -356,7 +356,8 @@ def ParseCommonMonoHOptions(STFile="XAMPPmonoH/SUSYTools_MonoH.conf"):
     SetupMonoHJetSelector().AntiKt02_BaselinePt = 10.e3
     SetupMonoHJetSelector().AntiKt02_BaselineEta = 2.5
 
-    SetupMonoHJetSelector().TrackJetContainer = str(GetPropertyFromConfFile(STFile, "TrackJet.Coll")) + "_BTagging" + str(GetPropertyFromConfFile(STFile, "BtagTrkJet.TimeStamp"))
+    # SetupMonoHJetSelector().TrackJetContainer = str(GetPropertyFromConfFile(STFile, "TrackJet.Coll")) + "_BTagging" + str(GetPropertyFromConfFile(STFile, "BtagTrkJet.TimeStamp"))
+    SetupMonoHJetSelector().TrackJetContainer = str(GetPropertyFromConfFile(STFile, "TrackJet.Coll"))
     if SetupMonoHJetSelector().TrackJetContainer == 'AntiKtVR30Rmax4Rmin02TrackJets':
         SetupMonoHJetSelector().AssociatedObjectsContainer = 'GhostVR30Rmax4Rmin02TrackJet'
     elif 'AntiKtVR30Rmax4Rmin02TrackJets_BTagging' in SetupMonoHJetSelector().TrackJetContainer:
@@ -391,7 +392,7 @@ def ParseCommonMonoHOptions(STFile="XAMPPmonoH/SUSYTools_MonoH.conf"):
     TrkWorkingPoint = str(GetPropertyFromConfFile(STFile, "BtagTrkJet.WP"))
     TrkMinPt = GetPropertyFromConfFile(STFile, "BtagTrkJet.MinPt")
 
-    SetupMonoHJetSelector().TrackJetBTagEfficiencyTool = SetupBtaggingEfficiencyTool(SetupMonoHJetSelector().TrackJetContainer,
+    SetupMonoHJetSelector().TrackJetBTagEfficiencyTool = SetupBtaggingEfficiencyTool(str(GetPropertyFromConfFile(STFile, "TrackJet.Coll")) + "_BTagging" + str(GetPropertyFromConfFile(STFile, "BtagTrkJet.TimeStamp")),
                                                                                      TrkWorkingPoint, TrkTagger, CalibPath, SystStrategy,
                                                                                      EigenvecRedB, EigenvecRedC, EigenvecRedLight,
                                                                                      str(GetBTagShowerDSID(applyMCMCSFs=True)),
diff --git a/XAMPPmonoH/share/runMonoH.py b/XAMPPmonoH/share/runMonoH.py
index 0cd368f..0dbfed2 100644
--- a/XAMPPmonoH/share/runMonoH.py
+++ b/XAMPPmonoH/share/runMonoH.py
@@ -4,7 +4,7 @@ import os
 include("XAMPPmonoH/MonoHToolSetup.py")
 
 AssembleIO()
-# SetupTransferAssociatedVRJetsAlg()
+SetupTransferAssociatedVRJetsAlg()
 SetupMonoHAnalysisHelper()
 ParseCommonMonoHOptions()
 
-- 
GitLab


From af947f1287ad652b774f63f3c29ad6c1ceb98087 Mon Sep 17 00:00:00 2001
From: Janik von Ahnen <janik.von.ahnen@cern.ch>
Date: Tue, 26 Jan 2021 01:46:33 +0100
Subject: [PATCH 3/8] switching to new b-tagger

---
 XAMPPmonoH/data/SUSYTools_MonoH.conf | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/XAMPPmonoH/data/SUSYTools_MonoH.conf b/XAMPPmonoH/data/SUSYTools_MonoH.conf
index 04cdc53..a10a47c 100755
--- a/XAMPPmonoH/data/SUSYTools_MonoH.conf
+++ b/XAMPPmonoH/data/SUSYTools_MonoH.conf
@@ -92,10 +92,10 @@ BadJet.Cut: TightBad
 #
 # master switch for btagging use in ST. If false, btagging is not used neither for jets decorations nor for OR (regardless of the options below)
 Btag.enable: true
-Btag.Tagger: DL1 # DL1, DL1mu, DL1rnn, MV2c10mu, MV2c10rnn, MC2cl100_MV2c100
+Btag.Tagger: DL1r # DL1, DL1mu, DL1rnn, MV2c10mu, MV2c10rnn, MC2cl100_MV2c100
 Btag.WP: FixedCutBEff_77
 Btag.SystStrategy: SFEigen
-Btag.TimeStamp: 201810 # 201810 (DL1) for old training (used in MonoHbb) and 201903 (DL1r) for new training
+Btag.TimeStamp: 201903 # 201810 (DL1) for old training (used in MonoHbb) and 201903 (DL1r) for new training
 Btag.MinPt: 20000. # not calibrated below 20 GeV
 # custom VHbb CDI file (fixed MC to MC SF)
 # XAMPPmonoH/CDI/boosted-CDI-20-02-2019.root
@@ -103,9 +103,9 @@ Btag.MinPt: 20000. # not calibrated below 20 GeV
 Btag.CalibPath: xAODBTaggingEfficiency/13TeV/2020-21-13TeV-MC16-CDI-2020-12-02_v2.root
 #
 # option to set different tagger and WP for track jets
-BtagTrkJet.Tagger: DL1
+BtagTrkJet.Tagger: DL1r
 BtagTrkJet.WP: FixedCutBEff_77
-BtagTrkJet.TimeStamp: 201810 # 201810 (DL1) for old training (used in MonoHbb) and 201903 (DL1r) for new training
+BtagTrkJet.TimeStamp: 201903 # 201810 (DL1) for old training (used in MonoHbb) and 201903 (DL1r) for new training
 BtagTrkJet.MinPt: 10000. # not calibrated below 10 GeV
 #
 # set the -999. to positive number to override default
-- 
GitLab


From e8be89a9c92e1c2359cd37313e72af71b9e80fb1 Mon Sep 17 00:00:00 2001
From: Janik von Ahnen <janik.von.ahnen@cern.ch>
Date: Tue, 2 Feb 2021 14:37:15 +0100
Subject: [PATCH 4/8] Making the muon invisilbe for th emuCR

---
 XAMPPmonoH/Root/MonoHAnalysisConfig.cxx | 4 ++--
 XAMPPmonoH/Root/MonoHAnalysisHelper.cxx | 5 ++++-
 XAMPPmonoH/Root/MonoHMetSelector.cxx    | 5 ++++-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx b/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx
index 5d64ed5..92b8423 100644
--- a/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx
+++ b/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx
@@ -871,10 +871,10 @@ namespace XAMPP {
         if (m_doPFlowElecCleaning) CREMuMergedCutFlow.push_back(PFlowElecCleaning);
 
         if (m_doMETTrigger)
-            CREMuResolvedCutFlow.push_back(IsMETTrigPassed);
+            CREMuMergedCutFlow.push_back(IsMETTrigPassed);
         else
             // Use the same triggers as for the dilepton regions, but ORed
-            CREMuResolvedCutFlow.push_back(
+            CREMuMergedCutFlow.push_back(
                 (IsSingleElecTrigPassed->combine(IsSingleElecTrigMatched, Cut::Combine::AND))
                     ->combine(IsSingleMuonTrigPassed->combine(IsSingleMuonTrigMatched, Cut::Combine::AND), Cut::Combine::OR));
 
diff --git a/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx b/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
index 1d88c9a..482756c 100644
--- a/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
+++ b/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
@@ -632,8 +632,11 @@ namespace XAMPP {
         bool doTwoLepton =
             ((m_muon_selection->GetSignalMuons()->size() == 2 && m_muon_selection->GetBaselineMuons()->size() == 2) ||
              (m_electron_selection->GetSignalElectrons()->size() == 2 && m_electron_selection->GetBaselineElectrons()->size() == 2));
+        bool doEMuLepton =
+            ((m_muon_selection->GetSignalMuons()->size() == 1 && m_muon_selection->GetBaselineMuons()->size() == 1) &&
+             (m_electron_selection->GetSignalElectrons()->size() == 1 && m_electron_selection->GetBaselineElectrons()->size() == 1));
         xAOD::MissingET* MetTSTProxy;
-        if (doOneLepton || doTwoLepton)
+        if (doOneLepton || doTwoLepton || doEMuLepton)
             MetTSTProxy = dec_XAMPPmetTSTlepInvis->GetValue();
         else
             MetTSTProxy = dec_XAMPPmetTST->GetValue();
diff --git a/XAMPPmonoH/Root/MonoHMetSelector.cxx b/XAMPPmonoH/Root/MonoHMetSelector.cxx
index f879096..2c800e0 100644
--- a/XAMPPmonoH/Root/MonoHMetSelector.cxx
+++ b/XAMPPmonoH/Root/MonoHMetSelector.cxx
@@ -82,9 +82,12 @@ namespace XAMPP {
         xAOD::ElectronContainer* BaselineElectrons = m_elec_selection->GetBaselineElectrons();
         xAOD::ElectronContainer* SignalElectrons = m_elec_selection->GetSignalElectrons();
 
+        // emu Control region. Only marking the muon as invisible
+        if (SignalMuons->size() == 1 && BaselineMuons->size() == 1 && SignalElectrons->size() == 1 && BaselineElectrons->size() == 1) {
+            ATH_CHECK(addToInvisible(SignalMuons->at(0), "TSTmuInvis"));
         // Events with exactly only one muon and no electron lie in the 1-muon CR
         // --> Marking the leading signal muon as invisible
-        if (SignalMuons->size() == 1 && BaselineMuons->size() == 1 && SignalElectrons->size() == 0 && BaselineElectrons->size() == 0) {
+        } else if (SignalMuons->size() == 1 && BaselineMuons->size() == 1 && SignalElectrons->size() == 0 && BaselineElectrons->size() == 0) {
             ATH_MSG_DEBUG("SignalMuon pt: " << SignalMuons->at(0)->pt() / 1000. << " eta: " << SignalMuons->at(0)->eta()
                                             << " phi: " << SignalMuons->at(0)->phi());
             ATH_CHECK(addToInvisible(SignalMuons->at(0), "TSTmuInvis"));
-- 
GitLab


From 92260ca3890f469ecf3631f4e198dd00a2d805a1 Mon Sep 17 00:00:00 2001
From: Janik von Ahnen <janik.von.ahnen@cern.ch>
Date: Wed, 3 Feb 2021 15:50:14 +0100
Subject: [PATCH 5/8] Correctly initializing corr TLV. Fixes *_J_corr for
 N_Jets10==0

---
 XAMPPmonoH/Root/MonoHAnalysisHelper.cxx | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx b/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
index 482756c..f4724db 100644
--- a/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
+++ b/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
@@ -1050,6 +1050,7 @@ namespace XAMPP {
         float pt_jj = -1;
         float eta_jj = -1;
         float phi_jj = -1;
+        for (auto& storePair : muonCorrDijets) storePair.second.setDijetP4(TLorentzVector(), TLorentzVector());
         if (BtagLightJets->size() > 1) {
             TLorentzVector p4_jj = BtagLightJets->at(0)->p4() + BtagLightJets->at(1)->p4();
             pt_jj = p4_jj.Pt();
@@ -1073,6 +1074,7 @@ namespace XAMPP {
         float NNXbbScoreTop = -1;
         float NNXbb_CombScore_25 = -1;
         bool IsTaggedByNNXbb_25_70 = false;
+        for (auto& storePair : muonCorrLargeRJets) storePair.second.setP4(TLorentzVector());
         if (NJets10 > 0) {
             m_J = FatJets->at(0)->m();
             if (m_doXbbScore) {
-- 
GitLab


From b8c3e7495a6ebb64e26b71642285339c503a1573 Mon Sep 17 00:00:00 2001
From: Janik von Ahnen <janik.von.ahnen@cern.ch>
Date: Thu, 11 Feb 2021 12:35:50 +0100
Subject: [PATCH 6/8] fixing gitignore and adding missing CMakeLists.txt

---
 .gitignore                |   3 +-
 XAMPPmonoH/CMakeLists.txt | 207 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 209 insertions(+), 1 deletion(-)
 create mode 100644 XAMPPmonoH/CMakeLists.txt

diff --git a/.gitignore b/.gitignore
index bdbc9d1..6fadd42 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,7 @@
 # Athena files
 ###
 .asetup.save
-CMakeLists.txt
+./CMakeLists.txt
 
 # Do not track built documentation or virtual environment needeed to build it
 XAMPPmonoH/docs/_build
@@ -40,3 +40,4 @@ XAMPPmonoH/data/CDI/boosted-CDI-20-02-2019.root
 #########
 *~
 *.bak
+/.vscode
diff --git a/XAMPPmonoH/CMakeLists.txt b/XAMPPmonoH/CMakeLists.txt
new file mode 100644
index 0000000..75c4907
--- /dev/null
+++ b/XAMPPmonoH/CMakeLists.txt
@@ -0,0 +1,207 @@
+# $Id: CMakeLists.txt 783761 2016-11-11 16:50:45Z nkoehler $
+################################################################################
+# Package: XAMPPmonoH
+################################################################################
+
+
+# Declare the package name:
+atlas_subdir( XAMPPmonoH )
+
+# Extra dependencies, based on the environment:
+set( extra_dep )
+if( XAOD_STANDALONE )
+   set( extra_dep Control/xAODRootAccess )
+else()
+   set( extra_dep Control/AthenaBaseComps GaudiKernel )
+endif()
+
+option( USE_XGBOOST "Enable compilation of XGBoost elements " OFF )
+
+if( USE_XGBOOST )
+  # Temporary directory for XGBoost build results:
+  set( _xgboostBuildDir ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XGBoostBuild )
+
+  # Set up the variables that the users can pick up XGBoost with:
+  set( XGBOOST_INCLUDE_DIRS
+    $<BUILD_INTERFACE:${_xgboostBuildDir}/include>
+    $<INSTALL_INTERFACE:include> )
+  set( XGBOOST_LIBRARIES
+    ${_xgboostBuildDir}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}xgboost${CMAKE_SHARED_LIBRARY_SUFFIX}
+    ${_xgboostBuildDir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}rabit${CMAKE_STATIC_LIBRARY_SUFFIX}
+    ${_xgboostBuildDir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}dmlc${CMAKE_STATIC_LIBRARY_SUFFIX} )
+
+  # Set up the build of XGBoost for the build area:
+  ExternalProject_Add( XGBoost
+    PREFIX ${CMAKE_BINARY_DIR}
+    INSTALL_DIR ${CMAKE_BINARY_DIR}/${ATLAS_PLATFORM}
+    GIT_REPOSITORY https://github.com/dmlc/xgboost.git
+    GIT_TAG 78ec77f
+    BUILD_IN_SOURCE 1
+    BUILD_COMMAND $(MAKE)
+    INSTALL_COMMAND
+    ${CMAKE_COMMAND} -E make_directory ${_xgboostBuildDir} &&
+    ${CMAKE_COMMAND} -E make_directory ${_xgboostBuildDir}/lib &&
+    ${CMAKE_COMMAND} -E make_directory ${_xgboostBuildDir}/include &&
+    ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/src/XGBoost/include/xgboost ${_xgboostBuildDir}/include/xgboost &&
+    ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/src/XGBoost/rabit/include/rabit ${_xgboostBuildDir}/include/rabit &&
+    ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/src/XGBoost/dmlc-core/include/dmlc ${_xgboostBuildDir}/include/dmlc &&
+    ${CMAKE_COMMAND} -E copy_if_different lib/${CMAKE_SHARED_LIBRARY_PREFIX}xgboost${CMAKE_SHARED_LIBRARY_SUFFIX} ${_xgboostBuildDir}/lib &&
+    ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_STATIC_LIBRARY_PREFIX}rabit${CMAKE_STATIC_LIBRARY_SUFFIX} ${_xgboostBuildDir}/lib &&
+    ${CMAKE_COMMAND} -E copy_if_different dmlc-core/${CMAKE_STATIC_LIBRARY_PREFIX}dmlc${CMAKE_STATIC_LIBRARY_SUFFIX} ${_xgboostBuildDir}/lib &&
+    ${CMAKE_COMMAND} -E copy_directory ${_xgboostBuildDir}/ <INSTALL_DIR>
+    BUILD_BYPRODUCTS ${XGBOOST_LIBRARIES} )
+
+  # Install XGBoost
+  install( DIRECTORY ${_xgboostBuildDir}/
+    DESTINATION . USE_SOURCE_PERMISSIONS )
+
+  # Clean up:
+  unset( _xgboostBuildDir )
+
+endif() # if USE_XGBOOST
+
+# Declare the package's dependencies:
+atlas_depends_on_subdirs(
+   PUBLIC
+   MetTriggerSFUncertainties
+   SMShapeUncertainties
+   Control/AthToolSupport/AsgTools
+   Event/xAOD/xAODCore
+   Event/xAOD/xAODEgamma
+   Event/xAOD/xAODEventInfo
+   Event/xAOD/xAODJet
+   Event/xAOD/xAODMissingET
+   Event/xAOD/xAODTrigMissingET
+   Event/xAOD/xAODMuon
+   Event/xAOD/xAODTau
+   Event/xAOD/xAODTracking
+   Event/xAOD/xAODTruth
+   Event/xAOD/xAODParticleEvent 
+   Event/xAOD/xAODLuminosity 
+   PhysicsAnalysis/AnalysisCommon/AssociationUtils
+   PhysicsAnalysis/AnalysisCommon/PATInterfaces
+   PhysicsAnalysis/AnalysisCommon/PMGTools
+   PhysicsAnalysis/MCTruthClassifier
+   PhysicsAnalysis/SUSYPhys/SUSYTools 
+   Reconstruction/Jet/JetJvtEfficiency
+   Reconstruction/Jet/JetSubStructureUtils
+   Trigger/TrigAnalysis/TrigDecisionTool
+   PRIVATE
+   XAMPPbase   
+   FlavorTagDiscriminants
+   AsgExternal/Asg_Test
+   Control/xAODRootAccess
+   Control/AthContainers
+   DataQuality/GoodRunsLists
+   Event/EventPrimitives
+   Event/FourMomUtils
+   Event/xAOD/xAODBTagging
+   Event/xAOD/xAODBase
+   Event/xAOD/xAODCaloEvent
+   Event/xAOD/xAODCutFlow
+   Event/xAOD/xAODPrimitives
+   PhysicsAnalysis/AnalysisCommon/IsolationSelection
+   PhysicsAnalysis/AnalysisCommon/PileupReweighting
+   PhysicsAnalysis/ElectronPhotonID/ElectronEfficiencyCorrection
+   PhysicsAnalysis/ElectronPhotonID/ElectronPhotonFourMomentumCorrection
+   PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools
+   PhysicsAnalysis/ElectronPhotonID/ElectronPhotonShowerShapeFudgeTool
+   PhysicsAnalysis/ElectronPhotonID/IsolationCorrections
+   PhysicsAnalysis/ElectronPhotonID/PhotonEfficiencyCorrection
+   PhysicsAnalysis/Interfaces/AsgAnalysisInterfaces
+   PhysicsAnalysis/JetMissingEtID/JetSelectorTools
+   PhysicsAnalysis/Interfaces/FTagAnalysisInterfaces
+   PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections
+   PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections
+   PhysicsAnalysis/MuonID/MuonSelectorTools
+   PhysicsAnalysis/TauID/TauAnalysisTools
+   Reconstruction/Jet/JetCPInterfaces
+   Reconstruction/Jet/JetCalibTools
+   Reconstruction/Jet/JetInterface
+   Reconstruction/Jet/JetResolution
+   Reconstruction/Jet/JetUncertainties
+   Reconstruction/Jet/JetMomentTools
+   Reconstruction/Jet/BoostedJetTaggers
+   Reconstruction/MET/METInterface
+   Reconstruction/MET/METUtilities
+   Reconstruction/tauRecTools
+   Tools/PathResolver
+   Trigger/TrigAnalysis/TriggerMatchingTool
+   Trigger/TrigConfiguration/TrigConfInterfaces
+   Trigger/TrigConfiguration/TrigConfxAOD
+   ${extra_deps} )
+
+# External dependencies:
+find_package( Boost )
+find_package( ROOT COMPONENTS Core Tree RIO Hist Physics )
+
+# Libraries in the package:
+atlas_add_library( XAMPPmonoHLib
+   XAMPPmonoH/*.h Root/*.cxx
+   PUBLIC_HEADERS XAMPPmonoH
+   INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${XGBOOST_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS}
+   LINK_LIBRARIES ${Boost_LIBRARIES} ${XGBOOST_LIBRARIES} ${ROOT_LIBRARIES} AsgTools xAODCore xAODEgamma xAODEventInfo xAODRootAccess FlavorTagDiscriminants
+   xAODJet xAODMissingET xAODMuon xAODTau xAODTracking xAODTruth xAODParticleEvent xAODLuminosity SUSYToolsLib xAODCutFlow
+   XAMPPbaseLib 
+   PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} ${BOOST_LIBRARIES} 
+   MetTriggerSFUncertaintiesLib SMShapeUncertaintiesLib
+   AssociationUtilsLib PATInterfaces TrigDecisionToolLib PMGToolsLib
+   MCTruthClassifierLib JetJvtEfficiencyLib JetSubStructureUtils
+   AthContainers EventPrimitives FourMomUtils xAODBTagging xAODBase
+   xAODPrimitives IsolationSelectionLib PileupReweightingLib
+   ElectronEfficiencyCorrectionLib ElectronPhotonFourMomentumCorrectionLib
+   ElectronPhotonSelectorToolsLib ElectronPhotonShowerShapeFudgeToolLib
+   IsolationCorrectionsLib PhotonEfficiencyCorrectionLib JetSelectorToolsLib
+   FTagAnalysisInterfacesLib MuonEfficiencyCorrectionsLib
+   MuonMomentumCorrectionsLib MuonSelectorToolsLib TauAnalysisToolsLib
+   JetCPInterfaces JetCalibToolsLib JetInterface JetResolutionLib
+   JetUncertaintiesLib JetMomentToolsLib METInterface METUtilitiesLib
+   PathResolver TriggerMatchingToolLib TrigConfInterfaces TrigConfxAODLib
+   xAODTrigMissingET xAODMetaData GoodRunsListsLib BoostedJetTaggersLib
+   PRIVATE_LINK_LIBRARIES xAODTrigger PathResolver )
+
+if( USE_XGBOOST )
+  add_dependencies( XAMPPmonoHLib XGBoost )
+  target_compile_definitions( XAMPPmonoHLib PUBLIC USE_XGBOOST )
+endif()
+
+if( NOT XAOD_STANDALONE )
+   atlas_add_component( XAMPPmonoH
+      src/*.h src/*.cxx src/components/*.cxx
+      INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
+      LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaBaseComps GaudiKernel GoodRunsLists
+      AthenaKernel AthAnalysisBaseCompsLib xAODEventInfo xAODMuon xAODPrimitives xAODCutFlow
+      xAODJet xAODBTagging xAODEgamma xAODMissingET xAODTracking xAODTau xAODParticleEvent
+      TauAnalysisToolsLib xAODCore AthContainers AsgTools xAODBase xAODCutFlow xAODRootAccess xAODTruth
+      xAODMetaData PATInterfaces PathResolver SUSYToolsLib XAMPPbaseLib XAMPPmonoHLib
+      MetTriggerSFUncertaintiesLib SMShapeUncertaintiesLib)
+endif()
+
+atlas_add_dictionary( XAMPPmonoHDict
+   XAMPPmonoH/XAMPPmonoHDict.h
+   XAMPPmonoH/selection.xml
+   LINK_LIBRARIES XAMPPmonoHLib )
+
+
+# Install files from the package:
+atlas_install_data( data/* )
+atlas_install_python_modules( python/*.py )
+atlas_install_joboptions( share/*.py )
+
+# Install python packages
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
+include(SetupPythonPackage)
+
+## Install rootpy
+#setup_python_package( rootpy
+#   "https://files.pythonhosted.org/packages/55/e5/07a19ef0bb1111039b69202ba30550cc65c6d295bb17a81861b5994bd3c2/rootpy-1.0.1.tar.gz"
+#   "3146957733f56f4981cd2f5162774f66"
+#   PATCH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/patch-setup.cfg setup.cfg
+#)
+#
+## Install seaborn plotting
+#setup_python_package( seaborn
+#   "https://files.pythonhosted.org/packages/7a/bf/04cfcfc9616cedd4b5dd24dfc40395965ea9f50c1db0d3f3e52b050f74a5/seaborn-0.9.0.tar.gz"
+#   "b50cfee47ab6c7d8e07646e805523e14"
+#   PATCH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/patch-setup.cfg setup.cfg
+#)
-- 
GitLab


From f8b61ddaf4f74840d9695d604d260f4794846c84 Mon Sep 17 00:00:00 2001
From: Janik von Ahnen <janik.von.ahnen@cern.ch>
Date: Mon, 22 Mar 2021 18:17:41 +0100
Subject: [PATCH 7/8] current state of emu-CR, ele and leading b-jet used for
 Higgs candidate

---
 XAMPPmonoH/Root/MonoHAnalysisConfig.cxx | 20 ++++----------------
 XAMPPmonoH/Root/MonoHAnalysisHelper.cxx | 20 ++++++++++++++++++++
 XAMPPmonoH/Root/MonoHMetSelector.cxx    | 11 +++++++++--
 3 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx b/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx
index 92b8423..b94b23e 100644
--- a/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx
+++ b/XAMPPmonoH/Root/MonoHAnalysisConfig.cxx
@@ -789,13 +789,7 @@ namespace XAMPP {
         // --------------------------------------------------------------------
         // If we use PFlow, we clean PFlow :)
         if (m_doPFlowElecCleaning) CREMuResolvedCutFlow.push_back(PFlowElecCleaning);
-        if (m_doMETTrigger)
-            CREMuResolvedCutFlow.push_back(IsMETTrigPassed);
-        else
-            // Use the same triggers as for the dilepton regions, but ORed
-            CREMuResolvedCutFlow.push_back(
-                (IsSingleElecTrigPassed->combine(IsSingleElecTrigMatched, Cut::Combine::AND))
-                    ->combine(IsSingleMuonTrigPassed->combine(IsSingleMuonTrigMatched, Cut::Combine::AND), Cut::Combine::OR));
+        CREMuResolvedCutFlow.push_back(IsMETTrigPassed);
 
         // Use the same muon selection as the 1L CR
         CREMuResolvedCutFlow.push_back(OneMuon);
@@ -821,7 +815,7 @@ namespace XAMPP {
 
         // We can't necessarily say which MET value we're cutting on here, but
         // we're definitely cutting on one of them... :)
-        CREMuResolvedCutFlow.push_back(MetTST150lepInvis->combine(MetTST150, Cut::Combine::OR));
+        CREMuResolvedCutFlow.push_back(MetTST150lepInvis);
         CREMuResolvedCutFlow.push_back(TwoJets);
         // This variable now cuts on >= 2 b-jets
         CREMuResolvedCutFlow.push_back(MoreThanOneBJet);
@@ -870,13 +864,7 @@ namespace XAMPP {
         // If we use PFlow, we clean PFlow :)
         if (m_doPFlowElecCleaning) CREMuMergedCutFlow.push_back(PFlowElecCleaning);
 
-        if (m_doMETTrigger)
-            CREMuMergedCutFlow.push_back(IsMETTrigPassed);
-        else
-            // Use the same triggers as for the dilepton regions, but ORed
-            CREMuMergedCutFlow.push_back(
-                (IsSingleElecTrigPassed->combine(IsSingleElecTrigMatched, Cut::Combine::AND))
-                    ->combine(IsSingleMuonTrigPassed->combine(IsSingleMuonTrigMatched, Cut::Combine::AND), Cut::Combine::OR));
+        CREMuMergedCutFlow.push_back(IsMETTrigPassed);
 
         // Use the same lepton selections as resolved
         CREMuMergedCutFlow.push_back(OneMuon);
@@ -891,7 +879,7 @@ namespace XAMPP {
         // extended tau veto merged
         CREMuMergedCutFlow.push_back(Extended_TauVeto_Merged);
         // Same as above
-        CREMuMergedCutFlow.push_back(MetTSTGreater500lepInvis->combine(MetTSTGreater500, Cut::Combine::OR));
+        CREMuMergedCutFlow.push_back(MetTSTGreater500lepInvis);
         CREMuMergedCutFlow.push_back(OneFatJet);
         CREMuMergedCutFlow.push_back(largeR_btagging);
         CREMuMergedCutFlow.push_back(HiggsMassMerged->combine(HiggsMassMergedCorr, Cut::Combine::OR));
diff --git a/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx b/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
index f4724db..cfb1ac9 100644
--- a/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
+++ b/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
@@ -802,6 +802,19 @@ namespace XAMPP {
         xAOD::JetContainer* ForwardJets = m_jet_selection->GetCustomJets("forward");
         xAOD::JetContainer* BJets = m_jet_selection->GetBJets();
 
+        xAOD::Jet* new_b_jet;
+        if (SignalElectrons->size()==1 && SignalMuons->size()==1 && BJets->size()){
+            TLorentzVector leading_ele_p4=SignalElectrons->at(0)->p4();
+            new_b_jet= new xAOD::Jet(*BJets->at(0));
+            new_b_jet->setJetP4(GetJetFourMom(leading_ele_p4));
+            // The OneMuon is the closest muon to the jet axis and is used for m_jj_corr
+            new_b_jet->setJetP4("OneMuon", GetJetFourMom(leading_ele_p4));
+            BJets->insert(BJets->begin(), new_b_jet);
+            allJets->insert(allJets->begin(), new_b_jet);
+            SignalJets->insert(SignalJets->begin(), new_b_jet);
+            BtagLightJets->insert(BtagLightJets->begin(), new_b_jet);
+        }
+
         m_jet1Muons.clear();
         m_jet2Muons.clear();
         m_fatJetMuons.clear();
@@ -1483,6 +1496,13 @@ namespace XAMPP {
             s_fatJetMuons->Fill(&m_fatJetMuons);
         }
 
+        if (SignalElectrons->size()==1 && SignalMuons->size()==1 && BJets->size()){
+            delete new_b_jet;
+            allJets->erase(allJets->begin());
+            BJets->erase(BJets->begin());
+            SignalJets->erase(SignalJets->begin());
+            BtagLightJets->erase(BtagLightJets->begin());
+        }
         return StatusCode::SUCCESS;
     }
 
diff --git a/XAMPPmonoH/Root/MonoHMetSelector.cxx b/XAMPPmonoH/Root/MonoHMetSelector.cxx
index 2c800e0..22da391 100644
--- a/XAMPPmonoH/Root/MonoHMetSelector.cxx
+++ b/XAMPPmonoH/Root/MonoHMetSelector.cxx
@@ -85,6 +85,11 @@ namespace XAMPP {
         // emu Control region. Only marking the muon as invisible
         if (SignalMuons->size() == 1 && BaselineMuons->size() == 1 && SignalElectrons->size() == 1 && BaselineElectrons->size() == 1) {
             ATH_CHECK(addToInvisible(SignalMuons->at(0), "TSTmuInvis"));
+            xAOD::ElectronContainer* preselection_ele=m_elec_selection->GetPreElectrons();
+            preselection_ele->at(0)->setPt( preselection_ele->at(0)->pt()*1.1);
+            ATH_CHECK(buildMET(m_MetTSTlepInvisible, "TSTmuInvis", softTrackTerm(), preselection_ele,
+                           m_muon_selection->GetPreMuons(), nullptr, nullptr, true));
+            preselection_ele->at(0)->setPt( preselection_ele->at(0)->pt()/1.1);
         // Events with exactly only one muon and no electron lie in the 1-muon CR
         // --> Marking the leading signal muon as invisible
         } else if (SignalMuons->size() == 1 && BaselineMuons->size() == 1 && SignalElectrons->size() == 0 && BaselineElectrons->size() == 0) {
@@ -105,8 +110,10 @@ namespace XAMPP {
             ATH_CHECK(addToInvisible(SignalElectrons->at(1), "TSTmuInvis"));
         }
 
-        ATH_CHECK(buildMET(m_MetTSTlepInvisible, "TSTmuInvis", softTrackTerm(), m_elec_selection->GetPreElectrons(),
-                           m_muon_selection->GetPreMuons(), nullptr, nullptr, true));
+        if (!(SignalMuons->size() == 1 && BaselineMuons->size() == 1 && SignalElectrons->size() == 1 && BaselineElectrons->size() == 1)) {
+            ATH_CHECK(buildMET(m_MetTSTlepInvisible, "TSTmuInvis", softTrackTerm(), m_elec_selection->GetPreElectrons(),
+                            m_muon_selection->GetPreMuons(), nullptr, nullptr, true));
+        }
         ATH_CHECK(m_sto_MetTSTlepInvis->Store(XAMPP::GetMET_obj("Final", m_MetTSTlepInvisible)));
 
         // parent class method needs to be called last because it also calls the
-- 
GitLab


From d59677bd146e9f139ef299b666e585b5a822d8d1 Mon Sep 17 00:00:00 2001
From: Janik von Ahnen <janik.von.ahnen@cern.ch>
Date: Wed, 26 May 2021 08:59:42 +0200
Subject: [PATCH 8/8] removing electron as b-jet and scaling electron pT in MET
 calculation

---
 XAMPPmonoH/Root/MonoHAnalysisHelper.cxx | 20 --------------------
 XAMPPmonoH/Root/MonoHMetSelector.cxx    | 11 ++---------
 2 files changed, 2 insertions(+), 29 deletions(-)

diff --git a/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx b/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
index cfb1ac9..f4724db 100644
--- a/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
+++ b/XAMPPmonoH/Root/MonoHAnalysisHelper.cxx
@@ -802,19 +802,6 @@ namespace XAMPP {
         xAOD::JetContainer* ForwardJets = m_jet_selection->GetCustomJets("forward");
         xAOD::JetContainer* BJets = m_jet_selection->GetBJets();
 
-        xAOD::Jet* new_b_jet;
-        if (SignalElectrons->size()==1 && SignalMuons->size()==1 && BJets->size()){
-            TLorentzVector leading_ele_p4=SignalElectrons->at(0)->p4();
-            new_b_jet= new xAOD::Jet(*BJets->at(0));
-            new_b_jet->setJetP4(GetJetFourMom(leading_ele_p4));
-            // The OneMuon is the closest muon to the jet axis and is used for m_jj_corr
-            new_b_jet->setJetP4("OneMuon", GetJetFourMom(leading_ele_p4));
-            BJets->insert(BJets->begin(), new_b_jet);
-            allJets->insert(allJets->begin(), new_b_jet);
-            SignalJets->insert(SignalJets->begin(), new_b_jet);
-            BtagLightJets->insert(BtagLightJets->begin(), new_b_jet);
-        }
-
         m_jet1Muons.clear();
         m_jet2Muons.clear();
         m_fatJetMuons.clear();
@@ -1496,13 +1483,6 @@ namespace XAMPP {
             s_fatJetMuons->Fill(&m_fatJetMuons);
         }
 
-        if (SignalElectrons->size()==1 && SignalMuons->size()==1 && BJets->size()){
-            delete new_b_jet;
-            allJets->erase(allJets->begin());
-            BJets->erase(BJets->begin());
-            SignalJets->erase(SignalJets->begin());
-            BtagLightJets->erase(BtagLightJets->begin());
-        }
         return StatusCode::SUCCESS;
     }
 
diff --git a/XAMPPmonoH/Root/MonoHMetSelector.cxx b/XAMPPmonoH/Root/MonoHMetSelector.cxx
index 22da391..2c800e0 100644
--- a/XAMPPmonoH/Root/MonoHMetSelector.cxx
+++ b/XAMPPmonoH/Root/MonoHMetSelector.cxx
@@ -85,11 +85,6 @@ namespace XAMPP {
         // emu Control region. Only marking the muon as invisible
         if (SignalMuons->size() == 1 && BaselineMuons->size() == 1 && SignalElectrons->size() == 1 && BaselineElectrons->size() == 1) {
             ATH_CHECK(addToInvisible(SignalMuons->at(0), "TSTmuInvis"));
-            xAOD::ElectronContainer* preselection_ele=m_elec_selection->GetPreElectrons();
-            preselection_ele->at(0)->setPt( preselection_ele->at(0)->pt()*1.1);
-            ATH_CHECK(buildMET(m_MetTSTlepInvisible, "TSTmuInvis", softTrackTerm(), preselection_ele,
-                           m_muon_selection->GetPreMuons(), nullptr, nullptr, true));
-            preselection_ele->at(0)->setPt( preselection_ele->at(0)->pt()/1.1);
         // Events with exactly only one muon and no electron lie in the 1-muon CR
         // --> Marking the leading signal muon as invisible
         } else if (SignalMuons->size() == 1 && BaselineMuons->size() == 1 && SignalElectrons->size() == 0 && BaselineElectrons->size() == 0) {
@@ -110,10 +105,8 @@ namespace XAMPP {
             ATH_CHECK(addToInvisible(SignalElectrons->at(1), "TSTmuInvis"));
         }
 
-        if (!(SignalMuons->size() == 1 && BaselineMuons->size() == 1 && SignalElectrons->size() == 1 && BaselineElectrons->size() == 1)) {
-            ATH_CHECK(buildMET(m_MetTSTlepInvisible, "TSTmuInvis", softTrackTerm(), m_elec_selection->GetPreElectrons(),
-                            m_muon_selection->GetPreMuons(), nullptr, nullptr, true));
-        }
+        ATH_CHECK(buildMET(m_MetTSTlepInvisible, "TSTmuInvis", softTrackTerm(), m_elec_selection->GetPreElectrons(),
+                           m_muon_selection->GetPreMuons(), nullptr, nullptr, true));
         ATH_CHECK(m_sto_MetTSTlepInvis->Store(XAMPP::GetMET_obj("Final", m_MetTSTlepInvisible)));
 
         // parent class method needs to be called last because it also calls the
-- 
GitLab