CMS 3D CMS Logo

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