Skip to content
Snippets Groups Projects
Commit cb51b400 authored by Carl Gwilliam's avatar Carl Gwilliam
Browse files

Merge

parent c5e058e7
No related branches found
No related tags found
2 merge requests!244Signal generation,!243Signal generation
Showing
with 98 additions and 43 deletions
......@@ -9,5 +9,5 @@
"sampler": "log",
"segment": 0,
"short": "MDC_PG_muon_fasernu_logE",
"zpos": -5000.0
"zpos": -4000.0
}
......@@ -113,6 +113,14 @@ if __name__ == '__main__':
#if args.zpos:
# ConfigFlags.Sim.Gun["z"] = args.zpos
doShiftLOS = (ConfigFlags.Sim.Beam.xangle or ConfigFlags.Sim.Beam.yangle or
ConfigFlags.Sim.Beam.xshift or ConfigFlags.Sim.Beam.yshift)
if doShiftLOS:
pgConfig = ConfigFlags.Sim.Gun
pgConfig["McEventKey"] = "BeamTruthEvent_ATLASCoord"
ConfigFlags.Sim.Gun = pgConfig
#
# MDC geometry configuration
#
......@@ -153,26 +161,22 @@ if __name__ == '__main__':
# Shift LOS
#
if (ConfigFlags.Sim.Beam.xangle or ConfigFlags.Sim.Beam.yangle or
ConfigFlags.Sim.Beam.xshift or ConfigFlags.Sim.Beam.yshift):
MCEventKey = "BeamTruthEventShifted"
if doShiftLOS:
import McParticleEvent.Pythonizations
from GeneratorUtils.ShiftLOSConfig import ShiftLOSCfg
cfg.merge(ShiftLOSCfg(ConfigFlags, OutputMCEventKey = MCEventKey,
cfg.merge(ShiftLOSCfg(ConfigFlags,
xcross = ConfigFlags.Sim.Beam.xangle,
ycross = ConfigFlags.Sim.Beam.yangle,
xshift = ConfigFlags.Sim.Beam.xshift,
yshift = ConfigFlags.Sim.Beam.yshift))
else:
MCEventKey = "BeamTruthEvent"
#
# Add the G4FaserAlg
#
from G4FaserAlg.G4FaserAlgConfigNew import G4FaserAlgCfg
cfg.merge(G4FaserAlgCfg(ConfigFlags, InputTruthCollection = MCEventKey))
cfg.merge(G4FaserAlgCfg(ConfigFlags))
#
# Dump config
#
......
......@@ -124,6 +124,14 @@ if __name__ == '__main__':
# Pass this in one go to ConfigFlags
ConfigFlags.Sim.Gun = sg_dict
doShiftLOS = (ConfigFlags.Sim.Beam.xangle or ConfigFlags.Sim.Beam.yangle or
ConfigFlags.Sim.Beam.xshift or ConfigFlags.Sim.Beam.yshift)
if doShiftLOS:
pgConfig = ConfigFlags.Sim.Gun
pgConfig["McEventKey"] = "BeamTruthEvent_ATLASCoord"
ConfigFlags.Sim.Gun = pgConfig
#
# MDC geometry configuration
#
......@@ -164,26 +172,22 @@ if __name__ == '__main__':
# Shift LOS
#
if (ConfigFlags.Sim.Beam.xangle or ConfigFlags.Sim.Beam.yangle or
ConfigFlags.Sim.Beam.xshift or ConfigFlags.Sim.Beam.yshift):
MCEventKey = "BeamTruthEventShifted"
if doShiftLOS:
import McParticleEvent.Pythonizations
from GeneratorUtils.ShiftLOSConfig import ShiftLOSCfg
cfg.merge(ShiftLOSCfg(ConfigFlags, OutputMCEventKey = MCEventKey,
cfg.merge(ShiftLOSCfg(ConfigFlags,
xcross = ConfigFlags.Sim.Beam.xangle,
ycross = ConfigFlags.Sim.Beam.yangle,
xshift = ConfigFlags.Sim.Beam.xshift,
yshift = ConfigFlags.Sim.Beam.yshift))
else:
MCEventKey = "BeamTruthEvent"
#
# Add the G4FaserAlg
#
from G4FaserAlg.G4FaserAlgConfigNew import G4FaserAlgCfg
cfg.merge(G4FaserAlgCfg(ConfigFlags, InputTruthCollection = MCEventKey))
cfg.merge(G4FaserAlgCfg(ConfigFlags))
#
# Dump config
#
......
......@@ -191,7 +191,7 @@ itemList = [ "xAOD::EventInfo#*"
#
if args.isMC:
# Add truth records here?
itemList.extend( ["McEventCollection#*"] )
itemList.extend( ["McEventCollection#*", "TrackerSimDataCollection#*"] )
acc.merge(OutputStreamCfg(ConfigFlags, "xAOD", itemList))
......
......@@ -124,7 +124,7 @@ fi
cd "$file_stem"
#
# Run job
if [[ -z "$rtag" ]]; then
if [[ -z "$tag" ]]; then
faserMDC_reco.py "--nevents=$nevents" "$file_path"
else
faserMDC_reco.py "--nevents=$nevents" "--reco=$tag" "$file_path"
......
......@@ -127,6 +127,7 @@ if __name__ == '__main__':
# Skip events
#
ConfigFlags.Exec.SkipEvents = args.skip
ConfigFlags.Exec.MaxEvents = args.nevents
#
# Output file name
#
......@@ -153,6 +154,9 @@ if __name__ == '__main__':
# import sys
# ConfigFlags.fillFromArgs(sys.argv[1:])
doShiftLOS = (ConfigFlags.Sim.Beam.xangle or ConfigFlags.Sim.Beam.yangle or
ConfigFlags.Sim.Beam.xshift or ConfigFlags.Sim.Beam.yshift)
#
# MDC geometry configuration
#
......@@ -178,7 +182,11 @@ if __name__ == '__main__':
if ConfigFlags.Input.Files[0].endswith(".events") or ConfigFlags.Input.Files[0].endswith(".hepmc"):
from HEPMCReader.HepMCReaderConfig import HepMCReaderCfg
cfg.merge(HepMCReaderCfg(ConfigFlags))
if doShiftLOS:
cfg.merge(HepMCReaderCfg(ConfigFlags, McEventKey = "BeamTruthEvent_ATLASCoord"))
else:
cfg.merge(HepMCReaderCfg(ConfigFlags))
from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
cfg.merge(McEventSelectorCfg(ConfigFlags))
......@@ -189,6 +197,11 @@ if __name__ == '__main__':
from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
cfg.merge(PoolReadCfg(ConfigFlags))
if doShiftLOS:
from SGComps.AddressRemappingConfig import InputOverwriteCfg
# Rename old truth collection to add ATLAS coord to can still use BeamTruthEvent for the one in FASER Coords
cfg.merge(InputOverwriteCfg("McEventCollection", "BeamTruthEvent", "McEventCollection", "BeamTruthEvent_ATLASCoord"))
#
# Output file
#
......@@ -198,26 +211,22 @@ if __name__ == '__main__':
#
# Shift LOS
#
if (ConfigFlags.Sim.Beam.xangle or ConfigFlags.Sim.Beam.yangle or
ConfigFlags.Sim.Beam.xshift or ConfigFlags.Sim.Beam.yshift):
if doShiftLOS:
MCEventKey = "BeamTruthEventShifted"
import McParticleEvent.Pythonizations
from GeneratorUtils.ShiftLOSConfig import ShiftLOSCfg
cfg.merge(ShiftLOSCfg(ConfigFlags, OutputMCEventKey = MCEventKey,
cfg.merge(ShiftLOSCfg(ConfigFlags,
xcross = ConfigFlags.Sim.Beam.xangle,
ycross = ConfigFlags.Sim.Beam.yangle,
xshift = ConfigFlags.Sim.Beam.xshift,
yshift = ConfigFlags.Sim.Beam.yshift))
else:
MCEventKey = "BeamTruthEvent"
#
# Add the G4FaserAlg
#
from G4FaserAlg.G4FaserAlgConfigNew import G4FaserAlgCfg
cfg.merge(G4FaserAlgCfg(ConfigFlags, InputTruthCollection = MCEventKey))
cfg.merge(G4FaserAlgCfg(ConfigFlags))
#
# Dump config
#
......@@ -235,10 +244,11 @@ if __name__ == '__main__':
# Execute and finish
#
if args.verbose:
cfg.foreach_component("*").OutputLevel = "DEBUG"
else:
cfg.foreach_component("*").OutputLevel = "INFO"
# This fails with ShiftLOSCfg...
#if args.verbose:
# cfg.foreach_component("*").OutputLevel = "DEBUG"
#else:
# cfg.foreach_component("*").OutputLevel = "INFO"
sc = cfg.run(maxEvents=args.nevents)
......
......@@ -2,7 +2,10 @@
# Used with a condor file to submit to vanilla universe
#
# Usage:
# submit_faserMDC_simluate.sh input_file output_file [release_directory] [working_directory] [skip] [nevts]
# submit_faserMDC_simluate.sh [--shift] input_file output_file [release_directory] [working_directory] [skip] [nevts]
#
# Options:
# --shift - apply crossing angle (and FASER shift)
#
# input_file - full file name (with path)
# output_file - full output file name
......@@ -22,6 +25,24 @@
SECONDS=0
#
# Parse command-line options
while [ -n "$1" ]
do
case "$1" in
-s | --shift)
echo "Applying crossing-angle shift"
xangle=1
shift;; # This 'eats' the argument
-*)
echo "Unknown option $1"
shift;;
*) break;; # Not an option, don't shift
esac
done
#
# Parse command-line arguments
infile=${1}
outfile=${2}
release_directory=${3}
......@@ -143,8 +164,11 @@ cd "${file_stem}"
# Run job
#if [[ -z "$tag" ]]; then
#fi
faserMDC_simulate.py --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
if [[ -z "$xangle" ]]; then
faserMDC_simulate.py --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
else
faserMDC_simulate.py --yangle -0.000150 --yshift 12.0 --skip "$skip_events" -n "$nevts" "$infile" "$outfile"
fi
#
# Print out ending time
date
......
......@@ -89,4 +89,3 @@ if __name__ == "__main__":
plt.hist(np.sqrt(xarr**2 + yarr**2))
plt.tight_layout()
plt.show()
x
......@@ -2,7 +2,7 @@
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
import sys, tempfile
import sys, tempfile, pathlib
from AthenaConfiguration.MainServicesConfig import AthSequencer
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
from AthenaConfiguration.ComponentFactory import CompFactory
......@@ -13,7 +13,8 @@ def get_file_skip_events(ConfigFlags):
"Create a file with events from ConfigFlags.Exec.SkipEvents to ConfigFlags.Exec.SkipEvents + ConfigFlags.Exec.MaxEvents"
usetemp = True
#usetemp = False
skip = ConfigFlags.Exec.SkipEvents
fname = ConfigFlags.Input.Files[0]
evtMax = ConfigFlags.Exec.MaxEvents
......@@ -21,12 +22,22 @@ def get_file_skip_events(ConfigFlags):
if skip == 0:
return fname
print(f"get_file_skip_events skipping {skip} events with max {evtMax}")
if usetemp:
fout = tempfile.NamedTemporaryFile("w", delete = False)
foutname = fout.name
else:
foutname, fext = ".".join(fname.split('.')[:-1]), fname.split('.')[-1]
foutname = f"{foutname}-evts{skip}-{skip+evtMax}.{fext}"
infile = pathlib.Path(fname)
# Put this in current working directory
if evtMax > 0:
end = skip+evtMax
else:
end = 'all'
foutname = f"{infile.stem}=evts{skip}-{end}.{infile.suffix}"
#foutname, fext = ".".join(fname.split('.')[:-1]), fname.split('.')[-1]
#foutname = f"{foutname}-evts{skip}-{skip+evtMax}{fext}"
fout = open(foutname, "w")
fout.write("HepMC::Version 2.06.09\nHepMC::IO_GenEvent-START_EVENT_LISTING\n")
......@@ -37,19 +48,22 @@ def get_file_skip_events(ConfigFlags):
if l.startswith("E "):
ievt += 1
if ievt > skip + evtMax:
break
if evtMax > 0 and ievt > skip + evtMax:
break
if ievt > skip:
#print(f"Writing event {ievt}")
fout.write(l)
# else:
# print(f"Skipping event {ievt}")
fout.write("HepMC::IO_GenEvent-END_EVENT_LISTING\n")
fout.close()
#print(f"Wrote to file {foutname}")
return foutname
def HepMCReaderCfg(ConfigFlags, **kwargs) :
cfg = ComponentAccumulator(AthSequencer("AthBeginSeq", Sequential = True))
from TruthIO.TruthIOConf import HepMCReadFromFile
......
File mode changed from 100644 to 100755
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment