Skip to content

L1 tracking update #47067

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions Configuration/StandardSequences/python/L1TrackTrigger_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from L1Trigger.TrackTrigger.TrackTrigger_cff import *
from SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff import *
from L1Trigger.TrackerDTC.ProducerED_cff import *
from L1Trigger.TrackerDTC.DTC_cff import *
from L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff import *

L1TrackTrigger=cms.Sequence(TrackTriggerClustersStubs*TrackTriggerAssociatorClustersStubs*TrackerDTCProducer)
L1TrackTrigger=cms.Sequence(TrackTriggerClustersStubs*TrackTriggerAssociatorClustersStubs*ProducerDTC)

# Customisation to enable TTTracks in geometry D41 and later (corresponding to phase2_trackerV14 or later). Includes the HGCAL L1 trigger
_tttracks_l1tracktrigger = L1TrackTrigger.copy()
Expand Down
131 changes: 101 additions & 30 deletions DataFormats/L1TrackTrigger/interface/TTBV.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef DataFormats_L1TrackTrigger_TTBV_h
#define DataFormats_L1TrackTrigger_TTBV_h

#include "FWCore/Utilities/interface/Exception.h"

#include <bitset>
#include <array>
#include <string>
Expand All @@ -20,16 +22,13 @@
class TTBV {
public:
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

public:
// constructor: default
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_) {
int index(0);
Expand All @@ -42,14 +41,17 @@ class TTBV {
}

// constructor: unsigned int value
TTBV(unsigned long long int value, int size) : twos_(false), size_(size), bs_(value) {}
TTBV(unsigned long long int value, int size) : twos_(false), size_(size), bs_(value) { checkU(value); }

// constructor: int value
TTBV(int value, int size, bool twos = false)
: twos_(twos), size_(size), bs_((!twos || value >= 0) ? value : value + iMax()) {}
: twos_(twos), size_(size), bs_((!twos || value >= 0) ? value : value + iMax()) {
checkI(value);
}

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

// constructor: string
TTBV(const std::string& str, bool twos = false) : twos_(twos), size_(str.size()), bs_(str) {}
Expand All @@ -70,10 +72,15 @@ class TTBV {
// underlying storage
const std::bitset<S_>& bs() const { return bs_; }

// access: single bit
// access: single bit value
bool operator[](int pos) const { return bs_[pos]; }

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

// access: single bit value with bounds check
bool test(int pos) const { return bs_.test(pos); }

// access: most significant bit copy
bool msb() const { return bs_[size_ - 1]; }

Expand All @@ -95,31 +102,31 @@ class TTBV {

// operator: boolean and
TTBV& operator&=(const TTBV& rhs) {
const int m(std::max(size_, rhs.size()));
this->resize(m);
TTBV bv(rhs);
bv.resize(m);
bs_ &= bv.bs_;
bs_ &= rhs.bs_;
return *this;
}

// operator: boolean and
TTBV operator&&(const TTBV& rhs) {
TTBV copy(*this);
return copy &= rhs;
}

// operator: boolean or
TTBV& operator|=(const TTBV& rhs) {
const int m(std::max(size_, rhs.size()));
this->resize(m);
TTBV bv(rhs);
bv.resize(m);
bs_ |= bv.bs_;
bs_ |= rhs.bs_;
return *this;
}

// operator: boolean or
TTBV operator||(const TTBV& rhs) {
TTBV copy(*this);
return copy |= rhs;
}

// operator: boolean xor
TTBV& operator^=(const TTBV& rhs) {
const int m(std::max(size_, rhs.size()));
this->resize(m);
TTBV bv(rhs);
bv.resize(m);
bs_ ^= bv.bs_;
bs_ ^= rhs.bs_;
return *this;
}

Expand Down Expand Up @@ -242,7 +249,7 @@ class TTBV {
bs_.set(n, msb);
size_ = size;
} else if (size < size_ && size > 0) {
this->operator<<=(size - size_);
this->operator<<=(size_ - size);
if (twos_)
this->msb() = msb;
}
Expand Down Expand Up @@ -281,11 +288,18 @@ class TTBV {

// 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);
int val = this->val(size, 0, twos);
this->operator>>=(size);
return val;
}

// maniplulation and conversion: extracts bool and removes this bit
bool extract() {
bool val = bs_[0];
this->operator>>=(1);
return val;
}

// manipulation: extracts slice and removes these bits
TTBV slice(int size, bool twos = false) {
TTBV ttBV(*this, size, 0, twos);
Expand All @@ -310,6 +324,14 @@ class TTBV {
return size_;
}

// position of least significant '1' or '0' in range [begin, end)
int plEncode(int begin, int end, bool b = true) const {
for (int e = begin; e < end; e++)
if (bs_.test(e) == b)
return e;
return size_;
}

// position of most significant '1' or '0'
int pmEncode(bool b = true) const {
for (int e = size_ - 1; e > -1; e--)
Expand All @@ -318,6 +340,14 @@ class TTBV {
return size_;
}

// position of most significant '1' or '0' in range [begin, end)
int pmEncode(int begin, int end, bool b = true) const {
for (int e = end - 1; e >= begin; e--)
if (bs_.test(e) == b)
return e;
return end;
}

// 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);
Expand All @@ -344,17 +374,58 @@ class TTBV {

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<double, S_ + 1> powersOfTwo() const {
std::array<double, S_ + 1> 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();
return lut[size_];
double iMax() const {
static const std::array<double, S_ + 1> lut = powersOfTwo();
return std::round(lut[size_]);
}

// check if value fits into binary BV
void checkU(unsigned long long int value) {
if (size_ == 0)
return;
if (value < iMax())
return;
cms::Exception exception("RunTimeError.");
exception << "Value " << value << " does not fit into a " << size_ << "b binary.";
exception.addContext("TTBV::checkU");
throw exception;
}

// check if value fits into twos's complement BV
void checkT(int value) {
if (size_ == 0)
return;
static const std::array<double, S_ + 1> lut = powersOfTwo();
auto abs = [](int val) { return val < 0 ? std::abs(val) - 1 : val; };
if (abs(value) < std::round(lut[size_ - 1]))
return;
cms::Exception exception("RunTimeError.");
exception << "Value " << value << " does not fit into a " << size_ << "b two's complement.";
exception.addContext("TTBV::checkT");
throw exception;
}

// check if value fits into twos complement / binary BV
void checkI(int value) {
if (size_ == 0)
return;
if (twos_)
checkT(value);
else if (value < 0) {
cms::Exception exception("RunTimeError.");
exception << size_ << "b Binary TTBV constructor called with negative value (" << value << ").";
exception.addContext("TTBV::checkI");
throw exception;
} else
checkU(value);
}
};

Expand Down
28 changes: 12 additions & 16 deletions DataFormats/L1TrackTrigger/src/TTDTC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

#include <numeric>

using namespace std;
using namespace edm;
using namespace tt;

TTDTC::TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion)
: numRegions_(numRegions),
numOverlappingRegions_(numOverlappingRegions),
Expand All @@ -15,13 +11,13 @@ TTDTC::TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion)
regions_(numRegions_),
channels_(numDTCsPerTFP_),
streams_(numRegions_ * numDTCsPerTFP_) {
iota(regions_.begin(), regions_.end(), 0);
iota(channels_.begin(), channels_.end(), 0);
std::iota(regions_.begin(), regions_.end(), 0);
std::iota(channels_.begin(), channels_.end(), 0);
}

// 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 TTDTC::setStream(int dtcRegion, int dtcBoard, int dtcChannel, const StreamStub& stream) {
void TTDTC::setStream(int dtcRegion, int dtcBoard, int dtcChannel, const tt::StreamStub& stream) {
// check arguments
const bool oorRegion = dtcRegion >= numRegions_ || dtcRegion < 0;
const bool oorBoard = dtcBoard >= numDTCsPerRegion_ || dtcBoard < 0;
Expand All @@ -45,7 +41,7 @@ void TTDTC::setStream(int dtcRegion, int dtcBoard, int dtcChannel, const StreamS

// 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 StreamStub& TTDTC::stream(int tfpRegion, int tfpChannel) const {
const tt::StreamStub& TTDTC::stream(int tfpRegion, int tfpChannel) const {
// check arguments
const bool oorRegion = tfpRegion >= numRegions_ || tfpRegion < 0;
const bool oorChannel = tfpChannel >= numDTCsPerTFP_ || tfpChannel < 0;
Expand All @@ -65,25 +61,25 @@ const StreamStub& TTDTC::stream(int tfpRegion, int tfpChannel) const {

// total number of frames
int TTDTC::size() const {
auto all = [](int sum, const StreamStub& stream) { return sum + stream.size(); };
return accumulate(streams_.begin(), streams_.end(), 0, all);
auto all = [](int sum, const tt::StreamStub& stream) { return sum + stream.size(); };
return std::accumulate(streams_.begin(), streams_.end(), 0, all);
}

// total number of stubs
int TTDTC::nStubs() const {
auto stubs = [](int sum, const FrameStub& frame) { return sum + frame.first.isNonnull(); };
auto stubs = [](int sum, const tt::FrameStub& frame) { return sum + frame.first.isNonnull(); };
int n(0);
for (const StreamStub& stream : streams_)
n += accumulate(stream.begin(), stream.end(), 0, stubs);
for (const tt::StreamStub& stream : streams_)
n += std::accumulate(stream.begin(), stream.end(), 0, stubs);
return n;
}

// total number of gaps
int TTDTC::nGaps() const {
auto gaps = [](int sum, const FrameStub& frame) { return sum + frame.first.isNull(); };
auto gaps = [](int sum, const tt::FrameStub& frame) { return sum + frame.first.isNull(); };
int n(0);
for (const StreamStub& stream : streams_)
n += accumulate(stream.begin(), stream.end(), 0, gaps);
for (const tt::StreamStub& stream : streams_)
n += std::accumulate(stream.begin(), stream.end(), 0, gaps);
return n;
}

Expand Down
1 change: 1 addition & 0 deletions DataFormats/WrappedStdDictionaries/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@
<class name="edm::Wrapper<unsigned short>"/>
<class name="edm::Wrapper<std::vector<std::pair<int,std::bitset<6> > > >" />
<class name="edm::Wrapper<std::vector<std::unique_ptr<int>>>"/>
<class name="edm::Wrapper<std::vector<std::pair<double, double>>>"/>
</lcgdict>
2 changes: 1 addition & 1 deletion L1Trigger/L1TTrackMatch/test/L1TrackObjectNtupleMaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2653,7 +2653,7 @@ void L1TrackObjectNtupleMaker::analyze(const edm::Event& iEvent, const edm::Even
myFake = 1;

myTP_pdgid = my_tp->pdgId();
if (my_tp->genParticles().size() > 0) {
if (!my_tp->genParticles().empty()) {
myTP_mother_pdgid = my_tp->genParticles().at(0)->mother(0)->pdgId();
}
myTP_pt = my_tp->p4().pt();
Expand Down
4 changes: 2 additions & 2 deletions L1Trigger/L1TTrackMatch/test/L1TrackObjectNtupleMaker_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@


# DTC emulation
process.load('L1Trigger.TrackerDTC.ProducerED_cff')
process.dtc = cms.Path(process.TrackerDTCProducer)
process.load('L1Trigger.TrackerDTC.DTC_cff')
process.dtc = cms.Path(process.ProducerDTC)

process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff")
process.load("L1Trigger.L1TTrackMatch.l1tTrackSelectionProducer_cfi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
process.load('Configuration.StandardSequences.SimL1Emulator_cff')
process.load('L1Trigger.TrackTrigger.TrackTrigger_cff')
process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff")
process.load("L1Trigger.TrackerDTC.ProducerES_cff")
process.load("L1Trigger.TrackerDTC.ProducerED_cff")
process.load("L1Trigger.TrackerDTC.DTC_cff")
process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")

process.l1tLayer1Barrel9 = process.l1tLayer1Barrel.clone()
Expand All @@ -52,7 +51,7 @@
process.PFInputsTask = cms.Task(
process.TTClustersFromPhase2TrackerDigis,
process.TTStubsFromPhase2TrackerDigis,
process.TrackerDTCProducer,
process.ProducerDTC,
process.offlineBeamSpot,
process.l1tTTTracksFromTrackletEmulation,
process.SimL1EmulatorTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
process.load('Configuration.StandardSequences.SimL1Emulator_cff')
process.load('L1Trigger.TrackTrigger.TrackTrigger_cff')
process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff")
process.load("L1Trigger.TrackerDTC.ProducerES_cff")
process.load("L1Trigger.TrackerDTC.ProducerED_cff")
process.load("L1Trigger.TrackerDTC.DTC_cff")
process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")

from L1Trigger.Phase2L1ParticleFlow.l1tSeedConePFJetProducer_cfi import l1tSeedConePFJetEmulatorProducer
Expand Down Expand Up @@ -69,7 +68,7 @@
process.PFInputsTask = cms.Task(
process.TTClustersFromPhase2TrackerDigis,
process.TTStubsFromPhase2TrackerDigis,
process.TrackerDTCProducer,
process.ProducerDTC,
process.offlineBeamSpot,
process.l1tTTTracksFromTrackletEmulation,
process.SimL1EmulatorTask
Expand Down
Loading