ATLAS Offline Software
Loading...
Searching...
No Matches
TileTB.py
Go to the documentation of this file.
1#!/usr/bin/env python
2"""
3# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4"""
5
6import sys
7import subprocess
8
9
10def runCommand(cmd, log, title, logFile):
11 log.info(f'Running {title}:')
12 log.info(' '.join([f'\'{o}\'' if ' ' in o else o for o in cmd]))
13
14 try:
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}!')
19 sys.exit(-1)
20
21
22if __name__ == "__main__":
23
24 from AthenaConfiguration.AllConfigFlags import initConfigFlags
25 from AthenaCommon.Constants import INFO
26
27 import logging
28 log = logging.getLogger('TileTB')
29 log.setLevel(INFO)
30 flags = initConfigFlags()
31
32 parser = flags.getArgumentParser(description='Run Tile TB simulation and digitization.')
33
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-row', 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')
69
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')
72
73 parser.set_defaults(evtMax=10)
74 args, _ = parser.parse_known_args()
75
76 layout = f'tb_Tile2000_2003_{args.layout}'
77 filePrefix = f'tiletb_pid{args.pid}_ene{args.energy}'
78
79 # =======>>> Set up the Tile TB simulation flags
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}"']
86
87 if args.eta:
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}']
93 else:
94 log.error('The following arguments should be provided: --eta or (--theta and --z)!')
95 sys.exit(-1)
96
97 if args.y:
98 simulationFlags += [f'flags.TestBeam.Y={args.y}']
99 if args.phi:
100 simulationFlags += [f'flags.TestBeam.Phi={args.phi}']
101
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']
106
107 # Check if post configuration of Tile simulation is needed
108 postConfig = False
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_row, args.do_tof_correction, args.do_birk, args.old_birk, args.birk1, args.birk2]):
111 postConfig = True
112 if args.ushape:
113 simulationFlags += [f'flags.Tile.Sim.Ushape={args.ushape}']
114 if args.steel:
115 simulationFlags += [f'flags.Tile.Sim.Steel={args.steel}']
116 if args.pvt:
117 simulationFlags += [f'flags.Tile.Sim.PVT={args.pvt}']
118 if args.cstube:
119 simulationFlags += [f'flags.Tile.Sim.CsTube={args.cstube}']
120 if args.delta_thit:
121 simulationFlags += [f'flags.Tile.Sim.DeltaTHit={args.delta_thit}']
122 if args.time_cut:
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}']
126 if args.do_tile_row:
127 simulationFlags += [f'flags.Tile.Sim.doTileRow={args.do_tile_row}']
128 if args.do_tof_correction:
129 simulationFlags += [f'flags.Tile.Sim.doTOFCorrection={args.do_tof_correction}']
130 if args.do_birk:
131 simulationFlags += [f'flags.Tile.Sim.doBirk={args.do_birk}']
132 if args.old_birk:
133 simulationFlags += [f'flags.Tile.Sim.OldBirk={args.old_birk}']
134 if args.birk1:
135 simulationFlags += [f'flags.Tile.Sim.Birk1={args.birk1}']
136 if args.birk2:
137 simulationFlags += [f'flags.Tile.Sim.Birk2={args.birk2}']
138
139 # =======>>> Set up the Tile TB simulation preExec
140 simulationPreExec = '; '.join(simulationFlags)
141
142 # =======>>> Set up the Tile TB simulation postExec
143 simulationPostExec = 'flags.dump(); '
144 if args.range_cut:
145 simulationPostExec += f' cfg.getService("PhysicsListSvc").GeneralCut={args.range_cut};'
146 if args.vp1:
147 simulationPostExec += ' from VP1Algs.VP1AlgConfig import VP1AlgCfg; cfg.merge(VP1AlgCfg(flags));'
148
149 hitsFile = f'{filePrefix}.HITS.pool.root'
150
151 # =======>>> Set up the Tile TB simulation command
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}',
157
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}']
165
166 # =======>>> Set up the Tile TB digitization flags
167 digitizationFlags = '; '.join([f'flags.TestBeam.Layout="{layout}"'])
168
169 # =======>>> Set up the Tile TB digitization command
170 digitizationCmd = ['athena', '--CA', 'TileSimEx/TileDigiRec.py',
171 '--filesInput', f'{hitsFile}',
172 '--preExec', f'{digitizationFlags}',
173 '--file-prefix', f'{filePrefix}',
174 '--aant-ntuple',
175 '--hits-ntuple',
176 '--testbeam']
177
178 # =======>>> Run Tile TB simulation and digitization commands
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)
runCommand(cmd, log, title, logFile)
Definition TileTB.py:10