diff --git a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_PG_muon_fasernu_logE-101302.json b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_PG_muon_fasernu_logE-101302.json index 8ae524dc0453e65117e33137ce2ddb081226887f..76ba19e1146b9107c3365cc5c5dd867ff26e6c94 100644 --- a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_PG_muon_fasernu_logE-101302.json +++ b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_PG_muon_fasernu_logE-101302.json @@ -9,5 +9,5 @@ "sampler": "log", "segment": 0, "short": "MDC_PG_muon_fasernu_logE", - "zpos": -5000.0 + "zpos": -4000.0 } diff --git a/Control/CalypsoExample/Generation/scripts/faserMDC_foresee.py b/Control/CalypsoExample/Generation/scripts/faserMDC_foresee.py index 607ce904658f777b0403a5b452b58b4160f66b0e..b48bbf861ed4bbac6e0a6fb6cc9fd95da5049138 100755 --- a/Control/CalypsoExample/Generation/scripts/faserMDC_foresee.py +++ b/Control/CalypsoExample/Generation/scripts/faserMDC_foresee.py @@ -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 # diff --git a/Control/CalypsoExample/Generation/scripts/faserMDC_particlegun.py b/Control/CalypsoExample/Generation/scripts/faserMDC_particlegun.py index c9f9154ef986e4216e07a38f0114f8bd1511b230..20970fdf37f5fb28f102949e5ef35cd1372f193c 100755 --- a/Control/CalypsoExample/Generation/scripts/faserMDC_particlegun.py +++ b/Control/CalypsoExample/Generation/scripts/faserMDC_particlegun.py @@ -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 # diff --git a/Control/CalypsoExample/Reconstruction/scripts/faserMDC_reco.py b/Control/CalypsoExample/Reconstruction/scripts/faserMDC_reco.py index f9003eeceda4528ce2a7af132971c5e1e5447cd2..942340f12c97db7e80850e0ede3be55d44bda54d 100755 --- a/Control/CalypsoExample/Reconstruction/scripts/faserMDC_reco.py +++ b/Control/CalypsoExample/Reconstruction/scripts/faserMDC_reco.py @@ -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)) diff --git a/Control/CalypsoExample/Reconstruction/scripts/submit_faserMDC_reco.sh b/Control/CalypsoExample/Reconstruction/scripts/submit_faserMDC_reco.sh index 60c39ca370330fcad5432523d33740722b754a8f..b04d56aa9d13f3bac39f02213e0f47625714c689 100755 --- a/Control/CalypsoExample/Reconstruction/scripts/submit_faserMDC_reco.sh +++ b/Control/CalypsoExample/Reconstruction/scripts/submit_faserMDC_reco.sh @@ -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" diff --git a/Control/CalypsoExample/Simulation/scripts/faserMDC_simulate.py b/Control/CalypsoExample/Simulation/scripts/faserMDC_simulate.py index 323adda69d9228ecdbde65431b09bf42a579745d..12de492f4070237b59dda273673b994bbc275d37 100755 --- a/Control/CalypsoExample/Simulation/scripts/faserMDC_simulate.py +++ b/Control/CalypsoExample/Simulation/scripts/faserMDC_simulate.py @@ -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) diff --git a/Control/CalypsoExample/Simulation/scripts/submit_faserMDC_simulate.sh b/Control/CalypsoExample/Simulation/scripts/submit_faserMDC_simulate.sh index e00adfd50005e3d3600a7a5df55a45039f89e391..3c175d72519eda6d9f973c84ea3c2b1af00b7dba 100755 --- a/Control/CalypsoExample/Simulation/scripts/submit_faserMDC_simulate.sh +++ b/Control/CalypsoExample/Simulation/scripts/submit_faserMDC_simulate.sh @@ -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 diff --git a/Generators/FaserParticleGun/python/RadialPosSampler.py b/Generators/FaserParticleGun/python/RadialPosSampler.py index dd599bf846d4d00380a045ed9a543123d48c8405..7f1ed179960acfc80c04609ad6971fc21844bf85 100644 --- a/Generators/FaserParticleGun/python/RadialPosSampler.py +++ b/Generators/FaserParticleGun/python/RadialPosSampler.py @@ -89,4 +89,3 @@ if __name__ == "__main__": plt.hist(np.sqrt(xarr**2 + yarr**2)) plt.tight_layout() plt.show() -x diff --git a/Generators/HEPMCReader/python/HepMCReaderConfig.py b/Generators/HEPMCReader/python/HepMCReaderConfig.py index bb116c11cab3f9f8da6ac3cfe51ac50b783509e6..affee04ea519250ba08f5c32c4b6596a3422fab6 100644 --- a/Generators/HEPMCReader/python/HepMCReaderConfig.py +++ b/Generators/HEPMCReader/python/HepMCReaderConfig.py @@ -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 diff --git a/Simulation/G4Faser/G4FaserAlg/test/G4FaserAlgConfigNew_Test.py b/Simulation/G4Faser/G4FaserAlg/test/G4FaserAlgConfigNew_Test.py old mode 100644 new mode 100755