ATLAS Offline Software
gTowerMakerFromGfexTowers.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 // gTowerMakerFromGfexTowers - description
7 // ---------------------------------------------------------
8 // This algorithm is meant to create from the xAOD::gFexTowerContainer (EDM) a gTowerContainer (a SG object the gFEX simulation needs)
9 // It needs to get both inputs available:
10 // * Decoded gFex input data, known as L1_gFexDataTowers
11 // * Emulated gFex input data, known as L1_gFexEmulatedTowers (to be confirmed if this is the name in gFex)
12 //
13 // begin : 14 07 2023
14 // email : cecilia.tosciri@cern.ch
15 //
16 //***************************************************************************/
17 
19 
20 #include "L1CaloFEXSim/gTower.h"
25 
26 #include "StoreGate/WriteHandle.h"
27 #include "StoreGate/ReadHandle.h"
28 
29 
30 namespace LVL1 {
31 
32 gTowerMakerFromGfexTowers::gTowerMakerFromGfexTowers(const std::string& name, ISvcLocator* pSvcLocator)
33  : AthAlgorithm(name, pSvcLocator)
34 {}
35 
36 
38 {
39  ATH_CHECK( m_gDataTowerKey.initialize(!m_isMC) );
40  // ATH_CHECK( m_gDataTower50Key.initialize(!m_isMC) );
43  ATH_CHECK( m_gTowerBuilderTool.retrieve() );
45 
46  return StatusCode::SUCCESS;
47 
48 }
49 
50 
52 {
53  ATH_MSG_DEBUG("Executing " << name() << ", input: " << m_gDataTowerKey.key() << ", output: " << m_gTowerContainerSGKey.key());
54 
55  const EventContext& ctx = Gaudi::Hive::currentContext();
56 
57  //Reading the decoded Data gTower container
58  SG::ReadHandle<xAOD::gFexTowerContainer> gDataTowerContainer;
59  bool gDataTowerFilled = false;
60  if(!m_isMC){
62  if(!gDataTowerContainer.isValid()) {
63  ATH_MSG_FATAL("Could not retrieve collection " << gDataTowerContainer.key() );
64  return StatusCode::FAILURE;
65  }
66  gDataTowerFilled = !gDataTowerContainer->empty();
67  }
68 
69  //Reading the Emulated gTower container
70  SG::ReadHandle<xAOD::gFexTowerContainer> gEmulatedTowerContainer;
71 
72  if(m_UseEmulated){
73  gEmulatedTowerContainer = SG::ReadHandle<xAOD::gFexTowerContainer>(m_gEmulTowerKey, ctx);
74  if(!gEmulatedTowerContainer.isValid()) {
75  ATH_MSG_FATAL("Could not retrieve collection " << gEmulatedTowerContainer.key() );
76  return StatusCode::FAILURE;
77  }
78  }
79 
80 
81 
82 
83  // STEP 0 - Make a fresh local gTowerContainer
84  std::unique_ptr<gTowerContainer> local_gTowerContainerRaw = std::make_unique<gTowerContainer>();
85 
86  // STEP 1 - Make some gTowers and fill the local container (This is the one the simulation reads)
87  m_gTowerBuilderTool->init(local_gTowerContainerRaw);
88 
89  // STEP 2 - Mapping gFexTowers with decoded Energies
90  if( !m_isMC && (gDataTowerFilled || m_UseEmulated) ) {
91 
92  SG::ReadHandle<xAOD::gFexTowerContainer> * data_gTowerContainer = &gDataTowerContainer;
93 
94  if(m_UseEmulated){
95  // If we allow emulated input data, then we need to check if decoded data is available, otherwise use emulated
96  data_gTowerContainer = gDataTowerContainer->empty() ? &gEmulatedTowerContainer : &gDataTowerContainer;
97  }
98 
99  ATH_MSG_DEBUG("Collection used to build the gTower for simulation: " << (*data_gTowerContainer).key() << " with size: "<<(*data_gTowerContainer)->size() << ". Expected towers 1152");
100 
101  for(const xAOD::gFexTower* my_gTower : *(*data_gTowerContainer) ) {
102 
103  unsigned int TTID = my_gTower->gFEXtowerID(); //This is the simulation tower ID
104 
105  // Find the simulation ID from this firmware ID
106  int ID = local_gTowerContainerRaw->getIDfromFWID(TTID);
107  if (ID == -1) {
108  ATH_MSG_WARNING("Cannot find simulation ID from firmware ID - This gFexTower will be ignored. (Needs investigation). Please report this!" );
109  continue;
110  }
111 
112  LVL1::gTower *targetTower;
113  if( (targetTower = local_gTowerContainerRaw->findTower(ID)) ) {
114 
115  targetTower->setTotalEt(my_gTower->towerEt());
116  targetTower->setIsSaturated(my_gTower->isSaturated());
117 
118  }
119  else {
120  ATH_MSG_WARNING("Tower ID is officially unknown - it will be ignored. (Needs investigation). Please report this!" );
121  continue;
122  }
123  }
124  }
125  else{
126  ATH_MSG_DEBUG("Falling into the legacy path");
127  ATH_CHECK(m_gSuperCellTowerMapperTool->AssignSuperCellsToTowers(local_gTowerContainerRaw));
128  ATH_CHECK(m_gSuperCellTowerMapperTool->AssignTriggerTowerMapper(local_gTowerContainerRaw));
129  }
130 
131  // STEP 3 - Write the completed gTowerContainer into StoreGate (move the local copy in memory)
133  ATH_CHECK(gTowerContainerSG.record(std::move( local_gTowerContainerRaw ) ) );
134 
135  // STEP 4 - Close and clean the event
136  m_gTowerBuilderTool->reset();
137 
138  return StatusCode::SUCCESS;
139 }
140 
141 
142 } // end of LVL1 namespace
gFexTowerContainer.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
LVL1::gTower::setIsSaturated
void setIsSaturated(char isSaturated)
Sets saturation flag.
Definition: gTower.cxx:170
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
LVL1::gTowerMakerFromGfexTowers::m_gSuperCellTowerMapperTool
ToolHandle< IgSuperCellTowerMapper > m_gSuperCellTowerMapperTool
Definition: gTowerMakerFromGfexTowers.h:53
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
LVL1::gTowerMakerFromGfexTowers::m_UseEmulated
Gaudi::Property< bool > m_UseEmulated
Definition: gTowerMakerFromGfexTowers.h:45
gTowerContainer.h
LVL1::gTower
The gTower class is an interface object for gFEX trigger algorithms The purposes are twofold:
Definition: gTower.h:38
LVL1::gTower::setTotalEt
void setTotalEt(int totEt)
Definition: gTower.cxx:88
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
gFEXCompression.h
gTowerBuilder.h
LVL1::gTowerMakerFromGfexTowers::execute
virtual StatusCode execute() override
Definition: gTowerMakerFromGfexTowers.cxx:51
WriteHandle.h
Handle class for recording to StoreGate.
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::gFexTower_v1
Class describing input data of a LVL1 eFEX.
Definition: gFexTower_v1.h:22
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
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
LVL1::gTowerMakerFromGfexTowers::m_gDataTowerKey
SG::ReadHandleKey< xAOD::gFexTowerContainer > m_gDataTowerKey
Definition: gTowerMakerFromGfexTowers.h:36
TrigConf::name
Definition: HLTChainList.h:35
LVL1::gTowerMakerFromGfexTowers::m_gEmulTowerKey
SG::ReadHandleKey< xAOD::gFexTowerContainer > m_gEmulTowerKey
Definition: gTowerMakerFromGfexTowers.h:42
LVL1::gTowerMakerFromGfexTowers::gTowerMakerFromGfexTowers
gTowerMakerFromGfexTowers(const std::string &name, ISvcLocator *pSvcLocator)
Definition: gTowerMakerFromGfexTowers.cxx:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LVL1::gTowerMakerFromGfexTowers::initialize
virtual StatusCode initialize() override
Definition: gTowerMakerFromGfexTowers.cxx:37
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
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
LVL1::gTowerMakerFromGfexTowers::m_gTowerBuilderTool
ToolHandle< IgTowerBuilder > m_gTowerBuilderTool
Definition: gTowerMakerFromGfexTowers.h:52
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ReadHandle.h
Handle class for reading from StoreGate.
LVL1::gTowerMakerFromGfexTowers::m_gTowerContainerSGKey
SG::WriteHandleKey< LVL1::gTowerContainer > m_gTowerContainerSGKey
Definition: gTowerMakerFromGfexTowers.h:50
gTower.h
LVL1::gTowerMakerFromGfexTowers::m_isMC
Gaudi::Property< bool > m_isMC
Definition: gTowerMakerFromGfexTowers.h:46
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
gTowerMakerFromGfexTowers.h