File indexing completed on 2024-09-07 04:36:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <memory>
0023
0024
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/stream/EDProducer.h"
0027
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/Utilities/interface/StreamID.h"
0033
0034 #include "DataFormats/L1Trigger/interface/Vertex.h"
0035 #include "L1Trigger/DemonstratorTools/interface/GTTInterface.h"
0036 #include "L1Trigger/DemonstratorTools/interface/BoardDataReader.h"
0037 #include "L1Trigger/DemonstratorTools/interface/codecs/vertices.h"
0038 #include "L1Trigger/DemonstratorTools/interface/codecs/tracks.h"
0039 #include "L1Trigger/DemonstratorTools/interface/utilities.h"
0040
0041
0042
0043
0044
0045 class GTTFileReader : public edm::stream::EDProducer<> {
0046 public:
0047 explicit GTTFileReader(const edm::ParameterSet&);
0048
0049 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0050
0051 private:
0052
0053 typedef TTTrack<Ref_Phase2TrackerDigi_> L1Track;
0054 typedef std::vector<L1Track> TTTrackCollection;
0055
0056
0057 void produce(edm::Event&, const edm::EventSetup&) override;
0058
0059
0060 const bool processOutputToCorrelator_;
0061 const bool processInputTracks_;
0062 const bool processOutputToGlobalTrigger_;
0063 const size_t kEmptyFramesOutputToCorrelator_;
0064 const size_t kEmptyFramesInputTracks_;
0065 const size_t kEmptyFramesOutputToGlobalTrigger_;
0066 std::optional<l1t::demo::BoardDataReader> fileReaderOutputToCorrelator_ = std::nullopt;
0067 std::string l1VertexCollectionName_;
0068 std::optional<l1t::demo::BoardDataReader> fileReaderInputTracks_ = std::nullopt;
0069 std::string l1TrackCollectionName_;
0070 std::optional<l1t::demo::BoardDataReader> fileReaderOutputToGlobalTrigger_ = std::nullopt;
0071 };
0072
0073 GTTFileReader::GTTFileReader(const edm::ParameterSet& iConfig)
0074 : processOutputToCorrelator_(iConfig.getParameter<bool>("processOutputToCorrelator")),
0075 processInputTracks_(iConfig.getParameter<bool>("processInputTracks")),
0076 processOutputToGlobalTrigger_(iConfig.getParameter<bool>("processOutputToGlobalTrigger")),
0077 kEmptyFramesOutputToCorrelator_(iConfig.getUntrackedParameter<unsigned int>("kEmptyFramesOutputToCorrelator")),
0078 kEmptyFramesInputTracks_(iConfig.getUntrackedParameter<unsigned int>("kEmptyFramesInputTracks")),
0079 kEmptyFramesOutputToGlobalTrigger_(
0080 iConfig.getUntrackedParameter<unsigned int>("kEmptyFramesOutputToGlobalTrigger")),
0081 l1VertexCollectionName_(iConfig.getParameter<std::string>("l1VertexCollectionName")),
0082 l1TrackCollectionName_(iConfig.getParameter<std::string>("l1TrackCollectionName")) {
0083 if (processOutputToCorrelator_) {
0084 fileReaderOutputToCorrelator_ =
0085 l1t::demo::BoardDataReader(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
0086 iConfig.getParameter<std::vector<std::string>>("filesOutputToCorrelator"),
0087 l1t::demo::gtt::kFramesPerTMUXPeriod,
0088 l1t::demo::gtt::kGTTBoardTMUX,
0089 kEmptyFramesOutputToCorrelator_,
0090 l1t::demo::gtt::kChannelMapOutputToCorrelator);
0091 produces<l1t::VertexWordCollection>(l1VertexCollectionName_);
0092 }
0093 if (processInputTracks_) {
0094 fileReaderInputTracks_ =
0095 l1t::demo::BoardDataReader(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
0096 iConfig.getParameter<std::vector<std::string>>("filesInputTracks"),
0097 l1t::demo::gtt::kFramesPerTMUXPeriod,
0098 l1t::demo::gtt::kGTTBoardTMUX,
0099 kEmptyFramesInputTracks_,
0100 l1t::demo::gtt::kChannelMapInput);
0101 produces<TTTrackCollection>(l1TrackCollectionName_);
0102 }
0103 if (processOutputToGlobalTrigger_) {
0104
0105
0106
0107
0108
0109
0110
0111 throw std::invalid_argument("Processing OutputToGlobalTrigger files has not been fully implemented and validated.");
0112
0113 }
0114 }
0115
0116
0117 void GTTFileReader::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0118 using namespace edm;
0119 using namespace l1t::demo::codecs;
0120 if (processOutputToCorrelator_ && fileReaderOutputToCorrelator_) {
0121 l1t::demo::EventData correlatorEventData(fileReaderOutputToCorrelator_.value().getNextEvent());
0122 l1t::VertexWordCollection vertices(decodeVertices(correlatorEventData.at({"vertices", 0})));
0123 edm::LogInfo("GTTFileReader") << vertices.size() << " vertices found";
0124
0125 iEvent.put(std::make_unique<l1t::VertexWordCollection>(vertices), l1VertexCollectionName_);
0126 }
0127
0128 if (processInputTracks_ && fileReaderInputTracks_) {
0129 l1t::demo::EventData inputEventData(fileReaderInputTracks_.value().getNextEvent());
0130 auto inputTracks = std::make_unique<TTTrackCollection>();
0131 for (size_t i = 0; i < l1t::demo::gtt::kTrackTMUX; i++) {
0132 auto iTracks = decodeTracks(inputEventData.at({"tracks", i}));
0133 for (auto& trackword : iTracks) {
0134 if (!trackword.getValidWord())
0135 continue;
0136 L1Track track = L1Track(trackword.getValidWord(),
0137 trackword.getRinvWord(),
0138 trackword.getPhiWord(),
0139 trackword.getTanlWord(),
0140 trackword.getZ0Word(),
0141 trackword.getD0Word(),
0142 trackword.getChi2RPhiWord(),
0143 trackword.getChi2RZWord(),
0144 trackword.getBendChi2Word(),
0145 trackword.getHitPatternWord(),
0146 trackword.getMVAQualityWord(),
0147 trackword.getMVAOtherWord());
0148
0149 auto sectors = (l1t::demo::codecs::sectorsEtaPhiFromGTTLinkID(i));
0150 track.setEtaSector(sectors.first);
0151 track.setPhiSector(sectors.second);
0152 track.trackWord_ = trackword.trackWord_;
0153 inputTracks->push_back(track);
0154 }
0155 }
0156 iEvent.put(std::move(inputTracks), l1TrackCollectionName_);
0157 }
0158 }
0159
0160
0161 void GTTFileReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0162
0163 edm::ParameterSetDescription desc;
0164 desc.add<bool>("processOutputToCorrelator")
0165 ->setComment("boolean flag to load Correlator outputs via BoardDataReader and produce vertex collection");
0166 desc.add<bool>("processInputTracks")
0167 ->setComment("boolean flag to load track inputs via BoardDataReader and produce a TTTrack collection");
0168 desc.add<bool>("processOutputToGlobalTrigger")
0169 ->setComment(
0170 "boolean flag to load Global Trigger outputs via BoardDataReader and produce Track Object collections");
0171 desc.addUntracked<unsigned int>("kEmptyFramesOutputToCorrelator", 0)
0172 ->setComment("empty frames to expect in OutputToCorrelator");
0173 desc.addUntracked<unsigned int>("kEmptyFramesInputTracks", 0)->setComment("empty frames to expect in Track Input");
0174 desc.addUntracked<unsigned int>("kEmptyFramesOutputToGlobalTrigger", 0)
0175 ->setComment("empty frames to expect in OutputToGlobalTrigger");
0176 desc.add<std::vector<std::string>>("filesOutputToCorrelator",
0177 {
0178 "L1GTTOutputToCorrelator_0.txt",
0179 });
0180 desc.add<std::vector<std::string>>("filesInputTracks",
0181 {
0182 "L1GTTInputFile_0.txt",
0183 });
0184 desc.add<std::vector<std::string>>("filesOutputToGlobalTrigger",
0185 {
0186 "L1GTTOutputToGlobalTriggerFile_0.txt",
0187 });
0188 desc.addUntracked<std::string>("format", "APx");
0189 desc.add<std::string>("l1VertexCollectionName", "L1VerticesFirmware");
0190 desc.add<std::string>("l1TrackCollectionName", "Level1TTTracks");
0191 descriptions.add("GTTFileReader", desc);
0192 }
0193
0194
0195 DEFINE_FWK_MODULE(GTTFileReader);