ATLAS Offline Software
TrigCaloClusterCalibrator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /********************************************************************
6  *
7  * NAME: TrigCaloClusterCalibrator
8  * PACKAGE: Trigger/TrigAlgorithms/TrigCaloRec
9  *
10  * AUTHOR: Jon Burr
11  * CREATED: 2020/07/10
12  *
13  * Shallow copy an existing cluster container and apply cluster processors to
14  * it. Largely copied from the TrigCaloClusterMaker.
15  *********************************************************************/
16 
19 #include "xAODCore/ShallowCopy.h"
21 #include "StoreGate/ReadHandle.h"
22 #include "StoreGate/WriteHandle.h"
24 #include <tuple>
25 
27  const std::string& name, ISvcLocator* pSvcLocator) :
28  AthReentrantAlgorithm(name, pSvcLocator)
29 {
30 }
31 
33 {
34  ATH_MSG_INFO("Initialise " << name() );
35 
36  if (!m_monTool.empty() )
37  ATH_CHECK(m_monTool.retrieve() );
38  else
39  ATH_MSG_INFO("No monitoring tool configured");
40 
41  ATH_CHECK( m_clusterCorrections.retrieve() );
45 
46  return StatusCode::SUCCESS;
47 }
48 
49 StatusCode TrigCaloClusterCalibrator::execute(const EventContext& ctx) const
50 {
51  ATH_MSG_DEBUG("Running " << name() );
52  auto time_corr = Monitored::Timer("TIME_ClustCorr");
53 
54  // Do the shallow copying
56  {
57  // Make a temporary scope - this means that the unique pointers die at the
58  // end of the scope (so don't hang around after the move call)
60  std::pair<xAOD::CaloClusterContainer*, xAOD::ShallowAuxContainer*> copyPair =
61  xAOD::shallowCopyContainer(*inputClusters);
62  // Show that we're taking ownership explicitly
63  std::unique_ptr<xAOD::CaloClusterContainer> clusters{copyPair.first};
64  std::unique_ptr<xAOD::ShallowAuxContainer> clustersAux{copyPair.second};
65  // And record
66  ATH_CHECK( outputClusters.record(std::move(clusters), std::move(clustersAux)));
67  // We also need to copy across the cell links information.
68  // To explain: the non-const cell iteration methods use an internal pointer,
69  // which is only finalized into an element link into the persistent
70  // container later. Therefore while we have a modifiable cluster, it has to
71  // have this local pointer present...
72  for (auto itrPair = std::make_pair(inputClusters->begin(), outputClusters->begin());
73  itrPair != std::make_pair(inputClusters->end(), outputClusters->end());
74  ++itrPair.first, ++itrPair.second) {
75  const CaloClusterCellLink* inputLinks = (**itrPair.first).getCellLinks();
76  if (!inputLinks) {
77  ATH_MSG_ERROR("Failed to read the cell links from the input clusters!");
78  return StatusCode::FAILURE;
79  }
80  (**itrPair.second).addCellLink(std::make_unique<CaloClusterCellLink>(*inputLinks));
81  }
82  }
83 
84  time_corr.start();
85  for (const ToolHandle<CaloClusterProcessor>& clcorr : m_clusterCorrections) {
86  for (xAOD::CaloCluster* cl : *outputClusters) {
87  if (!m_isSW.value() ||
88  (std::abs(cl->eta0()) < 1.45 && clcorr->name().find("37") != std::string::npos) ||
89  (std::abs(cl->eta0()) >= 1.45 && clcorr->name().find("55") != std::string::npos) ) {
90  ATH_CHECK(clcorr->execute(ctx, cl));
91  ATH_MSG_VERBOSE("Executed correction tool " << clcorr->name());
92  }
93  }
94  }
95  time_corr.stop();
96 
97  // Now we also have to make the cell links persistent
99  ATH_CHECK(CaloClusterStoreHelper::finalizeClusters(cellLinks, outputClusters.ptr()));
100  // After this is done, the non-const cell iteration functions will segfault!
101  // This means we really shouldn't let anyone retrieve this as a non-const
102  // container...
103  ATH_CHECK( outputClusters.setConst() );
104 
105  // fill monitored containers
106  // Only monitor kinematic quantities which the calibrations may have changed
108  time_corr,
109  Monitored::Collection("Et", *outputClusters, &xAOD::CaloCluster::et),
110  Monitored::Collection("Phi", *outputClusters, &xAOD::CaloCluster::calPhi),
111  Monitored::Collection("Eta", *outputClusters, &xAOD::CaloCluster::calEta)).fill();
112 
113  // Add REGTEST entries
114  if (!outputClusters->empty() ) {
115  ATH_MSG_DEBUG(" REGTEST: Last Cluster Et = " << outputClusters->back()->et());
116  ATH_MSG_DEBUG(" REGTEST: Last Cluster eta = " << outputClusters->back()->eta());
117  ATH_MSG_DEBUG(" REGTEST: Last Cluster phi = " << outputClusters->back()->phi());
118  }
119 
120  return StatusCode::SUCCESS;
121 }
ShallowCopy.h
CaloClusterStoreHelper::finalizeClusters
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
Definition: CaloClusterStoreHelper.cxx:64
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
TrigCaloClusterCalibrator::m_clusterCorrections
ToolHandleArray< CaloClusterProcessor > m_clusterCorrections
Definition: TrigCaloClusterCalibrator.h:50
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrigCaloClusterCalibrator::m_inputClustersKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_inputClustersKey
Definition: TrigCaloClusterCalibrator.h:52
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::CaloCluster_v1::calEta
flt_t calEta() const
Get in signal state CALIBRATED.
TrigCaloClusterCalibrator.h
xAOD::CaloCluster_v1::et
double et() const
Definition: CaloCluster_v1.h:856
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ShallowAuxContainer.h
TrigCaloClusterCalibrator::m_outputCellLinksKey
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_outputCellLinksKey
Definition: TrigCaloClusterCalibrator.h:60
SG::VarHandleBase::setConst
StatusCode setConst()
Set the 'const' bit for the bound proxy in the store.
Definition: StoreGate/src/VarHandleBase.cxx:606
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TrigCaloClusterCalibrator::TrigCaloClusterCalibrator
TrigCaloClusterCalibrator(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigCaloClusterCalibrator.cxx:26
WriteHandle.h
Handle class for recording to StoreGate.
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::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::CaloCluster_v1::calPhi
flt_t calPhi() const
Get in signal state CALIBRATED.
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.
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TrigCaloClusterCalibrator::m_isSW
Gaudi::Property< bool > m_isSW
Definition: TrigCaloClusterCalibrator.h:67
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
TrigCaloClusterCalibrator::m_outputClustersKey
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outputClustersKey
Definition: TrigCaloClusterCalibrator.h:56
CaloClusterStoreHelper.h
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TrigCaloClusterCalibrator::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrigCaloClusterCalibrator.cxx:49
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
ReadHandle.h
Handle class for reading from StoreGate.
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
TrigCaloClusterCalibrator::initialize
virtual StatusCode initialize() override
Definition: TrigCaloClusterCalibrator.cxx:32
TrigCaloClusterCalibrator::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigCaloClusterCalibrator.h:64