2from SimulationConfig.SimEnums
import BeamPipeSimMode, CalibrationRun, LArParameterization
62def enableNeutronRussianRoulette(flags):
63 """Activate Neutron Russian Roulette: Fast simulation" killing low energy neutrons with some probability."""
64 flags.Sim.NRRThreshold = 2. # MeV
65 flags.Sim.NRRWeight = 10.
66 flags.Sim.CalibrationRun = CalibrationRun.Off
85def enableG4GammaGeneralProcess(flags):
86 """Activate the G4GammaGeneralProcess and the UserAction required"""
87 flags.Sim.G4Commands+=["/process/em/UseGeneralProcess true"]
88 flags.Sim.OptionalUserActionList += ['G4UserActions.G4UserActionsConfig.FixG4CreatorProcessToolCfg']
91def disableG4GammaGeneralProcess(flags):
92 """Disables G4GammaGeneralProcess AND Woodcock tracking"""
93 commands = flags.Sim.G4Commands
94 commands.remove("/process/em/UseGeneralProcess true")
95 commands.remove("/process/em/useWoodcockTracking EMEC") # Woodcock tracking requires G4GammaGeneralProcess
96 flags.Sim.G4Commands = commands
97 optionalUserActions = flags.Sim.OptionalUserActionList
98 optionalUserActions.remove("G4UserActions.G4UserActionsConfig.FixG4CreatorProcessToolCfg")
99 flags.Sim.OptionalUserActionList = optionalUserActions
102def enableWoodcockTracking(flags):
103 """Activate the Woodcock Tracking in the EMEC"""
104 flags.Sim.G4Commands += ['/process/em/useWoodcockTracking EMEC']
105 # Please note that the Woodcock tracking enables the
106 # G4GammaGeneralProcess therefore the FixG4CreatorProcessTool must
107 # be added if it's not done before
108 if "G4UserActions.G4UserActionsConfig.FixG4CreatorProcessToolCfg" not in flags.Sim.OptionalUserActionList:
109 flags.Sim.OptionalUserActionList += ['G4UserActions.G4UserActionsConfig.FixG4CreatorProcessToolCfg']
112def disableWoodcockTracking(flags):
113 commands = flags.Sim.G4Commands
114 commands.remove("/process/em/useWoodcockTracking EMEC")
115 flags.Sim.G4Commands = commands
116 if "/process/em/UseGeneralProcess true" not in flags.Sim.G4Commands:
117 optionalUserActions = flags.Sim.OptionalUserActionList
118 optionalUserActions.remove("G4UserActions.G4UserActionsConfig.FixG4CreatorProcessToolCfg")
119 flags.Sim.OptionalUserActionList = optionalUserActions
122def enableG4Optimizations(flags):
123 """Enable G4 optimizations"""
125 # Activate magnetic field switch off in central LAr calorimeter
126 # More info: https://its.cern.ch/jira/browse/ATLPHYSVAL-773
127 enableMuonFieldOnlyInCalo(flags)
129 # Photon Russian Roulette
130 # "Fast simulation" killing low energy photons with some probability.
131 # More info: https://its.cern.ch/jira/browse/ATLASSIM-4096
132 enablePhotonRussianRoulette(flags)
134 # Neutron Russian Roulette
135 # "Fast simulation" killing low energy neutrons with some probability.
136 # More info: its.cern.ch/jira/browse/ATLASSIM-3924
137 enableNeutronRussianRoulette(flags)
140 # Turn on range cuts for gamma processes (conv, phot, compt)
141 # More info: https://its.cern.ch/jira/browse/ATLASSIM-3956
142 enableEMRangeCuts(flags)
144 # G4GammaGeneralProcess
145 # Activate the G4GammaGeneralProcess and the UserAction required
146 # to fix the creator process of secondary tracks.
147 enableG4GammaGeneralProcess(flags)
149 # Energy Loss fluctuation OFF
150 # Switch off the Energy loss fluctuation process
151 # More info: https://its.cern.ch/jira/browse/ATLASSIM-6995
152 # Main physics validation: https://its.cern.ch/jira/browse/ATLPHYSVAL-1009
153 # Follow-up validation for Muons: https://its.cern.ch/jira/browse/ATLPHYSVAL-1022
154 # Follow-up validation for Egamma: https://its.cern.ch/jira/browse/ATLPHYSVAL-1030
155 # This optimization is on hold for mc23e - for discrepancies seen in the
156 # follow-up validations by EgammaCP group.
157 # It will be evaluated for future campaigns.
158 # flags.Sim.G4Commands+=["/process/eLoss/fluct false"]
160 # Activate the Woodcock Tracking in the EMEC
161 # More info: https://its.cern.ch/jira/browse/ATLASSIM-5079
162 enableWoodcockTracking(flags)
165def disableG4Optimizations(flags):
166 """ Ensure all G4Optimizations are disabled - useful for debugging """
167 disableMuonFieldOnlyInCalo(flags)
168 disablePhotonRussianRoulette(flags)
169 disableNeutronRussianRoulette(flags)
170 disableEMRangeCuts(flags)
171 disableG4GammaGeneralProcess(flags)
172 disableWoodcockTracking(flags)
173 disableBeamPipeKill(flags)
174 disableFrozenShowersFCalOnly(flags)
175 disableMultipleStepsInMSCTransport(flags)
178def WoodcockTrackingInEMEC(flags):
179 # Use Woodcock Tracking in the EMEC rather than the EMECPara
180 # G4Region. This preInclude should be added at the end of the list
182 commands = flags.Sim.G4Commands
183 commands.remove("/process/em/useWoodcockTracking EMECPara")
184 flags.Sim.G4Commands = commands + ["/process/em/useWoodcockTracking EMEC"]
187def WoodcockTrackingInEMECPara(flags):
188 # Use Woodcock Tracking in the EMECPara rather than the EMEC
189 # G4Region. This preInclude should be added at the end of the list
191 commands = flags.Sim.G4Commands
192 commands.remove("/process/em/useWoodcockTracking EMEC")
193 flags.Sim.G4Commands = commands + ["/process/em/useWoodcockTracking EMECPara"]
196def PostIncludeTweakPhysicsRegionsCfg(flags, cfg):
197 # This postInclude drops BeamPipe::SectionF198 and
198 # BeamPipe::SectionF199 from the DeadMaterial G4Region, to avoid a
199 # clash with the BeampipeFwdCut G4Region.
200 from AthenaConfiguration.ComponentAccumulator import ConfigurationError
203 detConTool = cfg.getPublicTool('G4AtlasDetectorConstructionTool')
204 except ConfigurationError:
206 if detConTool is None:
208 detConTool.RegionCreators['DeadMaterialPhysicsRegionTool'].VolumeList.remove('BeamPipe::SectionF198')
209 detConTool.RegionCreators['DeadMaterialPhysicsRegionTool'].VolumeList.remove('BeamPipe::SectionF199')