ATLAS Offline Software
JRoIsUnpackingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "JRoIsUnpackingTool.h"
9 
10 
12  const std::string& name,
13  const IInterface* parent)
15 
16 
20 
21  return StatusCode::SUCCESS;
22 }
23 
24 
26  ATH_CHECK(decodeMapping([](const std::string& name){
27  return name.find('J') == 0 or name.find("JF") == 0 or name.find("JB") == 0;
28  }));
29  return StatusCode::SUCCESS;
30 }
31 
32 
33 StatusCode JRoIsUnpackingTool::unpack(const EventContext& ctx,
34  const ROIB::RoIBResult& roib,
35  const HLT::IDSet& activeChains) const {
36  using namespace TrigCompositeUtils;
37  // create and record the collections needed
41 
42  // Retrieve the L1 menu configuration
44  ATH_CHECK(l1Menu.isValid());
45  std::optional<ThrVecRef> jetThresholds;
46  ATH_CHECK(getL1Thresholds(*l1Menu, "JET", jetThresholds));
47 
48  // Flag if there was an overflow in the TOB transmission to CMX (there were more TOBs than can be transferred)
49  bool overflow{false};
50  constexpr static unsigned int s_maxJetTOBs{4}; // Hardcoded in L1Calo firmware, see ATR-23697 and ATR-12285
51  std::unordered_map<unsigned int, std::unordered_map<unsigned int, unsigned int>> tobCounts; // {crate, {module, count}}
52 
53  // RoIBResult contains vector of jet fragments
54  for ( const auto & jetFragment : roib.jetEnergyResult() ) {
55  for ( const auto & roi : jetFragment.roIVec() ) {
56  uint32_t roIWord = roi.roIWord();
57  if ( not ( LVL1::TrigT1CaloDefs::JetRoIWordType == roi.roIType() ) ) {
58  ATH_MSG_DEBUG( "Skipping RoI as it is not JET threshold " << roIWord <<" Type "<< roi.roIType() );
59  continue;
60  }
61 
62  if (!overflow) {
63  unsigned int crate = m_jepDecoder.crate(roIWord);
64  unsigned int module = m_jepDecoder.module(roIWord);
65  overflow = (++tobCounts[crate][module] > s_maxJetTOBs);
66  }
67 
68  recRoIs->push_back( std::make_unique<LVL1::RecJetRoI>(roIWord, l1Menu.cptr()) );
69  const LVL1::RecJetRoI* recRoI = recRoIs->back();
70 
71  trigRoIs->push_back( std::make_unique<TrigRoiDescriptor>(
72  roIWord, 0u ,0u,
73  recRoI->eta(), recRoI->eta()-m_roIWidth, recRoI->eta()+m_roIWidth,
74  recRoI->phi(), recRoI->phi()-m_roIWidth, recRoI->phi()+m_roIWidth) );
75 
76  ATH_MSG_DEBUG( "RoI word: 0x" << MSG::hex << std::setw( 8 ) << roIWord << MSG::dec );
77 
78  // The hltSeedingNodeName denotes an initial node with no parents
79  Decision* decision = TrigCompositeUtils::newDecisionIn( decisionOutput.ptr(), hltSeedingNodeName() );
80 
81  std::vector<unsigned> passedThresholdIDs;
82 
83  for (const auto& th : jetThresholds.value().get()) {
84  ATH_MSG_VERBOSE( "Checking if the threshold " << th->name() << " passed" );
85  if ( recRoI->passedThreshold(th->mapping()) ) {
86  passedThresholdIDs.push_back( HLT::Identifier( th->name() ) );
87  ATH_MSG_DEBUG( "Passed Threshold name " << th->name() );
88  addChainsToDecision( HLT::Identifier( th->name() ), decision, activeChains );
89  ATH_MSG_DEBUG( "Labeled object with chains: " << [&](){
92  return std::vector<TrigCompositeUtils::DecisionID>( ids.begin(), ids.end() ); }() );
93  }
94  }
95 
96  decision->setDetail( "thresholds", passedThresholdIDs );
97  decision->setObjectLink( initialRoIString(),
100  ElementLink<DataVector<LVL1::RecJetRoI>>(m_recRoIsKey.key(), recRoIs->size()-1) );
101  }
102  }
103 
104  // Decorate the decisions with overflow information
105  if (overflow) {
106  ATH_MSG_WARNING("L1Calo overflow for JET TOBs to CMX detected");
107  }
108  for (Decision* decision : *decisionOutput) {
109  decision->setDetail("overflow", static_cast<char>(overflow));
110  }
111 
112  if ( msgLvl(MSG::DEBUG) ) {
113  for ( auto roi: *trigRoIs ) {
114  ATH_MSG_DEBUG( "RoI Eta: " << roi->eta() << " Phi: " << roi->phi() << " RoIWord: " << roi->roiWord() );
115  }
116  }
117 
118  // monitoring
119  {
120  auto RoIsCount = Monitored::Scalar( "count", trigRoIs->size() );
121  auto RoIsPhi = Monitored::Collection( "phi", *trigRoIs, &TrigRoiDescriptor::phi );
122  auto RoIsEta = Monitored::Collection( "eta", *trigRoIs, &TrigRoiDescriptor::eta );
123  Monitored::Group( m_monTool, RoIsCount, RoIsEta, RoIsPhi );
124  }
125 
126  ATH_MSG_DEBUG( "Unpacked " << trigRoIs->size() << " RoIs" );
127 
128  return StatusCode::SUCCESS;
129 }
xAOD::TrigComposite_v1::setDetail
bool setDetail(const std::string &name, const TYPE &value)
Set an TYPE detail on the object.
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
RoIsUnpackingToolBase
Base class for RoI unpackers.
Definition: RoIsUnpackingToolBase.h:32
LVL1::RecJetRoI
This class defines the reconstructed em/tau hadron ROI.
Definition: RecJetRoI.h:39
LVL1::JEPRoIDecoder::crate
unsigned int crate(const unsigned int word) const
Return hardware coordinates.
Definition: JEPRoIDecoder.cxx:79
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
JRoIsUnpackingTool::start
virtual StatusCode start() override
Definition: JRoIsUnpackingTool.cxx:25
ROIB::RoIBResult
Class holding the LVL1 RoIB result build by the RoIBuilder.
Definition: RoIBResult.h:47
TrigCompositeUtils::hltSeedingNodeName
const std::string & hltSeedingNodeName()
Definition: TrigCompositeUtilsRoot.cxx:892
JRoIsUnpackingTool::unpack
StatusCode unpack(const EventContext &ctx, const ROIB::RoIBResult &roib, const HLT::IDSet &activeChains) const override
Definition: JRoIsUnpackingTool.cxx:33
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
RoIBResult.h
ROIB::RoIBResult::jetEnergyResult
const std::vector< JetEnergyResult > & jetEnergyResult() const
Gets the jet/energy part of the L1 RDO.
Definition: RoIBResult.cxx:64
TrigCompositeUtils::newDecisionIn
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name)
Helper method to create a Decision object, place it in the container and return a pointer to it.
Definition: TrigCompositeUtilsRoot.cxx:46
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
RoIsUnpackingToolBase::addChainsToDecision
void addChainsToDecision(HLT::Identifier thresholdId, TrigCompositeUtils::Decision *d, const HLT::IDSet &activeChains) const
Definition: RoIsUnpackingToolBase.cxx:88
TrigCompositeUtils::createAndStore
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
Definition: TrigCompositeUtilsRoot.cxx:30
TrigCompositeUtils::initialRecRoIString
const std::string & initialRecRoIString()
Definition: TrigCompositeUtilsRoot.cxx:872
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
JRoIsUnpackingTool.h
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
python.PyAthena.module
module
Definition: PyAthena.py:131
JRoIsUnpackingTool::JRoIsUnpackingTool
JRoIsUnpackingTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: JRoIsUnpackingTool.cxx:11
python.TriggerHandler.th
th
Definition: TriggerHandler.py:296
RoIsUnpackingToolBase::decodeMapping
StatusCode decodeMapping(std::function< bool(const std::string &)> &&filter)
Fills mapping from L1 threshold -> to HLT chain.
Definition: RoIsUnpackingToolBase.cxx:52
xAOD::TrigComposite_v1::setObjectLink
bool setObjectLink(const std::string &name, const ElementLink< CONTAINER > &link)
Set the link to an object.
TrigCompositeUtils::initialRoIString
const std::string & initialRoIString()
Definition: TrigCompositeUtilsRoot.cxx:868
RoIsUnpackingToolBase::getL1Thresholds
StatusCode getL1Thresholds(const TrigConf::L1Menu &l1Menu, const std::string &thrType, std::optional< ThrVecRef > &thrVec) const
Retrieve a vector of thresholds with type thrType from L1Menu.
Definition: RoIsUnpackingToolBase.cxx:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
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
TrigCompositeUtils::createAndStoreNoAux
SG::WriteHandle< CONT > createAndStoreNoAux(const SG::WriteHandleKey< CONT > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Creates and right away records the Container CONT with the key.
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
RoIsUnpackingToolBase::m_decisionsKey
SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > m_decisionsKey
Definition: RoIsUnpackingToolBase.h:51
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
HLT::Identifier
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:20
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
JRoIsUnpackingTool::m_jepDecoder
LVL1::JEPRoIDecoder m_jepDecoder
Definition: JRoIsUnpackingTool.h:38
LVL1::RecJetRoI::passedThreshold
bool passedThreshold(unsigned int thresholdNumber) const
returns TRUE if threshold number threshold_number has been passed by this ROI.
Definition: RecJetRoI.cxx:320
RoIsUnpackingToolBase::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: RoIsUnpackingToolBase.h:67
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
LVL1::JEPRoIDecoder::module
unsigned int module(const unsigned int word) const
Extract module number from Jet RoI word.
Definition: JEPRoIDecoder.cxx:84
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
TrigT1CaloDefs.h
RoIsUnpackingToolBase::m_trigRoIsKey
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_trigRoIsKey
Definition: RoIsUnpackingToolBase.h:57
RoIsUnpackingToolBase::m_l1MenuKey
SG::ReadHandleKey< TrigConf::L1Menu > m_l1MenuKey
Definition: RoIsUnpackingToolBase.h:60
JRoIsUnpackingTool::m_roIWidth
Gaudi::Property< float > m_roIWidth
Definition: JRoIsUnpackingTool.h:32
SG::WriteHandle< TrigRoiDescriptorCollection >
LVL1::TrigT1CaloDefs::JetRoIWordType
@ JetRoIWordType
Definition: TrigT1CaloDefs.h:168
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
RoiDescriptor::phi
virtual double phi() const override final
Methods to retrieve data members.
Definition: RoiDescriptor.h:100
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
JRoIsUnpackingTool::initialize
virtual StatusCode initialize() override
Definition: JRoIsUnpackingTool.cxx:17
HLT::IDSet
std::set< HLT::Identifier > IDSet
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:63
RoIsUnpackingToolBase::initialize
virtual StatusCode initialize() override
Definition: RoIsUnpackingToolBase.cxx:16
RoiDescriptor::eta
virtual double eta() const override final
Definition: RoiDescriptor.h:101
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
LVL1::RecJetRoI::eta
virtual double eta() const
returns eta coord of ROI
Definition: RecJetRoI.cxx:253
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
JRoIsUnpackingTool::m_recRoIsKey
SG::WriteHandleKey< DataVector< LVL1::RecJetRoI > > m_recRoIsKey
Definition: JRoIsUnpackingTool.h:29
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
LVL1::RecJetRoI::phi
virtual double phi() const
returns phi coord of ROI
Definition: RecJetRoI.cxx:243