Skip to content

Commit 86590fb

Browse files
jmitrevscerminar
authored andcommitted
Improve TDR regionizer modeling of empty data in packets; fix issues in the review (#24)
Address review comments + fixes for TDR regionizer (not used in default CMSSW configuration)
1 parent 3a51c5d commit 86590fb

File tree

10 files changed

+134
-144
lines changed

10 files changed

+134
-144
lines changed

DataFormats/L1TParticleFlow/interface/layer1_objs.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ namespace l1ct {
5151
float floatEmPt() const { return Scales::floatPt(hwEmPt); }
5252
float floatEta() const { return Scales::floatEta(hwEta); }
5353
float floatPhi() const { return Scales::floatPhi(hwPhi); }
54-
float floatSrrTot() const { return Scales::floatSrrTot(hwSrrTot); };
55-
float floatMeanZ() const { return Scales::floatMeanZ(hwMeanZ); };
56-
float floatHoe() const { return Scales::floatHoe(hwHoe); };
57-
float floatPiProb() const { return Scales::floatIDProb(hwPiProb); };
58-
float floatEmProb() const { return Scales::floatIDProb(hwEmProb); };
59-
float floatPuProb() const { return Scales::floatIDProb(hwPuProb()); };
54+
float floatSrrTot() const { return Scales::floatSrrTot(hwSrrTot); }
55+
float floatMeanZ() const { return Scales::floatMeanZ(hwMeanZ); }
56+
float floatHoe() const { return Scales::floatHoe(hwHoe); }
57+
float floatPiProb() const { return Scales::floatIDProb(hwPiProb); }
58+
float floatEmProb() const { return Scales::floatIDProb(hwEmProb); }
59+
float floatPuProb() const { return Scales::floatIDProb(hwPuProb()); }
6060

6161
bool hwIsEM() const { return hwEmID != 0; }
6262

@@ -220,12 +220,12 @@ namespace l1ct {
220220
float floatPhi() const { return Scales::floatPhi(hwPhi); }
221221
float floatShowerShape() const { return Scales::floatShoweShape(hwShowerShape); }
222222
float floatRelIso() const { return Scales::floatRelIso(hwRelIso); }
223-
float floatSrrTot() const { return Scales::floatSrrTot(hwSrrTot); };
224-
float floatMeanZ() const { return Scales::floatMeanZ(hwMeanZ); };
225-
float floatHoe() const { return Scales::floatHoe(hwHoe); };
226-
float floatPiProb() const { return Scales::floatIDProb(hwPiProb); };
227-
float floatEmProb() const { return Scales::floatIDProb(hwEmProb); };
228-
float floatPuProb() const { return Scales::floatIDProb(hwPuProb()); };
223+
float floatSrrTot() const { return Scales::floatSrrTot(hwSrrTot); }
224+
float floatMeanZ() const { return Scales::floatMeanZ(hwMeanZ); }
225+
float floatHoe() const { return Scales::floatHoe(hwHoe); }
226+
float floatPiProb() const { return Scales::floatIDProb(hwPiProb); }
227+
float floatEmProb() const { return Scales::floatIDProb(hwEmProb); }
228+
float floatPuProb() const { return Scales::floatIDProb(hwPuProb()); }
229229

230230
static const int BITWIDTH_BARREL_SLIM = pt_t::width + pt_t::width + eta_t::width + phi_t::width + emid_t::width;
231231
static const int BITWIDTH_ENDCAP_SLIM =

L1Trigger/Phase2L1ParticleFlow/interface/L1TCorrelatorLayer1PatternFileWriter.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ class L1TCorrelatorLayer1PatternFileWriter {
2727
std::map<l1t::demo::LinkId, std::vector<size_t>> channelIdsInput_, channelIdsOutput_;
2828
std::map<std::string, l1t::demo::ChannelSpec> channelSpecsInput_, channelSpecsOutput_;
2929

30-
const unsigned int tfTmuxFactor_ = 18, tfLinksFactor_ = 1; // numbers not really configurable in current architecture
31-
const unsigned int hgcTmuxFactor_ = 18, hgcLinksFactor_ = 4; // not really configurable in current architecture
32-
const unsigned int gctEmTmuxFactor_ = 6, gctEmLinksFactor_ = 1; // not really configurable in current architecture
33-
const unsigned int gctHadTmuxFactor_ = 6, gctHadLinksFactor_ = 1; // not really configurable in current architecture
34-
const unsigned int gmtTmuxFactor_ = 18, gmtLinksFactor_ = 1; // not really configurable in current architecture
35-
const unsigned int gttTmuxFactor_ = 6, gttLinksFactor_ = 1; // not really configurable in current architecture
30+
// The TmuxFactor represents the Tmux of the inputs. The LinksFactor is the number of links per sector.
31+
// They are not configurable in the current architecture.
32+
const unsigned int tfTmuxFactor_ = 18, tfLinksFactor_ = 1;
33+
const unsigned int hgcTmuxFactor_ = 18, hgcLinksFactor_ = 4;
34+
const unsigned int gctEmTmuxFactor_ = 6, gctEmLinksFactor_ = 1;
35+
const unsigned int gctHadTmuxFactor_ = 6, gctHadLinksFactor_ = 1;
36+
const unsigned int gmtTmuxFactor_ = 18, gmtLinksFactor_ = 1;
37+
const unsigned int gttTmuxFactor_ = 6, gttLinksFactor_ = 1;
3638
const unsigned int tfTimeslices_, hgcTimeslices_, gctEmTimeslices_, gctHadTimeslices_, gmtTimeslices_, gttTimeslices_;
3739
uint32_t gctLinksEcal_, gctLinksHad_;
3840
bool gctSingleLink_;

L1Trigger/Phase2L1ParticleFlow/interface/l1-converters/nn_activation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ namespace nnet {
100100
}
101101

102102
} // namespace nnet
103-
#endif
103+
#endif

L1Trigger/Phase2L1ParticleFlow/interface/regionizer/tdr_regionizer_elements_ref.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ namespace l1ct {
127127
class BufferEntry {
128128
public:
129129
BufferEntry() {}
130-
BufferEntry(const T& obj, std::vector<size_t> srIndices, int glbeta, int glbphi, int locphi, unsigned int clk);
130+
BufferEntry(const T& obj, std::vector<size_t> srIndices, int glbeta, int glbphi, bool duplicate, unsigned int clk);
131131

132132
unsigned int clock() const { return linkobjclk_; }
133133
int nextSR() const { return (objcount_ < srIndices_.size()) ? srIndices_[objcount_] : -1; }
134134
void incSR() { objcount_++; }
135135
int pt() const { return obj_.intPt(); }
136136
int glbPhi() const { return glbphi_; }
137137
int glbEta() const { return glbeta_; }
138-
int sectorLocalPhi() const { return locphi_; }
138+
int duplicate() const { return duplicate_; }
139139

140140
//T obj() { return obj_; }
141141
const T& obj() const { return obj_; }
@@ -146,8 +146,8 @@ namespace l1ct {
146146
std::vector<size_t> srIndices_;
147147
/// The global eta and phi of the object (hard to get with duplicates)
148148
int glbeta_, glbphi_;
149-
/// The local phi relative to the sector (not SR), used for GCT duplicate removal
150-
int locphi_;
149+
/// Is this a duplciate that should be ignored? used for GCT duplicate removal
150+
bool duplicate_;
151151
unsigned int linkobjclk_, objcount_;
152152
};
153153

@@ -161,15 +161,15 @@ namespace l1ct {
161161
std::vector<size_t> srs,
162162
int glbeta,
163163
int glbphi,
164-
int locphi,
165-
unsigned int dupNum,
164+
bool duplicate, // this is mainly for GCT, is it one of the duplicates
165+
unsigned int dupNum, // this is for the (currently unused) feature of multiple buffers per sector
166166
unsigned int ndup);
167167

168168
BufferEntry<T>& front() { return data_.front(); }
169169
const BufferEntry<T>& front() const { return data_.front(); }
170170

171171
/// sets the next time something is taken from this buffer
172-
void updateNextObjectTime(int currentTime);
172+
void updateNextObjectTime(int currentTime, bool incrementTime = true);
173173

174174
/// delete the front element
175175
void pop() { data_.pop_front(); }
@@ -179,7 +179,7 @@ namespace l1ct {
179179
int pt(unsigned int index = 0) const { return data_[index].pt(); }
180180
int glbPhi(unsigned int index = 0) const { return data_[index].glbPhi(); }
181181
int glbEta(unsigned int index = 0) const { return data_[index].glbEta(); }
182-
int sectorLocalPhi(unsigned int index = 0) const { return data_[index].sectorLocalPhi(); }
182+
int duplicate(unsigned int index = 0) const { return data_[index].duplicate(); }
183183

184184
unsigned int numEntries() const { return data_.size(); }
185185

@@ -197,15 +197,14 @@ namespace l1ct {
197197

198198
private:
199199
// used when building up the linkobjclk_ entries for the BufferEntries
200-
unsigned int nextObjClk(unsigned int ndup);
201-
200+
unsigned int nextObjClk(unsigned int ndup, bool skip); // may need to treat pt == 0 and overlap differently
202201
// transient--used only during event construction, not used after
203202
// Counts in 1.39ns increments (i.e. 360 increments by 2, 240 by 3)
204203
unsigned int clkindex360_;
205204
unsigned int clkindex240_;
206205

207-
static unsigned int constexpr INIT360 = 1;
208-
static unsigned int constexpr INIT240 = 0;
206+
static unsigned int constexpr INIT360 = 2;
207+
static unsigned int constexpr INIT240 = 4;
209208

210209
/// The actual data
211210
std::deque<BufferEntry<T>> data_;
@@ -293,7 +292,7 @@ namespace l1ct {
293292
unsigned int maxobjects_;
294293
/// The number of input sectors for this type of device
295294
unsigned int nsectors_;
296-
/// the minimumum phi of this board
295+
/// the minimum phi of this board
297296
int bigRegionMin_;
298297
/// the maximum phi of this board
299298
int bigRegionMax_;
@@ -302,7 +301,7 @@ namespace l1ct {
302301
/// How many buffers per link (default 1)
303302
unsigned int ndup_;
304303

305-
/// the region information assopciated with each input sector
304+
/// the region information associated with each input sector
306305
std::vector<l1ct::PFRegionEmu> sectors_;
307306

308307
/// the region information associated with each SR

L1Trigger/Phase2L1ParticleFlow/interface/regionizer/tdr_regionizer_elements_ref.icc

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,49 +39,54 @@ void l1ct::tdr_regionizer::Pipes<T>::setTaps(size_t taps) {
3939
// BUFFER ENTRY AND BUFFER
4040
template <typename T>
4141
l1ct::tdr_regionizer::BufferEntry<T>::BufferEntry(
42-
const T& obj, std::vector<size_t> srIndices, int glbeta, int glbphi, int locphi, unsigned int clk)
43-
: obj_(obj), srIndices_(srIndices), glbeta_(glbeta), glbphi_(glbphi), locphi_(locphi), linkobjclk_(clk) {
42+
const T& obj, std::vector<size_t> srIndices, int glbeta, int glbphi, bool duplicate, unsigned int clk)
43+
: obj_(obj), srIndices_(srIndices), glbeta_(glbeta), glbphi_(glbphi), duplicate_(duplicate), linkobjclk_(clk) {
4444
objcount_ = 0;
4545
}
4646

4747
template <typename T>
48-
inline void l1ct::tdr_regionizer::Buffer<T>::addEntry(const T& obj,
49-
std::vector<size_t> srIndices,
50-
int glbeta,
51-
int glbphi,
52-
int locphi,
53-
unsigned int dupNum,
54-
unsigned int ndup) {
48+
inline void l1ct::tdr_regionizer::Buffer<T>::addEntry(
49+
const T& obj,
50+
std::vector<size_t> srIndices,
51+
int glbeta,
52+
int glbphi,
53+
bool duplicate, // this is mainly for GCT, is it one of the duplicates
54+
unsigned int dupNum,
55+
unsigned int ndup) {
5556
// dupNum is the duplicate number of this buffer (int range 0 to ndup_-1)
56-
auto objClk = nextObjClk(ndup);
57-
data_.emplace_back(obj, srIndices, glbeta, glbphi, locphi, objClk);
57+
auto objClk = nextObjClk(ndup, obj.intPt() == 0);
58+
data_.emplace_back(obj, srIndices, glbeta, glbphi, duplicate, objClk);
5859
if (timeOfNextObject_ < 0) {
5960
timeOfNextObject_ = objClk;
6061
}
6162
}
6263

6364
template <typename T>
64-
void l1ct::tdr_regionizer::Buffer<T>::updateNextObjectTime(int currTime) {
65+
void l1ct::tdr_regionizer::Buffer<T>::updateNextObjectTime(int currTime, bool incrementTime) {
6566
if (data_.size() > 0) {
66-
timeOfNextObject_ = std::max(front().clock(), static_cast<unsigned int>(currTime + 1));
67+
auto nextTime = incrementTime ? currTime + 1 : currTime;
68+
timeOfNextObject_ = std::max(front().clock(), static_cast<unsigned int>(nextTime));
6769
} else {
6870
timeOfNextObject_ = -1;
6971
}
7072
}
7173

7274
template <typename T>
73-
inline unsigned int l1ct::tdr_regionizer::Buffer<T>::nextObjClk(unsigned int ndup) {
75+
inline unsigned int l1ct::tdr_regionizer::Buffer<T>::nextObjClk(unsigned int ndup, bool skip) {
7476
unsigned int nextVal = std::max(clkindex360_, clkindex240_) / 3;
7577

7678
clkindex360_ += 2 * ndup;
77-
clkindex240_ += 3;
7879

80+
// Though a 360MHz clock is used, one doesn't need to a 240MHz clock for pt == 0
81+
if (!skip) {
82+
clkindex240_ += 3;
83+
}
7984
return nextVal;
8085
}
8186

8287
// explicit for tracks
8388
template <>
84-
inline unsigned int l1ct::tdr_regionizer::Buffer<l1ct::TkObjEmu>::nextObjClk(unsigned int ndup) {
89+
inline unsigned int l1ct::tdr_regionizer::Buffer<l1ct::TkObjEmu>::nextObjClk(unsigned int ndup, bool skip) {
8590
if (ndup != 1) {
8691
throw std::invalid_argument("Only ndup==1 is currently supported for the TkObjEmu buffers.");
8792
}
@@ -93,8 +98,9 @@ inline unsigned int l1ct::tdr_regionizer::Buffer<l1ct::TkObjEmu>::nextObjClk(uns
9398
clkindex360_ += 2;
9499
}
95100

96-
clkindex240_ += 3;
97-
101+
if (!skip) {
102+
clkindex240_ += 3;
103+
}
98104
return nextVal;
99105
}
100106

@@ -173,7 +179,7 @@ void l1ct::tdr_regionizer::Regionizer<T>::initSectors(const std::vector<Detector
173179
// but it's easier to create the inverse, first
174180

175181
if (debug_) {
176-
dbgCout() << "secotors.size() = " << sectors.size() << std::endl;
182+
dbgCout() << "sectors.size() = " << sectors.size() << std::endl;
177183
}
178184

179185
for (const auto& sector : sectors) {
@@ -188,9 +194,6 @@ void l1ct::tdr_regionizer::Regionizer<T>::initSectors(const std::vector<Detector
188194
}
189195
nsectors_ = sectors_.size();
190196
buffers_.resize(nsectors_ * ndup_);
191-
// if (debug_) {
192-
// dbgCout() << "Number of sectors: " << nsectors_ << std::endl;
193-
// }
194197

195198
std::sort(sectorMapLogToPhys_.begin(), sectorMapLogToPhys_.end(), [this](size_t a, size_t b) {
196199
return this->sortSectors(a, b);
@@ -216,6 +219,7 @@ void l1ct::tdr_regionizer::Regionizer<T>::initSectors(const DetectorSector<T>& s
216219
assert(nsectors_ == 0);
217220
nsectors_ = 1;
218221
sectors_.push_back(sector.region);
222+
sectorMapLogToPhys_.push_back(0);
219223
sectorMapPhysToLog_.push_back(0);
220224
buffers_.resize(nsectors_ * ndup_);
221225
if (debug_) {
@@ -292,13 +296,6 @@ void l1ct::tdr_regionizer::Regionizer<T>::initRegions(const std::vector<PFInputR
292296
regions_.resize(regions.size());
293297
for (unsigned int i = 0; i < regions.size(); ++i) {
294298
regions_[i] = regions[i].region;
295-
// if (debug_) {
296-
// dbgCout() << "region eta/phi: " << regions_[i].intEtaCenter() << " " << regions_[i].intPhiCenter()
297-
// << ", eta half width = " << regions_[i].hwEtaHalfWidth.to_int()
298-
// << ", phi half width = " << regions_[i].hwPhiHalfWidth.to_int()
299-
// << ", eta extra = " << regions_[i].hwEtaExtra.to_int()
300-
// << ", phi extra = " << regions_[i].hwPhiExtra.to_int() << std::endl;
301-
// }
302299
if (isInBigRegion(regions_[i])) {
303300
regionmap_.push_back(i);
304301
if (debug_) {
@@ -398,7 +395,13 @@ void l1ct::tdr_regionizer::Regionizer<T>::addToBuffer(const T& obj, unsigned int
398395
auto glbphi = sectors_[sector].hwGlbPhiOf(obj).to_int();
399396
auto glbeta = sectors_[sector].hwGlbEtaOf(obj).to_int();
400397
// get the SR indices that this object should go into
401-
buffers_[buffer].addEntry(obj, getSmallRegions(glbeta, glbphi), glbeta, glbphi, obj.hwPhi.to_int(), dupNum, ndup_);
398+
buffers_[buffer].addEntry(obj,
399+
getSmallRegions(glbeta, glbphi),
400+
glbeta,
401+
glbphi,
402+
isDuplicate(obj.hwPhi.to_int(), logicBuffIndex(buffer)),
403+
dupNum,
404+
ndup_);
402405
}
403406

404407
template <typename T>
@@ -465,16 +468,29 @@ void l1ct::tdr_regionizer::Regionizer<T>::run() {
465468
if (buffer.timeOfNextObject() >= 0) {
466469
processedAll = false;
467470
}
468-
if (buffer.timeOfNextObject() == currTime) {
471+
while (buffer.timeOfNextObject() == currTime) {
469472
// time to handle the buffer entry
470473
const auto nextSR = buffer.front().nextSR();
471474
if (debug_) {
472-
dbgCout() << "Current time " << currTime << ", handling bufIdx " << bufIdx << " object with SR = " << nextSR
473-
<< ", pt = " << buffer.pt() << ", glbeta = " << buffer.glbEta() << ", glbphi = " << buffer.glbPhi()
474-
<< ", local(to link)phi = " << buffer.sectorLocalPhi() << std::endl;
475+
dbgCout() << "Current time " << currTime << ", handling bufIdx " << bufIdx << ", logical "
476+
<< logicBuffIndex(bufIdx) << " object with SR = " << nextSR << ", pt = " << buffer.pt()
477+
<< ", glbeta = " << buffer.glbEta() << ", glbphi = " << buffer.glbPhi()
478+
<< ", duplicate = " << buffer.duplicate() << std::endl;
475479
}
476-
if (nextSR < 0 || buffer.pt() == 0 || smallRegionObjects_[nextSR].size() == maxobjects_ ||
477-
isDuplicate(buffer.sectorLocalPhi(), logicBuffIndex(bufIdx))) {
480+
if (buffer.pt() == 0) { // double check that this also works for tracks
481+
if (debug_) {
482+
dbgCout() << "---Throw out, don't increment time" << std::endl;
483+
}
484+
buffer.pop();
485+
buffer.updateNextObjectTime(currTime, false); // do not increment time
486+
} else if (buffer.duplicate()) {
487+
// remove the whole object, not worrying about nextSR
488+
if (debug_) {
489+
dbgCout() << "---Throw out, duplicate, increment time" << std::endl;
490+
}
491+
buffer.pop();
492+
buffer.updateNextObjectTime(currTime); // do increment time
493+
} else if (nextSR < 0 || smallRegionObjects_[nextSR].size() == maxobjects_) {
478494
// throwout or SR full, just get rid of object
479495
if (debug_) {
480496
dbgCout() << "---Throw out" << std::endl;
@@ -548,7 +564,7 @@ size_t l1ct::tdr_regionizer::Regionizer<T>::logicBuffIndex(size_t bufIdx) const
548564
return logSector * ndup_ + bufIdx % ndup_;
549565
}
550566

551-
// default is no duplicates
567+
// default is no duplicates. Note, locPhi is for the sector, not small region
552568
template <typename T>
553569
bool l1ct::tdr_regionizer::Regionizer<T>::isDuplicate(int locphi, size_t logicBufIdx) const {
554570
return false;
@@ -578,24 +594,24 @@ inline bool l1ct::tdr_regionizer::Regionizer<l1ct::EmCaloObjEmu>::isDuplicate(in
578594
template <typename T>
579595
void l1ct::tdr_regionizer::Regionizer<T>::printDebug(int count) const {
580596
dbgCout() << "BUFFERS, (for " << numBuffers() << " buffers)" << std::endl;
581-
dbgCout() << count << "\tbuffer\tlogical\titem\tpt\teta\tphi\tlocphi\tclock" << std::endl;
597+
dbgCout() << count << "\tbuffer\tlogical\titem\tpt\teta\tphi\tduplicate\tclock" << std::endl;
582598
for (auto sector : sectorMapLogToPhys_) {
583599
for (unsigned int dup = 0; dup < ndup_; dup++) {
584600
const unsigned int buffer = sector * ndup_ + dup;
585601
for (unsigned int j = 0; j < numEntries(buffer); j++) {
586602
dbgCout() << "\t" << buffer << "\t" << logicBuffIndex(buffer) << "\t" << j << "\t" << buffers_[buffer].pt(j)
587603
<< "\t" << buffers_[buffer].glbEta(j) << "\t" << buffers_[buffer].glbPhi(j) << "\t"
588-
<< buffers_[buffer].sectorLocalPhi(j) << "\t" << buffers_[buffer].clock(j) << std::endl;
604+
<< buffers_[buffer].duplicate(j) << "\t" << buffers_[buffer].clock(j) << std::endl;
589605
}
590606
dbgCout() << "-------------------------------" << std::endl;
591607
}
592608
}
593609
dbgCout() << "PIPES, (for " << pipes_.size() << " pipes)" << std::endl;
594610
dbgCout() << count << "\tpipe\ttap\tsr\tpt\teta\tphi" << std::endl;
595-
for (size_t pipe = 0; pipe < pipes_.size(); pipe++) {
596-
for (size_t tap = 0; tap < pipes_.numTaps(); tap++) {
611+
for (int tap = pipes_.numTaps() - 1; tap >= 0; --tap) {
612+
for (int pipe = pipes_.size() - 1; pipe >= 0; --pipe) {
597613
auto entry = pipes_.entry(pipe, tap);
598-
dbgCout() << "\t" << pipe << "\t" << tap << "\t" << entry.sr() << "\t" << entry.pt() << "\t" << entry.glbEta()
614+
dbgCout() << "\t" << pipe << "\t" << tap + 1 << "\t" << entry.sr() << "\t" << entry.pt() << "\t" << entry.glbEta()
599615
<< "\t" << entry.glbPhi() << std::endl;
600616
}
601617
dbgCout() << "-------------------------------" << std::endl;
@@ -634,20 +650,12 @@ std::vector<std::vector<T>> l1ct::tdr_regionizer::Regionizer<T>::fillLinks(
634650
for (const auto& sector : sectors) {
635651
if (isInBigRegionLoose(sector.region)) {
636652
links.emplace_back();
637-
// if (debug_) {
638-
// dbgCout() << "sector.size() = " << sector.size() << std::endl;
639-
// }
640653
for (unsigned int io = 0; io < sector.size() && io < nclocks_; io++) {
641654
links.back().push_back(sector[io]);
642655
}
643656
}
644657
}
645658

646-
// if (debug_) {
647-
// dbgCout() << "fillLinks sectors.size() = " << sectors.size()
648-
// << ", links.size() = " << links.size() << ", links[0].size() = " << links[0].size()<< std::endl;
649-
// }
650-
651659
return links;
652660
}
653661

0 commit comments

Comments
 (0)