ATLAS Offline Software
DiTauIDDecoratorWrapper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "StoreGate/ReadHandle.h"
7 #include "xAODCore/ShallowCopy.h"
8 
9 namespace DerivationFramework {
10 
12  {
14  ATH_CHECK( m_tDiTauWPDecoratorTool.retrieve() );
15 
16  if ( m_WPCuts.size() != m_WPDecorKeys.size() ) {
17  ATH_MSG_ERROR ("Size mismatch between m_WPDecorKeys and m_WPCuts! Please check the configuration.");
18  return StatusCode::FAILURE;
19  }
20 
21  // initialize read/write handle keys
22  ATH_CHECK( m_ditauContainerKey.initialize() );
23  ATH_CHECK( m_scoreDecorKey.initialize() );
24  ATH_CHECK( m_WPDecorKeys.initialize() );
25 
26  return StatusCode::SUCCESS;
27  }
28 
29  StatusCode DiTauIDDecoratorWrapper::addBranches(const EventContext& ctx) const
30  {
31 
32  // retrieve ditau container
34  if (!ditauJetsReadHandle.isValid()) {
35  ATH_MSG_ERROR ("Could not retrieve DiTauJetContainer with key " << ditauJetsReadHandle.key());
36  return StatusCode::FAILURE;
37  }
38  const xAOD::DiTauJetContainer* ditauContainer = ditauJetsReadHandle.cptr();
39 
41 
42  std::vector<SG::WriteDecorHandle<xAOD::DiTauJetContainer, char> > WPDecors;
43  WPDecors.reserve (m_WPDecorKeys.size());
45  WPDecors.emplace_back (k, ctx);
46  }
47 
48  // create shallow copy
49  auto shallowCopy = xAOD::shallowCopyContainer (*ditauContainer);
50 
51  for (auto ditau : *shallowCopy.first) {
52 
53  float score = m_tDiTauOnnxDiscriminantTool->GetDiTauObjOnnxScore(*ditau);
54 
55  // copy over the relevant decorations (scores and working points)
56  const xAOD::DiTauJet* xDiTau = ditauContainer->at(ditau->index());
57  scoreDecor(*xDiTau) = score;
58 
59  int i=0;
61  bool decision = m_tDiTauWPDecoratorTool->passOmniWP(score, m_WPCuts.value().at(i));
62  dec(*xDiTau) = decision;
63  i++;
64  }
65  }
66 
67  delete shallowCopy.first;
68  delete shallowCopy.second;
69 
70  return StatusCode::SUCCESS;
71  }
72 }
ShallowCopy.h
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition: StoreGate/StoreGate/WriteDecorHandleKey.h:89
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DiTauIDDecoratorWrapper.h
DerivationFramework::DiTauIDDecoratorWrapper::m_scoreDecorKey
SG::WriteDecorHandleKey< xAOD::DiTauJetContainer > m_scoreDecorKey
Definition: DiTauIDDecoratorWrapper.h:34
DerivationFramework::DiTauIDDecoratorWrapper::m_WPDecorKeys
SG::WriteDecorHandleKeyArray< xAOD::DiTauJetContainer > m_WPDecorKeys
Definition: DiTauIDDecoratorWrapper.h:35
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::DiTauIDDecoratorWrapper::m_ditauContainerKey
SG::ReadHandleKey< xAOD::DiTauJetContainer > m_ditauContainerKey
Definition: DiTauIDDecoratorWrapper.h:33
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DerivationFramework::DiTauIDDecoratorWrapper::m_tDiTauWPDecoratorTool
ToolHandle< DiTauWPDecorator > m_tDiTauWPDecoratorTool
Definition: DiTauIDDecoratorWrapper.h:38
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
xAOD::score
@ score
Definition: TrackingPrimitives.h:514
DerivationFramework::DiTauIDDecoratorWrapper::m_WPCuts
Gaudi::Property< std::vector< float > > m_WPCuts
Definition: DiTauIDDecoratorWrapper.h:42
DerivationFramework::DiTauIDDecoratorWrapper::m_tDiTauOnnxDiscriminantTool
ToolHandle< DiTauOnnxDiscriminantTool > m_tDiTauOnnxDiscriminantTool
Definition: DiTauIDDecoratorWrapper.h:37
xAOD::DiTauJet_v1
Definition: DiTauJet_v1.h:31
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
ReadHandle.h
Handle class for reading from StoreGate.
DerivationFramework::DiTauIDDecoratorWrapper::initialize
virtual StatusCode initialize() override
Definition: DiTauIDDecoratorWrapper.cxx:11
fitman.k
k
Definition: fitman.py:528
DerivationFramework::DiTauIDDecoratorWrapper::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override
Definition: DiTauIDDecoratorWrapper.cxx:29