ATLAS Offline Software
TrigT1ZDC.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #include <fstream>
5 #include <stdexcept>
6 #include <bitset>
7 #include "TrigT1ZDC.h"
8 
9 
11 
12 namespace LVL1 {
13 
14  //--------------------------------
15  // Constructors and destructors
16  //--------------------------------
17 
18  TrigT1ZDC::TrigT1ZDC (const std::string& name, ISvcLocator* pSvcLocator)
19  : AthAlgorithm( name, pSvcLocator ) {}
20 
21  //---------------------------------
22  // initialise()
23  //---------------------------------
24 
26  {
27  ATH_CHECK(m_zdcCTPLocation.initialize());
28  ATH_CHECK(m_zdcModuleKey.initialize());
30  // Find the full path to filename:
32  ATH_MSG_INFO("Reading file " << file);
33  std::ifstream fin(file.c_str());
34  if(!fin){
35  ATH_MSG_ERROR("Can not read file: " << file);
36  return StatusCode::FAILURE;
37  }
39 
40  // Conversion factor from Run2 Energies (GeV) to dynamic range of LUT (4096 entries)
41  std::vector<float> convfact;
42  // if EnergyToADCScaleFactor is 0, using Run3 Data
43  // this means we make trigger decisions based on real trigger amplitudes
44  convfact.push_back((m_energyToADCScaleFactor) ? static_cast<float>(m_energyToADCScaleFactor) : static_cast<float>(1.0));
45 
46  // Will eventually obtain LUTs from COOL, for now obtain them from calibration area
47  // A data member to hold the side A LUT values
48  std::array<unsigned int, 4096> sideALUT = data["LucrodHighGain"]["LUTs"]["sideA"];
49  // A data member to hold the side C LUT values
50  std::array<unsigned int, 4096> sideCLUT = data["LucrodHighGain"]["LUTs"]["sideC"];
51  // A data member to hold the Combined LUT values
52  std::array<unsigned int, 256> combLUT = data["LucrodHighGain"]["LUTs"]["comb"];
53 
54  // Construct Simulation Objects
55  m_modInputs_p = std::make_shared<ZDCTriggerSim::ModuleAmplInputsFloat>(ZDCTriggerSim::ModuleAmplInputsFloat(convfact));
56  m_simTrig = std::make_shared<ZDCTriggerSimModuleAmpls>(ZDCTriggerSimModuleAmpls(sideALUT, sideCLUT, combLUT));
57 
58  ATH_MSG_DEBUG("TrigT1ZDC initilized");
59  return StatusCode::SUCCESS;
60  }
61 
62  //----------------------------------------------
63  // execute() method called once per event
64  //----------------------------------------------
65 
67  {
68 
69  const EventContext &ctx = Gaudi::Hive::currentContext();
70  // access ZDC modules
72  // access ZDC aux data
74  // create vector to store module CalibEnergy
75  std::vector<float> moduleEnergy = {0., 0., 0., 0., 0., 0., 0., 0.};
76 
77  // Read Single Modules
78  if (zdcModules.isValid())
79  {
80  for (const auto zdcModule : *zdcModules)
81  {
82  if (zdcModule->zdcType() == 0)
83  { // type = 0 are big modules, type = 1 the pixels
84 
85  ATH_MSG_DEBUG("ZDC Side " << zdcModule->zdcSide() << ", Module: " << zdcModule->zdcModule() << " and Energy: " << zdcModuleCalibEnergyHandle(*zdcModule));
86 
87  static const SG::ConstAccessor<uint16_t> LucrodTriggerAmpAcc("LucrodTriggerAmp");
88  // Side A
89  if (zdcModule->zdcSide() > 0)
90  {
91  moduleEnergy.at(zdcModule->zdcModule()) = (!m_energyToADCScaleFactor && LucrodTriggerAmpAcc.isAvailable(*zdcModule)) ? static_cast<float>(LucrodTriggerAmpAcc(*zdcModule)) : zdcModuleCalibEnergyHandle(*zdcModule);
92  }
93 
94  // Side C
95  if (zdcModule->zdcSide() < 0)
96  {
97  moduleEnergy.at(zdcModule->zdcModule() + 4) = (!m_energyToADCScaleFactor && LucrodTriggerAmpAcc.isAvailable(*zdcModule)) ? static_cast<float>(LucrodTriggerAmpAcc(*zdcModule)) : zdcModuleCalibEnergyHandle(*zdcModule);
98  }
99  }
100  }
101  }
102 
103  // Get Output as an integer (0-7)
104  m_modInputs_p->setData(moduleEnergy);
105 
106  // call ZDCTriggerSim to actually get ZDC Bits
107  unsigned int wordOut = m_simTrig->simLevel1Trig(ZDCTriggerSim::SimDataCPtr(m_modInputs_p));
108 
109  // convert int to bitset
110  std::bitset<3> bin(wordOut);
111 
112  // ZDC L1 items are located on CTPIN SLOT 9
113  // Each slot holds 4 connectors that each carry a 32 bit trigger word
114  // ZDC HG items are located on Connector 1 (CTPCAL)
115  // at bits 25, 26, 27
116  // for more info see
117  // twiki.cern.ch/twiki/bin/view/Atlas/LevelOneCentralTriggerSetup#CTPIN_Slot_9
118 
119  // load output into trigger word on correct bits
120  unsigned int word0 = 0;
121  word0 += (bin[0] << 25);
122  word0 += (bin[1] << 26);
123  word0 += (bin[2] << 27);
124 
125  // form CTP obejct
127 
128  //record CTP object
129  ATH_CHECK(zdcCTP.record(std::make_unique<ZdcCTP>(word0)));
130  ATH_MSG_DEBUG("Stored ZDC CTP object with words " << std::hex << (zdcCTP->cableWord0()) << " from LUTOutput " << std::dec << wordOut);
131  return StatusCode::SUCCESS;
132  }
133  }
LVL1::TrigT1ZDC::TrigT1ZDC
TrigT1ZDC(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigT1ZDC.cxx:18
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
ZDCTriggerSim::SimDataCPtr
std::shared_ptr< const ZDCTriggerSimDataBase > SimDataCPtr
Definition: ZDCTriggerSim.h:170
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
json
nlohmann::json json
Definition: HistogramDef.cxx:9
LVL1::TrigT1ZDC::m_zdcModuleCalibEnergyKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleCalibEnergyKey
Definition: TrigT1ZDC.h:57
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
bin
Definition: BinsDiffFromStripMedian.h:43
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
ZDCTriggerSimModuleAmpls
Definition: ZDCTriggerSim.h:279
LVL1::TrigT1ZDC::initialize
virtual StatusCode initialize() override
Definition: TrigT1ZDC.cxx:25
LVL1::TrigT1ZDC::m_modInputs_p
std::shared_ptr< ZDCTriggerSim::ModuleAmplInputsFloat > m_modInputs_p
A data member to hold the ZDCTrigger Object that stores input floats: shared ptr to ensure cleanup.
Definition: TrigT1ZDC.h:69
LVL1::TrigT1ZDC::m_lutFile
Gaudi::Property< std::string > m_lutFile
Definition: TrigT1ZDC.h:65
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigT1ZDC.h
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
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
json
nlohmann::json json
Definition: TrigT1ZDC.cxx:10
file
TFile * file
Definition: tile_monitor.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigConf::name
Definition: HLTChainList.h:35
ZDCTriggerSimData
Definition: ZDCTriggerSim.h:58
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
LVL1::TrigT1ZDC::m_energyToADCScaleFactor
Gaudi::Property< float > m_energyToADCScaleFactor
Definition: TrigT1ZDC.h:66
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
LVL1::TrigT1ZDC::m_zdcCTPLocation
SG::WriteHandleKey< ZdcCTP > m_zdcCTPLocation
Definition: TrigT1ZDC.h:60
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
compute_lumi.fin
fin
Definition: compute_lumi.py:19
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
LVL1::TrigT1ZDC::m_zdcModuleKey
SG::ReadHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleKey
Definition: TrigT1ZDC.h:52
LVL1::TrigT1ZDC::m_simTrig
std::shared_ptr< ZDCTriggerSimModuleAmpls > m_simTrig
A data member to hold the ZDCTrigger Object that computes the LUT logic: shared ptr to ensure cleanup...
Definition: TrigT1ZDC.h:72
LVL1::TrigT1ZDC::execute
virtual StatusCode execute() override
Definition: TrigT1ZDC.cxx:66