Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:37:42

0001 #!/bin/bash
0002 # example script to generate small sample of background mixed event file locally
0003 # you should always use background files from the simulation campaign data (https://eic.github.io/epic-prod/) when possible 
0004 # Shujie Li, 10.2025
0005 
0006 # pre-requists:
0007 #        1.  install SignalBackgroundMerger from https://github.com/eic/HEPMC_Merger
0008 #        2.  recommend to run within eic-shell to use the xrdfs command
0009 
0010 ## run as: ./run_merger.sh, then follow the options.
0011 
0012 # For SR and electron beam gas, please also read README files under JLab ifarm:
0013 #       SynRad: /volatile/eic/andrii/SynradG4_HepMC_Files_SR_on_IP6
0014 #       ESR beam losses: /volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC
0015 
0016 ## 1000 merged events at 18GeV takes about 2 hours for dd4hep+eicrecon.
0017 ## the 5 and 10 GeV mixed events will be 10x slower due to higher SR freq. Use the simulation campaign file if you can. 
0018 nev=100
0019 window=2000 #integration window of 2us --> 2000ns is the default
0020 skip=0 # skip the first N signal events
0021 seed=42
0022 ## signal frequency 
0023 #        =0: forced to have one signal per time slice/window, 
0024 #        >0: use the actual signal and background freq in sampling, 
0025 #        <0: (depracated) background with the default minbias (Q2<1 SIDIS) events as signal. 
0026 # Mixing frequencies can be found on ePIC Wiki: https://wiki.bnl.gov/EPIC/index.php?title=Background
0027 # Explanations on mixing scheme at https://github.com/eic/eic.github.io/blob/master/_resources/background_mixed_samples.md
0028 sf=0
0029 
0030 if [ "$sf" -gt 0 ]; then
0031     sig_type="dis"
0032 elif [ "$sf" -eq 0 ]; then
0033     sig_type="forced"
0034 else
0035     sig_type="minbias"
0036 fi
0037 
0038 ###############
0039 ## background sources 
0040 ## SR, brems, coulomb, touschek, pgas
0041 ## generatorStatus ID:
0042 ## 2000, 3000, 4000, 5000, 6000
0043 ###############
0044 echo "Please select an option:"
0045 echo "1: DIS 18x275"
0046 echo "2: DIS 18x275, no SR"
0047 echo "3: minbias 18x275"
0048 echo "4: DIS 10x275, SR scaled from 18GeV"
0049 echo "5: DIS 5x100, SR scaled from 18GeV"
0050 echo "6: Backgrounds only 18x275"
0051 
0052 # Read user input
0053 read -p "Enter option number (1-6): " option
0054 if   [[ "$option" == "1" ]]; then
0055     ebeam=18
0056     pbeam=275
0057     tag=""
0058     signal="pythia8NCDIS_18x275_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1.hepmc"
0059     bg_files=(
0060         # "root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/BACKGROUNDS/SYNRAD/dataprod_rel_1.0.0/18x275/dataprod_rel_1.0.0_synrad_18x275_run001.hepmc3.tree.root" ## old SR samples with all inner beampipe photons
0061         "root://dtn-eic.jlab.org//volatile/eic/andrii/SynradG4_HepMC_Files_SR_on_IP6/data/synrad/dataprod_rel_1.0.0/18x275/dataprod_rel_1.0.0_synrad_18x275_run001.preproc_10000repeats.hepmc3.tree.root" ## new SR with outer beampipe photons only, freq=3.3GHz
0062         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electronbrems/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electronbrems_18x275_50sec.hepmc3.tree.root"
0063         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electroncoulomb/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electroncoulomb_18x275_50sec.hepmc3.tree.root"
0064         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electrontouschek/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electrontouschek_18x275_50sec.hepmc3.tree.root"
0065         "root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/BACKGROUNDS/BEAMGAS/proton/pythia8.306-1.0/275GeV/pythia8.306-1.0_ProtonBeamGas_275GeV_run001.hepmc3.tree.root"
0066     )
0067     freqs=(3300000 18.26 0.86 0.55 22.5) ## kHz
0068     statuses=(2000 3000 4000 5000 6000)
0069 
0070 elif [[ "$option" == "2" ]]; then
0071     ebeam=18
0072     pbeam=275
0073     tag="_noSR_"
0074     signal="pythia8NCDIS_18x275_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1.hepmc"
0075     bg_files=(
0076         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electronbrems/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electronbrems_18x275_50sec.hepmc3.tree.root"
0077         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electroncoulomb/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electroncoulomb_18x275_50sec.hepmc3.tree.root"
0078         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electrontouschek/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electrontouschek_18x275_50sec.hepmc3.tree.root"
0079         "root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/BACKGROUNDS/BEAMGAS/proton/pythia8.306-1.0/275GeV/pythia8.306-1.0_ProtonBeamGas_275GeV_run001.hepmc3.tree.root"
0080     )
0081     freqs=(18.26 0.86 0.55 22.5) ## kHz
0082     statuses=(3000 4000 5000 6000)
0083 
0084 elif [[ "$option" == "3" ]]; then
0085     ebeam=18
0086     pbeam=275
0087     tag="_minbias_"
0088     signal="pythia_ep_noradcor_18x275_q2_0.000000001_1.0_run1.ab.hepmc3.tree.root"
0089     bg_files=(
0090         "dataprod_rel_1.0.0_synrad_18x275_run001.preproc_10000repeats.hepmc3.tree.root" ## new SR with outer beampipe photons only, freq=3.3GHz
0091         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electronbrems/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electronbrems_18x275_50sec.hepmc3.tree.root"
0092         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electroncoulomb/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electroncoulomb_18x275_50sec.hepmc3.tree.root"
0093         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electrontouschek/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electrontouschek_18x275_50sec.hepmc3.tree.root"
0094         "root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/BACKGROUNDS/BEAMGAS/proton/pythia8.306-1.0/275GeV/pythia8.306-1.0_ProtonBeamGas_275GeV_run001.hepmc3.tree.root"
0095     )
0096     freqs=(3300000 18.26 0.86 0.55 22.5) ## kHz
0097     statuses=(2000 3000 4000 5000 6000)
0098 
0099 elif [[ "$option" == "4" ]]; then
0100     ebeam=10
0101     pbeam=275
0102     tag="_scaled_SR_"
0103     signal="pythia8NCDIS_10x275_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1.hepmc"
0104 
0105     bg_files=(
0106     "root://dtn-eic.jlab.org//volatile/eic/andrii/SynradG4_HepMC_Files_SR_on_IP6/data/synrad/dataprod_rel_1.0.0/10x275/dataprod_rel_1.0.0_synrad_10x275_run001.preproc_10000repeats.hepmc3.tree.root"
0107     "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electronbrems/dataprod_rel_1.0.1/10x275/dataprod_rel_1.0.1_electronbrems_10x275_50sec.hepmc3.tree.root"
0108     "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electroncoulomb/dataprod_rel_1.0.1/10x275/dataprod_rel_1.0.1_electroncoulomb_10x275_50sec.hepmc3.tree.root"
0109     "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electrontouschek/dataprod_rel_1.0.1/10x275/dataprod_rel_1.0.1_electrontouschek_10x275_50sec.hepmc3.tree.root"
0110     "root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/BACKGROUNDS/BEAMGAS/proton/pythia8.306-1.0/275GeV/pythia8.306-1.0_ProtonBeamGas_275GeV_run001.hepmc3.tree.root"
0111     )
0112 
0113     freqs=(36608000 172.31 29.56 233.50 32.6) ## kHz
0114     statuses=(2000 3000 4000 5000 6000)
0115 
0116 elif [[ "$option" == "5" ]]; then
0117     ebeam=5
0118     pbeam=100
0119     tag="_scaled_SR_"
0120     signal="root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/DIS/NC/5x100/minQ2=1/pythia8NCDIS_5x100_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1.hepmc3.tree.root"
0121     bg_files=(
0122     "root://dtn-eic.jlab.org//volatile/eic/andrii/SynradG4_HepMC_Files_SR_on_IP6/data/synrad/dataprod_rel_1.0.0/5x100/dataprod_rel_1.0.0_synrad_5x100_run001.preproc_10000repeats.hepmc3.tree.root"
0123     "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electronbrems/dataprod_rel_1.0.1/5x100/dataprod_rel_1.0.1_electronbrems_5x100_50sec.hepmc3.tree.root"
0124     "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electroncoulomb/dataprod_rel_1.0.1/5x100/dataprod_rel_1.0.1_electroncoulomb_5x100_50sec.hepmc3.tree.root"
0125     "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electrontouschek/dataprod_rel_1.0.1/5x100/dataprod_rel_1.0.1_electrontouschek_5x100_50sec.hepmc3.tree.root"
0126     "root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/BACKGROUNDS/BEAMGAS/proton/pythia8.306-1.0/100GeV/pythia8.306-1.0_ProtonBeamGas_100GeV_run001.hepmc3.tree.root"
0127     )
0128     statuses=(2000 3000 4000 5000 6000) ## kHz
0129     freqs=(36608000 328.04 116.57 1112.3 22)
0130 
0131 elif [[ "$option" == "6" ]]; then
0132     ebeam=18
0133     pbeam=275
0134     sig_type="bgOnly"
0135     tag=""
0136     signal="pythia8NCDIS_18x275_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1.hepmc"
0137     bg_files=(
0138         # "root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/BACKGROUNDS/SYNRAD/dataprod_rel_1.0.0/18x275/dataprod_rel_1.0.0_synrad_18x275_run001.hepmc3.tree.root" ## old SR samples with all inner beampipe photons
0139         "root://dtn-eic.jlab.org//volatile/eic/andrii/SynradG4_HepMC_Files_SR_on_IP6/data/synrad/dataprod_rel_1.0.0/18x275/dataprod_rel_1.0.0_synrad_18x275_run001.preproc_10000repeats.hepmc3.tree.root" ## new SR with outer beampipe photons only, freq=3.3GHz
0140         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electronbrems/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electronbrems_18x275_50sec.hepmc3.tree.root"
0141         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electroncoulomb/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electroncoulomb_18x275_50sec.hepmc3.tree.root"
0142         "root://dtn-eic.jlab.org//volatile/eic/andrii/Xsuite_HepMC_Files_ESR_BeamLoss_on_ePIC/data/xsuite/electrontouschek/dataprod_rel_1.0.1/18x275/dataprod_rel_1.0.1_electrontouschek_18x275_50sec.hepmc3.tree.root"
0143         "root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/BACKGROUNDS/BEAMGAS/proton/pythia8.306-1.0/275GeV/pythia8.306-1.0_ProtonBeamGas_275GeV_run001.hepmc3.tree.root"
0144     )
0145     freqs=(3300000 18.26 0.86 0.55 22.5) ## kHz
0146     statuses=(2000 3000 4000 5000 6000)
0147 
0148 else
0149     echo "Invalid option selected."
0150     exit 1
0151 fi
0152 
0153 ## ------------------------------------------------
0154 ## assemble command
0155 ## ------------------------------------------------
0156 outfile=bgmerged_${sig_type}_${ebeam}x${pbeam}${tag}n${nev}.hepmc3.tree.root
0157 cmd="./SignalBackgroundMerger  -N ${nev} --rngSeed ${seed} -o merged/${outfile}"
0158 
0159 ## add signal
0160 if [[ "$option" == "6" ]]; then
0161     cmd+=" -i $signal -sf 0.01 -S $nskip -w $window"
0162 elif [ "$sf" -ge 0 ]; then ## use DIS signal file
0163     cmd+=" -i $signal -sf $sf -S $nskip -w $window"
0164 else ## use the default from the merger which is the sidis sample
0165     cmd+=" -i pythia_ep_noradcor_18x275_q2_0.000000001_1.0_run1.ab.hepmc3.tree.root -sf 83 "
0166 fi
0167 
0168 ## add background
0169 for bg_file in "${bg_files[@]}"; do
0170     # Extract the filename from the remote path
0171     filename=$(basename "$bg_file")
0172 
0173     # Check if the file exists locally
0174     if [ -f "$filename" ]; then
0175         echo "File '$filename' already exists locally."
0176     else
0177         echo "File '$filename' not found locally. Downloading..."
0178         # Use xrdcp to download the file
0179         xrdcp "$bg_file" "$filename"
0180 
0181         # Check if the download succeeded
0182         if [ $? -eq 0 ]; then
0183             echo "File '$filename' downloaded successfully."
0184         else
0185             echo "Failed to download file '$filename'."
0186             exit
0187         fi
0188     fi
0189 done
0190 
0191 length=${#bg_files[@]}
0192 
0193 # Loop over the arrays using an index
0194 for ((i=0; i<length; i++)); do
0195     filename=$(basename "${bg_files[i]}")
0196     cmd+=" -b $filename ${freqs[i]} 0 ${statuses[i]} "
0197 done
0198 
0199 # Print the final command
0200 echo "Generated command:"
0201 echo "$cmd"
0202 
0203 # Execute the command
0204 mkdir log
0205 mkdir merged
0206 
0207 eval "$cmd" >> log/$outfile.log
0208 
0209 echo "DONE! See output under log/ and merged/."
0210 echo Please add the following flags to your npsim command:
0211 echo       --physics.alternativeStableStatuses="2001 3001 4001 5001 6001"  --physics.alternativeDecayStatuses="2002 3002 4002 5002 6002"
0212 # ./SignalBackgroundMerger -i DIS_10x275_1.14kHz.hepmc -sf 0 -b proton_beamgas_275GeV_350kHz.hepmc3.tree.root 350 0 2000 -b electron_beamgas_10GeV_3177kHz.hepmc3.tree.root 3177 0 4000 -b synrad_18x275_14000kHz.hepmc.tree.root 14000 0 6000 -o test_new.hepmc -N 100 --rngSeed 42