ATLAS Offline Software
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 
5 #include "Lvl1ResultAccessTool.h"
6 
8 #include "CTPfragment/CTPdataformatVersion.h"
9 
10 #include "TrigConfData/L1Menu.h"
13 
14 
15 HLT::Lvl1ResultAccessTool::Lvl1ResultAccessTool(const std::string& name, const std::string& type,
16  const IInterface* parent) :
17  base_class(name, type, parent)
18 {
19 }
20 
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 // =============================================================
35 std::vector< std::unique_ptr<LVL1CTP::Lvl1Item> >
36 HLT::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 {
46  SG::ReadCondHandle<TrigConf::L1PrescalesSet> l1psRH(m_l1PrescaleSetInputKey, context);
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
70 bool
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 
84 namespace {
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 // ==============================
99 std::vector< const LVL1CTP::Lvl1Item* >
100 HLT::Lvl1ResultAccessTool::createL1Items( const std::vector< std::unique_ptr<LVL1CTP::Lvl1Item> >& lvl1ItemConfig,
101  const ROIB::RoIBResult& result,
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 
172 std::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 
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
get_generator_info.result
result
Definition: get_generator_info.py:21
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ROIB::EMTauResult
Definition: EMTauResult.h:25
ROIB::RoIBResult
Class holding the LVL1 RoIB result build by the RoIBuilder.
Definition: RoIBResult.h:47
LVL1::TrigT1CaloDefs::TauRoIWordType
@ TauRoIWordType
Definition: TrigT1CaloDefs.h:173
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
RoIBResult.h
HLT::Lvl1ResultAccessTool::createL1Items
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.
Definition: Lvl1ResultAccessTool.cxx:100
HLT::Lvl1ResultAccessTool::initialize
virtual StatusCode initialize() override
Definition: Lvl1ResultAccessTool.cxx:22
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
ROIB::JetEnergyRoI
Definition: JetEnergyRoI.h:20
TrigConf::L1Menu
L1 menu configuration.
Definition: L1Menu.h:28
HLT::Lvl1ResultAccessTool::isCalibrationEvent
virtual bool isCalibrationEvent(const ROIB::RoIBResult &result) const override
checks if we have calibration items fired in this event
Definition: Lvl1ResultAccessTool.cxx:71
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ROIB::JetEnergyResult
Definition: JetEnergyResult.h:24
Lvl1ResultAccessTool.h
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
Lvl1Result.h
LVL1CTP::Lvl1Item
Definition: Lvl1Item.h:37
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HLTUtils.h
TrigConf::HLTUtils::string2hash
static HLTHash string2hash(const std::string &, const std::string &category="TE")
hash function translating TE names into identifiers
lumiFormat.i
int i
Definition: lumiFormat.py:92
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
HLT::Lvl1ResultAccessTool::lvl1EMTauJetOverflow
virtual std::bitset< 3 > lvl1EMTauJetOverflow(const ROIB::RoIBResult &result) override
Check if there was an overflow in the TOB transmission to CMX.
Definition: Lvl1ResultAccessTool.cxx:173
HLT::Lvl1ResultAccessTool::Lvl1ResultAccessTool
Lvl1ResultAccessTool(const std::string &name, const std::string &type, const IInterface *parent)
std Gaudi constructor
Definition: Lvl1ResultAccessTool.cxx:15
TrigConf::L1PrescalesSet
L1 menu configuration.
Definition: L1PrescalesSet.h:19
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
LVL1CTP::Lvl1Result
Definition: Lvl1Result.h:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
item
Definition: ItemListSvc.h:43
python.PyAthena.v
v
Definition: PyAthena.py:157
ROIB::EMTauRoI
Definition: EMTauRoI.h:20
LVL1::TrigT1CaloDefs::JetRoIWordType
@ JetRoIWordType
Definition: TrigT1CaloDefs.h:167
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
python.XMLReader.l1menu
l1menu
Definition: XMLReader.py:73
LVL1::TrigT1CaloDefs::EMRoIWordType
@ EMRoIWordType
Definition: TrigT1CaloDefs.h:172
L1Menu.h
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
value_type
Definition: EDM_MasterSearch.h:11
checkFileSG.words
words
Definition: checkFileSG.py:76
python.compressB64.c
def c
Definition: compressB64.py:93
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
HLT::Lvl1ResultAccessTool::makeLvl1ItemConfig
virtual std::vector< std::unique_ptr< LVL1CTP::Lvl1Item > > makeLvl1ItemConfig(const EventContext &context) const override
Definition: Lvl1ResultAccessTool.cxx:36