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

New KF (hand merged with L1TK-dev-12_0_0_pre4) #88

Merged
merged 32 commits into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d5c622d
initial commit.
tschuh Jul 30, 2021
c8e21a7
renamed KFout producer to TT producer
tschuh Aug 5, 2021
b21f1c5
KFout producer and analyzer added. Producer is so far only a skeleton.
tschuh Aug 6, 2021
a9b7490
small includings fix.
tschuh Sep 22, 2021
cb0f47e
quick TTTypes fix
tschuh Sep 23, 2021
5042d05
comments for ian
tschuh Sep 29, 2021
7d39039
initial commit.
tschuh Jul 30, 2021
6fdec6c
renamed KFout producer to TT producer
tschuh Aug 5, 2021
1f65cc6
KFout producer and analyzer added. Producer is so far only a skeleton.
tschuh Aug 6, 2021
5eb1a39
small includings fix.
tschuh Sep 22, 2021
e6349a9
quick TTTypes fix
tschuh Sep 23, 2021
245a85e
comments for ian
tschuh Sep 29, 2021
8331a28
Merge branch 'tschuh12' of github.com:cms-L1TK/cmssw into tschuh12
tschuh Sep 30, 2021
79e1288
small script modifications
tschuh Oct 1, 2021
7138dba
little ntuple maker mod.
tschuh Oct 1, 2021
9f78a2c
readding fake fit config interface.
tschuh Oct 2, 2021
b45d351
track tigger association added, not in the best way.
tschuh Oct 3, 2021
f044e6f
tttrack associator added as it should be.
tschuh Oct 4, 2021
c0e5274
option to use TTStubAssMap to associate TTTracks with TPs removed and…
tschuh Oct 5, 2021
8799a56
Added Hybrid_NewKF
tomalin Oct 5, 2021
69c2614
Added comment
tomalin Oct 5, 2021
1147284
Update L1TrackNtupleMaker_cfg.py
tomalin Oct 6, 2021
f6bdfd2
added tmtt costumization and fakefit option to tracklet config
tschuh Oct 6, 2021
0250331
data format fix
tschuh Oct 6, 2021
b905888
README filled and Configuration.StandardSequences.L1TrackTrigger_cff …
tschuh Oct 12, 2021
1d43f3f
associateFinal added to StubAssociation.
tschuh Oct 12, 2021
6378b4f
Update README.md
tomalin Oct 15, 2021
487fb25
Merge branch 'L1TK-dev-12_0_0_pre4' into tschuh12
tomalin Oct 18, 2021
13b1563
minor changes in various comments.
tschuh Oct 19, 2021
38f2eae
KF 7 layer tracking debugged and defaulted.
tschuh Oct 20, 2021
8635459
turned supported geometry white list into a black list.
tschuh Oct 20, 2021
45d1843
Cbrown kfout (#93)
Chriisbrown Oct 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 132 additions & 40 deletions DataFormats/L1TrackTrigger/interface/TTBV.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,31 @@
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
#include <iostream>

/*!
* \class TTBV
* \brief Bit vector used by Track Trigger emulators. Mainly used to convert
* integers into arbitrary (within margin) sized two's complement string.
* integers into arbitrary (within margin) sized two's complement strings.
* \author Thomas Schuh
* \date 2020, Jan
*/
class TTBV {
public:
static constexpr int S = 64; // Frame width of emp infrastructure f/w, max number of bits a TTBV can handle
static constexpr int S_ = 64; // Frame width of emp infrastructure f/w, max number of bits a TTBV can handle

private:
bool twos_; // Two's complement (true) or binary (false)
int size_; // number or bits
std::bitset<S> bs_; // underlying storage
bool twos_; // Two's complement (true) or binary (false)
int size_; // number or bits
std::bitset<S_> bs_; // underlying storage

public:
// constructor: default
TTBV() : twos_(false), size_(S), bs_(std::bitset<S>(0)) {}
TTBV() : twos_(false), size_(0), bs_() {}

// constructor: double precision (IEEE 754); from most to least significant bit: 1 bit sign + 11 bit binary exponent + 52 bit binary mantisse
TTBV(const double d) : twos_(false), size_(S) {
TTBV(const double d) : twos_(false), size_(S_) {
int index(0);
const char* c = reinterpret_cast<const char*>(&d);
for (int iByte = 0; iByte < (int)sizeof(d); iByte++) {
Expand All @@ -40,45 +42,58 @@ class TTBV {
}

// constructor: unsigned int value
TTBV(unsigned long long int value, int size) : twos_(false), size_(size), bs_(std::bitset<S>(value)) {}
TTBV(unsigned long long int value, int size) : twos_(false), size_(size), bs_(value) {}

// constructor: int value
TTBV(int value, int size, bool Signed = false)
: twos_(Signed), size_(size), bs_(std::bitset<S>((!Signed || value >= 0) ? value : value + iMax())) {}
TTBV(int value, int size, bool twos = false)
: twos_(twos), size_(size), bs_((!twos || value >= 0) ? value : value + iMax()) {}

// constructor: double value + precision, biased (floor) representation
TTBV(double value, double base, int size, bool Signed = false) : TTBV((int)std::floor(value / base), size, Signed) {}
TTBV(double value, double base, int size, bool twos = false) : TTBV((int)std::floor(value / base), size, twos) {}

// constructor: string
TTBV(const std::string& str, bool Signed = false) : twos_(Signed), size_(str.size()), bs_(std::bitset<S>(str)) {}
TTBV(const std::string& str, bool twos = false) : twos_(twos), size_(str.size()), bs_(str) {}

// constructor: bitset
TTBV(const std::bitset<S>& bs, bool Signed = false) : twos_(Signed), size_(S), bs_(std::bitset<S>(bs)) {}
TTBV(const std::bitset<S_>& bs, bool twos = false) : twos_(twos), size_(S_), bs_(bs) {}

// access: data members
// constructor: slice reinterpret sign
TTBV(const TTBV& ttBV, int begin, int end = 0, bool twos = false) : twos_(twos), size_(begin - end), bs_(ttBV.bs_) {
bs_ <<= S_ - begin;
bs_ >>= S_ - begin + end;
}

// Two's complement (true) or binary (false)
bool twos() const { return twos_; }
// number or bits
int size() const { return size_; }
std::bitset<S> bs() const { return bs_; }
// underlying storage
const std::bitset<S_>& bs() const { return bs_; }

// access: single bit
bool operator[](int pos) const { return bs_[pos]; }
std::bitset<S>::reference operator[](int pos) { return bs_[pos]; }
std::bitset<S_>::reference operator[](int pos) { return bs_[pos]; }

// access: most significant bit
// access: most significant bit copy
bool msb() const { return bs_[size_ - 1]; }
std::bitset<S>::reference msb() { return bs_[size_ - 1]; }

// access: most significant bit reference
std::bitset<S_>::reference msb() { return bs_[size_ - 1]; }

// access: members of underlying bitset

bool all() const { return bs_.all(); }
bool any() const { return bs_.any(); }
bool none() const { return bs_.none(); }
int count() const { return bs_.count(); }

// operator: comparisons
// operator: comparisons equal
bool operator==(const TTBV& rhs) const { return bs_ == rhs.bs_; }

// operator: comparisons not equal
bool operator!=(const TTBV& rhs) const { return bs_ != rhs.bs_; }

// operator: boolean and, or, xor, not
// operator: boolean and
TTBV& operator&=(const TTBV& rhs) {
const int m(std::max(size_, rhs.size()));
this->resize(m);
Expand All @@ -87,6 +102,8 @@ class TTBV {
bs_ &= bv.bs_;
return *this;
}

// operator: boolean or
TTBV& operator|=(const TTBV& rhs) {
const int m(std::max(size_, rhs.size()));
this->resize(m);
Expand All @@ -95,6 +112,8 @@ class TTBV {
bs_ |= bv.bs_;
return *this;
}

// operator: boolean xor
TTBV& operator^=(const TTBV& rhs) {
const int m(std::max(size_, rhs.size()));
this->resize(m);
Expand All @@ -103,89 +122,112 @@ class TTBV {
bs_ ^= bv.bs_;
return *this;
}

// operator: not
TTBV operator~() const {
TTBV bv(*this);
return bv.flip();
}

// operator: bit shifts
// reference operator: bit remove right
TTBV& operator>>=(int pos) {
bs_ >>= pos;
size_ -= pos;
return *this;
}

// reference operator: bit remove left
TTBV& operator<<=(int pos) {
bs_ <<= S - size_ + pos;
bs_ >>= S - size_ + pos;
bs_ <<= S_ - size_ + pos;
bs_ >>= S_ - size_ + pos;
size_ -= pos;
return *this;
}

// operator: bit remove left copy
TTBV operator<<(int pos) const {
TTBV bv(*this);
return bv >>= pos;
return bv <<= pos;
}

// operator: bit remove right copy
TTBV operator>>(int pos) const {
TTBV bv(*this);
return bv <<= pos;
return bv >>= pos;
}

// operator: concatenation
// reference operator: concatenation
TTBV& operator+=(const TTBV& rhs) {
bs_ <<= rhs.size();
bs_ |= rhs.bs_;
size_ += rhs.size();
return *this;
}

// operator: concatenation copy
TTBV operator+(const TTBV& rhs) const {
TTBV lhs(*this);
return lhs += rhs;
}

// operator: value increment, overflow protected
TTBV& operator++() {
bs_ = std::bitset<S>(bs_.to_ullong() + 1);
bs_ = std::bitset<S_>(bs_.to_ullong() + 1);
this->resize(size_);
return *this;
}

// manipulation: all bits
// manipulation: all bits set to 0
TTBV& reset() {
bs_.reset();
return *this;
}

// manipulation: all bits set to 1
TTBV& set() {
for (int n = 0; n < size_; n++)
bs_.set(n);
return *this;
}

// manipulation: all bits flip 1 to 0 and vice versa
TTBV& flip() {
for (int n = 0; n < size_; n++)
bs_.flip(n);
return *this;
}

// manipulation: single bit
// manipulation: single bit set to 0
TTBV& reset(int pos) {
bs_.reset(pos);
return *this;
}

// manipulation: single bit set to 1
TTBV& set(int pos) {
bs_.set(pos);
return *this;
}

// manipulation: multiple bit set to 1
TTBV& set(std::vector<int> vpos) {
for (int pos : vpos)
bs_.set(pos);
return *this;
}

// manipulation: single bit flip 1 to 0 and vice versa
TTBV& flip(int pos) {
bs_.flip(pos);
return *this;
}

// manipulation: biased absolute value
// manipulation: absolute value of biased twos' complement. Converts twos' complenet into binary.
TTBV& abs() {
if (twos_) {
twos_ = false;
if (this->msb()) {
if (this->msb())
this->flip();
this->operator++();
}
size_--;
}
return *this;
Expand All @@ -208,7 +250,7 @@ class TTBV {
}

// conversion: to string
std::string str() const { return bs_.to_string().substr(S - size_, S); }
std::string str() const { return bs_.to_string().substr(S_ - size_, S_); }

// conversion: range based to string
std::string str(int start, int end = 0) const { return this->str().substr(size_ - start, size_ - end); }
Expand All @@ -217,14 +259,38 @@ class TTBV {
int val() const { return (twos_ && this->msb()) ? (int)bs_.to_ullong() - iMax() : bs_.to_ullong(); }

// conversion: to int, reinterpret sign
int val(bool Signed) const { return (Signed && this->msb()) ? (int)bs_.to_ullong() - iMax() : bs_.to_ullong(); }
int val(bool twos) const { return (twos && this->msb()) ? (int)bs_.to_ullong() - iMax() : bs_.to_ullong(); }

// conversion: range based to int, reinterpret sign
int val(int start, int end = 0, bool Signed = false) const { return TTBV(this->str(start, end), Signed).val(); }
int val(int start, int end = 0, bool twos = false) const { return TTBV(*this, start, end).val(twos); }

// conversion: to double for given precision assuming biased (floor) representation
double val(double base) const { return (this->val() + .5) * base; }

// conversion: range based to double for given precision assuming biased (floor) representation, reinterpret sign
double val(double base, int start, int end = 0, bool twos = false) const { return (this->val(start, end, twos) + .5) * base; }

// maniplulation and conversion: extracts range based to double reinterpret sign and removes these bits
double extract(double base, int size, bool twos = false) {
double val = this->val(base, size, 0, twos);
this->operator>>=(size);
return val;
}

// maniplulation and conversion: extracts range based to int reinterpret sign and removes these bits
int extract(int size, bool twos = false) {
double val = this->val(size, 0, twos);
this->operator>>=(size);
return val;
}

// manipulation: extracts slice and removes these bits
TTBV slice(int size, bool twos = false) {
TTBV ttBV(*this, size, 0, twos);
this->operator>>=(size);
return ttBV;
}

// range based count of '1's or '0's
int count(int begin, int end, bool b = true) const {
int c(0);
Expand All @@ -250,20 +316,46 @@ class TTBV {
return size_;
}

// position for n'th '1' or '0' counted from least to most significant bit
int encode(int n, bool b = true) const {
int sum(0);
for (int e = 0; e < size_; e++) {
if (bs_[e] == b) {
sum++;
if (sum == n)
return e;
}
}
return size_;
}

std::vector<int> ids(bool b = true, bool singed = false) const {
std::vector<int> v;
v.reserve(bs_.count());
for(int i = 0; i < size_; i++)
if (bs_[i] == b)
v.push_back(singed ? i + size_ / 2 : i);
return v;
}

friend std::ostream& operator<<(std::ostream& os, const TTBV& ttBV) { return os << ttBV.str(); }

private:
// look up table initializer for powers of 2
constexpr std::array<unsigned long long int, S> powersOfTwo() const {
std::array<unsigned long long int, S> lut = {};
for (int i = 0; i < S; i++)
constexpr std::array<unsigned long long int, S_> powersOfTwo() const {
std::array<unsigned long long int, S_> lut = {};
for (int i = 0; i < S_; i++)
lut[i] = std::pow(2, i);
return lut;
}

// returns 2 ** size_
unsigned long long int iMax() const {
static const std::array<unsigned long long int, S> lut = powersOfTwo();
static const std::array<unsigned long long int, S_> lut = powersOfTwo();
return lut[size_];
}
};



#endif
15 changes: 3 additions & 12 deletions DataFormats/L1TrackTrigger/interface/TTDTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@
*/
class TTDTC {
public:
// bit accurate Stub
typedef std::bitset<TTBV::S> BV;
// TTStub with bit accurate Stub
typedef std::pair<TTStubRef, BV> Frame;
// stub collection transported over an optical link between DTC and TFP
typedef std::vector<Frame> Stream;
// collection of optical links
typedef std::vector<Stream> Streams;

TTDTC() {}
TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion);
~TTDTC() {}
Expand All @@ -35,10 +26,10 @@ class TTDTC {
const std::vector<int>& tfpChannels() const { return channels_; }
// write one specific stream of TTStubRefs using DTC identifier (region[0-8], board[0-23], channel[0-1])
// dtcRegions aka detector regions are defined by tk layout
void setStream(int dtcRegion, int dtcBoard, int dtcChannel, const Stream& stream);
void setStream(int dtcRegion, int dtcBoard, int dtcChannel, const tt::StreamStub& stream);
// read one specific stream of TTStubRefs using TFP identifier (region[0-8], channel[0-47])
// tfpRegions aka processing regions are rotated by -0.5 region width w.r.t detector regions
const Stream& stream(int tfpRegion, int tfpChannel) const;
const tt::StreamStub& stream(int tfpRegion, int tfpChannel) const;
// total number of frames
int size() const;
// total number of stubs
Expand All @@ -64,7 +55,7 @@ class TTDTC {
// all TFP channel [default 0..47]
std::vector<int> channels_;
// collection of all optical links between DTC and TFP [default 432 links]
Streams streams_;
tt::StreamsStub streams_;
};

#endif
Loading