File indexing completed on 2025-04-17 08:10:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 flair_file="study_final_state.flair"
0011 num_comparison_plots=3
0012 plot_block_max_length=100
0013
0014
0015
0016 all_particles=$(cat $flair_file | grep "Plot:" | cut -d' ' -f2)
0017
0018
0019 for particle in ${all_particles[@]}; do
0020
0021 echo "particle=$particle";
0022
0023
0024 plot_line_number=$(grep -n -m1 "Plot: $particle" $flair_file | cut -d':' -f1)
0025 echo "plot_line_number=$plot_line_number"
0026
0027
0028 next_plot=$(grep -A$plot_block_max_length "Plot: $particle" $flair_file | grep -n -m2 "Plot: " | wc -l)
0029 if [ "$next_plot" -eq "2" ]; then
0030 has_next_plot=true
0031 else
0032 has_next_plot=false
0033 fi
0034 echo "has_next_plot=$has_next_plot";
0035
0036
0037 if [ "$has_next_plot" = true ] ; then
0038 next_plot_line_number=$(grep -A$plot_block_max_length "Plot: $particle" $flair_file | grep -n -m2 "Plot: " | tail -n1 | cut -d':' -f1)
0039
0040 next_plot_line_number=$(($plot_line_number + $next_plot_line_number - 1))
0041 else
0042
0043 next_plot_line_number=$(cat $flair_file | wc -l)
0044 fi
0045 echo "next_plot_line_number=$next_plot_line_number"
0046
0047
0048 for ((i=0; i < $num_comparison_plots; i++)); do
0049 data_file=$(sed -n "$plot_line_number,$next_plot_line_number p" $flair_file | grep "file\.$i" | cut -d' ' -f2)
0050 echo "data_file=$data_file"
0051
0052 if [ -z "$data_file" ]; then
0053 echo "Warning: Tried to look for data file $data_file, which does not exist! Field is not updated for this file."
0054
0055 else
0056
0057 data_det=$(grep "# Detector:.* $particle" $data_file | cut -d' ' -f4)
0058 data_det=$(($data_det - 1))
0059 echo "data_det=$data_det"
0060
0061
0062 if [ ! -z "$data_det" ]; then
0063
0064
0065 flair_det=$(sed -n "$plot_line_number,$next_plot_line_number p" $flair_file | grep "det\.$i")
0066 echo "flair_det=$flair_det"
0067
0068
0069 if [ ! -z "$flair_det" ]; then
0070 sed -i "$plot_line_number,$next_plot_line_number s/det\.$i.*/det\.$i: $data_det/g" $flair_file
0071
0072 else
0073
0074 echo "Warning: No det.$i defined for plot $particle, file $data_file: field was not updated."
0075 fi
0076
0077
0078 else
0079 sed -i "$plot_line_number,$next_plot_line_number s/det\.$i.*//" $flair_file
0080 fi
0081 fi
0082 done
0083
0084 done