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

Phase 2 Integration GTTFileReader expansion and refactor #43968

Merged
merged 24 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c38363f
update config in firmware workflow
cgsavard Nov 30, 2023
79543b0
Temporary fix to broken ingestion, no empty frames; should be configu…
Oct 26, 2023
ec230ad
Fix VertexWord creation, direct instantiation from words produces sa…
Oct 27, 2023
9ea9345
Add path for runtime_error if BoardDataReader finds improperly format…
Oct 27, 2023
314ea0c
Update GTTFileReader to load and produce collection of fixed Vertices
Oct 27, 2023
210a9fa
progress towards loading tracks through another reader
Oct 27, 2023
b2cbb0b
checkpoint for adding tracks to GTTFileReader, include renaming of fi…
Oct 28, 2023
b0bf392
Add track decoding with manual word setting and updated gttLinkID met…
Oct 31, 2023
6b469c6
setTrackWordBits as a boolean for l1tGTTInputProducer, which must be …
Oct 31, 2023
1ee0e82
Update gttLinkID and inverse functions in codecs
Nov 1, 2023
56803d1
code-checks and code-format for GTTFileReader updates
Nov 1, 2023
07b3146
Checkpoint factorize GTTInterface.h common elements for GTTFileReader
Nov 2, 2023
23bfbfa
Checkpoint factorize GTTInterface.h common elements for GTTFileWriter
Nov 2, 2023
c2dcf41
Add GTTInterface.h
Nov 2, 2023
296a94f
Add default constructor for BoardDataReader
Nov 2, 2023
ffb9fc9
Remove prototype constants, apply code-format, remove unused code
Nov 2, 2023
9884b0d
Remove unused GTTFileWriter, now in GTTInterface.h
Nov 2, 2023
7ba3ee5
Remove unused GTTFileReader constants, now in GTTInterface.h, add opt…
Nov 2, 2023
1931f4f
Add optional input capability parameters for the GTTFileReader into t…
Nov 2, 2023
2a336c9
Add GTTFileReader loading and overwriting for tracks and vertices as …
Dec 1, 2023
91e541a
code-format of GTTFileReader got lost somewhere in the re-re-re-rebasing
Dec 15, 2023
4d84a03
Use named constant for loop over tracks
Jan 13, 2024
e6e14d6
add gtt to l1t::demo::gtt namespace of constants, switch from combine…
Feb 6, 2024
4c0b06b
Switch to std::optional and remove default constructor for BoardDataR…
Feb 7, 2024
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
2 changes: 1 addition & 1 deletion L1Trigger/DemonstratorTools/interface/BoardDataReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ namespace l1t::demo {

} // namespace l1t::demo

#endif
#endif
108 changes: 108 additions & 0 deletions L1Trigger/DemonstratorTools/interface/GTTInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#ifndef L1Trigger_DemonstratorTools_GTTInterface_h
#define L1Trigger_DemonstratorTools_GTTInterface_h

#include <cstddef>

#include "L1Trigger/DemonstratorTools/interface/LinkId.h"
#include "L1Trigger/DemonstratorTools/interface/ChannelSpec.h"
#include "L1Trigger/DemonstratorTools/interface/EventData.h"
#include "L1Trigger/DemonstratorTools/interface/FileFormat.h"
#include "L1Trigger/DemonstratorTools/interface/Frame.h"

namespace l1t::demo::gtt {
// map of logical channel ID -> [TMUX period, interpacket-gap & offset; channel indices]
typedef std::map<LinkId, std::pair<ChannelSpec, std::vector<size_t>>> ChannelMap_t;

static constexpr size_t kFramesPerTMUXPeriod = 9;
static constexpr size_t kGapLengthInput = 6; //defined in terms of nTracks * (3/2) - 3 * 54?
static constexpr size_t kGapLengthOutputToCorrelator = 44; //can be defined in terms of 54 - nVertices?
static constexpr size_t kGapLengthOutputToGlobalTriggerSums = 3;
static constexpr size_t kGapLengthOutputToGlobalTriggerTaus = 36;
static constexpr size_t kGapLengthOutputToGlobalTriggerMesons = 15;
static constexpr size_t kGapLengthOutputToGlobalTriggerVertices = 6;
static constexpr size_t kTrackTMUX = 18; //TMUX of the TrackFindingProcessors
static constexpr size_t kGTTBoardTMUX =
6; //TMUX of the GTT in the current configuration: 6 boards running 3 events in parallel, with a paired board running parallel algorithms
static constexpr size_t kMaxLinesPerFile = 1024;

static constexpr size_t kVertexChanIndex = 0;

// TRACKS from TFP
static const std::map<l1t::demo::LinkId, std::vector<size_t>> kChannelIdsInput = {
/* logical channel within time slice -> vector of channel indices (one entry per time slice) */
/* for first link in a time slice, the channel index is 1 for 1st time slice, channel 19 in the 2nd*/
{{"tracks", 0}, {0, 18, 36}},
{{"tracks", 1}, {1, 19, 37}},
{{"tracks", 2}, {2, 20, 38}},
{{"tracks", 3}, {3, 21, 39}},
{{"tracks", 4}, {4, 22, 40}},
{{"tracks", 5}, {5, 23, 41}},
{{"tracks", 6}, {6, 24, 42}},
{{"tracks", 7}, {7, 25, 43}},
{{"tracks", 8}, {8, 26, 44}},
{{"tracks", 9}, {9, 27, 45}},
{{"tracks", 10}, {10, 28, 46}},
{{"tracks", 11}, {11, 29, 47}},
{{"tracks", 12}, {12, 30, 48}},
{{"tracks", 13}, {13, 31, 49}},
{{"tracks", 14}, {14, 32, 50}},
{{"tracks", 15}, {15, 33, 51}},
{{"tracks", 16}, {16, 34, 52}},
{{"tracks", 17}, {17, 35, 53}}};

static const ChannelMap_t kChannelMapInput = {
/* logical channel within time slice -> {{link TMUX, inter-packet gap}, vector of channel indices} */
{{"tracks", 0}, {{kTrackTMUX, kGapLengthInput}, {0, 18, 36}}},
{{"tracks", 1}, {{kTrackTMUX, kGapLengthInput}, {1, 19, 37}}},
{{"tracks", 2}, {{kTrackTMUX, kGapLengthInput}, {2, 20, 38}}},
{{"tracks", 3}, {{kTrackTMUX, kGapLengthInput}, {3, 21, 39}}},
{{"tracks", 4}, {{kTrackTMUX, kGapLengthInput}, {4, 22, 40}}},
{{"tracks", 5}, {{kTrackTMUX, kGapLengthInput}, {5, 23, 41}}},
{{"tracks", 6}, {{kTrackTMUX, kGapLengthInput}, {6, 24, 42}}},
{{"tracks", 7}, {{kTrackTMUX, kGapLengthInput}, {7, 25, 43}}},
{{"tracks", 8}, {{kTrackTMUX, kGapLengthInput}, {8, 26, 44}}},
{{"tracks", 9}, {{kTrackTMUX, kGapLengthInput}, {9, 27, 45}}},
{{"tracks", 10}, {{kTrackTMUX, kGapLengthInput}, {10, 28, 46}}},
{{"tracks", 11}, {{kTrackTMUX, kGapLengthInput}, {11, 29, 47}}},
{{"tracks", 12}, {{kTrackTMUX, kGapLengthInput}, {12, 30, 48}}},
{{"tracks", 13}, {{kTrackTMUX, kGapLengthInput}, {13, 31, 49}}},
{{"tracks", 14}, {{kTrackTMUX, kGapLengthInput}, {14, 32, 50}}},
{{"tracks", 15}, {{kTrackTMUX, kGapLengthInput}, {15, 33, 51}}},
{{"tracks", 16}, {{kTrackTMUX, kGapLengthInput}, {16, 34, 52}}},
{{"tracks", 17}, {{kTrackTMUX, kGapLengthInput}, {17, 35, 53}}}};

static const std::map<std::string, l1t::demo::ChannelSpec> kChannelSpecsInput = {
/* interface name -> {link TMUX, inter-packet gap} */
{"tracks", {kTrackTMUX, kGapLengthInput}}};

//OUTPUTS to Correlator
static const ChannelMap_t kChannelMapOutputToCorrelator = {
/* logical channel within time slice -> {{link TMUX, inter-packet gap}, vector of channel indices} */
{{"vertices", 0}, {{kGTTBoardTMUX, kGapLengthOutputToCorrelator}, {0}}}};

static const std::map<l1t::demo::LinkId, std::vector<size_t>> kChannelIdsOutputToCorrelator = {
/* logical channel within time slice -> vector of channel indices */
{{"vertices", 0}, {0}}};

static const std::map<std::string, l1t::demo::ChannelSpec> kChannelSpecsOutputToCorrelator = {
/* interface name -> {link TMUX, inter-packet gap} */
{"vertices", {kGTTBoardTMUX, kGapLengthOutputToCorrelator}}};

//OUTPUTS to Global Trigger
static const std::map<l1t::demo::LinkId, std::vector<size_t>> kChannelIdsOutputToGlobalTrigger = {
/* logical channel within time slice -> vector of channel indices (one entry per time slice) */
{{"sums", 0}, {0}},
{{"taus", 1}, {1}},
{{"mesons", 2}, {2}},
{{"vertices", 3}, {3}}};

static const std::map<std::string, l1t::demo::ChannelSpec> kChannelSpecsOutputToGlobalTrigger = {
/* interface name -> {link TMUX, inter-packet gap} */
{"sums", {kGTTBoardTMUX, kGapLengthOutputToGlobalTriggerSums}},
{"taus", {kGTTBoardTMUX, kGapLengthOutputToGlobalTriggerTaus}},
{"mesons", {kGTTBoardTMUX, kGapLengthOutputToGlobalTriggerMesons}},
{"vertices", {kGTTBoardTMUX, kGapLengthOutputToGlobalTriggerVertices}}};

} // namespace l1t::demo::gtt

#endif
149 changes: 117 additions & 32 deletions L1Trigger/DemonstratorTools/plugins/GTTFileReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
#include "FWCore/Utilities/interface/StreamID.h"

#include "DataFormats/L1Trigger/interface/Vertex.h"
#include "L1Trigger/DemonstratorTools/interface/GTTInterface.h"
#include "L1Trigger/DemonstratorTools/interface/BoardDataReader.h"
#include "L1Trigger/DemonstratorTools/interface/codecs/vertices.h"
#include "L1Trigger/DemonstratorTools/interface/codecs/tracks.h"
#include "L1Trigger/DemonstratorTools/interface/utilities.h"

//
Expand All @@ -48,61 +50,144 @@ class GTTFileReader : public edm::stream::EDProducer<> {

private:
// ----------constants, enums and typedefs ---------
// NOTE: At least some of the info from these constants will eventually come from config files
static constexpr size_t kFramesPerTMUXPeriod = 9;
static constexpr size_t kGapLength = 44;
static constexpr size_t kVertexTMUX = 6;
static constexpr size_t kVertexChanIndex = 0;
static constexpr size_t kEmptyFrames = 10;

const l1t::demo::BoardDataReader::ChannelMap_t kChannelSpecs = {
/* logical channel within time slice -> {{link TMUX, inter-packet gap}, vector of channel indices} */
{{"vertices", 0}, {{kVertexTMUX, kGapLength}, {kVertexChanIndex}}}};
typedef TTTrack<Ref_Phase2TrackerDigi_> L1Track;
typedef std::vector<L1Track> TTTrackCollection;

// ----------member functions ----------------------
void produce(edm::Event&, const edm::EventSetup&) override;

// ----------member data ---------------------------
l1t::demo::BoardDataReader fileReader_;
const bool processOutputToCorrelator_;
const bool processInputTracks_;
const bool processOutputToGlobalTrigger_;
const size_t kEmptyFramesOutputToCorrelator_;
const size_t kEmptyFramesInputTracks_;
const size_t kEmptyFramesOutputToGlobalTrigger_;
std::optional<l1t::demo::BoardDataReader> fileReaderOutputToCorrelator_ = std::nullopt;
std::string l1VertexCollectionName_;
std::optional<l1t::demo::BoardDataReader> fileReaderInputTracks_ = std::nullopt;
std::string l1TrackCollectionName_;
std::optional<l1t::demo::BoardDataReader> fileReaderOutputToGlobalTrigger_ = std::nullopt;
};

//
// class implementation
//

GTTFileReader::GTTFileReader(const edm::ParameterSet& iConfig)
: fileReader_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
iConfig.getParameter<std::vector<std::string>>("files"),
kFramesPerTMUXPeriod,
kVertexTMUX,
kEmptyFrames,
kChannelSpecs) {
produces<l1t::VertexWordCollection>();
: processOutputToCorrelator_(iConfig.getParameter<bool>("processOutputToCorrelator")),
processInputTracks_(iConfig.getParameter<bool>("processInputTracks")),
processOutputToGlobalTrigger_(iConfig.getParameter<bool>("processOutputToGlobalTrigger")),
kEmptyFramesOutputToCorrelator_(iConfig.getUntrackedParameter<unsigned int>("kEmptyFramesOutputToCorrelator")),
kEmptyFramesInputTracks_(iConfig.getUntrackedParameter<unsigned int>("kEmptyFramesInputTracks")),
kEmptyFramesOutputToGlobalTrigger_(
iConfig.getUntrackedParameter<unsigned int>("kEmptyFramesOutputToGlobalTrigger")),
l1VertexCollectionName_(iConfig.getParameter<std::string>("l1VertexCollectionName")),
l1TrackCollectionName_(iConfig.getParameter<std::string>("l1TrackCollectionName")) {
if (processOutputToCorrelator_) {
fileReaderOutputToCorrelator_ =
l1t::demo::BoardDataReader(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
iConfig.getParameter<std::vector<std::string>>("filesOutputToCorrelator"),
l1t::demo::gtt::kFramesPerTMUXPeriod,
l1t::demo::gtt::kGTTBoardTMUX,
kEmptyFramesOutputToCorrelator_,
l1t::demo::gtt::kChannelMapOutputToCorrelator);
produces<l1t::VertexWordCollection>(l1VertexCollectionName_);
}
if (processInputTracks_) {
fileReaderInputTracks_ =
l1t::demo::BoardDataReader(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
iConfig.getParameter<std::vector<std::string>>("filesInputTracks"),
l1t::demo::gtt::kFramesPerTMUXPeriod,
l1t::demo::gtt::kGTTBoardTMUX,
kEmptyFramesInputTracks_,
l1t::demo::gtt::kChannelMapInput);
produces<TTTrackCollection>(l1TrackCollectionName_);
}
if (processOutputToGlobalTrigger_) {
// fileReaderOutputToGlobalTrigger_ =
// l1t::demo::BoardDataReader(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
// iConfig.getParameter<std::vector<std::string>>("filesOutputToGlobalTrigger"),
// l1t::demo::gtt::kFramesPerTMUXPeriod,
// l1t::demo::gtt::kGTTBoardTMUX,
// kEmptyFramesOutputToGlobalTrigger_,
// l1t::demo::gtt::kChannelMapInput);
throw std::invalid_argument("Processing OutputToGlobalTrigger files has not been fully implemented and validated.");
// need to produce output collections for Prompt and Displaced Jets, HTMiss, ETMiss, Taus, Mesons, Vertices, and Isolated Tracks
}
}

// ------------ method called to produce the data ------------
void GTTFileReader::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;
using namespace l1t::demo::codecs;

l1t::demo::EventData eventData(fileReader_.getNextEvent());

l1t::VertexWordCollection vertices(decodeVertices(eventData.at({"vertices", 0})));

edm::LogInfo("GTTFileReader") << vertices.size() << " vertices found";

iEvent.put(std::make_unique<l1t::VertexWordCollection>(vertices));
if (processOutputToCorrelator_ && fileReaderOutputToCorrelator_) {
l1t::demo::EventData correlatorEventData(fileReaderOutputToCorrelator_.value().getNextEvent());
l1t::VertexWordCollection vertices(decodeVertices(correlatorEventData.at({"vertices", 0})));
edm::LogInfo("GTTFileReader") << vertices.size() << " vertices found";

iEvent.put(std::make_unique<l1t::VertexWordCollection>(vertices), l1VertexCollectionName_);
} // end if ( processOutputToCorrelator_ )

if (processInputTracks_ && fileReaderInputTracks_) {
l1t::demo::EventData inputEventData(fileReaderInputTracks_.value().getNextEvent());
auto inputTracks = std::make_unique<TTTrackCollection>();
for (size_t i = 0; i < l1t::demo::gtt::kTrackTMUX; i++) {
auto iTracks = decodeTracks(inputEventData.at({"tracks", i}));
for (auto& trackword : iTracks) {
if (!trackword.getValidWord())
continue;
L1Track track = L1Track(trackword.getValidWord(),
trackword.getRinvWord(),
trackword.getPhiWord(),
trackword.getTanlWord(),
trackword.getZ0Word(),
trackword.getD0Word(),
trackword.getChi2RPhiWord(),
trackword.getChi2RZWord(),
trackword.getBendChi2Word(),
trackword.getHitPatternWord(),
trackword.getMVAQualityWord(),
trackword.getMVAOtherWord());
//retrieve the eta (first) and phi (second) sectors for GTT, encoded in an std::pair
auto sectors = (l1t::demo::codecs::sectorsEtaPhiFromGTTLinkID(i));
track.setEtaSector(sectors.first);
track.setPhiSector(sectors.second);
track.trackWord_ = trackword.trackWord_;
inputTracks->push_back(track);
} //end loop over trackwoards
} // end loop over GTT input links
iEvent.put(std::move(inputTracks), l1TrackCollectionName_);
} // end if ( processInputTracks_ )
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void GTTFileReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
// GTTFileReader
edm::ParameterSetDescription desc;
desc.add<std::vector<std::string>>("files",
desc.add<bool>("processOutputToCorrelator")
->setComment("boolean flag to load Correlator outputs via BoardDataReader and produce vertex collection");
desc.add<bool>("processInputTracks")
->setComment("boolean flag to load track inputs via BoardDataReader and produce a TTTrack collection");
desc.add<bool>("processOutputToGlobalTrigger")
->setComment(
"boolean flag to load Global Trigger outputs via BoardDataReader and produce Track Object collections");
desc.addUntracked<unsigned int>("kEmptyFramesOutputToCorrelator", 0)
->setComment("empty frames to expect in OutputToCorrelator");
desc.addUntracked<unsigned int>("kEmptyFramesInputTracks", 0)->setComment("empty frames to expect in Track Input");
desc.addUntracked<unsigned int>("kEmptyFramesOutputToGlobalTrigger", 0)
->setComment("empty frames to expect in OutputToGlobalTrigger");
desc.add<std::vector<std::string>>("filesOutputToCorrelator",
{
"L1GTTOutputToCorrelator_0.txt",
});
desc.add<std::vector<std::string>>("filesInputTracks",
{
"L1GTTInputFile_0.txt",
});
desc.add<std::vector<std::string>>("filesOutputToGlobalTrigger",
{
"gttOutput_0.txt",
"L1GTTOutputToGlobalTriggerFile_0.txt",
});
desc.addUntracked<std::string>("format", "APx");
desc.add<std::string>("l1VertexCollectionName", "L1VerticesFirmware");
desc.add<std::string>("l1TrackCollectionName", "Level1TTTracks");
descriptions.add("GTTFileReader", desc);
}

Expand Down
Loading