ATLAS Offline Software
DiTauChargeDecorator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "StoreGate/ReadHandle.h"
9 
10 namespace DerivationFramework {
11 
12  DiTauChargeDecorator::DiTauChargeDecorator(const std::string& t, const std::string& n, const IInterface* p) :
13  base_class(t,n,p)
14  {
15  }
16 
18  {
19  // initialize read/write handle keys
20  ATH_CHECK( m_ditauContainerKey.initialize() );
21  ATH_CHECK( m_chargeKey.initialize() );
22 
23  return StatusCode::SUCCESS;
24  }
25 
26  StatusCode DiTauChargeDecorator::addBranches(const EventContext& ctx) const
27  {
28 
29 
30  // retrieve tau container
32  if (!ditauJetsReadHandle.isValid()) {
33  ATH_MSG_ERROR ("Could not retrieve DiTauJetContainer with key " << ditauJetsReadHandle.key());
34  return StatusCode::FAILURE;
35  }
36  const xAOD::DiTauJetContainer* ditauContainer = ditauJetsReadHandle.cptr();
37 
39 
40  for (const auto ditau : *ditauContainer) {
41  float ditau_charge = 0;
42  for (const auto& xTrack : ditau->trackLinks()) {
43  if (!xTrack.isValid())
44  continue;
45 
46  if(ditau->nSubjets() >= 2){
47  for (int i = 0; i < 2; ++i) { // loop over two leading subjets
48  TLorentzVector tlvSubjet = TLorentzVector();
49  tlvSubjet.SetPtEtaPhiE(ditau->subjetPt(i), ditau->subjetEta(i),
50  ditau->subjetPhi(i), ditau->subjetE(i));
51  double dR = tlvSubjet.DeltaR((*xTrack)->p4());
52  if (dR < 0.1) {
53  ditau_charge += (*xTrack)->charge();
54  break; //prevents double counting of tracks
55  }
56  } // loop over subjets
57  }
58  } // loop over tracks
59  dec_charge(*ditau) = ditau_charge;
60  }
61 
62  return StatusCode::SUCCESS;
63  }
64 }
65 
66 
DerivationFramework::DiTauChargeDecorator::m_ditauContainerKey
SG::ReadHandleKey< xAOD::DiTauJetContainer > m_ditauContainerKey
Definition: DiTauChargeDecorator.h:28
DerivationFramework::DiTauChargeDecorator::initialize
virtual StatusCode initialize() override
Definition: DiTauChargeDecorator.cxx:17
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
DerivationFramework::DiTauChargeDecorator::DiTauChargeDecorator
DiTauChargeDecorator(const std::string &t, const std::string &n, const IInterface *p)
Definition: DiTauChargeDecorator.cxx:12
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DiTauJetContainer.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::DiTauChargeDecorator::m_chargeKey
SG::WriteDecorHandleKey< xAOD::DiTauJetContainer > m_chargeKey
Definition: DiTauChargeDecorator.h:29
DerivationFramework::DiTauChargeDecorator::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override
Definition: DiTauChargeDecorator.cxx:26
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:727
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
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
DiTauChargeDecorator.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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
ReadHandle.h
Handle class for reading from StoreGate.