ATLAS Offline Software
Loading...
Searching...
No Matches
MUCTPI_AthTool.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// First the corresponding header.
6#include "MUCTPI_AthTool.h"
7#include "TriggerProcessor.h"
9#include "Configuration.h"
11
12// The headers from other ATLAS packages,
13// from most to least dependent.
14
15// Headers from external packages.
16
17// The new trigger configuration
18#include "TrigConfData/L1Menu.h"
19
20// Interfaces used by the simulation
23
24// The output object of the simulation
27
30#include "xAODTrigger/MuonRoI.h"
32
34
36
37// System headers.
38
39
40namespace LVL1MUCTPIPHASE1 {
41 const std::string MUCTPI_AthTool::m_DEFAULT_locationMuCTPItoCTP = "/Run/L1MuCTPItoCTPLocation";
42 const std::string MUCTPI_AthTool::m_DEFAULT_locationMuCTPItoRoIB = "/Run/L1MuCTPItoRoIBLocation";
43 const std::string MUCTPI_AthTool::m_DEFAULT_L1MuctpiStoreLocationRPC = "/Event/L1MuctpiStoreRPC";
44 const std::string MUCTPI_AthTool::m_DEFAULT_L1MuctpiStoreLocationTGC = "/Event/L1MuctpiStoreTGC";
45 const std::string MUCTPI_AthTool::m_DEFAULT_AODLocID = "LVL1_ROI";
46 const std::string MUCTPI_AthTool::m_DEFAULT_RDOLocID = "MUCTPI_RDO";
47 const std::string MUCTPI_AthTool::m_DEFAULT_barrelRoIFile = "TrigConfMuctpi/Data_ROI_Mapping_Barrel_040422.txt";
48 const std::string MUCTPI_AthTool::m_DEFAULT_ecfRoIFile = "TrigConfMuctpi/Data_RoI_Mapping_EF_040422.txt";
49 const std::string MUCTPI_AthTool::m_DEFAULT_side0LUTFile = "TrigConfMuctpi/lookup_0_040422.json";
50 const std::string MUCTPI_AthTool::m_DEFAULT_side1LUTFile = "TrigConfMuctpi/lookup_1_040422.json";
51
52 MUCTPI_AthTool::MUCTPI_AthTool(const std::string& type, const std::string& name, const IInterface* parent)
53 : AthAlgTool(type, name, parent)
54 {
55
56 // Init message
57 ATH_MSG_INFO( "=======================================" );
58 ATH_MSG_INFO( "Constructor for Phase1 MUCTPI_AthTool." );
59 ATH_MSG_INFO( "=======================================" );
60
61 }
62
64 {
65 ATH_MSG_INFO( "=======================================" );
66 ATH_MSG_INFO( "Initialisation for Phase1 MUCTPI_AthTool" );
67 ATH_MSG_INFO( "=======================================" );
68
69 //
70 // Set up the input source, and running conditions:
71 //
72 if( m_inputSource == "DIGITIZATION" ) {
73
74 ATH_MSG_INFO( "Setting input source to digitization" );
76
77 } else if( m_inputSource == "AOD" ) {
78
79 ATH_MSG_INFO( "Setting input source to AOD" );
81
82 } else if( m_inputSource == "RDO" ) {
83
84 ATH_MSG_INFO( "Setting input source to RDO" );
86
87 } else {
88
89 REPORT_ERROR( StatusCode::FAILURE )
90 << "Wrong input source specified: \"" << m_inputSource
91 << "\"";
92 return StatusCode::FAILURE;
93
94 }
95
96 //initialize MSP ROI configuration
97
98
99 const std::string barrelFileName = PathResolverFindCalibFile( m_barrelRoIFile );
100 const std::string ecfFileName = PathResolverFindCalibFile( m_ecfRoIFile );
101 const std::string side0LUTFileName = PathResolverFindCalibFile( m_side0LUTFile );
102 const std::string side1LUTFileName = PathResolverFindCalibFile( m_side1LUTFile );
103 ATH_MSG_INFO("Initializing L1Topo decoding with the following inputs");
104 ATH_MSG_INFO(" Barrel file: " << barrelFileName);
105 ATH_MSG_INFO(" EC/Fwd file: " << ecfFileName);
106 ATH_MSG_INFO(" Side 0 LUT: " << side0LUTFileName);
107 ATH_MSG_INFO(" Side 1 LUT: " << side1LUTFileName);
108 std::vector<std::string> topo_errors = m_theMuctpi.configureTopo(barrelFileName,
109 ecfFileName,
110 side0LUTFileName,
111 side1LUTFileName);
112 if (topo_errors.size())
113 {
114 std::stringstream err;
115 err << "Couldn't initialize L1Topo eta/phi encoding/decoding:\n";
116 for (unsigned i=0;i<topo_errors.size();i++) err << topo_errors[i] << "\n";
117 REPORT_ERROR( StatusCode::FAILURE ) << err.str();
118 return StatusCode::FAILURE;
119 }
120
121 //
122 // Set up the overlap handling of the simulation:
123 //
124
125 if( m_overlapStrategyName == "NULL" ) {
126
127 ATH_MSG_DEBUG( "Setting overlap strategy: \"NULL\"" );
128
129 } else if( m_overlapStrategyName == "LUT" ) {
130
131 ATH_MSG_DEBUG( "Setting overlap strategy: \"LUT\"" );
132
133 ATH_MSG_INFO( "XML LUT file defined in jobO: " << m_lutXMLFile );
134 const std::string fullFileName = PathResolverFindCalibFile( m_lutXMLFile );
135 ATH_MSG_DEBUG( "Full path to XML LUT file: " << fullFileName );
136
137 for (MuonSectorProcessor& msp : m_theMuctpi.getMuonSectorProcessors())
138 {
139 msp.configureOverlapRemoval(fullFileName);
140 }
141
142 } else {
143
144 REPORT_ERROR( StatusCode::FAILURE )
145 << "Wrong overlap strategy name specified: \""
146 << m_overlapStrategyName << "\"";
147 return StatusCode::FAILURE;
148
149 }
150
151
152
153 //Initialize Read/WriteHandleKeys
154 ATH_CHECK(m_muctpiPhase1KeyRPC.initialize());
155 ATH_CHECK(m_muctpiPhase1KeyTGC.initialize());
156 ATH_CHECK(m_MuCTPICTPWriteKey.initialize());
157 ATH_CHECK(m_MuCTPI_xAODWriteKeys.initialize());
158 ATH_CHECK(m_MuCTPIL1TopoKeys.initialize());
159
160 ATH_CHECK( m_rpcTool.retrieve() );
161 ATH_CHECK( m_tgcTool.retrieve() );
163
164 return StatusCode::SUCCESS;
165 }
166
168 {
169 ATH_MSG_INFO( "=======================================" );
170 ATH_MSG_INFO( "Start for Phase1 MUCTPI_AthTool" );
171 ATH_MSG_INFO( "=======================================" );
172
173 ATH_MSG_INFO( "initialize(): use L1 trigger menu from detector store" );
174 const TrigConf::L1Menu * l1menu = nullptr;
175 ATH_CHECK( m_detStore->retrieve(l1menu) );
176 m_theMuctpi.getTriggerProcessor().setTrigTool(*m_trigThresholdDecisionTool);
177 m_theMuctpi.getTriggerProcessor().setMenu(l1menu);
178 for (MuonSectorProcessor& msp : m_theMuctpi.getMuonSectorProcessors())
179 {
180 msp.setMenu(l1menu);
181 if (!msp.configurePtEncoding())
182 {
183 REPORT_ERROR( StatusCode::FAILURE )
184 << "Couldn't configure pt encoding in MuonSectorProcessor " << msp.getSide();
185 return StatusCode::FAILURE;
186 }
187 }
188
189 return StatusCode::SUCCESS;
190 }
191
192 //----------------------------------------------
193 // execute() method called once per event
194 //----------------------------------------------
195 StatusCode MUCTPI_AthTool::execute( ) const {
196
197 // Now this is a tricky part. We have to force the message logging of the
198 // MuCTPI simulation to display messages of the same level as this MsgStream.
199 ATH_MSG_DEBUG( "===============================" );
200 ATH_MSG_DEBUG( "Executing MUCTPI_AthTool" );
201 ATH_MSG_DEBUG( "===============================" );
202
203 // Now this is a tricky one. I only had to make the decision of which function to call
204 // at execute once in initialize(). Now I can call the right function like this:
205 return ( this->*m_executeFunction )();
206 }
207
213
214 ATH_MSG_DEBUG( "in executeFromDigi()" );
215
216 //
217 // Get the RPC MUCTPI-input object from StoreGate.
218 //
219 bool gotRPCInput( false );
221 const LVL1MUONIF::Lvl1MuCTPIInputPhase1* dHandleRPC = rh_muctpiRpc.ptr();
222 if (!dHandleRPC) {
223 ATH_MSG_WARNING( "Cannot retrieve RPC L1Muctpi object from StoreGate!" );
224 }
225 else {
226 ATH_MSG_DEBUG( "Retrieved RPC Lvl1MuCTPIInput object from StoreGate" );
227 gotRPCInput = true;
228 }
229
230 //
231 // Get the TGC MUCTPI-input object from StoreGate.
232 //
233 bool gotTGCInput( false );
235 const LVL1MUONIF::Lvl1MuCTPIInputPhase1* dHandleTGC = rh_muctpiTgc.ptr();
236 if (!dHandleTGC) {
237 ATH_MSG_WARNING( "Cannot retrieve TGC L1Muctpi object from StoreGate!" );
238 }
239 else {
240 ATH_MSG_DEBUG( "Retrieved TGC Lvl1MuCTPIInput object from StoreGate" );
241 gotTGCInput = true;
242 }
243
244 // Merge the two inputs:
246
247 if( ! ( gotRPCInput && gotTGCInput ) ) {
248 ATH_MSG_WARNING( "No input received from the RPC or TGC sector logic simulation" );
249 return StatusCode::SUCCESS;
250 }
251
252 mergedInput.merge( *dHandleRPC );
253 mergedInput.merge( *dHandleTGC );
254
257
258
259 //always process the central slice, which defaults to bcidOffset = 0
260 // process the input in the MUCTPI simulation
261 MUCTPIResults resultsBC0;
262 std::string ret = m_theMuctpi.processData(&mergedInput, resultsBC0, 0);
263 if (ret != "")
264 {
265 REPORT_ERROR( StatusCode::FAILURE ) << "Error while processing MUCTPI data: " << ret;
266 return StatusCode::FAILURE;
267 }
268 // Save the output of the simulation
269 CHECK( saveOutput(resultsBC0) );
270
271 // check the other 4 possible BC offset values in case the input objects tells us there are
272 // out of time candidates
276
277 for (const int bcidOffset : m_bcidOffsetList) {
278 if ( !mergedInput.isEmptyAll(bcidOffset) ) {
279 MUCTPIResults results;
280 // process the input in the MUCTPI simulation
281 m_theMuctpi.processData(&mergedInput, results, bcidOffset);
282 // Save the output of the simulation
283 CHECK( saveOutput(results, bcidOffset) );
284 } else {
285 // Record empty outputs
286 CHECK( saveOutput(std::nullopt, bcidOffset) );
287 }
288 }
289 } else {
290 // Record emtpy outputs
291 for (const int bcidOffset : m_bcidOffsetList) {
292 CHECK( saveOutput(std::nullopt, bcidOffset) );
293 }
294 }
295
296 return StatusCode::SUCCESS;
297 }
298
299
300 //This is a new execute() function. It reads the LVL1_ROI object from an AOD file, it converts
301 //the muon RoIs back into the input format of the MuCTPI, then runs the MuCTPI information
302 //with this transformed input.
304
305 //this functionality still needs converted to the new data format.
306 //in particular, Converter.cxx doesn't exist anymore.
307
308 // Retrieve the LVL1_ROI object from the AOD:
309 // const LVL1_ROI* lvl1RoI = 0;
310 // CHECK( evtStore()->retrieve( lvl1RoI, m_aodLocId ) );
311 // ATH_MSG_DEBUG( "Retrieved LVL1_ROI object from StoreGate" );
312
313 // // Extract the RoIs into a vector:
314 // std::vector< unsigned int > convertableRoIs;
315 // LVL1_ROI::muons_type::const_iterator muonRoI_itr = lvl1RoI->getMuonROIs().begin();
316 // LVL1_ROI::muons_type::const_iterator muonRoI_end = lvl1RoI->getMuonROIs().end();
317 // for( ; muonRoI_itr != muonRoI_end; ++muonRoI_itr ) {
318 // convertableRoIs.push_back( muonRoI_itr->getROIWord() );
319 // }
320
321 // // Create the input to the MuCTPI:
322 // LVL1MUONIF::Lvl1MuCTPIInputPhase1 convertedInput;
323 // CHECK( Converter::convertRoIs( convertableRoIs, &convertedInput ) );
324
325 // // process the input with the MuCTPI simulation
326 // m_theMuctpi.processData( &convertedInput );
327
328 // store CTP result in interface object and put to StoreGate
329 //TEMPORARILY REMOVED UNTIL MUCTPICTP UPDATED TO VECTOR!
330 //LVL1::MuCTPICTP* theCTPResult = new LVL1::MuCTPICTP( m_theMuctpi.getCTPData() );
331 //CHECK( evtStore()->record( theCTPResult, m_ctpOutputLocId ) );
332 // ATH_MSG_DEBUG( "CTP word recorded to StoreGate with key: "
333 // << m_ctpOutputLocId );
334
335 // // Save the output of the simulation
336 // CHECK( saveOutput() );
337
338 return StatusCode::SUCCESS;
339 }
340
341
342 //This is a new execute() function. It reads the MuCTPI_RDO object from an RDO file, it
343 //converts the muon data words back into the input format of the MuCTPI, then runs the
344 //MuCTPI information with this transformed input.
345
347
348 //this function still needs to be written.
349 //in particular, converter doesn't exist anymore.
350
351 // ATH_MSG_DEBUG( "in executeFromRDO()" );
352
353 // // Retrieve the MuCTPI_RDO object from the digitized file:
354 // SG::ReadHandle<MuCTPI_RDO> rh_muctpi_rdo(m_MuCTPI_RDOReadKey);
355 // const MuCTPI_RDO* old_RDO = rh_muctpi_rdo.ptr();
356 // ATH_MSG_DEBUG( "Retrieved MuCTPI_RDO object from StoreGate" );
357
358 // // Get the BCID of the collision:
359 // const unsigned int bcid = ( ( old_RDO->candidateMultiplicity() >> 18 ) & 0x7 );
360
361 // // Create the input to the MuCTPI:
362 // LVL1MUONIF::Lvl1MuCTPIInputPhase1 convertedInput;
363 // CHECK( Converter::convertRDO( old_RDO->dataWord(), bcid, &convertedInput ) );
364
365 // // process the input with the MuCTPI simulation
366 // m_theMuctpi.processData( &convertedInput );
367
368 // // Save the output of the simulation
369 // CHECK( saveOutput() );
370
371 return StatusCode::SUCCESS;
372 }
373
374
375
376
377 StatusCode MUCTPI_AthTool::saveOutput(std::optional<std::reference_wrapper<MUCTPIResults>> results, int bcidOffset) const {
378
379 // Record an empty MuCTPI xAOD container (filled later below)
380 auto xAODRoIsKeyIt = m_MuCTPI_xAODWriteKeys.begin();
381 std::advance(xAODRoIsKeyIt, bcidOffset+2);
382 auto xAODRoIs = SG::makeHandle(*xAODRoIsKeyIt);
383 ATH_CHECK(xAODRoIs.record(std::make_unique<xAOD::MuonRoIContainer>(),
384 std::make_unique<xAOD::MuonRoIAuxContainer>()));
385 ATH_MSG_DEBUG("Recorded MuonRoIContainer with key " << xAODRoIs.key());
386
387 // Create a WriteHandle for L1Topo output
388 auto l1topoKeyIt = m_MuCTPIL1TopoKeys.begin();
389 std::advance(l1topoKeyIt, bcidOffset+2);
390 SG::WriteHandle<LVL1::MuCTPIL1Topo> l1topo(*l1topoKeyIt);
391
392 // If no results for this BCID, record empty outputs and return
393 if (!results.has_value()) {
394 ATH_CHECK(l1topo.record(std::make_unique<LVL1::MuCTPIL1Topo>()));
395 ATH_MSG_DEBUG("L1Topo output recorded to StoreGate with key " << l1topo.key());
396 ATH_MSG_DEBUG("No results for BCID offset " << bcidOffset << " - recorded empty outputs");
397 return StatusCode::SUCCESS;
398 }
399
400 // Store CTP result in interface object and put to StoreGate (only for BC=0)
401 if (bcidOffset==0) {
402 // Check that the multiplicity was filled
403 const std::vector<unsigned int>& ctpData = results->get().ctp_words;
404 if (ctpData.empty()) {
405 ATH_MSG_ERROR("TriggerProcessor didn't provide correct CTP data");
406 return StatusCode::FAILURE;
407 }
408 // Record
410 ATH_CHECK(muctpi_ctp.record(std::make_unique<LVL1::MuCTPICTP>(ctpData)));
411 ATH_MSG_DEBUG("CTP word recorded to StoreGate with key " << muctpi_ctp.key());
412 }
413
414 // Create MuCTPI xAOD and fill the container
415 for (const DAQData& data : results->get().daq_data) {
416 xAODRoIs->push_back(std::make_unique<xAOD::MuonRoI>());
417
419 switch (LVL1::MuCTPIBits::getSubsysID(data.dataWord)) {
420 case LVL1::MuCTPIBits::SubsysID::Endcap: // same for Endcap and Forward
422 ATH_CHECK( m_tgcTool->roiData(data.dataWord, roiData) );
423 break;
424 }
426 ATH_CHECK( m_rpcTool->roiData(data.dataWord, roiData) );
427 break;
428 }
429 default: {
430 ATH_MSG_ERROR("Failed to determine Sector ID from RoI word 0x" << std::hex << data.dataWord << std::dec);
431 return StatusCode::FAILURE;
432 }
433 }
434 // despite the name "GetMin" we are actually getting the Max thr value here
435 std::pair<std::string, double> maxThrInfo = m_trigThresholdDecisionTool->getMinThresholdNameAndValue(data.thresholdDecisions, roiData.eta());
436 xAODRoIs->back()->initialize(data.dataWord, roiData.eta(), roiData.phi(), maxThrInfo.first, maxThrInfo.second, 0); // Note: last 0 is the extraRoI word for phase-II RoI
437 }
438
439 // Get outputs for L1Topo and store into Storegate
440 ATH_CHECK(l1topo.record(std::make_unique<LVL1::MuCTPIL1Topo>(results->get().l1topoData.getCandidates())));
441 if (bcidOffset!=0) {l1topo->setBcidOffset(bcidOffset);}
442 ATH_MSG_DEBUG("L1Topo output recorded to StoreGate with key " << l1topo.key());
443
444 return StatusCode::SUCCESS;
445 }
446}
447
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define REPORT_ERROR(SC)
Report an error.
#define CHECK(...)
Evaluate an expression and check for errors.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
StatusCode(LVL1MUCTPIPHASE1::MUCTPI_AthTool::* m_executeFunction)(void) const
Function pointer to the execute function we want to use:
Gaudi::Property< std::string > m_overlapStrategyName
Gaudi::Property< std::string > m_ecfRoIFile
static const std::string m_DEFAULT_side0LUTFile
virtual StatusCode initialize() override
static const std::string m_DEFAULT_AODLocID
static const std::string m_DEFAULT_L1MuctpiStoreLocationTGC
Gaudi::Property< std::string > m_side0LUTFile
StatusCode executeFromDigi() const
Event loop method for running as part of digitization.
static const std::string m_DEFAULT_locationMuCTPItoCTP
static const std::string m_DEFAULT_barrelRoIFile
Gaudi::Property< std::string > m_lutXMLFile
static const std::string m_DEFAULT_locationMuCTPItoRoIB
virtual StatusCode start() override
ServiceHandle< StoreGateSvc > m_detStore
static const std::string m_DEFAULT_RDOLocID
MUCTPI_AthTool(const std::string &type, const std::string &name, const IInterface *parent)
SG::WriteHandleKey< LVL1::MuCTPICTP > m_MuCTPICTPWriteKey
ToolHandle< LVL1::ITrigT1MuonRecRoiTool > m_tgcTool
static constexpr std::array< int, 4 > m_bcidOffsetList
Gaudi::Property< std::string > m_barrelRoIFile
SG::WriteHandleKeyArray< xAOD::MuonRoIContainer > m_MuCTPI_xAODWriteKeys
Gaudi::Property< std::string > m_side1LUTFile
SG::ReadHandleKey< LVL1MUONIF::Lvl1MuCTPIInputPhase1 > m_muctpiPhase1KeyRPC
SG::WriteHandleKeyArray< LVL1::MuCTPIL1Topo > m_MuCTPIL1TopoKeys
ToolHandle< LVL1::ITrigT1MuonRecRoiTool > m_rpcTool
StatusCode executeFromRDO() const
Event loop method for running on an RDO file.
static const std::string m_DEFAULT_side1LUTFile
ToolHandle< LVL1::TrigThresholdDecisionTool > m_trigThresholdDecisionTool
StatusCode executeFromAOD() const
Event loop method for running on an AOD file.
static const std::string m_DEFAULT_L1MuctpiStoreLocationRPC
StatusCode saveOutput(std::optional< std::reference_wrapper< MUCTPIResults > > results, int bcidOffset=0) const
Save the outputs of the simulation into StoreGate.
SG::ReadHandleKey< LVL1MUONIF::Lvl1MuCTPIInputPhase1 > m_muctpiPhase1KeyTGC
Gaudi::Property< std::string > m_inputSource
static const std::string m_DEFAULT_ecfRoIFile
Class representing (part of) the input data to the MuCTPI for Phase 1.
void merge(const Lvl1MuCTPIInputPhase1 &another)
Merge SectorLogic data of another object into this data of a system (Barrel, Endcap or Forward) is no...
bool isEmptyAll(int bcid=0) const
Return "true" if data of all systems for this bcid is empty.
bool hasOutOfTimeCandidates(size_t systemAddress) const
Return "true" if data of specified system is filled for bunches other than 'current' bunch.
const_pointer_type ptr()
Dereference the pointer.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
L1 menu configuration.
Definition L1Menu.h:28
constexpr SubsysID getSubsysID(uint32_t word)
Decode the subsys ID from RoI candidate word.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())