Skip to content

Commit

Permalink
New KF (hand merged with L1TK-dev-12_0_0_pre4) (#88)
Browse files Browse the repository at this point in the history
* initial commit.

* renamed KFout producer to TT producer

* KFout producer and analyzer added. Producer is so far only a skeleton.

* small includings fix.

* quick TTTypes fix

* comments for ian

* initial commit.

* renamed KFout producer to TT producer

* KFout producer and analyzer added. Producer is so far only a skeleton.

* small includings fix.

* quick TTTypes fix

* comments for ian

* small script modifications

* little ntuple maker mod.

* readding fake fit config interface.

* track tigger association added, not in the best way.

* tttrack associator added as it should be.

* option to use TTStubAssMap to associate TTTracks with TPs removed and output module cleaned up.

* Added Hybrid_NewKF

* Added comment

* Update L1TrackNtupleMaker_cfg.py

fix typo made by Ian

* added tmtt costumization and fakefit option to tracklet config

* data format fix

* README filled and Configuration.StandardSequences.L1TrackTrigger_cff removed from run scripts.

* associateFinal added to StubAssociation.

* Update README.md

English corrections

* minor changes in various comments.

* KF 7 layer tracking debugged and defaulted.

* turned supported geometry white list into a black list.

* Cbrown kfout (#93)

* Initial Commit for Kfout emulator

* with ttTrackRefMap back in

* Correct link structure and eta routing

* No more print statements

* Remove print statements

* Merge changes in kfout producer

* Thomas' comments #1

* Thomas' comments #2

* Change dphi/dz LUT scaling to num of bits

* Fix bug to phi sector correction

* sync with FW fix

* Commit of distribution server for clock accuracy

* Fix to undefined operation on numLinkTracks

* Fix to numLinkTracks #2

Co-authored-by: Ian Tomalin <ian.tomalin@stfc.ac.uk>
Co-authored-by: Chriisbrown <41648127+Chriisbrown@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 24, 2021
1 parent f4bc4a9 commit 0a352c8
Show file tree
Hide file tree
Showing 157 changed files with 12,661 additions and 1,013 deletions.
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

0 comments on commit 0a352c8

Please sign in to comment.