Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
tschuh committed Nov 22, 2024
1 parent 8befcea commit c9a89dd
Show file tree
Hide file tree
Showing 192 changed files with 12,036 additions and 10,137 deletions.
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
129 changes: 99 additions & 30 deletions DataFormats/L1TrackTrigger/interface/TTBV.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,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 +39,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 +70,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 +100,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 +247,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 +286,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 +322,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 +338,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 +372,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
2 changes: 2 additions & 0 deletions DataFormats/L1TrackTrigger/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@
<class name="edm::Wrapper<tt::TTTrackRefMap>"/>
<class name="TTDTC"/>
<class name="edm::Wrapper<TTDTC>"/>
<class name="std::vector<std::pair<double, double>>"/>
<class name="edm::Wrapper<std::vector<std::pair<double, double>>>"/>
</lcgdict>

4 changes: 2 additions & 2 deletions L1Trigger/L1TTrackMatch/test/L1TrackObjectNtupleMaker_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,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
29 changes: 29 additions & 0 deletions L1Trigger/TrackFindingTMTT/interface/L1track3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@ namespace tmtt {
: L1track3D(
settings, stubs, cellLocationHT, helixRphi, helixRz, 0.0, iPhiSec, iEtaReg, optoLinkID, mergedHTcell) {}

// KF emulator: constructor
L1track3D(Settings* settings,
std::vector<Stub*> stubs,
double qOverPt,
double phi0,
double z0,
double tanLambda,
double helixD0,
int iPhiSec,
int iEtaReg)
: settings_(settings),
stubs_(stubs),
stubsConst_(std::vector<const Stub*>()),
bestStubs_(std::unordered_set<const Stub*>()),
nLayers_(0),
cellLocationHT_(0, 0),
helixRphi_(qOverPt, phi0),
helixRz_(z0, tanLambda),
helixD0_(helixD0),
iPhiSec_(iPhiSec),
iEtaReg_(iEtaReg),
optoLinkID_(0),
mergedHTcell_(false),
seedLayerType_(TrackletSeedType()),
seedPS_(0),
matchedTP_(nullptr),
matchedStubs_(std::vector<const Stub*>()),
nMatchedLayers_(0) {}

~L1track3D() override = default;

//--- Set/get optional info for tracklet tracks.
Expand Down
13 changes: 13 additions & 0 deletions L1Trigger/TrackFindingTMTT/interface/Stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ namespace tmtt {
const DegradeBend* degradeBend,
const StubKiller* stubKiller);

// KF emualtor: stub constructor
Stub(const TTStubRef& ttStubRef,
double r,
double phi,
double z,
int layerId,
int layerIdReduced,
double stripPitch,
double stripLength,
bool psModule,
bool barrel,
bool tiltedBarrel);

bool operator==(const Stub& stubOther) { return (this->index() == stubOther.index()); }

// Return reference to original TTStub.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
#--- Options for Kalman filter track fitters ---
#
# Larger number has more debug printout. "1" is useful for understanding why tracks are lost, best combined with TrackFitCheat=True.
KalmanDebugLevel = cms.uint32(0),
KalmanDebugLevel = cms.uint32(2),
# Fit will reject fitted tracks unless it can assign at least this number of stubs to them.
KalmanMinNumStubs = cms.uint32(4),
# Fit will attempt to add up to this nummber of stubs to each fitted tracks, but won't bother adding more.
Expand Down
4 changes: 2 additions & 2 deletions L1Trigger/TrackFindingTMTT/src/Settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace tmtt {
stubMatchStrict_(false),

// Kalman filter track fit cfg
kalmanDebugLevel_(0),
//kalmanDebugLevel_(2), // Good for debugging
//kalmanDebugLevel_(0),
kalmanDebugLevel_(2), // Good for debugging
kalmanMinNumStubs_(4),
kalmanMaxNumStubs_(6),
kalmanAddBeamConstr_(false), // Apply post-fit beam-spot constraint to 5-param fit
Expand Down
Loading

0 comments on commit c9a89dd

Please sign in to comment.