Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MF standardized regression tests + fix some loose ends in MF #28642

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions DetectorDescription/DDCMS/plugins/DDCompactViewMFESProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class DDCompactViewMFESProducer : public edm::ESProducer, public edm::EventSetup
edm::ValidityInterval &) override;

private:
const string m_label;
const edm::ESGetToken<DDDetector, IdealMagneticFieldRecord> m_detToken;
};

DDCompactViewMFESProducer::DDCompactViewMFESProducer(const edm::ParameterSet &iConfig)
: m_label(iConfig.getParameter<std::string>("appendToDataLabel")) {
setWhatProduced(this);
: m_detToken(setWhatProduced(this).consumes<DDDetector>(
edm::ESInputTag("", iConfig.getParameter<std::string>("appendToDataLabel")))) {
findingRecord<IdealMagneticFieldRecord>();
}

Expand All @@ -66,10 +66,7 @@ void DDCompactViewMFESProducer::fillDescriptions(edm::ConfigurationDescriptions
}

DDCompactViewMFESProducer::ReturnType DDCompactViewMFESProducer::produce(const IdealMagneticFieldRecord &iRecord) {
edm::ESHandle<DDDetector> det;
iRecord.get(m_label, det);

auto product = std::make_unique<DDCompactView>(*det);
auto product = std::make_unique<DDCompactView>(iRecord.get(m_detToken));
return product;
}

Expand Down
3 changes: 2 additions & 1 deletion DetectorDescription/DDCMS/test/python/testMFGeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
)

process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer",
confGeomXMLFiles = cms.FileInPath('DetectorDescription/DDCMS/data/cms-mf-geometry.xml'),
confGeomXMLFiles = cms.FileInPath('MagneticField/GeomBuilder/data/cms-mf-geometry_160812.xml'), # Geometry version 160812
# confGeomXMLFiles = cms.FileInPath('MagneticField/GeomBuilder/data/cms-mf-geometry_71212.xml'), # Geometry version 71212
appendToDataLabel = cms.string('MagneticField')
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import FWCore.ParameterSet.Config as cms


# This cfi contains everything needed to use the VolumeBased magnetic
# field engine version 160812 built using dd4hep for the geometry.
#
# PLEASE DO NOT USE THIS DIRECTLY
# Always use the standard sequence Configuration.StandardSequences.MagneticField_cff


DDDetectorESProducer = cms.ESSource("DDDetectorESProducer",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, this will not work in the standard setup due to a conflict with DDDetectorESProducer DD4hep_GeometrySim_cff.
perhaps add MF or smth for a different name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny, enough it does not work if I rename it to eg

process.DDDetectorMFESProducer = cms.ESSource("DDDetectorESProducer", ...

I then get:

An exception of category 'NoProxyException' occurred while
[0] Processing Event run: 1 lumi: 1 event: 1 stream: 0
[1] Running path 'p'
[2] Calling method for module testMagGeometryAnalyzer/'test'
[3] Using EventSetup component DD4hep_VolumeBasedMagneticFieldESProducer/'MagneticFieldESProducer' to make data MagneticField/'' in record Id
[4] Using EventSetup component DDCompactViewMFESProducer/'' to make data DDCompactView/'magfield' in record IdealMagneticFieldRecord
Exception Message:
No data of type "DDDetector" with label "magfield" in record "IdealMagneticFieldRecord"

It can be quickly reproduced editing

process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer",
.

@cvuosalo, @ianna, any idea of why this happens and how to avoid this?

@slava77 I will go on with the other fixes (in a new PR) while this is getting understood.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused in what's failing and what is edited.
volumeBasedMagneticField_dd4hep_160812_cfi.py is currently included only in regression.py, but it runs only testMagneticField, while the error message is coming from testMagGeometryAnalyzer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to apply the modification in cmssw/MagneticField/GeomBuilder/test/python/testMagGeometry.py first, as mentioned in my message above. This contains a (stripped-down) copy of the same config, for the purpose of testing the geometry.
Of course I need to fix volumeBasedMagneticField_dd4hep_160812_cfi.py as well, but the problem would be the same.

confGeomXMLFiles = cms.FileInPath('MagneticField/GeomBuilder/data/cms-mf-geometry_160812.xml'),
rootDDName = cms.string('cmsMagneticField:MAGF'),
appendToDataLabel = cms.string('magfield')
)


DDCompactViewMFESProducer = cms.ESProducer("DDCompactViewMFESProducer",
appendToDataLabel = cms.string('magfield')
)


ParametrizedMagneticFieldProducer = cms.ESProducer("ParametrizedMagneticFieldProducer",
version = cms.string('OAE_1103l_071212'),
parameters = cms.PSet(
BValue = cms.string('3_8T')
),
label = cms.untracked.string('parametrizedField')
)


VolumeBasedMagneticFieldESProducer = cms.ESProducer("DD4hep_VolumeBasedMagneticFieldESProducer",
DDDetector = cms.ESInputTag('', 'magfield'),
appendToDataLabel = cms.string(''),
useParametrizedTrackerField = cms.bool(True),
label = cms.untracked.string(''),
attribute = cms.string('magfield'),
value = cms.string('magfield'),
paramLabel = cms.string('parametrizedField'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like only DDDetector, attribute, and value are different from volumeBasedMagneticField_160812_cfi.
The ParametrizedMagneticFieldProducer above is also the same.
If this is supposed to stay for more than a week or so, it seems reasonable to refactor the common parts in volumeBasedMagneticField_160812_common_cfi

 ParametrizedMagneticFieldProducer = cms.ESProducer("ParametrizedMagneticFieldProducer",
...

VolumeBasedMagneticFieldCommon = cms.PSet (
#common parts here 
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is supposed to stay until DD4Hep becomes the default and DDD is dropped, which I guess is not happening in a week or so.
I have a slight preference for keeping the minimum number of cfi files since they quickly get confusing (one more is to be added for the DD4Hep producer from DB), but OK if you insist...

BTW could you suggest what I should do with the file that I removed (FromGun2DigiAnal_.py) which is also being addressed in another PR (see above)? Thanks.

version = cms.string('grid_160812_3_8t'),
geometryVersion = cms.int32(160812),
debugBuilder = cms.untracked.bool(False),
cacheLastVolume = cms.untracked.bool(True),
scalingVolumes = cms.vint32(),
scalingFactors = cms.vdouble(),


gridFiles = cms.VPSet(
# ### Specs for using specific tables for every volume
# cms.PSet(
# volumes = cms.string('1001-1464,2001-2464'),
# sectors = cms.string('0') ,
# master = cms.int32(0),
# path = cms.string('s[s]/grid.[v].bin'),
# ),


# Volumes for which specific tables are used for each sector
cms.PSet(
volumes = cms.string('1001-1010,1012-1027,1030-1033,1036-1041,1044-1049,1052-1057,1060-1063,1066-1071,1074-1077,1080-1097,1102-1129,1138-1402,1415-1416,' +
'2001-2010,2012-2027,2030-2033,2036-2041,2044-2049,2052-2057,2060-2063,2066-2071,2074-2077,2080-2097,2102-2129,2138-2402,2415-2416'),
sectors = cms.string('0') ,
master = cms.int32(0),
path = cms.string('s[s]/grid.[v].bin'),
),

# Replicate sector 1 for volumes outside any detector
cms.PSet(
volumes = cms.string('1011,1028-1029,1034-1035,1042-1043,1050-1051,1058-1059,1064-1065,1072-1073,1078-1079,'+ # volumes extending from R~7.6 m to to R=9 m,
'1098-1101,1130-1137,' + # Forward volumes, ouside CASTOR/HF
'1403-1414,1417-1464,' # Volumes beyond |Z|>17.74
'2011,2028-2029,2034-2035,2042-2043,2050-2051,2058-2059,2064-2065,2072-2073,2078-2079,'+
'2098-2101,2130-2137,'+
'2403-2414,2417-2464'),
sectors = cms.string('0'),
master = cms.int32(1),
path = cms.string('s01/grid.[v].bin'),
),
)
)


### To set a different nominal map, set the following in your .py:

### 3T
#VolumeBasedMagneticFieldESProducer.version = cms.string('grid_160812_3t')
#ParametrizedMagneticFieldProducer.parameters.BValue = cms.string('3_0T')

### 3.5T
#VolumeBasedMagneticFieldESProducer.version = cms.string('grid_160812_3_5t')
#ParametrizedMagneticFieldProducer.parameters.BValue = cms.string('3_5T')


### Run I, 3.8T
#VolumeBasedMagneticFieldESProducer.version = cms.string('grid_160812_3_8t_Run1')
117 changes: 109 additions & 8 deletions MagneticField/Engine/test/regression.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,133 @@

import FWCore.ParameterSet.Config as cms
import FWCore.ParameterSet.VarParsing as VarParsing

options = VarParsing.VarParsing()

options.register('producerType',
'static_DDD', #default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"MF producer to use. Valid values: 'static_DDD', 'static_DD4Hep' or 'fromDB'")

options.register('era',
'RunII', #default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"'RunI'or 'RunII'")

options.register('current',
18000, #default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.float,
"Magnet current (nominal values: 18164=3.8T; 16730=3.5T; 14340=3T; 9500=2T")

options.parseArguments()


process = cms.Process("MAGNETICFIELDTEST")

process.source = cms.Source("EmptySource")

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(1)
)

process.load("MagneticField.Engine.volumeBasedMagneticField_160812_cfi")


REFERENCEFILE = 'none'
if options.current > 18765 or options.current <= 4779 :
print '\nERROR: invalid current value: ', options.current,'\n'
exit()
elif options.current > 17543 :
if options.era == 'RunII' :
REFERENCEFILE = 'MagneticField/Engine/data/Regression/referenceField_160812_RII_3_8T.bin'
elif options.era == 'RunI' :
REFERENCEFILE = 'MagneticField/Engine/data/Regression/referenceField_160812_RI_3_8T.bin'
else:
print '\nERROR: Invalid era: ', options.era,'\n'
exit()
elif options.current > 15617 :
REFERENCEFILE = 'MagneticField/Engine/data/Regression/referenceField_160812_3_5T.bin'
elif options.current > 11987 :
REFERENCEFILE = 'MagneticField/Engine/data/Regression/referenceField_160812_3T.bin'
elif options.current > 4779 :
REFERENCEFILE = 'MagneticField/Engine/data/Regression/referenceField_71212_2T.bin'


if options.producerType == 'static_DDD':
if options.current > 17543 :
process.load("MagneticField.Engine.volumeBasedMagneticField_160812_cfi") # 3.8T, RII
if options.era == 'RunI' :
process.VolumeBasedMagneticFieldESProducer.version = cms.string('grid_160812_3_8t_Run1') # 3.8T, RII
elif options.current > 15617 :
process.load("MagneticField.Engine.volumeBasedMagneticField_160812_cfi")
process.VolumeBasedMagneticFieldESProducer.version = cms.string('grid_160812_3_5t') # 3.5T
process.ParametrizedMagneticFieldProducer.parameters.BValue = cms.string('3_5T')
elif options.current > 11987 :
process.load("MagneticField.Engine.volumeBasedMagneticField_160812_cfi")
process.VolumeBasedMagneticFieldESProducer.version = cms.string('grid_160812_3t')
process.ParametrizedMagneticFieldProducer.parameters.BValue = cms.string('3_0T')
elif options.current > 4779 :
process.load("MagneticField.Engine.volumeBasedMagneticField_71212_cfi") #2.0T


elif options.producerType == 'static_DD4Hep' :
process.load("MagneticField.Engine.volumeBasedMagneticField_dd4hep_160812_cfi")
if options.current > 17543 :
if options.era == 'RunI' :
process.VolumeBasedMagneticFieldESProducer.version = cms.string('grid_160812_3_8t_Run1') # 3.8T, RII
elif options.current > 15617 :
process.VolumeBasedMagneticFieldESProducer.version = cms.string('grid_160812_3_5t') # 3.5T
process.ParametrizedMagneticFieldProducer.parameters.BValue = cms.string('3_5T')
elif options.current > 11987 :
process.VolumeBasedMagneticFieldESProducer.version = cms.string('grid_160812_3t')
process.ParametrizedMagneticFieldProducer.parameters.BValue = cms.string('3_0T')
elif options.current > 4779 :
print '\nERROR: Unsupported current for static_DD4Hep: ', options.current,'\n'
exit()


elif options.producerType == 'fromDB':
process.load("Configuration.StandardSequences.MagneticField_cff")
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '') # Note: testing the proper set-up of data and MC iovs is beyond the scope of this script.

if options.era == 'RunII' :
process.source.firstRun = cms.untracked.uint32(300000)
elif options.era == 'RunI' :
process.source.firstRun = cms.untracked.uint32(100)

# Note that this tests the map and the valueOverride method, but not the mechanism using the actual RunInfo, one mor set of tests could be added for this purpose.
if options.current > 17543:
process.VolumeBasedMagneticFieldESProducer.valueOverride = -1 #3.8T is the default
elif options.current > 15617 :
process.VolumeBasedMagneticFieldESProducer.valueOverride = 17000 #3.5 T
elif options.current > 11987 :
process.VolumeBasedMagneticFieldESProducer.valueOverride = 14000 #3 T
elif options.current > 4779 :
process.VolumeBasedMagneticFieldESProducer.valueOverride = 10000 #2 T

else :
print '\nERROR: invalid producerType', producerType,'\n'


print '\nRegression for MF built with', options.producerType, 'era:', options.era, 'current:', options.current,'\n'


process.testMagneticField = cms.EDAnalyzer("testMagneticField",

## Uncomment to write down the reference file
# outputTable = cms.untracked.string("newtable.txt"),
# outputTable = cms.untracked.string("newtable.bin"),

## Use the specified reference file to compare with
inputTable = cms.untracked.string("/afs/cern.ch/cms/OO/mag_field/CMSSW/regression/referenceField_160812_3_8t.txt"),
inputTable = cms.untracked.string(REFERENCEFILE),

## Valid input file types: "xyz_cm", "rpz_m", "xyz_m", "TOSCA"
inputTableType = cms.untracked.string("xyz_cm"),
## Valid input file types: "xyz", "rpz_m", "xyz_m", "TOSCA"
inputTableType = cms.untracked.string("xyz"),

## Resolution used for validation, number of points
resolution = cms.untracked.double(0.0001),
numberOfPoints = cms.untracked.int32(1000000),
numberOfPoints = cms.untracked.int32(1000000),

## Size of testing volume (cm):
InnerRadius = cms.untracked.double(0), # default: 0
Expand Down