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

L1 tracking update #47067

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
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>
10 changes: 5 additions & 5 deletions L1Trigger/L1TTrackMatch/test/L1TrackObjectNtupleMaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,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 Expand Up @@ -2365,7 +2365,7 @@ void L1TrackObjectNtupleMaker::analyze(const edm::Event& iEvent, const edm::Even

this_l1track++;
} //end track loop
} //end if SaveAllTracks
} //end if SaveAllTracks

// ----------------------------------------------------------------------------------------------
// loop over (extended) L1 tracks
Expand Down Expand Up @@ -2579,7 +2579,7 @@ void L1TrackObjectNtupleMaker::analyze(const edm::Event& iEvent, const edm::Even
m_trkExt_selected_associated_emulation_foretmiss_index->push_back(this_l1track);
this_l1track++;
} //end track loop
} //end if SaveAllTracks (displaced)
} //end if SaveAllTracks (displaced)

// ----------------------------------------------------------------------------------------------
// loop over tracking particles
Expand Down Expand Up @@ -2829,7 +2829,7 @@ void L1TrackObjectNtupleMaker::analyze(const edm::Event& iEvent, const edm::Even
}

} // end loop over matched L1 tracks
} // end has at least 1 matched L1 track
} // end has at least 1 matched L1 track
// ----------------------------------------------------------------------------------------------

float tmp_matchtrk_pt = -999;
Expand Down Expand Up @@ -3000,7 +3000,7 @@ void L1TrackObjectNtupleMaker::analyze(const edm::Event& iEvent, const edm::Even
}

} // end loop over matched L1 tracks
} // end has at least 1 matched L1 track
} // end has at least 1 matched L1 track
// ----------------------------------------------------------------------------------------------

float tmp_matchtrkExt_pt = -999;
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 @@ -80,8 +80,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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
stubs_(stubs),
stubs_(std::move(stubs)),

to avoid a copy.

stubsConst_(std::vector<const Stub*>()),
bestStubs_(std::unordered_set<const Stub*>()),
Comment on lines +87 to +88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These have the same effect as default constructor, and are thus not needed.

Suggested change
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*>()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Suggested change
matchedStubs_(std::vector<const Stub*>()),

nMatchedLayers_(0) {}

~L1track3D() override = default;

//--- Set/get optional info for tracklet tracks.
Expand Down
Loading