ATLAS Offline Software
jTowerMakerFromJfexTowers.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 // jTowerMakerFromJfexTowers - description
7 // ---------------------------------------------------------
8 // This algorithm is meant to create from the xAOD::jFexTowerContainer (EDM) a jTowerContainer (a SG object the jFEX simulation needs)
9 // It needs to get both inputs available:
10 // * Decoded jFex input data, known as L1_jFexDataTowers (It can be empty, since it is pre-scaled)
11 // * Emulated jFex input data, known as L1_jFexEmulatedTowers
12 //
13 // begin : 01 06 2023
14 // email : sergi.rodriguez@cern.ch
15 //
16 //***************************************************************************/
17 
18 #undef NDEBUG
19 
21 
22 #include "L1CaloFEXSim/jTower.h"
27 
28 #include "StoreGate/WriteHandle.h"
29 #include "StoreGate/ReadHandle.h"
30 
31 #define DEBUG_VHB 1
32 
33 
34 namespace LVL1 {
35 
36 jTowerMakerFromJfexTowers::jTowerMakerFromJfexTowers(const std::string& name, ISvcLocator* pSvcLocator)
37  : AthReentrantAlgorithm(name, pSvcLocator)
38 {}
39 
40 
42 {
43  ATH_MSG_DEBUG("isMC: " << m_isMC );
44  ATH_MSG_DEBUG("UseEmulated: " << m_UseEmulated );
45  ATH_CHECK( m_DataTowerKey.initialize(!m_isMC) );
46  ATH_CHECK( m_EmulTowerKey.initialize(m_UseEmulated) );
48  ATH_CHECK( m_jTowerBuilderTool.retrieve() );
50 
51  return StatusCode::SUCCESS;
52 
53 }
54 
55 
56 StatusCode jTowerMakerFromJfexTowers::execute(const EventContext& ctx) const
57 {
58  ATH_MSG_DEBUG("Executing " << name() << ", processing event number " );
59 
60  //Reading the decoded Data jTower container
61  SG::ReadHandle<xAOD::jFexTowerContainer> jDataTowerContainer;
62  bool jDataTowerFilled = false;
63  if(!m_isMC){
64  jDataTowerContainer = SG::ReadHandle<xAOD::jFexTowerContainer>(m_DataTowerKey, ctx);
65  if(!jDataTowerContainer.isValid()) {
66  ATH_MSG_ERROR("Could not retrieve collection " << jDataTowerContainer.key() );
67  return StatusCode::FAILURE;
68  }
69  jDataTowerFilled = !jDataTowerContainer->empty();
70  }
71 
72  //Reading the Emulated jTower container
73  SG::ReadHandle<xAOD::jFexTowerContainer> jEmulatedTowerContainer;
74 
75  if(m_UseEmulated){
76  jEmulatedTowerContainer = SG::ReadHandle<xAOD::jFexTowerContainer>(m_EmulTowerKey, ctx);
77  if(!jEmulatedTowerContainer.isValid()) {
78  ATH_MSG_ERROR("Could not retrieve collection " << jEmulatedTowerContainer.key() );
79  return StatusCode::FAILURE;
80  }
81  }
82 
83 
84  // STEP 0 - Make a fresh local jTowerContainer
85  std::unique_ptr<jTowerContainer> local_jTowerContainerRaw = std::make_unique<jTowerContainer>();
86 
87  // STEP 1 - Make some jTowers and fill the local container (This is the one the simulation reads)
88  m_jTowerBuilderTool->init(local_jTowerContainerRaw);
89 
90  // STEP 2 - Mapping jFexTowers with decoded Energies
91  if( jDataTowerFilled || m_UseEmulated ) {
92 
93  SG::ReadHandle<xAOD::jFexTowerContainer> * data_jTowerContainer;
94 
95  if(m_UseEmulated && !jDataTowerFilled){
96  data_jTowerContainer = &jEmulatedTowerContainer;
97  }
98  else{
99  data_jTowerContainer = &jDataTowerContainer;
100  }
101 
102  ATH_MSG_DEBUG("Collection used to build the jTower for simulation: " << (*data_jTowerContainer).key() << " with size: "<<(*data_jTowerContainer)->size());
103 
104  for(const xAOD::jFexTower* my_jTower : *(*data_jTowerContainer) ) {
105 
106  unsigned int TTID = my_jTower->jFEXtowerID();
107 
108  LVL1::jTower *targetTower;
109  if( (targetTower = local_jTowerContainerRaw->findTower(TTID)) ) {
110 
111  targetTower->setiEta( my_jTower->globalEta() );
112  targetTower->setiPhi( my_jTower->globalPhi() );
113  targetTower->setCentreEta( my_jTower->eta() );
114  targetTower->setCentrePhi( my_jTower->phi() );
115  targetTower->setOnlineID( my_jTower->OnlineID() );
116 
117  uint8_t source = my_jTower->Calosource(); // Values: EMB:0 Tile:1 EMEC:2 HEC:3 FCAL1:4 FCAL2:5 FCAL3:6
118 
119  // Set up for Tile energies
120  if(source == 1) {
121  // Always in the hadronic layer = 1
122  targetTower->set_Et(1,(my_jTower->et_count()).at(0)*500);// conversion factor of 500
123 
124  //setting the saturaion
125  if( (my_jTower->isjTowerSat()).at(0) ) targetTower->setHADSat();
126  }
127  else { //Now we do LATOME
128 
129  int layer = 1; // Hadronic layer
130  if(source == 0 or source == 2 or source == 4 ) layer = 0; // Electromagnetic layer
131 
132  // LATOME encoded Et needs to be converted to MeV
133  targetTower->set_Et(layer, jFEXCompression::Expand( (my_jTower->et_count()).at(0) ) );
134 
135  //Setting the saturation
136  if( (my_jTower->isjTowerSat()).at(0) ){
137  if( layer == 1 ){
138  targetTower->setHADSat();
139  }
140  else{
141  targetTower->setEMSat();
142  }
143  }
144  }
145  }
146  else {
147  ATH_MSG_ERROR("Tower ID is officially unknown - it will be ignored. (Needs investigation). Please report this!" );
148  continue;
149  }
150  }
151  }
152  else{
153  ATH_MSG_ERROR("Falling into the legacy path. This should never happen!. Use EmulatedTowers or DataTowers - Contact L1Calo offline experts");
154  return StatusCode::FAILURE;
155 
156  // Prefer to keep this for debugging purposes - Experts only
157  // It does reconstruct the jTowers using eta/phi coordinates and internal parameters from the CaloCell and TriggerTower containers.
158  // EmulatedTowers and DataTowers are xAOD objects, so they can saved into an AOD file.
159  ATH_CHECK(m_jSuperCellTowerMapperTool->AssignSuperCellsToTowers(local_jTowerContainerRaw));
160  ATH_CHECK(m_jSuperCellTowerMapperTool->AssignTriggerTowerMapper(local_jTowerContainerRaw));
161  }
162 
163  // STEP 3 - Once coordinates energies and all are filled, then we fill pileup and noise values
164  ATH_CHECK(m_jTowerBuilderTool->AssignPileupAndNoiseValues(local_jTowerContainerRaw));
165 
166  // STEP 4 - Write the completed jTowerContainer into StoreGate (move the local copy in memory)
168  ATH_CHECK(jTowerContainerSG.record(std::move( local_jTowerContainerRaw ) ) );
169 
170  // STEP 5 - Close and clean the event
171  m_jTowerBuilderTool->reset();
172 
173  return StatusCode::SUCCESS;
174 }
175 
176 
177 } // end of LVL1 namespace
jFexTowerContainer.h
LVL1::jTower::setCentreEta
void setCentreEta(float ieta)
Add to eta/phi values of a specified tower.
Definition: jTower.cxx:298
jTowerMakerFromJfexTowers.h
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
LVL1::jTower::setiEta
void setiEta(int ieta)
Definition: jTower.cxx:302
LVL1::jTowerMakerFromJfexTowers::m_jSuperCellTowerMapperTool
ToolHandle< IjSuperCellTowerMapper > m_jSuperCellTowerMapperTool
Definition: jTowerMakerFromJfexTowers.h:52
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
LVL1::jTowerMakerFromJfexTowers::m_DataTowerKey
SG::ReadHandleKey< xAOD::jFexTowerContainer > m_DataTowerKey
Definition: jTowerMakerFromJfexTowers.h:36
jTowerBuilder.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
LVL1::jFEXCompression::Expand
static int Expand(unsigned int code)
Uncompress data.
Definition: jFEXCompression.cxx:58
WriteHandle.h
Handle class for recording to StoreGate.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LVL1::jTower::setiPhi
void setiPhi(int iphi)
Definition: jTower.cxx:312
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
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
LVL1::jTowerMakerFromJfexTowers::initialize
virtual StatusCode initialize() override
Definition: jTowerMakerFromJfexTowers.cxx:41
LVL1::jTowerMakerFromJfexTowers::m_jTowerBuilderTool
ToolHandle< IjTowerBuilder > m_jTowerBuilderTool
Definition: jTowerMakerFromJfexTowers.h:51
LVL1::jTower::setCentrePhi
void setCentrePhi(float iphi)
Definition: jTower.cxx:306
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigConf::name
Definition: HLTChainList.h:35
LVL1::jTower::setOnlineID
void setOnlineID(int tower_id_online)
Definition: jTower.cxx:316
jTowerContainer.h
LVL1::jTowerMakerFromJfexTowers::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: jTowerMakerFromJfexTowers.cxx:56
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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
LVL1::jTower::setHADSat
void setHADSat()
Definition: jTower.h:62
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::jTower::setEMSat
void setEMSat()
set and get saturation
Definition: jTower.h:59
jFEXCompression.h
LVL1::jTower
The jTower class is an interface object for jFEX trigger algorithms The purposes are twofold:
Definition: jTower.h:40
LVL1::jTower::set_Et
void set_Et(int layer, int et)
Set ET value in MeV.
Definition: jTower.cxx:103
ReadHandle.h
Handle class for reading from StoreGate.
LVL1::jTowerMakerFromJfexTowers::m_jTowerContainerSGKey
SG::WriteHandleKey< LVL1::jTowerContainer > m_jTowerContainerSGKey
Definition: jTowerMakerFromJfexTowers.h:49
xAOD::jFexTower_v1
Class describing input data of a LVL1 jFEX.
Definition: jFexTower_v1.h:22
jTower.h
LVL1::jTowerMakerFromJfexTowers::jTowerMakerFromJfexTowers
jTowerMakerFromJfexTowers(const std::string &name, ISvcLocator *pSvcLocator)
Definition: jTowerMakerFromJfexTowers.cxx:36
LVL1::jTowerMakerFromJfexTowers::m_EmulTowerKey
SG::ReadHandleKey< xAOD::jFexTowerContainer > m_EmulTowerKey
Definition: jTowerMakerFromJfexTowers.h:41
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
LVL1::jTowerMakerFromJfexTowers::m_UseEmulated
Gaudi::Property< bool > m_UseEmulated
Definition: jTowerMakerFromJfexTowers.h:44
LVL1::jTowerMakerFromJfexTowers::m_isMC
Gaudi::Property< bool > m_isMC
Definition: jTowerMakerFromJfexTowers.h:45