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

Improve L1MuGMTMatrix #27538

Merged
merged 2 commits into from Jul 24, 2019
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: 5 additions & 4 deletions L1Trigger/GlobalMuonTrigger/src/L1MuGMTDebugBlock.cc
Expand Up @@ -40,8 +40,9 @@ L1MuGMTDebugBlock::L1MuGMTDebugBlock(int minbx, int maxbx)
_phisel(maxbx - minbx + 1, std::vector<unsigned>(32, 0)),
_etasel(maxbx - minbx + 1, std::vector<unsigned>(32, 0)),
_isMIPISO(maxbx - minbx + 1, std::vector<unsigned>(32, 0)),
_pairMatrices(maxbx - minbx + 1, std::vector<L1MuGMTMatrix<bool> >(NumMatrices, L1MuGMTMatrix<bool>(4, 4))),
_mqMatrices(maxbx - minbx + 1, std::vector<L1MuGMTMatrix<int> >(NumMatrices, L1MuGMTMatrix<int>(4, 4))),
_pairMatrices(maxbx - minbx + 1,
std::vector<L1MuGMTMatrix<bool> >(NumMatrices, L1MuGMTMatrix<bool>(4, 4, false))),
_mqMatrices(maxbx - minbx + 1, std::vector<L1MuGMTMatrix<int> >(NumMatrices, L1MuGMTMatrix<int>(4, 4, 0))),
_cancelbits(maxbx - minbx + 1, std::vector<unsigned>(4)),
_brlmuons(maxbx - minbx + 1, std::vector<L1MuGMTExtendedCand>(4)),
_fwdmuons(maxbx - minbx + 1, std::vector<L1MuGMTExtendedCand>(4))
Expand Down Expand Up @@ -107,8 +108,8 @@ void L1MuGMTDebugBlock::reset() {
_isMIPISO[bx][i] = 0;
}
for (int i = 0; i < NumMatrices; i++) {
_pairMatrices[bx][i].init(false);
_mqMatrices[bx][i].init(0);
_pairMatrices[bx][i].reset(false);
_mqMatrices[bx][i].reset(0);
}
for (int i = 0; i < 4; i++) {
_brlmuons[bx][i].reset();
Expand Down
16 changes: 9 additions & 7 deletions L1Trigger/GlobalMuonTrigger/src/L1MuGMTInputEvent.cc
Expand Up @@ -33,7 +33,13 @@
//----------------
// Constructors --
//----------------
L1MuGMTInputEvent::L1MuGMTInputEvent() : m_runnr(0L), m_evtnr(0L), m_mip_bits(14, 18), m_iso_bits(14, 18) {
L1MuGMTInputEvent::L1MuGMTInputEvent()
: m_runnr(0L),
m_evtnr(0L),
m_mip_bits(14, 18, false),
m_iso_bits(14, 18, true) //this is more useful when reading a standalone input file
//since "not-quiet" bits are stored there
{
std::vector<L1MuRegionalCand> empty_vec;
m_inputmuons["INC"] = empty_vec;
m_inputmuons["IND"] = empty_vec;
Expand All @@ -48,10 +54,6 @@ L1MuGMTInputEvent::L1MuGMTInputEvent() : m_runnr(0L), m_evtnr(0L), m_mip_bits(14
m_inputmuons["IND"].reserve(4);
m_inputmuons["INB"].reserve(4);
m_inputmuons["INF"].reserve(4);

m_mip_bits.init(false);
m_iso_bits.init(true); //this is more useful when reading a standalone input file
//since "not-quiet" bits are stored there
}

//--------------
Expand All @@ -77,8 +79,8 @@ void L1MuGMTInputEvent::reset() {
it->second.clear();
}

m_mip_bits.init(false);
m_iso_bits.init(true); //see CTOR for info on this
m_mip_bits.reset(false);
m_iso_bits.reset(true); //see CTOR for info on this
}

const L1MuRegionalCand* L1MuGMTInputEvent::getInputMuon(std::string chipid, unsigned index) const {
Expand Down
14 changes: 6 additions & 8 deletions L1Trigger/GlobalMuonTrigger/src/L1MuGMTMatcher.cc
Expand Up @@ -62,8 +62,8 @@ L1MuGMTMatcher::L1MuGMTMatcher(const L1MuGlobalMuonTrigger& gmt, int id)
m_id(id),
first(MaxMatch),
second(MaxMatch),
matchQuality(MaxMatch, MaxMatch),
pairMatrix(MaxMatch, MaxMatch) {
matchQuality(MaxMatch, MaxMatch, 0),
pairMatrix(MaxMatch, MaxMatch, false) {
first.reserve(MaxMatch);
second.reserve(MaxMatch);
}
Expand All @@ -89,8 +89,8 @@ void L1MuGMTMatcher::run() {
// clear Matcher
//
void L1MuGMTMatcher::reset() {
matchQuality.init(0);
pairMatrix.init(false);
matchQuality.reset(0);
pairMatrix.reset(false);

for (unsigned i = 0; i < MaxMatch; i++) {
first[i] = nullptr;
Expand Down Expand Up @@ -183,10 +183,8 @@ void L1MuGMTMatcher::load() {
// match muons
//
void L1MuGMTMatcher::match() {
L1MuGMTMatrix<bool> maxMatrix(MaxMatch, MaxMatch);
L1MuGMTMatrix<bool> disableMatrix(MaxMatch, MaxMatch);
maxMatrix.init(false);
disableMatrix.init(false);
L1MuGMTMatrix<bool> maxMatrix(MaxMatch, MaxMatch, false);
L1MuGMTMatrix<bool> disableMatrix(MaxMatch, MaxMatch, false);

// loop over all combinations

Expand Down
108 changes: 43 additions & 65 deletions L1Trigger/GlobalMuonTrigger/src/L1MuGMTMatrix.h
Expand Up @@ -25,6 +25,7 @@
#include <cassert>
#include <string>
#include <sstream>
#include <memory>

//----------------------
// Base Class Headers --
Expand All @@ -44,22 +45,24 @@ template <class T>
class L1MuGMTMatrix {
public:
/// constructor
L1MuGMTMatrix(int r, int c);
L1MuGMTMatrix(int r, int c, T v);

/// copy constructor
L1MuGMTMatrix(const L1MuGMTMatrix<T>&);

L1MuGMTMatrix(L1MuGMTMatrix<T>&&) = default;

/// destructor
virtual ~L1MuGMTMatrix();
virtual ~L1MuGMTMatrix() = default;

///
T& operator()(int r, int c);

///
const T& operator()(int r, int c) const;

/// initialize matrix
void init(T v = 0);
/// reset all elements
void reset(T v);

/// set matrix element
void set(int r, int c, T v);
Expand Down Expand Up @@ -92,49 +95,30 @@ class L1MuGMTMatrix {
void print() const;

private:
T& get(int r, int c) { return p_[r * c_size + c]; }

T const& get(int r, int c) const { return p_[r * c_size + c]; }

int r_size, c_size;

T** p;
std::unique_ptr<T[]> p_;
};

template <class T>
L1MuGMTMatrix<T>::L1MuGMTMatrix(int r, int c) : r_size(r), c_size(c) {
p = new T*[r];

assert(p != nullptr);

for (int i = 0; i < r; i++) {
p[i] = new T[c];
assert(p[i] != nullptr);
L1MuGMTMatrix<T>::L1MuGMTMatrix(int r, int c, T v) : r_size(r), c_size(c), p_(new T[r * c]) {
for (int i = 0; i < r_size * c_size; ++i) {
p_[i] = v;
}
}

// copy constructor

template <class T>
L1MuGMTMatrix<T>::L1MuGMTMatrix(const L1MuGMTMatrix<T>& mat) : r_size(mat.r_size), c_size(mat.c_size) {
p = new T*[r_size];

assert(p != nullptr);

for (int i = 0; i < r_size; i++) {
p[i] = new T[c_size];
assert(p[i] != nullptr);
for (int j = 0; j < c_size; j++)
p[i][j] = mat.p[i][j];
}
}

//--------------
// Destructor --
//--------------
template <class T>
L1MuGMTMatrix<T>::~L1MuGMTMatrix() {
for (int i = 0; i < r_size; i++) {
delete[] p[i];
L1MuGMTMatrix<T>::L1MuGMTMatrix(const L1MuGMTMatrix<T>& mat)
: r_size(mat.r_size), c_size(mat.c_size), p_(new T[r_size * c_size]) {
for (int i = 0; i < r_size * c_size; ++i) {
p_[i] = mat.p_[i];
}

delete[] p;
}

//
Expand All @@ -144,7 +128,7 @@ template <class T>
T& L1MuGMTMatrix<T>::operator()(int r, int c) {
assert(r >= 0 && r < r_size && c >= 0 && c < c_size);

return p[r][c];
return get(r, c);
}

//
Expand All @@ -154,17 +138,16 @@ template <class T>
const T& L1MuGMTMatrix<T>::operator()(int r, int c) const {
assert(r >= 0 && r < r_size && c >= 0 && c < c_size);

return p[r][c];
return get(r, c);
}

//
// initialize matrix
// reset elements
//
template <class T>
void L1MuGMTMatrix<T>::init(T v) {
for (int r = 0; r < r_size; r++) {
for (int c = 0; c < c_size; c++)
p[r][c] = v;
void L1MuGMTMatrix<T>::reset(T v) {
for (int i = 0; i < r_size * c_size; ++i) {
p_[i] = v;
}
}

Expand All @@ -175,7 +158,7 @@ template <class T>
void L1MuGMTMatrix<T>::set(int r, int c, T v) {
assert(r >= 0 && r < r_size && c >= 0 && c < c_size);

p[r][c] = v;
get(r, c) = v;
}

//
Expand All @@ -186,9 +169,8 @@ L1MuGMTMatrix<T>& L1MuGMTMatrix<T>::operator=(const L1MuGMTMatrix& m) {
if (this != &m) {
assert(m.c_size == c_size && m.r_size == r_size);

for (int r = 0; r < r_size; r++) {
for (int c = 0; c < c_size; c++)
p[r][c] = m.p[r][c];
for (int i = 0; i < r_size * c_size; ++i) {
p_[i] = m.p_[i];
}
}

Expand All @@ -202,10 +184,8 @@ template <class T>
L1MuGMTMatrix<T>& L1MuGMTMatrix<T>::operator+=(const L1MuGMTMatrix& m) {
assert(m.c_size == c_size && m.r_size == r_size);

for (int r = 0; r < r_size; r++) {
for (int c = 0; c < c_size; c++) {
p[r][c] += m.p[r][c];
}
for (int i = 0; i < r_size * c_size; ++i) {
p_[i] += m.p_[i];
}

return *this;
Expand All @@ -216,9 +196,8 @@ L1MuGMTMatrix<T>& L1MuGMTMatrix<T>::operator+=(const L1MuGMTMatrix& m) {
//
template <class T>
L1MuGMTMatrix<T>& L1MuGMTMatrix<T>::operator+=(const T& s) {
for (int r = 0; r < r_size; r++) {
for (int c = 0; c < c_size; c++)
p[r][c] += s;
for (int i = 0; i < r_size * c_size; ++i) {
p_[i] += s;
}

return *this;
Expand All @@ -229,9 +208,8 @@ L1MuGMTMatrix<T>& L1MuGMTMatrix<T>::operator+=(const T& s) {
//
template <class T>
L1MuGMTMatrix<T>& L1MuGMTMatrix<T>::operator*=(const T& s) {
for (int r = 0; r < r_size; r++) {
for (int c = 0; c < c_size; c++)
p[r][c] *= s;
for (int i = 0; i < r_size * c_size; ++i) {
p_[i] *= s;
}

return *this;
Expand All @@ -245,17 +223,17 @@ bool L1MuGMTMatrix<T>::isMax(int r, int c) const {
bool max = true;

for (int i = 0; i < c; i++) {
max = max && (this->p[r][c] > this->p[r][i]);
max = max && (this->get(r, c) > this->get(r, i));
}
for (int i = c + 1; i < c_size; i++) {
max = max && (this->p[r][c] >= this->p[r][i]);
max = max && (this->get(r, c) >= this->get(r, i));
}

for (int j = 0; j < r; j++) {
max = max && (this->p[r][c] > this->p[j][c]);
max = max && (this->get(r, c) > this->get(j, c));
}
for (int j = r + 1; j < r_size; j++) {
max = max && (this->p[r][c] >= this->p[j][c]);
max = max && (this->get(r, c) >= this->get(j, c));
}

return max;
Expand All @@ -268,10 +246,10 @@ template <class T>
bool L1MuGMTMatrix<T>::isMin(int r, int c) const {
bool min = true;
for (int i = 0; i < c_size; i++) {
min = min && (this->p[r][c] <= this->p[r][i]);
min = min && (this->get(r, c) <= this->get(r, i));
}
for (int j = 0; j < r_size; j++) {
min = min && (this->p[r][c] <= this->p[j][c]);
min = min && (this->get(r, c) <= this->get(j, c));
}

return min;
Expand All @@ -284,7 +262,7 @@ template <class T>
int L1MuGMTMatrix<T>::colAny(int c) const {
int stat = -1;
for (int i = 0; i < r_size; i++) {
if (this->p[i][c] > 0)
if (this->get(i, c) > 0)
stat = i;
}

Expand All @@ -298,7 +276,7 @@ template <class T>
int L1MuGMTMatrix<T>::rowAny(int r) const {
int stat = -1;
for (int i = 0; i < c_size; i++) {
if (this->p[r][i] > 0)
if (this->get(r, i) > 0)
stat = i;
}

Expand All @@ -313,7 +291,7 @@ void L1MuGMTMatrix<T>::print() const {
for (int r = 0; r < r_size; r++) {
std::stringstream output;
for (int c = 0; c < c_size; c++)
output << p[r][c] << "\t";
output << get(r, c) << "\t";
edm::LogVerbatim("GMTMatrix_print") << output.str();
}
edm::LogVerbatim("GMTMatrix_print");
Expand Down
10 changes: 4 additions & 6 deletions L1Trigger/GlobalMuonTrigger/src/L1MuGMTPSB.cc
Expand Up @@ -54,13 +54,11 @@ L1MuGMTPSB::L1MuGMTPSB(const L1MuGlobalMuonTrigger& gmt, edm::ConsumesCollector&
m_RpcMuons(L1MuGMTConfig::MAXRPC),
m_DtbxMuons(L1MuGMTConfig::MAXDTBX),
m_CscMuons(L1MuGMTConfig::MAXCSC),
m_Isol(14, 18),
m_Mip(14, 18) {
m_Isol(14, 18, false),
m_Mip(14, 18, false) {
m_RpcMuons.reserve(L1MuGMTConfig::MAXRPC);
m_DtbxMuons.reserve(L1MuGMTConfig::MAXDTBX);
m_CscMuons.reserve(L1MuGMTConfig::MAXCSC);
m_Isol.init(false);
m_Mip.init(false);
iC.consumes<std::vector<L1MuRegionalCand> >(L1MuGMTConfig::getDTInputTag());
iC.consumes<std::vector<L1MuRegionalCand> >(L1MuGMTConfig::getCSCInputTag());
iC.consumes<std::vector<L1MuRegionalCand> >(L1MuGMTConfig::getRPCbInputTag());
Expand Down Expand Up @@ -204,8 +202,8 @@ void L1MuGMTPSB::reset() {
while (iter != m_CscMuons.end())
(*(iter++)).reset();

m_Isol.init(false);
m_Mip.init(false);
m_Isol.reset(false);
m_Mip.reset(false);
}

//
Expand Down
4 changes: 4 additions & 0 deletions L1Trigger/GlobalMuonTrigger/test/BuildFile.xml
Expand Up @@ -12,6 +12,10 @@
<use name="hepmc"/>
<use name="root"/>
<use name="CLHEP"/>
<bin file="test_*.cc" name="L1TriggerGlobalMuonTriggerTest">
<use name="catch2"/>
<use name="L1Trigger/GlobalMuonTrigger"/>
</bin>
<library file="CruzetL1DTfilter.cc" name="CruzetL1DTfilter">
<flags EDM_PLUGIN="1"/>
</library>
Expand Down