ATLAS Offline Software
Loading...
Searching...
No Matches
TauEfficiencyCorrectionsTool.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):
13
14namespace TauAnalysisTools
15{
16
17//______________________________________________________________________________
19 : asg::AsgMetadataTool( sName )
21 , m_bIsData(false)
22 , m_bIsConfigured(false)
23 , m_iRunNumber(0)
24{}
25
26//______________________________________________________________________________
32
33//______________________________________________________________________________
35{
36 ATH_MSG_INFO( "Initializing TauEfficiencyCorrectionsTool" );
37
39
41 ATH_MSG_WARNING("Truth match check will be skipped. This is ONLY FOR TESTING PURPOSE!");
42
43 // check efficiency correction type
45 {
46 ATH_MSG_ERROR("Could not retrieve any EfficiencyCorrectionType");
47 return StatusCode::FAILURE;
48 }
49
50 if(m_sRecommendationTag == "2025-prerec") {
52 } else if (m_sRecommendationTag == "2022-prerec") {
53 ATH_MSG_WARNING("2022-prerec tag are pre-recommendations superseeded by 2025-prerec");
55 }
56 else {
57 ATH_MSG_ERROR("Unknown RecommendationTag " << m_sRecommendationTag);
58 return StatusCode::FAILURE;
59 }
60
61 // for (auto tCommonEfficiencyTool : m_vCommonEfficiencyTools)
62 for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
63 {
64 ATH_CHECK((**it).setProperty("OutputLevel", this->msg().level()));
65 ATH_CHECK((**it).initialize());
66 }
67
68 // Add the affecting systematics to the global registry
70 if (!registry.registerSystematics(*this))
71 {
72 ATH_MSG_ERROR ("Unable to register the systematics");
73 return StatusCode::FAILURE;
74 }
75
77
78 return StatusCode::SUCCESS;
79}
80
82{
83 const xAOD::EventInfo* xEventInfo = nullptr;
84 ATH_CHECK(evtStore()->retrieve(xEventInfo, "EventInfo"));
85
86 if(m_sRecommendationTag == "2022-prerec"){
87 if (xEventInfo->runNumber() != 284500 && xEventInfo->runNumber() != 300000 && xEventInfo->runNumber() != 310000) // mc21/2022: 410000
88 {
89 ANA_MSG_WARNING( "Could not determine MC campaign from run number! The mu dependent systematic of the trigger scale factors should not be trusted. Current (" << xEventInfo->runNumber() << "). Will only print this warning once." );
90 }
91 if (xEventInfo->runNumber() < 410000) // mc21/2022: 410000
92 {
93 ANA_MSG_WARNING( "TauEfficiency callibrations from 2022-prerec are not recommended for Run2 MC. Will only print this warning once." );
94 }
95 }
96 return StatusCode::SUCCESS;
97}
98
100{
101 if (!m_bIsConfigured)
102 {
103 const xAOD::EventInfo* xEventInfo = nullptr;
104 ATH_CHECK(evtStore()->retrieve(xEventInfo,"EventInfo"));
106 m_bIsConfigured = true;
107 }
108
109 if (!m_firstEvent){
111 m_firstEvent = true;
112
113 }
114 if (m_bIsData)
115 return StatusCode::SUCCESS;
116
117 const xAOD::EventInfo* xEventInfo = nullptr;
118 ATH_CHECK(evtStore()->retrieve(xEventInfo, "EventInfo"));
119
121 {
122 // Reset the number at the beginning of event
123 m_iRunNumber = 0;
124 }
125
126 return StatusCode::SUCCESS;
127}
128
129//______________________________________________________________________________
131{
132 ATH_MSG_DEBUG( "TauEfficiencyCorrectionsTool with name " << name() << " is configured as follows:" );
133 for (auto iEfficiencyCorrectionType : m_vEfficiencyCorrectionTypes) {
134 ATH_MSG_DEBUG( " EfficiencyCorrectionTypes " << iEfficiencyCorrectionType );
135 }
136 ATH_MSG_DEBUG( " InputFilePathRecoHadTau " << m_sInputFilePathRecoHadTau );
137 ATH_MSG_DEBUG( " InputFilePathEleIDHadTau " << m_sInputFilePathEleIDHadTau );
138 ATH_MSG_DEBUG( " InputFilePathEleIDElectron " << m_sInputFilePathEleIDElectron );
139 ATH_MSG_DEBUG( " InputFilePathJetIDHadTau " << m_sInputFilePathJetIDHadTau );
140 ATH_MSG_DEBUG( " InputFilePathDecayModeHadTau " << m_sInputFilePathDecayModeHadTau );
141 ATH_MSG_DEBUG( " InputFilePathTriggerHadTau " << m_sInputFilePathTriggerHadTau );
142 ATH_MSG_DEBUG( " RecommendationTag " << m_sRecommendationTag );
143 ATH_MSG_DEBUG( " TriggerName " << m_sTriggerName );
144 ATH_MSG_DEBUG( " UseTauSubstructure " << m_bUseTauSubstructure );
145 ATH_MSG_DEBUG( " JetIDLevel " << m_iJetIDLevel );
146 ATH_MSG_DEBUG( " EleIDLevel " << m_iEleIDLevel );
147 ATH_MSG_DEBUG( " Campaign " << m_sCampaign );
148 ATH_MSG_DEBUG( " useFastSim " << m_useFastSim);
149}
150
151//______________________________________________________________________________
153 double& eff, unsigned int /*iRunNumber*/)
154{
155 eff = 1.;
156
157 if (m_bIsData)
159
162
163 for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
164 {
165 if ( !(**it)->isSupportedRunNumber(m_iRunNumber) )
166 continue;
167 double dToolEff = 1.;
168 CP::CorrectionCode tmpCorrectionCode = (**it)->getEfficiencyScaleFactor(xTau, dToolEff, m_iRunNumber);
169 if (tmpCorrectionCode != CP::CorrectionCode::Ok)
170 return tmpCorrectionCode;
171 eff *= dToolEff;
172 }
174}
175
176//______________________________________________________________________________
178{
179 if (m_bIsData)
181
184
185 for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
186 {
187 CP::CorrectionCode tmpCorrectionCode = (**it)->applyEfficiencyScaleFactor(xTau, m_iRunNumber);
188 if (tmpCorrectionCode != CP::CorrectionCode::Ok)
189 return tmpCorrectionCode;
190 }
192}
193
195//______________________________________________________________________________
197{
198 for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
199 if ((**it)->isAffectedBySystematic(systematic))
200 return true;
201 return false;
202}
203
205//______________________________________________________________________________
207{
208 CP::SystematicSet sAffectingSystematics;
209 for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
210 sAffectingSystematics.insert((**it)->affectingSystematics());
211 return sAffectingSystematics;
212}
213
215//______________________________________________________________________________
217{
218 CP::SystematicSet sRecommendedSystematics;
219 for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
220 sRecommendedSystematics.insert((**it)->recommendedSystematics());
221 return sRecommendedSystematics;
222}
223
224//______________________________________________________________________________
226{
227 for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
228 if ((**it)->applySystematicVariation(sSystematicSet) == StatusCode::FAILURE)
229 return StatusCode::FAILURE;
230 return StatusCode::SUCCESS;
231}
232
233//=================================PRIVATE-PART=================================
235{
236 std::string sDirectory = "TauAnalysisTools/" + std::string(sSharedFilesVersion) + "/EfficiencyCorrections/";
237 for (auto iEfficiencyCorrectionType : m_vEfficiencyCorrectionTypes){
238
239 if (iEfficiencyCorrectionType == SFJetIDHadTau)
240 {
241 if (m_sInputFilePathJetIDHadTau.empty()) {
242 if(m_useFastSim) {
243 ATH_MSG_WARNING("No fast-sim recommendation for Tau RNN, using full sim");
244 }
245
246 if(m_sCampaign=="mc23"){
247 m_sInputFilePathJetIDHadTau = sDirectory + "RNNID_TrueHadTau_mc23_v2.root";
248 } else if (m_sCampaign=="mc20"){
249 m_sInputFilePathJetIDHadTau = sDirectory + "RNNID_TrueHadTau_mc20_v1.root";
250 }
251 }
252 m_sVarName = "TauScaleFactorJetIDHadTau";
253
254 std::string sJetIDWP = ConvertJetIDToString(m_iJetIDLevel);
255 if (sJetIDWP.empty()) {
256 ATH_MSG_WARNING("Could not find valid ID working point. Skip ID efficiency corrections.");
257 continue;
258 }
259
260 asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>* tTool = new asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>("TauAnalysisTools::CommonEfficiencyTool/JetIDHadTauTool", this);
261 m_vCommonEfficiencyTools.push_back(tTool);
262 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathJetIDHadTau));
263 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
264 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
265 ATH_CHECK(tTool->setProperty("WP", sJetIDWP));
266 }
267 else if (iEfficiencyCorrectionType == SFRecoHadTau)
268 {
269 if (m_sInputFilePathRecoHadTau.empty()) m_sInputFilePathRecoHadTau = sDirectory + "Reco_TrueHadTau_2019-summer_v2.root";
270 m_sVarName = "TauScaleFactorReconstructionHadTau";
271
272 asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>* tTool = new asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>("TauAnalysisTools::CommonEfficiencyTool/RecoHadTauTool", this);
273 m_vCommonEfficiencyTools.push_back(tTool);
274 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathRecoHadTau));
275 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
276 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
277 }
278 else if (iEfficiencyCorrectionType == SFEleIDHadTau)
279 {
280 // the path must be updated once RNN eVeto SFs are available
281 if (m_sInputFilePathEleIDHadTau.empty()) m_sInputFilePathEleIDHadTau = sDirectory + "EleOLR_TrueHadTau_2016-ichep.root";
282 m_sVarName = "TauScaleFactorEleIDHadTau";
283
284 asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>* tTool = new asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>("TauAnalysisTools::CommonEfficiencyTool/EleIDHadTauTool", this);
285 m_vCommonEfficiencyTools.push_back(tTool);
286 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathEleIDHadTau));
287 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
288 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
289 }
290 else if (iEfficiencyCorrectionType == SFEleIDElectron)
291 {
292 // the path must be updated once RNN eVeto SFs are available
293 if (m_sInputFilePathEleIDElectron.empty()) {
294 if(m_useFastSim) {
295 ATH_MSG_WARNING("No fast-sim recommendation for tau electron veto, using full sim");
296 }
297
298 if(m_sCampaign=="mc23"){
299 if( m_iJetIDLevel == static_cast<int>(JETIDRNNLOOSE)){
300 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_2022_looseRNNTauID_1p.root";
301 } else if( m_iJetIDLevel == static_cast<int>(JETIDRNNMEDIUM)){
302 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_2022_mediumRNNTauID_1p.root";
303 }
304 else {
305 ATH_MSG_ERROR("SFEleIDElectron correction not supported for JetIDLevel="<<m_iJetIDLevel);
306 return StatusCode::FAILURE;
307 }
308 } else if(m_sCampaign=="mc20"){
309 if( m_iJetIDLevel == static_cast<int>(JETIDRNNLOOSE)){
310 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_Run2_looseRNNTauID_1p.root";
311 } else if( m_iJetIDLevel == static_cast<int>(JETIDRNNMEDIUM)){
312 m_sInputFilePathEleIDElectron = sDirectory + "EleRNN_TrueElectron_Run2_mediumRNNTauID_1p_v1.root";
313 }
314 else {
315 ATH_MSG_ERROR("SFEleIDElectron correction not supported for JetIDLevel="<<m_iJetIDLevel);
316 return StatusCode::FAILURE;
317 }
318 }
319 }
320 m_sVarName = "TauScaleFactorEleIDElectron";
321
322 asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>* tTool = new asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>("TauAnalysisTools::CommonEfficiencyTool/EleIDElectronTool", this);
323 m_vCommonEfficiencyTools.push_back(tTool);
324 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathEleIDElectron));
325 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
326 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
327 ATH_CHECK(tTool->setProperty("WP", ConvertEleIDToString(m_iEleIDLevel)));
328 ATH_CHECK(tTool->setProperty("UseTauSubstructure", false));
329
330 } else if (iEfficiencyCorrectionType == SFTriggerHadTau){
331
332 if (m_sTriggerName.empty()) {
333 ATH_MSG_ERROR("Property \"Trigger\" was not set, please provide a trigger name.");
334 return StatusCode::FAILURE;
335 }
336 if (m_sInputFilePathTriggerHadTau.empty()) {
337 // Determine the input file name from the given trigger name.
338 if(m_sCampaign=="mc23a"){
339 if (m_sTriggerName.value().find("mediumRNN_tracktwoMVA") != std::string::npos) {
340 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN/Trigger_TrueHadTau_data2022"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
341 }
342 else {
343 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");
344 return StatusCode::FAILURE;
345 }
346 } else if(m_sCampaign=="mc23d"){
347 if (m_sTriggerName.value().find("mediumRNN_tracktwoMVA") != std::string::npos) {
348 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN/Trigger_TrueHadTau_data2023"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
349 }
350 else {
351 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");
352 return StatusCode::FAILURE;
353 }
354 } else if(m_sCampaign=="mc20"){
355 if (m_sTriggerName.value().find("tracktwoEF") != std::string::npos) {
356 // check explicitly tau160 as the root file for this trigger was renamed
357 if (m_sTriggerName.value().find("tau160") != std::string::npos) {
358 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN_R22/Trigger_TrueHadTau_data2018_comb_HLT_tau160L1TAU100_medium1_tracktwoEF_v1.root";
359 } else {
360 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN_R22/Trigger_TrueHadTau_data2018"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
361 }
362 } else if (m_sTriggerName.value().find("tracktwo") != std::string::npos) {
363 // check explicitly tau160 as the root file for this trigger was renamed
364 if (m_sTriggerName.value().find("tau160") != std::string::npos) {
365 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN_R22/Trigger_TrueHadTau_data161718_comb_HLT_tau160_medium1_tracktwo_v1.root";
366 } else if (m_sTriggerName.value().find("tau125") != std::string::npos) {
367 // fall back to R21 recommendations for tau125 as currently SFs are not available for this trigger
368 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN/Trigger_TrueHadTau_2019-summer_data161718_comb_HLT_tau125_medium1_tracktwo.root";
369 } else if (m_sTriggerName.value().find("tau60") != std::string::npos) {
370 // SFs for tau60 are only for partial period
371 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN_R22/Trigger_TrueHadTau_data1718"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
372 } else {
373 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN_R22/Trigger_TrueHadTau_data161718"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
374 }
375 } else {
376 ATH_MSG_ERROR("Trigger " << m_sTriggerName << " is not supported. Please fix \"TriggerName\" property. If this is correct, then please contact the tau trigger coordinators");
377 return StatusCode::FAILURE;
378 }
379 } else {
380 ATH_MSG_ERROR("SFs are not available for " << m_sCampaign << " campaign. If the config is correct, then please contact the tau trigger coordinators");
381 return StatusCode::FAILURE;
382 }
383 }
384 m_sVarName = "TauScaleFactorTriggerHadTau";
385
386 asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>* tTool = new asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>("TauAnalysisTools::CommonEfficiencyTool/TriggerHadTauTool", this);
387 m_vCommonEfficiencyTools.push_back(tTool);
388 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathTriggerHadTau));
389 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
390 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
391 ATH_CHECK(tTool->setProperty("WP", ConvertTriggerIDToString(m_iJetIDLevel)));
392 ATH_CHECK(tTool->setProperty("DoTauTrig", true));
393 }
394 else {
395 ATH_MSG_WARNING("unsupported EfficiencyCorrectionsType with enum " << iEfficiencyCorrectionType);
396 }
397 }
398
399 return StatusCode::SUCCESS;
400}
401
402//_____________________________________________________________________________
403// this whole block is a place holder until we get R22 Run2 recommendations
404// none of these SFs are valid for R22 MC, except possibly RNN ID to very coarse approximation
406{
407 std::string sDirectory = "TauAnalysisTools/" + std::string(sSharedFilesVersion) + "/EfficiencyCorrections/";
408
409 // initialise paths and SF names unless they have been configured by the user
410 for (auto iEfficiencyCorrectionType : m_vEfficiencyCorrectionTypes)
411 {
412 if (iEfficiencyCorrectionType == SFJetIDHadTau)
413 {
414 if (m_sInputFilePathJetIDHadTau.empty()) {
415 if(m_useFastSim) {
416 ATH_MSG_WARNING("No fast-sim recommendation for Tau RNN, using full sim");
417 }
418
419 m_sInputFilePathJetIDHadTau = sDirectory + "RNNID_TrueHadTau_2022-prerecommendation_v2.root";
420 }
421 m_sVarName = "TauScaleFactorJetIDHadTau";
422
423 std::string sJetIDWP = ConvertJetIDToString(m_iJetIDLevel);
424 if (sJetIDWP.empty()) {
425 ATH_MSG_WARNING("Could not find valid ID working point. Skip ID efficiency corrections.");
426 continue;
427 }
428
429 asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>* tTool = new asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>("TauAnalysisTools::CommonEfficiencyTool/JetIDHadTauTool", this);
430 m_vCommonEfficiencyTools.push_back(tTool);
431 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathJetIDHadTau));
432 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
433 //ATH_CHECK(tTool->setProperty("UseTauSubstructure", m_bUseTauSubstructure));
434 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
435 ATH_CHECK(tTool->setProperty("WP", sJetIDWP));
436 }
437 else if (iEfficiencyCorrectionType == SFEleIDHadTau)
438 {
439 // the path must be updated once RNN eVeto SFs are available
440 if (m_sInputFilePathEleIDHadTau.empty()) m_sInputFilePathEleIDHadTau = sDirectory + "EleOLR_TrueHadTau_2016-ichep.root";
441 m_sVarName = "TauScaleFactorEleIDHadTau";
442
443 asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>* tTool = new asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>("TauAnalysisTools::CommonEfficiencyTool/EleIDHadTauTool", this);
444 m_vCommonEfficiencyTools.push_back(tTool);
445 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathEleIDHadTau));
446 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
447 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
448 }
449 else if (iEfficiencyCorrectionType == SFEleIDElectron)
450 {
451 // the path must be updated once RNN eVeto SFs are available
452 if (m_sInputFilePathEleIDElectron.empty()) {
453 if(m_useFastSim) {
454 ATH_MSG_WARNING("No fast-sim recommendation for tau electron veto, using full sim");
455 }
456
457 m_sInputFilePathEleIDElectron = sDirectory+ "EleRNN_TrueElectron_2022-mc20-prerec-v2.root";
458 }
459 m_sVarName = "TauScaleFactorEleIDElectron";
460
461 asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>* tTool = new asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>("TauAnalysisTools::CommonEfficiencyTool/EleIDElectronTool", this);
462 m_vCommonEfficiencyTools.push_back(tTool);
463 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathEleIDElectron));
464 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
465 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
466 ATH_CHECK(tTool->setProperty("WP", ConvertEleIDToString(m_iEleIDLevel)));
467 ATH_CHECK(tTool->setProperty("UseTauSubstructure", false));
468 }
469 else if (iEfficiencyCorrectionType == SFRecoHadTau)
470 {
471 if (m_sInputFilePathRecoHadTau.empty()) m_sInputFilePathRecoHadTau = sDirectory + "Reco_TrueHadTau_2019-summer_v2.root";
472 m_sVarName = "TauScaleFactorReconstructionHadTau";
473
474 asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>* tTool = new asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>("TauAnalysisTools::CommonEfficiencyTool/RecoHadTauTool", this);
475 m_vCommonEfficiencyTools.push_back(tTool);
476 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathRecoHadTau));
477 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
478 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
479 }
480 else if (iEfficiencyCorrectionType == SFDecayModeHadTau)
481 {
482 if (m_sInputFilePathDecayModeHadTau.empty()) m_sInputFilePathDecayModeHadTau = sDirectory + "DecayModeSubstructure_TrueHadTau_2019-summer.root";
483 m_sVarName = "TauScaleFactorDecayModeHadTau";
484
485 std::string sJetIDWP = ConvertJetIDToString(m_iJetIDLevel);
486 if (sJetIDWP.empty()) {
487 ATH_MSG_WARNING("Could not find valid ID working point. Skip ID efficiency corrections.");
488 continue;
489 }
490
492 m_vCommonEfficiencyTools.push_back(tTool);
494 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathDecayModeHadTau));
495 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
496 ATH_CHECK(tTool->setProperty("UseTauSubstructure", true));
497 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
498 ATH_CHECK(tTool->setProperty("WP", sJetIDWP));
499 }
500 else if (iEfficiencyCorrectionType == SFTriggerHadTau)
501 {
502 if (m_sTriggerName.empty()) {
503 ATH_MSG_ERROR("Property \"Trigger\" was not set, please provide a trigger name.");
504 return StatusCode::FAILURE;
505 }
506 if (m_sInputFilePathTriggerHadTau.empty()) {
507 // Determine the input file name from the given trigger name.
508 // Triggers having "mediumRNN_tracktwoMVA are only part of 2018aftTS1.
509 // Every other trigger having "tracktwoEF" is only part of 2018.
510 // Every other trigger having "tau160_medium1" is only part of 2016.
511 // Every other trigger having "tau160" is only part of 2017/2018.
512 // Lastly check for other possible triggers, if this is not fulfilled the passed trigger is not supported.
513 if (m_sTriggerName.value().find("mediumRNN_tracktwoMVA") != std::string::npos) {
514 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN/Trigger_TrueHadTau_2019-summer_data2018aftTS1"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
515 }
516 else if (m_sTriggerName.value().find("tracktwoEF") != std::string::npos) {
517 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN/Trigger_TrueHadTau_2019-summer_data2018"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
518 }
519 else if (m_sTriggerName.value().find("tau160_medium1") != std::string::npos) {
520 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN/Trigger_TrueHadTau_2019-summer_data2016"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
521 }
522 else if ((m_sTriggerName.value().find("tau160") != std::string::npos) || (m_sTriggerName.value().find("tau60") != std::string::npos)) {
523 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN/Trigger_TrueHadTau_2019-summer_data1718"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
524 }
525 else if ((m_sTriggerName.value().find("tau125") != std::string::npos) || (m_sTriggerName.value().find("tau25") != std::string::npos) || (m_sTriggerName.value().find("tau35") != std::string::npos) || (m_sTriggerName.value().find("tau50") != std::string::npos) || (m_sTriggerName.value().find("tau80") != std::string::npos) ) {
526 m_sInputFilePathTriggerHadTau = sDirectory+"Trigger/RNN/Trigger_TrueHadTau_2019-summer_data161718"+GetTriggerSFMeasurementString()+m_sTriggerName+".root";
527 }
528 else {
529 ATH_MSG_ERROR("Trigger " << m_sTriggerName << " is not supported. Please fix \"TriggerName\" property.");
530 return StatusCode::FAILURE;
531 }
532 }
533 m_sVarName = "TauScaleFactorTriggerHadTau";
534
535 asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>* tTool = new asg::AnaToolHandle<ITauEfficiencyCorrectionsTool>("TauAnalysisTools::CommonEfficiencyTool/TriggerHadTauTool", this);
536 m_vCommonEfficiencyTools.push_back(tTool);
537 ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathTriggerHadTau));
538 ATH_CHECK(tTool->setProperty("VarName", m_sVarName));
539 ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
540 ATH_CHECK(tTool->setProperty("WP", ConvertTriggerIDToString(m_iJetIDLevel)));
541 ATH_CHECK(tTool->setProperty("DoTauTrig", true));
542 }
543 else {
544 ATH_MSG_WARNING("unsupported EfficiencyCorrectionsType with enum " << iEfficiencyCorrectionType);
545 }
546 }
547
548 return StatusCode::SUCCESS;
549}
550
551// auto detection of simulation flavour, used to cross check configuration of tool
552//______________________________________________________________________________
554{
555 if (inputMetaStore()->contains<xAOD::FileMetaData>("FileMetaData")) {
556 const xAOD::FileMetaData* fmd = nullptr;
557 ATH_CHECK( inputMetaStore()->retrieve( fmd, "FileMetaData" ) );
558 std::string simType("");
559 bool result = fmd->value( xAOD::FileMetaData::simFlavour , simType );
560 // if no result -> no simFlavor metadata, so must be data
561 if(result) std::transform(simType.begin(), simType.end(), simType.begin(), ::toupper);
562
563 if( simType.find("ATLFAST3") != std::string::npos && !m_useFastSim){
564 ATH_MSG_WARNING("Input file is AF3 sample but you are _not_ using AF3 corrections and uncertainties, you should set \"useFastSim\" to \"true\"");
565 } else if (simType.find("FULLG4")!=std::string::npos && m_useFastSim){
566 ATH_MSG_WARNING("Input file is full simulation but you are using AF3 corrections and uncertainties, you should set \"useFastSim\" to \"false\"");
567 }
568 }
569
570 return StatusCode::SUCCESS;
571}
572
573//______________________________________________________________________________
574std::string TauEfficiencyCorrectionsTool::ConvertJetIDToString(const int iLevel) const
575{
576 switch(iLevel)
577 {
578 case JETIDNONE:
579 return "none";
580 case JETIDRNNVERYLOOSE:
581 ATH_MSG_WARNING("Efficiency corrections for JETIDRNNVERYLOOSE working point are not supported.");
582 return "";
583 case JETIDRNNLOOSE:
584 return "jetrnnsigloose";
585 case JETIDRNNMEDIUM:
586 return "jetrnnsigmedium";
587 case JETIDRNNTIGHT:
588 return "jetrnnsigtight";
589 default:
590 ATH_MSG_WARNING("No valid JetID level passed.");
591 return "";
592 }
593}
594
595std::string TauEfficiencyCorrectionsTool::ConvertEleIDToString(const int iLevel) const
596{
597 switch(iLevel)
598 {
599 case ELEIDRNNTIGHT:
600 return "eleRNNTight";
601 case ELEIDRNNMEDIUM:
602 return "eleRNNMedium";
603 case ELEIDRNNLOOSE:
604 return "eleRNNLoose";
605 default:
606 ATH_MSG_WARNING("No valid EleID level passed.");
607 return "";
608 }
609}
610
611//______________________________________________________________________________
613{
614 switch(iLevel)
615 {
616 case JETIDRNNLOOSE:
617 return "loose";
618 case JETIDRNNMEDIUM:
619 return "medium";
620 case JETIDRNNTIGHT:
621 return "tight";
622 default:
623 ATH_MSG_WARNING("No valid TriggerID level passed.");
624 return "";
625 }
626}
627
628//______________________________________________________________________________
630{
631 std::string sMeasurement = "_comb_";
632
633 if (m_sTriggerSFMeasurement == "Ztautau")
634 sMeasurement = "_Ztt_";
635 else if (m_sTriggerSFMeasurement == "ttbar")
636 sMeasurement = "_ttbar_";
637 else if (m_sTriggerSFMeasurement != "combined")
638 ATH_MSG_WARNING("Trigger scale factor measurement \'" << m_sTriggerSFMeasurement << "\' is not supported. \'combined\' is used instead.");
639
640 return sMeasurement;
641}
642
644{
645 // read the random run rumber from the EventInfo
647 {
648 static const SG::ConstAccessor<unsigned int> acc_rnd("RandomRunNumber");
649 const xAOD::EventInfo* eventInfo = nullptr;
650 if (!evtStore()->contains<xAOD::EventInfo>("EventInfo") || !evtStore()->retrieve(eventInfo, "EventInfo").isSuccess())
651 {
652 ANA_MSG_ERROR("Could not retrieve EventInfo");
653 return StatusCode::FAILURE;
654 }
655
656 if (!acc_rnd.isAvailable(*eventInfo))
657 {
658 ANA_MSG_ERROR("Failed to find the RandomRunNumber decoration. Call the apply() method from the PileupReweightingTool beforehand to get period dependent SFs.");
659 return StatusCode::FAILURE;
660 }
661
662 m_iRunNumber = acc_rnd(*eventInfo);
663
664 ANA_MSG_VERBOSE("Read RandomRunNumber as " << m_iRunNumber);
665 }
666
667 return StatusCode::SUCCESS;
668}
669
670} // namespace TauAnalysisTools
#define ASG_MAKE_ANA_TOOL(handle, type)
create the tool in the given tool handle
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
#define ANA_MSG_VERBOSE(xmsg)
Macro printing verbose messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
static const char *const sSharedFilesVersion
Version of the calibration files.
ServiceHandle< StoreGateSvc > & evtStore()
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.
StatusCode registerSystematics(const IReentrantSystematicsTool &tool)
effects: register all the systematics from the tool
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 isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual StatusCode initialize()
Function initialising the tool.
virtual bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const
returns: whether this tool is affected by the given systematics
virtual void printConfig() const
Print tool configuration.
virtual CP::SystematicSet affectingSystematics() const
returns: the list of all systematics this tool can be affected by
TauEfficiencyCorrectionsTool(const std::string &sName)
Create a proper constructor for Athena.
virtual StatusCode beginInputFile()
Function called when a new input file is opened.
virtual CP::SystematicSet recommendedSystematics() const
returns: the list of all systematics this tool recommends to use
Gaudi::Property< std::vector< int > > m_vecEfficiencyCorrectionTypes
virtual CP::CorrectionCode getEfficiencyScaleFactor(const xAOD::TauJet &xTau, double &eff, unsigned int iRunNumber=0)
Get the tau efficiency scale factor.
StatusCode beginEvent()
Function called when a new events is loaded.
std::vector< asg::AnaToolHandle< ITauEfficiencyCorrectionsTool > * > m_vCommonEfficiencyTools
virtual CP::CorrectionCode applyEfficiencyScaleFactor(const xAOD::TauJet &xTau, unsigned int iRunNumber=0)
Decorate the tau with its efficiency scale factor.
virtual StatusCode applySystematicVariation(const CP::SystematicSet &systConfig)
effects: configure this tool for the given list of systematic variations.
a modified tool handle that allows its owner to configure new tools from the C++ side
AsgMetadataTool(const std::string &name)
Normal ASG tool constructor with a name.
MetaStorePtr_t inputMetaStore() const
Accessor for the input metadata store.
bool eventType(EventType type) const
Check for one particular bitmask value.
@ IS_SIMULATION
true: simulation, false: data
uint32_t runNumber() const
The current event's run number.
@ simFlavour
Fast or Full sim [string].
bool value(MetaDataType type, std::string &val) const
Get a pre-defined string value out of the object.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
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.