CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 // Trigger configuration includes
27 
28 // GCT include files
30 
31 // RCT data includes
33 
34 // GCT data includes
36 
37 using std::vector;
38 
40  m_jetEtCalibLuts(),
41  m_writeInternalData(ps.getParameter<bool>("writeInternalData")),
42  m_verbose(ps.getUntrackedParameter<bool>("verbose", false)),
43  m_conditionsLabel(ps.getParameter<std::string>("conditionsLabel"))
44  {
45 
46  // list of products
47  produces<L1GctEmCandCollection>("isoEm");
48  produces<L1GctEmCandCollection>("nonIsoEm");
49  produces<L1GctJetCandCollection>("cenJets");
50  produces<L1GctJetCandCollection>("forJets");
51  produces<L1GctJetCandCollection>("tauJets");
52  produces<L1GctInternJetDataCollection>();
53  produces<L1GctEtTotalCollection>();
54  produces<L1GctEtHadCollection>();
55  produces<L1GctEtMissCollection>();
56  produces<L1GctHtMissCollection>();
57  produces<L1GctInternEtSumCollection>();
58  produces<L1GctInternHtMissCollection>();
59  produces<L1GctHFBitCountsCollection>();
60  produces<L1GctHFRingEtSumsCollection>();
61 
62  // get the input label
64  m_inputLabel = inputTag.label();
65 
66  // Get the number of bunch crossings to be processed
67  int firstBx = -ps.getParameter<unsigned>("preSamples");
68  int lastBx = ps.getParameter<unsigned>("postSamples");
69 
70  // instantiate the GCT. Argument selects the type of jetFinder to be used.
72  std::string jfTypeStr = ps.getParameter<std::string>("jetFinderType");
73  if (jfTypeStr == "tdrJetFinder") { jfType = L1GctJetLeafCard::tdrJetFinder; }
74  else if (jfTypeStr != "hardwareJetFinder") {
75  edm::LogWarning ("L1GctEmulatorSetup") << "Unrecognised jetFinder option " << jfTypeStr
76  << "\nHardware jetFinder will be used";
77  }
78  bool hwTest = ps.getParameter<bool>("hardwareTest");
79  if (hwTest) {
80  unsigned mask = ps.getUntrackedParameter<unsigned>("jetLeafMask", 0);
81  m_gct = new L1GlobalCaloTrigger(jfType, mask);
82  edm::LogWarning ("L1GctEmulatorSetup") << "Emulator has been configured in hardware test mode with mask " << mask
83  << "\nThis mode should NOT be used for Physics studies!";
84  } else {
85  m_gct = new L1GlobalCaloTrigger(jfType);
86  }
87  m_gct->setBxRange(firstBx, lastBx);
88 
89  // Fill the jetEtCalibLuts vector
90  lutPtr nextLut( new L1GctJetEtCalibrationLut() );
91 
92  for (unsigned ieta=0; ieta<L1GctJetFinderParams::NUMBER_ETA_VALUES; ieta++) {
93  nextLut->setEtaBin(ieta);
94  m_jetEtCalibLuts.push_back(nextLut);
95  nextLut.reset ( new L1GctJetEtCalibrationLut() );
96  }
97 
98  // Setup the tau algorithm parameters
99  bool useImprovedTauAlgo = ps.getParameter<bool>("useImprovedTauAlgorithm");
100  bool ignoreTauVetoBitsForIsolation = ps.getParameter<bool>("ignoreRCTTauVetoBitsForIsolation");
101  m_gct->setupTauAlgo(useImprovedTauAlgo, ignoreTauVetoBitsForIsolation);
102 
103  // set verbosity (not implemented yet!)
104  // m_gct->setVerbose(m_verbose);
105 
106  // print debug info?
107  if (m_verbose) {
108  m_gct->print();
109  }
110  consumes<L1CaloEmCollection>(m_inputLabel);
111  consumes<L1CaloRegionCollection>(m_inputLabel);
112 }
113 
115  if (m_gct != 0) delete m_gct;
116 }
117 
118 
120 {
121 }
122 
124 {
125 }
126 
128 {
129  int success = 0;
130  if (&c==0) {
131  success = -1;
132  if (m_verbose) {
133  edm::LogWarning("L1GctConfigFailure") << "Cannot find EventSetup information." << std::endl;
134  }
135  }
136 
137  if (success == 0) {
138  // get data from EventSetup
140  c.get< L1GctJetFinderParamsRcd >().get( m_conditionsLabel, jfPars ) ; // which record?
142  c.get< L1GctChannelMaskRcd >().get( m_conditionsLabel, chanMask ) ; // which record?
144  c.get< L1JetEtScaleRcd >().get( m_conditionsLabel, etScale ) ; // which record?
145  edm::ESHandle< L1CaloEtScale > htMissScale ;
146  c.get< L1HtMissScaleRcd >().get( m_conditionsLabel, htMissScale ) ; // which record?
147  edm::ESHandle< L1CaloEtScale > hfRingEtScale ;
148  c.get< L1HfRingEtScaleRcd >().get( m_conditionsLabel, hfRingEtScale ) ; // which record?
149 
150 
151  if (jfPars.product() == 0) {
152  success = -1;
153  if (m_verbose) {
154  edm::LogWarning("L1GctConfigFailure")
155  << "Failed to find a L1GctJetFinderParamsRcd:L1GctJetFinderParams in EventSetup!" << std::endl;
156  }
157  }
158 
159  if (chanMask.product() == 0) {
160  success = -1;
161  if (m_verbose) {
162  edm::LogWarning("L1GctConfigFailure")
163  << "Failed to find a L1GctChannelMaskRcd:L1GctChannelMask in EventSetup!" << std::endl;
164  }
165  }
166 
167  if (hfRingEtScale.product() == 0) {
168  success = -1;
169  if (m_verbose) {
170  edm::LogWarning("L1GctConfigFailure")
171  << "Failed to find a L1HfRingEtScaleRcd:L1HfRingEtScaleRcd in EventSetup!" << std::endl;
172  }
173  }
174 
175 
176  if (success==0) {
177  // tell the jet Et Luts about the scales
178  for (unsigned ieta=0; ieta<m_jetEtCalibLuts.size(); ieta++) {
179  m_jetEtCalibLuts.at(ieta)->setFunction(jfPars.product());
180  m_jetEtCalibLuts.at(ieta)->setOutputEtScale(etScale.product());
181  }
182 
183  // pass all the setup info to the gct
185  m_gct->setJetFinderParams(jfPars.product());
186  m_gct->setHtMissScale(htMissScale.product());
187  m_gct->setupHfSumLuts(hfRingEtScale.product());
188  m_gct->setChannelMask(chanMask.product());
189  }
190  }
191 
192  if (success != 0 && m_verbose) {
193  edm::LogError("L1GctConfigError")
194  << "Configuration failed - GCT emulator will not be run" << std::endl;
195  }
196  return success;
197 }
198 
200 
201  // The emulator will always produce output collections, which get filled as long as
202  // the setup and input data are present. Start by making empty output collections.
203 
204  // create the em and jet collections
205  std::auto_ptr<L1GctEmCandCollection> isoEmResult (new L1GctEmCandCollection( ) );
206  std::auto_ptr<L1GctEmCandCollection> nonIsoEmResult(new L1GctEmCandCollection( ) );
207  std::auto_ptr<L1GctJetCandCollection> cenJetResult(new L1GctJetCandCollection( ) );
208  std::auto_ptr<L1GctJetCandCollection> forJetResult(new L1GctJetCandCollection( ) );
209  std::auto_ptr<L1GctJetCandCollection> tauJetResult(new L1GctJetCandCollection( ) );
210 
211  // create the energy sum digis
212  std::auto_ptr<L1GctEtTotalCollection> etTotResult (new L1GctEtTotalCollection( ) );
213  std::auto_ptr<L1GctEtHadCollection> etHadResult (new L1GctEtHadCollection ( ) );
214  std::auto_ptr<L1GctEtMissCollection> etMissResult(new L1GctEtMissCollection ( ) );
215  std::auto_ptr<L1GctHtMissCollection> htMissResult(new L1GctHtMissCollection ( ) );
216 
217  // create the Hf sums digis
218  std::auto_ptr<L1GctHFBitCountsCollection> hfBitCountResult (new L1GctHFBitCountsCollection ( ) );
219  std::auto_ptr<L1GctHFRingEtSumsCollection> hfRingEtSumResult(new L1GctHFRingEtSumsCollection( ) );
220 
221  // create internal data collections
222  std::auto_ptr<L1GctInternJetDataCollection> internalJetResult (new L1GctInternJetDataCollection( ));
223  std::auto_ptr<L1GctInternEtSumCollection> internalEtSumResult (new L1GctInternEtSumCollection ( ));
224  std::auto_ptr<L1GctInternHtMissCollection> internalHtMissResult(new L1GctInternHtMissCollection ( ));
225 
226  // get config data from EventSetup.
227  // check this has been done successfully before proceeding
228  if (configureGct(c) == 0) {
229 
230  // get the RCT data
233  bool gotEm = e.getByLabel(m_inputLabel, em);
234  bool gotRgn = e.getByLabel(m_inputLabel, rgn);
235 
236  // check the data
237  if (!gotEm && m_verbose) {
238  edm::LogError("L1GctInputFailedError")
239  << "Failed to get em candidates with label " << m_inputLabel << " - GCT emulator will not be run" << std::endl;
240  }
241 
242  if (!gotRgn && m_verbose) {
243  edm::LogError("L1GctInputFailedError")
244  << "Failed to get calo regions with label " << m_inputLabel << " - GCT emulator will not be run" << std::endl;
245  }
246 
247  if (gotEm && !em.isValid()) {
248  gotEm = false;
249  if (m_verbose) {
250  edm::LogError("L1GctInputFailedError")
251  << "isValid() flag set to false for em candidates with label " << m_inputLabel << " - GCT emulator will not be run" << std::endl;
252  }
253  }
254 
255  if (gotRgn && !rgn.isValid()) {
256  gotRgn = false;
257  if (m_verbose) {
258  edm::LogError("L1GctInputFailedError")
259  << "isValid() flag set to false for calo regions with label " << m_inputLabel << " - GCT emulator will not be run" << std::endl;
260  }
261  }
262 
263  // if all is ok, proceed with GCT processing
264  if (gotEm && gotRgn) {
265  // reset the GCT internal buffers
266  m_gct->reset();
267 
268  // fill the GCT source cards
269  m_gct->fillEmCands(*em);
270  m_gct->fillRegions(*rgn);
271 
272  // process the event
273  m_gct->process();
274 
275  // fill the em and jet collections
276  *isoEmResult = m_gct->getIsoElectrons();
277  *nonIsoEmResult = m_gct->getNonIsoElectrons();
278  *cenJetResult = m_gct->getCentralJets();
279  *forJetResult = m_gct->getForwardJets();
280  *tauJetResult = m_gct->getTauJets();
281 
282  // fill the energy sum digis
283  *etTotResult = m_gct->getEtSumCollection();
284  *etHadResult = m_gct->getEtHadCollection();
285  *etMissResult = m_gct->getEtMissCollection();
286  *htMissResult = m_gct->getHtMissCollection();
287 
288  // fill the Hf sums digis
289  *hfBitCountResult = m_gct->getHFBitCountsCollection ();
290  *hfRingEtSumResult = m_gct->getHFRingEtSumsCollection();
291 
292  // fill internal data collections if required
293  if (m_writeInternalData) {
294  *internalJetResult = m_gct->getInternalJets();
295  *internalEtSumResult = m_gct->getInternalEtSums();
296  *internalHtMissResult = m_gct->getInternalHtMiss();
297  }
298  }
299  }
300 
301  // put the collections into the event
302  e.put(isoEmResult,"isoEm");
303  e.put(nonIsoEmResult,"nonIsoEm");
304  e.put(cenJetResult,"cenJets");
305  e.put(forJetResult,"forJets");
306  e.put(tauJetResult,"tauJets");
307  e.put(etTotResult);
308  e.put(etHadResult);
309  e.put(etMissResult);
310  e.put(htMissResult);
311  e.put(hfBitCountResult);
312  e.put(hfRingEtSumResult);
313 
314  e.put(internalJetResult);
315  e.put(internalEtSumResult);
316  e.put(internalHtMissResult);
317 
318 }
319 
321 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
L1GctHFRingEtSumsCollection getHFRingEtSumsCollection() const
void fillEmCands(const std::vector< L1CaloEmCand > &rgn)
set electrons from the RCT at the input to be processed
L1GctJetCandCollection getTauJets() const
tau jet outputs to GT
void setupTauAlgo(const bool useImprovedAlgo, const bool ignoreVetoBitsForIsolation)
setup the tau algorithm parameters
L1GctHFBitCountsCollection getHFBitCountsCollection() const
std::vector< L1GctEtMiss > L1GctEtMissCollection
Jet Et calibration LUT.
std::vector< L1GctHFRingEtSums > L1GctHFRingEtSumsCollection
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setJetFinderParams(const L1GctJetFinderParams *const jfpars)
std::vector< L1GctEtHad > L1GctEtHadCollection
std::vector< L1GctInternHtMiss > L1GctInternHtMissCollection
L1GlobalCaloTrigger::lutPtr lutPtr
typedefs
Definition: L1GctEmulator.h:33
L1GctJetCandCollection getForwardJets() const
forward jet outputs to GT
L1GctEmCandCollection getNonIsoElectrons() const
non-iso electron outputs to GT
L1GctHtMissCollection getHtMissCollection() const
Htmiss output to GT.
Bit-level emulation of the Global Calorimeter Trigger.
L1GctEtTotalCollection getEtSumCollection() const
Total Et output to GT.
std::vector< L1GctEtTotal > L1GctEtTotalCollection
L1GlobalCaloTrigger * m_gct
Definition: L1GctEmulator.h:53
std::vector< L1GctHFBitCounts > L1GctHFBitCountsCollection
std::vector< L1GctJetCand > L1GctJetCandCollection
void setHtMissScale(const L1CaloEtScale *const scale)
setup scale for missing Ht
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
L1GctInternHtMissCollection getInternalHtMiss() const
std::string m_conditionsLabel
Definition: L1GctEmulator.h:65
void fillRegions(const std::vector< L1CaloRegion > &rgn)
L1GctEtHadCollection getEtHadCollection() const
Total hadronic Et output to GT.
void setupHfSumLuts(const L1CaloEtScale *const scale)
setup Hf sum LUTs
void setBxRange(const int firstBx, const int lastBx)
L1GctJetCandCollection getCentralJets() const
central jet outputs to GT
bool isValid() const
Definition: HandleBase.h:75
L1GctInternJetDataCollection getInternalJets() const
all jets from jetfinders in raw format
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
static const unsigned NUMBER_ETA_VALUES
Number of eta bins used in correction.
void reset()
Reset internal buffers.
void setChannelMask(const L1GctChannelMask *const mask)
setup the input channel mask
L1GctEmCandCollection getIsoElectrons() const
std::vector< L1GctHtMiss > L1GctHtMissCollection
void setJetEtCalibrationLuts(const lutPtrVector &jfluts)
setup the Jet Calibration Luts
bool m_writeInternalData
Definition: L1GctEmulator.h:59
lutPtrVector m_jetEtCalibLuts
Definition: L1GctEmulator.h:56
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
std::vector< L1GctInternJetData > L1GctInternJetDataCollection
std::string m_inputLabel
Definition: L1GctEmulator.h:50
std::vector< L1GctInternEtSum > L1GctInternEtSumCollection
volatile std::atomic< bool > shutdown_flag false
int configureGct(const edm::EventSetup &c)
L1GctEmulator(const edm::ParameterSet &ps)
constructor
~L1GctEmulator()
destructor
L1GctEtMissCollection getEtMissCollection() const
Etmiss output to GT.
void process()
process an event
void produce(edm::Event &e, const edm::EventSetup &c)
std::vector< L1GctEmCand > L1GctEmCandCollection
L1GctInternEtSumCollection getInternalEtSums() const
Et sums and components in internal format.