CMS 3D CMS Logo

L1GtBeamModeFilter.cc
Go to the documentation of this file.
1 
13 // this class header
15 
16 // system include files
17 #include <vector>
18 #include <iostream>
19 
20 #include <boost/cstdint.hpp>
21 
22 // user include files
26 
28 
31 
33 
36 
37 // constructor(s)
39 
40  m_condInEdmInputTag(parSet.getParameter<edm::InputTag>(
41  "CondInEdmInputTag")),
42  m_l1GtEvmReadoutRecordTag(parSet.getParameter<edm::InputTag>(
43  "L1GtEvmReadoutRecordTag")),
44  m_allowedBeamMode(parSet.getParameter<std::vector<unsigned int> >(
45  "AllowedBeamMode")),
46  m_invertResult(parSet.getParameter<bool>(
47  "InvertResult")),
48  m_isDebugEnabled(edm::isDebugEnabled()),
49  m_condInRunBlockValid(false) {
50 
51  if (m_isDebugEnabled) {
52 
53  LogDebug("L1GtBeamModeFilter") << std::endl;
54 
55  LogTrace("L1GtBeamModeFilter")
56  << "\nInput tag for ConditionsInEdm product: "
58  << "\nInput tag for L1 GT EVM record: "
60  << "\nAllowed beam modes:"
61  << std::endl;
62 
63  for (std::vector<unsigned int>::const_iterator itMode =
64  m_allowedBeamMode.begin(); itMode != m_allowedBeamMode.end(); ++itMode) {
65 
66  LogTrace("L1GtBeamModeFilter") << " " << (*itMode) << std::endl;
67 
68  }
69 
70  LogTrace("L1GtBeamModeFilter")
71  << "\nInvert result (use as NOT filter): "
73  << std::endl;
74 
75  LogTrace("L1GtBeamModeFilter") << std::endl;
76 
77  }
78 }
79 
80 // destructor
82  // empty now
83 }
84 
85 // member functions
86 
88  const edm::EventSetup& evSetup) {
89 
90  // initialize filter result
91  bool filterResult = false;
92 
93  // for MC samples, return always true (not even checking validity of L1GlobalTriggerEvmReadoutRecord)
94  // eventually, the BST information will be filled also in MC simulation to spare this check
95 
96  if (!(iEvent.isRealData())) {
97  //LogDebug("L1GtBeamModeFilter") << "\nRunning on MC sample."
98  // << "\nAll events are automatically selected, without testing the beam mode"
99  // << "\n" << std::endl;
100 
101  if (m_invertResult) {
102  return false;
103  } else {
104  return true;
105  }
106 
107  }
108 
109  // data
110 
111  // initialize beam mode value
112  boost::uint16_t beamModeValue = 0;
113 
114  // get Run Data - the same code can be run in beginRun, with getByLabel from edm::Run
115  // TODO should I cache the run/luminosity section? to be decided after moving beamMode to LumiBlock
116  const edm::Run& iRun = iEvent.getRun();
117 
118  // get ConditionsInRunBlock
120  iRun.getByLabel(m_condInEdmInputTag, condInRunBlock);
121 
122  if (!condInRunBlock.isValid()) {
123 
124  LogDebug("L1GtBeamModeFilter") << "\nConditionsInRunBlock with \n "
126  << "\nrequested in configuration, but not found in the event."
127  << "\n" << std::endl;
128 
129  m_condInRunBlockValid = false;
130 
131  } else {
132 
133  m_condInRunBlockValid = true;
134  beamModeValue = condInRunBlock->beamMode;
135 
136  }
137 
138  // fall through to L1GlobalTriggerEvmReadoutRecord if ConditionsInRunBlock
139  // not available
140  if (!m_condInRunBlockValid) {
141 
142  // get L1GlobalTriggerEvmReadoutRecord and beam mode
144  iEvent.getByLabel(m_l1GtEvmReadoutRecordTag, gtEvmReadoutRecord);
145 
146  if (!gtEvmReadoutRecord.isValid()) {
147  LogDebug("L1GtBeamModeFilter")
148  << "\nL1GlobalTriggerEvmReadoutRecord with input tag "
150  << "\nrequested in configuration, but not found in the event."
151  << std::endl;
152 
153  // both products are missing, return false for both normal and inverted result
154  return false;
155 
156  } else {
157 
158  beamModeValue = (gtEvmReadoutRecord->gtfeWord()).beamMode();
159 
160  }
161 
162  }
163 
164  LogDebug("L1GtBeamModeFilter") << "\nBeam mode: " << beamModeValue
165  << std::endl;
166 
167  for (std::vector<unsigned int>::const_iterator itMode =
168  m_allowedBeamMode.begin(); itMode != m_allowedBeamMode.end(); ++itMode) {
169 
170  if (beamModeValue == (*itMode)) {
171  filterResult = true;
172 
173  //LogTrace("L1GtBeamModeFilter") << "Event selected - beam mode: "
174  // << beamModeValue << "\n" << std::endl;
175 
176  break;
177 
178  }
179  }
180 
181  //
182 
183  if (m_invertResult) {
184  filterResult = !filterResult;
185  }
186 
187  return filterResult;
188 
189 }
190 
#define LogDebug(id)
std::vector< unsigned int > m_allowedBeamMode
vector of beam modes (coded as integer numbers)
bool filter(edm::Event &, const edm::EventSetup &) override
filter the event
bool isDebugEnabled()
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:280
~L1GtBeamModeFilter() override
destructor
L1GtBeamModeFilter(const edm::ParameterSet &)
constructor
const L1GtfeExtWord gtfeWord() const
get / set GTFE word (record) in the GT readout record
edm::InputTag m_l1GtEvmReadoutRecordTag
InputTag for the L1 Global Trigger EVM readout record.
Run const & getRun() const
Definition: Event.cc:99
bool m_condInRunBlockValid
valid ConditionsInRunBlock product
bool isRealData() const
Definition: EventBase.h:62
int iEvent
Definition: GenABIO.cc:224
bool m_isDebugEnabled
cache edm::isDebugEnabled()
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
#define LogTrace(id)
bool m_invertResult
return the inverted result
HLT enums.
edm::InputTag m_condInEdmInputTag
input tag for ConditionInEdm products
Definition: Run.h:45