Skip to content
Snippets Groups Projects
Commit ef3a2a77 authored by Eric Torrence's avatar Eric Torrence
Browse files

Merge branch 'mdc_reco' into 'master'

Mdc signal updates

See merge request faser/calypso!233
parents 87a24b38 a9eaf189
No related branches found
No related tags found
No related merge requests found
Showing
with 224 additions and 10 deletions
......@@ -10,5 +10,5 @@
-11,
11
],
"mass": 0.511
"mass": 100.0
}
......@@ -10,5 +10,5 @@
-11,
11
],
"mass": 0.511
"mass": 10.0
}
......@@ -10,5 +10,5 @@
-11,
11
],
"mass": 0.511
"mass": 10.0
}
......@@ -10,5 +10,5 @@
22,
22
],
"mass": 0.0
"mass": 100.0
}
......@@ -10,5 +10,5 @@
22,
22
],
"mass": 0.0
"mass": 10.0
}
......@@ -10,5 +10,5 @@
22,
22
],
"mass": 0.0
"mass": 10.0
}
......@@ -10,5 +10,5 @@
-13,
13
],
"mass": 105.66
"mass": 316.2
}
......@@ -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
......
################################################################################
# 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 )
# Simulation.py
#!/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())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment