14#include "MuCalDecode/CalibEvent.h"
15#include "MuCalDecode/CalibUti.h"
21 const std::string& name,
22 const IInterface* parent):
41 return StatusCode::SUCCESS;
64 << name <<
" buffer size=" << calBufferSize);
67 ATH_MSG_INFO(
"Opening muon calibration stream. Buffer name: "
68 << name <<
" buffer size: " << calBufferSize);
71 return StatusCode::SUCCESS;
92 return StatusCode::SUCCESS;
111 std::vector<uint32_t>& localBuffer,
113 const EventContext& ctx)
const
119 unsigned int totalHits = mdtHits.size()+rpcHits.size()+tgcHits.size();
120 if ( totalHits > 500 ) {
122 return StatusCode::SUCCESS;
128 return StatusCode::FAILURE;
137 uint32_t runId = ctx.eventID().run_number();
138 uint32_t lvl1Id = eventInfo->extendedLevel1ID();
142 float eta = (float) track.etaVtx;
143 float phi = (float) track.phiVtx;
144 float pt = (float) track.pt;
146 uint32_t mrods[4] = {0, 0, 0, 0};
148 std::vector<uint32_t> robIdList_MDT;
149 double etaMin = roi->
eta()-0.05;
150 double etaMax = roi->
eta()+0.05;
151 double phi_roi = roi->
phi();
152 double phiMin = roi->
phi()-0.05;
153 double phiMax = roi->
phi()+0.05;
154 if( phi_roi < 0 ) phi_roi += 2*
M_PI;
155 if( phiMin < 0 ) phiMin += 2*
M_PI;
156 if( phiMax < 0 ) phiMax += 2*
M_PI;
161 m_regSel_MDT->lookup( ctx )->ROBIDList(*iroi,robIdList_MDT);
164 ATH_MSG_DEBUG(
"Size of the MDT rob list: " << robIdList_MDT.size());
165 int isize = robIdList_MDT.size()<5 ? robIdList_MDT.size() : 4;
166 for (
int ii = 0 ; ii<isize ; ++ii ) {
167 ATH_MSG_DEBUG(
"robId: 0x" << std::hex << robIdList_MDT.at(ii) << std::dec);
168 mrods[ii] = robIdList_MDT.at(ii);
172 std::vector<uint32_t> robIdList_TGC;
173 m_regSel_TGC->lookup(ctx)->ROBIDList(*iroi,robIdList_TGC);
174 ATH_MSG_DEBUG(
"Size of the TGC rob list: " << robIdList_TGC.size());
177 LVL2_MUON_CALIBRATION::CalibEvent event(1,runId,lvl1Id,1,1,mrods,name().c_str(),
eta,
phi,pt);
178 LVL2_MUON_CALIBRATION::MdtCalibFragment mdtFragment;
181 if ( mdtHits.size()>0 ) {
185 event << mdtFragment;
189 return StatusCode::SUCCESS;
193 if ( rpcHits.size() > 0 ) {
194 LVL2_MUON_CALIBRATION::RpcCalibFragment rpcFragment;
197 ATH_MSG_WARNING(
"Could not create the Rpc fragment of the calibration stream");
200 ATH_MSG_DEBUG(
"Adding the RPC fragment to the calibration stream");
201 event << rpcFragment;
205 if ( tgcHits.size() > 0 ) {
206 LVL2_MUON_CALIBRATION::TgcCalibFragment tgcFragment;
208 if (
createTgcFragment(robIdList_TGC, tgcFragment, ctx) != StatusCode::SUCCESS ) {
209 ATH_MSG_ERROR(
"Could not create the Tgc fragment of the calibration stream");
212 ATH_MSG_DEBUG(
"Adding the TGC fragment to the calibration stream");
213 event << tgcFragment;
223 m_circ->dumpToCirc (event);
227 if (doDataScouting) {
229 uint16_t eventSize_ds =
event.size();
230 if (eventSize_ds>1000)
return StatusCode::SUCCESS;
232 std::unique_ptr<uint8_t[]> buff_ds = std::make_unique<uint8_t[]>(eventSize_ds);
235 uint16_t eventSize8bits = eventSize_ds;
236 uint16_t eventSize32bits = eventSize8bits/4;
237 event.dumpWords(buff_ds.get(),eventSize_ds);
242 ATH_MSG_DEBUG(
"Size of the DATASCOUTING buffer in 32 bits words: " << eventSize32bits);
243 for ( uint16_t words = 0 ; words != eventSize32bits ; words++) {
244 uint32_t byte1 = buff_ds[words*4];
245 uint32_t byte2 = buff_ds[words*4 + 1];
246 uint32_t byte3 = buff_ds[words*4 + 2];
247 uint32_t byte4 = buff_ds[words*4 + 3];
250 uint32_t dataWord = (byte4 << 24) + (byte3 << 16) + (byte2 << 8) + byte1 ;
252 ATH_MSG_DEBUG(
"Data word " << words <<
" = " << std::hex <<
"0x" << dataWord << std::dec);
254 localBuffer.push_back(dataWord);
260 return StatusCode::SUCCESS;
267 LVL2_MUON_CALIBRATION::MdtCalibFragment& mdtFragment,
268 float trackPhi)
const
271 TrigL2MuonSA::MdtHits::const_iterator it = mdtHits.begin();
272 for ( ; it != mdtHits.end() ; ++it ) {
274 int stationName = (*it).name;
275 int stationEta = (*it).StationEta;
276 int stationPhi = (*it).StationPhi;
277 int multilayer = (*it).Multilayer;
278 int layer = (*it).TubeLayer;
279 int tube = (*it).Tube;
281 uint32_t
ID = LVL2_MUON_CALIBRATION::MdtIdIntoWord(stationName,
282 stationEta,stationPhi,multilayer,layer,tube);
284 uint16_t leadingCoarseTime = (*it).LeadingCoarseTime;
285 uint16_t leadingFineTime = (*it).LeadingFineTime;
286 uint16_t trailingCoarseTime = (*it).TrailingCoarseTime;
287 uint16_t trailingFineTime = (*it).TrailingFineTime;
288 uint16_t adc = (*it).Adc;
290 LVL2_MUON_CALIBRATION::MdtCalibData mdt(
ID,leadingCoarseTime,leadingFineTime,
291 trailingCoarseTime,trailingFineTime,adc
300 return StatusCode::SUCCESS;
309 LVL2_MUON_CALIBRATION::RpcCalibFragment& rpcFragment,
const EventContext& ctx)
const
314 if ( roi->
getSource() != 0 )
return StatusCode::SUCCESS;
321 unsigned int roiNumber = roi->
getRoI();
329 unsigned int padIdHash;
333 if( itPad==
nullptr ) {
335 return StatusCode::FAILURE;
337 const RpcPad* rpcPad = itPad;
339 uint16_t sector = rpcPad->
sector();
340 uint16_t sysId = (sector<32)? 0x66 : 0x65;
341 uint16_t secId = sector%32;
342 uint16_t padId = rpcPad->
onlineId();
343 uint16_t status = rpcPad->
status();
346 LVL2_MUON_CALIBRATION::RpcCalibFragment frag(sysId,secId,padId,status,
error);
349 for (; it3!=rpcPad->
end() ; ++it3) {
353 uint16_t fel1Id = cma->
fel1Id();
354 uint16_t febcId = cma->
febcId();
355 uint16_t crc = cma->
crc();
357 LVL2_MUON_CALIBRATION::RpcCalibData matrix(cmaId,fel1Id,febcId,crc);
361 for (; it5 != (*it3)->end() ; ++it5) {
364 uint16_t bcid = fChannel->
bcid();
365 uint16_t time = fChannel->
time();
366 uint16_t ijk = fChannel->
ijk();
367 uint16_t channel = fChannel->
channel();
368 uint16_t ovl = fChannel->
ovl();
369 uint16_t thr = fChannel->
thr();
371 if(ijk!=7) matrix.getHit(bcid,time,ijk,channel);
372 else matrix.getHit(bcid,time,ijk,ovl,thr);
376 rpcFragment << matrix;
381 ATH_MSG_WARNING(
"Can't get the pad address from the RpcCablingCondData");
382 return StatusCode::FAILURE;
385 return StatusCode::SUCCESS;
394 LVL2_MUON_CALIBRATION::TgcCalibFragment& tgcFragment,
395 const EventContext& ctx)
const
399 if ( robIdList_TGC.size()<1 ) {
401 return StatusCode::SUCCESS;
405 uint16_t systemId = 1;
407 uint16_t subSystemId = ( (robIdList_TGC.at(0) & 0xff0000) >> 16 );
408 uint16_t rdoId = ( robIdList_TGC.at(0) & 0xff );
410 uint16_t roiNumber = 0;
412 tgcFragment = LVL2_MUON_CALIBRATION::TgcCalibFragment(systemId,subSystemId,rdoId,roiNumber);
418 return StatusCode::FAILURE;
426 LVL2_MUON_CALIBRATION::TgcCalibData tgc_payload;
429 for ( ; it != tgcRdoContainer->
end() ; ++it ) {
437 for ( ; itRaw != (*it)->end() ; ++itRaw ) {
440 LVL2_MUON_CALIBRATION::TGC_BYTESTREAM_READOUTHIT roh;
441 LVL2_MUON_CALIBRATION::TGC_BYTESTREAM_READOUTTRIPLETSTRIP tps;
442 LVL2_MUON_CALIBRATION::TGC_BYTESTREAM_READOUTTRACKLET rot;
443 LVL2_MUON_CALIBRATION::TGC_BYTESTREAM_HIPT hpt;
444 LVL2_MUON_CALIBRATION::TGC_BYTESTREAM_SL sl;
447 switch (raw->
type()) {
450 roh.channel = raw->
channel()-40;
451 roh.sbId = raw->
slbId();
454 roh.ldbId = raw->
sswId();
466 tps.sbId = raw->
slbId();
467 tps.ldbId = raw->
sswId();
477 rot.delta = raw->
delta();
478 rot.sbId = raw->
slbId();
479 rot.ldbId = raw->
sswId();
489 hpt.delta = raw->
delta();
490 hpt.hitId = raw->
hitId();
492 hpt.cand = raw->
index();
493 hpt.chip = raw->
chip();
494 hpt.sector = raw->
sector();
506 sl.cand = raw->
index();
507 sl.sector = raw->
sector();
516 return StatusCode::FAILURE;
520 tgc_payload.getHit(roh,tps,rot,hpt,sl);
525 tgcFragment << tgc_payload;
527 return StatusCode::SUCCESS;
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
std::vector< Identifier > ID
unsigned bcBitmap(uint16_t bcTag)
DataModel_detail::const_iterator< DataVector > const_iterator
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Describes the API of the Region of Ineterest geometry.
const_iterator end() const
return const_iterator for end of container
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
const_iterator begin() const
return const_iterator for first entry
bool give_PAD_address(unsigned short int SubsystemId, unsigned short int SectorId, unsigned short int RoIId, unsigned int &padIdHash) const
Use IdentifiableContainer with RpcPad.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
An unit object of TGC ROD output.
uint16_t position() const
uint16_t subMatrix() const
uint16_t tracklet() const
uint16_t threshold() const
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
float eta() const
The pseudorapidity ( ) of the muon candidate.
Hemisphere getHemisphere() const
Returns the hemisphere that detected the muon candidate.
RoISource getSource() const
Returns the system that detected the muon candidate.
float phi() const
The azimuthal angle ( ) of the muon candidate.
int getSectorID() const
Get the sector ID number.
@ Positive
The candidate came from the +z side (side A)
int getRoI() const
Get the "RoI number" (position inside the sector)
std::vector< MdtHitData > MdtHits
std::vector< RpcHitData > RpcHits
std::vector< TgcHitData > TgcHits