Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 09:44:41

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 
0051 # Read user input
0052 read -p "Enter option number (1-5): " option
0053 if   [[ "$option" == "1" ]]; then
0054     ebeam=18
0055     pbeam=275
0056     tag=""
0057     signal="pythia8NCDIS_18x275_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1.hepmc"
0058     bg_files=(
0059         # "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
0060         "dataprod_rel_1.0.0_synrad_18x275_run001.preproc_10000repeats.hepmc3.tree.root" ## new SR with outer beampipe photons only, freq=3.3GHz
0061         "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"
0062         "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"
0063         "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"
0064         "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"
0065     )
0066     freqs=(3300000 18.26 0.86 0.55 22.5) ## kHz
0067     statuses=(2000 3000 4000 5000 6000)
0068 
0069 elif [[ "$option" == "2" ]]; then
0070     ebeam=18
0071     pbeam=275
0072     tag="_noSR_"
0073     signal="pythia8NCDIS_18x275_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1.hepmc"
0074     bg_files=(
0075         "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"
0076         "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"
0077         "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"
0078         "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"
0079     )
0080     freqs=(18.26 0.86 0.55 22.5) ## kHz
0081     statuses=(3000 4000 5000 6000)
0082 
0083 elif [[ "$option" == "3" ]]; then
0084     ebeam=18
0085     pbeam=275
0086     tag="_minbias_"
0087     signal="pythia_ep_noradcor_18x275_q2_0.000000001_1.0_run1.ab.hepmc3.tree.root"
0088     bg_files=(
0089         "dataprod_rel_1.0.0_synrad_18x275_run001.preproc_10000repeats.hepmc3.tree.root" ## new SR with outer beampipe photons only, freq=3.3GHz
0090         "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"
0091         "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"
0092         "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"
0093         "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"
0094     )
0095     freqs=(3300000 18.26 0.86 0.55 22.5) ## kHz
0096     statuses=(2000 3000 4000 5000 6000)
0097 
0098 elif [[ "$option" == "4" ]]; then
0099     ebeam=10
0100     pbeam=275
0101     tag="_scaled_SR_"
0102     signal="pythia8NCDIS_10x275_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1.hepmc"
0103 
0104     bg_files=(
0105     "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"
0106     "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"
0107     "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"
0108     "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"
0109     "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"
0110     )
0111 
0112     freqs=(36608000 172.31 29.56 233.50 32.6) ## kHz
0113     statuses=(2000 3000 4000 5000 6000)
0114 
0115 elif [[ "$option" == "5" ]]; then
0116     ebeam=5
0117     pbeam=100
0118     tag="_scaled_SR_"
0119     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"
0120     bg_files=(
0121     "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"
0122     "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"
0123     "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"
0124     "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"
0125     "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"
0126     )
0127     statuses=(2000 3000 4000 5000 6000) ## kHz
0128     freqs=(36608000 328.04 116.57 1112.3 22)
0129 else
0130     echo "Invalid option selected."
0131     exit 1
0132 fi
0133 
0134 ## ------------------------------------------------
0135 ## assemble command
0136 ## ------------------------------------------------
0137 outfile=bgmerged_${sig_type}_${ebeam}x${pbeam}${tag}n${nev}.hepmc
0138 cmd="./SignalBackgroundMerger  -N ${nev} --rngSeed ${seed} -o merged/${outfile}"
0139 
0140 ## add signal
0141 if [ "$sf" -ge 0 ]; then ## use DIS signal file
0142     cmd+=" -i $signal -sf $sf -S $nskip -w $window"
0143 else ## use the default from the merger which is the sidis sample
0144 # /volatile/eic/EPIC/EVGEN/SIDIS/pythia6-eic/1.0.0/18x275/q2_0to1/
0145     cmd+=" -i pythia_ep_noradcor_18x275_q2_0.000000001_1.0_run1.ab.hepmc3.tree.root -sf 83 "
0146 fi
0147 
0148 ## add background
0149 for bg_file in "${bg_files[@]}"; do
0150     # Extract the filename from the remote path
0151     filename=$(basename "$bg_file")
0152 
0153     # Check if the file exists locally
0154     if [ -f "$filename" ]; then
0155         echo "File '$filename' already exists locally."
0156     else
0157         echo "File '$filename' not found locally. Downloading..."
0158         # Use xrdcp to download the file
0159         xrdcp "$bg_file" "$filename"
0160 
0161         # Check if the download succeeded
0162         if [ $? -eq 0 ]; then
0163             echo "File '$filename' downloaded successfully."
0164         else
0165             echo "Failed to download file '$filename'."
0166             exit
0167         fi
0168     fi
0169 done
0170 
0171 length=${#bg_files[@]}
0172 
0173 # Loop over the arrays using an index
0174 for ((i=0; i<length; i++)); do
0175     filename=$(basename "${bg_files[i]}")
0176     cmd+=" -b $filename ${freqs[i]} 0 ${statuses[i]} "
0177 done
0178 
0179 # Print the final command
0180 echo "Generated command:"
0181 echo "$cmd"
0182 
0183 # Execute the command
0184 mkdir log
0185 mkdir merged
0186 
0187 eval "$cmd" >> log/$outfile.log
0188 
0189 echo "DONE! See output under log/ and merged/."
0190 echo Please add the following flags to your npsim command:
0191 echo       --physics.alternativeStableStatuses="2001 3001 4001 5001 6001"  --physics.alternativeDecayStatuses="2002 3002 4002 5002 6002"
0192 # ./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