Skip to content

Commit 51b889c

Browse files
authored
Merge pull request #45032 from kbunkow/from-CMSSW_14_1_X_2024-05-22-2300_KBv1
possibility of configuring the OMTF emulator directly from XMLs
2 parents 3ed2913 + 83e721b commit 51b889c

11 files changed

+258
-396
lines changed

L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/OMTFReconstruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class OMTFReconstruction {
6767
int bxMin, bxMax;
6868

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

7274
unique_ptr<OMTFinputMaker> inputMaker;

L1Trigger/L1TMuonOverlapPhase1/src/Omtf/OMTFProcessor.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ void OMTFProcessor<GoldenPatternType>::init(const edm::ParameterSet& edmCfg, edm
9595

9696
edm::LogVerbatim("OMTFReconstruction") << "useFloatingPointExtrapolation " << useFloatingPointExtrapolation
9797
<< std::endl;
98-
edm::LogVerbatim("OMTFReconstruction") << "extrapolFactorsFilename " << extrapolFactorsFilename << std::endl;
9998
}
10099

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

913-
edm::LogVerbatim("OMTFReconstruction")
914-
<< "iRefLayer " << iRefLayer << " iLayer " << iLayer << " keyType " << keyType << std::endl;
910+
LogTrace("OMTFReconstruction") << "iRefLayer " << iRefLayer << " iLayer " << iLayer << " keyType " << keyType
911+
<< std::endl;
915912

916913
auto& valueNodes = lutNode.second;
917914
for (boost::property_tree::ptree::value_type& valueNode : valueNodes) {
918915
if (valueNode.first == "LutVal") {
919916
int key = valueNode.second.get<int>("<xmlattr>.key");
920917
float value = valueNode.second.get<float>("<xmlattr>.value");
921918
extrapolFactors.at(iRefLayer).at(iLayer)[key] = value;
922-
edm::LogVerbatim("OMTFReconstruction") << "key " << key << " value " << value << std::endl;
919+
LogTrace("OMTFReconstruction") << "key " << key << " value " << value << std::endl;
923920
}
924921
}
925922
}

L1Trigger/L1TMuonOverlapPhase1/src/Omtf/OMTFReconstruction.cc

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,51 +64,82 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
6464
const MuonGeometryTokens& muonGeometryTokens,
6565
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord>& magneticFieldEsToken,
6666
const edm::ESGetToken<Propagator, TrackingComponentsRecord>& propagatorEsToken) {
67-
const L1TMuonOverlapParams* omtfParams = nullptr;
68-
6967
std::string processorType = "OMTFProcessor"; //GoldenPatternWithStat GoldenPattern
7068
if (edmParameterSet.exists("processorType")) {
7169
processorType = edmParameterSet.getParameter<std::string>("processorType");
7270
}
7371

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

74+
bool readConfigFromXml = edmParameterSet.exists("configXMLFile");
75+
76+
if (buildPatternsFromXml != readConfigFromXml)
77+
throw cms::Exception(
78+
"OMTFReconstruction::beginRun: buildPatternsFromXml != readConfigFromXml - both patternsXMLFiles and "
79+
"configXMLFile should be defined (or not) for the simOmtDigis or simOmtfPhase2Digis");
80+
7681
edm::LogVerbatim("OMTFReconstruction") << "OMTFReconstruction::beginRun " << run.id()
7782
<< " buildPatternsFromXml: " << buildPatternsFromXml << std::endl;
7883

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

87-
omtfParams = &(eventSetup.getData(omtfParamsEsToken));
88-
if (!omtfParams) {
89-
edm::LogError("OMTFReconstruction") << "Could not retrieve parameters from Event Setup" << std::endl;
90+
const L1TMuonOverlapParams* omtfParamsFromES = &(eventSetup.getData(omtfParamsEsToken));
91+
if (!omtfParamsFromES) {
92+
edm::LogError("OMTFReconstruction") << "Could not retrieve omtfParams from Event Setup" << std::endl;
93+
throw cms::Exception("OMTFReconstruction::beginRun: Could not retrieve omtfParams from Event Setup");
9094
}
91-
omtfConfig->configure(omtfParams);
95+
96+
omtfConfig->configure(omtfParamsFromES);
9297

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

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

98103
//patterns from the edm::EventSetup are reloaded every beginRun
99-
if (buildPatternsFromXml == false) {
100-
edm::LogVerbatim("OMTFReconstruction") << "getting patterns from EventSetup" << std::endl;
101-
if (processorType == "OMTFProcessor") {
102-
omtfProc = std::make_unique<OMTFProcessor<GoldenPattern> >(
103-
omtfConfig.get(), edmParameterSet, eventSetup, omtfParams);
104-
omtfProc->printInfo();
105-
}
104+
//therefore OMTFProcessor is re-created here
105+
edm::LogVerbatim("OMTFReconstruction") << "getting patterns from EventSetup" << std::endl;
106+
if (processorType == "OMTFProcessor") {
107+
omtfProc = std::make_unique<OMTFProcessor<GoldenPattern> >(
108+
omtfConfig.get(), edmParameterSet, eventSetup, omtfParamsFromES);
109+
omtfProc->printInfo();
106110
}
107111
}
108112
}
109113

110-
//if we read the patterns directly from the xml, we do it only once, at the beginning of the first run, not every run
114+
//if buildPatternsFromXml == true - the entire configuration (patterns and hwToLogicLayer) comes from phyton,
115+
//so we read it only once, at the beginning of the first run, not every run
111116
if (omtfProc == nullptr && buildPatternsFromXml) {
117+
std::string fName = edmParameterSet.getParameter<edm::FileInPath>("configXMLFile").fullPath();
118+
119+
edm::LogVerbatim("OMTFReconstruction")
120+
<< "OMTFReconstruction::beginRun - reading config from file: " << fName << std::endl;
121+
122+
XMLConfigReader xmlConfigReader;
123+
xmlConfigReader.setConfigFile(fName);
124+
125+
omtfParams.reset(new L1TMuonOverlapParams());
126+
xmlConfigReader.readConfig(omtfParams.get());
127+
128+
//getPatternsVersion() parses the entire patterns xml - si it is very inefficient
129+
//moreover, PatternsVersion is not used anywhere
130+
//Therefore we we dont use xmlPatternReader.getPatternsVersion(); but set patternsVersion to 0
131+
unsigned int patternsVersion = 0;
132+
unsigned int fwVersion = omtfParams->fwVersion();
133+
omtfParams->setFwVersion((fwVersion << 16) + patternsVersion);
134+
135+
omtfConfig->configure(omtfParams.get());
136+
137+
//the parameters can be overwritten from the python config
138+
omtfConfig->configureFromEdmParameterSet(edmParameterSet);
139+
140+
inputMaker->initialize(edmParameterSet, eventSetup, muonGeometryTokens);
141+
142+
//reading patterns from the xml----------------------------------------------------------
112143
std::vector<std::string> patternsXMLFiles;
113144

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

125-
XMLConfigReader xmlReader;
126-
127156
std::string patternType = "GoldenPattern"; //GoldenPatternWithStat GoldenPattern
128157
if (edmParameterSet.exists("patternType")) {
129158
patternType = edmParameterSet.getParameter<std::string>("patternType");
@@ -136,15 +165,14 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
136165
omtfConfig.get(),
137166
edmParameterSet,
138167
eventSetup,
139-
xmlReader.readPatterns<GoldenPattern>(*omtfParams, patternsXMLFiles, false));
168+
xmlConfigReader.readPatterns<GoldenPattern>(*omtfParams, patternsXMLFiles, false));
140169
} else { //in principle should not happen
141170
throw cms::Exception("OMTFReconstruction::beginRun: omtfParams is nullptr");
142171
}
143172
}
144173

145-
edm::LogVerbatim("OMTFReconstruction")
146-
<< "OMTFProcessor constructed. processorType " << processorType << ". GoldenPattern type: " << patternType
147-
<< " nProcessors " << omtfConfig->nProcessors() << std::endl;
174+
edm::LogVerbatim("OMTFReconstruction") << "OMTFProcessor constructed. processorType " << processorType
175+
<< ". GoldenPattern type: " << patternType << std::endl;
148176
} else if (patternType == "GoldenPatternWithStat") {
149177
//pattern generation is only possible if the processor is constructed only once per job
150178
//PatternGenerator modifies the patterns!!!
@@ -154,7 +182,7 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
154182
omtfConfig.get(),
155183
edmParameterSet,
156184
eventSetup,
157-
xmlReader.readPatterns<GoldenPatternWithStat>(*omtfParams, patternsXMLFiles, false));
185+
xmlConfigReader.readPatterns<GoldenPatternWithStat>(*omtfParams, patternsXMLFiles, false));
158186
} else { //in principle should not happen
159187
throw cms::Exception("OMTFReconstruction::beginRun: omtfParams is nullptr");
160188
}
@@ -205,7 +233,7 @@ void OMTFReconstruction::addObservers(
205233
if (edmParameterSet.getParameter<bool>("eventCaptureDebug")) {
206234
observers.emplace_back(std::make_unique<EventCapture>(
207235
edmParameterSet, omtfConfig.get(), candidateSimMuonMatcher, muonGeometryTokens
208-
//, &(omtfProcGoldenPat->getPatterns() )
236+
//&(omtfProcGoldenPat->getPatterns() ),
209237
//watch out, will crash if the proc is re-constructed from the DB after L1TMuonOverlapParamsRcd change
210238
));
211239
}
@@ -228,7 +256,7 @@ void OMTFReconstruction::addObservers(
228256
if (edmParameterSet.getParameter<bool>("eventCaptureDebug")) {
229257
observers.emplace_back(std::make_unique<EventCapture>(
230258
edmParameterSet, omtfConfig.get(), candidateSimMuonMatcher, muonGeometryTokens
231-
//&(omtfProcGoldenPat->getPatterns() )
259+
//&(omtfProcGoldenPat->getPatterns() ),
232260
//watch out, will crash if the proc is re-constructed from the DB after L1TMuonOverlapParamsRcd change
233261
));
234262
}

L1Trigger/L1TMuonOverlapPhase2/python/fakeOmtfParamsPhase2_cff.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

L1Trigger/L1TMuonOverlapPhase2/python/simOmtfPhase2Digis_cfi.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
import FWCore.ParameterSet.Config as cms
22

3-
43
###OMTF emulator configuration
5-
simOmtfPhase2Digis = cms.EDProducer("L1TMuonOverlapPhase2TrackProducer",
6-
4+
simOmtfPhase2Digis = cms.EDProducer("L1TMuonOverlapPhase2TrackProducer",
75
srcDTPh = cms.InputTag('simDtTriggerPrimitiveDigis'),
86
srcDTTh = cms.InputTag('simDtTriggerPrimitiveDigis'),
97
srcCSC = cms.InputTag('simCscTriggerPrimitiveDigis','MPCSORTED'),
108
srcRPC = cms.InputTag('simMuonRPCDigis'),
119
srcDTPhPhase2 = cms.InputTag('dtTriggerPhase2PrimitiveDigis'),
12-
13-
simTracksTag = cms.InputTag('g4SimHits'),
10+
srcDTThPhase2 = cms.InputTag('dtTriggerPhase2PrimitiveDigis'),
11+
12+
## XML / PATTERNS file:
13+
configXMLFile = cms.FileInPath("L1Trigger/L1TMuon/data/omtf_config/hwToLogicLayer_0x0209.xml"),
14+
patternsXMLFile = cms.FileInPath("L1Trigger/L1TMuon/data/omtf_config/Patterns_ExtraplMB1nadMB2DTQualAndEtaFixedP_ValueP1Scale_t20_v1_SingleMu_iPt_and_OneOverPt_classProb17_recalib2_minDP0.xml"),
15+
extrapolFactorsFilename = cms.FileInPath("L1Trigger/L1TMuon/data/omtf_config/ExtrapolationFactors_ExtraplMB1nadMB2DTQual_ValueP1Scale_t20.xml"),
16+
1417
dumpResultToXML = cms.bool(False),
1518
dumpDetailedResultToXML = cms.bool(False),
1619
XMLDumpFileName = cms.string("TestEvents.xml"),
1720
dumpGPToXML = cms.bool(False),
1821
readEventsFromXML = cms.bool(False),
1922
eventsXMLFiles = cms.vstring("TestEvents.xml"),
2023

21-
24+
2225
dropRPCPrimitives = cms.bool(False),
2326
dropCSCPrimitives = cms.bool(False),
2427

@@ -42,13 +45,13 @@
4245

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

45-
usePhiBExtrapolationFromMB1 = cms.bool(False),
46-
usePhiBExtrapolationFromMB2 = cms.bool(False),
47-
useStubQualInExtr = cms.bool(False),
48-
useEndcapStubsRInExtr = cms.bool(False),
48+
usePhiBExtrapolationFromMB1 = cms.bool(True),
49+
usePhiBExtrapolationFromMB2 = cms.bool(True),
50+
useStubQualInExtr = cms.bool(True),
51+
useEndcapStubsRInExtr = cms.bool(True),
4952
useFloatingPointExtrapolation = cms.bool(False),
50-
53+
5154
sorterType = cms.string("byLLH"),
52-
ghostBusterType = cms.string("GhostBusterPreferRefDt"), # byLLH byRefLayer GhostBusterPreferRefDt
53-
goldenPatternResultFinalizeFunction = cms.int32(9)
55+
ghostBusterType = cms.string("byRefLayer"), # byLLH byRefLayer GhostBusterPreferRefDt
56+
goldenPatternResultFinalizeFunction = cms.int32(10)
5457
)

L1Trigger/L1TMuonOverlapPhase2/python/simOmtfPhase2Digis_extrapol_cfi.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)