ATLAS Offline Software
TrigCaloTowerMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // ********************************************************************
6 //
7 // NAME: TrigCaloTowerMaker.cxx
8 // PACKAGE: Trigger/TrigAlgorithms/TrigCaloRec
9 //
10 // AUTHOR: P.A. Delsart
11 // This is an Hlt algorithm that creates Calorimeter towers
12 // It assumes CaloCellContainers are already produced and accessable
13 // through the input TriggerElement. Based on TrigCaloRec
14 //
15 // ********************************************************************
16 //
17 //
18 #include <sstream>
19 #include "GaudiKernel/IToolSvc.h"
20 #include "GaudiKernel/TypeNameString.h"
21 #include "GaudiKernel/StatusCode.h"
22 
23 #include "CxxUtils/phihelper.h"
26 
30 
31 #include "CaloEvent/CaloTowerContainer.h"
32 #include "CaloEvent/CaloTowerSeg.h"
34 
35 #include "TrigCaloTowerMaker.h"
36 
37 class ISvcLocator;
38 
40  ISvcLocator* pSvcLocator)
41  : AthReentrantAlgorithm(name, pSvcLocator),
42  m_includeFcal(false) {
43 
44 }
45 
47 // INITIALIZE:
48 // The initialize method will create all the required algorithm objects
49 // Note that it is NOT NECESSARY to run the initialize of individual
50 // sub-algorithms. The framework takes care of it.
52 
54  ATH_MSG_DEBUG("in initialize()");
55 
56  if (!m_monTool.empty()) {
57  ATH_MSG_DEBUG("Retrieving monTool");
58  CHECK(m_monTool.retrieve());
59  } else {
60  ATH_MSG_INFO("No monTool configured => NO MONITOING");
61  }
62 
63  ATH_CHECK(m_towerMakerTools.retrieve());
64 
66  for (auto& tool: m_towerMakerTools) {
67  tool->setTowerSeg(theTowerSeg);
68  }
69  // presence of tool with the name FC triggers use of FCal
70  for (auto& tool: m_towerMakerTools) {
71  if ( tool->name().find("FC") != std::string::npos) {
72  m_includeFcal = true;
73  ATH_MSG_INFO("Tool " << tool->name() << " is configured, will use FCal");
74  }
75  }
76 
78 
82  ATH_CHECK(m_caloTowerNav4LinkKey.initialize());
83 
84  ATH_MSG_DEBUG("Initialization of TrigCaloTowerMaker completed successfully");
85 
86  return StatusCode::SUCCESS;
87 }
88 
89 StatusCode TrigCaloTowerMaker::execute(const EventContext& ctx) const {
90  // Monitoring initialization...
91  auto timer = Monitored::Timer("TIME_execute");
92  auto time_tools = Monitored::Timer("TIME_tools");
93  auto mon_towerContainerSize = Monitored::Scalar("towerContainerSize", 0.);
94 
95  auto monitorIt =
96  Monitored::Group(m_monTool, timer, time_tools, mon_towerContainerSize);
97 
98  ATH_MSG_DEBUG("in execute()");
99 
100 
101  // Get RoiDescriptor
102  const bool seedLess = m_inputRoiKey.empty();
103  TrigRoiDescriptor roiDescriptor;
104  if (!seedLess) {
107  if ( !roiCollection.isValid()) {
108  ATH_MSG_ERROR("Cell maker did not get a valid RoIs collection");
109  return StatusCode::FAILURE;
110  }
111  if (roiCollection->size() == 0) {
112  ATH_MSG_DEBUG(" RoI collection size = 0");
113  return StatusCode::SUCCESS;
114  }
115  if (roiCollection->size() > 1)
116  ATH_MSG_WARNING("Misconfiguration - Called with "
117  << roiCollection->size()
118  << " ROI, but it should be called with 1 RoI - Will only "
119  "process the first RoI");
120 
121  roiDescriptor = roiCollection->front();
122  ATH_MSG_DEBUG("Operating on " << roiCollection->size() << "RoI(s)");
123  } else {
124  roiDescriptor = TrigRoiDescriptor(true);
125  }
126  ATH_MSG_DEBUG(" RoI id " << roiDescriptor.roiId()
127  << " located at phi = " << roiDescriptor.phi()
128  << ", eta = " << roiDescriptor.eta());
129 
130  auto caloTowerContainer = SG::makeHandle(m_outputTowerKey, ctx);
131 
135 
136  if (roiDescriptor.composite()) {
138  " Attempting to use composite RoI as a normal RoI - this is probably "
139  "*not* what you want to do "
140  << roiDescriptor);
141  }
142 
143  double eta0 = roiDescriptor.eta();
144  double phi0 = roiDescriptor.phi();
145 
147  double etamin = eta0 - m_deta / 2.;
148  double etamax = eta0 + m_deta / 2.;
149  // What if phimin < 0 or phimax > 2Pi ?? question
150  double phimin = phi0 - m_dphi / 2.;
151  double phimax = phi0 + m_dphi / 2.;
152 
153  ATH_MSG_DEBUG(" eta0 = " << eta0 << " phi0 = " << phi0
154  << " etamin = " << etamin << " etamax = " << etamax
155  << " phimin = " << phimin << " phimax = " << phimax);
156 
158  CaloTowerSeg::SubSeg subseg =
159  myseg.subseg(roiDescriptor.eta(), m_deta, roiDescriptor.phi(), m_dphi);
160  if (m_includeFcal) {
161  ATH_CHECK(
162  caloTowerContainer.record(std::make_unique<CaloTowerContainer>(myseg)));
163  } else {
164  ATH_CHECK(caloTowerContainer.record(
165  std::make_unique<CaloTowerContainer>(subseg.segmentation())));
166  }
167  CaloTowerContainer* pCaloTowerContainer = caloTowerContainer.ptr();
168 
169  ATH_CHECK(caloTowerContainer.symLink(m_caloTowerNav4LinkKey));
170  ATH_MSG_DEBUG("CaloTowerContainer"
171  << caloTowerContainer.name()
172  << " symlinked to INavigable4MomentumCollection in StoreGate");
173 
174  auto caloCellContainer = SG::makeHandle(m_inputCellsKey, ctx);
175  ATH_CHECK( caloCellContainer.isValid() );
176 
177  // Get the last container in the vector. Should be th one produced by the
178  // previous TrigCaloCellMaker.
179  const CaloCellContainer* theCellCont = caloCellContainer.ptr();
180 
182  " REGTEST: Retrieved a Cell Container of Size= " << theCellCont->size());
183 
184  // Now Build the towers
185  // -----------------------------------------------------------------
186  time_tools.start();
187 
188  for ( auto& tool: m_towerMakerTools ) {
189  if (m_includeFcal) {
190  ATH_CHECK(tool->execute(ctx, pCaloTowerContainer, theCellCont));
191  ATH_MSG_DEBUG("Executed tool " << tool.name());
192  } else {
193  ATH_CHECK(tool->execute(ctx, pCaloTowerContainer, theCellCont, &subseg));
194  ATH_MSG_DEBUG("Executed tool " << tool.name());
195  }
196  }
197  time_tools.stop();
198 
199  ATH_MSG_DEBUG(" REGTEST: Produced a Tower Container "
200  << caloTowerContainer.name() << " at "
201  << caloTowerContainer.cptr()
202  << " of Size= " << pCaloTowerContainer->size());
203  ATH_MSG_DEBUG(" handle info: " << caloTowerContainer);
204  mon_towerContainerSize = static_cast<float>(pCaloTowerContainer->size());
205 
206  return StatusCode::SUCCESS;
207 }
TrigCaloTowerMaker::m_maxEta
Gaudi::Property< double > m_maxEta
Definition: TrigCaloTowerMaker.h:58
TrigCaloTowerMaker::m_deta
Gaudi::Property< double > m_deta
Definition: TrigCaloTowerMaker.h:60
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
TrigCaloTowerMaker::m_nPhiTowers
Gaudi::Property< unsigned int > m_nPhiTowers
Number of phi segments in which we divide the calorimeter.
Definition: TrigCaloTowerMaker.h:54
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
INavigable4Momentum.h
TrigCaloTowerMaker::m_outputTowerKey
SG::WriteHandleKey< CaloTowerContainer > m_outputTowerKey
Definition: TrigCaloTowerMaker.h:76
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
InDetAccessor::phi0
@ phi0
Definition: InDetAccessor.h:33
TrigCaloTowerMaker::m_includeFcal
bool m_includeFcal
To help structure Tower container.
Definition: TrigCaloTowerMaker.h:89
RoiDescriptor::composite
virtual bool composite() const override final
SuperRoI compatability methods.
Definition: RoiDescriptor.h:137
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CaloTowerSeg.h
TrigCaloTowerMaker::m_dphi
Gaudi::Property< double > m_dphi
Definition: TrigCaloTowerMaker.h:61
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
TrigCaloTowerMaker::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrigCaloTowerMaker.cxx:89
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
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
CaloTowerSeg::SubSeg
A rectangular window within the segmentation.
Definition: CaloTowerSeg.h:220
TrigCaloTowerMaker::m_inputRoiKey
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_inputRoiKey
Definition: TrigCaloTowerMaker.h:66
CaloTowerContainer
Storable container class for CaloTower.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:77
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrigCaloTowerMaker.h
INavigable4MomentumCollection.h
DataVector::front
const T * front() const
Access the first element in the collection as an rvalue.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigCaloTowerMaker::m_inputCellsKey
SG::ReadHandleKey< CaloCellContainer > m_inputCellsKey
Definition: TrigCaloTowerMaker.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
phihelper.h
Helper for azimuthal angle calculations.
TrigCaloTowerMaker::m_caloTowerNav4LinkKey
SG::WriteHandleKey< INavigable4MomentumCollection > m_caloTowerNav4LinkKey
Definition: TrigCaloTowerMaker.h:81
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
TrigRoiDescriptor::roiId
virtual unsigned int roiId() const override final
these quantities probably don't need to be used any more
Definition: TrigRoiDescriptor.h:133
CaloTowerSeg::SubSeg::segmentation
CaloTowerSeg segmentation() const
Return a new segmentation object corresponding to this window.
Definition: CaloTowerSeg.cxx:85
TrigCaloTowerMaker::m_towerMakerTools
ToolHandleArray< CaloTowerBuilderToolBase > m_towerMakerTools
Definition: TrigCaloTowerMaker.h:64
TrigCaloTowerMaker::initialize
virtual StatusCode initialize() override
HLT method to initialize.
Definition: TrigCaloTowerMaker.cxx:53
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
RoiDescriptor::phi
virtual double phi() const override final
Methods to retrieve data members.
Definition: RoiDescriptor.h:100
TrigCaloTowerMaker::m_nEtaTowers
Gaudi::Property< unsigned int > m_nEtaTowers
Number of eta segments in which we divide the calorimeter.
Definition: TrigCaloTowerMaker.h:51
TrigCaloTowerMaker::m_minEta
Gaudi::Property< double > m_minEta
Eta limits of the region where the towers are built.
Definition: TrigCaloTowerMaker.h:57
TrigCaloTowerMaker::TrigCaloTowerMaker
TrigCaloTowerMaker(const std::string &name, ISvcLocator *pSvcLocator)
constructor
Definition: TrigCaloTowerMaker.cxx:39
RoiDescriptor::eta
virtual double eta() const override final
Definition: RoiDescriptor.h:101
CaloTowerSeg
Data object stores CaloTower segmentation.
Definition: CaloTowerSeg.h:37
TrigCaloTowerMaker::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigCaloTowerMaker.h:91
TrigRoiDescriptor
Athena::TPCnvVers::Current TrigRoiDescriptor
Definition: TrigSteeringEventTPCnv.cxx:68
TrigRoiDescriptor.h
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
LArCellBinning.etamin
etamin
Definition: LArCellBinning.py:137
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
CaloTowerBuilderToolBase.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
CaloTowerSeg::subseg
SubSeg subseg(double eta, double deta, double phi, double dphi) const
Return a window within the current segmentation.
Definition: CaloTowerSeg.cxx:23