Skip to content

Commit 13a0ef8

Browse files
authored
Merge pull request #47067 from cms-L1TK/L1TK-PR-14_2_0_pre4
L1 tracking update
2 parents 8d747a3 + b878632 commit 13a0ef8

File tree

220 files changed

+15917
-13077
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+15917
-13077
lines changed

Configuration/StandardSequences/python/L1TrackTrigger_cff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from L1Trigger.TrackTrigger.TrackTrigger_cff import *
44
from SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff import *
5-
from L1Trigger.TrackerDTC.ProducerED_cff import *
5+
from L1Trigger.TrackerDTC.DTC_cff import *
66
from L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff import *
77

8-
L1TrackTrigger=cms.Sequence(TrackTriggerClustersStubs*TrackTriggerAssociatorClustersStubs*TrackerDTCProducer)
8+
L1TrackTrigger=cms.Sequence(TrackTriggerClustersStubs*TrackTriggerAssociatorClustersStubs*ProducerDTC)
99

1010
# Customisation to enable TTTracks in geometry D41 and later (corresponding to phase2_trackerV14 or later). Includes the HGCAL L1 trigger
1111
_tttracks_l1tracktrigger = L1TrackTrigger.copy()

DataFormats/L1TrackTrigger/interface/TTBV.h

Lines changed: 101 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef DataFormats_L1TrackTrigger_TTBV_h
22
#define DataFormats_L1TrackTrigger_TTBV_h
33

4+
#include "FWCore/Utilities/interface/Exception.h"
5+
46
#include <bitset>
57
#include <array>
68
#include <string>
@@ -20,16 +22,13 @@
2022
class TTBV {
2123
public:
2224
static constexpr int S_ = 64; // Frame width of emp infrastructure f/w, max number of bits a TTBV can handle
23-
2425
private:
2526
bool twos_; // Two's complement (true) or binary (false)
2627
int size_; // number or bits
2728
std::bitset<S_> bs_; // underlying storage
28-
2929
public:
3030
// constructor: default
3131
TTBV() : twos_(false), size_(0), bs_() {}
32-
3332
// constructor: double precision (IEEE 754); from most to least significant bit: 1 bit sign + 11 bit binary exponent + 52 bit binary mantisse
3433
TTBV(const double d) : twos_(false), size_(S_) {
3534
int index(0);
@@ -42,14 +41,17 @@ class TTBV {
4241
}
4342

4443
// constructor: unsigned int value
45-
TTBV(unsigned long long int value, int size) : twos_(false), size_(size), bs_(value) {}
44+
TTBV(unsigned long long int value, int size) : twos_(false), size_(size), bs_(value) { checkU(value); }
4645

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

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

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

73-
// access: single bit
75+
// access: single bit value
7476
bool operator[](int pos) const { return bs_[pos]; }
77+
78+
// access: single bit reference
7579
std::bitset<S_>::reference operator[](int pos) { return bs_[pos]; }
7680

81+
// access: single bit value with bounds check
82+
bool test(int pos) const { return bs_.test(pos); }
83+
7784
// access: most significant bit copy
7885
bool msb() const { return bs_[size_ - 1]; }
7986

@@ -95,31 +102,31 @@ class TTBV {
95102

96103
// operator: boolean and
97104
TTBV& operator&=(const TTBV& rhs) {
98-
const int m(std::max(size_, rhs.size()));
99-
this->resize(m);
100-
TTBV bv(rhs);
101-
bv.resize(m);
102-
bs_ &= bv.bs_;
105+
bs_ &= rhs.bs_;
103106
return *this;
104107
}
105108

109+
// operator: boolean and
110+
TTBV operator&&(const TTBV& rhs) {
111+
TTBV copy(*this);
112+
return copy &= rhs;
113+
}
114+
106115
// operator: boolean or
107116
TTBV& operator|=(const TTBV& rhs) {
108-
const int m(std::max(size_, rhs.size()));
109-
this->resize(m);
110-
TTBV bv(rhs);
111-
bv.resize(m);
112-
bs_ |= bv.bs_;
117+
bs_ |= rhs.bs_;
113118
return *this;
114119
}
115120

121+
// operator: boolean or
122+
TTBV operator||(const TTBV& rhs) {
123+
TTBV copy(*this);
124+
return copy |= rhs;
125+
}
126+
116127
// operator: boolean xor
117128
TTBV& operator^=(const TTBV& rhs) {
118-
const int m(std::max(size_, rhs.size()));
119-
this->resize(m);
120-
TTBV bv(rhs);
121-
bv.resize(m);
122-
bs_ ^= bv.bs_;
129+
bs_ ^= rhs.bs_;
123130
return *this;
124131
}
125132

@@ -242,7 +249,7 @@ class TTBV {
242249
bs_.set(n, msb);
243250
size_ = size;
244251
} else if (size < size_ && size > 0) {
245-
this->operator<<=(size - size_);
252+
this->operator<<=(size_ - size);
246253
if (twos_)
247254
this->msb() = msb;
248255
}
@@ -281,11 +288,18 @@ class TTBV {
281288

282289
// maniplulation and conversion: extracts range based to int reinterpret sign and removes these bits
283290
int extract(int size, bool twos = false) {
284-
double val = this->val(size, 0, twos);
291+
int val = this->val(size, 0, twos);
285292
this->operator>>=(size);
286293
return val;
287294
}
288295

296+
// maniplulation and conversion: extracts bool and removes this bit
297+
bool extract() {
298+
bool val = bs_[0];
299+
this->operator>>=(1);
300+
return val;
301+
}
302+
289303
// manipulation: extracts slice and removes these bits
290304
TTBV slice(int size, bool twos = false) {
291305
TTBV ttBV(*this, size, 0, twos);
@@ -310,6 +324,14 @@ class TTBV {
310324
return size_;
311325
}
312326

327+
// position of least significant '1' or '0' in range [begin, end)
328+
int plEncode(int begin, int end, bool b = true) const {
329+
for (int e = begin; e < end; e++)
330+
if (bs_.test(e) == b)
331+
return e;
332+
return size_;
333+
}
334+
313335
// position of most significant '1' or '0'
314336
int pmEncode(bool b = true) const {
315337
for (int e = size_ - 1; e > -1; e--)
@@ -318,6 +340,14 @@ class TTBV {
318340
return size_;
319341
}
320342

343+
// position of most significant '1' or '0' in range [begin, end)
344+
int pmEncode(int begin, int end, bool b = true) const {
345+
for (int e = end - 1; e >= begin; e--)
346+
if (bs_.test(e) == b)
347+
return e;
348+
return end;
349+
}
350+
321351
// position for n'th '1' or '0' counted from least to most significant bit
322352
int encode(int n, bool b = true) const {
323353
int sum(0);
@@ -344,17 +374,58 @@ class TTBV {
344374

345375
private:
346376
// look up table initializer for powers of 2
347-
constexpr std::array<unsigned long long int, S_> powersOfTwo() const {
348-
std::array<unsigned long long int, S_> lut = {};
349-
for (int i = 0; i < S_; i++)
377+
constexpr std::array<double, S_ + 1> powersOfTwo() const {
378+
std::array<double, S_ + 1> lut = {};
379+
for (int i = 0; i <= S_; i++)
350380
lut[i] = std::pow(2, i);
351381
return lut;
352382
}
353383

354384
// returns 2 ** size_
355-
unsigned long long int iMax() const {
356-
static const std::array<unsigned long long int, S_> lut = powersOfTwo();
357-
return lut[size_];
385+
double iMax() const {
386+
static const std::array<double, S_ + 1> lut = powersOfTwo();
387+
return std::round(lut[size_]);
388+
}
389+
390+
// check if value fits into binary BV
391+
void checkU(unsigned long long int value) {
392+
if (size_ == 0)
393+
return;
394+
if (value < iMax())
395+
return;
396+
cms::Exception exception("RunTimeError.");
397+
exception << "Value " << value << " does not fit into a " << size_ << "b binary.";
398+
exception.addContext("TTBV::checkU");
399+
throw exception;
400+
}
401+
402+
// check if value fits into twos's complement BV
403+
void checkT(int value) {
404+
if (size_ == 0)
405+
return;
406+
static const std::array<double, S_ + 1> lut = powersOfTwo();
407+
auto abs = [](int val) { return val < 0 ? std::abs(val) - 1 : val; };
408+
if (abs(value) < std::round(lut[size_ - 1]))
409+
return;
410+
cms::Exception exception("RunTimeError.");
411+
exception << "Value " << value << " does not fit into a " << size_ << "b two's complement.";
412+
exception.addContext("TTBV::checkT");
413+
throw exception;
414+
}
415+
416+
// check if value fits into twos complement / binary BV
417+
void checkI(int value) {
418+
if (size_ == 0)
419+
return;
420+
if (twos_)
421+
checkT(value);
422+
else if (value < 0) {
423+
cms::Exception exception("RunTimeError.");
424+
exception << size_ << "b Binary TTBV constructor called with negative value (" << value << ").";
425+
exception.addContext("TTBV::checkI");
426+
throw exception;
427+
} else
428+
checkU(value);
358429
}
359430
};
360431

DataFormats/L1TrackTrigger/src/TTDTC.cc

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33

44
#include <numeric>
55

6-
using namespace std;
7-
using namespace edm;
8-
using namespace tt;
9-
106
TTDTC::TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion)
117
: numRegions_(numRegions),
128
numOverlappingRegions_(numOverlappingRegions),
@@ -15,13 +11,13 @@ TTDTC::TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion)
1511
regions_(numRegions_),
1612
channels_(numDTCsPerTFP_),
1713
streams_(numRegions_ * numDTCsPerTFP_) {
18-
iota(regions_.begin(), regions_.end(), 0);
19-
iota(channels_.begin(), channels_.end(), 0);
14+
std::iota(regions_.begin(), regions_.end(), 0);
15+
std::iota(channels_.begin(), channels_.end(), 0);
2016
}
2117

2218
// write one specific stream of TTStubRefs using DTC identifier (region[0-8], board[0-23], channel[0-1])
2319
// dtcRegions aka detector regions are defined by tk layout
24-
void TTDTC::setStream(int dtcRegion, int dtcBoard, int dtcChannel, const StreamStub& stream) {
20+
void TTDTC::setStream(int dtcRegion, int dtcBoard, int dtcChannel, const tt::StreamStub& stream) {
2521
// check arguments
2622
const bool oorRegion = dtcRegion >= numRegions_ || dtcRegion < 0;
2723
const bool oorBoard = dtcBoard >= numDTCsPerRegion_ || dtcBoard < 0;
@@ -45,7 +41,7 @@ void TTDTC::setStream(int dtcRegion, int dtcBoard, int dtcChannel, const StreamS
4541

4642
// read one specific stream of TTStubRefs using TFP identifier (region[0-8], channel[0-47])
4743
// tfpRegions aka processing regions are rotated by -0.5 region width w.r.t detector regions
48-
const StreamStub& TTDTC::stream(int tfpRegion, int tfpChannel) const {
44+
const tt::StreamStub& TTDTC::stream(int tfpRegion, int tfpChannel) const {
4945
// check arguments
5046
const bool oorRegion = tfpRegion >= numRegions_ || tfpRegion < 0;
5147
const bool oorChannel = tfpChannel >= numDTCsPerTFP_ || tfpChannel < 0;
@@ -65,25 +61,25 @@ const StreamStub& TTDTC::stream(int tfpRegion, int tfpChannel) const {
6561

6662
// total number of frames
6763
int TTDTC::size() const {
68-
auto all = [](int sum, const StreamStub& stream) { return sum + stream.size(); };
69-
return accumulate(streams_.begin(), streams_.end(), 0, all);
64+
auto all = [](int sum, const tt::StreamStub& stream) { return sum + stream.size(); };
65+
return std::accumulate(streams_.begin(), streams_.end(), 0, all);
7066
}
7167

7268
// total number of stubs
7369
int TTDTC::nStubs() const {
74-
auto stubs = [](int sum, const FrameStub& frame) { return sum + frame.first.isNonnull(); };
70+
auto stubs = [](int sum, const tt::FrameStub& frame) { return sum + frame.first.isNonnull(); };
7571
int n(0);
76-
for (const StreamStub& stream : streams_)
77-
n += accumulate(stream.begin(), stream.end(), 0, stubs);
72+
for (const tt::StreamStub& stream : streams_)
73+
n += std::accumulate(stream.begin(), stream.end(), 0, stubs);
7874
return n;
7975
}
8076

8177
// total number of gaps
8278
int TTDTC::nGaps() const {
83-
auto gaps = [](int sum, const FrameStub& frame) { return sum + frame.first.isNull(); };
79+
auto gaps = [](int sum, const tt::FrameStub& frame) { return sum + frame.first.isNull(); };
8480
int n(0);
85-
for (const StreamStub& stream : streams_)
86-
n += accumulate(stream.begin(), stream.end(), 0, gaps);
81+
for (const tt::StreamStub& stream : streams_)
82+
n += std::accumulate(stream.begin(), stream.end(), 0, gaps);
8783
return n;
8884
}
8985

DataFormats/WrappedStdDictionaries/src/classes_def.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@
5656
<class name="edm::Wrapper<unsigned short>"/>
5757
<class name="edm::Wrapper<std::vector<std::pair<int,std::bitset<6> > > >" />
5858
<class name="edm::Wrapper<std::vector<std::unique_ptr<int>>>"/>
59+
<class name="edm::Wrapper<std::vector<std::pair<double, double>>>"/>
5960
</lcgdict>

L1Trigger/L1TTrackMatch/test/L1TrackObjectNtupleMaker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2657,7 +2657,7 @@ void L1TrackObjectNtupleMaker::analyze(const edm::Event& iEvent, const edm::Even
26572657
myFake = 1;
26582658

26592659
myTP_pdgid = my_tp->pdgId();
2660-
if (my_tp->genParticles().size() > 0) {
2660+
if (!my_tp->genParticles().empty()) {
26612661
myTP_mother_pdgid = my_tp->genParticles().at(0)->mother(0)->pdgId();
26622662
}
26632663
myTP_pt = my_tp->p4().pt();

L1Trigger/L1TTrackMatch/test/L1TrackObjectNtupleMaker_cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181

8282

8383
# DTC emulation
84-
process.load('L1Trigger.TrackerDTC.ProducerED_cff')
85-
process.dtc = cms.Path(process.TrackerDTCProducer)
84+
process.load('L1Trigger.TrackerDTC.DTC_cff')
85+
process.dtc = cms.Path(process.ProducerDTC)
8686

8787
process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff")
8888
process.load("L1Trigger.L1TTrackMatch.l1tTrackSelectionProducer_cfi")

L1Trigger/Phase2L1ParticleFlow/test/make_l1ctLayer1_dumpFiles_fromRAW_cfg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
process.load('Configuration.StandardSequences.SimL1Emulator_cff')
3434
process.load('L1Trigger.TrackTrigger.TrackTrigger_cff')
3535
process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff")
36-
process.load("L1Trigger.TrackerDTC.ProducerES_cff")
37-
process.load("L1Trigger.TrackerDTC.ProducerED_cff")
36+
process.load("L1Trigger.TrackerDTC.DTC_cff")
3837
process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")
3938

4039
process.l1tLayer1Barrel9 = process.l1tLayer1Barrel.clone()
@@ -52,7 +51,7 @@
5251
process.PFInputsTask = cms.Task(
5352
process.TTClustersFromPhase2TrackerDigis,
5453
process.TTStubsFromPhase2TrackerDigis,
55-
process.TrackerDTCProducer,
54+
process.ProducerDTC,
5655
process.offlineBeamSpot,
5756
process.l1tTTTracksFromTrackletEmulation,
5857
process.SimL1EmulatorTask

L1Trigger/Phase2L1ParticleFlow/test/make_l1ct_patternFiles_fromRAW_cfg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
process.load('Configuration.StandardSequences.SimL1Emulator_cff')
3434
process.load('L1Trigger.TrackTrigger.TrackTrigger_cff')
3535
process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff")
36-
process.load("L1Trigger.TrackerDTC.ProducerES_cff")
37-
process.load("L1Trigger.TrackerDTC.ProducerED_cff")
36+
process.load("L1Trigger.TrackerDTC.DTC_cff")
3837
process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")
3938

4039
from L1Trigger.Phase2L1ParticleFlow.l1tSeedConePFJetProducer_cfi import l1tSeedConePFJetEmulatorProducer
@@ -69,7 +68,7 @@
6968
process.PFInputsTask = cms.Task(
7069
process.TTClustersFromPhase2TrackerDigis,
7170
process.TTStubsFromPhase2TrackerDigis,
72-
process.TrackerDTCProducer,
71+
process.ProducerDTC,
7372
process.offlineBeamSpot,
7473
process.l1tTTTracksFromTrackletEmulation,
7574
process.SimL1EmulatorTask

0 commit comments

Comments
 (0)