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 
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
230 
231  // regional muon candidates
233  allPatterns,
234  m_cscTag.label(),
235  m_cscTag.instance(),
237  "cscMuon",
240  allPatterns,
241  m_dtTag.label(),
242  m_dtTag.instance(),
244  "dtMuon",
247  allPatterns,
248  m_rpcfTag.label(),
251  "fwdMuon",
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::make_unique<L1GtPatternWriter>(
298 }
299 
304  m_writer->close();
305  m_fileStream.close();
306 }
L1GtPatternGenerator::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
analyze each event
Definition: L1GtPatternGenerator.cc:216
L1GtPatternGenerator::endJob
void endJob() override
end of job
Definition: L1GtPatternGenerator.cc:303
L1GtPatternGenerator::m_rpcfTag
edm::InputTag m_rpcfTag
Definition: L1GtPatternGenerator.h:78
mps_fire.i
i
Definition: mps_fire.py:428
L1GctHFBitCounts::raw
uint16_t raw() const
the raw data
Definition: L1GctHFBitCounts.h:64
L1GctEtMiss::et
unsigned et() const
get the magnitude
Definition: L1GctEtMiss.h:56
input
static const std::string input
Definition: EdmProvDump.cc:48
L1GtPatternGenerator::m_dtTag
edm::InputTag m_dtTag
input tags for regional muon data
Definition: L1GtPatternGenerator.h:75
MessageLogger.h
L1GtPatternGenerator::m_footer
std::string m_footer
Definition: L1GtPatternGenerator.h:90
edm::InputTag::instance
std::string const & instance() const
Definition: InputTag.h:37
ESHandle.h
L1GtPatternGenerator::extractGlobalTriggerData
void extractGlobalTriggerData(const edm::Event &iEvent, L1GtPatternMap &patterns)
Definition: L1GtPatternGenerator.cc:158
L1GtPatternGenerator::packRegionalMuons
static uint32_t packRegionalMuons(uint32_t rawValue)
Definition: L1GtPatternGenerator.cc:151
L1GctCollections.h
patZpeak.handle
handle
Definition: patZpeak.py:23
L1GtPatternGenerator::m_header
std::string m_header
formatting instructions
Definition: L1GtPatternGenerator.h:89
L1GtPatternGenerator::m_columnLengths
std::vector< uint32_t > m_columnLengths
Definition: L1GtPatternGenerator.h:92
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
L1GtPatternGenerator::m_gmtTag
edm::InputTag m_gmtTag
input tag for GMT data
Definition: L1GtPatternGenerator.h:69
L1GctEtMiss::phi
unsigned phi() const
get the Et
Definition: L1GctEtMiss.h:62
l1tstage2_dqm_sourceclient-live_cfg.rawData
rawData
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:162
L1GtPatternGenerator::m_fileStream
std::ofstream m_fileStream
Definition: L1GtPatternGenerator.h:85
extractRecordData
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)=nullptr)
Definition: L1GtPatternGenerator.cc:90
edm::Handle
Definition: AssociativeIterator.h:50
L1GtPatternMap::begin
LineMap::const_iterator begin() const
Definition: L1GtPatternMap.cc:25
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
L1GtPatternGenerator::m_debug
bool m_debug
Definition: L1GtPatternGenerator.h:95
L1GtPatternGenerator::m_rpcbTag
edm::InputTag m_rpcbTag
Definition: L1GtPatternGenerator.h:77
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
L1MuRegionalCand.h
L1GtPatternGenerator.h
L1MuRegionalCand::getDataWord
unsigned getDataWord() const
return data word
Definition: L1MuRegionalCand.h:107
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
L1GctHtMiss::raw
uint32_t raw() const
get the data
Definition: L1GctHtMiss.h:56
L1GtPatternGenerator::beginJob
void beginJob() override
analyze
Definition: L1GtPatternGenerator.cc:289
L1GtPatternGenerator::packHfRecords
void packHfRecords(const std::string &resultName, L1GtPatternMap &allPatterns)
Definition: L1GtPatternGenerator.cc:191
L1GctEtHad::raw
uint16_t raw() const
get the data
Definition: L1GctEtHad.h:40
L1GctEtTotal::raw
uint16_t raw() const
get the data
Definition: L1GctEtTotal.h:40
L1GtPatternMap::getLine
L1GtPatternLine & getLine(int eventNr, int bxNr)
Definition: L1GtPatternMap.cc:20
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
chopWords
static std::vector< uint32_t > chopWords(const std::vector< bool > &aWord)
Definition: L1GtPatternGenerator.cc:123
L1GtFdlWord.h
L1GtPatternGenerator::m_cscTag
edm::InputTag m_cscTag
Definition: L1GtPatternGenerator.h:76
L1GtPatternLine
Definition: L1GtPatternLine.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1GtPatternMap::end
LineMap::const_iterator end() const
Definition: L1GtPatternMap.cc:26
L1GtPatternGenerator::m_fileName
std::string m_fileName
output file name
Definition: L1GtPatternGenerator.h:84
L1GtPatternGenerator::~L1GtPatternGenerator
~L1GtPatternGenerator() override
Definition: L1GtPatternGenerator.cc:69
L1GtPatternGenerator::m_writer
std::unique_ptr< L1GtPatternWriter > m_writer
Definition: L1GtPatternGenerator.h:97
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
iEvent
int iEvent
Definition: GenABIO.cc:224
value
Definition: value.py:1
L1GtPatternGenerator::m_gctTag
edm::InputTag m_gctTag
input tag for GCT data
Definition: L1GtPatternGenerator.h:66
extractGlobalTriggerWord
static void extractGlobalTriggerWord(const std::vector< bool > input, L1GtPatternLine &line, const std::string &prefix)
Definition: L1GtPatternGenerator.cc:138
edm::EventSetup
Definition: EventSetup.h:58
L1GtPatternMap.h
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
L1GtPatternGenerator::m_gtTag
edm::InputTag m_gtTag
input tag for GT data
Definition: L1GtPatternGenerator.h:72
L1MuGMTCand.h
L1GtPatternGenerator::L1GtPatternGenerator
L1GtPatternGenerator(const edm::ParameterSet &)
Definition: L1GtPatternGenerator.cc:37
L1GctHFRingEtSums::raw
uint16_t raw() const
get the raw data
Definition: L1GctHFRingEtSums.h:64
L1GtPatternMap
Definition: L1GtPatternMap.h:22
L1GtPatternGenerator::m_bx
std::vector< int > m_bx
Definition: L1GtPatternGenerator.h:93
L1GtUtils.h
Exception
Definition: hltDiff.cc:245
dqmiodumpmetadata.counts
counts
Definition: dqmiodumpmetadata.py:25
L1GctHtMiss.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
L1GctEmCand::raw
uint16_t raw() const
get the raw data
Definition: L1GctEmCand.h:56
mps_fire.result
result
Definition: mps_fire.py:311
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
L1MuGMTCand::getDataWord
unsigned getDataWord() const
get muon data word
Definition: L1MuGMTCand.h:64
L1GtPatternGenerator::m_columnDefaults
std::vector< uint32_t > m_columnDefaults
Definition: L1GtPatternGenerator.h:94
edm::Event
Definition: Event.h:73
mps_splice.line
line
Definition: mps_splice.py:76
edm::InputTag
Definition: InputTag.h:15
L1GlobalTriggerReadoutRecord.h
L1GctJetCand::raw
uint16_t raw() const
get the raw data
Definition: L1GctJetCand.h:50
label
const char * label
Definition: PFTauDecayModeTools.cc:11
L1GtPatternWriter.h
hcallasereventfilter2012_cfi.prefix
prefix
Definition: hcallasereventfilter2012_cfi.py:10
L1GtPatternGenerator::m_columnNames
std::vector< std::string > m_columnNames
Definition: L1GtPatternGenerator.h:91