Loading [MathJax]/jax/output/SVG/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TauSmearingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // EDM include(s):
8 
9 // Local include(s):
12 
13 #include <algorithm>
14 
15 namespace TauAnalysisTools
16 {
17 
18 TauSmearingTool::TauSmearingTool( const std::string& sName )
19  : asg::AsgMetadataTool( sName )
20  , m_tCommonSmearingTool(sName+"_CommonSmearingTool", this)
21 {
22  declareProperty( "InputFilePath", m_sInputFilePath = "" );
23  declareProperty( "RecommendationTag", m_sRecommendationTag = "2022-prerec" );
24  declareProperty( "Campaign", m_sCampaign = "mc21" );
25  declareProperty( "Generator", m_sGenerator = "PoPy" );
26  declareProperty( "SkipTruthMatchCheck", m_bSkipTruthMatchCheck = false );
27  declareProperty( "ApplyFading", m_bApplyFading = true );
28  declareProperty( "MVATESQualityCheck", m_bMVATESQualityCheck = true );
29  declareProperty( "ApplyInsituCorrection", m_bApplyInsituCorrection = true );
30  declareProperty( "useFastSim", m_useFastSim = false );
31 }
32 
34 {
35 }
36 
38 {
39  ATH_MSG_INFO( "Initializing TauSmearingTool" );
40 
42  ATH_MSG_WARNING("Truth match check will be skipped. This is ONLY FOR TESTING PURPOSE!");
43 
44  if (m_sInputFilePath.empty()) {
45  std::string sDirectory = "TauAnalysisTools/" + std::string(sSharedFilesVersion) + "/Smearing/";
46 
47  if(m_sRecommendationTag == "2025-prerec") {
48  ATH_MSG_WARNING("2025-prerec is under development and not complete yet.");
49 
50  if (m_sCampaign!="mc23" && m_sCampaign!="mc20"){
51  ATH_MSG_ERROR("unknown campaign (mc20|mc23):" << m_sCampaign);
52  return StatusCode::FAILURE;
53  }
54 
55  if(m_useFastSim) {
56  ATH_MSG_WARNING("No fast-sim recommendation for tau smearing is available, using full sim");
57  }
58 
59  if (m_sCampaign=="mc23") {
60  m_sInputFilePath = sDirectory+"TES_TrueHadTau_RNN_mc23_v0.root";
61  } else {
62  m_sInputFilePath = sDirectory+"TES_TrueHadTau_RNN_mc20_v0.root";
63  }
64 
65  } else if (m_sRecommendationTag == "2022-prerec") {
66 
67  if (m_sCampaign!="mc21" && m_sCampaign!="mc20"){
68  ATH_MSG_ERROR("unknown campaign (mc20|mc21):" << m_sCampaign);
69  return StatusCode::FAILURE;
70  }
71 
72  if (m_sGenerator!="PoPy" && m_sCampaign!="Sherpa"){
73  ATH_MSG_ERROR("unknown generator tag (PoPy|Sherpa):" << m_sCampaign);
74  return StatusCode::FAILURE;
75  }
76 
77  if(m_useFastSim) {
78  ATH_MSG_WARNING("No fast-sim recommendation for tau smearing is available, using full sim");
79  }
80 
81  if (m_sGenerator == "PoPy" && m_sCampaign=="mc20") m_sInputFilePath = sDirectory+"TES_TrueHadTau_PoPy8_mc20-prerec_v2.root";
82  if (m_sCampaign=="mc21") {
83  m_sInputFilePath = sDirectory+"TES_TrueHadTau_PoPy8_mc21-prerec_v2.root";
84  if (m_sGenerator=="Sherpa")ATH_MSG_WARNING("No Sherpa mc21 recommendations available yet, using PoPy8!");
85  }
86  if (m_sGenerator == "Sherpa" && m_sCampaign=="mc20") m_sInputFilePath = sDirectory+"TES_TrueHadTau_Sherpa2211-prerec_v2.root";
87  }
88  else {
89  ATH_MSG_ERROR("unknown recommendation tag " << m_sRecommendationTag);
90  return StatusCode::FAILURE;
91  }
92  }
94  ATH_CHECK(m_tCommonSmearingTool.setProperty("InputFilePath", m_sInputFilePath));
95  ATH_CHECK(m_tCommonSmearingTool.setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
96  ATH_CHECK(m_tCommonSmearingTool.setProperty("ApplyFading", m_bApplyFading));
97  ATH_CHECK(m_tCommonSmearingTool.setProperty("MVATESQualityCheck", m_bMVATESQualityCheck));
98  ATH_CHECK(m_tCommonSmearingTool.setProperty("ApplyInsituCorrection", m_bApplyInsituCorrection));
99  ATH_CHECK(m_tCommonSmearingTool.setProperty("OutputLevel", this->msg().level()));
100  ATH_CHECK(m_tCommonSmearingTool.initialize());
101 
102  // Add the affecting systematics to the global registry
104  if (!registry.registerSystematics(*this)) {
105  ATH_MSG_ERROR ("Unable to register the systematics");
106  return StatusCode::FAILURE;
107  }
108 
109  return StatusCode::SUCCESS;
110 }
111 
112 // auto detection of simulation flavour, used to cross check configuration of tool
113 //______________________________________________________________________________
115 {
116  if (inputMetaStore()->contains<xAOD::FileMetaData>("FileMetaData")) {
117  const xAOD::FileMetaData* fmd = nullptr;
118  ATH_CHECK( inputMetaStore()->retrieve( fmd, "FileMetaData" ) );
119  std::string simType("");
120  bool result = fmd->value( xAOD::FileMetaData::simFlavour , simType );
121  // if no result -> no simFlavor metadata, so must be data
122  if(result) std::transform(simType.begin(), simType.end(), simType.begin(), ::toupper);
123 
124  if( simType.find("ATLFAST3") != std::string::npos && !m_useFastSim){
125  ATH_MSG_WARNING("Input file is AF3 sample but you are _not_ using AF3 corrections and uncertainties, you should set \"useFastSim\" to \"true\"");
126  } else if (simType.find("FULLG4")!=std::string::npos && m_useFastSim){
127  ATH_MSG_WARNING("Input file is full simulation but you are using AF3 corrections and uncertainties, you should set \"useFastSim\" to \"false\"");
128  }
129  }
130 
131  return StatusCode::SUCCESS;
132 }
133 
135 {
136  return m_tCommonSmearingTool->applyCorrection(xTau);
137 }
138 
140 {
141  return m_tCommonSmearingTool->correctedCopy(input, output);
142 }
143 
146 {
147  return m_tCommonSmearingTool->isAffectedBySystematic( systematic );
148 }
149 
152 {
153  return m_tCommonSmearingTool->affectingSystematics();
154 }
155 
158 {
159  return m_tCommonSmearingTool->recommendedSystematics();
160 }
161 
163 {
164  return m_tCommonSmearingTool->applySystematicVariation( sSystematicSet );
165 }
166 
167 
168 } // namespace TauAnalysisTools
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.Dso.registry
registry
Definition: Control/AthenaServices/python/Dso.py:159
TauAnalysisTools
Definition: TruthCollectionMakerTau.h:16
TauAnalysisTools::TauSmearingTool::~TauSmearingTool
~TauSmearingTool()
Definition: TauSmearingTool.cxx:33
get_generator_info.result
result
Definition: get_generator_info.py:21
TauAnalysisTools::TauSmearingTool::correctedCopy
virtual CP::CorrectionCode correctedCopy(const xAOD::TauJet &input, xAOD::TauJet *&output) const
Create a corrected copy from a constant tau.
Definition: TauSmearingTool.cxx:139
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TauAnalysisTools::TauSmearingTool::m_useFastSim
bool m_useFastSim
Definition: TauSmearingTool.h:71
TauAnalysisTools::TauSmearingTool::m_sInputFilePath
std::string m_sInputFilePath
Definition: TauSmearingTool.h:67
asg
Definition: DataHandleTestTool.h:28
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
asg::AsgMetadataTool::inputMetaStore
MetaStorePtr_t inputMetaStore() const
Accessor for the input metadata store.
Definition: AsgMetadataTool.cxx:88
TauAnalysisTools::CommonSmearingTool
Definition: CommonSmearingTool.h:43
CP::SystematicVariation
Definition: SystematicVariation.h:47
ASG_MAKE_ANA_TOOL
#define ASG_MAKE_ANA_TOOL(handle, type)
create the tool in the given tool handle
Definition: AnaToolHandle.h:690
TauAnalysisTools::TauSmearingTool::m_sCampaign
std::string m_sCampaign
Definition: TauSmearingTool.h:70
xAOD::FileMetaData_v1::value
bool value(MetaDataType type, std::string &val) const
Get a pre-defined string value out of the object.
Definition: FileMetaData_v1.cxx:195
xAOD::FileMetaData_v1::simFlavour
@ simFlavour
Fast or Full sim [string].
Definition: FileMetaData_v1.h:76
TauAnalysisTools::TauSmearingTool::affectingSystematics
virtual CP::SystematicSet affectingSystematics() const
returns: the list of all systematics this tool can be affected by
Definition: TauSmearingTool.cxx:151
TauAnalysisTools::TauSmearingTool::applyCorrection
virtual CP::CorrectionCode applyCorrection(xAOD::TauJet &xTau) const
Apply the correction on a modifyable object.
Definition: TauSmearingTool.cxx:134
SharedFilesVersion.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TauAnalysisTools::TauSmearingTool::m_tCommonSmearingTool
asg::AnaToolHandle< ITauSmearingTool > m_tCommonSmearingTool
Definition: TauSmearingTool.h:66
SystematicRegistry.h
TauSmearingTool.h
TauAnalysisTools::TauSmearingTool::recommendedSystematics
virtual CP::SystematicSet recommendedSystematics() const
returns: the list of all systematics this tool recommends to use
Definition: TauSmearingTool.cxx:157
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TauAnalysisTools::TauSmearingTool::applySystematicVariation
virtual StatusCode applySystematicVariation(const CP::SystematicSet &systConfig)
effects: configure this tool for the given list of systematic variations.
Definition: TauSmearingTool.cxx:162
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::FileMetaData_v1
Class holding file-level metadata about an xAOD file.
Definition: FileMetaData_v1.h:34
TauAnalysisTools::TauSmearingTool::m_bMVATESQualityCheck
bool m_bMVATESQualityCheck
Definition: TauSmearingTool.h:74
TauAnalysisTools::TauSmearingTool::TauSmearingTool
TauSmearingTool(const std::string &sName)
Create a proper constructor for Athena.
Definition: TauSmearingTool.cxx:18
TauAnalysisTools::TauSmearingTool::m_sRecommendationTag
std::string m_sRecommendationTag
Definition: TauSmearingTool.h:68
TauAnalysisTools::TauSmearingTool::isAffectedBySystematic
virtual bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const
returns: whether this tool is affected by the given systematis
Definition: TauSmearingTool.cxx:145
TauAnalysisTools::TauSmearingTool::beginInputFile
virtual StatusCode beginInputFile()
Function called when a new input file is opened.
Definition: TauSmearingTool.cxx:114
FileMetaData.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TauAnalysisTools::TauSmearingTool::m_sGenerator
std::string m_sGenerator
Definition: TauSmearingTool.h:69
CP::SystematicRegistry
This module implements the central registry for handling systematic uncertainties with CP tools.
Definition: SystematicRegistry.h:25
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
TauAnalysisTools::TauSmearingTool::m_bApplyFading
bool m_bApplyFading
Definition: TauSmearingTool.h:73
TauAnalysisTools::TauSmearingTool::m_bApplyInsituCorrection
bool m_bApplyInsituCorrection
Definition: TauSmearingTool.h:75
TauAnalysisTools::TauSmearingTool::m_bSkipTruthMatchCheck
bool m_bSkipTruthMatchCheck
Definition: TauSmearingTool.h:72
TauAnalysisTools::TauSmearingTool::initialize
virtual StatusCode initialize()
Function initialising the tool.
Definition: TauSmearingTool.cxx:37
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition: SystematicRegistry.cxx:25