ATLAS Offline Software
Loading...
Searching...
No Matches
Lvl1ResultAccessTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8#include "CTPfragment/CTPdataformatVersion.h"
9
10#include "TrigConfData/L1Menu.h"
13
14
15HLT::Lvl1ResultAccessTool::Lvl1ResultAccessTool(const std::string& name, const std::string& type,
16 const IInterface* parent) :
17 base_class(name, type, parent)
18{
19}
20
21StatusCode
23
24 ATH_CHECK( m_l1PrescaleSetInputKey.initialize( ) );
25 ATH_CHECK( m_l1ResultKey.initialize( ) );
26
27 return StatusCode::SUCCESS;
28}
29
30// =============================================================
31// Prepare LVL1 items, i.e. name -> hashID, put everything into
32// a vector where the position corresponds to the LVL1 item
33// position in the CTP result!
34// =============================================================
35std::vector< std::unique_ptr<LVL1CTP::Lvl1Item> >
36HLT::Lvl1ResultAccessTool::makeLvl1ItemConfig(const EventContext& context) const
37{
38 // vector holding all configured LVL1 items, default initializes to empty unique_ptr
39 constexpr size_t numberOfCTPItems = 512; // this is fixed
40 std::vector<std::unique_ptr<LVL1CTP::Lvl1Item>> lvl1ItemConfig(numberOfCTPItems);
41
42 const TrigConf::L1Menu *l1menu = nullptr;
43 if( detStore()->retrieve(l1menu).isFailure() ) {
44 ATH_MSG_ERROR("No L1Menu found");
45 } else {
47 if( !l1psRH.isValid() ) {
48 ATH_MSG_ERROR("No valid L1PrescalesSet handle");
49 } else {
50 const TrigConf::L1PrescalesSet* l1PrescaleSet{*l1psRH};
51 if(l1PrescaleSet == nullptr) {
52 ATH_MSG_ERROR( "No L1PrescalesSet available");
53 } else {
54 for(auto & item : *l1menu) {
55 double prescale = l1PrescaleSet->getPrescaleFromCut(l1PrescaleSet->prescale(item.name()).cut);
56 lvl1ItemConfig[item.ctpId()] = std::make_unique<LVL1CTP::Lvl1Item>( item.name(),
58 0, 0, 0, prescale);
59 }
60 }
61 }
62 }
63 return lvl1ItemConfig;
64}
65
66
67// check for calo calibration bits
68// get the calibration triggers, 253, 254 and 255 ie, bits
69// 29, 30 and 31 from word 7
70bool
72
74 int ctpVersion = result.cTPResult().header().formatVersion() & 0xf ;
75 CTPdataformatVersion v(ctpVersion);
76 std::vector<ROIB::CTPRoI> ctpRoIVec(result.cTPResult().TAV());
77 // if ( ctpRoIVec.size() >= 8 && (ctpRoIVec[7].roIWord() & 0xE0000000) )
78 if ( ctpRoIVec.size()==v.getTAVwords() && ( ctpRoIVec[ctpRoIVec.size()-1].roIWord() & 0xE0000000 ) )
79 return true;
80 else
81 return false;
82}
83
84namespace {
85 bool getBit(const std::vector<ROIB::CTPRoI>& words, unsigned position) {
86 unsigned w = position/32;
87 unsigned b = position%32;
88 if ( words.size() > w) {
89 uint32_t roIWord = words[w].roIWord();
90 return (roIWord >> b) & 0x1;
91 }
92 return false;
93 }
94}
95
96// ==============================
97// create LVL1 items
98// ==============================
99std::vector< const LVL1CTP::Lvl1Item* >
100HLT::Lvl1ResultAccessTool::createL1Items( const std::vector< std::unique_ptr<LVL1CTP::Lvl1Item> >& lvl1ItemConfig,
102 LVL1CTP::Lvl1Result const** lvl1ResultOut /*= nullptr*/) const
103{
104 std::vector< const LVL1CTP::Lvl1Item* > items;
105 std::vector<ROIB::CTPRoI> bitsBP = result.cTPResult().TBP();
106 std::vector<ROIB::CTPRoI> bitsAP = result.cTPResult().TAP();
107 std::vector<ROIB::CTPRoI> bitsAV = result.cTPResult().TAV();
108
109 bool calib_flag = isCalibrationEvent(result);
110 ATH_MSG_DEBUG("Calibration event? " << calib_flag);
111
112 // loop over all configured items if no calibration, else only 3 last // Needs fixing
113 int ctpVersion = result.cTPResult().header().formatVersion() & 0xf ;
114 CTPdataformatVersion v(ctpVersion);
115
116 unsigned first_item = calib_flag ? v.getMaxTrigItems()-3 : 0; // last three items are calib items, only those should be activated
117
118 for ( unsigned i = first_item; i < lvl1ItemConfig.size(); i++ ) {
119 if ( !lvl1ItemConfig[ i ] ) continue; // empty slot
120
121 LVL1CTP::Lvl1Item* item = lvl1ItemConfig[ i ].get();
122 *item = LVL1CTP::Lvl1Item( item->name(), item->hashId(),
123 getBit(bitsBP, i),
124 getBit(bitsAP, i),
125 getBit(bitsAV, i),
126 item->prescaleFactor() );
127 items.push_back(item);
128 ATH_MSG_DEBUG("Set bits on "<< item->name() <<" PS="<< item->prescaleFactor() <<" BP=" <<getBit(bitsBP, i)<<" AP="<<getBit(bitsAP, i)<<" AV="<<getBit(bitsAV, i));
129 }
130
131 // Fill TBP, TAP in case we're creating the Lvl1Result
132 if (lvl1ResultOut) {
133 auto lvl1Result = std::make_unique<LVL1CTP::Lvl1Result>(true);
134
135 // 1.) TAV
136 const std::vector<ROIB::CTPRoI> ctpRoIVecAV = result.cTPResult().TAV();
137 for (unsigned int iWord = 0; iWord < ctpRoIVecAV.size(); ++iWord) {
138 uint32_t roIWord = ctpRoIVecAV[iWord].roIWord();
139 lvl1Result->itemsAfterVeto().push_back(roIWord);
140 ATH_MSG_DEBUG("TAV word #" << iWord << " is 0x" << std::hex << std::setw( 8 ) << std::setfill( '0' ) << roIWord << std::dec);
141 }
142
143 // 1.) TBP
144 const std::vector<ROIB::CTPRoI> ctpRoIVecBP = result.cTPResult().TBP();
145 for (unsigned int iWord=0; iWord < ctpRoIVecBP.size(); ++iWord) {
146 uint32_t roIWord = ctpRoIVecBP[iWord].roIWord();
147 lvl1Result->itemsBeforePrescale().push_back(roIWord);
148 ATH_MSG_DEBUG( "TBP word #" << iWord << " is 0x" << std::hex
149 << std::setw( 8 ) << std::setfill( '0' ) << roIWord << std::dec);
150 }
151
152 // 2.) TAP
153 const std::vector<ROIB::CTPRoI> ctpRoIVecAP = result.cTPResult().TAP();
154 for (unsigned int iWord=0; iWord < ctpRoIVecAP.size(); ++iWord) {
155 uint32_t roIWord = ctpRoIVecAP[iWord].roIWord();
156 lvl1Result->itemsAfterPrescale().push_back(roIWord);
157
158 ATH_MSG_DEBUG("TAP word #" << iWord << " is 0x" << std::hex << std::setw( 8 ) << std::setfill( '0' ) << roIWord << std::dec);
159
160 }
161 // make sure TBP, TAP, TAV all have 8 entries !
162 if (lvl1Result->itemsBeforePrescale().size() < 8) lvl1Result->itemsBeforePrescale().resize(8, 0);
163 if (lvl1Result->itemsAfterPrescale().size() < 8) lvl1Result->itemsAfterPrescale().resize(8, 0);
164 if (lvl1Result->itemsAfterVeto().size() < 8) lvl1Result->itemsAfterVeto().resize(8, 0);
165 *lvl1ResultOut = lvl1Result.get();
166 ATH_CHECK(SG::makeHandle(m_l1ResultKey).record( std::move(lvl1Result)), {});
167 } // if (lvl1ResultOut)
168
169 return items;
170}
171
172std::bitset<3>
174{
175 const int MAXEM = 5; // see ATR-12285
176 const int MAXTAU = 5;
177 const int MAXJET = 4;
178
179 std::map<std::pair<int,int>, int> em, tau, jet; // (crate,module) : count
180
181 // Count number of RoIs per crate/module
182 for (const ROIB::EMTauResult& res : result.eMTauResult()) {
183 for (const ROIB::EMTauRoI& roi : res.roIVec()) {
184 int c = m_cpDecoder.crate(roi.roIWord());
185 int m = m_cpDecoder.module(roi.roIWord());
186 int t = m_cpDecoder.roiType(roi.roIWord());
187
188 if (t==LVL1::TrigT1CaloDefs::EMRoIWordType) ++em[{c,m}];
189 else if (t==LVL1::TrigT1CaloDefs::TauRoIWordType) ++tau[{c,m}];
190 }
191 }
192
193 for (const ROIB::JetEnergyResult& res : result.jetEnergyResult()) {
194 for (const ROIB::JetEnergyRoI& roi : res.roIVec()) {
195 int c = m_jepDecoder.crate(roi.roIWord());
196 int m = m_jepDecoder.module(roi.roIWord());
197 int t = m_jepDecoder.roiType(roi.roIWord());
198
200 }
201 }
202
203 // Check if there was an overflow
204 std::bitset<3> overflow;
205 overflow[0] = std::count_if(em.begin(), em.end(), [](const decltype(em)::value_type& i){return i.second>MAXEM;});
206 overflow[1] = std::count_if(tau.begin(), tau.end(), [](const decltype(tau)::value_type& i){return i.second>MAXTAU;});
207 overflow[2] = std::count_if(jet.begin(), jet.end(), [](const decltype(jet)::value_type& i){return i.second>MAXJET;});
208
209 if (msgLvl(MSG::DEBUG)) {
210 msg() << "EM RoI multiplicities by crate,module: ";
211 for (const auto& i : em) msg() << "(" << i.first.first << "," << i.first.second << "):" << i.second << " ";
212
213 msg() << endmsg << "Tau RoI multiplicities by crate,module: ";
214 for (const auto& i : tau) msg() << "(" << i.first.first << "," << i.first.second << "):" << i.second << " ";
215
216 msg() << endmsg << "Jet RoI multiplicities by crate,module: ";
217 for (const auto& i : jet) msg() << "(" << i.first.first << "," << i.first.second << "):" << i.second << " ";
218 msg() << endmsg;
219 }
220
221 return overflow;
222}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
std::pair< std::vector< unsigned int >, bool > res
static bool getBit(unsigned char field, unsigned num)
virtual bool isCalibrationEvent(const ROIB::RoIBResult &result) const override
checks if we have calibration items fired in this event
virtual std::vector< std::unique_ptr< LVL1CTP::Lvl1Item > > makeLvl1ItemConfig(const EventContext &context) const override
virtual StatusCode initialize() override
SG::ReadCondHandleKey< TrigConf::L1PrescalesSet > m_l1PrescaleSetInputKey
access to L1Prescales
virtual std::bitset< 3 > lvl1EMTauJetOverflow(const ROIB::RoIBResult &result) override
Check if there was an overflow in the TOB transmission to CMX.
LVL1::JEPRoIDecoder m_jepDecoder
SG::WriteHandleKey< LVL1CTP::Lvl1Result > m_l1ResultKey
virtual std::vector< const LVL1CTP::Lvl1Item * > createL1Items(const std::vector< std::unique_ptr< LVL1CTP::Lvl1Item > > &lvl1ItemConfig, const ROIB::RoIBResult &result, LVL1CTP::Lvl1Result const **lvl1ResultOut=nullptr) const override
Extract LVL1 items from given RoIBResult.
Lvl1ResultAccessTool(const std::string &name, const std::string &type, const IInterface *parent)
std Gaudi constructor
Class holding the LVL1 RoIB result build by the RoIBuilder.
Definition RoIBResult.h:47
static HLTHash string2hash(const std::string &, const std::string &category="TE")
hash function translating TE names into identifiers
L1 menu configuration.
Definition L1Menu.h:28
L1 menu configuration.
const L1Prescale & prescale(const std::string &itemName) const
double getPrescaleFromCut(uint32_t cut) const
prescale = 2*24/(cut+1.)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
MsgStream & msg
Definition testRead.cxx:32