ATLAS Offline Software
TauAnalysisToolsExampleAthena.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // EDM include(s):
8 
9 // Local include(s):
11 
12 using namespace TauAnalysisTools;
13 
14 TauAnalysisToolsExampleAthena::TauAnalysisToolsExampleAthena( const std::string& name, ISvcLocator* svcLoc )
15  : AthAlgorithm( name, svcLoc )
16  , m_selTool( "TauAnalysisTools::TauSelectionTool/TauSelectionTool", this )
17  , m_smearTool( "TauAnalysisTools::TauSmearingTool/TauSmearingTool", this )
18  , m_effTool( "TauAnalysisTools::TauEfficiencyCorrectionsTool/TauEfficiencyCorrectionsTool", this )
19 {
20  declareProperty( "SGKey", m_sgKey_TauJets = "TauJets" );
21  declareProperty( "SGKey_MuonRM", m_sgKey_TauJets_MuonRM = "TauJets_MuonRM" );
22  declareProperty( "UseMuonRemovalTaus", m_useMuonRemovalTaus = false );
23  declareProperty( "TauSelectionTool", m_selTool );
24  declareProperty( "TauSmearingTool", m_smearTool );
25  declareProperty( "TauEfficiencyTool", m_effTool );
26 }
27 
29 {
30  // Greet the user:
31  ATH_MSG_INFO( "Initialising" );
32  ATH_MSG_DEBUG( "TauJets SGKey = " << m_sgKey_TauJets );
34  ATH_MSG_DEBUG( "TauJets_MuonRM SGKey = " << m_sgKey_TauJets_MuonRM );
35  }
36  ATH_MSG_DEBUG( "TauSelectionTool = " << m_selTool );
37  ATH_MSG_DEBUG( "TauSmearingTool = " << m_smearTool );
38  ATH_MSG_DEBUG( "TauEfficiencyTool = " << m_effTool );
39 
40  // Retrieve the tools:
41  ATH_CHECK( m_selTool.retrieve() );
42  ATH_CHECK( m_smearTool.retrieve() );
43  ATH_CHECK( m_effTool.retrieve() );
44 
45  // Return gracefully:
46  return StatusCode::SUCCESS;
47 }
48 
50 {
51  // Retrieve the taus:
52  std::vector<const xAOD::TauJet*> taus_to_calibrate;
53  const xAOD::TauJetContainer* taus_std = 0;
54  ATH_CHECK( evtStore()->retrieve( taus_std, m_sgKey_TauJets ) );
55  ATH_MSG_INFO( "Number of taus: " << taus_std->size() );
56  const xAOD::TauJetContainer* taus_muonRM = 0;
58  ATH_CHECK( evtStore()->retrieve( taus_muonRM, m_sgKey_TauJets_MuonRM ) );
59  ATH_MSG_INFO( "Number of muon removal taus: " << taus_muonRM->size() );
60  taus_to_calibrate = TauAnalysisTools::combineTauJetsWithMuonRM(taus_std, taus_muonRM);
61  }
62  else {
63  for (const xAOD::TauJet* tau : *taus_std){
64  taus_to_calibrate.push_back(tau);
65  }
66  }
67  // Loop over them:
68  for(const xAOD::TauJet* tau_uncali : taus_to_calibrate)
69  {
70  ATH_MSG_DEBUG( " current tau: eta = " << tau_uncali->eta()
71  << ", phi = " << tau_uncali->phi()
72  << ", pt = " << tau_uncali->pt() );
73 
74  // Select "good" taus:
75  if( ! m_selTool->accept( *tau_uncali ) ) continue;
76 
77  // Print some info about the selected tau:
78  ATH_MSG_INFO( " Selected tau: eta = " << tau_uncali->eta()
79  << ", phi = " << tau_uncali->phi()
80  << ", pt = " << tau_uncali->pt() );
81 
82  // copy constant objects to non-constant
83  xAOD::TauJet* tau = 0;
84  tau = new xAOD::TauJet();
85  tau->makePrivateStore( *tau_uncali );
86 
87  ATH_CHECK (m_effTool->applyEfficiencyScaleFactor(*tau));
88 
89  static const SG::ConstAccessor<double> accTauScaleFactorJetID ("TauScaleFactorJetID");
90  ATH_MSG_INFO( " sf = " << accTauScaleFactorJetID (*tau) );
91 
92  ATH_CHECK (m_smearTool->applyCorrection(*tau));
93  ATH_MSG_INFO( "Unsmeared tau pt " << tau->pt() << " Smeared tau pt: " << tau->p4().Pt());
94  }
95 
96  // Return gracefully:
97  return StatusCode::SUCCESS;
98 }
TauAnalysisTools::TauAnalysisToolsExampleAthena::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: TauAnalysisToolsExampleAthena.cxx:28
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TauAnalysisTools::TauAnalysisToolsExampleAthena::m_useMuonRemovalTaus
bool m_useMuonRemovalTaus
Definition: TauAnalysisToolsExampleAthena.h:42
TauAnalysisTools
Definition: TruthCollectionMakerTau.h:16
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TauAnalysisTools::TauAnalysisToolsExampleAthena::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: TauAnalysisToolsExampleAthena.cxx:49
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SG::ConstAccessor< double >
TauAnalysisTools::TauAnalysisToolsExampleAthena::m_smearTool
ToolHandle< ITauSmearingTool > m_smearTool
Connection to the smearing tool.
Definition: TauAnalysisToolsExampleAthena.h:47
xAOD::TauJet_v3::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TauAnalysisToolsExampleAthena.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TauJet
TauJet_v3 TauJet
Definition of the current "tau version".
Definition: Event/xAOD/xAODTau/xAODTau/TauJet.h:17
TauJetContainer.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
TauAnalysisTools::TauAnalysisToolsExampleAthena::m_sgKey_TauJets_MuonRM
std::string m_sgKey_TauJets_MuonRM
Special StoreGate key for the muon-removed taus.
Definition: TauAnalysisToolsExampleAthena.h:41
AthAlgorithm
Definition: AthAlgorithm.h:47
TauAnalysisTools::TauAnalysisToolsExampleAthena::m_selTool
ToolHandle< ITauSelectionTool > m_selTool
Connection to the selection tool.
Definition: TauAnalysisToolsExampleAthena.h:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:172
xAOD::TauJet_v3::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: TauJet_v3.cxx:97
TauAnalysisTools::TauAnalysisToolsExampleAthena::m_effTool
ToolHandle< ITauEfficiencyCorrectionsTool > m_effTool
Connection to the efficiency correction tool.
Definition: TauAnalysisToolsExampleAthena.h:49
TauAnalysisTools::TauAnalysisToolsExampleAthena::m_sgKey_TauJets
std::string m_sgKey_TauJets
StoreGate key for the tau container to investigate.
Definition: TauAnalysisToolsExampleAthena.h:37
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
TauAnalysisTools::TauAnalysisToolsExampleAthena::TauAnalysisToolsExampleAthena
TauAnalysisToolsExampleAthena(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: TauAnalysisToolsExampleAthena.cxx:14
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TauAnalysisTools::combineTauJetsWithMuonRM
std::vector< const xAOD::TauJet * > combineTauJetsWithMuonRM(const xAOD::TauJetContainer *taus_std, const xAOD::TauJetContainer *taus_muonRM)
combine the standard taujets container with the muon removal container
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:620