Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-05 23:13:00

0001 #include "L1Trigger/GlobalCaloTrigger/plugins/L1GctEmulator.h"
0002 
0003 // system includes
0004 #include <memory>
0005 #include <vector>
0006 
0007 // EDM includes
0008 #include "FWCore/PluginManager/interface/ModuleDef.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 
0017 // GCT include files
0018 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetEtCalibrationLut.h"
0019 
0020 // RCT data includes
0021 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
0022 
0023 // GCT data includes
0024 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctCollections.h"
0025 
0026 using std::vector;
0027 
0028 L1GctEmulator::L1GctEmulator(const edm::ParameterSet& ps)
0029     : m_jetEtCalibLuts(),
0030       m_writeInternalData(ps.getParameter<bool>("writeInternalData")),
0031       m_verbose(ps.getUntrackedParameter<bool>("verbose", false)),
0032       m_conditionsLabel(ps.getParameter<std::string>("conditionsLabel")) {
0033   // list of products
0034   produces<L1GctEmCandCollection>("isoEm");
0035   produces<L1GctEmCandCollection>("nonIsoEm");
0036   produces<L1GctJetCandCollection>("cenJets");
0037   produces<L1GctJetCandCollection>("forJets");
0038   produces<L1GctJetCandCollection>("tauJets");
0039   produces<L1GctInternJetDataCollection>();
0040   produces<L1GctEtTotalCollection>();
0041   produces<L1GctEtHadCollection>();
0042   produces<L1GctEtMissCollection>();
0043   produces<L1GctHtMissCollection>();
0044   produces<L1GctInternEtSumCollection>();
0045   produces<L1GctInternHtMissCollection>();
0046   produces<L1GctHFBitCountsCollection>();
0047   produces<L1GctHFRingEtSumsCollection>();
0048 
0049   // get the input label
0050   edm::InputTag inputTag = ps.getParameter<edm::InputTag>("inputLabel");
0051   m_inputLabel = inputTag.label();
0052 
0053   // Get the number of bunch crossings to be processed
0054   int firstBx = -ps.getParameter<unsigned>("preSamples");
0055   int lastBx = ps.getParameter<unsigned>("postSamples");
0056 
0057   // instantiate the GCT. Argument selects the type of jetFinder to be used.
0058   L1GctJetLeafCard::jetFinderType jfType = L1GctJetLeafCard::hardwareJetFinder;
0059   std::string jfTypeStr = ps.getParameter<std::string>("jetFinderType");
0060   if (jfTypeStr == "tdrJetFinder") {
0061     jfType = L1GctJetLeafCard::tdrJetFinder;
0062   } else if (jfTypeStr != "hardwareJetFinder") {
0063     edm::LogWarning("L1GctEmulatorSetup")
0064         << "Unrecognised jetFinder option " << jfTypeStr << "\nHardware jetFinder will be used";
0065   }
0066   bool hwTest = ps.getParameter<bool>("hardwareTest");
0067   if (hwTest) {
0068     unsigned mask = ps.getUntrackedParameter<unsigned>("jetLeafMask", 0);
0069     m_gct = std::make_unique<L1GlobalCaloTrigger>(jfType, mask);
0070     edm::LogWarning("L1GctEmulatorSetup") << "Emulator has been configured in hardware test mode with mask " << mask
0071                                           << "\nThis mode should NOT be used for Physics studies!";
0072   } else {
0073     m_gct = std::make_unique<L1GlobalCaloTrigger>(jfType);
0074   }
0075   m_gct->setBxRange(firstBx, lastBx);
0076 
0077   // Fill the jetEtCalibLuts vector
0078   lutPtr nextLut(new L1GctJetEtCalibrationLut());
0079 
0080   for (unsigned ieta = 0; ieta < L1GctJetFinderParams::NUMBER_ETA_VALUES; ieta++) {
0081     nextLut->setEtaBin(ieta);
0082     m_jetEtCalibLuts.push_back(nextLut);
0083     nextLut.reset(new L1GctJetEtCalibrationLut());
0084   }
0085 
0086   // Setup the tau algorithm parameters
0087   bool useImprovedTauAlgo = ps.getParameter<bool>("useImprovedTauAlgorithm");
0088   bool ignoreTauVetoBitsForIsolation = ps.getParameter<bool>("ignoreRCTTauVetoBitsForIsolation");
0089   m_gct->setupTauAlgo(useImprovedTauAlgo, ignoreTauVetoBitsForIsolation);
0090 
0091   // set verbosity (not implemented yet!)
0092   //  m_gct->setVerbose(m_verbose);
0093 
0094   // print debug info?
0095   if (m_verbose) {
0096     m_gct->print();
0097   }
0098   m_emToken = consumes<L1CaloEmCollection>(inputTag);
0099   m_regionToken = consumes<L1CaloRegionCollection>(inputTag);
0100   m_jfParsToken = esConsumes<L1GctJetFinderParams, L1GctJetFinderParamsRcd>(edm::ESInputTag("", m_conditionsLabel));
0101   m_chanMaskToken = esConsumes<L1GctChannelMask, L1GctChannelMaskRcd>(edm::ESInputTag("", m_conditionsLabel));
0102   m_etScaleToken = esConsumes<L1CaloEtScale, L1JetEtScaleRcd>(edm::ESInputTag("", m_conditionsLabel));
0103   m_htMissScaleToken = esConsumes<L1CaloEtScale, L1HtMissScaleRcd>(edm::ESInputTag("", m_conditionsLabel));
0104   m_hfRingEtScaleToken = esConsumes<L1CaloEtScale, L1HfRingEtScaleRcd>(edm::ESInputTag("", m_conditionsLabel));
0105 }
0106 
0107 int L1GctEmulator::configureGct(const edm::EventSetup& c) {
0108   int success = 0;
0109 
0110   if (success == 0) {
0111     // get data from EventSetup
0112     edm::ESHandle<L1GctJetFinderParams> jfPars = c.getHandle(m_jfParsToken);
0113     edm::ESHandle<L1GctChannelMask> chanMask = c.getHandle(m_chanMaskToken);
0114     edm::ESHandle<L1CaloEtScale> etScale = c.getHandle(m_etScaleToken);
0115     edm::ESHandle<L1CaloEtScale> htMissScale = c.getHandle(m_htMissScaleToken);
0116     edm::ESHandle<L1CaloEtScale> hfRingEtScale = c.getHandle(m_hfRingEtScaleToken);
0117 
0118     if (jfPars.product() == nullptr) {
0119       success = -1;
0120       if (m_verbose) {
0121         edm::LogWarning("L1GctConfigFailure")
0122             << "Failed to find a L1GctJetFinderParamsRcd:L1GctJetFinderParams in EventSetup!" << std::endl;
0123       }
0124     }
0125 
0126     if (chanMask.product() == nullptr) {
0127       success = -1;
0128       if (m_verbose) {
0129         edm::LogWarning("L1GctConfigFailure")
0130             << "Failed to find a L1GctChannelMaskRcd:L1GctChannelMask in EventSetup!" << std::endl;
0131       }
0132     }
0133 
0134     if (hfRingEtScale.product() == nullptr) {
0135       success = -1;
0136       if (m_verbose) {
0137         edm::LogWarning("L1GctConfigFailure")
0138             << "Failed to find a L1HfRingEtScaleRcd:L1HfRingEtScaleRcd in EventSetup!" << std::endl;
0139       }
0140     }
0141 
0142     if (success == 0) {
0143       // tell the jet Et Luts about the scales
0144       for (unsigned ieta = 0; ieta < m_jetEtCalibLuts.size(); ieta++) {
0145         m_jetEtCalibLuts.at(ieta)->setFunction(jfPars.product());
0146         m_jetEtCalibLuts.at(ieta)->setOutputEtScale(etScale.product());
0147       }
0148 
0149       // pass all the setup info to the gct
0150       m_gct->setJetEtCalibrationLuts(m_jetEtCalibLuts);
0151       m_gct->setJetFinderParams(jfPars.product());
0152       m_gct->setHtMissScale(htMissScale.product());
0153       m_gct->setupHfSumLuts(hfRingEtScale.product());
0154       m_gct->setChannelMask(chanMask.product());
0155     }
0156   }
0157 
0158   if (success != 0 && m_verbose) {
0159     edm::LogError("L1GctConfigError") << "Configuration failed - GCT emulator will not be run" << std::endl;
0160   }
0161   return success;
0162 }
0163 
0164 void L1GctEmulator::produce(edm::Event& e, const edm::EventSetup& c) {
0165   // The emulator will always produce output collections, which get filled as long as
0166   // the setup and input data are present. Start by making empty output collections.
0167 
0168   // create the em and jet collections
0169   std::unique_ptr<L1GctEmCandCollection> isoEmResult(new L1GctEmCandCollection());
0170   std::unique_ptr<L1GctEmCandCollection> nonIsoEmResult(new L1GctEmCandCollection());
0171   std::unique_ptr<L1GctJetCandCollection> cenJetResult(new L1GctJetCandCollection());
0172   std::unique_ptr<L1GctJetCandCollection> forJetResult(new L1GctJetCandCollection());
0173   std::unique_ptr<L1GctJetCandCollection> tauJetResult(new L1GctJetCandCollection());
0174 
0175   // create the energy sum digis
0176   std::unique_ptr<L1GctEtTotalCollection> etTotResult(new L1GctEtTotalCollection());
0177   std::unique_ptr<L1GctEtHadCollection> etHadResult(new L1GctEtHadCollection());
0178   std::unique_ptr<L1GctEtMissCollection> etMissResult(new L1GctEtMissCollection());
0179   std::unique_ptr<L1GctHtMissCollection> htMissResult(new L1GctHtMissCollection());
0180 
0181   // create the Hf sums digis
0182   std::unique_ptr<L1GctHFBitCountsCollection> hfBitCountResult(new L1GctHFBitCountsCollection());
0183   std::unique_ptr<L1GctHFRingEtSumsCollection> hfRingEtSumResult(new L1GctHFRingEtSumsCollection());
0184 
0185   // create internal data collections
0186   std::unique_ptr<L1GctInternJetDataCollection> internalJetResult(new L1GctInternJetDataCollection());
0187   std::unique_ptr<L1GctInternEtSumCollection> internalEtSumResult(new L1GctInternEtSumCollection());
0188   std::unique_ptr<L1GctInternHtMissCollection> internalHtMissResult(new L1GctInternHtMissCollection());
0189 
0190   // get config data from EventSetup.
0191   // check this has been done successfully before proceeding
0192   if (configureGct(c) == 0) {
0193     // get the RCT data
0194     edm::Handle<L1CaloEmCollection> em;
0195     edm::Handle<L1CaloRegionCollection> rgn;
0196     bool gotEm = e.getByToken(m_emToken, em);
0197     bool gotRgn = e.getByToken(m_regionToken, rgn);
0198 
0199     // check the data
0200     if (!gotEm && m_verbose) {
0201       edm::LogError("L1GctInputFailedError") << "Failed to get em candidates with label " << m_inputLabel
0202                                              << " - GCT emulator will not be run" << std::endl;
0203     }
0204 
0205     if (!gotRgn && m_verbose) {
0206       edm::LogError("L1GctInputFailedError")
0207           << "Failed to get calo regions with label " << m_inputLabel << " - GCT emulator will not be run" << std::endl;
0208     }
0209 
0210     if (gotEm && !em.isValid()) {
0211       gotEm = false;
0212       if (m_verbose) {
0213         edm::LogError("L1GctInputFailedError") << "isValid() flag set to false for em candidates with label "
0214                                                << m_inputLabel << " - GCT emulator will not be run" << std::endl;
0215       }
0216     }
0217 
0218     if (gotRgn && !rgn.isValid()) {
0219       gotRgn = false;
0220       if (m_verbose) {
0221         edm::LogError("L1GctInputFailedError") << "isValid() flag set to false for calo regions with label "
0222                                                << m_inputLabel << " - GCT emulator will not be run" << std::endl;
0223       }
0224     }
0225 
0226     // if all is ok, proceed with GCT processing
0227     if (gotEm && gotRgn) {
0228       // reset the GCT internal buffers
0229       m_gct->reset();
0230 
0231       // fill the GCT source cards
0232       m_gct->fillEmCands(*em);
0233       m_gct->fillRegions(*rgn);
0234 
0235       // process the event
0236       m_gct->process();
0237 
0238       // fill the em and jet collections
0239       *isoEmResult = m_gct->getIsoElectrons();
0240       *nonIsoEmResult = m_gct->getNonIsoElectrons();
0241       *cenJetResult = m_gct->getCentralJets();
0242       *forJetResult = m_gct->getForwardJets();
0243       *tauJetResult = m_gct->getTauJets();
0244 
0245       // fill the energy sum digis
0246       *etTotResult = m_gct->getEtSumCollection();
0247       *etHadResult = m_gct->getEtHadCollection();
0248       *etMissResult = m_gct->getEtMissCollection();
0249       *htMissResult = m_gct->getHtMissCollection();
0250 
0251       // fill the Hf sums digis
0252       *hfBitCountResult = m_gct->getHFBitCountsCollection();
0253       *hfRingEtSumResult = m_gct->getHFRingEtSumsCollection();
0254 
0255       // fill internal data collections if required
0256       if (m_writeInternalData) {
0257         *internalJetResult = m_gct->getInternalJets();
0258         *internalEtSumResult = m_gct->getInternalEtSums();
0259         *internalHtMissResult = m_gct->getInternalHtMiss();
0260       }
0261     }
0262   }
0263 
0264   // put the collections into the event
0265   e.put(std::move(isoEmResult), "isoEm");
0266   e.put(std::move(nonIsoEmResult), "nonIsoEm");
0267   e.put(std::move(cenJetResult), "cenJets");
0268   e.put(std::move(forJetResult), "forJets");
0269   e.put(std::move(tauJetResult), "tauJets");
0270   e.put(std::move(etTotResult));
0271   e.put(std::move(etHadResult));
0272   e.put(std::move(etMissResult));
0273   e.put(std::move(htMissResult));
0274   e.put(std::move(hfBitCountResult));
0275   e.put(std::move(hfRingEtSumResult));
0276 
0277   e.put(std::move(internalJetResult));
0278   e.put(std::move(internalEtSumResult));
0279   e.put(std::move(internalHtMissResult));
0280 }
0281 
0282 DEFINE_FWK_MODULE(L1GctEmulator);