Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:28:28

0001 #!/bin/bash
0002 set -e
0003 # script for material map validation with ACTS python bindings
0004 # run as : ./run_material_map_validation.sh --nevents 1000
0005 # Shujie Li, 03. 2024 (https://github.com/eic/snippets/pull/3)
0006 : ${DETECTOR_CONFIG:="epic_craterlake_material_map"}
0007 # Check if DETECTOR_PATH are set
0008 if [[ -z ${DETECTOR_PATH} ]] ; then
0009   echo "You must set \$DETECTOR_PATH before running this script."
0010   exit -1
0011 fi
0012 
0013 # Download required Acts files
0014 ACTS_VERSION="v39.2.0"
0015 ACTS_URL="https://github.com/acts-project/acts/raw/"
0016 ACTS_FILES=(
0017   "Examples/Scripts/Python/geometry.py"
0018   "Examples/Scripts/Python/material_mapping.py"
0019   "Examples/Scripts/Python/material_recording.py"
0020   "Examples/Scripts/Python/material_validation.py"
0021   "Examples/Scripts/MaterialMapping/writeMapConfig.py"
0022   "Examples/Scripts/MaterialMapping/configureMap.py"
0023   "Examples/Scripts/MaterialMapping/GeometryVisualisationAndMaterialHandling.py"
0024   "Examples/Scripts/MaterialMapping/Mat_map.C"
0025   "Examples/Scripts/MaterialMapping/Mat_map_surface_plot.C"
0026   "Examples/Scripts/MaterialMapping/Mat_map_surface_plot_ratio.C"
0027   "Examples/Scripts/MaterialMapping/Mat_map_surface_plot_dist.C"
0028   "Examples/Scripts/MaterialMapping/Mat_map_surface_plot_1D.C"
0029   "Examples/Scripts/MaterialMapping/materialPlotHelper.cpp"
0030   "Examples/Scripts/MaterialMapping/materialPlotHelper.hpp"
0031 )
0032 for file in ${ACTS_FILES[@]} ; do
0033   if [ ! -f ${file} ] ; then
0034     curl --silent --location --create-dirs --output ${file} ${ACTS_URL}/${ACTS_VERSION}/${file}
0035     if [ "${file}" = "Examples/Scripts/MaterialMapping/Mat_map.C" ] ; then
0036       # help with B0 being cropped
0037       patch -p1 <<EOF
0038 diff -aru a/Examples/Scripts/MaterialMapping/Mat_map.C b/Examples/Scripts/MaterialMapping/Mat_map.C
0039 --- a/Examples/Scripts/MaterialMapping/Mat_map.C
0040 +++ b/Examples/Scripts/MaterialMapping/Mat_map.C
0041 @@ -145,7 +145,8 @@
0042 
0043      // 2D map for Validation input
0044      TCanvas *VM = new TCanvas("VM","Validation Map") ;
0045 -    Val_file->Draw("mat_y:mat_z","std::abs(mat_x)<1");
0046 +    Val_file->Draw("sqrt(mat_x**2+mat_y**2):mat_z>>mat_map1","(mat_z>-5000)&(mat_z<8000)");
0047 +    VM->SetGrid();
0048 
0049      eta_0->Draw("Same");
0050      eta_1p->Draw("Same");
0051 EOF
0052     fi
0053   fi
0054 done
0055 export PYTHONPATH=$PWD/Examples/Scripts/Python:$PYTHONPATH
0056 
0057 # FIXME
0058 # Disable ACTS FpeMonitor due to unexplained FPEINV in RootMaterialTrackReader
0059 # FPE summary for Reader: RootMaterialTrackReader
0060 # FLTINV: (2 times)
0061 #  0# Acts::MaterialSlab::MaterialSlab(Acts::Material const&, float) in /opt/local/python/acts/../../lib/libActsCore.so
0062 #  1# ActsExamples::RootMaterialTrackReader::read(ActsExamples::AlgorithmContext const&) in /opt/local/python/acts/../../lib/libActsExamplesIoRoot.so
0063 #  2# ActsExamples::Sequencer::run()::$_0::operator()() const::{lambda(tbb::blocked_range<unsigned long> const&)#1}::operator()(tbb::blocked_range<unsigned long> const&) const in /opt/local/python/acts/../../lib/libActsExamplesFramework.so
0064 #  3# ActsExamples::Sequencer::run()::$_0::operator()() const in /opt/local/python/acts/../../lib/libActsExamplesFramework.so
0065 #  4# ActsExamples::Sequencer::run() in /opt/local/python/acts/../../lib/libActsExamplesFramework.so
0066 #  5# 0x000070B51DE55640 in /opt/local/python/acts/ActsPythonBindings.cpython-310-x86_64-linux-gnu.so
0067 #  6# 0x000070B51DE49ACD in /opt/local/python/acts/ActsPythonBindings.cpython-310-x86_64-linux-gnu.so
0068 #  7# cfunction_call at Objects/methodobject.c:543
0069 export ACTS_SEQUENCER_DISABLE_FPEMON=1
0070 
0071 # Default arguments
0072 # FIXME
0073 # This was originally
0074 #   nevents=1000
0075 #   nparticles=5000
0076 # but reduced to get the job to complete...
0077 nevents=100
0078 nparticles=500
0079 
0080 function print_the_help {
0081   echo "USAGE:    [--nevents <int>] [--nparticles <int>]"
0082   echo "OPTIONAL ARGUMENTS:"
0083   echo "          --nevents       Number of events (default: $nevents)"
0084   echo "          --nparticles    Number of particles per event (default: $nparticles)"
0085   echo "          -h,--help     Print this message"
0086   echo ""
0087   echo "  Run material map validation."
0088   exit
0089 }
0090 
0091 while [[ $# -gt 1 ]]
0092 do
0093   key="$1"
0094   case $key in
0095     --nevents)
0096       nevents=$2
0097       shift # past value
0098       shift
0099       ;;
0100     --nparticles)
0101       nparticles=$2
0102       shift # past value
0103       shift
0104       ;;
0105     *)    # unknown option
0106       #POSITIONAL+=("$1") # save it in an array for later
0107       echo "unknown option $1"
0108       print_the_help
0109       shift # past argument
0110       ;;
0111   esac
0112 done
0113 set -- "${POSITIONAL[@]}" # restore positional parameters
0114 
0115 recordingFile=geant4_material_tracks.root
0116 geoFile=geometry-map.json
0117 matFile=material-map.cbor
0118 trackFile=material-map_tracks.root
0119 propFile=propagation_material
0120 
0121 echo "::group::----GEANTINO SCAN------"
0122 # output geant4_material_tracks.root
0123 # 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.
0124 python material_recording_epic.py -i ${DETECTOR_PATH}/${DETECTOR_CONFIG}.xml -n ${nevents} -t ${nparticles} -o ${recordingFile}
0125 echo "::endgroup::"
0126 
0127 echo "::group::-----MAPPING Configuration-----"
0128 # map geometry to geometry-map.json
0129 python geometry_epic.py -i ${DETECTOR_PATH}/${DETECTOR_CONFIG}.xml
0130 
0131 # take geometry-map.json and read out config-map.json
0132 python Examples/Scripts/MaterialMapping/writeMapConfig.py ${geoFile} config-map.json
0133 
0134 # turn on approaches and beampipe surfaces for material mapping
0135 # you can always manually adjust the mapmaterial flag and binnings in config-map.json
0136 python materialmap_config.py -i config-map.json -o config-map_regenerated.json
0137 
0138 # turn config-map.json into modified geometry-map.json
0139 python Examples/Scripts/MaterialMapping/configureMap.py ${geoFile} config-map_regenerated.json
0140 
0141 # generate figures to display tracking layers and volumes as seen by ACTS
0142 rm -rf plots
0143 mkdir -p plots
0144 python Examples/Scripts/MaterialMapping/GeometryVisualisationAndMaterialHandling.py --geometry ${geoFile}
0145 echo "::endgroup::"
0146 
0147 echo "::group::----MAPPING Debugging-----"
0148 echo "Volumes by name:"
0149 jq -r '.Volumes.entries[] | "vol=\(.volume): \(.value.NAME)"' geometry-map.json
0150 echo "Volume surfaces:"
0151 jq -r '.Surfaces.entries[] | select(.boundary != null) | "vol=\(.volume)|bnd=\(.boundary): \(.value.type) \(.value.bounds.type) \(.value.bounds.values) rot=\(.value.transform.rotation) pos=\(.value.transform.translation)"' geometry-map.json
0152 echo "Layer surfaces:"
0153 jq -r '.Surfaces.entries[] | select(.volume < 40 and .layer != null) | "vol=\(.volume)|lay=\(.layer): \(.value.type) \(.value.bounds.type) \(.value.bounds.values) rot=\(.value.transform.rotation) pos=\(.value.transform.translation)"' geometry-map.json
0154 echo "::endgroup::"
0155 
0156 echo "::group::----MAPPING------------"
0157 # input: geant4_material_tracks.root, geometry-map.json
0158 # 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
0159 #         material-maps_tracks.root(recorded steps from geantino, for validation purpose)
0160 sed -i 's/acts\.logging\.INFO/acts.logging.VERBOSE/g' Examples/Scripts/Python/material_mapping.py
0161 sed -i 's/navigator = Navigator($/&level=acts.logging.VERBOSE,/' Examples/Scripts/Python/material_mapping.py
0162 sed -i 's/propagator = Propagator(stepper, navigator)$/propagator = Propagator(stepper, navigator, loglevel=acts.logging.VERBOSE)/' Examples/Scripts/Python/material_mapping.py
0163 set -o pipefail
0164 python material_mapping_epic.py --xmlFile ${DETECTOR_PATH}/${DETECTOR_CONFIG}.xml --geoFile ${geoFile} --matFile ${matFile} | tail -n 5000
0165 echo "::endgroup::"
0166 
0167 echo "::group::----Prepare validation rootfile--------"
0168 # output propagation-material.root
0169 python material_validation_epic.py --xmlFile ${DETECTOR_PATH}/${DETECTOR_CONFIG}.xml --outputName ${propFile}_regenerated --matFile ${matFile} -n ${nevents}  -t ${nparticles}
0170 python material_validation_epic.py --xmlFile ${DETECTOR_PATH}/${DETECTOR_CONFIG}.xml --outputName ${propFile}_current --matFile "calibrations/materials-map.cbor" -n ${nevents} -t ${nparticles}
0171 echo "::endgroup::"
0172 
0173 echo "::group::-------Comparison plots---------"
0174 rm -rf Validation/regenerated
0175 mkdir -p Validation/regenerated
0176 root -l -b -q Examples/Scripts/MaterialMapping/Mat_map.C'("'${propFile}_regenerated'.root","'${trackFile}'","Validation/regenerated")'
0177 rm -rf Validation/current
0178 mkdir -p Validation/current
0179 root -l -b -q Examples/Scripts/MaterialMapping/Mat_map.C'("'${propFile}_current'.root","'${trackFile}'","Validation/current")'
0180 
0181 rm -rf Surfaces
0182 mkdir -p Surfaces/regenerated/ratio_plot
0183 mkdir -p Surfaces/regenerated/prop_plot
0184 mkdir -p Surfaces/regenerated/map_plot
0185 mkdir -p Surfaces/current/ratio_plot
0186 mkdir -p Surfaces/current/prop_plot
0187 mkdir -p Surfaces/current/map_plot
0188 mkdir -p Surfaces/dist_plot
0189 mkdir -p Surfaces/1D_plot
0190 
0191 root -l -b -q Examples/Scripts/MaterialMapping/Mat_map_surface_plot_ratio.C'("'${propFile}_regenerated'.root","'${trackFile}'",-1,"Surfaces/regenerated/ratio_plot","Surfaces/regenerated/prop_plot","Surfaces/regenerated/map_plot")'
0192 root -l -b -q Examples/Scripts/MaterialMapping/Mat_map_surface_plot_ratio.C'("'${propFile}_current'.root","'${trackFile}'",-1,"Surfaces/current/ratio_plot","Surfaces/current/prop_plot","Surfaces/current/map_plot")'
0193 root -l -b -q Examples/Scripts/MaterialMapping/Mat_map_surface_plot_dist.C'("'${trackFile}'",-1,"Surfaces/dist_plot")'
0194 root -l -b -q Examples/Scripts/MaterialMapping/Mat_map_surface_plot_1D.C'("'${trackFile}'",-1,"Surfaces/1D_plot")'
0195 echo "::endgroup::"