3 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
11 log.info(f
'Running {title}:')
12 log.info(
' '.
join([f
'\'{o}\'' if ' ' in o
else o
for o
in cmd]))
15 subprocess.run(cmd, stdout=logFile, stderr=subprocess.STDOUT, text=
True, check=
True)
16 log.info(f
'Finished {title} successfully!')
17 except subprocess.CalledProcessError:
18 log.error(f
'Failed to run {title}!')
22 if __name__ ==
"__main__":
24 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
28 log = logging.getLogger(
'TileTB')
32 parser = flags.getArgumentParser(description=
'Run Tile TB simulation and digitization.')
34 simargs = parser.add_argument_group(
'Tile TB simulation')
35 simargs.add_argument(
'--runNumber', default=410000, help=
'Run number to simulate')
36 simargs.add_argument(
'--physics-list', default=
None, help=
'Override G4 physics list')
37 simargs.add_argument(
'--conditions-tag', default=
'OFLCOND-MC12-SDR-27', help=
'Conditions tag to use')
38 simargs.add_argument(
'--pid', default=11, help=
'Beam PID')
39 simargs.add_argument(
'--energy', default=100000, help=
'Beam energy in MeV')
40 simargs.add_argument(
'--eta', default=
None, help=
'Set eta only if you want eta-projective scan')
41 simargs.add_argument(
'--theta', default=
None, help=
'For 90 degrees scans put theta=+/-90. Positive theta - beam enters from positive eta side (as defined in CTB setup!)')
42 simargs.add_argument(
'--z', default=
None, help=
'Z coordinate is calculated along front face of module at R=2290, \
43 this is the distance from center of the modules to the desired impact point, positive value - impact point at positive eta side. \
44 For 90 degrees scans sensitive Z is from 2300 to 2300+3*100+3*130+3*150+2*190=3820')
45 simargs.add_argument(
'--y', default=
None, help=
'Put non-zero value here if you want beam above (>0) or below (<0) center')
46 simargs.add_argument(
'--phi', default=
None, help=
'Put 5.625 or -5.625 if you want to rotate table to up/bottom module')
47 simargs.add_argument(
'--layout', type=str, default=
'2B1EB', choices=[
'2B1EB',
'2B2EB',
'3B',
'5B'], help=
'TileCal standalone setup with 2 barrels and 1 extended barrel on top (2B1EB), \
48 2 barrels and 2 extended barrels on top (2B2EB), 3 barrels (3B), 5 barrels (5B) - use for sampling fraction calculation')
49 simargs.add_argument(
'--ushape', default=
None, help=
'Needed for the U-shape (any value of Ushape > 0 means that tile size equal to size of master plate, for Ushape <=0 - size of the tile is like in old geometry )')
50 simargs.add_argument(
'--steel', default=
None, help=
'Select steel with 0.45 percent Manganse for absorber instead of pure Iron. Any value > 0 enables Steel')
51 simargs.add_argument(
'--pvt', default=
None, help=
'Use PVT instead of PS for scintillator material. Any value > 0 enables PVT')
52 simargs.add_argument(
'--cstube', default=
None, help=
'Special option to enable Cs tubes in simulation. Any value > 0 enables them')
53 simargs.add_argument(
'--verbose-tracking', action=
'store_true', help=
'Use verbose G4 tracking')
54 simargs.add_argument(
'--calibration-run', action=
'store_true', help=
'Simulation with calibration hits')
55 simargs.add_argument(
'--delta-thit', default=
None, help=
'A time granularity for G4 hits in TileHit, \
56 it can be just one number, e.g. 5.0 which means that the same, granularity is used everywhere or it can be a vector which contains 3*N+1 elements, \
57 e.g. 0.1,-5,5, 0.5,-75,75, 5.0 which means that for [-5,5] ns interval granularity 0.1ns will be used for [-75,75] ns interval granularity 0.5ns will be used \
58 and 5ns granularity will be used for all other hits')
59 simargs.add_argument(
'--time-cut', default=
None, help=
'Time cut for hits, all hits go to one single time bin if time is above this cut ')
60 simargs.add_argument(
'--plate-to-cell', default=
None, help=
'Special flag for Calibration Hits. If true then Tile. Plates are the parts of the adjacent Tile cells. If false then they are Dead Materials')
61 simargs.add_argument(
'--do-tile-raw', default=
None, help=
'Enable energy per tile row in TileHit')
62 simargs.add_argument(
'--do-tof-correction', default=
None, help=
'Apply TOF correction (subtract Time Of Flight from ATLAS center')
63 simargs.add_argument(
'--do-birk', default=
None, help=
'Enable Birk\'s law')
64 simargs.add_argument(
'--old-birk', action=
'store_true', help=
'Use expected values from NIM 80 (1970) 239-244: birk1=0.0130 g/(MeV*cm^2), birk2=9.6e-6 (g/(MeV*cm^2))^2')
65 simargs.add_argument(
'--birk1', default=
None, help=
'Parameter for Birk\'s law')
66 simargs.add_argument(
'--birk2', default=
None, help=
'Parameter for Birk\'s law')
67 simargs.add_argument(
'--range-cut', default=
None, help=
'Set non-standard range cut')
68 simargs.add_argument(
'--vp1', action=
'store_true', help=
'Run VP1')
70 digargs = parser.add_argument_group(
'Tile TB digitization')
71 digargs.add_argument(
'--sfr-tag', default=
None, help=
'Override sampling fraction, fixed: TileOfl02CalibSfr-SIM-06, eta dependent: TileOfl02CalibSfr-SIM-07')
73 parser.set_defaults(evtMax=10)
74 args, _ = parser.parse_known_args()
76 layout = f
'tb_Tile2000_2003_{args.layout}'
77 filePrefix = f
'tiletb_pid{args.pid}_ene{args.energy}'
80 simulationFlags = [f
'flags.TestBeam.BeamPID={args.pid}',
81 f
'flags.TestBeam.BeamEnergy={args.energy}',
82 ' flags.TestBeam.Zbeam=[-20,20]',
83 ' flags.TestBeam.Ybeam=[-20,20]',
84 ' flags.TestBeam.Tbeam=[-31250,-23750]',
85 f
'flags.TestBeam.Layout="{layout}"']
88 filePrefix += f
'_eta{args.eta}'
89 simulationFlags += [f
'flags.TestBeam.Eta={args.eta}']
90 elif args.theta
and args.z:
91 filePrefix += f
'_z{args.z}_{args.theta}deg'
92 simulationFlags += [f
'flags.TestBeam.Theta={args.theta}', f
'flags.TestBeam.Z={args.z}']
94 log.error(
'The following arguments should be provided: --eta or (--theta and --z)!')
98 simulationFlags += [f
'flags.TestBeam.Y={args.y}']
100 simulationFlags += [f
'flags.TestBeam.Phi={args.phi}']
102 if args.verbose_tracking:
103 simulationFlags += [
'flags.Sim.G4Commands+=["/tracking/verbose 1"]']
104 if args.calibration_run:
105 simulationFlags += [
'from SimulationConfig.SimEnums import CalibrationRun; flags.Sim.CalibrationRun=CalibrationRun.Tile']
109 if any([args.ushape, args.steel, args.pvt, args.cstube, args.delta_thit, args.time_cut, args.plate_to_cell,
110 args.do_tile_raw, args.do_tof_correction, args.do_birk, args.old_birk, args.birk1, args.birk2]):
113 simulationFlags += [f
'flags.Tile.Sim.Ushape={args.ushape}']
115 simulationFlags += [f
'flags.Tile.Sim.Steel={args.steel}']
117 simulationFlags += [f
'flags.Tile.Sim.PVT={args.pvt}']
119 simulationFlags += [f
'flags.Tile.Sim.CsTube={args.cstube}']
121 simulationFlags += [f
'flags.Tile.Sim.DeltaTHit={args.delta_thit}']
123 simulationFlags += [f
'flags.Tile.Sim.TimeCut={args.time_cut}']
124 if args.plate_to_cell:
125 simulationFlags += [f
'flags.Tile.Sim.PlateToCell={args.plate_to_cell}']
127 simulationFlags += [f
'flags.Tile.Sim.DoTileRow={args.do_tile_raw}']
128 if args.do_tof_correction:
129 simulationFlags += [f
'flags.Tile.Sim.DoTOFCorrection={args.DoTOFCorrection}']
131 simulationFlags += [f
'flags.Tile.Sim.DoBirk={args.do_birk}']
133 simulationFlags += [f
'flags.Tile.Sim.OldBirk={args.old_birk}']
135 simulationFlags += [f
'flags.Tile.Sim.birk1={args.birk1}']
137 simulationFlags += [f
'flags.Tile.Sim.birk2={args.birk2}']
140 simulationPreExec =
'; '.
join(simulationFlags)
143 simulationPostExec =
'flags.dump(); '
145 simulationPostExec += f
' cfg.getService("PhysicsListSvc").GeneralCut={args.range_cut};'
147 simulationPostExec +=
' from VP1Algs.VP1AlgConfig import VP1AlgCfg; cfg.merge(VP1AlgCfg(flags));'
149 hitsFile = f
'{filePrefix}.HITS.pool.root'
152 simulationCmd = [
'TestBeam_tf.py',
'--CA',
153 '--maxEvents', f
'{args.evtMax}',
154 '--DataRunNumber', f
'{args.runNumber}',
155 '--outputHITSFile', f
'{hitsFile}',
156 '--conditionsTag', f
'{args.conditions_tag}',
158 '--ignorePatterns',
'ISF_MC12Truth.+ERROR']
159 if args.physics_list:
160 simulationCmd += [
'--physicsList', f
'{args.physics_list}']
161 if simulationPreExec:
162 simulationCmd += [
'--preExec', f
'{simulationPreExec}']
163 if simulationPostExec:
164 simulationCmd += [
'--postExec', f
'{simulationPostExec}']
167 digitizationFlags =
'; '.
join([f
'flags.TestBeam.Layout="{layout}"'])
170 digitizationCmd = [
'athena',
'--CA',
'TileSimEx/TileDigiRec.py',
171 '--filesInput', f
'{hitsFile}',
172 '--preExec', f
'{digitizationFlags}',
173 '--file-prefix', f
'{filePrefix}',
179 with open(f
'{filePrefix}.log',
'w')
as logFile:
180 runCommand(simulationCmd, log,
'Tile TB simulation', logFile)
181 runCommand(digitizationCmd, log,
'Tile TB digitization', logFile)