ATLAS Offline Software
LArFCalSamplingFractionG4AtlasConfig.py
Go to the documentation of this file.
1 #!/usr/bin/env athena.py
2 
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #
5 # This CA configuration script replaces the previously used legacy script for simulating sampling fractions
6 #
7 
8 import sys
9 
10 from AthenaConfiguration.AllConfigFlags import initConfigFlags
11 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
12 from AthenaConfiguration.ComponentFactory import CompFactory
13 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
14 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
15 
16 # Common parameters
17 module = "fcal1" # Choose from "fcal1", "fcal2" or "fcal3"
18 
19 
20 def FCalParticleGunCfg(flags):
21  acc = ComponentAccumulator()
22 
23  # Import paticle gun
24  import ParticleGun as PG
25 
26  pg = PG.ParticleGun(randomStream = "SINGLE", randomSeed = flags.Random.SeedOffset)
27 
28  # Setting particle gun specifications
29  pg.sampler.pid = 11
30  pg.sampler.mom = PG.EEtaMPhiSampler(energy=params['pg_E'], eta=params['pg_eta'])
31  pg.sampler.pos = PG.PosSampler(x=params['pg_x'], y=params['pg_y'], z=params['pg_z'], t=params['pg_z'])
32 
33  acc.addEventAlgo(pg)
34 
35  return acc
36 
37 
38 def LArFCalSamplingFractionConfig(flags, name="LArFCalSamplingFraction", **kwargs):
39  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
40  acc = LArGMCfg(flags)
41  acc.addEventAlgo(CompFactory.LArFCalSamplingFraction(name=name, **kwargs))
42 
43  return acc
44 
45 
46 # Iniitialize flags
47 flags = initConfigFlags()
48 
49 # FCal module distances
50 fcal1_z, fcal2_z, fcal3_z = 4713.5, 5173.3, 5647.8
51 
52 # Seetting parameters
53 params = {
54  'n_event': 200, # Number of events to simulate
55  'pg_E': 40000, # Particle gun energy [MeV]
56  'pg_x': [212.5, 277.5], # Particle gun x-coordinate; constant or range
57  'pg_y': [7.5, 72.5], # Particle gun y-coordinate; constant or range
58  'pg_z': None, # Particle gun z-coordinate (distance to IP); should be constant
59  'pg_eta': None, # Particle gun eta; constant or range
60 }
61 
62 # Check which module is chosen
63 if module.lower() == "fcal1":
64  params['pg_z'] = fcal1_z
65  params['pg_eta'] = [3.5, 3.8]
66 elif module.lower() == "fcal2":
67  params['pg_z'] = fcal2_z
68  params['pg_eta'] = [3.5, 3.8]
69 elif module.lower() == "fcal3":
70  params['pg_z'] = fcal3_z
71  params['pg_eta'] = [3.5, 3.8]
72 
73 # Setting important flags for the simulation
74 flags.Sim.WorldRRange = 15000.
75 flags.Sim.WorldZRange = 27000.
76 flags.IOVDb.GlobalTag = "OFLCOND-MC16-SDR-16"
77 flags.GeoModel.AtlasVersion = 'ATLAS-R2-2016-01-00-01'
78 flags.Output.HITSFileName = "atlasG4.hits.pool.root"
79 
80 # Detector flags - disabling/enabling relevant subsystems
81 flags.Detector.GeometryCalo = True
82 flags.Detector.EnableCalo = True
83 flags.Detector.GeometryID = False
84 flags.Detector.EnableID = False
85 flags.Detector.GeometryID = False
86 flags.Detector.EnableID = False
87 flags.Detector.GeometryLucid = False
88 flags.Detector.EnableLucid = False
89 
90 # Disable input file
91 flags.Input.Files = []
92 
93 # Lock the flags to prevent further changes
94 flags.lock()
95 
96 # Main CA
97 acc = MainServicesCfg(flags)
98 
99 # Merge with particle gun
100 acc.merge(FCalParticleGunCfg(flags))
101 
102 # Merge with sampling algorithm
103 acc.merge(LArFCalSamplingFractionConfig(flags))
104 
105 # Output service for ROOT file
106 acc.merge(OutputStreamCfg(flags, "HITS"))
107 
108 # Adding HIST output
109 acc.addService(CompFactory.THistSvc(name="THistSvc", Output=[ "AANT DATAFILE='LArFCalSamplingFraction.{}.{:g}GeV.aan.root' OPT='RECREATE'".format(module, params['pg_E']/1000) ]))
110 
111 # Print and run the accumulator
112 acc.printConfig(withDetails=True)
113 
114 # Finalize
115 acc.run()
116 sys.exit( acc.run().isFailure() )
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
vtune_athena.format
format
Definition: vtune_athena.py:14
python.OutputStreamConfig.OutputStreamCfg
def OutputStreamCfg(flags, streamName, ItemList=[], MetadataItemList=[], disableEventTag=False, trigNavThinningSvc=None, takeItemsFromInput=False, extendProvenanceRecord=True, AcceptAlgs=[], HelperTools=[])
Definition: OutputStreamConfig.py:12
LArFCalSamplingFractionG4AtlasConfig.LArFCalSamplingFractionConfig
def LArFCalSamplingFractionConfig(flags, name="LArFCalSamplingFraction", **kwargs)
Definition: LArFCalSamplingFractionG4AtlasConfig.py:38
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
LArFCalSamplingFractionG4AtlasConfig.FCalParticleGunCfg
def FCalParticleGunCfg(flags)
Definition: LArFCalSamplingFractionG4AtlasConfig.py:20