Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMTF three fixes to unpacking and emulation bugs #23136

Merged
merged 6 commits into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion DataFormats/L1TMuon/interface/EMTF/EventHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace l1t {
EventHeader() :
l1a(-99), l1a_BXN(-99), sp_TS(-99), endcap(-99), sector(-99), sp_ersv(-99), sp_addr(-99),
tbin(-99), ddm(-99), spa(-99), rpca(-99), skip(-99), rdy(-99), bsy(-99), osy(-99),
wof(-99), me1a(-99), me1b(-99), me2(-99), me3(-99), me4(-99), format_errors(0), dataword(-99)
wof(-99), me1a(-99), me1b(-99), me2(-99), me3(-99), me4(-99),
cppf(-99), cppf_crc(-99), format_errors(0), dataword(-99)
{};

virtual ~EventHeader() {};
Expand All @@ -41,6 +42,8 @@ namespace l1t {
void set_me2(int bits) { me2 = bits; }
void set_me3(int bits) { me3 = bits; }
void set_me4(int bits) { me4 = bits; }
void set_cppf(int bits) { cppf = bits; }
void set_cppf_crc(int bits) { cppf_crc = bits; }
void add_format_error() { format_errors += 1; }
void set_dataword(uint64_t bits) { dataword = bits; }

Expand All @@ -65,6 +68,8 @@ namespace l1t {
int ME2() const { return me2; }
int ME3() const { return me3; }
int ME4() const { return me4; }
int CPPF() const { return cppf; }
int CPPF_CRC() const { return cppf_crc; }
int Format_errors() const { return format_errors; }
uint64_t Dataword() const { return dataword; }

Expand All @@ -90,6 +95,8 @@ namespace l1t {
int me2;
int me3;
int me4;
int cppf;
int cppf_crc;
int format_errors;
uint64_t dataword;

Expand Down
10 changes: 9 additions & 1 deletion EventFilter/L1TRawToDigi/interface/Unpacker.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ namespace l1t {

class Unpacker {
public:
virtual bool unpack(const Block& block, UnpackerCollections *coll) = 0;
Unpacker() : algoVersion_(0) {};
virtual ~Unpacker() = default;
virtual bool unpack(const Block& block, UnpackerCollections *coll) = 0;

// Modeled on plugins/implementations_stage2/MuonUnpacker.h
inline unsigned int getAlgoVersion() { return algoVersion_; };
inline void setAlgoVersion(const unsigned int version) { algoVersion_ = version; };

private:
unsigned int algoVersion_;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,15 @@ namespace l1t {
if(GetHexBits(HD1a, 12, 15) != 9) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD1a are incorrect"; }
if(GetHexBits(HD1b, 12, 15) != 9) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD1b are incorrect"; }
if(GetHexBits(HD1c, 12, 15) != 9) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD1c are incorrect"; }
if(GetHexBits(HD1c, 0, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD1c are incorrect"; }
if(GetHexBits(HD1d, 12, 15) != 9) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD1d are incorrect"; }
if(GetHexBits(HD2a, 12, 15) != 10) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2a are incorrect"; }
if(GetHexBits(HD2a, 0, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2a are incorrect"; }
if(GetHexBits(HD2b, 12, 15) != 10) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2b are incorrect"; }
if(GetHexBits(HD2c, 12, 15) != 10) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2c are incorrect"; }
if(GetHexBits(HD2c, 11, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2c are incorrect"; }
if(GetHexBits(HD2d, 12, 15) != 10) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2d are incorrect"; }
if(GetHexBits(HD3a, 9, 14) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3a are incorrect"; }
if(GetHexBits(HD3a, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3a are incorrect"; }
if(GetHexBits(HD3b, 11, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3b are incorrect"; }
if(GetHexBits(HD3c, 11, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3c are incorrect"; }
if(GetHexBits(HD3d, 11, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3d are incorrect"; }
if(GetHexBits(HD3b, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3b are incorrect"; }
if(GetHexBits(HD3c, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3c are incorrect"; }
if(GetHexBits(HD3d, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3d are incorrect"; }

return errors;

Expand Down Expand Up @@ -203,6 +199,8 @@ namespace l1t {
EventHeader_.set_me2 ( GetHexBits(HD3b, 0, 10) );
EventHeader_.set_me3 ( GetHexBits(HD3c, 0, 10) );
EventHeader_.set_me4 ( GetHexBits(HD3d, 0, 10) );
EventHeader_.set_cppf ( GetHexBits(HD3a, 11, 14, HD3b, 11, 13) );
EventHeader_.set_cppf_crc( GetHexBits(HD3c, 11, 14, HD3d, 11, 13) );
// EventHeader_.set_dataword(uint64_t bits) { dataword = bits; };

write_Event:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ namespace l1t {
}

// Converts station, CSC_ID, sector, subsector, and neighbor from the ME output
std::vector<int> convert_ME_location(int _station, int _csc_ID, int _sector) {
std::vector<int> convert_ME_location(int _station, int _csc_ID, int _sector, bool _csc_ID_shift = false) {
int new_sector = _sector;
int new_csc_ID = _csc_ID; // Before FW update on 05.05.16, shift by +1 from 0,1,2... convention to 1,2,3...
int new_csc_ID = _csc_ID;
if (_csc_ID_shift) new_csc_ID += 1; // Before FW update on 05.05.16, shift by +1 from 0,1,2... convention to 1,2,3...
if (_station == 0) { int arr[] = { 1, new_csc_ID, new_sector, 1, 0}; std::vector<int> vec(arr, arr+5); return vec; }
else if (_station == 1) { int arr[] = { 1, new_csc_ID, new_sector, 2, 0}; std::vector<int> vec(arr, arr+5); return vec; }
else if (_station <= 4) { int arr[] = {_station, new_csc_ID, new_sector, -1, 0}; std::vector<int> vec(arr, arr+5); return vec; }
else if (_station == 5) new_sector = (_sector != 1) ? _sector-1 : 6;
else if (_station == 5) new_sector = (_sector != 1) ? _sector-1 : 6; // Indicates neighbor chamber, don't return yet
else { int arr[] = {_station, _csc_ID, _sector, -99, -99}; std::vector<int> vec(arr, arr+5); return vec; }

// Mapping for chambers from neighboring sector
if (new_csc_ID == 1) { int arr[] = {1, 3, new_sector, 2, 1}; std::vector<int> vec(arr, arr+5); return vec; }
else if (new_csc_ID == 2) { int arr[] = {1, 6, new_sector, 2, 1}; std::vector<int> vec(arr, arr+5); return vec; }
else if (new_csc_ID == 3) { int arr[] = {1, 9, new_sector, 2, 1}; std::vector<int> vec(arr, arr+5); return vec; }
Expand Down Expand Up @@ -150,14 +152,23 @@ namespace l1t {
// ME_.set_dataword ( uint64_t dataword);

// Convert specially-encoded ME quantities
std::vector<int> conv_vals = convert_ME_location( ME_.Station(), ME_.CSC_ID(),
(res->at(iOut)).PtrEventHeader()->Sector() );
bool csc_ID_shift = (getAlgoVersion() <= 8348); // For FW versions <= 28.04.2016, shift by +1 from 0,1,2... convention to 1,2,3...
// Computed as (Year - 2000)*2^9 + Month*2^5 + Day (see Block.cc and EMTFBlockTrailers.cc)
std::vector<int> conv_vals = convert_ME_location( ME_.Station(), ME_.CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), csc_ID_shift );

Hit_.set_station ( conv_vals.at(0) );
Hit_.set_csc_ID ( conv_vals.at(1) );
Hit_.set_sector ( conv_vals.at(2) );
Hit_.set_subsector ( conv_vals.at(3) );
Hit_.set_neighbor ( conv_vals.at(4) );

if (Hit_.Station() < 1 || Hit_.Station() > 4) edm::LogWarning("L1T|EMTF") << "EMTF unpacked LCT station = " << Hit_.Station()
<< ", outside proper [1, 4] range" << std::endl;
if (Hit_.CSC_ID() < 1 || Hit_.CSC_ID() > 9) edm::LogWarning("L1T|EMTF") << "EMTF unpacked LCT CSC ID = " << Hit_.CSC_ID()
<< ", outside proper [1, 9] range" << std::endl;
if (Hit_.Sector() < 1 || Hit_.Sector() > 6) edm::LogWarning("L1T|EMTF") << "EMTF unpacked LCT sector = " << Hit_.Sector()
<< ", outside proper [1, 6] range" << std::endl;

// Fill the EMTFHit
ImportME( Hit_, ME_, (res->at(iOut)).PtrEventHeader()->Endcap(), (res->at(iOut)).PtrEventHeader()->Sector() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace l1t {

// Check that each word is 16 bits
for (unsigned int i = 0; i < 4; i++) {
if (GetHexBits(payload[i], 16, 31) != 0) { errors += 1;
if (GetHexBits(payload[i], 16, 31) != 0) { errors += 1;
edm::LogError("L1T|EMTF") << "Payload[" << i << "] has more than 16 bits in 'RPC Data Record'"; }
}

Expand All @@ -52,17 +52,13 @@ namespace l1t {
uint16_t RPCd = payload[3];

// Check Format
if (GetHexBits(RPCa, 11, 15) != 0) { errors += 1;
if (GetHexBits(RPCa, 15, 15) != 0) { errors += 1;
edm::LogError("L1T|EMTF") << "Format identifier bits in RPCa are incorrect"; }
if (GetHexBits(RPCb, 5, 7) != 0) { errors += 1;
if (GetHexBits(RPCb, 15, 15) != 0) { errors += 1;
edm::LogError("L1T|EMTF") << "Format identifier bits in RPCb are incorrect"; }
if (GetHexBits(RPCb, 15, 15) != 0) { errors += 1;
edm::LogError("L1T|EMTF") << "Format identifier bits in RPCb are incorrect"; }
if (GetHexBits(RPCc, 12, 13) != 0) { errors += 1;
edm::LogError("L1T|EMTF") << "Format identifier bits in RPCc are incorrect"; }
if (GetHexBits(RPCc, 15, 15) != 1) { errors += 1;
if (GetHexBits(RPCc, 15, 15) != 1) { errors += 1;
edm::LogError("L1T|EMTF") << "Format identifier bits in RPCc are incorrect"; }
if (GetHexBits(RPCd, 4, 15) != 0) { errors += 1;
if (GetHexBits(RPCd, 15, 15) != 0) { errors += 1;
edm::LogError("L1T|EMTF") << "Format identifier bits in RPCd are incorrect"; }

return errors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ namespace l1t {
//Check Format
if(GetHexBits(TR1a, 12, 15) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1a are incorrect"; }
if(GetHexBits(TR1b, 12, 15) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1b are incorrect"; }
if(GetHexBits(TR1b, 0, 3) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1b are incorrect"; }
if(GetHexBits(TR1b, 4, 6) != 7) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1b are incorrect"; }
if(GetHexBits(TR1c, 9, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1c are incorrect"; }
// FIXME: we are consistently reading GetHexBits(TR1c, 12, 15) == 14 - AWB 10.02.16
// if(GetHexBits(TR1c, 12, 15) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1c are incorrect"; }
if(GetHexBits(TR1c, 12, 15) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1c are incorrect"; }
if(GetHexBits(TR1d, 12, 15) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1d are incorrect"; }
// FIXME: we are consistently reading GetHexBits(TR2a, 5, 11) == 18 - AWB 10.02.16
// if(GetHexBits(TR2a, 5, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR2a are incorrect"; }
if(GetHexBits(TR2a, 12, 15) != 14) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR2a are incorrect"; }
if(GetHexBits(TR2b, 12, 15) != 14) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR2b are incorrect"; }
if(GetHexBits(TR2c, 12, 15) != 14) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR2c are incorrect"; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ namespace l1t {

auto emtf_headers_unp = UnpackerFactory::get()->make("stage2::emtf::HeadersBlockUnpacker"); // Unpack "AMC data header" and "Event Record Header"
auto emtf_counters_unp = UnpackerFactory::get()->make("stage2::emtf::CountersBlockUnpacker"); // Unpack "Block of Counters"
auto emtf_me_unp = UnpackerFactory::get()->make("stage2::emtf::MEBlockUnpacker"); // Unpack "ME Data Record"
auto emtf_rpc_unp = UnpackerFactory::get()->make("stage2::emtf::RPCBlockUnpacker"); // // Unpack "RPC Data Record"
auto emtf_sp_unp = UnpackerFactory::get()->make("stage2::emtf::SPBlockUnpacker"); // Unpack "SP Output Data Record"
auto emtf_me_unp = UnpackerFactory::get()->make("stage2::emtf::MEBlockUnpacker"); // Unpack "ME Data Record"
auto emtf_rpc_unp = UnpackerFactory::get()->make("stage2::emtf::RPCBlockUnpacker"); // Unpack "RPC Data Record"
auto emtf_sp_unp = UnpackerFactory::get()->make("stage2::emtf::SPBlockUnpacker"); // Unpack "SP Output Data Record"
auto emtf_trailers_unp = UnpackerFactory::get()->make("stage2::emtf::TrailersBlockUnpacker"); // Unpack "Event Record Trailer"

emtf_me_unp->setAlgoVersion(fw); // Currently only the CSC LCT unpacking needs the firmware version, can add others as needed - AWB 09.04.18

// Index of res is block->header().getID(), matching block_patterns_ in src/Block.cc
res[511] = emtf_headers_unp;
res[2] = emtf_counters_unp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace l1t {
namespace stage2 {
IntermediateMuonUnpacker::IntermediateMuonUnpacker() : res1_(nullptr), res2_(nullptr), algoVersion_(0), coll1Cnt_(0)
IntermediateMuonUnpacker::IntermediateMuonUnpacker() : res1_(nullptr), res2_(nullptr), coll1Cnt_(0)
{
}

Expand Down Expand Up @@ -126,7 +126,7 @@ namespace l1t {
// The intermediate muons of the uGMT (FED number 1402) do not
// have coordinates estimated at the vertex in the RAW data.
// The corresponding bits are set to zero.
MuonRawDigiTranslator::fillMuon(mu, raw_data_00_31, raw_data_32_63, 1402, algoVersion_);
MuonRawDigiTranslator::fillMuon(mu, raw_data_00_31, raw_data_32_63, 1402, getAlgoVersion());

LogDebug("L1T") << "Mu" << nWord/2 << ": eta " << mu.hwEta() << " phi " << mu.hwPhi() << " pT " << mu.hwPt() << " iso " << mu.hwIso() << " qual " << mu.hwQual() << " charge " << mu.hwCharge() << " charge valid " << mu.hwChargeValid();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ namespace l1t {

bool unpack(const Block& block, UnpackerCollections *coll) override;

inline unsigned int getAlgoVersion() { return algoVersion_; };
inline void setAlgoVersion(const unsigned int version) { algoVersion_ = version; };

private:
static constexpr unsigned nWords_ = 6; // every link transmits 6 words (3 muons) per bx
static constexpr unsigned bxzs_enable_shift_ = 1;

MuonBxCollection* res1_;
MuonBxCollection* res2_;
unsigned int algoVersion_;
unsigned int coll1Cnt_;

void unpackBx(int bx, const std::vector<uint32_t>& payload, unsigned int startIdx=0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace l1t {
namespace stage2 {
MuonUnpacker::MuonUnpacker() : res_(nullptr), algoVersion_(0), muonCopy_(0)
MuonUnpacker::MuonUnpacker() : res_(nullptr), muonCopy_(0)
{
}

Expand Down Expand Up @@ -74,7 +74,7 @@ namespace l1t {

Muon mu;

MuonRawDigiTranslator::fillMuon(mu, raw_data_00_31, raw_data_32_63, fed_, algoVersion_);
MuonRawDigiTranslator::fillMuon(mu, raw_data_00_31, raw_data_32_63, fed_, getAlgoVersion());

LogDebug("L1T") << "Mu" << nWord/2 << ": eta " << mu.hwEta() << " phi " << mu.hwPhi() << " pT " << mu.hwPt() << " iso " << mu.hwIso() << " qual " << mu.hwQual() << " charge " << mu.hwCharge() << " charge valid " << mu.hwChargeValid();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ namespace l1t {

bool unpack(const Block& block, UnpackerCollections *coll) override;

inline unsigned int getAlgoVersion() { return algoVersion_; };
inline int getFedNumber() { return fed_; };
inline unsigned int getMuonCopy() { return muonCopy_; };

inline void setAlgoVersion(const unsigned int version) { algoVersion_ = version; };
inline void setFedNumber(const int fed) { fed_ = fed; };
inline void setMuonCopy(const unsigned int copy) { muonCopy_ = copy; };

Expand All @@ -27,7 +25,6 @@ namespace l1t {
static constexpr unsigned bxzs_enable_shift_ = 1;

MuonBxCollection* res_;
unsigned int algoVersion_;
int fed_;
unsigned int muonCopy_;

Expand Down
37 changes: 26 additions & 11 deletions EventFilter/L1TRawToDigi/src/Block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,38 @@ namespace l1t {
if (end16 - data16 < header_size + counter_size + trailer_size) {
edm::LogError("L1T") << "MTF7 payload smaller than allowed!";
data_ = end_;
} else if (
((data16[0] >> 12) != 0x9) || ((data16[1] >> 12) != 0x9) ||
((data16[2] >> 12) != 0x9) || ((data16[3] >> 12) != 0x9) ||
((data16[4] >> 12) != 0xA) || ((data16[5] >> 12) != 0xA) ||
((data16[6] >> 12) != 0xA) || ((data16[7] >> 12) != 0xA) ||
((data16[8] >> 9) != 0b1000000) || ((data16[9] >> 11) != 0) ||
((data16[10] >> 11) != 0) || ((data16[11] >> 11) != 0)) {
} else if ( // Check bits for EMTF Event Record Header
((data16[0] >> 12) != 0x9) || ((data16[1] >> 12) != 0x9) ||
((data16[2] >> 12) != 0x9) || ((data16[3] >> 12) != 0x9) ||
((data16[4] >> 12) != 0xA) || ((data16[5] >> 12) != 0xA) ||
((data16[6] >> 12) != 0xA) || ((data16[7] >> 12) != 0xA) ||
((data16[8] >> 15) != 0x1) || ((data16[9] >> 15) != 0x0) ||
((data16[10] >> 15) != 0x0) || ((data16[11] >> 15) != 0x0)) {
edm::LogError("L1T") << "MTF7 payload has invalid header!";
data_ = end_;
} else if (
} else if ( // Check bits for EMTF MPC Link Errors
((data16[12] >> 15) != 0) || ((data16[13] >> 15) != 1) ||
((data16[14] >> 15) != 0) || ((data16[15] >> 15) != 0)) {
edm::LogError("L1T") << "MTF7 payload has invalid counter block!";
data_ = end_;
} else if (
false) {
// TODO: check trailer
}

// Check bits for EMTF Event Record Trailer, get firmware version
algo_ = 0; // Firmware version
for (int i = 4; i < 1590; i++) { // Start after Counters block, up to 108 ME / 84 RPC / 3 SP blocks per BX, 8 BX
if ( ((data16[4*i+0] >> 12) == 0xF) && ((data16[4*i+1] >> 12) == 0xF) &&
((data16[4*i+2] >> 12) == 0xF) && ((data16[4*i+3] >> 12) == 0xF) &&
((data16[4*i+4] >> 12) == 0xE) && ((data16[4*i+5] >> 12) == 0xE) &&
((data16[4*i+6] >> 12) == 0xE) && ((data16[4*i+7] >> 12) == 0xE) ) { // Indicators for the Trailer block
algo_ = (((data16[4*i+2] >> 4) & 0x3F) << 9); // Year (6 bits)
algo_ |= (((data16[4*i+2] >> 0) & 0x0F) << 5); // Month (4 bits)
algo_ |= (((data16[4*i+4] >> 0) & 0x1F) << 0); // Day (5 bits)
break;
}
}
if (algo_ == 0) {
edm::LogError("L1T") << "MTF7 payload has no valid EMTF firmware version!";
data_ = end_;
}
}

Expand Down