CMS 3D CMS Logo

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