diff --git a/HLTrigger/Configuration/python/customizeHLTforCMSSW.py b/HLTrigger/Configuration/python/customizeHLTforCMSSW.py index 90a1f649ed921..cf6b3f412d26e 100644 --- a/HLTrigger/Configuration/python/customizeHLTforCMSSW.py +++ b/HLTrigger/Configuration/python/customizeHLTforCMSSW.py @@ -243,6 +243,16 @@ def checkHLTfor43774(process): print('# TSG WARNING: check value of parameter "useAbs" in',filt,'(expect True but is False)!') return process + +def customizeHLTfor44510(process): + """ + Customisation for running HLT with the updated L1 UTM and AXOL1TL condition parsing from the PR 44054 + """ + for producer in producers_by_type(process, "L1TGlobalProducer"): + if hasattr(producer, 'AXOL1TLModelVersion'): + delattr(producer, 'AXOL1TLModelVersion') + return process + # CMSSW version specific customizations def customizeHLTforCMSSW(process, menuType="GRun"): @@ -260,4 +270,7 @@ def customizeHLTforCMSSW(process, menuType="GRun"): process = checkHLTfor43774(process) + # customizes AXOL1TL condition in the L1 menu + process = customizeHLTfor44510(process) + return process diff --git a/L1Trigger/L1TGlobal/interface/AXOL1TLCondition.h b/L1Trigger/L1TGlobal/interface/AXOL1TLCondition.h index d08e1bfc9cd3d..64540dce2714b 100644 --- a/L1Trigger/L1TGlobal/interface/AXOL1TLCondition.h +++ b/L1Trigger/L1TGlobal/interface/AXOL1TLCondition.h @@ -59,11 +59,6 @@ namespace l1t { void setuGtB(const GlobalBoard*); - //get / set AXOL1TL model version - inline const std::string gtModelVerion() const { return m_AXOL1TLmodelversion; } - - void setModelVersion(const std::string modelversionname); - private: /// copy function for copy constructor and operator= void copy(const AXOL1TLCondition& cp); @@ -73,9 +68,6 @@ namespace l1t { /// pointer to uGt GlobalBoard, to be able to get the trigger objects const GlobalBoard* m_gtGTB; - - //to set modelversion from globalboard<-globalproducer<-config - std::string m_AXOL1TLmodelversion = "NONE"; }; } // namespace l1t diff --git a/L1Trigger/L1TGlobal/interface/AXOL1TLTemplate.h b/L1Trigger/L1TGlobal/interface/AXOL1TLTemplate.h index 20911ada8fbf1..9be22f30a5687 100644 --- a/L1Trigger/L1TGlobal/interface/AXOL1TLTemplate.h +++ b/L1Trigger/L1TGlobal/interface/AXOL1TLTemplate.h @@ -52,9 +52,13 @@ class AXOL1TLTemplate : public GlobalCondition { public: inline const std::vector* objectParameter() const { return &m_objectParameter; } + inline const std::string& modelVersion() const { return m_modelVersion; } + /// set functions void setConditionParameter(const std::vector& objParameter); + void setModelVersion(const std::string& modelversion); + /// print the condition void print(std::ostream& myCout) const override; @@ -67,6 +71,9 @@ class AXOL1TLTemplate : public GlobalCondition { /// variables containing the parameters std::vector m_objectParameter; + + /// model version + std::string m_modelVersion; }; #endif diff --git a/L1Trigger/L1TGlobal/interface/GlobalBoard.h b/L1Trigger/L1TGlobal/interface/GlobalBoard.h index f5198a61d6230..a6d14a0c8d5a6 100644 --- a/L1Trigger/L1TGlobal/interface/GlobalBoard.h +++ b/L1Trigger/L1TGlobal/interface/GlobalBoard.h @@ -204,8 +204,6 @@ namespace l1t { void setResetPSCountersEachLumiSec(bool val) { m_resetPSCountersEachLumiSec = val; } void setSemiRandomInitialPSCounters(bool val) { m_semiRandomInitialPSCounters = val; } - void setAXOL1TLModelVersion(std::string axol1tlModelVersion); - public: inline void setVerbosity(const int verbosity) { m_verbosity = verbosity; } @@ -244,8 +242,6 @@ namespace l1t { int m_bxFirst_; int m_bxLast_; - std::string m_axol1tlModelVersion = "NULL"; - std::bitset m_gtlAlgorithmOR; std::bitset m_gtlDecisionWord; diff --git a/L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.cc b/L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.cc index b7eed1da6480a..81a51738e67c5 100644 --- a/L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.cc +++ b/L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.cc @@ -68,9 +68,6 @@ void L1TGlobalProducer::fillDescriptions(edm::ConfigurationDescriptions& descrip desc.add("AlgorithmTriggersUnmasked", false) ->setComment("not required, but recommend to specify explicitly in config"); - //AXOl1TL model version: - desc.add("AXOL1TLModelVersion", ""); - // switch for muon showers in Run-3 desc.add("useMuonShowers", false); @@ -133,7 +130,6 @@ L1TGlobalProducer::L1TGlobalProducer(const edm::ParameterSet& parSet) m_algoblkInputTag(parSet.getParameter("AlgoBlkInputTag")), m_resetPSCountersEachLumiSec(parSet.getParameter("resetPSCountersEachLumiSec")), m_semiRandomInitialPSCounters(parSet.getParameter("semiRandomInitialPSCounters")), - m_AXOL1TLModelVersion(parSet.getParameter("AXOL1TLModelVersion")), m_useMuonShowers(parSet.getParameter("useMuonShowers")) { m_egInputToken = consumes>(m_egInputTag); m_tauInputToken = consumes>(m_tauInputTag); @@ -625,10 +621,6 @@ void L1TGlobalProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSet m_uGtBrd->receiveMuonObjectData(iEvent, m_muInputToken, receiveMu, m_nrL1Mu); - //for getting model version to the condition class, later will come from the menu - //used in runGTL - m_uGtBrd->setAXOL1TLModelVersion(m_AXOL1TLModelVersion); - if (m_useMuonShowers) m_uGtBrd->receiveMuonShowerObjectData(iEvent, m_muShowerInputToken, receiveMuShower, m_nrL1MuShower); diff --git a/L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.h b/L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.h index f3c5e84e97837..2da54f435f6fb 100644 --- a/L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.h +++ b/L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.h @@ -195,9 +195,6 @@ class L1TGlobalProducer : public edm::stream::EDProducer<> { // if false, the prescale counters are initialised to zero bool m_semiRandomInitialPSCounters; - //string to store AXOL1TL model version - std::string m_AXOL1TLModelVersion; - // switch to load muon showers in the global board bool m_useMuonShowers; }; diff --git a/L1Trigger/L1TGlobal/plugins/TriggerMenuParser.cc b/L1Trigger/L1TGlobal/plugins/TriggerMenuParser.cc index c1e0a86e22f61..81fb9afa080e2 100644 --- a/L1Trigger/L1TGlobal/plugins/TriggerMenuParser.cc +++ b/L1Trigger/L1TGlobal/plugins/TriggerMenuParser.cc @@ -322,7 +322,8 @@ void l1t::TriggerMenuParser::parseCondFormats(const L1TUtmTriggerMenu* utmMenu) parseEnergySumZdc(condition, chipNr, false); //parse AXOL1TL - } else if (condition.getType() == esConditionType::AnomalyDetectionTrigger) { + } else if (condition.getType() == esConditionType::Axol1tlTrigger || + condition.getType() == esConditionType::AnomalyDetectionTrigger) { parseAXOL1TL(condition, chipNr); //parse Muons @@ -2752,19 +2753,51 @@ bool l1t::TriggerMenuParser::parseAXOL1TL(L1TUtmCondition condAXOL1TL, unsigned int lowerThresholdInd = 0; int upperThresholdInd = -1; - const std::vector& cuts = object.getCuts(); - for (size_t kk = 0; kk < cuts.size(); kk++) { - const L1TUtmCut& cut = cuts.at(kk); + //save model and threshold + std::string model = ""; - switch (cut.getCutType()) { - case esCutType::AnomalyScore: + // for UTM v12+ + if (object.getType() == tmeventsetup::Axol1tl) { + const std::vector& cuts = object.getCuts(); + for (size_t kk = 0; kk < cuts.size(); kk++) { + const L1TUtmCut& cut = cuts.at(kk); + + //save model + if (cut.getCutType() == tmeventsetup::Model) { + model = cut.getData(); + } + //save score + else if (cut.getCutType() == esCutType::Score) { + lowerThresholdInd = cut.getMinimum().value; + upperThresholdInd = cut.getMaximum().value; + } //end else if + } //end cut loop + } //end if getType + // LEGACY + // for UTM pre v12 + else if (condAXOL1TL.getType() == esConditionType::AnomalyDetectionTrigger) { + // hard-code model version for legacy Menu + model = "v3"; + + const std::vector& cuts = object.getCuts(); + for (size_t kk = 0; kk < cuts.size(); kk++) { + const L1TUtmCut& cut = cuts.at(kk); + if (cut.getCutType() == esCutType::AnomalyScore) { lowerThresholdInd = cut.getMinimum().value; upperThresholdInd = cut.getMaximum().value; break; - default: - break; - } //end switch - } //end cut loop + } + } //end cut loop + } else { + edm::LogError("TriggerMenuParser") << " Error: not a proper AXOL1TL condition" << std::endl; + return false; + } + + // check model version is not empty + if (model == "") { + edm::LogError("TriggerMenuParser") << " Error: AXOL1TL movel version is empty" << std::endl; + return false; + } //fill object params objParameter[0].minAXOL1TLThreshold = lowerThresholdInd; @@ -2777,6 +2810,7 @@ bool l1t::TriggerMenuParser::parseAXOL1TL(L1TUtmCondition condAXOL1TL, unsigned axol1tlCond.setCondChipNr(chipNr); axol1tlCond.setCondRelativeBx(relativeBx); axol1tlCond.setConditionParameter(objParameter); + axol1tlCond.setModelVersion(model); if (edm::isDebugEnabled()) { std::ostringstream myCoutStream; diff --git a/L1Trigger/L1TGlobal/python/simGtStage2Digis_cfi.py b/L1Trigger/L1TGlobal/python/simGtStage2Digis_cfi.py index 685ae9b7dd690..1f38f24ab957a 100644 --- a/L1Trigger/L1TGlobal/python/simGtStage2Digis_cfi.py +++ b/L1Trigger/L1TGlobal/python/simGtStage2Digis_cfi.py @@ -16,7 +16,6 @@ JetInputTag = cms.InputTag("simCaloStage2Digis"), EtSumInputTag = cms.InputTag("simCaloStage2Digis"), EtSumZdcInputTag = cms.InputTag("etSumZdcProducer"), - AXOL1TLModelVersion = cms.string("GTADModel_v3"), AlgorithmTriggersUnmasked = cms.bool(True), AlgorithmTriggersUnprescaled = cms.bool(True), GetPrescaleColumnFromData = cms.bool(False), diff --git a/L1Trigger/L1TGlobal/src/AXOL1TLCondition.cc b/L1Trigger/L1TGlobal/src/AXOL1TLCondition.cc index 76861ea2ec598..83fdc4225bbbc 100644 --- a/L1Trigger/L1TGlobal/src/AXOL1TLCondition.cc +++ b/L1Trigger/L1TGlobal/src/AXOL1TLCondition.cc @@ -90,10 +90,20 @@ const bool l1t::AXOL1TLCondition::evaluateCondition(const int bxEval) const { int useBx = bxEval + m_gtAXOL1TLTemplate->condRelativeBx(); //HLS4ML stuff - std::string AXOL1TLmodelversion = m_AXOL1TLmodelversion; //config loading method + std::string AXOL1TLmodelversion = "GTADModel_" + m_gtAXOL1TLTemplate->modelVersion(); //loading from menu/template + + //otherwise load model (if possible) and run inference hls4mlEmulator::ModelLoader loader(AXOL1TLmodelversion); std::shared_ptr model; - model = loader.load_model(); + + try { + model = loader.load_model(); + } catch (std::runtime_error& e) { + // for stopping with exception if model version cannot be loaded + throw cms::Exception("ModelError") + << " ERROR: failed to load AXOL1TL model version \"" << AXOL1TLmodelversion + << "\" that was specified in menu. Model version not found in cms-hls4ml externals."; + } // //pointers to objects const BXVector* candMuVec = m_gtGTB->getCandL1Mu(); @@ -249,11 +259,6 @@ const bool l1t::AXOL1TLCondition::evaluateCondition(const int bxEval) const { return condResult; } -//in order to set model version from config -void l1t::AXOL1TLCondition::setModelVersion(const std::string modelversionname) { - m_AXOL1TLmodelversion = modelversionname; -} - void l1t::AXOL1TLCondition::print(std::ostream& myCout) const { myCout << "Dummy Print for AXOL1TLCondition" << std::endl; m_gtAXOL1TLTemplate->print(myCout); diff --git a/L1Trigger/L1TGlobal/src/AXOL1TLTemplate.cc b/L1Trigger/L1TGlobal/src/AXOL1TLTemplate.cc index 1e411f30f215d..e238f8f6da08b 100644 --- a/L1Trigger/L1TGlobal/src/AXOL1TLTemplate.cc +++ b/L1Trigger/L1TGlobal/src/AXOL1TLTemplate.cc @@ -39,6 +39,9 @@ void AXOL1TLTemplate::setConditionParameter(const std::vector& m_objectParameter = objParameter; } +//setModelVersion - set the model version of the condition +void AXOL1TLTemplate::setModelVersion(const std::string& modelversion) { m_modelVersion = modelversion; } + void AXOL1TLTemplate::print(std::ostream& myCout) const { myCout << "\n AXOL1TLTemplate print..." << std::endl; @@ -65,6 +68,7 @@ void AXOL1TLTemplate::copy(const AXOL1TLTemplate& cp) { m_condChipNr = cp.condChipNr(); m_condRelativeBx = cp.condRelativeBx(); + m_modelVersion = cp.modelVersion(); // new for utm 0.12.0 m_objectParameter = *(cp.objectParameter()); } diff --git a/L1Trigger/L1TGlobal/src/GlobalBoard.cc b/L1Trigger/L1TGlobal/src/GlobalBoard.cc index 02144cb63a767..b026a2fd1af68 100644 --- a/L1Trigger/L1TGlobal/src/GlobalBoard.cc +++ b/L1Trigger/L1TGlobal/src/GlobalBoard.cc @@ -112,11 +112,6 @@ void l1t::GlobalBoard::setBxFirst(int bx) { m_bxFirst_ = bx; } void l1t::GlobalBoard::setBxLast(int bx) { m_bxLast_ = bx; } -// temporary class for getting axol1tl version from config to condition class until it can be got from the utm menu -void l1t::GlobalBoard::setAXOL1TLModelVersion(std::string axol1tlModelVersion) { - m_axol1tlModelVersion = axol1tlModelVersion; -} - void l1t::GlobalBoard::init(const int numberPhysTriggers, const int nrL1Mu, const int nrL1MuShower, @@ -656,8 +651,6 @@ void l1t::GlobalBoard::runGTL(const edm::Event&, axol1tlCondition->setVerbosity(m_verbosity); - axol1tlCondition->setModelVersion(m_axol1tlModelVersion); - axol1tlCondition->evaluateConditionStoreResult(iBxInEvent); cMapResults[itCond->first] = axol1tlCondition;