CMS 3D CMS Logo

L1GctEmulator.cc
Go to the documentation of this file.
2 
3 // system includes
4 #include <memory>
5 #include <vector>
6 
7 // EDM includes
14 
16 
17 // GCT include files
19 
20 // RCT data includes
22 
23 // GCT data includes
25 
26 using std::vector;
27 
29  : m_jetEtCalibLuts(),
30  m_writeInternalData(ps.getParameter<bool>("writeInternalData")),
31  m_verbose(ps.getUntrackedParameter<bool>("verbose", false)),
32  m_conditionsLabel(ps.getParameter<std::string>("conditionsLabel")) {
33  // list of products
34  produces<L1GctEmCandCollection>("isoEm");
35  produces<L1GctEmCandCollection>("nonIsoEm");
36  produces<L1GctJetCandCollection>("cenJets");
37  produces<L1GctJetCandCollection>("forJets");
38  produces<L1GctJetCandCollection>("tauJets");
39  produces<L1GctInternJetDataCollection>();
40  produces<L1GctEtTotalCollection>();
41  produces<L1GctEtHadCollection>();
42  produces<L1GctEtMissCollection>();
43  produces<L1GctHtMissCollection>();
44  produces<L1GctInternEtSumCollection>();
45  produces<L1GctInternHtMissCollection>();
46  produces<L1GctHFBitCountsCollection>();
47  produces<L1GctHFRingEtSumsCollection>();
48 
49  // get the input label
51  m_inputLabel = inputTag.label();
52 
53  // Get the number of bunch crossings to be processed
54  int firstBx = -ps.getParameter<unsigned>("preSamples");
55  int lastBx = ps.getParameter<unsigned>("postSamples");
56 
57  // instantiate the GCT. Argument selects the type of jetFinder to be used.
59  std::string jfTypeStr = ps.getParameter<std::string>("jetFinderType");
60  if (jfTypeStr == "tdrJetFinder") {
62  } else if (jfTypeStr != "hardwareJetFinder") {
63  edm::LogWarning("L1GctEmulatorSetup")
64  << "Unrecognised jetFinder option " << jfTypeStr << "\nHardware jetFinder will be used";
65  }
66  bool hwTest = ps.getParameter<bool>("hardwareTest");
67  if (hwTest) {
68  unsigned mask = ps.getUntrackedParameter<unsigned>("jetLeafMask", 0);
69  m_gct = std::make_unique<L1GlobalCaloTrigger>(jfType, mask);
70  edm::LogWarning("L1GctEmulatorSetup") << "Emulator has been configured in hardware test mode with mask " << mask
71  << "\nThis mode should NOT be used for Physics studies!";
72  } else {
73  m_gct = std::make_unique<L1GlobalCaloTrigger>(jfType);
74  }
75  m_gct->setBxRange(firstBx, lastBx);
76 
77  // Fill the jetEtCalibLuts vector
78  lutPtr nextLut(new L1GctJetEtCalibrationLut());
79 
80  for (unsigned ieta = 0; ieta < L1GctJetFinderParams::NUMBER_ETA_VALUES; ieta++) {
81  nextLut->setEtaBin(ieta);
82  m_jetEtCalibLuts.push_back(nextLut);
83  nextLut.reset(new L1GctJetEtCalibrationLut());
84  }
85 
86  // Setup the tau algorithm parameters
87  bool useImprovedTauAlgo = ps.getParameter<bool>("useImprovedTauAlgorithm");
88  bool ignoreTauVetoBitsForIsolation = ps.getParameter<bool>("ignoreRCTTauVetoBitsForIsolation");
89  m_gct->setupTauAlgo(useImprovedTauAlgo, ignoreTauVetoBitsForIsolation);
90 
91  // set verbosity (not implemented yet!)
92  // m_gct->setVerbose(m_verbose);
93 
94  // print debug info?
95  if (m_verbose) {
96  m_gct->print();
97  }
98  m_emToken = consumes<L1CaloEmCollection>(inputTag);
99  m_regionToken = consumes<L1CaloRegionCollection>(inputTag);
100  m_jfParsToken = esConsumes<L1GctJetFinderParams, L1GctJetFinderParamsRcd>(edm::ESInputTag("", m_conditionsLabel));
101  m_chanMaskToken = esConsumes<L1GctChannelMask, L1GctChannelMaskRcd>(edm::ESInputTag("", m_conditionsLabel));
102  m_etScaleToken = esConsumes<L1CaloEtScale, L1JetEtScaleRcd>(edm::ESInputTag("", m_conditionsLabel));
103  m_htMissScaleToken = esConsumes<L1CaloEtScale, L1HtMissScaleRcd>(edm::ESInputTag("", m_conditionsLabel));
104  m_hfRingEtScaleToken = esConsumes<L1CaloEtScale, L1HfRingEtScaleRcd>(edm::ESInputTag("", m_conditionsLabel));
105 }
106 
108  int success = 0;
109 
110  if (success == 0) {
111  // get data from EventSetup
113  edm::ESHandle<L1GctChannelMask> chanMask = c.getHandle(m_chanMaskToken);
115  edm::ESHandle<L1CaloEtScale> htMissScale = c.getHandle(m_htMissScaleToken);
116  edm::ESHandle<L1CaloEtScale> hfRingEtScale = c.getHandle(m_hfRingEtScaleToken);
117 
118  if (jfPars.product() == nullptr) {
119  success = -1;
120  if (m_verbose) {
121  edm::LogWarning("L1GctConfigFailure")
122  << "Failed to find a L1GctJetFinderParamsRcd:L1GctJetFinderParams in EventSetup!" << std::endl;
123  }
124  }
125 
126  if (chanMask.product() == nullptr) {
127  success = -1;
128  if (m_verbose) {
129  edm::LogWarning("L1GctConfigFailure")
130  << "Failed to find a L1GctChannelMaskRcd:L1GctChannelMask in EventSetup!" << std::endl;
131  }
132  }
133 
134  if (hfRingEtScale.product() == nullptr) {
135  success = -1;
136  if (m_verbose) {
137  edm::LogWarning("L1GctConfigFailure")
138  << "Failed to find a L1HfRingEtScaleRcd:L1HfRingEtScaleRcd in EventSetup!" << std::endl;
139  }
140  }
141 
142  if (success == 0) {
143  // tell the jet Et Luts about the scales
144  for (unsigned ieta = 0; ieta < m_jetEtCalibLuts.size(); ieta++) {
145  m_jetEtCalibLuts.at(ieta)->setFunction(jfPars.product());
146  m_jetEtCalibLuts.at(ieta)->setOutputEtScale(etScale.product());
147  }
148 
149  // pass all the setup info to the gct
150  m_gct->setJetEtCalibrationLuts(m_jetEtCalibLuts);
151  m_gct->setJetFinderParams(jfPars.product());
152  m_gct->setHtMissScale(htMissScale.product());
153  m_gct->setupHfSumLuts(hfRingEtScale.product());
154  m_gct->setChannelMask(chanMask.product());
155  }
156  }
157 
158  if (success != 0 && m_verbose) {
159  edm::LogError("L1GctConfigError") << "Configuration failed - GCT emulator will not be run" << std::endl;
160  }
161  return success;
162 }
163 
165  // The emulator will always produce output collections, which get filled as long as
166  // the setup and input data are present. Start by making empty output collections.
167 
168  // create the em and jet collections
169  std::unique_ptr<L1GctEmCandCollection> isoEmResult(new L1GctEmCandCollection());
170  std::unique_ptr<L1GctEmCandCollection> nonIsoEmResult(new L1GctEmCandCollection());
171  std::unique_ptr<L1GctJetCandCollection> cenJetResult(new L1GctJetCandCollection());
172  std::unique_ptr<L1GctJetCandCollection> forJetResult(new L1GctJetCandCollection());
173  std::unique_ptr<L1GctJetCandCollection> tauJetResult(new L1GctJetCandCollection());
174 
175  // create the energy sum digis
176  std::unique_ptr<L1GctEtTotalCollection> etTotResult(new L1GctEtTotalCollection());
177  std::unique_ptr<L1GctEtHadCollection> etHadResult(new L1GctEtHadCollection());
178  std::unique_ptr<L1GctEtMissCollection> etMissResult(new L1GctEtMissCollection());
179  std::unique_ptr<L1GctHtMissCollection> htMissResult(new L1GctHtMissCollection());
180 
181  // create the Hf sums digis
182  std::unique_ptr<L1GctHFBitCountsCollection> hfBitCountResult(new L1GctHFBitCountsCollection());
183  std::unique_ptr<L1GctHFRingEtSumsCollection> hfRingEtSumResult(new L1GctHFRingEtSumsCollection());
184 
185  // create internal data collections
186  std::unique_ptr<L1GctInternJetDataCollection> internalJetResult(new L1GctInternJetDataCollection());
187  std::unique_ptr<L1GctInternEtSumCollection> internalEtSumResult(new L1GctInternEtSumCollection());
188  std::unique_ptr<L1GctInternHtMissCollection> internalHtMissResult(new L1GctInternHtMissCollection());
189 
190  // get config data from EventSetup.
191  // check this has been done successfully before proceeding
192  if (configureGct(c) == 0) {
193  // get the RCT data
196  bool gotEm = e.getByToken(m_emToken, em);
197  bool gotRgn = e.getByToken(m_regionToken, rgn);
198 
199  // check the data
200  if (!gotEm && m_verbose) {
201  edm::LogError("L1GctInputFailedError") << "Failed to get em candidates with label " << m_inputLabel
202  << " - GCT emulator will not be run" << std::endl;
203  }
204 
205  if (!gotRgn && m_verbose) {
206  edm::LogError("L1GctInputFailedError")
207  << "Failed to get calo regions with label " << m_inputLabel << " - GCT emulator will not be run" << std::endl;
208  }
209 
210  if (gotEm && !em.isValid()) {
211  gotEm = false;
212  if (m_verbose) {
213  edm::LogError("L1GctInputFailedError") << "isValid() flag set to false for em candidates with label "
214  << m_inputLabel << " - GCT emulator will not be run" << std::endl;
215  }
216  }
217 
218  if (gotRgn && !rgn.isValid()) {
219  gotRgn = false;
220  if (m_verbose) {
221  edm::LogError("L1GctInputFailedError") << "isValid() flag set to false for calo regions with label "
222  << m_inputLabel << " - GCT emulator will not be run" << std::endl;
223  }
224  }
225 
226  // if all is ok, proceed with GCT processing
227  if (gotEm && gotRgn) {
228  // reset the GCT internal buffers
229  m_gct->reset();
230 
231  // fill the GCT source cards
232  m_gct->fillEmCands(*em);
233  m_gct->fillRegions(*rgn);
234 
235  // process the event
236  m_gct->process();
237 
238  // fill the em and jet collections
239  *isoEmResult = m_gct->getIsoElectrons();
240  *nonIsoEmResult = m_gct->getNonIsoElectrons();
241  *cenJetResult = m_gct->getCentralJets();
242  *forJetResult = m_gct->getForwardJets();
243  *tauJetResult = m_gct->getTauJets();
244 
245  // fill the energy sum digis
246  *etTotResult = m_gct->getEtSumCollection();
247  *etHadResult = m_gct->getEtHadCollection();
248  *etMissResult = m_gct->getEtMissCollection();
249  *htMissResult = m_gct->getHtMissCollection();
250 
251  // fill the Hf sums digis
252  *hfBitCountResult = m_gct->getHFBitCountsCollection();
253  *hfRingEtSumResult = m_gct->getHFRingEtSumsCollection();
254 
255  // fill internal data collections if required
256  if (m_writeInternalData) {
257  *internalJetResult = m_gct->getInternalJets();
258  *internalEtSumResult = m_gct->getInternalEtSums();
259  *internalHtMissResult = m_gct->getInternalHtMiss();
260  }
261  }
262  }
263 
264  // put the collections into the event
265  e.put(std::move(isoEmResult), "isoEm");
266  e.put(std::move(nonIsoEmResult), "nonIsoEm");
267  e.put(std::move(cenJetResult), "cenJets");
268  e.put(std::move(forJetResult), "forJets");
269  e.put(std::move(tauJetResult), "tauJets");
270  e.put(std::move(etTotResult));
271  e.put(std::move(etHadResult));
272  e.put(std::move(etMissResult));
273  e.put(std::move(htMissResult));
274  e.put(std::move(hfBitCountResult));
275  e.put(std::move(hfRingEtSumResult));
276 
277  e.put(std::move(internalJetResult));
278  e.put(std::move(internalEtSumResult));
279  e.put(std::move(internalHtMissResult));
280 }
281 
void produce(edm::Event &e, const edm::EventSetup &c) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< L1GctJetFinderParams, L1GctJetFinderParamsRcd > m_jfParsToken
Definition: L1GctEmulator.h:60
edm::EDGetTokenT< L1CaloEmCollection > m_emToken
Definition: L1GctEmulator.h:56
std::vector< L1GctEtMiss > L1GctEtMissCollection
Jet Et calibration LUT.
std::vector< L1GctHFRingEtSums > L1GctHFRingEtSumsCollection
std::vector< L1GctEtHad > L1GctEtHadCollection
std::vector< L1GctInternHtMiss > L1GctInternHtMissCollection
L1GlobalCaloTrigger::lutPtr lutPtr
typedefs
Definition: L1GctEmulator.h:43
Log< level::Error, false > LogError
edm::ESGetToken< L1CaloEtScale, L1HfRingEtScaleRcd > m_hfRingEtScaleToken
Definition: L1GctEmulator.h:64
constexpr uint32_t mask
Definition: gpuClustering.h:24
std::vector< L1GctEtTotal > L1GctEtTotalCollection
T getUntrackedParameter(std::string const &, T const &) const
std::vector< L1GctHFBitCounts > L1GctHFBitCountsCollection
std::vector< L1GctJetCand > L1GctJetCandCollection
T const * product() const
Definition: ESHandle.h:86
edm::ESGetToken< L1CaloEtScale, L1HtMissScaleRcd > m_htMissScaleToken
Definition: L1GctEmulator.h:63
const std::string m_conditionsLabel
Definition: L1GctEmulator.h:79
edm::ESGetToken< L1GctChannelMask, L1GctChannelMaskRcd > m_chanMaskToken
Definition: L1GctEmulator.h:61
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< L1GlobalCaloTrigger > m_gct
Definition: L1GctEmulator.h:67
static const unsigned NUMBER_ETA_VALUES
Number of eta bins used in correction.
const bool m_verbose
Definition: L1GctEmulator.h:76
std::vector< L1GctHtMiss > L1GctHtMissCollection
lutPtrVector m_jetEtCalibLuts
Definition: L1GctEmulator.h:70
bool isValid() const
Definition: HandleBase.h:70
std::vector< L1GctInternJetData > L1GctInternJetDataCollection
std::string m_inputLabel
Definition: L1GctEmulator.h:55
edm::ESGetToken< L1CaloEtScale, L1JetEtScaleRcd > m_etScaleToken
Definition: L1GctEmulator.h:62
std::vector< L1GctInternEtSum > L1GctInternEtSumCollection
Log< level::Warning, false > LogWarning
int configureGct(const edm::EventSetup &c)
const bool m_writeInternalData
Definition: L1GctEmulator.h:73
L1GctEmulator(const edm::ParameterSet &ps)
constructor
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< L1CaloRegionCollection > m_regionToken
Definition: L1GctEmulator.h:57
std::vector< L1GctEmCand > L1GctEmCandCollection