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