CMS 3D CMS Logo

L1GtPatternGenerator.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <memory>
20 #include <iomanip>
21 #include <fstream>
22 
23 // user include files
35 
36 // constructor
38  // input tags for trigger records
39  m_gctTag = parSet.getParameter<edm::InputTag>("GctInputTag");
40  m_gmtTag = parSet.getParameter<edm::InputTag>("GmtInputTag");
41  m_gtTag = parSet.getParameter<edm::InputTag>("GtInputTag");
42  m_dtTag = parSet.getParameter<edm::InputTag>("DtInputTag");
43  m_cscTag = parSet.getParameter<edm::InputTag>("CscInputTag");
44  m_rpcbTag = parSet.getParameter<edm::InputTag>("RpcbInputTag");
45  m_rpcfTag = parSet.getParameter<edm::InputTag>("RpcfInputTag");
46 
47  // output formatting stuff
48  m_header = parSet.getParameter<std::string>("PatternFileHeader");
49  m_footer = parSet.getParameter<std::string>("PatternFileFooter");
50  m_columnNames = parSet.getParameter<std::vector<std::string> >("PatternFileColumns");
51  m_columnLengths = parSet.getParameter<std::vector<uint32_t> >("PatternFileLengths");
52  m_columnDefaults = parSet.getParameter<std::vector<uint32_t> >("PatternFileDefaultValues");
53  m_fileName = parSet.getParameter<std::string>("PatternFileName");
54  m_bx = parSet.getParameter<std::vector<int> >("bx");
55  m_debug = parSet.getParameter<bool>("DebugOutput");
56 
57  if (m_columnLengths.size() != m_columnNames.size()) {
58  edm::LogWarning("L1GtPatternGenerator")
59  << "Length of PatternFileColumns does not match length of PatternFileLenghts, " << m_columnNames.size()
60  << " vs " << m_columnLengths.size() << std::endl;
61  }
62 
63  LogDebug("L1GtPatternGenerator") << "\nL1 GCT record: " << m_gctTag
64  << "\nL1 GMT record: " << m_gmtTag
65  << "\nL1 GT record: " << m_gtTag << std::endl;
66 }
67 
68 // destructor
70 
71 // local helper functions
72 
89 template <class TRecord, typename TResult>
90 static void extractRecordData(const edm::Event& iEvent,
91  L1GtPatternMap& allPatterns,
92  const std::string& label,
93  const std::string& instance,
94  TResult (TRecord::*rawFunctionPtr)() const,
95  const std::string& prefix,
96  uint32_t (*packingFunction)(uint32_t) = nullptr) {
97  // Extract record from event.
99  iEvent.getByLabel(label, instance, handle);
100 
101  if (!handle.isValid()) {
102  throw cms::Exception(__func__) << "Failed to extract record of type " << typeid(TRecord).name() << " labeled "
103  << label << ", instance " << instance;
104  }
105 
106  edm::EventNumber_t eventNr = iEvent.id().event();
107 
108  // Then loop over collection and add each event to the map.
109  for (typename std::vector<TRecord>::const_iterator it = handle->begin(); it != handle->end(); ++it) {
110  int bx = it->bx();
111  L1GtPatternLine& line = allPatterns.getLine(eventNr, bx);
112  uint32_t value = ((*it).*rawFunctionPtr)();
113  if (packingFunction != nullptr) {
114  value = packingFunction(value);
115  }
116 
117  line.push(prefix, value);
118  }
119 }
120 
121 /*** Convert a vector of bools into a vector of uint32_ts. Probably
122  optimizable, but let's just trust that it doesn't matter... */
123 static std::vector<uint32_t> chopWords(const std::vector<bool>& aWord) {
124  std::vector<uint32_t> result;
125 
126  result.resize((aWord.size() + 31) / 32, 0);
127 
128  for (unsigned i = 0; i < aWord.size(); ++i) {
129  result[i / 32] |= aWord[i] << (i % 32);
130  }
131 
132  return result;
133 }
134 
138 static void extractGlobalTriggerWord(const std::vector<bool> input, L1GtPatternLine& line, const std::string& prefix) {
139  std::vector<uint32_t> resultWords = chopWords(input);
140 
141  // add in reverse order, so that higher-order words have lower indices
142  // (like in "natural" number representation) (10 -> digit1=1 digit2=0)
143  for (unsigned i = resultWords.size(); i > 0; --i) {
144  line.push(prefix, resultWords[i - 1]);
145  }
146 }
147 
152  uint32_t invertMask = 0x0000FF00;
153  uint32_t toKeep = rawData & (~invertMask);
154  return toKeep | (~rawData & invertMask);
155 }
156 
157 // member functions
159  // extract global trigger readout record
161  iEvent.getByLabel(m_gtTag, handle);
162 
163  // continue if it's present
164  if (!handle.isValid()) {
165  throw cms::Exception(__func__) << "Failed to extract GT readout record labeled " << m_gtTag.label() << ", instance "
166  << m_gtTag.instance();
167  }
168 
169  edm::EventNumber_t eventNr = iEvent.id().event();
170 
171  // for each FDL word...
172  const std::vector<L1GtFdlWord>& fdlWords = handle->gtFdlVector();
173  for (std::vector<L1GtFdlWord>::const_iterator it = fdlWords.begin(); it != fdlWords.end(); ++it) {
174  // extract relevant data
175  int bx = it->bxInEvent();
176 
177  // find matching pattern file line
178  L1GtPatternLine& line = patterns.getLine(eventNr, bx);
179 
180  extractGlobalTriggerWord(it->gtDecisionWord(), line, "gtDecision");
181  extractGlobalTriggerWord(it->gtDecisionWordExtended(), line, "gtDecisionExt");
182  extractGlobalTriggerWord(it->gtTechnicalTriggerWord(), line, "gtTechTrigger");
183 
184  line.push("gtFinalOr", it->finalOR());
185  }
186 }
187 
191 void L1GtPatternGenerator::packHfRecords(const std::string& resultName, L1GtPatternMap& allPatterns) {
192  // iterate over each pattern line
193  for (L1GtPatternMap::LineMap::iterator it = allPatterns.begin(); it != allPatterns.end(); ++it) {
194  // Get the HF bit counts and ring sums
195  uint32_t counts = it->second.get("hfBitCounts1");
196  uint32_t sums = it->second.get("hfRingEtSums1");
197 
198  // Bits 0..11 -> 4 bit counts
199  uint32_t hfPsbValue = (counts & 0xFFF) |
200  // Bit 12..14 ring 1 pos. rap. HF Et sum
201  (sums & 0x7) << 12 |
202  // Bits 16.. rest of the ET sums
203  (sums >> 3) << 16;
204  // TODO: Spec states non-data values for Bits 15, 31, 47 and 63.
205 
206  // Export computed value to pattern writer. */
207  it->second.push(resultName, hfPsbValue);
208  }
209 }
210 
216 void L1GtPatternGenerator::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
217  // debug information
218  const unsigned int runNumber = iEvent.run();
219  const unsigned int lsNumber = iEvent.luminosityBlock();
220  const unsigned int eventNumber = iEvent.id().event();
221 
222  LogTrace("L1GtPatternGenerator") << "\n\nL1GtPatternGenerator::analyze: Run: " << runNumber << " LS: " << lsNumber
223  << " Event: " << eventNumber << "\n\n"
224  << std::endl;
225 
226  L1GtPatternMap allPatterns;
227 
228  // GMT muon candidates
229  extractRecordData(iEvent, allPatterns, m_gmtTag.label(), m_gmtTag.instance(), &L1MuGMTCand::getDataWord, "gmtMuon");
230 
231  // regional muon candidates
232  extractRecordData(iEvent,
233  allPatterns,
234  m_cscTag.label(),
235  m_cscTag.instance(),
237  "cscMuon",
239  extractRecordData(iEvent,
240  allPatterns,
241  m_dtTag.label(),
242  m_dtTag.instance(),
244  "dtMuon",
246  extractRecordData(iEvent,
247  allPatterns,
248  m_rpcfTag.label(),
251  "fwdMuon",
253  extractRecordData(iEvent,
254  allPatterns,
255  m_rpcbTag.label(),
258  "brlMuon",
260 
261  // GCT objects
262  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "nonIsoEm", &L1GctEmCand::raw, "gctEm");
263  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "isoEm", &L1GctEmCand::raw, "gctIsoEm");
264  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctEtMiss::et, "etMiss");
265  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctEtMiss::phi, "etMissPhi");
266  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctHtMiss::raw, "htMiss");
267  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctEtHad::raw, "etHad");
268  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctEtTotal::raw, "etTotal");
269  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "cenJets", &L1GctJetCand::raw, "cenJet");
270  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "forJets", &L1GctJetCand::raw, "forJet");
271  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "tauJets", &L1GctJetCand::raw, "tauJet");
272  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctHFBitCounts::raw, "hfBitCounts");
273  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctHFRingEtSums::raw, "hfRingEtSums");
274 
275  // Post processing:
276  // HFBitCounts/HFRingEtSums need to be mangled to PSB values
277  packHfRecords("hfPsbValue", allPatterns);
278 
279  // GT objects
280  extractGlobalTriggerData(iEvent, allPatterns);
281 
282  // Output
283  m_writer->writePatterns(allPatterns);
284 }
285 
290  m_fileStream.open(m_fileName.c_str());
291 
292  if (!m_fileStream) {
293  edm::LogError("L1GtPatternGenerator") << "Failed to open output file " << m_fileName;
294  }
295 
296  m_writer = std::unique_ptr<L1GtPatternWriter>(new L1GtPatternWriter(
298 }
299 
304  m_writer->close();
305  m_fileStream.close();
306 }
#define LogDebug(id)
void analyze(const edm::Event &, const edm::EventSetup &) override
analyze each event
uint32_t raw() const
get the data
Definition: L1GctHtMiss.h:56
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
L1GtPatternLine & getLine(int eventNr, int bxNr)
uint16_t raw() const
get the data
Definition: L1GctEtHad.h:40
LineMap::const_iterator begin() const
edm::InputTag m_dtTag
input tags for regional muon data
uint16_t raw() const
get the raw data
Definition: L1GctEmCand.h:56
static PFTauRenderPlugin instance
std::vector< uint32_t > m_columnDefaults
const std::vector< L1GtFdlWord > gtFdlVector() const
get the vector of L1GtFdlWord
unsigned long long EventNumber_t
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
unsigned phi() const
get the Et
Definition: L1GctEtMiss.h:62
std::vector< uint32_t > m_columnLengths
edm::InputTag m_gmtTag
input tag for GMT data
static std::string const input
Definition: EdmProvDump.cc:48
static void extractRecordData(const edm::Event &iEvent, L1GtPatternMap &allPatterns, const std::string &label, const std::string &instance, TResult(TRecord::*rawFunctionPtr)() const, const std::string &prefix, uint32_t(*packingFunction)(uint32_t)=0)
void beginJob() override
analyze
void extractGlobalTriggerData(const edm::Event &iEvent, L1GtPatternMap &patterns)
std::unique_ptr< L1GtPatternWriter > m_writer
char const * label
unsigned getDataWord() const
get muon data word
Definition: L1MuGMTCand.h:64
std::string m_header
formatting instructions
std::string m_fileName
output file name
int iEvent
Definition: GenABIO.cc:224
unsigned getDataWord() const
return data word
LineMap::const_iterator end() const
edm::InputTag m_gctTag
input tag for GCT data
static void extractGlobalTriggerWord(const std::vector< bool > input, L1GtPatternLine &line, const std::string &prefix)
void packHfRecords(const std::string &resultName, L1GtPatternMap &allPatterns)
RunNumber_t run() const
Definition: Event.h:107
Definition: value.py:1
edm::InputTag m_gtTag
input tag for GT data
bool isValid() const
Definition: HandleBase.h:70
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
#define LogTrace(id)
unsigned et() const
get the magnitude
Definition: L1GctEtMiss.h:56
L1GtPatternGenerator(const edm::ParameterSet &)
std::string const & label() const
Definition: InputTag.h:36
uint16_t raw() const
get the data
Definition: L1GctEtTotal.h:40
std::vector< int > m_bx
uint16_t raw() const
get the raw data
void endJob() override
end of job
edm::EventID id() const
Definition: EventBase.h:59
void push(const std::string &prefix, uint32_t value)
uint16_t raw() const
the raw data
std::string const & instance() const
Definition: InputTag.h:37
static uint32_t packRegionalMuons(uint32_t rawValue)
static std::vector< uint32_t > chopWords(const std::vector< bool > &aWord)
uint16_t raw() const
get the raw data
Definition: L1GctJetCand.h:50
std::vector< std::string > m_columnNames