ATLAS Offline Software
Loading...
Searching...
No Matches
TrigT1Run2ZDC.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#include <fstream>
5#include <stdexcept>
6#include <bitset>
7#include "TrigT1Run2ZDC.h"
9
10using json = nlohmann::json;
11
12namespace LVL1 {
13
14 //--------------------------------
15 // Constructors and destructors
16 //--------------------------------
17
18 TrigT1Run2ZDC::TrigT1Run2ZDC (const std::string& name, ISvcLocator* pSvcLocator)
19 : AthReentrantAlgorithm( 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 }
38 json data = json::parse(fin);
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("TrigT1Run2ZDC initilized");
59 return StatusCode::SUCCESS;
60 }
61
62 //----------------------------------------------
63 // execute() method called once per event
64 //----------------------------------------------
65
66 StatusCode TrigT1Run2ZDC::execute(const EventContext &ctx) const
67 {
68 // access ZDC modules
70 // access ZDC aux data
72 // create vector to store module CalibEnergy
73 std::vector<float> moduleEnergy = {0., 0., 0., 0., 0., 0., 0., 0.};
74
75 // Read Single Modules
76 if (zdcModules.isValid())
77 {
78 for (const auto zdcModule : *zdcModules)
79 {
80 if (zdcModule->zdcType() == 0)
81 { // type = 0 are big modules, type = 1 the pixels
82
83 ATH_MSG_DEBUG("ZDC Side " << zdcModule->zdcSide() << ", Module: " << zdcModule->zdcModule() << " and Energy: " << zdcModuleCalibEnergyHandle(*zdcModule));
84 // Side A
85 static const SG::ConstAccessor<uint16_t> lucrodTriggerAmpAcc("LucrodTriggerAmp");
86 if (zdcModule->zdcSide() > 0)
87 {
88 moduleEnergy.at(zdcModule->zdcModule()) = (!m_energyToADCScaleFactor && lucrodTriggerAmpAcc.isAvailable(*zdcModule)) ? static_cast<float>(lucrodTriggerAmpAcc(*zdcModule)) : zdcModuleCalibEnergyHandle(*zdcModule);
89 }
90
91 // Side C
92 if (zdcModule->zdcSide() < 0)
93 {
94 moduleEnergy.at(zdcModule->zdcModule() + 4) = (!m_energyToADCScaleFactor && lucrodTriggerAmpAcc.isAvailable(*zdcModule)) ? static_cast<float>(lucrodTriggerAmpAcc(*zdcModule)) : zdcModuleCalibEnergyHandle(*zdcModule);
95 }
96 }
97 }
98 }
99
100 // Get Output as an integer (0-7)
101 m_modInputs_p->setData(moduleEnergy);
102
103 // call ZDCTriggerSim to actually get ZDC Bits
104 unsigned int wordOut = m_simTrig->simLevel1Trig(ZDCTriggerSim::SimDataCPtr(m_modInputs_p));
105
106 // convert int to bitset
107 std::bitset<3> bin(wordOut);
108
109 // load output into trigger word on correct bits
110 unsigned int word0 = 0;
111 word0 += (bin[0] << 25);
112 word0 += (bin[1] << 26);
113 word0 += (bin[2] << 27);
114
115 // form CTP obejct
117
118 //record CTP object
119 ATH_CHECK(zdcCTP.record(std::make_unique<ZdcCTP>(word0)));
120 ATH_MSG_DEBUG("Stored ZDC CTP object with words " << std::hex << (zdcCTP->cableWord0()) << " from LUTOutput " << std::dec << wordOut);
121 return StatusCode::SUCCESS;
122 }
123 }
#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