Skip to content

Commit

Permalink
Merge pull request #45032 from kbunkow/from-CMSSW_14_1_X_2024-05-22-2…
Browse files Browse the repository at this point in the history
…300_KBv1

possibility of configuring the OMTF emulator directly from XMLs
  • Loading branch information
cmsbuild authored Jun 12, 2024
2 parents 3ed2913 + 83e721b commit 51b889c
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 396 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class OMTFReconstruction {
int bxMin, bxMax;

///OMTF objects
//omtfParams are created only if they are read from the xml file in beginRun(). If the params goes from eventSetup, omtfParams are null
unique_ptr<L1TMuonOverlapParams> omtfParams;
unique_ptr<OMTFConfiguration> omtfConfig;

unique_ptr<OMTFinputMaker> inputMaker;
Expand Down
9 changes: 3 additions & 6 deletions L1Trigger/L1TMuonOverlapPhase1/src/Omtf/OMTFProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ void OMTFProcessor<GoldenPatternType>::init(const edm::ParameterSet& edmCfg, edm

edm::LogVerbatim("OMTFReconstruction") << "useFloatingPointExtrapolation " << useFloatingPointExtrapolation
<< std::endl;
edm::LogVerbatim("OMTFReconstruction") << "extrapolFactorsFilename " << extrapolFactorsFilename << std::endl;
}

template <class GoldenPatternType>
Expand Down Expand Up @@ -294,8 +293,6 @@ std::vector<l1t::RegionalMuonCand> OMTFProcessor<GoldenPatternType>::getFinalcan
//check if it matters if it needs to be here as well
trackAddr[1] = myCand->getRefLayer();
trackAddr[2] = myCand->getDisc();
//TODO: uGMT expects only 3 sub-addresses, so not set 4th. This is anyway currently not used.
//trackAddr[3] = myCand->getGpResultUnconstr().getPdfSumUnconstr();
if (candidate.hwPt() > 0 || candidate.hwPtUnconstrained() > 0) {
candidate.setTrackAddress(trackAddr);
candidate.setTFIdentifiers(iProcessor, mtfType);
Expand Down Expand Up @@ -910,16 +907,16 @@ void OMTFProcessor<GoldenPatternType>::loadExtrapolFactors(const std::string& fi
int iLayer = lutNode.second.get<int>("<xmlattr>.Layer");
std::string keyType = lutNode.second.get<std::string>("<xmlattr>.KeyType");

edm::LogVerbatim("OMTFReconstruction")
<< "iRefLayer " << iRefLayer << " iLayer " << iLayer << " keyType " << keyType << std::endl;
LogTrace("OMTFReconstruction") << "iRefLayer " << iRefLayer << " iLayer " << iLayer << " keyType " << keyType
<< std::endl;

auto& valueNodes = lutNode.second;
for (boost::property_tree::ptree::value_type& valueNode : valueNodes) {
if (valueNode.first == "LutVal") {
int key = valueNode.second.get<int>("<xmlattr>.key");
float value = valueNode.second.get<float>("<xmlattr>.value");
extrapolFactors.at(iRefLayer).at(iLayer)[key] = value;
edm::LogVerbatim("OMTFReconstruction") << "key " << key << " value " << value << std::endl;
LogTrace("OMTFReconstruction") << "key " << key << " value " << value << std::endl;
}
}
}
Expand Down
80 changes: 54 additions & 26 deletions L1Trigger/L1TMuonOverlapPhase1/src/Omtf/OMTFReconstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,51 +64,82 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
const MuonGeometryTokens& muonGeometryTokens,
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord>& magneticFieldEsToken,
const edm::ESGetToken<Propagator, TrackingComponentsRecord>& propagatorEsToken) {
const L1TMuonOverlapParams* omtfParams = nullptr;

std::string processorType = "OMTFProcessor"; //GoldenPatternWithStat GoldenPattern
if (edmParameterSet.exists("processorType")) {
processorType = edmParameterSet.getParameter<std::string>("processorType");
}

bool buildPatternsFromXml = (edmParameterSet.exists("patternsXMLFile") || edmParameterSet.exists("patternsXMLFiles"));

bool readConfigFromXml = edmParameterSet.exists("configXMLFile");

if (buildPatternsFromXml != readConfigFromXml)
throw cms::Exception(
"OMTFReconstruction::beginRun: buildPatternsFromXml != readConfigFromXml - both patternsXMLFiles and "
"configXMLFile should be defined (or not) for the simOmtDigis or simOmtfPhase2Digis");

edm::LogVerbatim("OMTFReconstruction") << "OMTFReconstruction::beginRun " << run.id()
<< " buildPatternsFromXml: " << buildPatternsFromXml << std::endl;

//if the buildPatternsFromXml == false - we are making the omtfConfig and omtfProc for every run,
//as the configuration my change between the runs,
//if buildPatternsFromXml == true - we assume the the entire configuration comes from phyton,
//so we do it only for the first run
if (omtfProc == nullptr || buildPatternsFromXml == false) {
if (buildPatternsFromXml == false) {
if (omtfParamsRecordWatcher.check(eventSetup)) {
edm::LogVerbatim("OMTFReconstruction") << "retrieving omtfParams from EventSetup" << std::endl;

omtfParams = &(eventSetup.getData(omtfParamsEsToken));
if (!omtfParams) {
edm::LogError("OMTFReconstruction") << "Could not retrieve parameters from Event Setup" << std::endl;
const L1TMuonOverlapParams* omtfParamsFromES = &(eventSetup.getData(omtfParamsEsToken));
if (!omtfParamsFromES) {
edm::LogError("OMTFReconstruction") << "Could not retrieve omtfParams from Event Setup" << std::endl;
throw cms::Exception("OMTFReconstruction::beginRun: Could not retrieve omtfParams from Event Setup");
}
omtfConfig->configure(omtfParams);

omtfConfig->configure(omtfParamsFromES);

//the parameters can be overwritten from the python config
omtfConfig->configureFromEdmParameterSet(edmParameterSet);

inputMaker->initialize(edmParameterSet, eventSetup, muonGeometryTokens);

//patterns from the edm::EventSetup are reloaded every beginRun
if (buildPatternsFromXml == false) {
edm::LogVerbatim("OMTFReconstruction") << "getting patterns from EventSetup" << std::endl;
if (processorType == "OMTFProcessor") {
omtfProc = std::make_unique<OMTFProcessor<GoldenPattern> >(
omtfConfig.get(), edmParameterSet, eventSetup, omtfParams);
omtfProc->printInfo();
}
//therefore OMTFProcessor is re-created here
edm::LogVerbatim("OMTFReconstruction") << "getting patterns from EventSetup" << std::endl;
if (processorType == "OMTFProcessor") {
omtfProc = std::make_unique<OMTFProcessor<GoldenPattern> >(
omtfConfig.get(), edmParameterSet, eventSetup, omtfParamsFromES);
omtfProc->printInfo();
}
}
}

//if we read the patterns directly from the xml, we do it only once, at the beginning of the first run, not every run
//if buildPatternsFromXml == true - the entire configuration (patterns and hwToLogicLayer) comes from phyton,
//so we read it only once, at the beginning of the first run, not every run
if (omtfProc == nullptr && buildPatternsFromXml) {
std::string fName = edmParameterSet.getParameter<edm::FileInPath>("configXMLFile").fullPath();

edm::LogVerbatim("OMTFReconstruction")
<< "OMTFReconstruction::beginRun - reading config from file: " << fName << std::endl;

XMLConfigReader xmlConfigReader;
xmlConfigReader.setConfigFile(fName);

omtfParams.reset(new L1TMuonOverlapParams());
xmlConfigReader.readConfig(omtfParams.get());

//getPatternsVersion() parses the entire patterns xml - si it is very inefficient
//moreover, PatternsVersion is not used anywhere
//Therefore we we dont use xmlPatternReader.getPatternsVersion(); but set patternsVersion to 0
unsigned int patternsVersion = 0;
unsigned int fwVersion = omtfParams->fwVersion();
omtfParams->setFwVersion((fwVersion << 16) + patternsVersion);

omtfConfig->configure(omtfParams.get());

//the parameters can be overwritten from the python config
omtfConfig->configureFromEdmParameterSet(edmParameterSet);

inputMaker->initialize(edmParameterSet, eventSetup, muonGeometryTokens);

//reading patterns from the xml----------------------------------------------------------
std::vector<std::string> patternsXMLFiles;

if (edmParameterSet.exists("patternsXMLFile")) {
Expand All @@ -122,8 +153,6 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
for (auto& patternsXMLFile : patternsXMLFiles)
edm::LogVerbatim("OMTFReconstruction") << "reading patterns from " << patternsXMLFile << std::endl;

XMLConfigReader xmlReader;

std::string patternType = "GoldenPattern"; //GoldenPatternWithStat GoldenPattern
if (edmParameterSet.exists("patternType")) {
patternType = edmParameterSet.getParameter<std::string>("patternType");
Expand All @@ -136,15 +165,14 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
omtfConfig.get(),
edmParameterSet,
eventSetup,
xmlReader.readPatterns<GoldenPattern>(*omtfParams, patternsXMLFiles, false));
xmlConfigReader.readPatterns<GoldenPattern>(*omtfParams, patternsXMLFiles, false));
} else { //in principle should not happen
throw cms::Exception("OMTFReconstruction::beginRun: omtfParams is nullptr");
}
}

edm::LogVerbatim("OMTFReconstruction")
<< "OMTFProcessor constructed. processorType " << processorType << ". GoldenPattern type: " << patternType
<< " nProcessors " << omtfConfig->nProcessors() << std::endl;
edm::LogVerbatim("OMTFReconstruction") << "OMTFProcessor constructed. processorType " << processorType
<< ". GoldenPattern type: " << patternType << std::endl;
} else if (patternType == "GoldenPatternWithStat") {
//pattern generation is only possible if the processor is constructed only once per job
//PatternGenerator modifies the patterns!!!
Expand All @@ -154,7 +182,7 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
omtfConfig.get(),
edmParameterSet,
eventSetup,
xmlReader.readPatterns<GoldenPatternWithStat>(*omtfParams, patternsXMLFiles, false));
xmlConfigReader.readPatterns<GoldenPatternWithStat>(*omtfParams, patternsXMLFiles, false));
} else { //in principle should not happen
throw cms::Exception("OMTFReconstruction::beginRun: omtfParams is nullptr");
}
Expand Down Expand Up @@ -205,7 +233,7 @@ void OMTFReconstruction::addObservers(
if (edmParameterSet.getParameter<bool>("eventCaptureDebug")) {
observers.emplace_back(std::make_unique<EventCapture>(
edmParameterSet, omtfConfig.get(), candidateSimMuonMatcher, muonGeometryTokens
//, &(omtfProcGoldenPat->getPatterns() )
//&(omtfProcGoldenPat->getPatterns() ),
//watch out, will crash if the proc is re-constructed from the DB after L1TMuonOverlapParamsRcd change
));
}
Expand All @@ -228,7 +256,7 @@ void OMTFReconstruction::addObservers(
if (edmParameterSet.getParameter<bool>("eventCaptureDebug")) {
observers.emplace_back(std::make_unique<EventCapture>(
edmParameterSet, omtfConfig.get(), candidateSimMuonMatcher, muonGeometryTokens
//&(omtfProcGoldenPat->getPatterns() )
//&(omtfProcGoldenPat->getPatterns() ),
//watch out, will crash if the proc is re-constructed from the DB after L1TMuonOverlapParamsRcd change
));
}
Expand Down
17 changes: 0 additions & 17 deletions L1Trigger/L1TMuonOverlapPhase2/python/fakeOmtfParamsPhase2_cff.py

This file was deleted.

29 changes: 16 additions & 13 deletions L1Trigger/L1TMuonOverlapPhase2/python/simOmtfPhase2Digis_cfi.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import FWCore.ParameterSet.Config as cms


###OMTF emulator configuration
simOmtfPhase2Digis = cms.EDProducer("L1TMuonOverlapPhase2TrackProducer",

simOmtfPhase2Digis = cms.EDProducer("L1TMuonOverlapPhase2TrackProducer",
srcDTPh = cms.InputTag('simDtTriggerPrimitiveDigis'),
srcDTTh = cms.InputTag('simDtTriggerPrimitiveDigis'),
srcCSC = cms.InputTag('simCscTriggerPrimitiveDigis','MPCSORTED'),
srcRPC = cms.InputTag('simMuonRPCDigis'),
srcDTPhPhase2 = cms.InputTag('dtTriggerPhase2PrimitiveDigis'),

simTracksTag = cms.InputTag('g4SimHits'),
srcDTThPhase2 = cms.InputTag('dtTriggerPhase2PrimitiveDigis'),

## XML / PATTERNS file:
configXMLFile = cms.FileInPath("L1Trigger/L1TMuon/data/omtf_config/hwToLogicLayer_0x0209.xml"),
patternsXMLFile = cms.FileInPath("L1Trigger/L1TMuon/data/omtf_config/Patterns_ExtraplMB1nadMB2DTQualAndEtaFixedP_ValueP1Scale_t20_v1_SingleMu_iPt_and_OneOverPt_classProb17_recalib2_minDP0.xml"),
extrapolFactorsFilename = cms.FileInPath("L1Trigger/L1TMuon/data/omtf_config/ExtrapolationFactors_ExtraplMB1nadMB2DTQual_ValueP1Scale_t20.xml"),

dumpResultToXML = cms.bool(False),
dumpDetailedResultToXML = cms.bool(False),
XMLDumpFileName = cms.string("TestEvents.xml"),
dumpGPToXML = cms.bool(False),
readEventsFromXML = cms.bool(False),
eventsXMLFiles = cms.vstring("TestEvents.xml"),


dropRPCPrimitives = cms.bool(False),
dropCSCPrimitives = cms.bool(False),

Expand All @@ -42,13 +45,13 @@

stubEtaEncoding = cms.string("valueP1Scale"), #TODO change to valueP1Scale when InputMakerPhase2 is modifiwed

usePhiBExtrapolationFromMB1 = cms.bool(False),
usePhiBExtrapolationFromMB2 = cms.bool(False),
useStubQualInExtr = cms.bool(False),
useEndcapStubsRInExtr = cms.bool(False),
usePhiBExtrapolationFromMB1 = cms.bool(True),
usePhiBExtrapolationFromMB2 = cms.bool(True),
useStubQualInExtr = cms.bool(True),
useEndcapStubsRInExtr = cms.bool(True),
useFloatingPointExtrapolation = cms.bool(False),

sorterType = cms.string("byLLH"),
ghostBusterType = cms.string("GhostBusterPreferRefDt"), # byLLH byRefLayer GhostBusterPreferRefDt
goldenPatternResultFinalizeFunction = cms.int32(9)
ghostBusterType = cms.string("byRefLayer"), # byLLH byRefLayer GhostBusterPreferRefDt
goldenPatternResultFinalizeFunction = cms.int32(10)
)

This file was deleted.

Loading

0 comments on commit 51b889c

Please sign in to comment.