ATLAS Offline Software
TrigMuonRoITool.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 "TrigMuonRoITool.h"
10 
11 
13  const std::string& name,
14  const IInterface* parent):
15  base_class(type,name,parent),
16  m_robDataProviderSvc( "ROBDataProviderSvc", name ),
17  m_decodeMuCTPiFromROB(false)
18 {
19  // Declare the properties
20  declareProperty("DaqMuCTPiROBid",m_daqMuCTPiROBid=0x760000);
21  declareProperty("DecodeMuCTPiFromROB",m_decodeMuCTPiFromROB=false);
22 }
23 
24 
26 {
28  ATH_CHECK( m_robDataProviderSvc.retrieve() );
29 
30  // Print the property values
31  ATH_MSG_DEBUG(" ROB ID: DAQ muCTPi = " << m_daqMuCTPiROBid
32  << std::setw(6) << " (=0x" << MSG::hex << m_daqMuCTPiROBid.value() << MSG::dec << ")");
33 
34  // Build the vector with ROB Ids to retrieve
35  m_muCTPiRobIds.push_back(m_daqMuCTPiROBid.value());
36 
37  //Retrieve the MuCTPi RDO is we aren't decoding them ourselves
39 
40  return StatusCode::SUCCESS;
41 }
42 
43 
45 std::unique_ptr<TrigMuonRoITool::MuonRois> TrigMuonRoITool::decodeMuCTPi(const EventContext& ctx) const {
46 
47  // save input stream flags
48  char log_fill_char_save = (msg().stream()).fill();
49 
50 
52  // decode MUCTPI
54 
55  // MuCTPi pointer
56  const MuCTPI_RDO* daqmuCTPIResult = 0;
57 
58  // Build muCTPi from DAQ ROB
61 
62  // in L2 the DAQ muCTPi ROB needs to be retreived first from the ROS
63  m_robDataProviderSvc->addROBData(ctx, m_muCTPiRobIds);
64 
65  // get the muCTPi ROB fragment
66  std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> muCTPiRobFragmentVec;
67  muCTPiRobFragmentVec.reserve(m_muCTPiRobIds.size());
68  m_robDataProviderSvc->getROBData(ctx, m_muCTPiRobIds,muCTPiRobFragmentVec);
69 
70  if (muCTPiRobFragmentVec.size()==0) {
71  ATH_MSG_DEBUG(" decodeMuCTPi: No muCTPi ROB found.");
72  return nullptr;
73  }
74 
75  // check for received ROB id and return if it doesn't match the DAQ MuCTPI ROB
76  ATH_MSG_DEBUG(" decodeMuCTPi: ROB id = 0x" << std::setw(6) << MSG::hex << muCTPiRobFragmentVec[0]->source_id() << MSG::dec);
77 
78  if (muCTPiRobFragmentVec[0]->source_id() != (uint32_t)m_daqMuCTPiROBid.value()) {
79  ATH_MSG_DEBUG(" decodeMuCTPi: received ROB id = 0x" << std::setw(6) << MSG::hex << muCTPiRobFragmentVec[0]->source_id() << MSG::dec
80  << " does not match requested ROB id = 0x"
81  << std::setw(6) << MSG::hex << m_daqMuCTPiROBid.value() << MSG::dec);
82  return nullptr;
83  }
84 
85  // decode now the ROB
86  uint32_t formatVersion = muCTPiRobFragmentVec[0]->rod_version();
87  uint32_t evtNum = muCTPiRobFragmentVec[0]->rod_lvl1_id();
88  uint32_t robFragSize = muCTPiRobFragmentVec[0]->fragment_size_word();
89  uint32_t rodFragSize = muCTPiRobFragmentVec[0]->rod_fragment_size_word();
90  uint32_t robId = muCTPiRobFragmentVec[0]->source_id();
91  uint32_t rodId = muCTPiRobFragmentVec[0]->rod_source_id();
92  const uint32_t bcId = muCTPiRobFragmentVec[0]->rod_bc_id();
93 
94  const uint32_t* status;
95  muCTPiRobFragmentVec[0]->rod_status( status );
96  // nstatus, errorStat not used, cause compilation warning
97  //uint32_t nstatus = muCTPiRobFragmentVec[0]->rod_nstatus();
98  //uint32_t errorStat( 0 );
99  //if( nstatus > 0 ) errorStat = static_cast< uint32_t >( *status );
100  //
101 
102  ATH_MSG_DEBUG("ROB ID 0x" << MSG::hex << robId << " ROD ID 0x"
103  << rodId << MSG::dec << " ROB fragment size "
104  << robFragSize << " ROD fragment size " << rodFragSize);
105 
106  ATH_MSG_DEBUG(" ROD Header L1 ID " << evtNum
107  << " ROD Header BCID " << bcId
108  << " ROD Header Format version " << formatVersion);
109 
111  muCTPiRobFragmentVec[0]->rod_data( it_data );
112  const uint32_t ndata = muCTPiRobFragmentVec[0]->rod_ndata();
113  ATH_MSG_DEBUG( " Dumping RoI Words:");
114  ATH_MSG_DEBUG( " number of data words: " << ndata);
115  // candidate multiplicity
116  std::vector< uint32_t > candidateMultiplicity;
117  // data words
118  std::vector< uint32_t > dataWord;
119  for( uint32_t i = 0; i < ndata; ++i, ++it_data ) {
120  if( *it_data >> LVL1::MuCTPIBits::MULT_WORD_FLAG_SHIFT ) {
121  candidateMultiplicity.push_back( static_cast< uint32_t >( *it_data ) );
122  ATH_MSG_DEBUG(" 0x" << MSG::hex << std::setw( 8 ) << std::setfill( '0' )
123  << ( *it_data ) << " (candidate multiplicity)" << std::setfill( log_fill_char_save ));
124  } else {
125  dataWord.push_back( static_cast< uint32_t >( *it_data ) );
126  ATH_MSG_DEBUG(" 0x" << MSG::hex << std::setw( 8 ) << std::setfill( '0' )
127  << ( *it_data ) << " (candidate word)"
128  << " (--> RoI word = 0x" << MSG::hex << std::setw( 8 ) << std::setfill( '0' )
129  << mirodToRoIBDataWord( *it_data ) << ")"
130  << std::setfill( log_fill_char_save ));
131  }
132  }
133 
134  // create MuCTPi RDO (DAQ muCTPi Result)
135  daqmuCTPIResult = new MuCTPI_RDO( std::move(candidateMultiplicity), std::move(dataWord) );
136  }
137 
138  // Retrieve the MuCTPi RDO via data handle
140  else{
141  SG::ReadHandle<MuCTPI_RDO> rdoHandle(m_muCTPIKey, ctx);
142  if(rdoHandle.isValid()){
143  daqmuCTPIResult = rdoHandle.cptr();
144  }
145  else{
146  ATH_MSG_WARNING("Can't get MUCTPI_RDO object");
147  return nullptr;
148  }
149  }
150 
151  // print contents
152  if (msgLvl(MSG::DEBUG)) {
154  for(std::vector< uint32_t >::const_iterator it = daqmuCTPIResult->dataWord().begin();
155  it != daqmuCTPIResult->dataWord().end(); ++it) {
158  }
159  }
160 
161  // now select out the RoI candidates for the BCID which triggered the event and save them in
162  // a special list indexed by RoI ID
163  uint16_t roiEventBCID = MuCTPI_MultiplicityWord_Decoder(daqmuCTPIResult->candidateMultiplicity()).getBCID();
165 
166  // reset the containers and fill them with new data
167  auto inTime_muCTPIRoIs= std::vector<ROIB::MuCTPIRoI>();
168  auto outOfTime_muCTPIRoIs= std::vector< std::pair<ROIB::MuCTPIRoI,int> >();
169 
170  inTime_muCTPIRoIs.reserve( roiEventNCan );
171  outOfTime_muCTPIRoIs.reserve( roiEventNCan );
172 
173  for(std::vector< uint32_t >::const_iterator it = daqmuCTPIResult->dataWord().begin();
174  it != daqmuCTPIResult->dataWord().end(); ++it) {
175 
176  // decode the RDO data word
177  MuCTPI_DataWord_Decoder daqRoI(*it);
178 
179  // create a L1 RoI
181 
182  if (roiEventBCID == daqRoI.getBCID()) { // RoI matches event BCID
183  inTime_muCTPIRoIs.push_back(roI);
184  } else {
185  outOfTime_muCTPIRoIs.push_back( std::pair<ROIB::MuCTPIRoI,int>(roI,(int(daqRoI.getBCID())-int(roiEventBCID))) );
186  }
187  } // end loop over data words
188 
189  // print contents of RoI arrays
190  if (msgLvl(MSG::DEBUG)) {
191  ATH_MSG_DEBUG(" RoIs in time with event BCID: Number of RoIs = " << inTime_muCTPIRoIs.size());
192  for (std::vector< ROIB::MuCTPIRoI >::iterator it = inTime_muCTPIRoIs.begin(); it != inTime_muCTPIRoIs.end(); ++it) {
193  dumpRoIBDataWord((*it).roIWord());
194  }
195 
196  ATH_MSG_DEBUG(" RoIs out of time with event BCID: Number of RoIs = " << outOfTime_muCTPIRoIs.size());
197  for (std::vector< std::pair<ROIB::MuCTPIRoI,int> >::iterator it = outOfTime_muCTPIRoIs.begin(); it != outOfTime_muCTPIRoIs.end(); ++it) {
198  ATH_MSG_DEBUG( " Difference(RoI(BCID) - Event(BCID)) = " << (*it).second);
199  dumpRoIBDataWord(((*it).first).roIWord());
200  }
201  }
202 
203  std::unique_ptr<TrigMuonRoITool::MuonRois> rois(new TrigMuonRoITool::MuonRois(std::move(inTime_muCTPIRoIs), std::move(outOfTime_muCTPIRoIs)));
204 
205 
207  delete daqmuCTPIResult;
208 
209  return rois;
210 }
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
214  return ( ( ( data_word & 0x8000000 ) >> 4 ) | ( ( data_word & 0x3fe0000 ) >> 3 ) |
215  ( data_word & 0x3fff ) );
216 }
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
220 
221  ROIB::MuCTPIRoI roI(data_word);
222 
223  std::string loc = "UNDEFINED";
225  loc = "ENDCAP";
226  else if( roI.getSectorLocation() == MuCTPI_RDO::FORWARD )
227  loc = "FORWARD";
228  else if( roI.getSectorLocation() == MuCTPI_RDO::BARREL )
229  loc = "BARREL";
230 
231  ATH_MSG_DEBUG( "RoIB word : 0x" << MSG::hex << roI.roIWord() );
232  ATH_MSG_DEBUG( "Threshold : pt" << roI.pt() );
233  ATH_MSG_DEBUG( "Sector location : " << loc );
234  std::string sectorOffset("");
235  if ((roI.getSectorAddress() & LVL1::MuCTPIBits::SECTOR_HEMISPHERE_MASK) &&
236  (roI.getSectorLocation() == MuCTPI_RDO::BARREL)) sectorOffset = " + 32 for Hemisphere = 1 ";
237  ATH_MSG_DEBUG( "Sector ID : " << roI.getSectorID() << sectorOffset );
238  ATH_MSG_DEBUG( "Sector addr : 0x" << MSG::hex << roI.getSectorAddress());
239  ATH_MSG_DEBUG( "Sector overflow : " << roI.getSectorOverflow() );
240  ATH_MSG_DEBUG( "RoI overflow : " << roI.getRoiOverflow() );
241  ATH_MSG_DEBUG( "RoI number : " << roI.getRoiNumber() );
242  ATH_MSG_DEBUG( "IsHighestPt : " << roI.getCandidateIsHighestPt() );
243  ATH_MSG_DEBUG( "Overlap : " << roI.getOverlapBits() );
244  ATH_MSG_DEBUG( "Hemisphere : " << (roI.getSectorAddress() & LVL1::MuCTPIBits::SECTOR_HEMISPHERE_MASK) );
245  return;
246 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ROIB::MuCTPIRoI::getSectorLocation
MuCTPI_RDO::SectorLocation getSectorLocation() const
Method returning the name of the system that produced the RoI.
Definition: MuCTPIRoI.cxx:180
ROIB::MuCTPIRoI::getRoiNumber
uint16_t getRoiNumber() const
Method returning the RoI in which the candidate was detected.
Definition: MuCTPIRoI.cxx:115
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TrigMuonRoITool::TrigMuonRoITool
TrigMuonRoITool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TrigMuonRoITool.cxx:12
initialize
void initialize()
Definition: run_EoverP.cxx:894
skel.it
it
Definition: skel.GENtoEVGEN.py:396
MuCTPI_RDO::BARREL
@ BARREL
Definition: MuCTPI_RDO.h:45
MuCTPI_RDO::FORWARD
@ FORWARD
Definition: MuCTPI_RDO.h:45
TrigMuonRoITool::m_muCTPIKey
SG::ReadHandleKey< MuCTPI_RDO > m_muCTPIKey
Definition: TrigMuonRoITool.h:32
ROIB::MuCTPIRoI
Class for storing the 32-bit muon RoI word.
Definition: MuCTPIRoI.h:39
ROIB::MuCTPIRoI::getRoiOverflow
uint16_t getRoiOverflow() const
Method telling whether there were more than one candidates in this candidate's RoI.
Definition: MuCTPIRoI.cxx:100
TrigMuonRoITool::m_muCTPiRobIds
std::vector< uint32_t > m_muCTPiRobIds
vectors with muCTPi ROB Ids to retrieve
Definition: TrigMuonRoITool.h:42
ROIB::MuCTPIRoI::getCandidateIsHighestPt
uint16_t getCandidateIsHighestPt() const
Method telling whether the candidate had the highest pT in the sector.
Definition: MuCTPIRoI.cxx:217
TrigMuonRoITool::m_daqMuCTPiROBid
IntegerProperty m_daqMuCTPiROBid
Source identifiers for ROB fragments.
Definition: TrigMuonRoITool.h:39
MuCTPI_MultiplicityWord_Decoder.h
MuCTPI_DataWord_Decoder::dumpData
void dumpData() const
Function dumping the stored information to the message stream.
Definition: MuCTPI_DataWord_Decoder.cxx:204
MuCTPI_RDO::ENDCAP
@ ENDCAP
Definition: MuCTPI_RDO.h:45
TrigMuonRoITool::decodeMuCTPi
virtual std::unique_ptr< TrigMuonRoITool::MuonRois > decodeMuCTPi(const EventContext &ctx) const override
Decoding the muCTPi RoIB and DAQ ROB and return in and out of time RoIs.
Definition: TrigMuonRoITool.cxx:45
OFFLINE_FRAGMENTS_NAMESPACE::PointerType
const DataType * PointerType
Definition: RawEvent.h:25
MuCTPI_RDO::candidateMultiplicity
uint32_t candidateMultiplicity() const
Function returning the candidate multiplicity for the triggered bunch crossing.
Definition: MuCTPI_RDO.h:106
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
lumiFormat.i
int i
Definition: lumiFormat.py:85
ROIB::MuCTPIRoI::roIWord
uint32_t roIWord() const
Method returning the RoI word.
Definition: MuCTPIRoI.cxx:35
TrigMuonRoITool::initialize
virtual StatusCode initialize() override
Definition: TrigMuonRoITool.cxx:25
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
MuCTPI_DataWord_Decoder::getBCID
uint16_t getBCID() const
3-bit BCID fragment saved with the candidate
Definition: MuCTPI_DataWord_Decoder.cxx:154
TrigMuonRoITool::mirodToRoIBDataWord
uint32_t mirodToRoIBDataWord(uint32_t data_word) const
Helper for converting a mirod DAQ data word to a muCTPi RoIB data word.
Definition: TrigMuonRoITool.cxx:213
TrigMuonRoITool::m_robDataProviderSvc
IIROBDataProviderSvc_t m_robDataProviderSvc
Reference to the ROBDataProviderSvc service.
Definition: TrigMuonRoITool.h:36
MuCTPI_MultiplicityWord_Decoder
Class helping to decode the MuCTPI multiplicity words.
Definition: MuCTPI_MultiplicityWord_Decoder.h:32
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
MuCTPI_DataWord_Decoder.h
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
MuCTPI_MultiplicityWord_Decoder::getNCandidates
uint16_t getNCandidates() const
Function returning the total number of muon candidates.
Definition: MuCTPI_MultiplicityWord_Decoder.cxx:42
bcId
uint16_t bcId(uint32_t data)
Definition: TgcByteStreamData.h:326
MuCTPI_MultiplicityWord_Decoder::dumpData
void dumpData() const
Function dumping the stored information to the message stream.
Definition: MuCTPI_MultiplicityWord_Decoder.cxx:88
ROIB::MuCTPIRoI::getSectorAddress
unsigned int getSectorAddress() const
Method returning the "electronics address" of the candidate.
Definition: MuCTPIRoI.cxx:66
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MuCTPI_Bits.h
ROIB::MuCTPIRoI::pt
unsigned int pt() const
Method returning the pT of the RoI candidate.
Definition: MuCTPIRoI.cxx:52
MuCTPI_DataWord_Decoder
Class helping to decode the MuCTPI data words.
Definition: MuCTPI_DataWord_Decoder.h:37
MuCTPI_RDO.h
MuCTPI_RDO
Class representing the readout data of the MuCTPI hardware and simulation.
Definition: MuCTPI_RDO.h:41
TrigMuonRoITool::m_decodeMuCTPiFromROB
bool m_decodeMuCTPiFromROB
Configurable to decide how to decode muCTPi.
Definition: TrigMuonRoITool.h:54
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
TriggerTest.rois
rois
Definition: TriggerTest.py:23
MuCTPI_MultiplicityWord_Decoder::getBCID
uint16_t getBCID() const
Function returning the 3-bit BCID fragment in the multiplicity word.
Definition: MuCTPI_MultiplicityWord_Decoder.cxx:78
ROIB::MuCTPIRoI::getOverlapBits
uint16_t getOverlapBits() const
Method returning the "overlap bits" of the candidate.
Definition: MuCTPIRoI.cxx:153
merge.status
status
Definition: merge.py:17
TrigMuonRoITool.h
TrigMuonRoITool::dumpRoIBDataWord
void dumpRoIBDataWord(uint32_t data_word) const
Helper to print contents of a muCTPi RoIB data word.
Definition: TrigMuonRoITool.cxx:219
ROIB::MuCTPIRoI::getSectorID
uint16_t getSectorID() const
Method returning the number of the trigger sector producing the candidate.
Definition: MuCTPIRoI.cxx:200
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
MuCTPI_RDO::dataWord
const std::vector< uint32_t > & dataWord() const
Function returning the muon candidate data words.
Definition: MuCTPI_RDO.h:141
ROIB::MuCTPIRoI::getSectorOverflow
uint16_t getSectorOverflow() const
Method telling whether there were more than two candidates in this candidate's sector.
Definition: MuCTPIRoI.cxx:87