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

update material map script for acts v35.2 #826

Merged
merged 11 commits into from
Feb 9, 2025
14 changes: 14 additions & 0 deletions configurations/craterlake_material_map.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# This contains all geometry to be used in the material map
ebeam: 5
pbeam: 41
features:
beampipe:
tracking:
Expand All @@ -13,5 +15,17 @@ features:
silicon_disks:
tof_barrel:
tof_endcap:
pid:
dirc:
pfrich:
drich:
ecal:
forward_homogeneous:
forward_insert_homogeneous:
hcal:
lfhcal_with_space_for_insert:
forward_insert:
far_forward:
default:
far_backward:
default:
9 changes: 9 additions & 0 deletions scripts/material_map/material_mapping_epic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@
args = p.parse_args()

mapName = args.matFile.split('.')[0]
if '.json' in args.matFile:
mapFormat = JsonFormat.Json
elif '.cbor' in args.matFile:
mapFormat = JsonFormat.Cbor
else:
print('ERROR(material_mapping_epic.py): please provide a material map file in .json or .cbor format')
exit()

detector, trackingGeometry, decorators = epic.getDetector(
args.xmlFile, args.geoFile)


runMaterialMapping(
trackingGeometry,
decorators,
Expand All @@ -48,4 +56,5 @@
readCachedSurfaceInformation=False,
mapVolume= False,
mapName = mapName,
mapFormat = mapFormat,
).run()
13 changes: 10 additions & 3 deletions scripts/material_map/material_validation_epic.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"--matFile",
type=str,
default="material-map.json",
help="input material map file, can be either Json or Cbor",
help="input material map file with extension, can be either xx.json or xx.cbor",
)
p.add_argument(
"--outputName",
Expand All @@ -38,16 +38,23 @@
p.add_argument(
"-n","--nevents",
type=int,
default=100,
default=1000,
help="number of events to run",
)

p.add_argument(
"-t","--ntracks",
type=int,
default=1000,
help="number of tracks per event")

args = p.parse_args()

detector, trackingGeometry, decorators = epic.getDetector(args.xmlFile, args.matFile)

field = acts.ConstantBField(acts.Vector3(0, 0, 0))

runMaterialValidation(
runMaterialValidation(args.nevents, args.ntracks,
trackingGeometry, decorators, field,
outputDir=os.getcwd(), outputName=args.outputName,
s=Sequencer(events=args.nevents, numThreads=-1)
Expand Down
28 changes: 17 additions & 11 deletions scripts/material_map/run_material_map_validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ set -e
# script for material map validation with ACTS python bindings
# run as : ./run_material_map_validation.sh --nevents 1000
# Shujie Li, 03. 2024 (https://github.com/eic/snippets/pull/3)

# Check if DETECTOR_PATH and DETECTOR_CONFIG are set
if [[ -z ${DETECTOR_PATH} || -z ${DETECTOR_CONFIG} ]] ; then
echo "You must set \$DETECTOR_PATH and \$DETECTOR_CONFIG before running this script."
MAP_DETECTOR_CONFIG="epic_craterlake_material_map"
# Check if DETECTOR_PATH and MAP_DETECTOR_CONFIG are set
if [[ -z ${DETECTOR_PATH} || -z ${MAP_DETECTOR_CONFIG} ]] ; then
echo "You must set \$DETECTOR_PATH and \$MAP_DETECTOR_CONFIG before running this script."
exit -1
fi

# Download required Acts files
ACTS_VERSION="8e1b7a659d912cd98db9d700906ff59e708da574" # v34.1.0
ACTS_VERSION="b3b09f46d064c43050dd3d21cdf51d7a412134fc" #v35.2.0
ACTS_URL="https://github.com/acts-project/acts/raw/"
ACTS_FILES=(
"Examples/Scripts/Python/geometry.py"
Expand All @@ -20,6 +20,7 @@ ACTS_FILES=(
"Examples/Scripts/Python/material_validation.py"
"Examples/Scripts/MaterialMapping/writeMapConfig.py"
"Examples/Scripts/MaterialMapping/configureMap.py"
"Examples/Scripts/MaterialMapping/GeometryVisualisationAndMaterialHandling.py"
"Examples/Scripts/MaterialMapping/Mat_map.C"
"Examples/Scripts/MaterialMapping/Mat_map_surface_plot.C"
"Examples/Scripts/MaterialMapping/Mat_map_surface_plot_ratio.C"
Expand Down Expand Up @@ -78,19 +79,19 @@ set -- "${POSITIONAL[@]}" # restore positional parameters

recordingFile=geant4_material_tracks.root
geoFile=geometry-map.json
matFile=material-map.json
matFile=material-map.cbor
trackFile=material-map_tracks.root
propFile=propagation_material

echo "::group::----GEANTINO SCAN------"
# output geant4_material_tracks.root
# The result of the geantino scan will be a root file containing material tracks. Those contain the direction and production vertex of the geantino, the total material accumulated and all the interaction points in the detector.
python material_recording_epic.py -i ${DETECTOR_PATH}/${DETECTOR_CONFIG}.xml -n ${nevents} -t ${nparticles} -o ${recordingFile}
python material_recording_epic.py -i ${DETECTOR_PATH}/${MAP_DETECTOR_CONFIG}.xml -n ${nevents} -t ${nparticles} -o ${recordingFile}
echo "::endgroup::"

echo "::group::-----MAPPING Configuration-----"
# map geometry to geometry-map.json
python geometry_epic.py -i ${DETECTOR_PATH}/${DETECTOR_CONFIG}.xml
python geometry_epic.py -i ${DETECTOR_PATH}/${MAP_DETECTOR_CONFIG}.xml

# take geometry-map.json and read out config-map.json
python Examples/Scripts/MaterialMapping/writeMapConfig.py ${geoFile} config-map.json
Expand All @@ -101,19 +102,24 @@ python materialmap_config.py -i config-map.json -o config-map_new.json

# turn config-map.json into modified geometry-map.json
python Examples/Scripts/MaterialMapping/configureMap.py ${geoFile} config-map_new.json

# generate figures to display tracking layers and volumes as seen by ACTS
rm -rf plots
mkdir -p plots
python Examples/Scripts/MaterialMapping/GeometryVisualisationAndMaterialHandling.py --geometry ${geoFile}
echo "::endgroup::"

echo "::group::----MAPPING------------"
# input: geant4_material_tracks.root, geometry-map.json
# output: material-maps.json or cbor. This is the material map that you want to provide to EICrecon, i.e. -Pacts:MaterialMap=XXX .Please --matFile to specify the name and type
# material-maps_tracks.root(recorded steps from geantino, for validation purpose)
python material_mapping_epic.py --xmlFile ${DETECTOR_PATH}/${DETECTOR_CONFIG}.xml --geoFile ${geoFile} --matFile ${matFile}
python material_mapping_epic.py --xmlFile ${DETECTOR_PATH}/${MAP_DETECTOR_CONFIG}.xml --geoFile ${geoFile} --matFile ${matFile}
echo "::endgroup::"

echo "::group::----Prepare validation rootfile--------"
# output propagation-material.root
python material_validation_epic.py --xmlFile ${DETECTOR_PATH}/${DETECTOR_CONFIG}.xml --outputName ${propFile}_new --matFile ${matFile} -n ${nevents}
python material_validation_epic.py --xmlFile ${DETECTOR_PATH}/${DETECTOR_CONFIG}.xml --outputName ${propFile}_old --matFile "calibrations/materials-map.cbor" -n ${nevents}
python material_validation_epic.py --xmlFile ${DETECTOR_PATH}/${MAP_DETECTOR_CONFIG}.xml --outputName ${propFile}_new --matFile ${matFile} -n ${nevents} -t ${nparticles}
python material_validation_epic.py --xmlFile ${DETECTOR_PATH}/${MAP_DETECTOR_CONFIG}.xml --outputName ${propFile}_old --matFile "calibrations/materials-map.cbor" -n ${nevents} -t ${nparticles}
echo "::endgroup::"

echo "::group::-------Comparison plots---------"
Expand Down