18{
19
20
21TauEfficiencyCorrectionsTool::TauEfficiencyCorrectionsTool( const std::string& sName )
22 :
asg::AsgMetadataTool( sName )
23 , m_bIsData(false)
24 , m_bIsConfigured(false)
25 , m_iRunNumber(0)
26{}
27
28
29TauEfficiencyCorrectionsTool::~TauEfficiencyCorrectionsTool()
30{}
31
32
33StatusCode TauEfficiencyCorrectionsTool::initialize()
34{
35 ATH_MSG_INFO(
"Initializing TauEfficiencyCorrectionsTool" );
36
37 m_vEfficiencyCorrectionTypes = m_vecEfficiencyCorrectionTypes.value();
38
39 if (m_bSkipTruthMatchCheck)
40 ATH_MSG_WARNING(
"Truth match check will be skipped. This is ONLY FOR TESTING PURPOSE!");
41
42
43 if (m_vEfficiencyCorrectionTypes.empty())
44 {
45 ATH_MSG_ERROR(
"Could not retrieve any EfficiencyCorrectionType");
46 return StatusCode::FAILURE;
47 }
48
49 if(m_sRecommendationTag == "2025-prerec") {
51 } else {
52 ATH_MSG_ERROR(
"Unknown RecommendationTag " << m_sRecommendationTag);
53 return StatusCode::FAILURE;
54 }
55
56
58 if (!
registry.registerSystematics(*
this))
59 {
61 return StatusCode::FAILURE;
62 }
63
64 printConfig();
65
66 return StatusCode::SUCCESS;
67}
68
69StatusCode TauEfficiencyCorrectionsTool::firstEvent()
70{
71 return StatusCode::SUCCESS;
72}
73
74StatusCode TauEfficiencyCorrectionsTool::beginEvent()
75{
76 if (!m_bIsConfigured)
77 {
79 ATH_CHECK(evtStore()->retrieve(xEventInfo,
"EventInfo"));
81 m_bIsConfigured = true;
82 }
83
84 if (!m_firstEvent){
86 m_firstEvent = true;
87
88 }
89 if (m_bIsData && !m_applyToData)
90 return StatusCode::SUCCESS;
91
93 ATH_CHECK(evtStore()->retrieve(xEventInfo,
"EventInfo"));
94
95 if (m_bReadRandomRunNumber)
96 {
97
98 m_iRunNumber = 0;
99 }
100
101 return StatusCode::SUCCESS;
102}
103
104
105void TauEfficiencyCorrectionsTool::printConfig() const
106{
107 ATH_MSG_DEBUG(
"TauEfficiencyCorrectionsTool with name " <<
name() <<
" is configured as follows:" );
108 for (auto iEfficiencyCorrectionType : m_vEfficiencyCorrectionTypes) {
109 ATH_MSG_DEBUG(
" EfficiencyCorrectionTypes " << iEfficiencyCorrectionType );
110 }
111 ATH_MSG_DEBUG(
" InputFilePathRecoHadTau " << m_sInputFilePathRecoHadTau );
112 ATH_MSG_DEBUG(
" InputFilePathEleIDHadTau " << m_sInputFilePathEleIDHadTau );
113 ATH_MSG_DEBUG(
" InputFilePathEleIDElectron " << m_sInputFilePathEleIDElectron );
114 ATH_MSG_DEBUG(
" InputFilePathJetIDHadTau " << m_sInputFilePathJetIDHadTau );
115 ATH_MSG_DEBUG(
" InputFilePathDecayModeHadTau " << m_sInputFilePathDecayModeHadTau );
116 ATH_MSG_DEBUG(
" InputFilePathTriggerHadTau " << m_sInputFilePathTriggerHadTau );
117 ATH_MSG_DEBUG(
" RecommendationTag " << m_sRecommendationTag );
119 ATH_MSG_DEBUG(
" UseTauSubstructure " << m_bUseTauSubstructure );
124}
125
126
128 double& eff, unsigned int )
129{
131
132 if (m_bIsData && !m_applyToData)
134
137
138 if(!(m_tTool->isSupportedRunNumber(m_iRunNumber)))
140
141 double dToolEff = 1.;
142 CP::CorrectionCode tmpCorrectionCode = m_tTool->getEfficiencyScaleFactor(xTau, dToolEff, m_iRunNumber);
144 return tmpCorrectionCode;
145
147
149}
150
151
153{
154 if (m_bIsData && !m_applyToData)
156
159
160 CP::CorrectionCode tmpCorrectionCode = m_tTool->applyEfficiencyScaleFactor(xTau, m_iRunNumber);
162 return tmpCorrectionCode;
163
165}
166
168
170{
171 if (m_tTool->isAffectedBySystematic(systematic))
172 return true;
173
174 return false;
175}
176
178
180{
182 sAffectingSystematics.
insert(m_tTool->affectingSystematics());
183 return sAffectingSystematics;
184}
185
187
189{
191 sRecommendedSystematics.
insert(m_tTool->recommendedSystematics());
192 return sRecommendedSystematics;
193}
194
195
196StatusCode TauEfficiencyCorrectionsTool::applySystematicVariation (
const CP::SystematicSet& sSystematicSet)
197{
198 ATH_CHECK(m_tTool->applySystematicVariation(sSystematicSet));
199 return StatusCode::SUCCESS;
200}
201
202
203StatusCode TauEfficiencyCorrectionsTool::initializeTools_2025_prerec()
204{
205 std::string sDirectory =
"TauAnalysisTools/" + std::string(
sSharedFilesVersion) +
"/EfficiencyCorrections/";
206 for (auto iEfficiencyCorrectionType : m_vEfficiencyCorrectionTypes){
207
209 {
210 if (m_sInputFilePathJetIDHadTau.empty()) {
211
212 if(m_useGNTau){
213 if(m_sCampaign=="mc23"){
214 m_sInputFilePathJetIDHadTau = m_useFastSim ? sDirectory + "GNTauID_TrueHadTau_Run3_incl_AF3.root" : sDirectory + "GNTauID_TrueHadTau_Run3.root";
215 } else if (m_sCampaign=="mc20"){
216 m_sInputFilePathJetIDHadTau = m_useFastSim ? sDirectory + "GNTauID_TrueHadTau_Run2_incl_AF3.root" : sDirectory + "GNTauID_TrueHadTau_Run2.root";
217 } else {
218 ATH_MSG_ERROR(
"GNTau ID correction not supported for campaign "<< m_sCampaign);
219 return StatusCode::FAILURE;
220 }
221 } else {
222
223 if(m_sCampaign=="mc23"){
224 m_sInputFilePathJetIDHadTau = m_useFastSim ? sDirectory + "RNNID_TrueHadTau_mc23_v2_incl_AF3.root" : sDirectory + "RNNID_TrueHadTau_mc23_v2.root";
225 } else if (m_sCampaign=="mc20"){
226 m_sInputFilePathJetIDHadTau = m_useFastSim ? sDirectory + "RNNID_TrueHadTau_mc20_v1_incl_AF3.root" : sDirectory + "RNNID_TrueHadTau_mc20_v1.root";
227 }
228 }
229 }
230 m_sVarName = "TauScaleFactorJetIDHadTau";
231
232 std::string sJetIDWP = ConvertJetIDToString(m_iJetIDLevel);
233 if (sJetIDWP.empty()) {
234 ATH_MSG_WARNING(
"Could not find valid ID working point. Skip ID efficiency corrections.");
235 continue;
236 }
237
238 if (m_tTool.empty()){
240 ATH_CHECK(
config.setProperty(
"InputFilePath", m_sInputFilePathJetIDHadTau));
242 ATH_CHECK(
config.setProperty(
"SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
246 }
248 }
250 {
251 if (m_sInputFilePathRecoHadTau.empty()) m_sInputFilePathRecoHadTau = sDirectory + "Reco_TrueHadTau_2026_v0.root";
252 m_sVarName = "TauScaleFactorReconstructionHadTau";
253
254 if (m_tTool.empty()){
256 ATH_CHECK(
config.setProperty(
"InputFilePath", m_sInputFilePathRecoHadTau));
258 ATH_CHECK(
config.setProperty(
"SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
261 }
263 }
265 {
266 if (m_sInputFilePathEleIDHadTau.empty()) {
268 m_sInputFilePathEleIDHadTau = sDirectory + "EleRNN_TrueHadTau_2026_eRNNLoose.root";
270 m_sInputFilePathEleIDHadTau = sDirectory + "EleRNN_TrueHadTau_2026_eRNNMedium.root";
271 } else {
272 ATH_MSG_ERROR(
"SFEleIDHadTau correction not supported for EleIDLevel="<<m_iEleIDLevel);
273 return StatusCode::FAILURE;
274 }
275 }
276 m_sVarName = "TauScaleFactorEleIDHadTau";
277 std::string ele_wp = ConvertEleIDToString(m_iEleIDLevel);
278
279 if (m_tTool.empty()){
281 ATH_CHECK(
config.setProperty(
"InputFilePath", m_sInputFilePathEleIDHadTau));
283 ATH_CHECK(
config.setProperty(
"SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
288 }
290 }
292 {
293
294 if (m_sInputFilePathEleIDElectron.empty()) {
295 if(m_useFastSim) {
296 ATH_MSG_WARNING(
"No fast-sim recommendation for tau electron veto, using full sim");
297 }
298
299 if(m_sCampaign=="mc23"){
300 if(m_useGNTau){
302 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_2026_looseGNTauID_1p.root";
304 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_2026_mediumGNTauID_1p.root";
305 }
306 else {
307 ATH_MSG_ERROR(
"SFEleIDElectron correction not supported for JetIDLevel="<<m_iJetIDLevel);
308 return StatusCode::FAILURE;
309 }
310 } else {
312 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_2022_looseRNNTauID_1p.root";
314 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_2022_mediumRNNTauID_1p.root";
315 }
316 else {
317 ATH_MSG_ERROR(
"SFEleIDElectron correction not supported for JetIDLevel="<<m_iJetIDLevel);
318 return StatusCode::FAILURE;
319 }
320 }
321 } else if(m_sCampaign=="mc20"){
322 if(m_useGNTau){
324 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_Run2_looseGNTauID_1p.root";
326 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_Run2_mediumGNTauID_1p.root";
327 }
328 else {
329 ATH_MSG_ERROR(
"SFEleIDElectron correction not supported for JetIDLevel="<<m_iJetIDLevel);
330 return StatusCode::FAILURE;
331 }
332 } else {
334 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_Run2_looseRNNTauID_1p.root";
336 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_Run2_mediumRNNTauID_1p_v1.root";
337 }
338 else {
339 ATH_MSG_ERROR(
"SFEleIDElectron correction not supported for JetIDLevel="<<m_iJetIDLevel);
340 return StatusCode::FAILURE;
341 }
342 }
343 }
344 }
345 m_sVarName = "TauScaleFactorEleIDElectron";
346 std::string ele_wp = ConvertEleIDToString(m_iEleIDLevel);
347 std::string sJetIDWP = ConvertJetIDToString(m_iJetIDLevel);
348
349 if (m_tTool.empty()){
351 ATH_CHECK(
config.setProperty(
"InputFilePath", m_sInputFilePathEleIDElectron));
353 ATH_CHECK(
config.setProperty(
"SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
358 }
360
362
363 if (m_sTriggerName.empty()) {
364 ATH_MSG_ERROR(
"Property \"Trigger\" was not set, please provide a trigger name.");
365 return StatusCode::FAILURE;
366 }
367
368 std::string trigFold = m_useGNTau ? "GNTau" : "RNN";
369
370 if(m_useGNTau && m_sCampaign!="mc23a")
371 ATH_MSG_WARNING(
"TauTrigger recommendations using offline GNTau ID are ONLY available for 2022 datasets. In all other cases the tool is retrieving the offline RNN ID based recommendations, which are NOT recommended to use");
372
373 if (m_sInputFilePathTriggerHadTau.empty()) {
374
375 if(m_sCampaign=="mc23a"){
376 if (m_sTriggerName.value().find("mediumRNN_tracktwoMVA") != std::string::npos) {
377 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/"+trigFold+"/Trigger_TrueHadTau_data2022"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
378 }
379 else {
380 ATH_MSG_ERROR(
"Trigger " << m_sTriggerName <<
" is not supported for " << m_sCampaign <<
" campaign. Please fix \"TriggerName\" property. In case of doubt please consult with TauTrigger coordinators");
381 return StatusCode::FAILURE;
382 }
383 } else if(m_sCampaign=="mc23d"){
384 if (m_sTriggerName.value().find("mediumRNN_tracktwoMVA") != std::string::npos) {
385 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN/Trigger_TrueHadTau_data2023"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
386 }
387 else {
388 ATH_MSG_ERROR(
"Trigger " << m_sTriggerName <<
" is not supported for " << m_sCampaign <<
" campaign. Please fix \"TriggerName\" property. In case of doubt please consult with TauTrigger coordinators");
389 return StatusCode::FAILURE;
390 }
391 } else if(m_sCampaign=="mc20"){
392 if (m_sTriggerName.value().find("tracktwoEF") != std::string::npos) {
393
394 if (m_sTriggerName.value().find("tau160") != std::string::npos) {
395 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN_R22/Trigger_TrueHadTau_data2018_comb_HLT_tau160L1TAU100_medium1_tracktwoEF_v1.root";
396 } else {
397 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN_R22/Trigger_TrueHadTau_data2018"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
398 }
399 } else if (m_sTriggerName.value().find("tracktwo") != std::string::npos) {
400
401 if (m_sTriggerName.value().find("tau160") != std::string::npos) {
402 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN_R22/Trigger_TrueHadTau_data161718_comb_HLT_tau160_medium1_tracktwo_v1.root";
403 } else if (m_sTriggerName.value().find("tau125") != std::string::npos) {
404
405 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN/Trigger_TrueHadTau_2019-summer_data161718_comb_HLT_tau125_medium1_tracktwo.root";
406 } else if (m_sTriggerName.value().find("tau60") != std::string::npos) {
407
408 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN_R22/Trigger_TrueHadTau_data1718"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
409 } else {
410 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN_R22/Trigger_TrueHadTau_data161718"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
411 }
412 } else {
413 ATH_MSG_ERROR(
"Trigger " << m_sTriggerName <<
" is not supported. Please fix \"TriggerName\" property. If this is correct, then please contact the tau trigger coordinators");
414 return StatusCode::FAILURE;
415 }
416 } else {
417 ATH_MSG_ERROR(
"SFs are not available for " << m_sCampaign <<
" campaign. If the config is correct, then please contact the tau trigger coordinators");
418 return StatusCode::FAILURE;
419 }
420 }
421 m_sVarName = "TauScaleFactorTriggerHadTau";
422 std::string sJetIDWP = ConvertTriggerIDToString(m_iJetIDLevel);
423
424 if (m_tTool.empty()){
425 asg::AsgToolConfig config(
"TauAnalysisTools::CommonEfficiencyTool/TriggerHadTauTool_"+m_sTriggerName+
"_tauID_"+sJetIDWP);
426 ATH_CHECK(
config.setProperty(
"InputFilePath", m_sInputFilePathTriggerHadTau));
428 ATH_CHECK(
config.setProperty(
"SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
433 }
435 }
436 else {
437 ATH_MSG_WARNING(
"unsupported EfficiencyCorrectionsType with enum " << iEfficiencyCorrectionType);
438 }
439 }
440
441 return StatusCode::SUCCESS;
442}
443
444
445
446StatusCode TauEfficiencyCorrectionsTool::beginInputFile()
447{
450 ATH_CHECK( inputMetaStore()->retrieve( fmd,
"FileMetaData" ) );
451 std::string simType("");
453
454 if(result) std::transform(simType.begin(), simType.end(), simType.begin(), ::toupper);
455
456 if( simType.find("ATLFAST3") != std::string::npos && !m_useFastSim){
457 ATH_MSG_WARNING(
"Input file is AF3 sample but you are _not_ using AF3 corrections and uncertainties, you should set \"useFastSim\" to \"true\"");
458 } else if (simType.find("FULLG4")!=std::string::npos && m_useFastSim){
459 ATH_MSG_WARNING(
"Input file is full simulation but you are using AF3 corrections and uncertainties, you should set \"useFastSim\" to \"false\"");
460 }
461 }
462
463 return StatusCode::SUCCESS;
464}
465
466
467std::string TauEfficiencyCorrectionsTool::ConvertJetIDToString(const int iLevel) const
468{
469 switch(iLevel)
470 {
472 return "none";
474 ATH_MSG_WARNING(
"Efficiency corrections for JETIDRNNVERYLOOSE working point are not supported.");
475 return "";
477 return "jetrnnsigloose";
479 return "jetrnnsigmedium";
481 return "jetrnnsigtight";
483 ATH_MSG_WARNING(
"Efficiency corrections for JETIDGNTAUVERYLOOSE working point are not supported.");
484 return "";
486 return "jetgntausigloose";
488 return "jetgntausigmedium";
490 return "jetgntausigtight";
491 default:
493 return "";
494 }
495}
496
497std::string TauEfficiencyCorrectionsTool::ConvertEleIDToString(const int iLevel) const
498{
499 switch(iLevel)
500 {
502 return "eleRNNTight";
504 return "eleRNNMedium";
506 return "eleRNNLoose";
507 default:
509 return "";
510 }
511}
512
513
514std::string TauEfficiencyCorrectionsTool::ConvertTriggerIDToString(const int iLevel) const
515{
516 switch(iLevel)
517 {
519 return "loose";
521 return "medium";
523 return "tight";
524 default:
526 return "";
527 }
528}
529
530
531std::string TauEfficiencyCorrectionsTool::GetTriggerSFMeasurementString() const
532{
533 std::string sMeasurement = "_comb_";
534
535 if (m_sTriggerSFMeasurement == "Ztautau")
536 sMeasurement = "_Ztt_";
537 else if (m_sTriggerSFMeasurement == "ttbar")
538 sMeasurement = "_ttbar_";
539 else if (m_sTriggerSFMeasurement != "combined")
540 ATH_MSG_WARNING(
"Trigger scale factor measurement \'" << m_sTriggerSFMeasurement <<
"\' is not supported. \'combined\' is used instead.");
541
542 return sMeasurement;
543}
544
545StatusCode TauEfficiencyCorrectionsTool::readRandomRunNumber()
546{
547
548 if (m_bReadRandomRunNumber && m_iRunNumber == 0)
549 {
553 {
555 return StatusCode::FAILURE;
556 }
557
558 if (!acc_rnd.isAvailable(*eventInfo))
559 {
560 ANA_MSG_ERROR(
"Failed to find the RandomRunNumber decoration. Call the apply() method from the PileupReweightingTool beforehand to get period dependent SFs.");
561 return StatusCode::FAILURE;
562 }
563
564 m_iRunNumber = acc_rnd(*eventInfo);
565
567 }
568
569 return StatusCode::SUCCESS;
570}
571
572}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
static const char *const sSharedFilesVersion
Version of the calibration files.
Return value from object correction CP tools.
@ Ok
The correction was done successfully.
This module implements the central registry for handling systematic uncertainties with CP tools.
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Class to wrap a set of SystematicVariations.
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Helper class to provide constant type-safe access to aux data.
bool eventType(EventType type) const
Check for one particular bitmask value.
@ IS_SIMULATION
true: simulation, false: data
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
EventInfo_v1 EventInfo
Definition of the latest event info version.
TauJet_v3 TauJet
Definition of the current "tau version".
FileMetaData_v1 FileMetaData
Declare the latest version of the class.