Skip to content

Commit

Permalink
kf bug fixes, f/w sync. (cms-sw#188)
Browse files Browse the repository at this point in the history
* kf bug fixes, f/w sync.

* updated reduced dat files and channel assignment.

* correct channel assignment.

* reduced dat files deleted.
  • Loading branch information
tschuh committed Oct 28, 2022
1 parent dce8511 commit 36af472
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 49 deletions.
2 changes: 1 addition & 1 deletion L1Trigger/TrackFindingTracklet/python/Customize_cff.py
Expand Up @@ -24,7 +24,7 @@ def reducedConfig(process):
# this are tt::Setup::dtcId in order as in process.TTTracksFromTrackletEmulation.processingModulesFile translated by
# reverssing naming logic described in L1FPGATrackProducer
# TO DO: Eliminate cfg param IRChannelsIn by taking this info from Tracklet wiring map.
process.ChannelAssignment.IRChannelsIn = cms.vint32( 0, 1, 25, 2, 26, 4, 28, 5, 29, 6, 30, 7, 31, 8, 32, 9, 33 )
process.ChannelAssignment.IRChannelsIn = cms.vint32( 0, 1, 25, 2, 26, 4, 5, 29, 6, 30, 7, 31, 8, 9, 33 )
process.TTTracksFromTrackletEmulation.Reduced = True
process.TTTracksFromTrackletEmulation.memoryModulesFile = 'L1Trigger/TrackFindingTracklet/data/reduced_memorymodules.dat'
process.TTTracksFromTrackletEmulation.processingModulesFile = 'L1Trigger/TrackFindingTracklet/data/reduced_processingmodules.dat'
Expand Down
6 changes: 3 additions & 3 deletions L1Trigger/TrackFindingTracklet/python/Demonstrator_cfi.py
Expand Up @@ -3,9 +3,9 @@

TrackTriggerDemonstrator_params = cms.PSet (

LabelIn = cms.string( "TrackFindingTrackletProducerTBout" ), #
LabelOut = cms.string( "TrackFindingTrackletProducerKFin" ), #
DirIPBB = cms.string( "/heplnw039/tschuh/work/proj/kfin/" ), # path to ipbb proj area
LabelIn = cms.string( "TrackFindingTrackletProducerIRin" ), #
LabelOut = cms.string( "TrackFindingTrackletProducerTBout" ), #
DirIPBB = cms.string( "/heplnw039/tschuh/work/proj/IRinTBout/" ), # path to ipbb proj area
RunTime = cms.double( 8.0 ) # runtime in us

)
6 changes: 3 additions & 3 deletions L1Trigger/TrackFindingTracklet/test/demonstrator_cfg.py
Expand Up @@ -24,8 +24,8 @@
#--- Load code that compares s/w with f/w
process.load( 'L1Trigger.TrackFindingTracklet.Demonstrator_cff' )
from L1Trigger.TrackFindingTracklet.Customize_cff import *
#reducedConfig( process )
fwConfig( process )
reducedConfig( process )
#fwConfig( process )

# build schedule
process.tt = cms.Sequence ( process.TrackerDTCProducer
Expand Down Expand Up @@ -67,7 +67,7 @@
process.source = cms.Source(
"PoolSource",
fileNames = cms.untracked.vstring( options.inputMC ),
#skipEvents = cms.untracked.uint32( 993 ),
skipEvents = cms.untracked.uint32( 1 ),
secondaryFileNames = cms.untracked.vstring(),
duplicateCheckMode = cms.untracked.string( 'noDuplicateCheck' )
)
Expand Down
2 changes: 1 addition & 1 deletion L1Trigger/TrackerTFP/interface/Demonstrator.h
Expand Up @@ -39,7 +39,7 @@ namespace trackerTFP {
// creates frame number
std::string frame(int& nFrame) const;
// converts bv into hex
std::string hex(const tt::Frame& bv) const;
std::string hex(const tt::Frame& bv, bool first = false) const;

// path to ipbb proj area
std::string dirIPBB_;
Expand Down
4 changes: 2 additions & 2 deletions L1Trigger/TrackerTFP/interface/State.h
Expand Up @@ -82,8 +82,8 @@ namespace trackerTFP {
double v1() const { return pow(stub_->dZ(), 2); }
// output frame
tt::FrameTrack frame() const { return TrackKF(*track_, x1_, x0_, x3_, x2_).frame(); }
// collection of stubs added so far to state
std::vector<StubKF> stubs() const;
// fill collection of stubs added so far to state
void fill(std::vector<StubKF>& stubs) const;

private:
// provides data fomats
Expand Down
20 changes: 9 additions & 11 deletions L1Trigger/TrackerTFP/src/Demonstrator.cc
Expand Up @@ -57,10 +57,10 @@ namespace trackerTFP {
ss << this->frame(nFrame);
for (int channel = 0; channel < numChannel; channel++) {
const vector<Frame>& bvs = bits[offset + channel];
ss << (frame < (int)bvs.size() ? hex(bvs[frame]) : hex(Frame()));
ss << (frame < (int)bvs.size() ? hex(bvs[frame], frame == 0) : hex(Frame(), frame == 0));
}
for (int channel = 0; channel < voidChannel; channel++)
ss << " 0v" << string(TTBV::S_ / 4, '0');
ss << " 0000 " << string(TTBV::S_ / 4, '0');
ss << endl;
}
}
Expand Down Expand Up @@ -108,15 +108,13 @@ namespace trackerTFP {
string Demonstrator::header(int numLinks) const {
stringstream ss;
// file header
ss << "Board CMSSW" << endl << " Quad/Chan :";
// quad header
for (int link = 0; link < numLinks; link++)
ss << " q" << setfill('0') << setw(2) << link / 4 << "c" << link % 4 << " ";
ss << endl;
ss << "Board CMSSW" << endl
<< "Metadata: (strobe,) start of orbit, start of packet, end of packet, valid" << endl
<< endl;
// link header
ss << " Link :";
for (int link = 0; link < numLinks; link++)
ss << " " << setfill('0') << setw(3) << link << " ";
ss << " " << setfill('0') << setw(3) << link << " ";
ss << endl;
return ss.str();
}
Expand All @@ -127,7 +125,7 @@ namespace trackerTFP {
for (int gap = 0; gap < numFramesInfra_; gap++) {
ss << frame(nFrame);
for (int link = 0; link < numLinks; link++)
ss << " 0v" << string(TTBV::S_ / 4, '0');
ss << " 0000 " << string(TTBV::S_ / 4, '0');
ss << endl;
}
return ss.str();
Expand All @@ -141,9 +139,9 @@ namespace trackerTFP {
}

// converts bv into hex
string Demonstrator::hex(const Frame& bv) const {
string Demonstrator::hex(const Frame& bv, bool first) const {
stringstream ss;
ss << " 1v" << setfill('0') << setw(TTBV::S_ / 4) << std::hex << bv.to_ullong();
ss << (first ? " 1001 " : " 0001 ") << setfill('0') << setw(TTBV::S_ / 4) << std::hex << bv.to_ullong();
return ss.str();
}

Expand Down
29 changes: 13 additions & 16 deletions L1Trigger/TrackerTFP/src/KalmanFilter.cc
Expand Up @@ -146,7 +146,9 @@ namespace trackerTFP {
streamsStubs[offset + layer].reserve(states.size());
for (State* state : states) {
tracks.emplace_back(state->frame());
for (const StubKF& stub : state->stubs())
vector<StubKF> stubs;
state->fill(stubs);
for (const StubKF& stub : stubs)
streamsStubs[offset + stub.layer()].emplace_back(stub.frame());
// adding a gap to all layer without a stub
for (int layer : state->hitPattern().ids(false))
Expand Down Expand Up @@ -225,21 +227,19 @@ namespace trackerTFP {
state = pop_front(stack);
streamOutput.push_back(state);
// The remainder of the code in this loop deals with combinatoric states.
if (state != nullptr)
if (state)
// Assign next combinatoric stub to state
comb(state);
delay.push_back(state);
state = pop_front(delay);
if (state != nullptr)
if (state)
stack.push_back(state);
}
stream = streamOutput;
for (State*& state : stream) {
if (!state || !state->stub() || state->layer() != layer_)
continue;
// Update state with next stub using KF maths
update(state);
}
// Update state with next stub using KF maths
for (State*& state : stream)
if (state && state->stub() && state->layer() == layer_)
update(state);
}

// Assign next combinatoric (i.e. not first in layer) stub to state
Expand All @@ -249,25 +249,22 @@ namespace trackerTFP {
const vector<StubKFin*>& stubs = track->layerStubs(layer_);
const TTBV& hitPattern = state->hitPattern();
StubKFin* stubNext = nullptr;
// Get first stub on this layer if state reached min layers
if (!stub) {
if (hitPattern.count() < setup_->kfMaxLayers() && track->hitPattern(layer_))
stubNext = track->layerStub(layer_);
} else if (stub->layer() == layer_) {
bool valid = state->stub() && state->layer() == layer_;
if (valid) {
// Get next unused stub on this layer
const int pos = distance(stubs.begin(), find(stubs.begin(), stubs.end(), stub)) + 1;
if (pos != (int)stubs.size())
stubNext = stubs[pos];
// picks next stub on different layer, nullifies state if skipping layer is not valid
else {
bool valid(true);
// having already maximum number of added layers
if (hitPattern.count() == setup_->kfMaxLayers())
valid = false;
// Impossible for this state to ever get enough layers to form valid track
if (hitPattern.count() + track->hitPattern().count(stub->layer() + 1, setup_->numLayers()) <
setup_->kfMinLayers())
valid = false;
// not diffrent layers left
if (layer_ == setup_->numLayers() - 1)
valid = false;
if (valid) {
Expand All @@ -281,7 +278,7 @@ namespace trackerTFP {
}
}
}
if (stubNext) {
if (valid) {
// create combinatoric state
states_.emplace_back(state, stubNext);
state = &states_.back();
Expand Down
22 changes: 10 additions & 12 deletions L1Trigger/TrackerTFP/src/State.cc
Expand Up @@ -83,7 +83,7 @@ namespace trackerTFP {
layerMap_[layer] = distance(stubs.begin(), find(stubs.begin(), stubs.end(), stub_));
// pick next stub (first stub in next layer with stub)
stub_ = nullptr;
if (hitPattern_.count() == setup_->kfMinLayers())
if (hitPattern_.count() == setup_->kfMaxLayers())
return;
for (int nextLayer = layer + 1; nextLayer < setup_->numLayers(); nextLayer++) {
if (track_->hitPattern(nextLayer)) {
Expand All @@ -93,30 +93,28 @@ namespace trackerTFP {
}
}

// collection of stubs added so far to state
vector<StubKF> State::stubs() const {
vector<StubKF> stubs;
// fills collection of stubs added so far to state
void State::fill(vector<StubKF>& stubs) const {
stubs.reserve(hitPattern_.count());
State* s = parent_;
while (s) {
stubs.emplace_back(*(s->stub()), x0_, x1_, x2_, x3_);
s = s->parent();
}
return stubs;
}

// Determine quality of completed state
void State::finish() {
const vector<StubKF>& stubs = this->stubs();
auto consistent = [this](int& sum, const StubKF& stub) {
auto inConsistentRange = [](float v, float r, float d) { return abs(v) <= (r + d) / 2.; };
// Check stub consistent with helix, allowing for stub & digi uncertainty
const bool inRange0 =
inConsistentRange(stub.phi(), stub.dPhi(), dataFormats_->format(Variable::dPhi, Process::kf).base());
const bool inRange1 =
inConsistentRange(stub.z(), stub.dZ(), dataFormats_->format(Variable::dZ, Process::kf).base());
static const DataFormat& phi = dataFormats_->format(Variable::phi, Process::kf);
static const DataFormat& z = dataFormats_->format(Variable::z, Process::kf);
// Check stub consistent with helix, allowing for stub uncertainty
const bool inRange0 = 2. * abs(stub.phi()) - stub.dPhi() < phi.base();
const bool inRange1 = 2. * abs(stub.z()) - stub.dZ() < z.base();
return sum += (inRange0 && inRange1 ? 1 : 0);
};
vector<StubKF> stubs;
fill(stubs);
numConsistentLayers_ = accumulate(stubs.begin(), stubs.end(), 0, consistent);
TTBV pattern = hitPattern_;
pattern |= maybePattern();
Expand Down

0 comments on commit 36af472

Please sign in to comment.