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