Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:14:57

0001 #!/bin/bash
0002 #
0003 # This script runs the test of KalmanFitter timing vs. p at different eta
0004 # using particle gun particles
0005 # To run the test:./KF_timing.sh -d <detector> -b <bFieldMap> -t <numTracksPerEvent> -n <numEvents>
0006 # In default, it will run with Generic detector in constant B field using 1 event and 100 tracks/event
0007 
0008 help()
0009 {
0010    echo ""
0011    echo "Usage: $0 -d <detector> -b <bFieldMap> -t <numTracksPerEvent> -n <numEvents>"
0012    echo -e "\t-d The detector type, either 'Generic' or 'DD4hep'. Optional. In default 'Generic'"
0013    echo -e "\t-x The '.xml' for DD4hep detector input. Required if the detector is 'DD4hep'. In default empty"
0014    echo -e "\t-b The '.txt' or '.root' file for B Field map. Optional. In default using constant BField: (0, 0, 2)"
0015    echo -e "\t-t The number of tracks per event. Optional. In default: 100"
0016    echo -e "\t-n The number of events. Optional. In default: 1"
0017    exit 1 # Exit script after printing help
0018 }
0019 
0020 if [ ! -f "ActsExampleFatrasGeneric" ]; then
0021   echo Please run this script under the directory where the executables are located
0022   exit 1
0023 fi
0024 
0025 #Default number of tracks/event and event
0026 detector=Generic
0027 numTracksPerEvent=100
0028 numEvents=1
0029 # Get parameters
0030 while getopts "d:x:b:t:n:" opt
0031 do
0032    case "$opt" in
0033       d ) detector="$OPTARG" ;;
0034       x ) dd4hepInput="$OPTARG" ;;
0035       b ) bFieldMap="$OPTARG" ;;
0036       t ) numTracksPerEvent="$OPTARG" ;;
0037       n ) numEvents="$OPTARG" ;;
0038       ? ) help ;; # Print help in case unknown parameter
0039    esac
0040 done
0041 
0042 #check input for DDhep input
0043 if [ "${detector}" == DD4hep ]; then
0044    if [ -z "${dd4hepInput}" ]; then
0045       echo "Empty input for --dd4hep-input. A file like $<source/Examples/Detectors/DD4hepDetector/compact/OpenDataDetector/OpenDataDetector.xml must be provided. Have to exit"
0046       exit 1
0047    fi
0048    if [ ! -f "${dd4hepInput}" ]; then
0049       echo "The ${dd4hepInput} does not exist!"
0050       exit 1
0051    fi
0052    dd4hep_input="--dd4hep-input=${dd4hepInput}"
0053 fi
0054 
0055 # Check input for B field
0056 bField='--bf-value 0 0 2'
0057 if [ -z "${bFieldMap}" ]; then
0058    echo "bFieldMap is empty. Will use constant B Field (0, 0, 2) then."
0059 elif [ -f "$bFieldMap" ] ; then
0060    echo "Input bField map: $bFieldMap "
0061    bField='--bf-map ${bFieldMap}'
0062 else
0063    echo "Input file for bField map file does not exist!"
0064    exit 1
0065 fi
0066 
0067 #Print the parameters
0068 echo "Test detector: ${detector}"
0069 echo "B Field: ${bField}"
0070 echo "Number of tracks per event: ${numTracksPerEvent}"
0071 echo "Number of events: ${numEvents}"
0072 
0073 time_stamp=`date +%F%T`
0074 exe_dir=${PWD}
0075 run_dir=KalmanFitter_timing_${time_stamp}
0076 
0077 mkdir ${run_dir}
0078 cd ${run_dir}
0079 
0080 output_file='output.log'
0081 echo "*****KalmanFitter timing test vs. p*****" > ${output_file}
0082 echo "Test Detector: ${detector}" >> ${output_file}
0083 echo "BField: ${bField}" >> ${output_file}
0084 echo "Events: ${numEvents}" >> ${output_file}
0085 echo "Tracks_per_event: ${numTracksPerEvent}" >> ${output_file}
0086 echo "****************************************" >> ${output_file}
0087 echo "*"
0088 echo "* job | eta | p | fit_time_per_event" >> ${output_file}
0089 
0090 jobID=0
0091    # Loop over the pt bins
0092    for pt in 0.1 0.5 1.0 2.0 3.0 4.0 5.0 8.0 10.0 50.0 100.0 ; do
0093       # Loop over the eta bin number
0094       for etaBin in 0 1 2 3 4; do
0095          etaLow=$(echo "${etaBin}*0.5"|bc)
0096          etaUp=$(echo "${etaBin}*0.5 + 0.5"|bc)
0097          eta=$(echo "${etaBin}*0.5 + 0.25"|bc)
0098 
0099          # Run sim
0100          sim="${exe_dir}/ActsExampleFatras${detector} ${dd4hep_input} ${bField} -n ${numEvents} --gen-nparticles ${numTracksPerEvent} --gen-mom-gev ${pt}:${pt} --gen-eta ${etaLow}:${etaUp} --output-csv=1 --output-dir=data/sim_${detector}/e${numEvents}_t${numTracksPerEvent}_eta${eta}_pt${pt}"
0101          echo "Run sim with '${sim}'"
0102          eval ${sim}
0103 
0104          # Run reco
0105          reco="$exe_dir/ActsExampleTruthTracks${detector} ${dd4hep_input} ${bField} --input-dir=data/sim_${detector}/e${numEvents}_t${numTracksPerEvent}_eta${eta}_pt${pt} --output-dir=data/reco_${detector}/e${numEvents}_t${numTracksPerEvent}_eta${eta}_pt${pt}"
0106          echo "Run reco with '${reco}'"
0107          eval ${reco}
0108 
0109          # Archive with Job ID
0110          mv data/reco_${detector}/e${numEvents}_t${numTracksPerEvent}_eta${eta}_pt${pt}/timing.tsv timing_${jobID}.tsv
0111          # Extract the fitting time
0112          fit_time_str=`grep "Algorithm:TrackFittingAlgorithm" timing_${jobID}.tsv | awk '{print $3}'`
0113          # Make sure the fit time is fixed-point for calculation with bc
0114          fit_time_per_event=$(echo ${fit_time_str} | awk '{printf("%.10f\n", $1)}')
0115          fit_time_per_track=$(echo "${fit_time_per_event}/${numTracksPerEvent}"|bc -l)
0116          echo "${jobID}, ${etaBin}, ${pt}, ${fit_time_per_track}" >> ${output_file}
0117 
0118          # JobID
0119          let "jobID++"
0120       done
0121    done