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  : 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  }
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 
66  StatusCode TrigT1ZDC::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 
85  static const SG::ConstAccessor<uint16_t> LucrodTriggerAmpAcc("LucrodTriggerAmp");
86  // Side A
87  if (zdcModule->zdcSide() > 0)
88  {
89  moduleEnergy.at(zdcModule->zdcModule()) = (!m_energyToADCScaleFactor && LucrodTriggerAmpAcc.isAvailable(*zdcModule)) ? static_cast<float>(LucrodTriggerAmpAcc(*zdcModule)) : zdcModuleCalibEnergyHandle(*zdcModule);
90  }
91 
92  // Side C
93  if (zdcModule->zdcSide() < 0)
94  {
95  moduleEnergy.at(zdcModule->zdcModule() + 4) = (!m_energyToADCScaleFactor && LucrodTriggerAmpAcc.isAvailable(*zdcModule)) ? static_cast<float>(LucrodTriggerAmpAcc(*zdcModule)) : zdcModuleCalibEnergyHandle(*zdcModule);
96  }
97  }
98  }
99  }
100 
101  // Get Output as an integer (0-7)
102  m_modInputs_p->setData(moduleEnergy);
103 
104  // call ZDCTriggerSim to actually get ZDC Bits
105  unsigned int wordOut = m_simTrig->simLevel1Trig(ZDCTriggerSim::SimDataCPtr(m_modInputs_p));
106 
107  // convert int to bitset
108  std::bitset<3> bin(wordOut);
109 
110  // ZDC L1 items are located on CTPIN SLOT 9
111  // Each slot holds 4 connectors that each carry a 32 bit trigger word
112  // ZDC HG items are located on Connector 1 (CTPCAL)
113  // at bits 25, 26, 27
114  // for more info see
115  // twiki.cern.ch/twiki/bin/view/Atlas/LevelOneCentralTriggerSetup#CTPIN_Slot_9
116 
117  // load output into trigger word on correct bits
118  unsigned int word0 = 0;
119  word0 += (bin[0] << 25);
120  word0 += (bin[1] << 26);
121  word0 += (bin[2] << 27);
122 
123  // form CTP obejct
125 
126  //record CTP object
127  ATH_CHECK(zdcCTP.record(std::make_unique<ZdcCTP>(word0)));
128  ATH_MSG_DEBUG("Stored ZDC CTP object with words " << std::hex << (zdcCTP->cableWord0()) << " from LUTOutput " << std::dec << wordOut);
129  return StatusCode::SUCCESS;
130  }
131  }
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:56
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:68
LVL1::TrigT1ZDC::m_lutFile
Gaudi::Property< std::string > m_lutFile
Definition: TrigT1ZDC.h:64
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
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
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
LVL1::TrigT1ZDC::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrigT1ZDC.cxx:66
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
LVL1::TrigT1ZDC::m_energyToADCScaleFactor
Gaudi::Property< float > m_energyToADCScaleFactor
Definition: TrigT1ZDC.h:65
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:59
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:51
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:71