Skip to content

Commit

Permalink
Original AXO emu changes from Melissa quinnanm
Browse files Browse the repository at this point in the history
  • Loading branch information
artlbv committed Mar 22, 2024
1 parent 4ce99ab commit 12c3ddb
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 24 deletions.
2 changes: 1 addition & 1 deletion L1Trigger/L1TGlobal/interface/AXOL1TLCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace l1t {
const GlobalBoard* m_gtGTB;

//to set modelversion from globalboard<-globalproducer<-config
std::string m_AXOL1TLmodelversion = "NONE";
std::string m_AXOL1TLmodelversion = "";
};

} // namespace l1t
Expand Down
7 changes: 7 additions & 0 deletions L1Trigger/L1TGlobal/interface/AXOL1TLTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ class AXOL1TLTemplate : public GlobalCondition {
public:
inline const std::vector<ObjectParameter>* objectParameter() const { return &m_objectParameter; }

inline const std::string& modelVersion() const { return m_modelVersion; }

/// set functions
void setConditionParameter(const std::vector<ObjectParameter>& objParameter);

void setModelVersion(const std::string& modelversion);

/// print the condition
void print(std::ostream& myCout) const override;

Expand All @@ -67,6 +71,9 @@ class AXOL1TLTemplate : public GlobalCondition {

/// variables containing the parameters
std::vector<ObjectParameter> m_objectParameter;

/// model version
std::string m_modelVersion;
};

#endif
20 changes: 14 additions & 6 deletions L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ void L1TGlobalProducer::fillDescriptions(edm::ConfigurationDescriptions& descrip
desc.add<bool>("AlgorithmTriggersUnmasked", false)
->setComment("not required, but recommend to specify explicitly in config");

//AXOl1TL model version:
desc.add<std::string>("AXOL1TLModelVersion", "");

// switch for muon showers in Run-3
desc.add<bool>("useMuonShowers", false);

Expand Down Expand Up @@ -133,7 +130,6 @@ L1TGlobalProducer::L1TGlobalProducer(const edm::ParameterSet& parSet)
m_algoblkInputTag(parSet.getParameter<edm::InputTag>("AlgoBlkInputTag")),
m_resetPSCountersEachLumiSec(parSet.getParameter<bool>("resetPSCountersEachLumiSec")),
m_semiRandomInitialPSCounters(parSet.getParameter<bool>("semiRandomInitialPSCounters")),
m_AXOL1TLModelVersion(parSet.getParameter<std::string>("AXOL1TLModelVersion")),
m_useMuonShowers(parSet.getParameter<bool>("useMuonShowers")) {
m_egInputToken = consumes<BXVector<EGamma>>(m_egInputTag);
m_tauInputToken = consumes<BXVector<Tau>>(m_tauInputTag);
Expand Down Expand Up @@ -224,6 +220,8 @@ L1TGlobalProducer::L1TGlobalProducer(const edm::ParameterSet& parSet)
m_l1GtParCacheID = 0ULL;
m_l1GtMenuCacheID = 0ULL;

m_AXOL1TLModelVersion = "";

m_numberPhysTriggers = 0;
m_numberDaqPartitions = 0;

Expand Down Expand Up @@ -403,6 +401,17 @@ void L1TGlobalProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSet
m_l1GtMenu->print(std::cout, printV);

m_l1GtMenuCacheID = l1GtMenuCacheID;

//get model version to condition class via GlobalBoard.runGTL, comes from menu rather than config
//for throwing exception when using L1Menu_Collisions2024_v1_0_0
if ((gtParser.gtTriggerMenuName() == "L1Menu_Collisions2024_v1_0_0") ||
(gtParser.gtTriggerMenuName() == "L1Menu_Collisions2024_v0_0_0")) {
throw cms::Exception("ConditionsError")
<< " Error L1T menu version " << gtParser.gtTriggerMenuName()
<< " is unsupported due to incompatible utm grammar, please use L1Menu_Collisions2024_v1_0_1 or later";
} else {
m_AXOL1TLModelVersion = gtParser.AXOL1TLModelVersion();
}
}

// get / update the board maps from the EventSetup
Expand Down Expand Up @@ -625,8 +634,7 @@ 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
//set axo model version in global board from version in menu
m_uGtBrd->setAXOL1TLModelVersion(m_AXOL1TLModelVersion);

if (m_useMuonShowers)
Expand Down
37 changes: 26 additions & 11 deletions L1Trigger/L1TGlobal/plugins/TriggerMenuParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ void l1t::TriggerMenuParser::setVecCorrelationWithOverlapRemovalTemplate(
m_vecCorrelationWithOverlapRemovalTemplate = vecCorrelationWithOverlapRemovalTempl;
}

//set the AXO model version so it can be fetched from the GlobalProducer
void l1t::TriggerMenuParser::setAXOL1TLModelVersion(const std::string& axol1tlmodelversion) {
m_axol1tlModelVersion = axol1tlmodelversion;
}

// set the vectors containing the conditions for correlation templates
//
void l1t::TriggerMenuParser::setCorMuonTemplate(const std::vector<std::vector<MuonTemplate> >& corMuonTempl) {
Expand Down Expand Up @@ -322,7 +327,7 @@ 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) {
parseAXOL1TL(condition, chipNr);

//parse Muons
Expand Down Expand Up @@ -2752,19 +2757,25 @@ bool l1t::TriggerMenuParser::parseAXOL1TL(L1TUtmCondition condAXOL1TL, unsigned
int lowerThresholdInd = 0;
int upperThresholdInd = -1;

const std::vector<L1TUtmCut>& 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:
if (object.getType() == tmeventsetup::Axol1tl) {
const std::vector<L1TUtmCut>& 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;
break;
default:
break;
} //end switch
} //end cut loop
} //end else if
} //end cut loop
} //end if getType

//fill object params
objParameter[0].minAXOL1TLThreshold = lowerThresholdInd;
Expand All @@ -2777,6 +2788,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;
Expand All @@ -2792,6 +2804,9 @@ bool l1t::TriggerMenuParser::parseAXOL1TL(L1TUtmCondition condAXOL1TL, unsigned

(m_vecAXOL1TLTemplate[chipNr]).push_back(axol1tlCond);

//fill class model version variable
l1t::TriggerMenuParser::setAXOL1TLModelVersion(model);

return true;
}

Expand Down
8 changes: 8 additions & 0 deletions L1Trigger/L1TGlobal/plugins/TriggerMenuParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ namespace l1t {
void setVecCorrelationWithOverlapRemovalTemplate(
const std::vector<std::vector<CorrelationWithOverlapRemovalTemplate> >&);

// get/set the AXO model version so it can be fetched from the GlobalProducer
inline const std::string& AXOL1TLModelVersion() const { return m_axol1tlModelVersion; }

void setAXOL1TLModelVersion(const std::string&);

// get / set the vectors containing the conditions for correlation templates
//
inline const std::vector<std::vector<MuonTemplate> >& corMuonTemplate() const { return m_corMuonTemplate; }
Expand Down Expand Up @@ -425,6 +430,9 @@ namespace l1t {
std::vector<std::vector<CaloTemplate> > m_corCaloTemplate;
std::vector<std::vector<EnergySumTemplate> > m_corEnergySumTemplate;

/// AXOL1TL Model Version
std::string m_axol1tlModelVersion = "";

/// map containing the physics algorithms (by name)
AlgorithmMap m_algorithmMap;

Expand Down
1 change: 0 additions & 1 deletion L1Trigger/L1TGlobal/python/simGtStage2Digis_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
23 changes: 19 additions & 4 deletions L1Trigger/L1TGlobal/src/AXOL1TLCondition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,25 @@ 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 = m_AXOL1TLmodelversion; //loading from menu

//if model version is empty, throw exception. Should not ever happen
if (AXOL1TLmodelversion == "" || AXOL1TLmodelversion == "GTADModel_") {
throw cms::Exception("ModelError") << " Error: AXOL1TL model version not set!";
}

//otherwise load model (if possible) and run inference
hls4mlEmulator::ModelLoader loader(AXOL1TLmodelversion);
std::shared_ptr<hls4mlEmulator::Model> 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. " << std::endl;
}

// //pointers to objects
const BXVector<const l1t::Muon*>* candMuVec = m_gtGTB->getCandL1Mu();
Expand Down Expand Up @@ -249,9 +264,9 @@ const bool l1t::AXOL1TLCondition::evaluateCondition(const int bxEval) const {
return condResult;
}

//in order to set model version from config
//in order to set model version from menu->triggermenuparser->globalproducer->globalboard->here
void l1t::AXOL1TLCondition::setModelVersion(const std::string modelversionname) {
m_AXOL1TLmodelversion = modelversionname;
m_AXOL1TLmodelversion = "GTADModel_" + modelversionname;
}

void l1t::AXOL1TLCondition::print(std::ostream& myCout) const {
Expand Down
4 changes: 4 additions & 0 deletions L1Trigger/L1TGlobal/src/AXOL1TLTemplate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ void AXOL1TLTemplate::setConditionParameter(const std::vector<ObjectParameter>&
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;

Expand All @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion L1Trigger/L1TGlobal/src/GlobalBoard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ 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
// for getting axol1tl version from menu->GlobalProducer->GlobalBoard->condition class
void l1t::GlobalBoard::setAXOL1TLModelVersion(std::string axol1tlModelVersion) {
m_axol1tlModelVersion = axol1tlModelVersion;
}
Expand Down

0 comments on commit 12c3ddb

Please sign in to comment.