ATLAS Offline Software
TrigTauCaloRoiUpdater.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "GaudiKernel/MsgStream.h"
8 #include "GaudiKernel/IToolSvc.h"
9 #include "GaudiKernel/StatusCode.h"
10 
12 #include "CxxUtils/phihelper.h"
13 
14 #include "TLorentzVector.h"
15 
16 TrigTauCaloRoiUpdater::TrigTauCaloRoiUpdater(const std::string & name, ISvcLocator* pSvcLocator)
17  : AthReentrantAlgorithm(name, pSvcLocator)
18 {
19 
20 }
21 
22 
24 {
25  ATH_MSG_DEBUG("Initializing " << name());
26  ATH_MSG_DEBUG("dRForCenter: " << m_dRForCenter);
27 
28  ATH_MSG_DEBUG("Initialising HandleKeys");
32 
33  return StatusCode::SUCCESS;
34 }
35 
36 
37 StatusCode TrigTauCaloRoiUpdater::execute(const EventContext& ctx) const
38 {
39  ATH_MSG_DEBUG("Running " << name());
40 
41  //---------------------------------------------------------------
42  // Prepare I/O
43  //---------------------------------------------------------------
44 
45  // Prepare output RoI container
46  std::unique_ptr<TrigRoiDescriptorCollection> roiCollection = std::make_unique<TrigRoiDescriptorCollection>();
48  ATH_CHECK(outputRoIHandle.record(std::move(roiCollection)));
49 
50 
51  // Retrieve input RoI descriptor
53  ATH_MSG_DEBUG("Size of roisHandle: " << roisHandle->size());
54  const TrigRoiDescriptor* roiDescriptor = roisHandle->at(0); // We only have one RoI in the handle
55 
56 
57  // Fill local variables for RoI reference position
58  float eta = roiDescriptor->eta();
59  float phi = roiDescriptor->phi();
60 
61  const float dEta = (roiDescriptor->etaPlus() - roiDescriptor->etaMinus()) / 2;
62  const float dPhi = CxxUtils::deltaPhi(roiDescriptor->phiPlus(), roiDescriptor->phiMinus()) / 2;
63 
64  ATH_MSG_DEBUG("RoI ID: " << roiDescriptor->roiId() << ", eta: " << eta << ", phi: " << phi);
65 
66 
67 
68  //---------------------------------------------------------------
69  // Find detector tau axis
70  //---------------------------------------------------------------
71 
72  // Retrieve Input CaloClusterContainer
74  ATH_CHECK(CCContainerHandle.isValid());
75  const xAOD::CaloClusterContainer *RoICaloClusterContainer = CCContainerHandle.get();
76 
77  if(!RoICaloClusterContainer) {
78  ATH_MSG_ERROR("No CaloCluster container found");
79  return StatusCode::FAILURE;
80  }
81 
82  ATH_MSG_DEBUG("Size of vector CaloCluster container is: " << RoICaloClusterContainer->size());
83 
84  // We first need to get the barycenter of the LCTopo jet, including all clusters
85  TLorentzVector tau_barycenter;
86  for(const xAOD::CaloCluster* cluster : *RoICaloClusterContainer) {
87  // Skip clusters with negative energy
88  if(cluster->e() < 0) continue;
89 
90  tau_barycenter += cluster->p4();
91  }
92 
93  // Determine the LCTopo jet pT at the detector axis
94  TLorentzVector tau_detector_axis;
95  for(const xAOD::CaloCluster* cluster : *RoICaloClusterContainer) {
96  // Skip clusters with negative energy
97  if(cluster->e() < 0) continue;
98 
99  // Skip clusters further than a maximum Delta R
100  if(tau_barycenter.DeltaR(cluster->p4()) > m_dRForCenter) continue;
101 
102  tau_detector_axis += cluster->p4();
103  }
104 
105 
106 
107  //---------------------------------------------------------------
108  // Update the RoI
109  //---------------------------------------------------------------
110 
111  // Only update the roi if tau_detector_axis.Pt() > 0, i.e. if the calo cluster sum makes sense
112  if(tau_detector_axis.Pt() > 0) {
113  eta = tau_detector_axis.Eta();
114  phi = tau_detector_axis.Phi();
115  }
116 
117  // Create the new RoI
118  outputRoIHandle->push_back(std::make_unique<TrigRoiDescriptor>(
119  roiDescriptor->roiWord(), roiDescriptor->l1Id(), roiDescriptor->roiId(),
120  eta, eta-dEta, eta+dEta,
122  roiDescriptor->zed(), roiDescriptor->zedMinus(), roiDescriptor->zedPlus()
123  ));
124 
125 
126  ATH_MSG_DEBUG("Input RoI: " << *roiDescriptor);
127  ATH_MSG_DEBUG("Output RoI: " << *outputRoIHandle->back());
128 
129  return StatusCode::SUCCESS;
130 }
TrigTauCaloRoiUpdater::m_roIInputKey
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roIInputKey
Definition: TrigTauCaloRoiUpdater.h:31
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
RoiDescriptor::zedMinus
virtual double zedMinus() const override final
z at the most backward end of the RoI
Definition: RoiDescriptor.h:113
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CxxUtils::wrapToPi
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition: phihelper.h:24
TrigTauCaloRoiUpdater::m_dRForCenter
Gaudi::Property< float > m_dRForCenter
Definition: TrigTauCaloRoiUpdater.h:29
TrigRoiDescriptor::roiWord
virtual unsigned int roiWord() const override final
Definition: TrigRoiDescriptor.h:135
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
TrigTauCaloRoiUpdater::m_clustersKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clustersKey
Definition: TrigTauCaloRoiUpdater.h:32
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TauGNNUtils::Variables::Track::dPhi
bool dPhi(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:538
TrigTauCaloRoiUpdater.h
TrigTauCaloRoiUpdater::TrigTauCaloRoiUpdater
TrigTauCaloRoiUpdater(const std::string &, ISvcLocator *)
Definition: TrigTauCaloRoiUpdater.cxx:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigRoiDescriptor::l1Id
virtual unsigned int l1Id() const override final
Definition: TrigRoiDescriptor.h:134
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
RoiDescriptor::zed
virtual double zed() const override final
Definition: RoiDescriptor.h:102
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CxxUtils::deltaPhi
T deltaPhi(T phiA, T phiB)
Return difference phiA - phiB in range [-pi, pi].
Definition: phihelper.h:42
phihelper.h
Helper for azimuthal angle calculations.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
TrigRoiDescriptor::roiId
virtual unsigned int roiId() const override final
these quantities probably don't need to be used any more
Definition: TrigRoiDescriptor.h:133
SG::WriteHandle< TrigRoiDescriptorCollection >
RoiDescriptor::etaPlus
virtual double etaPlus() const override final
gets eta at zedPlus
Definition: RoiDescriptor.h:115
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
RoiDescriptor::phi
virtual double phi() const override final
Methods to retrieve data members.
Definition: RoiDescriptor.h:100
TrigTauCaloRoiUpdater::initialize
virtual StatusCode initialize() override
Definition: TrigTauCaloRoiUpdater.cxx:23
RoiDescriptor::eta
virtual double eta() const override final
Definition: RoiDescriptor.h:101
TrigRoiDescriptor.h
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
TrigTauCaloRoiUpdater::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrigTauCaloRoiUpdater.cxx:37
RoiDescriptor::phiPlus
virtual double phiPlus() const override final
gets phiPlus
Definition: RoiDescriptor.h:118
RoiDescriptor::etaMinus
virtual double etaMinus() const override final
gets eta at zMinus
Definition: RoiDescriptor.h:116
TauGNNUtils::Variables::Track::dEta
bool dEta(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:527
RoiDescriptor::phiMinus
virtual double phiMinus() const override final
gets phiMinus
Definition: RoiDescriptor.h:119
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigTauCaloRoiUpdater::m_roIOutputKey
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_roIOutputKey
Definition: TrigTauCaloRoiUpdater.h:33
RoiDescriptor::zedPlus
virtual double zedPlus() const override final
z at the most forward end of the RoI
Definition: RoiDescriptor.h:112