diff --git a/L1Trigger/DemonstratorTools/interface/BoardDataReader.h b/L1Trigger/DemonstratorTools/interface/BoardDataReader.h index da180b9bbe9db..c574cdeee32b8 100644 --- a/L1Trigger/DemonstratorTools/interface/BoardDataReader.h +++ b/L1Trigger/DemonstratorTools/interface/BoardDataReader.h @@ -64,4 +64,4 @@ namespace l1t::demo { } // namespace l1t::demo -#endif \ No newline at end of file +#endif diff --git a/L1Trigger/DemonstratorTools/interface/GTTInterface.h b/L1Trigger/DemonstratorTools/interface/GTTInterface.h new file mode 100644 index 0000000000000..bca84920d3326 --- /dev/null +++ b/L1Trigger/DemonstratorTools/interface/GTTInterface.h @@ -0,0 +1,108 @@ +#ifndef L1Trigger_DemonstratorTools_GTTInterface_h +#define L1Trigger_DemonstratorTools_GTTInterface_h + +#include + +#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>> 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> 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 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> kChannelIdsOutputToCorrelator = { + /* logical channel within time slice -> vector of channel indices */ + {{"vertices", 0}, {0}}}; + + static const std::map kChannelSpecsOutputToCorrelator = { + /* interface name -> {link TMUX, inter-packet gap} */ + {"vertices", {kGTTBoardTMUX, kGapLengthOutputToCorrelator}}}; + + //OUTPUTS to Global Trigger + static const std::map> 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 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 diff --git a/L1Trigger/DemonstratorTools/plugins/GTTFileReader.cc b/L1Trigger/DemonstratorTools/plugins/GTTFileReader.cc index 459f79f82a8f0..d9ce88f96b3c6 100644 --- a/L1Trigger/DemonstratorTools/plugins/GTTFileReader.cc +++ b/L1Trigger/DemonstratorTools/plugins/GTTFileReader.cc @@ -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" // @@ -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 L1Track; + typedef std::vector 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 fileReaderOutputToCorrelator_ = std::nullopt; + std::string l1VertexCollectionName_; + std::optional fileReaderInputTracks_ = std::nullopt; + std::string l1TrackCollectionName_; + std::optional fileReaderOutputToGlobalTrigger_ = std::nullopt; }; -// -// class implementation -// - GTTFileReader::GTTFileReader(const edm::ParameterSet& iConfig) - : fileReader_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter("format")), - iConfig.getParameter>("files"), - kFramesPerTMUXPeriod, - kVertexTMUX, - kEmptyFrames, - kChannelSpecs) { - produces(); + : processOutputToCorrelator_(iConfig.getParameter("processOutputToCorrelator")), + processInputTracks_(iConfig.getParameter("processInputTracks")), + processOutputToGlobalTrigger_(iConfig.getParameter("processOutputToGlobalTrigger")), + kEmptyFramesOutputToCorrelator_(iConfig.getUntrackedParameter("kEmptyFramesOutputToCorrelator")), + kEmptyFramesInputTracks_(iConfig.getUntrackedParameter("kEmptyFramesInputTracks")), + kEmptyFramesOutputToGlobalTrigger_( + iConfig.getUntrackedParameter("kEmptyFramesOutputToGlobalTrigger")), + l1VertexCollectionName_(iConfig.getParameter("l1VertexCollectionName")), + l1TrackCollectionName_(iConfig.getParameter("l1TrackCollectionName")) { + if (processOutputToCorrelator_) { + fileReaderOutputToCorrelator_ = + l1t::demo::BoardDataReader(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter("format")), + iConfig.getParameter>("filesOutputToCorrelator"), + l1t::demo::gtt::kFramesPerTMUXPeriod, + l1t::demo::gtt::kGTTBoardTMUX, + kEmptyFramesOutputToCorrelator_, + l1t::demo::gtt::kChannelMapOutputToCorrelator); + produces(l1VertexCollectionName_); + } + if (processInputTracks_) { + fileReaderInputTracks_ = + l1t::demo::BoardDataReader(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter("format")), + iConfig.getParameter>("filesInputTracks"), + l1t::demo::gtt::kFramesPerTMUXPeriod, + l1t::demo::gtt::kGTTBoardTMUX, + kEmptyFramesInputTracks_, + l1t::demo::gtt::kChannelMapInput); + produces(l1TrackCollectionName_); + } + if (processOutputToGlobalTrigger_) { + // fileReaderOutputToGlobalTrigger_ = + // l1t::demo::BoardDataReader(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter("format")), + // iConfig.getParameter>("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(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(vertices), l1VertexCollectionName_); + } // end if ( processOutputToCorrelator_ ) + + if (processInputTracks_ && fileReaderInputTracks_) { + l1t::demo::EventData inputEventData(fileReaderInputTracks_.value().getNextEvent()); + auto inputTracks = std::make_unique(); + 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>("files", + desc.add("processOutputToCorrelator") + ->setComment("boolean flag to load Correlator outputs via BoardDataReader and produce vertex collection"); + desc.add("processInputTracks") + ->setComment("boolean flag to load track inputs via BoardDataReader and produce a TTTrack collection"); + desc.add("processOutputToGlobalTrigger") + ->setComment( + "boolean flag to load Global Trigger outputs via BoardDataReader and produce Track Object collections"); + desc.addUntracked("kEmptyFramesOutputToCorrelator", 0) + ->setComment("empty frames to expect in OutputToCorrelator"); + desc.addUntracked("kEmptyFramesInputTracks", 0)->setComment("empty frames to expect in Track Input"); + desc.addUntracked("kEmptyFramesOutputToGlobalTrigger", 0) + ->setComment("empty frames to expect in OutputToGlobalTrigger"); + desc.add>("filesOutputToCorrelator", + { + "L1GTTOutputToCorrelator_0.txt", + }); + desc.add>("filesInputTracks", + { + "L1GTTInputFile_0.txt", + }); + desc.add>("filesOutputToGlobalTrigger", { - "gttOutput_0.txt", + "L1GTTOutputToGlobalTriggerFile_0.txt", }); desc.addUntracked("format", "APx"); + desc.add("l1VertexCollectionName", "L1VerticesFirmware"); + desc.add("l1TrackCollectionName", "Level1TTTracks"); descriptions.add("GTTFileReader", desc); } diff --git a/L1Trigger/DemonstratorTools/plugins/GTTFileWriter.cc b/L1Trigger/DemonstratorTools/plugins/GTTFileWriter.cc index c79de7f8ee836..009a8a6de2202 100644 --- a/L1Trigger/DemonstratorTools/plugins/GTTFileWriter.cc +++ b/L1Trigger/DemonstratorTools/plugins/GTTFileWriter.cc @@ -42,6 +42,7 @@ #include "DataFormats/L1Trigger/interface/VertexWord.h" #include "L1Trigger/DemonstratorTools/interface/BoardDataWriter.h" +#include "L1Trigger/DemonstratorTools/interface/GTTInterface.h" #include "L1Trigger/DemonstratorTools/interface/codecs/tracks.h" #include "L1Trigger/DemonstratorTools/interface/codecs/vertices.h" #include "L1Trigger/DemonstratorTools/interface/codecs/tkjets.h" @@ -61,61 +62,6 @@ class GTTFileWriter : public edm::one::EDAnalyzer { 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 kGapLengthInput = 6; - static constexpr size_t kGapLengthOutputToCorrelator = 44; - 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; - static constexpr size_t kGTTBoardTMUX = 6; - static constexpr size_t kMaxLinesPerFile = 1024; - - const std::map> kChannelIdsInput = { - /* logical channel within time slice -> vector of channel indices (one entry per time slice) */ - {{"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}}}; - - const std::map kChannelSpecsInput = { - /* interface name -> {link TMUX, inter-packet gap} */ - {"tracks", {kTrackTMUX, kGapLengthInput}}}; - - const std::map>> - kChannelSpecsOutputToCorrelator = { - /* logical channel within time slice -> {{link TMUX, inter-packet gap}, vector of channel indices} */ - {{"vertices", 0}, {{kGTTBoardTMUX, kGapLengthOutputToCorrelator}, {0}}}}; - - const std::map> 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}}}; - - const std::map kChannelSpecsOutputToGlobalTrigger = { - /* interface name -> {link TMUX, inter-packet gap} */ - {"sums", {kGTTBoardTMUX, kGapLengthOutputToGlobalTriggerSums}}, - {"taus", {kGTTBoardTMUX, kGapLengthOutputToGlobalTriggerTaus}}, - {"mesons", {kGTTBoardTMUX, kGapLengthOutputToGlobalTriggerMesons}}, - {"vertices", {kGTTBoardTMUX, kGapLengthOutputToGlobalTriggerVertices}}}; typedef TTTrack Track_t; typedef std::vector TrackCollection_t; @@ -165,51 +111,52 @@ GTTFileWriter::GTTFileWriter(const edm::ParameterSet& iConfig) fileWriterInputTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter("format")), iConfig.getUntrackedParameter("inputFilename"), iConfig.getUntrackedParameter("fileExtension"), - kFramesPerTMUXPeriod, - kGTTBoardTMUX, - kMaxLinesPerFile, - kChannelIdsInput, - kChannelSpecsInput), + l1t::demo::gtt::kFramesPerTMUXPeriod, + l1t::demo::gtt::kGTTBoardTMUX, + l1t::demo::gtt::kMaxLinesPerFile, + l1t::demo::gtt::kChannelIdsInput, + l1t::demo::gtt::kChannelSpecsInput), fileWriterConvertedTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter("format")), iConfig.getUntrackedParameter("inputConvertedFilename"), iConfig.getUntrackedParameter("fileExtension"), - kFramesPerTMUXPeriod, - kGTTBoardTMUX, - kMaxLinesPerFile, - kChannelIdsInput, - kChannelSpecsInput), + l1t::demo::gtt::kFramesPerTMUXPeriod, + l1t::demo::gtt::kGTTBoardTMUX, + l1t::demo::gtt::kMaxLinesPerFile, + l1t::demo::gtt::kChannelIdsInput, + l1t::demo::gtt::kChannelSpecsInput), fileWriterSelectedTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter("format")), iConfig.getUntrackedParameter("selectedTracksFilename"), iConfig.getUntrackedParameter("fileExtension"), - kFramesPerTMUXPeriod, - kGTTBoardTMUX, - kMaxLinesPerFile, - kChannelIdsInput, - kChannelSpecsInput), + l1t::demo::gtt::kFramesPerTMUXPeriod, + l1t::demo::gtt::kGTTBoardTMUX, + l1t::demo::gtt::kMaxLinesPerFile, + l1t::demo::gtt::kChannelIdsInput, + l1t::demo::gtt::kChannelSpecsInput), fileWriterVertexAssociatedTracks_( l1t::demo::parseFileFormat(iConfig.getUntrackedParameter("format")), iConfig.getUntrackedParameter("vertexAssociatedTracksFilename"), iConfig.getUntrackedParameter("fileExtension"), - kFramesPerTMUXPeriod, - kGTTBoardTMUX, - kMaxLinesPerFile, - kChannelIdsInput, - kChannelSpecsInput), + l1t::demo::gtt::kFramesPerTMUXPeriod, + l1t::demo::gtt::kGTTBoardTMUX, + l1t::demo::gtt::kMaxLinesPerFile, + l1t::demo::gtt::kChannelIdsInput, + l1t::demo::gtt::kChannelSpecsInput), fileWriterOutputToCorrelator_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter("format")), iConfig.getUntrackedParameter("outputCorrelatorFilename"), iConfig.getUntrackedParameter("fileExtension"), - kFramesPerTMUXPeriod, - kGTTBoardTMUX, - kMaxLinesPerFile, - kChannelSpecsOutputToCorrelator), + l1t::demo::gtt::kFramesPerTMUXPeriod, + l1t::demo::gtt::kGTTBoardTMUX, + l1t::demo::gtt::kMaxLinesPerFile, + l1t::demo::gtt::kChannelIdsOutputToCorrelator, + l1t::demo::gtt::kChannelSpecsOutputToCorrelator), fileWriterOutputToGlobalTrigger_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter("format")), iConfig.getUntrackedParameter("outputGlobalTriggerFilename"), iConfig.getUntrackedParameter("fileExtension"), - kFramesPerTMUXPeriod, - kGTTBoardTMUX, - kMaxLinesPerFile, - kChannelIdsOutputToGlobalTrigger, - kChannelSpecsOutputToGlobalTrigger) {} + l1t::demo::gtt::kFramesPerTMUXPeriod, + l1t::demo::gtt::kGTTBoardTMUX, + l1t::demo::gtt::kMaxLinesPerFile, + l1t::demo::gtt::kChannelIdsOutputToGlobalTrigger, + l1t::demo::gtt::kChannelSpecsOutputToGlobalTrigger) {} void GTTFileWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; diff --git a/L1Trigger/DemonstratorTools/python/l1tGTTFileReader_cfi.py b/L1Trigger/DemonstratorTools/python/l1tGTTFileReader_cfi.py index 10033c8fb738b..8ad98ebe93d91 100644 --- a/L1Trigger/DemonstratorTools/python/l1tGTTFileReader_cfi.py +++ b/L1Trigger/DemonstratorTools/python/l1tGTTFileReader_cfi.py @@ -1,6 +1,16 @@ import FWCore.ParameterSet.Config as cms l1tGTTFileReader = cms.EDProducer('GTTFileReader', - files = cms.vstring("gttOutput_0.txt"), #, "gttOutput_1.txt"), + processOutputToCorrelator = cms.bool(True), + processInputTracks = cms.bool(False), + processOutputToGlobalTrigger = cms.bool(False), #Not fully implemented yet, partial skeleton added + kEmptyFramesOutputToCorrelator = cms.untracked.uint32(0), + kEmptyFramesInputTracks = cms.untracked.uint32(0), + kEmptyFramesOutputToGlobalTrigger = cms.untracked.uint32(0), + filesOutputToCorrelator = cms.vstring("L1GTTOutputToCorrelatorFile_0.txt"), + filesInputTracks = cms.vstring("L1GTTInputFile_0.txt"), + filesOutputToGlobalTrigger = cms.vstring("L1GTTOutputToGlobalTriggerFile_0.txt"), + l1VertexCollectionName = cms.string("L1VerticesFirmware"), + l1TrackCollectionName = cms.string("Level1TTTracks"), format = cms.untracked.string("APx") ) diff --git a/L1Trigger/DemonstratorTools/src/BoardDataReader.cc b/L1Trigger/DemonstratorTools/src/BoardDataReader.cc index 161f62d4974fb..f392c23279ab0 100644 --- a/L1Trigger/DemonstratorTools/src/BoardDataReader.cc +++ b/L1Trigger/DemonstratorTools/src/BoardDataReader.cc @@ -74,15 +74,15 @@ namespace l1t::demo { continue; bool expectValid(((j - framesBeforeFirstPacket) % eventLength) < packetLength); - if (expectValid) { if (not chanData.at(j).valid) throw std::runtime_error("Frame " + std::to_string(j) + " on channel " + std::to_string(indices.at(tmuxIndex)) + - " is invalid, but expected valid frame"); + " is invalid, but expected valid frame (path='" + path + "')"); } else if (chanData.at(j).valid) throw std::runtime_error("Frame " + std::to_string(j) + " on channel " + - std::to_string(indices.at(tmuxIndex)) + " is valid, but expected invalid frame"); + std::to_string(indices.at(tmuxIndex)) + + " is valid, but expected invalid frame (path='" + path + "')"); } } } diff --git a/L1Trigger/DemonstratorTools/src/codecs_vertices.cc b/L1Trigger/DemonstratorTools/src/codecs_vertices.cc index f81e221e5666c..363402b342109 100644 --- a/L1Trigger/DemonstratorTools/src/codecs_vertices.cc +++ b/L1Trigger/DemonstratorTools/src/codecs_vertices.cc @@ -29,14 +29,23 @@ namespace l1t::demo::codecs { for (const auto& x : frames) { if (not x.test(VertexWord::kValidLSB)) break; - - VertexWord v(VertexWord::vtxvalid_t(1), - VertexWord::vtxz0_t(x(VertexWord::kZ0MSB, VertexWord::kZ0LSB)), - VertexWord::vtxmultiplicity_t(x(VertexWord::kNTrackInPVMSB, VertexWord::kNTrackInPVLSB)), - VertexWord::vtxsumpt_t(x(VertexWord::kSumPtMSB, VertexWord::kSumPtLSB)), - VertexWord::vtxquality_t(x(VertexWord::kQualityMSB, VertexWord::kQualityLSB)), - VertexWord::vtxinversemult_t(x(VertexWord::kNTrackOutPVMSB, VertexWord::kNTrackOutPVLSB)), - VertexWord::vtxunassigned_t(x(VertexWord::kUnassignedMSB, VertexWord::kUnassignedLSB))); + VertexWord::vtxvalid_t validWord; + VertexWord::vtxz0_t z0Word; + VertexWord::vtxmultiplicity_t multWord; + VertexWord::vtxsumpt_t sumPtWord; + VertexWord::vtxquality_t qualityWord; + VertexWord::vtxinversemult_t inverseMultWord; + VertexWord::vtxunassigned_t unassignedWord; + + validWord.V = x(VertexWord::kValidMSB, VertexWord::kValidLSB); + z0Word.V = x(VertexWord::kZ0MSB, VertexWord::kZ0LSB); + multWord.V = x(VertexWord::kNTrackInPVMSB, VertexWord::kNTrackInPVLSB); + sumPtWord.V = x(VertexWord::kSumPtMSB, VertexWord::kSumPtLSB); + qualityWord.V = x(VertexWord::kQualityMSB, VertexWord::kQualityLSB); + inverseMultWord.V = x(VertexWord::kNTrackOutPVMSB, VertexWord::kNTrackOutPVLSB); + unassignedWord.V = x(VertexWord::kUnassignedMSB, VertexWord::kUnassignedLSB); + + VertexWord v(validWord, z0Word, multWord, sumPtWord, qualityWord, qualityWord, unassignedWord); vertices.push_back(v); } diff --git a/L1Trigger/DemonstratorTools/test/gtt/createFirmwareInputFiles_cfg.py b/L1Trigger/DemonstratorTools/test/gtt/createFirmwareInputFiles_cfg.py index 293efb9de91e4..cb51e15320174 100644 --- a/L1Trigger/DemonstratorTools/test/gtt/createFirmwareInputFiles_cfg.py +++ b/L1Trigger/DemonstratorTools/test/gtt/createFirmwareInputFiles_cfg.py @@ -25,9 +25,26 @@ VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "Number of streams to run") +options.register ('tracks', + 'donotload', # default value + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.string, + "Whether to load tracks from buffers and how to treat them in the processing chain ('donotload', 'load', 'overwrite')") +options.register ('vertices', + 'donotload', # default value + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.string, + "Whether to load vertices from buffers and how to treat them in the processing chain ('donotload', 'load', 'overwrite')") +options.register ('readerformat', + 'EMPv2', # default value + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.string, + "File format of loaded tracks and vertices (APx, EMPv2)") options.parseArguments() inputFiles = [] +inputBuffers = [] +inputTrackBuffers = [] for filePath in options.inputFiles: if filePath.endswith(".root"): inputFiles.append(filePath) @@ -36,11 +53,18 @@ filePath = filePath.replace("/", ".") inputFilesImport = getattr(__import__(filePath.strip(".py"),fromlist=["readFiles"]),"readFiles") inputFiles.extend( inputFilesImport ) + if options.vertices: + inputBuffersImport = getattr(__import__(filePath.strip(".py"),fromlist=["correlator_source"]),"correlator_source").fileNames + inputBuffers.extend( inputBuffersImport ) + if options.tracks: + inputTrackBuffersImport = getattr(__import__(filePath.strip(".py"),fromlist=["track_source"]),"track_source").fileNames + inputTrackBuffers.extend( inputTrackBuffersImport ) else: inputFiles += FileUtils.loadListFromFile(filePath) # PART 2: SETUP MAIN CMSSW PROCESS + process = cms.Process("GTTFileWriter") process.load('Configuration.Geometry.GeometryExtended2026D88Reco_cff') @@ -69,8 +93,20 @@ process.load('L1Trigger.L1TTrackMatch.l1tTrackerEmuHTMiss_cfi') process.load('L1Trigger.L1TTrackMatch.l1tTrackerEmuEtMiss_cfi') process.load('L1Trigger.DemonstratorTools.l1tGTTFileWriter_cfi') - +process.load('L1Trigger.DemonstratorTools.l1tGTTFileReader_cfi') + +process.l1tGTTFileReader.processOutputToCorrelator = cms.bool((options.vertices in ['load', 'overwrite'])) +process.l1tGTTFileReader.processInputTracks = cms.bool((options.tracks in ['load', 'overwrite'])) +process.l1tGTTFileReader.processOutputToGlobalTrigger = cms.bool(False) #NotImplemented +process.l1tGTTFileReader.filesOutputToCorrelator = inputBuffers if (options.vertices in ['load', 'overwrite']) else cms.vstring("L1GTTOutputToCorrelatorFile_0.txt") +process.l1tGTTFileReader.filesInputTracks = inputTrackBuffers if (options.tracks in ['load', 'overwrite']) else cms.vstring("L1GTTInputFile_0.txt") +process.l1tGTTFileReader.filesOutputToGlobalTrigger = cms.vstring("L1GTTOutputToGlobalTriggerFile_0.txt") +process.l1tGTTFileReader.format = cms.untracked.string(options.readerformat) + process.l1tGTTInputProducer.debug = cms.int32(options.debug) +if (options.tracks in ['overwrite']): + process.l1tGTTInputProducer.l1TracksInputTag = cms.InputTag("l1tGTTFileReader", "Level1TTTracks") + process.l1tGTTInputProducer.setTrackWordBits = cms.bool(False) process.l1tTrackSelectionProducer.processSimulatedTracks = cms.bool(False) process.l1tVertexFinderEmulator.VertexReconstruction.VxMinTrackPt = cms.double(0.0) @@ -104,7 +140,6 @@ process.l1tTrackerEmuHTMiss.debug = (options.debug > 0) #Disable internal track selection -#There is a problem with setting all of these (especially eta) to high numbers. process.l1tTrackJetsEmulation.trk_zMax = cms.double(20.46912512) # maximum track z from TrackWord if options.debug: @@ -115,10 +150,16 @@ ) process.l1tGTTFileWriter.format = cms.untracked.string(options.format) #FIXME Put all this into the default GTTFileWriter -process.l1tGTTFileWriter.tracks = cms.untracked.InputTag("l1tTTTracksFromTrackletEmulation", "Level1TTTracks") +if options.tracks == 'overwrite': + process.l1tGTTFileWriter.tracks = cms.untracked.InputTag("l1tGTTFileReader", "Level1TTTracks") +else: + process.l1tGTTFileWriter.tracks = cms.untracked.InputTag("l1tTTTracksFromTrackletEmulation", "Level1TTTracks") process.l1tGTTFileWriter.convertedTracks = cms.untracked.InputTag("l1tGTTInputProducer", "Level1TTTracksConverted") process.l1tGTTFileWriter.selectedTracks = cms.untracked.InputTag("l1tTrackSelectionProducer", "Level1TTTracksSelectedEmulation") -process.l1tGTTFileWriter.vertices = cms.untracked.InputTag("l1tVertexFinderEmulator", "L1VerticesEmulation") +if options.vertices == 'overwrite': + process.l1tGTTFileWriter.vertices = cms.untracked.InputTag("l1tGTTFileReader", "L1VerticesFirmware") +else: + process.l1tGTTFileWriter.vertices = cms.untracked.InputTag("l1tVertexFinderEmulator", "L1VerticesEmulation") process.l1tGTTFileWriter.vertexAssociatedTracks = cms.untracked.InputTag("l1tTrackVertexAssociationProducer", "Level1TTTracksSelectedAssociatedEmulation") process.l1tGTTFileWriter.jets = cms.untracked.InputTag("l1tTrackJetsEmulation","L1TrackJets") process.l1tGTTFileWriter.htmiss = cms.untracked.InputTag("l1tTrackerEmuHTMiss", "L1TrackerEmuHTMiss") @@ -131,8 +172,10 @@ process.MessageLogger.cerr.FwkReport.reportEvery = 1 process.Timing = cms.Service("Timing", summaryOnly = cms.untracked.bool(True)) - -process.p = cms.Path(process.l1tGTTFileWriter) +if options.tracks in ['load', 'overwrite'] or options.vertices in ['load', 'overwrite']: + process.p = cms.Path(process.l1tGTTFileReader * process.l1tGTTFileWriter) +else: + process.p = cms.Path(process.l1tGTTFileWriter) process.p.associate(cms.Task(process.l1tGTTInputProducer, process.l1tTrackSelectionProducer, process.l1tVertexFinderEmulator, diff --git a/L1Trigger/L1TTrackMatch/plugins/L1GTTInputProducer.cc b/L1Trigger/L1TTrackMatch/plugins/L1GTTInputProducer.cc index 5074ec2c2cec1..0833f7dd6af6e 100644 --- a/L1Trigger/L1TTrackMatch/plugins/L1GTTInputProducer.cc +++ b/L1Trigger/L1TTrackMatch/plugins/L1GTTInputProducer.cc @@ -112,6 +112,7 @@ class L1GTTInputProducer : public edm::global::EDProducer<> { // ----------member data --------------------------- const edm::EDGetTokenT l1TracksToken_; const std::string outputCollectionName_; + bool setTrackWordBits_; int debug_; std::vector pt_lut_; std::vector eta_lut_; @@ -123,6 +124,7 @@ class L1GTTInputProducer : public edm::global::EDProducer<> { L1GTTInputProducer::L1GTTInputProducer(const edm::ParameterSet& iConfig) : l1TracksToken_(consumes(iConfig.getParameter("l1TracksInputTag"))), outputCollectionName_(iConfig.getParameter("outputCollectionName")), + setTrackWordBits_(iConfig.getParameter("setTrackWordBits")), debug_(iConfig.getParameter("debug")) { // Generate the required luts generate_eta_lut(); @@ -429,7 +431,7 @@ void L1GTTInputProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::E vPtOutput->reserve(nOutput); vEtaOutput->reserve(nOutput); for (const auto& track : *l1TracksHandle) { - if (!(track.nFitPars() == Npars4 || track.nFitPars() == Npars5)) { + if (setTrackWordBits_ && !(track.nFitPars() == Npars4 || track.nFitPars() == Npars5)) { throw cms::Exception("nFitPars unknown") << "L1GTTInputProducer::produce method is called with numFitPars_ = " << track.nFitPars() << ". The only possible values are 4/5."; @@ -439,12 +441,13 @@ void L1GTTInputProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::E vTTTrackOutput->push_back(track); auto& currentTrackRef = vTTTrackOutput->back(); if (debug_ >= 2) { - edm::LogInfo("L1GTTInputProducer") << "produce::word before anything " - << currentTrackRef.getTrackWord().to_string(2); + edm::LogInfo("L1GTTInputProducer") << "produce::word before anything with setTrackWordBits_ = " + << setTrackWordBits_ << ": " << currentTrackRef.getTrackWord().to_string(2); } // Do an initial setting of the bits based on the floating point values - currentTrackRef.setTrackWordBits(); + if (setTrackWordBits_) + currentTrackRef.setTrackWordBits(); if (debug_ >= 2) { edm::LogInfo("L1GTTInputProducer") << "produce::word after initial setting of the track word " << currentTrackRef.getTrackWord().to_string(2); @@ -531,6 +534,10 @@ void L1GTTInputProducer::fillDescriptions(edm::ConfigurationDescriptions& descri desc.add("debug", 0)->setComment("Verbosity levels: 0, 1, 2, 3"); desc.add("l1TracksInputTag", edm::InputTag("TTTracksFromTrackletEmulation", "Level1TTTracks")); desc.add("outputCollectionName", "Level1TTTracksConverted"); + desc.add("setTrackWordBits", true) + ->setComment( + "flag indicated whether the TTTrack_TrackWord should be set from float parameters or skipped (if TrackWord " + "set by e.g. GTTFileReader decoding)"); descriptions.addWithDefaultLabel(desc); } diff --git a/L1Trigger/L1TTrackMatch/python/l1tGTTInputProducer_cfi.py b/L1Trigger/L1TTrackMatch/python/l1tGTTInputProducer_cfi.py index 48714cf2597c4..687399712f7e8 100644 --- a/L1Trigger/L1TTrackMatch/python/l1tGTTInputProducer_cfi.py +++ b/L1Trigger/L1TTrackMatch/python/l1tGTTInputProducer_cfi.py @@ -3,11 +3,13 @@ l1tGTTInputProducer = cms.EDProducer('L1GTTInputProducer', l1TracksInputTag = cms.InputTag("l1tTTTracksFromTrackletEmulation", "Level1TTTracks"), outputCollectionName = cms.string("Level1TTTracksConverted"), + setTrackWordBits = cms.bool(True), debug = cms.int32(0) # Verbosity levels: 0, 1, 2, 3 ) l1tGTTInputProducerExtended = cms.EDProducer('L1GTTInputProducer', l1TracksInputTag = cms.InputTag("l1tTTTracksFromExtendedTrackletEmulation", "Level1TTTracks"), outputCollectionName = cms.string("Level1TTTracksExtendedConverted"), + setTrackWordBits = cms.bool(True), debug = cms.int32(0) # Verbosity levels: 0, 1, 2, 3 )