diff --git a/MCwrapper/MakeMC.csh b/MCwrapper/MakeMC.csh index 3d3f3d9d..543fedbe 100755 --- a/MCwrapper/MakeMC.csh +++ b/MCwrapper/MakeMC.csh @@ -58,21 +58,23 @@ setenv NUMTHREADS 1 endif # PRINT INPUTS +echo "CONTEXT = $JANA_CALIB_CONTEXT" echo "ENVIRONMENT = $ENVIRONMENT" echo "CONFIG_FILE = $CONFIG_FILE" echo "OUTDIR = $OUTDIR" echo "RUN_NUMBER = $RUN_NUMBER" echo "FILE_NUMBER = $FILE_NUMBER" echo "NUM TO GEN = $EVT_TO_GEN" -echo "generator = $GENERATOR" +echo "generator = $GENERATOR" echo "generation = $GENR $CLEANGENR" -echo "Geant = $GEANT $CLEANGEANT" -echo "GCONTROL = $CUSTOM_GCONTROL" -echo "BKG_FOLD = $BKGFOLDSTR" -echo "MCsmear = $SMEAR $CLEANSMEAR" -echo "Recon = $RECON $CLEANRECON" +echo "Geant = $GEANT $CLEANGEANT" +echo "GCONTROL = $CUSTOM_GCONTROL" +echo "BKG_FOLD = $BKGFOLDSTR" +echo "MCsmear = $SMEAR $CLEANSMEAR" +echo "Recon = $RECON $CLEANRECON" echo "detected c-shell" + #printenv #necessary to run swif, uses local directory if swif=0 is used if ("$MCSWIF" == "1") then @@ -91,6 +93,25 @@ else cp $CUSTOM_GCONTROL/Gcontrol.in ./ endif + +@ length_count = `echo $RUN_NUMBER | wc -c` - 1 + +set formatted_runNumber="" +while ( $length_count < 6 ) +set formatted_runNumber = "0""$formatted_runNumber" +@ length_count = $length_count + 1 +end +set formatted_runNumber=$formatted_runNumber$RUN_NUMBER + +@ flength_count = `echo $FILE_NUMBER | wc -c` - 1 + +set formatted_fileNumber="" +while ( $flength_count < 3 ) +set formatted_fileNumber = "0""$formatted_fileNumber" +@ flength_count = $flength_count + 1 +end +set formatted_fileNumber=$formatted_fileNumber$FILE_NUMBER + if ("$GENR" != "0") then if ("$GENERATOR" != "genr8" && "$GENERATOR" != "bggen" && "$GENERATOR" != "genEtaRegge" && "$GENERATOR" != "gen_2pi_amp" && "$GENERATOR" != "gen_pi0" && "$GENERATOR" != "gen_2pi_primakoff" ) then echo "NO VALID GENERATOR GIVEN" @@ -107,13 +128,13 @@ if ("$GENR" != "0") then if ("$GENERATOR" == "genr8") then echo "configuring genr8" - cp $CONFIG_FILE ./genr8\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + cp $CONFIG_FILE ./genr8\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf else if ("$GENERATOR" == "bggen") then echo "configuring bggen" cp $MCWRAPPER_CENTRAL/Generators/bggen/particle.dat ./ cp $MCWRAPPER_CENTRAL/Generators/bggen/pythia.dat ./ cp $MCWRAPPER_CENTRAL/Generators/bggen/pythia-geant.map ./ - cp $CONFIG_FILE ./bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + cp $CONFIG_FILE ./bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf if ( `echo $eBEAM_ENERGY | grep -o "\." | wc -l` == 0) then set eBEAM_ENERGY = $eBEAM_ENERGY\. endif @@ -129,129 +150,161 @@ if ("$GENR" != "0") then else if ("$GENERATOR" == "genEtaRegge") then echo "configuring genEtaRegge" - cp $CONFIG_FILE ./genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + cp $CONFIG_FILE ./genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf else if ("$GENERATOR" == "gen_2pi_amp") then echo "configuring gen_2pi_amp" - cp $CONFIG_FILE ./gen_2pi_amp\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + cp $CONFIG_FILE ./gen_2pi_amp\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf else if ("$GENERATOR" == "gen_2pi_primakoff") then echo "configuring gen_2pi_primakoff" - cp $CONFIG_FILE ./gen_2pi_primakoff\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + cp $CONFIG_FILE ./gen_2pi_primakoff\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf else if ("$GENERATOR" == "gen_pi0") then echo "configuring gen_pi0" - cp $CONFIG_FILE ./gen_pi0\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + cp $CONFIG_FILE ./gen_pi0\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf endif set config_file_name=`basename "$CONFIG_FILE"` echo $config_file_name if ("$GENERATOR" == "genr8") then echo "RUNNING GENR8" - set RUNNUM = $RUN_NUMBER+$FILE_NUMBER - sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' genr8\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + set RUNNUM = $formatted_runNumber+$formatted_fileNumber + sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' genr8\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf # RUN genr8 and convert - genr8 -r$RUN_NUMBER -M$EVT_TO_GEN -A$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.ascii < genr8\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf #$config_file_name - genr8_2_hddm $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.ascii + genr8 -r$formatted_runNumber -M$EVT_TO_GEN -A$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.ascii < genr8\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf #$config_file_name + genr8_2_hddm $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.ascii else if ("$GENERATOR" == "bggen") then set colsize=`rcnd $RUN_NUMBER collimator_diameter | awk '{print $1}' | sed -r 's/.{2}$//' | sed -e 's/\.//g'` - if ("$colsize" == "B" || "$colsize" == "R" ) then + if ("$colsize" == "B" || "$colsize" == "R" || "$JANA_CALIB_CONTEXT" != "variation=mc") then set colsize = "34" endif set RANDOM=$$ echo $RANDOM - sed -i 's/TEMPTRIG/'$EVT_TO_GEN'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPRUNNO/'$RUN_NUMBER'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPCOLD/'0.00$colsize'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPRAND/'$RANDOM'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPMINGENE/'$GEN_MIN_ENERGY'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPMAXGENE/'$GEN_MAX_ENERGY'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + sed -i 's/TEMPTRIG/'$EVT_TO_GEN'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPRUNNO/'$RUN_NUMBER'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPCOLD/'0.00$colsize'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPRAND/'$RANDOM'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPMINGENE/'$GEN_MIN_ENERGY'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPMAXGENE/'$GEN_MAX_ENERGY'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf - ln -s bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf fort.15 + ln -s bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf fort.15 bggen - mv bggen.hddm $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm + mv bggen.hddm $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm else if ("$GENERATOR" == "genEtaRegge") then echo "RUNNING GENETAREGGE" set colsize=`rcnd $RUN_NUMBER collimator_diameter | awk '{print $1}' | sed -r 's/.{2}$//' | sed -e 's/\.//g'` - if ("$colsize" == "B" || "$colsize" == "R" ) then + if ("$colsize" == "B" || "$colsize" == "R" || "$JANA_CALIB_CONTEXT" != "variation=mc") then set colsize = "34" endif - sed -i 's/TEMPCOLD/'0.00$colsize'/' genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPMINGENE/'$GEN_MIN_ENERGY'/' genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPMAXGENE/'$GEN_MAX_ENERGY'/' genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - genEtaRegge -N$EVT_TO_GEN -O$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -I'genEtaRegge'\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + sed -i 's/TEMPCOLD/'0.00$colsize'/' genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPMINGENE/'$GEN_MIN_ENERGY'/' genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPMAXGENE/'$GEN_MAX_ENERGY'/' genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + genEtaRegge -N$EVT_TO_GEN -O$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -I'genEtaRegge'\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf else if ("$GENERATOR" == "gen_2pi_amp") then echo "RUNNING GEN_2PI_AMP" set optionals_line = `head -n 1 $config_file_name | sed -r 's/.//'` echo $optionals_line - echo gen_2pi_amp -c gen_2pi_amp\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf -o $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -hd $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY $optionals_line - gen_2pi_amp -c gen_2pi_amp\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf -hd $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -o $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY - b $GEN_MAX_ENERGY $optionals_line + echo gen_2pi_amp -c gen_2pi_amp\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf -o $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -hd $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY $optionals_line + gen_2pi_amp -c gen_2pi_amp\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf -hd $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -o $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY - b $GEN_MAX_ENERGY $optionals_line else if ("$GENERATOR" == "gen_2pi_primakoff") then echo "RUNNING GEN_2PI_PRIMAKOFF" set optionals_line = `head -n 1 $config_file_name | sed -r 's/.//'` echo $optionals_line - echo gen_2pi_primakoff -c gen_2pi_primakoff\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf -o $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -hd $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY $optionals_line - gen_2pi_primakoff -c gen_2pi_primakoff\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf -hd $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -o $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY - b $GEN_MAX_ENERGY $optionals_line + echo gen_2pi_primakoff -c gen_2pi_primakoff\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf -o $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -hd $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY $optionals_line + gen_2pi_primakoff -c gen_2pi_primakoff\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf -hd $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -o $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY - b $GEN_MAX_ENERGY $optionals_line else if ("$GENERATOR" == "gen_pi0") then echo "RUNNING GEN_PI0" set optionals_line = `head -n 1 $config_file_name | sed -r 's/.//'` echo $optionals_line - gen_pi0 -c gen_pi0\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf -hd $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -o $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY -p $COHERENT_PEAK -s $FILE_NUMBER $optionals_line -m $eBEAM_ENERGY + gen_pi0 -c gen_pi0\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf -hd $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -o $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY -p $COHERENT_PEAK -s $formatted_fileNumber $optionals_line -m $eBEAM_ENERGY endif #GEANT/smearing -#modify TEMPIN/TEMPOUT/TEMPTRIG/TOSMEAR in control.in - if ("$GEANT" != "0") then - echo "RUNNING GEANT"$GEANTVER - set colsize=`rcnd $RUN_NUMBER collimator_diameter | awk '{print $1}' | sed -r 's/.{2}$//' | sed -e 's/\.//g'` - if ("$colsize" == "B" || "$colsize" == "R" ) then - set colsize = "34" - endif + if ("$GEANT" != "0") then + echo "RUNNING GEANT"$GEANTVER + set colsize=`rcnd $RUN_NUMBER collimator_diameter | awk '{print $1}' | sed -r 's/.{2}$//' | sed -e 's/\.//g'` + if ("$colsize" == "B" || "$colsize" == "R" || "$JANA_CALIB_CONTEXT" != "variation=mc") then + set colsize = "34" + endif - if ( `echo $eBEAM_ENERGY | grep -o "\." | wc -l` == 0) then - set eBEAM_ENERGY = $eBEAM_ENERGY\. - endif - if ( `echo $COHERENT_PEAK | grep -o "\." | wc -l` == 0) then - set COHERENT_PEAK = $COHERENT_PEAK\. - endif + if ( `echo $eBEAM_ENERGY | grep -o "\." | wc -l` == 0) then + set eBEAM_ENERGY = $eBEAM_ENERGY\. + endif + if ( `echo $COHERENT_PEAK | grep -o "\." | wc -l` == 0) then + set COHERENT_PEAK = $COHERENT_PEAK\. + endif + + set inputfile=$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber + cp Gcontrol.in $PWD/control'_'$formatted_runNumber'_'$formatted_fileNumber.in + chmod 777 $PWD/control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPIN/'$inputfile.hddm'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPRUNG/'$RUN_NUMBER'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPOUT/'$inputfile'_geant.hddm/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPTRIG/'$EVT_TO_GEN'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPCOLD/'0.00$colsize'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + + if ( "$BKGFOLDSTR" != "BeamPhotons" ) then + echo "removing Beam Photon background from geant simulation" + sed -i 's/BGRATE/cBGRATE/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/BGGATE/cBGGATE/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + endif - set inputfile=$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER - cp Gcontrol.in $PWD/control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - chmod 777 $PWD/control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPIN/'$inputfile.hddm'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPRUNG/'$RUN_NUMBER'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPOUT/'$inputfile'_geant.hddm/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPTRIG/'$EVT_TO_GEN'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - #sed -i 's/TOSMEAR/'$SMEAR'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPCOLD/'0.00$colsize'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - mv $PWD/control'_'$RUN_NUMBER'_'$FILE_NUMBER.in $PWD/control.in + mv $PWD/control'_'$formatted_runNumber'_'$formatted_fileNumber.in $PWD/control.in - if ("$GEANTVER" == "3") then - hdgeant - else if ("$GEANTVER" == "4") then - #make run.mac then call it below - rm -f run.mac - echo "/run/beamOn $EVT_TO_GEN" > run.mac - echo "exit" >>! run.mac - hdgeant4 -t$NUMTHREADS run.mac - rm run.mac - else - echo "INVALID GEANT VERSION" - exit - endif + if ("$GEANTVER" == "3") then + hdgeant + else if ("$GEANTVER" == "4") then + #make run.mac then call it below + rm -f run.mac + echo "/run/beamOn $EVT_TO_GEN" > run.mac + echo "exit" >>! run.mac + hdgeant4 -t$NUMTHREADS run.mac + rm run.mac + else + echo "INVALID GEANT VERSION" + exit + endif if ("$SMEAR" != "0") then echo "RUNNING MCSMEAR" - if ("$BKGFOLDSTR" == "0") then - mcsmear -o$inputfile'_geant_smeared.hddm' $inputfile'_geant.hddm' + if ("$BKGFOLDSTR" == "BeamPhotons" || "$BKGFOLDSTR" == "None") then + echo "running MCsmear without folding in random background" + mcsmear -o$inputfile'_geant_smeared.hddm' $inputfile'_geant.hddm' else - echo 'mcsmear -o'$inputfile'_geant_smeared.hddm'' '$inputfile'_geant.hddm'' '$BKGFOLDSTR - mcsmear -o$inputfile'_geant_smeared.hddm' $inputfile'_geant.hddm' $BKGFOLDSTR + if("$BKGFOLDSTR" == "DEFAULT") then + #find file and run:1 + echo "Finding the right file to fold in" + set runperiod="RunPeriod-2017-01" + + if ( $RUN_NUMBER > 40000) then + #set runperiod="RunPeriod-2017-10" + endif + + if ( $RUN_NUMBER < 30000 ) then + echo "Warning: random triggers did not exist by this point" + endif + set bkglocstring="/cache/halld/""$runperiod""/sim/random_triggers/""$formatted_runNumber"".hddm" + #set bkglocstring="/w/halld-scifs1a/home/tbritton/converted.hddm" + + if (! -f $bkglocstring) then + echo "Could not find mix-in file "$bkglocstring + exit + else + echo "mcsmear -o$inputfile"\_"geant"\_"smeared.hddm $inputfile"\_"geant.hddm $bkglocstring"\:"1" + mcsmear -o$inputfile\_geant\_smeared.hddm $inputfile\_geant.hddm $bkglocstring\:1 + endif + + else + #trust the user and use their string + echo 'mcsmear -o'$inputfile'_geant_smeared.hddm'' '$inputfile'_geant.hddm'' '$BKGFOLDSTR + mcsmear -o$inputfile'_geant_smeared.hddm' $inputfile'_geant.hddm' $BKGFOLDSTR + endif endif #run reconstruction if ("$CLEANGENR" == "1") then @@ -264,14 +317,14 @@ if ("$GENR" != "0") then unlink fort.15 endif - rm $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm + rm $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm endif if ("$RECON" != "0") then echo "RUNNING RECONSTRUCTION" hd_root $inputfile'_geant_smeared.hddm' -PPLUGINS=danarest,monitoring_hists -PNTHREADS=$NUMTHREADS - mv hd_root.root hd_root_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root - mv dana_rest.hddm dana_rest_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm + mv hd_root.root hd_root_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root + mv dana_rest.hddm dana_rest_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm if ("$CLEANGEANT" == "1") then rm *_geant.hddm diff --git a/MCwrapper/MakeMC.sh b/MCwrapper/MakeMC.sh index 36951846..69af911f 100755 --- a/MCwrapper/MakeMC.sh +++ b/MCwrapper/MakeMC.sh @@ -1,6 +1,6 @@ #!/bin/bash -# SET INPUTS +# INPUTS export ENVIRONMENT=$1 shift export CONFIG_FILE=$1 @@ -15,7 +15,7 @@ export FILE_NUMBER=$1 shift export EVT_TO_GEN=$1 shift -export JANA_CALIB_CONTEXT "variation="$1 +export JANA_CALIB_CONTEXT="variation="$1 shift export GENR=$1 shift @@ -54,239 +54,294 @@ shift export GEN_MAX_ENERGY=$1 if [[ "$GEANTVER" == "3" ]]; then - export NUMTHREADS=1 +export NUMTHREADS 1 fi # PRINT INPUTS +echo "CONTEXT = $JANA_CALIB_CONTEXT" echo "ENVIRONMENT = $ENVIRONMENT" echo "CONFIG_FILE = $CONFIG_FILE" echo "OUTDIR = $OUTDIR" echo "RUN_NUMBER = $RUN_NUMBER" echo "FILE_NUMBER = $FILE_NUMBER" echo "NUM TO GEN = $EVT_TO_GEN" -echo "generator = $GENERATOR" +echo "generator = $GENERATOR" echo "generation = $GENR $CLEANGENR" -echo "Geant = $GEANT $CLEANGEANT" -echo "GCONTROL = $CUSTOM_GCONTROL" -echo "BKG_FOLD = $BKGFOLDSTR" -echo "MCsmear = $SMEAR $CLEANSMEAR" -echo "Recon = $RECON $CLEANRECON" +echo "Geant = $GEANT $CLEANGEANT" +echo "GCONTROL = $CUSTOM_GCONTROL" +echo "BKG_FOLD = $BKGFOLDSTR" +echo "MCsmear = $SMEAR $CLEANSMEAR" +echo "Recon = $RECON $CLEANRECON" echo "detected bash" + #printenv #necessary to run swif, uses local directory if swif=0 is used -if [[ "$MCSWIF" -eq "1" ]]; then - # ENVIRONMENT - echo $ENVIRONMENT - source $ENVIRONMENT - echo pwd=$PWD - mkdir -p $OUTDIR - mkdir -p $OUTDIR/log +if [[ "$MCSWIF" == "1" ]]; then +# ENVIRONMENT +echo $ENVIRONMENT +source $ENVIRONMENT +echo pwd=$PWD +mkdir -p $OUTDIR +mkdir -p $OUTDIR/log fi -if [[ "$CUSTOM_GCONTROL" -eq "0" ]]; then - cp $MCWRAPPER_CENTRAL/Gcontrol.in ./ - chmod 777 ./Gcontrol.in +if [[ "$CUSTOM_GCONTROL" == "0" ]]; then +cp $MCWRAPPER_CENTRAL/Gcontrol.in ./ +chmod 777 ./Gcontrol.in else - cp $CUSTOM_GCONTROL/Gcontrol.in ./ +cp $CUSTOM_GCONTROL/Gcontrol.in ./ fi + +length_count=$((`echo $RUN_NUMBER | wc -c` - 1)) + +formatted_runNumber="" +while [ $length_count -lt 6 ]; do +formatted_runNumber="0""$formatted_runNumber" +length_count=$(($length_count + 1)) +done + +formatted_runNumber=$formatted_runNumber$RUN_NUMBER +flength_count=$((`echo $FILE_NUMBER | wc -c` - 1)) + +formatted_fileNumber="" +while [ $flength_count -lt 3 ]; do +formatted_fileNumber="0""$formatted_fileNumber" +flength_count=$(($flength_count + 1)) +done + +formatted_fileNumber=$formatted_fileNumber$FILE_NUMBER + if [[ "$GENR" != "0" ]]; then if [[ "$GENERATOR" != "genr8" && "$GENERATOR" != "bggen" && "$GENERATOR" != "genEtaRegge" && "$GENERATOR" != "gen_2pi_amp" && "$GENERATOR" != "gen_pi0" && "$GENERATOR" != "gen_2pi_primakoff" ]]; then echo "NO VALID GENERATOR GIVEN" echo "only [genr8, bggen, genEtaRegge, gen_2pi_amp, gen_pi0] are supported" exit fi - + if [[ -f $CONFIG_FILE ]]; then - echo " input file found" - else - echo $CONFIG_FILE" does not exist" - exit + echo " input file found" + else + echo $CONFIG_FILE" does not exist" + exit fi - - if [[ "$GENERATOR" -eq "genr8" ]]; then + + if [[ "$GENERATOR" == "genr8" ]]; then echo "configuring genr8" - cp $CONFIG_FILE ./genr8\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - elif [[ "$GENERATOR" -eq "bggen" ]]; then + cp $CONFIG_FILE ./genr8\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + elif [[ "$GENERATOR" == "bggen" ]]; then echo "configuring bggen" cp $MCWRAPPER_CENTRAL/Generators/bggen/particle.dat ./ cp $MCWRAPPER_CENTRAL/Generators/bggen/pythia.dat ./ cp $MCWRAPPER_CENTRAL/Generators/bggen/pythia-geant.map ./ - cp $CONFIG_FILE ./bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - if [[ `echo $eBEAM_ENERGY | grep -o "\." | wc -l` -eq 0 ]]; then + cp $CONFIG_FILE ./bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + if [[ `echo $eBEAM_ENERGY | grep -o "\." | wc -l` == 0 ]]; then eBEAM_ENERGY=$eBEAM_ENERGY\. fi - if [[ `echo $COHERENT_PEAK | grep -o "\." | wc -l` -eq 0 ]]; then + if [[ `echo $COHERENT_PEAK | grep -o "\." | wc -l` == 0 ]]; then COHERENT_PEAK=$COHERENT_PEAK\. fi - if [[ `echo $GEN_MIN_ENERGY | grep -o "\." | wc -l` -eq 0 ]]; then + if [[ `echo $GEN_MIN_ENERGY | grep -o "\." | wc -l` == 0 ]]; then GEN_MIN_ENERGY=$GEN_MIN_ENERGY\. fi - if [[ `echo $GEN_MAX_ENERGY | grep -o "\." | wc -l` -eq 0 ]]; then + if [[ `echo $GEN_MAX_ENERGY | grep -o "\." | wc -l` == 0 ]]; then GEN_MAX_ENERGY=$GEN_MAX_ENERGY\. fi - elif [[ "$GENERATOR" -eq "genEtaRegge" ]]; then + elif [[ "$GENERATOR" == "genEtaRegge" ]]; then echo "configuring genEtaRegge" - cp $CONFIG_FILE ./genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - elif [[ "$GENERATOR" -eq "gen_2pi_amp" ]]; then + cp $CONFIG_FILE ./genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + elif [[ "$GENERATOR" == "gen_2pi_amp" ]]; then echo "configuring gen_2pi_amp" - cp $CONFIG_FILE ./gen_2pi_amp\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - elif [[ "$GENERATOR" -eq "gen_2pi_primakoff" ]]; then + cp $CONFIG_FILE ./gen_2pi_amp\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + elif [[ "$GENERATOR" == "gen_2pi_primakoff" ]]; then echo "configuring gen_2pi_primakoff" - cp $CONFIG_FILE ./gen_2pi_primakoff\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - elif [[ "$GENERATOR" -eq "gen_pi0" ]]; then + cp $CONFIG_FILE ./gen_2pi_primakoff\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + elif [[ "$GENERATOR" == "gen_pi0" ]]; then echo "configuring gen_pi0" - cp $CONFIG_FILE ./gen_pi0\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + cp $CONFIG_FILE ./gen_pi0\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf fi config_file_name=`basename "$CONFIG_FILE"` echo $config_file_name - if [[ "$GENERATOR" -eq "genr8" ]]; then + if [[ "$GENERATOR" == "genr8" ]]; then echo "RUNNING GENR8" - RUNNUM=$RUN_NUMBER+$FILE_NUMBER - sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' genr8\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + RUNNUM=$formatted_runNumber+$formatted_fileNumber + sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' genr8\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf # RUN genr8 and convert - genr8 -r$RUN_NUMBER -M$EVT_TO_GEN -A$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.ascii < genr8\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf #$config_file_name - genr8_2_hddm $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.ascii - elif [[ "$GENERATOR" -eq "bggen" ]]; then + genr8 -r$formatted_runNumber -M$EVT_TO_GEN -A$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.ascii < genr8\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf #$config_file_name + genr8_2_hddm $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.ascii + elif [[ "$GENERATOR" == "bggen" ]]; then colsize=`rcnd $RUN_NUMBER collimator_diameter | awk '{print $1}' | sed -r 's/.{2}$//' | sed -e 's/\.//g'` - if [[ "$colsize" -eq "B" || "$colsize" -eq "R" ]]; then - colsize="34" + if [[ "$colsize" == "B" || "$colsize" == "R" || "$JANA_CALIB_CONTEXT" != "variation=mc" ]]; then + colsize="34" fi RANDOM=$$ echo $RANDOM - sed -i 's/TEMPTRIG/'$EVT_TO_GEN'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPRUNNO/'$RUN_NUMBER'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPCOLD/'0.00$colsize'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPRAND/'$RANDOM'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPMINGENE/'$GEN_MIN_ENERGY'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPMAXGENE/'$GEN_MAX_ENERGY'/' bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf + sed -i 's/TEMPTRIG/'$EVT_TO_GEN'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPRUNNO/'$RUN_NUMBER'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPCOLD/'0.00$colsize'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPRAND/'$RANDOM'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPMINGENE/'$GEN_MIN_ENERGY'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPMAXGENE/'$GEN_MAX_ENERGY'/' bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf - ln -s bggen\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf fort.15 + ln -s bggen\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf fort.15 bggen - mv bggen.hddm $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm - elif [[ "$GENERATOR" -eq "genEtaRegge" ]]; then + mv bggen.hddm $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm + elif [[ "$GENERATOR" == "genEtaRegge" ]]; then echo "RUNNING GENETAREGGE" colsize=`rcnd $RUN_NUMBER collimator_diameter | awk '{print $1}' | sed -r 's/.{2}$//' | sed -e 's/\.//g'` - if [[ "$colsize" -eq "B" || "$colsize" -eq "R" ]]; then - colsize="34" + if [[ "$colsize" == "B" || "$colsize" == "R" || "$JANA_CALIB_CONTEXT" != "variation=mc" ]]; then + colsize="34" fi - sed -i 's/TEMPCOLD/'0.00$colsize'/' genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPMINGENE/'$GEN_MIN_ENERGY'/' genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - sed -i 's/TEMPMAXGENE/'$GEN_MAX_ENERGY'/' genEtaRegge\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - genEtaRegge -N$EVT_TO_GEN -O$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -I'genEtaRegge'\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf - elif [[ "$GENERATOR" -eq "gen_2pi_amp" ]]; then + sed -i 's/TEMPCOLD/'0.00$colsize'/' genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPMINGENE/'$GEN_MIN_ENERGY'/' genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + sed -i 's/TEMPMAXGENE/'$GEN_MAX_ENERGY'/' genEtaRegge\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + genEtaRegge -N$EVT_TO_GEN -O$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -I'genEtaRegge'\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf + elif [[ "$GENERATOR" == "gen_2pi_amp" ]]; then echo "RUNNING GEN_2PI_AMP" optionals_line=`head -n 1 $config_file_name | sed -r 's/.//'` echo $optionals_line - echo gen_2pi_amp -c gen_2pi_amp\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf -o $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -hd $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY $optionals_line - gen_2pi_amp -c gen_2pi_amp\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf -hd $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -o $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY - b $GEN_MAX_ENERGY $optionals_line - elif [[ "$GENERATOR" -eq "gen_2pi_primakoff" ]]; then + echo gen_2pi_amp -c gen_2pi_amp\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf -o $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -hd $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY $optionals_line + gen_2pi_amp -c gen_2pi_amp\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf -hd $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -o $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY - b $GEN_MAX_ENERGY $optionals_line + elif [[ "$GENERATOR" == "gen_2pi_primakoff" ]]; then echo "RUNNING GEN_2PI_PRIMAKOFF" optionals_line=`head -n 1 $config_file_name | sed -r 's/.//'` echo $optionals_line - echo gen_2pi_primakoff -c gen_2pi_primakoff\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf -o $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -hd $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY $optionals_line - gen_2pi_primakoff -c gen_2pi_primakoff\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf -hd $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -o $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY - b $GEN_MAX_ENERGY $optionals_line - elif [[ "$GENERATOR" -eq "gen_pi0" ]]; then + echo gen_2pi_primakoff -c gen_2pi_primakoff\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf -o $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -hd $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY $optionals_line + gen_2pi_primakoff -c gen_2pi_primakoff\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf -hd $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -o $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY - b $GEN_MAX_ENERGY $optionals_line + elif [[ "$GENERATOR" == "gen_pi0" ]]; then echo "RUNNING GEN_PI0" optionals_line=`head -n 1 $config_file_name | sed -r 's/.//'` echo $optionals_line - gen_pi0 -c gen_pi0\_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.conf -hd $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm -o $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY -p $COHERENT_PEAK -s $FILE_NUMBER $optionals_line -m $eBEAM_ENERGY + gen_pi0 -c gen_pi0\_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.conf -hd $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm -o $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root -n $EVT_TO_GEN -r $RUN_NUMBER -a $GEN_MIN_ENERGY -b $GEN_MAX_ENERGY -p $COHERENT_PEAK -s $formatted_fileNumber $optionals_line -m $eBEAM_ENERGY fi - - #GEANT/smearing - #modify TEMPIN/TEMPOUT/TEMPTRIG/TOSMEAR in control.in - - if [[ "$GEANT" != "0" ]]; then - echo "RUNNING GEANT"$GEANTVER - colsize=`rcnd $RUN_NUMBER collimator_diameter | awk '{print $1}' | sed -r 's/.{2}$//' | sed -e 's/\.//g'` - if [[ "$colsize" -eq "B" || "$colsize" -eq "R" ]]; then - colsize="34" - fi - if [[ `echo $eBEAM_ENERGY | grep -o "\." | wc -l` -eq 0 ]]; then - eBEAM_ENERGY=$eBEAM_ENERGY\. - fi - if [[ `echo $COHERENT_PEAK | grep -o "\." | wc -l` -eq 0 ]]; then - COHERENT_PEAK=$COHERENT_PEAK\. - fi - - inputfile=$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER - cp Gcontrol.in $PWD/control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - chmod 777 $PWD/control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPIN/'$inputfile.hddm'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPRUNG/'$RUN_NUMBER'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPOUT/'$inputfile'_geant.hddm/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPTRIG/'$EVT_TO_GEN'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - #sed -i 's/TOSMEAR/'$SMEAR'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - sed -i 's/TEMPCOLD/'0.00$colsize'/' control'_'$RUN_NUMBER'_'$FILE_NUMBER.in - mv $PWD/control'_'$RUN_NUMBER'_'$FILE_NUMBER.in $PWD/control.in +#GEANT/smearing + + if [[ "$GEANT" != "0" ]]; then + echo "RUNNING GEANT"$GEANTVER + colsize=`rcnd $RUN_NUMBER collimator_diameter | awk '{print $1}' | sed -r 's/.{2}$//' | sed -e 's/\.//g'` + if [[ "$colsize" == "B" || "$colsize" == "R" || "$JANA_CALIB_CONTEXT" != "variation=mc" ]]; then + colsize="34" + fi + + if [[ `echo $eBEAM_ENERGY | grep -o "\." | wc -l` == 0 ]]; then + eBEAM_ENERGY=$eBEAM_ENERGY\. + fi + if [[ `echo $COHERENT_PEAK | grep -o "\." | wc -l` == 0 ]]; then + COHERENT_PEAK=$COHERENT_PEAK\. + fi + + inputfile=$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber + cp Gcontrol.in $PWD/control'_'$formatted_runNumber'_'$formatted_fileNumber.in + chmod 777 $PWD/control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPELECE/'$eBEAM_ENERGY'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPCOHERENT/'$COHERENT_PEAK'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPIN/'$inputfile.hddm'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPRUNG/'$RUN_NUMBER'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPOUT/'$inputfile'_geant.hddm/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPTRIG/'$EVT_TO_GEN'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/TEMPCOLD/'0.00$colsize'/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + + if [[ "$BKGFOLDSTR" != "BeamPhotons" ]]; then + echo "removing Beam Photon background from geant simulation" + sed -i 's/BGRATE/cBGRATE/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + sed -i 's/BGGATE/cBGGATE/' control'_'$formatted_runNumber'_'$formatted_fileNumber.in + fi + + mv $PWD/control'_'$formatted_runNumber'_'$formatted_fileNumber.in $PWD/control.in - if [[ "$GEANTVER" -eq "3" ]]; then - hdgeant - elif [[ "$GEANTVER" -eq "4" ]]; then - #make run.mac then call it below - rm -f run.mac - echo "/run/beamOn $EVT_TO_GEN" >run.mac - echo "exit" >>! run.mac - hdgeant4 -t$NUMTHREADS run.mac - rm run.mac - else - echo "INVALID GEANT VERSION" - exit - fi + if [[ "$GEANTVER" == "3" ]]; then + hdgeant + elif [[ "$GEANTVER" == "4" ]]; then + #make run.mac then call it below + rm -f run.mac + echo "/run/beamOn $EVT_TO_GEN" > run.mac + echo "exit" >>! run.mac + hdgeant4 -t$NUMTHREADS run.mac + rm run.mac + else + echo "INVALID GEANT VERSION" + exit + fi if [[ "$SMEAR" != "0" ]]; then echo "RUNNING MCSMEAR" - if [[ "$BKGFOLDSTR" -eq "0" ]]; then + if [[ "$BKGFOLDSTR" == "BeamPhotons" || "$BKGFOLDSTR" == "None" ]]; then + echo "running MCsmear without folding in random background" mcsmear -o$inputfile'_geant_smeared.hddm' $inputfile'_geant.hddm' else - echo 'mcsmear -o'$inputfile'_geant_smeared.hddm'' '$inputfile'_geant.hddm'' '$BKGFOLDSTR - mcsmear -o$inputfile'_geant_smeared.hddm' $inputfile'_geant.hddm' $BKGFOLDSTR + if [[ "$BKGFOLDSTR" == "DEFAULT" ]]; then + #find file and run:1 + echo "Finding the right file to fold in" + runperiod="RunPeriod-2017-01" + + if [[ $RUN_NUMBER -gt 40000 ]]; then + #runperiod="RunPeriod-2017-10" + echo + fi + + if [[ $RUN_NUMBER -lt 30000 ]]; then + echo "Warning: random triggers did not exist by this point" + fi + bkglocstring="/cache/halld/""$runperiod""/sim/random_triggers/""$formatted_runNumber"".hddm" + #bkglocstring="/w/halld-scifs1a/home/tbritton/converted.hddm" + + if [[! -f $bkglocstring]]; then + echo "Could not find mix-in file "$bkglocstring + exit + else + echo "mcsmear -o$inputfile"\_"geant"\_"smeared.hddm $inputfile"\_"geant.hddm $bkglocstring"\:"1" + mcsmear -o$inputfile\_geant\_smeared.hddm $inputfile\_geant.hddm $bkglocstring\:1 + fi + + else + #trust the user and use their string + echo 'mcsmear -o'$inputfile'_geant_smeared.hddm'' '$inputfile'_geant.hddm'' '$BKGFOLDSTR + mcsmear -o$inputfile'_geant_smeared.hddm' $inputfile'_geant.hddm' $BKGFOLDSTR + fi fi #run reconstruction - if [[ "$CLEANGENR" -eq "1" ]]; then - if [[ "$GENERATOR" -eq "genr8" ]]; then + if [[ "$CLEANGENR" == "1" ]]; then + if [[ "$GENERATOR" == "genr8" ]]; then rm *.ascii - elif [[ "$GENERATOR" -eq "bggen" ]]; then + elif [[ "$GENERATOR" == "bggen" ]]; then rm particle.dat rm pythia.dat rm pythia-geant.map unlink fort.15 fi - rm $GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm + rm $GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm fi if [[ "$RECON" != "0" ]]; then echo "RUNNING RECONSTRUCTION" hd_root $inputfile'_geant_smeared.hddm' -PPLUGINS=danarest,monitoring_hists -PNTHREADS=$NUMTHREADS - mv hd_root.root hd_root_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.root - mv dana_rest.hddm dana_rest_$GEN_NAME\_$RUN_NUMBER\_$FILE_NUMBER.hddm + mv hd_root.root hd_root_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.root + mv dana_rest.hddm dana_rest_$GEN_NAME\_$formatted_runNumber\_$formatted_fileNumber.hddm - if [[ "$CLEANGEANT" -eq "1" ]]; then - rm *_geant.hddm - if [[ "$PWD" != "$MCWRAPPER_CENTRAL" ]]; then - rm Gcontrol.in - fi + if [[ "$CLEANGEANT" == "1" ]]; then + rm *_geant.hddm + if [[ "$PWD" != "$MCWRAPPER_CENTRAL" ]]; then + rm Gcontrol.in + fi fi - if [[ "$CLEANSMEAR" -eq "1" ]]; then - rm *_smeared.hddm - rm smear.root + if [[ "$CLEANSMEAR" == "1" ]]; then + rm *_smeared.hddm + rm smear.root fi - if [[ "$CLEANRECON" -eq "1" ]]; then - rm dana_rest* + if [[ "$CLEANRECON" == "1" ]]; then + rm dana_rest* fi fi fi @@ -305,6 +360,6 @@ fi if [[ ! -d "$OUTDIR/root/" ]]; then mkdir $OUTDIR/root/ fi -mv $PWD/*.conf $OUTDIR/configurations/ -mv $PWD/*.hddm $OUTDIR/hddm/ -mv $PWD/*.root $OUTDIR/root/ + mv $PWD/*.conf $OUTDIR/configurations/ + mv $PWD/*.hddm $OUTDIR/hddm/ + mv $PWD/*.root $OUTDIR/root/ diff --git a/MCwrapper/examples/MC.config b/MCwrapper/examples/MC.config index 98559fd1..c80ac38c 100644 --- a/MCwrapper/examples/MC.config +++ b/MCwrapper/examples/MC.config @@ -6,6 +6,7 @@ # OUTPUT DATA LOCATION DATA_OUTPUT_BASE_DIR=OUTPUT-LOCATION#your desired output location +NCORES=4 # Number of CPU threads to use GENERATOR=generator-to-use GENERATOR_CONFIG=config file for generator @@ -17,8 +18,7 @@ GEN_MIN_ENERGY=4 GEN_MAX_ENERGY=12 GEANT_VERSION=4 -#BKG_FOLD=bg.hddm:1.8 #hook for future mcmear developments - +BKG=BeamPhotons #[None, BeamPhotons, DEFAULT, custom bg.hddm:1.8] #==================================================================================== #EVERYTHING BELOW FOR SWIF ONLY @@ -32,7 +32,6 @@ TRACK= simulation # https://scicomp.jlab.org/docs/batch_job_tracks ENVIRONMENT_FILE=your-environment-files#change this to your own environment file # RESOURCES for swif jobs -NCORES=4 # Number of CPU cores DISK=5GB # Max Disk usage RAM=5GB # Max RAM usage TIMELIMIT=300minutes # Max walltime diff --git a/MCwrapper/gluex_MC.py b/MCwrapper/gluex_MC.py index 8fc0103d..cce145a8 100755 --- a/MCwrapper/gluex_MC.py +++ b/MCwrapper/gluex_MC.py @@ -119,7 +119,7 @@ def main(argv): GEANTVER = 4 - BGFOLD="0" + BGFOLD="DEFAULT" @@ -216,7 +216,7 @@ def main(argv): CUSTOM_MAKEMC=rm_comments[0].strip() elif str(parts[0]).upper()=="CUSTOM_GCONTROL" : CUSTOM_GCONTROL=rm_comments[0].strip() - elif str(parts[0]).upper()=="BKG_FOLD" : + elif str(parts[0]).upper()=="BKG" : BGFOLD=rm_comments[0].strip() elif str(parts[0]).upper()=="eBEAM_ENERGY" : eBEAM_ENERGY=rm_comments[0].strip()