diff --git a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_100MeV_1Em5-110001.json b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_100MeV_1Em5-110001.json index 68af1b5c19fc3f1e6f79e5de2f31a927cc766f4b..782dda26b0ebb02c6553cfeed61daf0bfd59c563 100644 --- a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_100MeV_1Em5-110001.json +++ b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_100MeV_1Em5-110001.json @@ -10,5 +10,5 @@ -11, 11 ], - "mass": 0.511 + "mass": 100.0 } diff --git a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_10MeV_1Em4-110003.json b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_10MeV_1Em4-110003.json index 9abe2bce8b4383e0a7eafb235e4b8e4529cd57d2..41326579b17bf5befc48f03423749770b12e8a68 100644 --- a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_10MeV_1Em4-110003.json +++ b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_10MeV_1Em4-110003.json @@ -10,5 +10,5 @@ -11, 11 ], - "mass": 0.511 + "mass": 10.0 } diff --git a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_10MeV_1Em5-110002.json b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_10MeV_1Em5-110002.json index d91f21e93823e37dcc72c97094383cf740c7c96b..112a4e79f625481e9524b6ac04d939d618a3171f 100644 --- a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_10MeV_1Em5-110002.json +++ b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Aee_10MeV_1Em5-110002.json @@ -10,5 +10,5 @@ -11, 11 ], - "mass": 0.511 + "mass": 10.0 } diff --git a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_100MeV_1Em4-110007.json b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_100MeV_1Em4-110007.json index f255067359c539cbd9abbf6945871ca7d4e35712..044d1840123099f44b7f208f0a0d95e52717ff2e 100644 --- a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_100MeV_1Em4-110007.json +++ b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_100MeV_1Em4-110007.json @@ -10,5 +10,5 @@ 22, 22 ], - "mass": 0.0 + "mass": 100.0 } diff --git a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_10MeV_1Em2-110006.json b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_10MeV_1Em2-110006.json index 40f6f97ba55c5c715fa4164e90193f81f01de228..7d4d8496ec2270679c8e41f082083057723dfaa9 100644 --- a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_10MeV_1Em2-110006.json +++ b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_10MeV_1Em2-110006.json @@ -10,5 +10,5 @@ 22, 22 ], - "mass": 0.0 + "mass": 10.0 } diff --git a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_10MeV_1Em4-110005.json b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_10MeV_1Em4-110005.json index fe3131b47fabc77e30a6f1b94c538a130efdbfef..6bdc7701c5c18ea683f4311d90ada6440a94c693 100644 --- a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_10MeV_1Em4-110005.json +++ b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Alp_10MeV_1Em4-110005.json @@ -10,5 +10,5 @@ 22, 22 ], - "mass": 0.0 + "mass": 10.0 } diff --git a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Amm_316MeV_2Em6-110004.json b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Amm_316MeV_2Em6-110004.json index 7f62ae1fade37e822f824b57970c23e8b33d32ce..d4e9bf1c6b154d39e240f4e094bf648a593613bd 100644 --- a/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Amm_316MeV_2Em6-110004.json +++ b/Control/CalypsoExample/Generation/data/mdc/FaserMC-MDC_FS_Amm_316MeV_2Em6-110004.json @@ -10,5 +10,5 @@ -13, 13 ], - "mass": 105.66 + "mass": 316.2 } diff --git a/Control/CalypsoExample/Generation/scripts/faserMDC_foresee.py b/Control/CalypsoExample/Generation/scripts/faserMDC_foresee.py index 50c8131c19a28fd605457bedeaa39d5dfd3c8bf9..9579e2cf5432a5210fe365ecd5e08ba10ad3d643 100755 --- a/Control/CalypsoExample/Generation/scripts/faserMDC_foresee.py +++ b/Control/CalypsoExample/Generation/scripts/faserMDC_foresee.py @@ -95,8 +95,7 @@ if __name__ == '__main__': # String seeding doesn't work for numpy, make integer by hashing instead import hashlib - # Note args.pid is a list - # For ParticleGun to accept this, we need to turn it into a set... + # Note the mother mass here is in GeV for some reason import ParticleGun as PG ConfigFlags.Sim.Gun = { "Generator" : "Foresee", @@ -104,7 +103,7 @@ if __name__ == '__main__': "model_name" : args.model, "daughter1_pid" : args.pid[0], "daughter2_pid" : args.pid[1], - "mass" : args.mass, + "mother_mass" : args.mass/1000., "randomSeed" : int(hashlib.sha512(args.outfile.encode()).hexdigest(), 16) } # Note the nominal z position is -3.75m, which is a bit upstream of vetoNu diff --git a/Control/CalypsoExample/Simulation/CMakeLists.txt b/Control/CalypsoExample/Simulation/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..440e12c8c1df89217ed1e7df9b3c7314ff4303d4 --- /dev/null +++ b/Control/CalypsoExample/Simulation/CMakeLists.txt @@ -0,0 +1,12 @@ +################################################################################ +# Package: Simulation +################################################################################ + +# Declare the package name: +atlas_subdir( Simulation ) + +# Install files from the package: +atlas_install_python_modules( python/*.py ) +atlas_install_scripts( scripts/*.sh scripts/*.py ) + + diff --git a/Control/CalypsoExample/Simulation/python/__init__.py b/Control/CalypsoExample/Simulation/python/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..1019c31f8428bc651bbfdb56065098ecc35f870c --- /dev/null +++ b/Control/CalypsoExample/Simulation/python/__init__.py @@ -0,0 +1 @@ +# Simulation.py diff --git a/Control/CalypsoExample/Simulation/scripts/faserMDC_simulate.py b/Control/CalypsoExample/Simulation/scripts/faserMDC_simulate.py new file mode 100755 index 0000000000000000000000000000000000000000..0c93b9fe6191dff44c1db47a38a747653f8d7bc4 --- /dev/null +++ b/Control/CalypsoExample/Simulation/scripts/faserMDC_simulate.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python +""" +Produce simulated hits from input 4-vectors +Derived from G4FaserAlgConfigNew + +Usage: +faserMDC_simulate.py filepath + +filepath - full path, including url if needed, to the input 4-vector file + +Copyright (C) 2002-2021 CERN for the benefit of the ATLAS and FASER collaborations +""" + +if __name__ == '__main__': + + import sys + import time + a = time.time() +# +# Parse command-line options +# + import sys + import argparse + + parser = argparse.ArgumentParser(description="Run FASER simulation") + + parser.add_argument("file_path", + help="Fully qualified path of the raw input file") + + parser.add_argument("-t", "--tag", default="", + help="Specify sim tag (to append to output filename)") + parser.add_argument("-n", "--nevents", type=int, default=-1, + help="Specify number of events to process (default: all)") + parser.add_argument("-v", "--verbose", action='store_true', + help="Turn on DEBUG output") + + args = parser.parse_args() + + from pathlib import Path + + filepath = Path(args.file_path) + +# +# Parse input file +# + print(f"Starting digitization of {filepath.name}") + + filestem = filepath.stem + if len(args.tag) > 0: + filestem += f"-{args.tag}" + + outfile = f"{filestem}-HITS.root" + runnumber = 123456 # To be improved... + segment = 0 + + print(f"Outfile: {outfile}") + +# +# Figure out events to run +# + if args.nevents > 0: + print(f"Reconstructing {args.nevents} events by command-line option") +# +# Set up logging and config behaviour +# + from AthenaCommon.Logging import log + from AthenaCommon.Constants import DEBUG, VERBOSE + from AthenaCommon.Configurable import Configurable + log.setLevel(DEBUG) + Configurable.configurableRun3Behavior = 1 +# +# Import and set config flags +# + from CalypsoConfiguration.AllConfigFlags import ConfigFlags + from AthenaConfiguration.Enums import ProductionStep + ConfigFlags.Common.ProductionStep = ProductionStep.Simulation +# +# All these must be specified to avoid auto-configuration +# + ConfigFlags.Input.RunNumber = [runnumber] #Isn't updating - todo: investigate + ConfigFlags.Input.OverrideRunNumber = True + ConfigFlags.Input.LumiBlockNumber = [(segment+1)] + ConfigFlags.Input.isMC = True +# +# Input file name +# + # Path mangles // in url, so use direct file_path here + ConfigFlags.Input.Files = args.file_path +# +# Output file name +# + ConfigFlags.Output.HITSFileName = outfile +# +# Sim ConfigFlags +# + ConfigFlags.Sim.Layout = "FASER" + ConfigFlags.Sim.PhysicsList = "FTFP_BERT" + ConfigFlags.Sim.ReleaseGeoModel = False + ConfigFlags.Sim.IncludeParentsInG4Event = True # Controls whether BeamTruthEvent is written to output HITS file + + ConfigFlags.addFlag("Sim.Beam.xangle", 0) # Potential beam crossing angles + ConfigFlags.addFlag("Sim.Beam.yangle", 0) + + ConfigFlags.GeoModel.FaserVersion = "FASERNU-02" # Geometry set-up + ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-02" # Conditions set-up + ConfigFlags.addFlag("Input.InitialTimeStamp", 0) # To avoid autoconfig + ConfigFlags.GeoModel.Align.Dynamic = False + + # import sys + # ConfigFlags.fillFromArgs(sys.argv[1:]) + +# +# MDC geometry configuration +# + detectors = ['Veto', 'Preshower', 'FaserSCT', 'Ecal', 'Trigger', 'Dipole', 'Emulsion'] +# +# Setup detector flags +# + from CalypsoConfiguration.DetectorConfigFlags import setupDetectorsFromList + setupDetectorsFromList(ConfigFlags, detectors, toggle_geometry=True) +# +# Finalize flags +# + ConfigFlags.lock() +# +# Initialize a new component accumulator +# + from CalypsoConfiguration.MainServicesConfig import MainServicesCfg + cfg = MainServicesCfg(ConfigFlags) + +# +# Check whether a known input file was specified +# + if ConfigFlags.Input.Files[0].endswith(".events") or ConfigFlags.Input.Files[0].endswith(".hepmc"): + + from HEPMCReader.HepMCReaderConfig import HepMCReaderCfg + cfg.merge(HepMCReaderCfg(ConfigFlags)) + + from McEventSelector.McEventSelectorConfig import McEventSelectorCfg + cfg.merge(McEventSelectorCfg(ConfigFlags)) +# +# Else, set up to read it as a pool.root file +# + else: + from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg + cfg.merge(PoolReadCfg(ConfigFlags)) + +# +# Output file +# + from AthenaPoolCnvSvc.PoolWriteConfig import PoolWriteCfg + cfg.merge(PoolWriteCfg(ConfigFlags)) + +# +# Shift LOS +# + + if ConfigFlags.Sim.Beam.xangle or ConfigFlags.Sim.Beam.yangle: + MCEventKey = "BeamTruthEventShifted" + import McParticleEvent.Pythonizations + from GeneratorUtils.ShiftLOSConfig import ShiftLOSCfg + cfg.merge(ShiftLOSCfg(ConfigFlags, OutputMCEventKey = MCEventKey, + xcross = ConfigFlags.Sim.Beam.xangle, ycross = ConfigFlags.Sim.Beam.yangle)) + else: + MCEventKey = "BeamTruthEvent" + +# +# Add the G4FaserAlg +# + from G4FaserAlg.G4FaserAlgConfigNew import G4FaserAlgCfg + cfg.merge(G4FaserAlgCfg(ConfigFlags, InputTruthCollection = MCEventKey)) +# +# Dump config +# + from AthenaConfiguration.ComponentFactory import CompFactory + cfg.addEventAlgo(CompFactory.JobOptsDumperAlg(FileName="G4FaserTestConfig.txt")) + cfg.getService("StoreGateSvc").Dump = True + cfg.getService("ConditionStore").Dump = True + cfg.printConfig(withDetails=True, summariseProps = False) # gags on ParticleGun if summariseProps = True? + + ConfigFlags.dump() + #f = open("test.pkl","wb") + #cfg.store(f) + #f.close() +# +# Execute and finish +# + + if args.verbose: + cfg.foreach_component("*").OutputLevel = "DEBUG" + else: + cfg.foreach_component("*").OutputLevel = "INFO" + + sc = cfg.run(maxEvents=args.nevents) + + b = time.time() + log.info("Run G4FaserAlg in " + str(b-a) + " seconds") +# +# Success should be 0 +# + sys.exit(not sc.isSuccess()) +