CMS 3D CMS Logo

GTTFileReader.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/DemonstratorTools
4 // Class: GTTFileReader
5 //
15 //
16 // Original Author: Thomas Williams <thomas.williams@stfc.ac.uk>
17 // Created: Fri, 19 Feb 2021 01:10:55 GMT
18 //
19 //
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
33 
40 
41 //
42 // class declaration
43 //
44 
46 public:
47  explicit GTTFileReader(const edm::ParameterSet&);
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51 private:
52  // ----------constants, enums and typedefs ---------
54  typedef std::vector<L1Track> TTTrackCollection;
55 
56  // ----------member functions ----------------------
57  void produce(edm::Event&, const edm::EventSetup&) override;
58 
59  // ----------member data ---------------------------
61  const bool processInputTracks_;
66  std::optional<l1t::demo::BoardDataReader> fileReaderOutputToCorrelator_ = std::nullopt;
68  std::optional<l1t::demo::BoardDataReader> fileReaderInputTracks_ = std::nullopt;
70  std::optional<l1t::demo::BoardDataReader> fileReaderOutputToGlobalTrigger_ = std::nullopt;
71 };
72 
74  : processOutputToCorrelator_(iConfig.getParameter<bool>("processOutputToCorrelator")),
75  processInputTracks_(iConfig.getParameter<bool>("processInputTracks")),
76  processOutputToGlobalTrigger_(iConfig.getParameter<bool>("processOutputToGlobalTrigger")),
77  kEmptyFramesOutputToCorrelator_(iConfig.getUntrackedParameter<unsigned int>("kEmptyFramesOutputToCorrelator")),
78  kEmptyFramesInputTracks_(iConfig.getUntrackedParameter<unsigned int>("kEmptyFramesInputTracks")),
79  kEmptyFramesOutputToGlobalTrigger_(
80  iConfig.getUntrackedParameter<unsigned int>("kEmptyFramesOutputToGlobalTrigger")),
81  l1VertexCollectionName_(iConfig.getParameter<std::string>("l1VertexCollectionName")),
82  l1TrackCollectionName_(iConfig.getParameter<std::string>("l1TrackCollectionName")) {
86  iConfig.getParameter<std::vector<std::string>>("filesOutputToCorrelator"),
91  produces<l1t::VertexWordCollection>(l1VertexCollectionName_);
92  }
93  if (processInputTracks_) {
96  iConfig.getParameter<std::vector<std::string>>("filesInputTracks"),
101  produces<TTTrackCollection>(l1TrackCollectionName_);
102  }
104  // fileReaderOutputToGlobalTrigger_ =
105  // l1t::demo::BoardDataReader(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
106  // iConfig.getParameter<std::vector<std::string>>("filesOutputToGlobalTrigger"),
107  // l1t::demo::gtt::kFramesPerTMUXPeriod,
108  // l1t::demo::gtt::kGTTBoardTMUX,
109  // kEmptyFramesOutputToGlobalTrigger_,
110  // l1t::demo::gtt::kChannelMapInput);
111  throw std::invalid_argument("Processing OutputToGlobalTrigger files has not been fully implemented and validated.");
112  // need to produce output collections for Prompt and Displaced Jets, HTMiss, ETMiss, Taus, Mesons, Vertices, and Isolated Tracks
113  }
114 }
115 
116 // ------------ method called to produce the data ------------
118  using namespace edm;
119  using namespace l1t::demo::codecs;
121  l1t::demo::EventData correlatorEventData(fileReaderOutputToCorrelator_.value().getNextEvent());
122  l1t::VertexWordCollection vertices(decodeVertices(correlatorEventData.at({"vertices", 0})));
123  edm::LogInfo("GTTFileReader") << vertices.size() << " vertices found";
124 
125  iEvent.put(std::make_unique<l1t::VertexWordCollection>(vertices), l1VertexCollectionName_);
126  } // end if ( processOutputToCorrelator_ )
127 
129  l1t::demo::EventData inputEventData(fileReaderInputTracks_.value().getNextEvent());
130  auto inputTracks = std::make_unique<TTTrackCollection>();
131  for (size_t i = 0; i < l1t::demo::gtt::kTrackTMUX; i++) {
132  auto iTracks = decodeTracks(inputEventData.at({"tracks", i}));
133  for (auto& trackword : iTracks) {
134  if (!trackword.getValidWord())
135  continue;
136  L1Track track = L1Track(trackword.getValidWord(),
137  trackword.getRinvWord(),
138  trackword.getPhiWord(),
139  trackword.getTanlWord(),
140  trackword.getZ0Word(),
141  trackword.getD0Word(),
142  trackword.getChi2RPhiWord(),
143  trackword.getChi2RZWord(),
144  trackword.getBendChi2Word(),
145  trackword.getHitPatternWord(),
146  trackword.getMVAQualityWord(),
147  trackword.getMVAOtherWord());
148  //retrieve the eta (first) and phi (second) sectors for GTT, encoded in an std::pair
150  track.setEtaSector(sectors.first);
151  track.setPhiSector(sectors.second);
152  track.trackWord_ = trackword.trackWord_;
153  inputTracks->push_back(track);
154  } //end loop over trackwoards
155  } // end loop over GTT input links
157  } // end if ( processInputTracks_ )
158 }
159 
160 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
162  // GTTFileReader
164  desc.add<bool>("processOutputToCorrelator")
165  ->setComment("boolean flag to load Correlator outputs via BoardDataReader and produce vertex collection");
166  desc.add<bool>("processInputTracks")
167  ->setComment("boolean flag to load track inputs via BoardDataReader and produce a TTTrack collection");
168  desc.add<bool>("processOutputToGlobalTrigger")
169  ->setComment(
170  "boolean flag to load Global Trigger outputs via BoardDataReader and produce Track Object collections");
171  desc.addUntracked<unsigned int>("kEmptyFramesOutputToCorrelator", 0)
172  ->setComment("empty frames to expect in OutputToCorrelator");
173  desc.addUntracked<unsigned int>("kEmptyFramesInputTracks", 0)->setComment("empty frames to expect in Track Input");
174  desc.addUntracked<unsigned int>("kEmptyFramesOutputToGlobalTrigger", 0)
175  ->setComment("empty frames to expect in OutputToGlobalTrigger");
176  desc.add<std::vector<std::string>>("filesOutputToCorrelator",
177  {
178  "L1GTTOutputToCorrelator_0.txt",
179  });
180  desc.add<std::vector<std::string>>("filesInputTracks",
181  {
182  "L1GTTInputFile_0.txt",
183  });
184  desc.add<std::vector<std::string>>("filesOutputToGlobalTrigger",
185  {
186  "L1GTTOutputToGlobalTriggerFile_0.txt",
187  });
188  desc.addUntracked<std::string>("format", "APx");
189  desc.add<std::string>("l1VertexCollectionName", "L1VerticesFirmware");
190  desc.add<std::string>("l1TrackCollectionName", "Level1TTTracks");
191  descriptions.add("GTTFileReader", desc);
192 }
193 
194 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const ChannelMap_t kChannelMapInput
Definition: GTTInterface.h:53
const size_t kEmptyFramesOutputToCorrelator_
void produce(edm::Event &, const edm::EventSetup &) override
const bool processOutputToGlobalTrigger_
FileFormat parseFileFormat(const std::string &)
Definition: utilities.cc:73
static constexpr size_t kTrackTMUX
Definition: GTTInterface.h:23
std::string l1TrackCollectionName_
T getUntrackedParameter(std::string const &, T const &) const
const bool processInputTracks_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::string l1VertexCollectionName_
const bool processOutputToCorrelator_
static std::pair< unsigned int, unsigned int > sectorsEtaPhiFromGTTLinkID(unsigned int id)
Definition: tracks.h:29
static constexpr size_t kFramesPerTMUXPeriod
Definition: GTTInterface.h:16
int iEvent
Definition: GenABIO.cc:224
static constexpr size_t kGTTBoardTMUX
Definition: GTTInterface.h:24
std::optional< l1t::demo::BoardDataReader > fileReaderOutputToGlobalTrigger_
TTTrack< Ref_Phase2TrackerDigi_ > L1Track
std::vector< l1t::VertexWord > decodeVertices(const std::vector< ap_uint< 64 >> &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const size_t kEmptyFramesInputTracks_
std::vector< VertexWord > VertexWordCollection
Definition: VertexWord.h:197
std::optional< l1t::demo::BoardDataReader > fileReaderInputTracks_
Log< level::Info, false > LogInfo
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
std::optional< l1t::demo::BoardDataReader > fileReaderOutputToCorrelator_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
GTTFileReader(const edm::ParameterSet &)
static const ChannelMap_t kChannelMapOutputToCorrelator
Definition: GTTInterface.h:79
Class representing information phase-2 ATCA I/O data corresponding to a single event, with logical channel IDs (essentially string-uint pairs, e.g. tracks-0 to tracks-17).
Definition: EventData.h:28
def move(src, dest)
Definition: eostools.py:511
std::vector< TTTrack_TrackWord > decodeTracks(const std::vector< ap_uint< 64 >> &)
const size_t kEmptyFramesOutputToGlobalTrigger_
std::vector< L1Track > TTTrackCollection