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