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  // Extract record from event.
106  iEvent.getByLabel(label, instance, handle);
107 
108  if(!handle.isValid()) {
109  throw cms::Exception(__func__) << "Failed to extract record of type " << typeid(TRecord).name() <<
110  " labeled " << label << ", instance " << instance;
111  }
112 
113  edm::EventNumber_t eventNr = iEvent.id().event();
114 
115  // Then loop over collection and add each event to the map.
116  for(typename std::vector<TRecord>::const_iterator it = handle->begin(); it != handle->end(); ++it) {
117  int bx = it->bx();
118  L1GtPatternLine& line = allPatterns.getLine(eventNr, bx);
119  uint32_t value = ((*it).*rawFunctionPtr)();
120  if(packingFunction != NULL) {
121  value = packingFunction(value);
122  }
123 
124  line.push(prefix, value);
125  }
126 }
127 
128 /*** Convert a vector of bools into a vector of uint32_ts. Probably
129  optimizable, but let's just trust that it doesn't matter... */
130 static std::vector<uint32_t> chopWords(const std::vector<bool>& aWord) {
131  std::vector<uint32_t> result;
132 
133  result.resize((aWord.size()+31)/32, 0);
134 
135  for(unsigned i = 0 ; i < aWord.size(); ++i) {
136  result[i/32] |= aWord[i] << (i%32);
137  }
138 
139  return result;
140 }
141 
145 static void extractGlobalTriggerWord(const std::vector<bool> input, L1GtPatternLine& line, const std::string& prefix)
146 {
147  std::vector<uint32_t> resultWords = chopWords(input);
148 
149  // add in reverse order, so that higher-order words have lower indices
150  // (like in "natural" number representation) (10 -> digit1=1 digit2=0)
151  for(unsigned i = resultWords.size() ; i > 0; --i) {
152  line.push(prefix, resultWords[i-1]);
153  }
154 }
155 
159 uint32_t L1GtPatternGenerator::packRegionalMuons(uint32_t rawData) {
160  uint32_t invertMask = 0x0000FF00;
161  uint32_t toKeep = rawData & (~invertMask);
162  return toKeep | (~rawData & invertMask);
163 }
164 
165 
166 // member functions
168 
169  // extract global trigger readout record
171  iEvent.getByLabel(m_gtTag, handle);
172 
173  // continue if it's present
174  if(!handle.isValid()) {
175  throw cms::Exception(__func__) << "Failed to extract GT readout record labeled "
176  << m_gtTag.label() << ", instance " << m_gtTag.instance();
177  }
178 
179  edm::EventNumber_t eventNr = iEvent.id().event();
180 
181  // for each FDL word...
182  const std::vector<L1GtFdlWord>& fdlWords = handle->gtFdlVector();
183  for(std::vector<L1GtFdlWord>::const_iterator it = fdlWords.begin();
184  it != fdlWords.end() ; ++it) {
185  // extract relevant data
186  int bx = it->bxInEvent();
187 
188  // find matching pattern file line
189  L1GtPatternLine& line = patterns.getLine(eventNr, bx);
190 
191  extractGlobalTriggerWord(it->gtDecisionWord(), line, "gtDecision");
192  extractGlobalTriggerWord(it->gtDecisionWordExtended(), line, "gtDecisionExt");
193  extractGlobalTriggerWord(it->gtTechnicalTriggerWord(), line, "gtTechTrigger");
194 
195  line.push("gtFinalOr", it->finalOR());
196  }
197 }
198 
203 {
204  // iterate over each pattern line
205  for(L1GtPatternMap::LineMap::iterator it = allPatterns.begin();
206  it != allPatterns.end(); ++it) {
207  // Get the HF bit counts and ring sums
208  uint32_t counts = it->second.get("hfBitCounts1");
209  uint32_t sums = it->second.get("hfRingEtSums1");
210 
211 
212  // Bits 0..11 -> 4 bit counts
213  uint32_t hfPsbValue = (counts & 0xFFF) |
214  // Bit 12..14 ring 1 pos. rap. HF Et sum
215  (sums & 0x7) << 12 |
216  // Bits 16.. rest of the ET sums
217  (sums >> 3) << 16;
218  // TODO: Spec states non-data values for Bits 15, 31, 47 and 63.
219 
220  // Export computed value to pattern writer. */
221  it->second.push(resultName, hfPsbValue);
222  }
223 }
224 
230 void L1GtPatternGenerator::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup)
231 {
232  // debug information
233  const unsigned int runNumber = iEvent.run();
234  const unsigned int lsNumber = iEvent.luminosityBlock();
235  const unsigned int eventNumber = iEvent.id().event();
236 
237  LogTrace("L1GtPatternGenerator") << "\n\nL1GtPatternGenerator::analyze: Run: " << runNumber << " LS: " << lsNumber << " Event: "
238  << eventNumber << "\n\n" << std::endl;
239 
240 
241  L1GtPatternMap allPatterns;
242 
243  // GMT muon candidates
244  extractRecordData(iEvent, allPatterns, m_gmtTag.label(), m_gmtTag.instance(), &L1MuGMTCand::getDataWord, "gmtMuon");
245 
246  // regional muon candidates
251 
252  // GCT objects
253  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "nonIsoEm", &L1GctEmCand::raw, "gctEm");
254  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "isoEm", &L1GctEmCand::raw, "gctIsoEm");
255  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctEtMiss::et, "etMiss");
256  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctEtMiss::phi, "etMissPhi");
257  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctHtMiss::raw, "htMiss");
258  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctEtHad::raw, "etHad");
259  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctEtTotal::raw, "etTotal");
260  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "cenJets", &L1GctJetCand::raw, "cenJet");
261  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "forJets", &L1GctJetCand::raw, "forJet");
262  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "tauJets", &L1GctJetCand::raw, "tauJet");
263  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctHFBitCounts::raw, "hfBitCounts");
264  extractRecordData(iEvent, allPatterns, m_gctTag.label(), "", &L1GctHFRingEtSums::raw, "hfRingEtSums");
265 
266  // Post processing:
267  // HFBitCounts/HFRingEtSums need to be mangled to PSB values
268  packHfRecords("hfPsbValue", allPatterns);
269 
270  // GT objects
271  extractGlobalTriggerData(iEvent, allPatterns);
272 
273  // Output
274  m_writer->writePatterns(allPatterns);
275 }
276 
281 {
282  m_fileStream.open(m_fileName.c_str());
283 
284  if(!m_fileStream) {
285  edm::LogError("L1GtPatternGenerator") << "Failed to open output file " << m_fileName;
286  }
287 
289 }
290 
295 {
296  m_writer->close();
297  m_fileStream.close();
298 }
#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:41
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)
static PFTauRenderPlugin instance
std::vector< uint32_t > m_columnDefaults
unsigned long long EventNumber_t
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
#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:43
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:230
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:85
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:75
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
#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:60
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