7 @brief Script to run Tile TestBeam Reconstruction/Monitoring
10 from AthenaConfiguration.Enums
import BeamType
11 from AthenaConfiguration.AutoConfigFlags
import GetFileMD
12 from TileConfiguration.TileConfigFlags
import TileRunType
13 from TileRecEx
import TileInputFiles
21 RunTileTBRec.py --run RUNNUMBER --evtMax 1
22 RunTileTBRec.py --filesInput=FILE1,FILE2 Exec.SkipEvents=100
24 At least one should provide the following arguments or Athena configuration flags (flags have higher priority):
25 Input file(s), e.g.: --run RUNNUMBER | --filesInput=FILE1,FILE2 | Input.Files="['FILE1','FILE2']"
28 if __name__ ==
'__main__':
31 from AthenaCommon.Logging
import logging
32 log = logging.getLogger(
'RunTileTBRec')
37 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
43 parser = argparse.ArgumentParser(parents=parserParents, add_help=
False, fromfile_prefix_chars=
'@', epilog=epiLog, formatter_class=argparse.RawTextHelpFormatter)
45 parser.add_argument(
'--preExec', help=
'Code to execute before locking configs')
46 parser.add_argument(
'--postExec', help=
'Code to execute after setup')
47 parser.add_argument(
'--postInclude', nargs=
'+', help=
'Configuration fragment to include after main job options')
48 parser.add_argument(
'--printConfig', action=
'store_true', help=
'Print detailed Athena configuration')
49 parser.add_argument(
'--dumpArguments', action=
'store_true', help=
'Print arguments and exit')
50 parser.add_argument(
'--outputVersion', type=str, default=
"", help=
'Version to be used in output files for ntuple and monitoring')
51 parser.add_argument(
'--outputDirectory', default=
'.', help=
'Output directory for produced files')
53 parser.add_argument(
'--frag-ids', dest=
'fragIDs', nargs=
"*", default=[
'0x100',
'0x101',
'0x200',
'0x201',
'0x402'],
54 help=
'Tile Frag IDs of modules to be monitored. Empty=ALL')
55 parser.add_argument(
'--demo-cabling', dest=
'demoCabling', type=int, default=2018, help=
'Time Demonatrator cabling to be used')
56 parser.add_argument(
'--nsamples', type=int, default=
None, help=
'Number of samples')
57 parser.add_argument(
'--use-sqlite', dest=
'useSqlite', default=
'/afs/cern.ch/user/t/tiledemo/public/efmon/condb/tileSqlite.db',
58 help=
'Providing local SQlite file, conditions constants will be used from it')
59 parser.add_argument(
'--mon', default=
False, help=
'Run Tile TB monitoring', action=argparse.BooleanOptionalAction)
60 parser.add_argument(
'--offline-units', type=int, choices=[0, 1, 2, 3], default=
None,
61 help=
'Offline units in ntuple: 0 (ADC), 1 (pC), 2 (Cesium pC), 3 (MeV)')
64 run_type_group = parser.add_argument_group(
'Tile Run Type')
65 run_type = run_type_group.add_mutually_exclusive_group()
66 run_type.add_argument(
'--cis', action=
'store_true', help=
'Tile CIS run type')
67 run_type.add_argument(
'--mono-cis', action=
'store_true', dest=
'mono_cis', help=
'Tile mono CIS run type')
68 run_type.add_argument(
'--laser', action=
'store_true', help=
'Tile laser run type')
69 run_type.add_argument(
'--pedestals', action=
'store_true', help=
'Tile pedestals run type')
70 run_type.add_argument(
'--physics', action=
'store_true', help=
'Tile physics run type')
73 method = parser.add_argument_group(
'Tile reconstuction method')
74 method.add_argument(
'--opt2', default=
False, help=
'Use Tile Opt2 reconstuction method', action=argparse.BooleanOptionalAction)
75 method.add_argument(
'--opt-atlas', dest=
'opt_atlas', default=
False, help=
'Use Tile OptATLAS reconstuction method', action=argparse.BooleanOptionalAction)
76 method.add_argument(
'--fit', default=
True, help=
'Use Tile Fit reconstuction method', action=argparse.BooleanOptionalAction)
78 args, _ = parser.parse_known_args()
80 if args.dumpArguments:
81 log.info(
'=====>>> FINAL ARGUMENTS FOLLOW')
82 print(
'{:40} : {}'.
format(
'Argument Name',
'Value'))
83 for a, v
in (vars(args)).
items():
84 print(f
'{a:40} : {v}')
87 fragIDs = [
int(fragID, base=16)
for fragID
in args.fragIDs]
90 flags.Input.Files = []
93 flags.fillFromArgs(parser=parser)
96 flags.Exec.MaxEvents = 3
97 flags.Common.isOnline =
True
98 from AthenaConfiguration.TestDefaults
import defaultGeometryTags
99 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN2
100 flags.DQ.useTrigger =
False
101 flags.DQ.enableLumiAccess =
False
102 flags.Exec.PrintAlgsSequence =
True
104 flags.Tile.doFit =
True
105 flags.Tile.useDCS =
False
106 flags.Tile.NoiseFilter = 0
107 flags.Tile.correctTime =
False
108 flags.Tile.correctTimeJumps =
False
109 flags.Tile.BestPhaseFromCOOL =
False
110 flags.Tile.doOverflowFit =
False
112 flags.Tile.RunType = TileRunType.PHY
113 flags.Beam.Type = BeamType.Collisions
116 flags.Beam.Energy = beamEnergy * GeV
119 if not flags.Input.Files
and args.run:
121 if not flags.Input.Files:
122 log.error(
'Input files must be provided! For example: --filesInput=file1,file2,... or --run RUNNUMBER')
127 flags.Tile.RunType = TileRunType.CIS
129 flags.Tile.RunType = TileRunType.MONOCIS
131 flags.Tile.RunType = TileRunType.LAS
133 flags.Tile.RunType = TileRunType.PED
135 flags.Tile.RunType = TileRunType.PHY
138 flags.Tile.doOpt2 = args.opt2
139 flags.Tile.doOptATLAS = args.opt_atlas
140 flags.Tile.doFit = args.fit
143 flags.fillFromArgs(parser=parser)
145 runNumber = flags.Input.RunNumbers[0]
146 if not flags.Output.HISTFileName:
147 flags.Output.HISTFileName = f
'{args.outputDirectory}/tiletbmon_{runNumber}{args.outputVersion}.root'
150 log.info(f
'Executing preExec: {args.preExec}')
155 log.info(
'=====>>> FINAL CONFIG FLAGS SETTINGS FOLLOW:')
156 flags.dump(pattern=
'Tile.*|Beam.*|Input.*|Exec.*|IOVDb.[D|G].*', evaluate=
True)
159 nSamples = args.nsamples
161 nSamples = 7
if flags.Tile.RunType.isBiGain()
or runNumber <= 2110820
else 15
162 log.info(f
'Auto configure number of samples: {nSamples}')
165 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
169 from TileByteStream.TileByteStreamConfig
import TileRawDataReadingCfg
177 from TileTBRec.TileTestBeamRecoConfig
import TileTestBeamRawChannelMakerCfg
182 cfg.getService(
'IOVDbSvc').overrideTags += [
183 f
'<prefix>/TILE</prefix> <db>sqlite://;schema={args.useSqlite};dbname={flags.IOVDb.DatabaseInstance}</db>',
185 f
'<prefix>/TILE/ONL01/STATUS/ROD</prefix> <db>COOLONL_TILE/{flags.IOVDb.DatabaseInstance}</db>'
190 from TileTBRec.TileTestBeamRecoConfig
import TileTestBeamRecoCfg
192 cfg.merge(
TileTestBeamRecoCfg(flags, useDemoCabling=args.demoCabling, nsamples=16, useFELIX=
True) )
194 from TileMonitoring.RunTileTBMonitoring
import TileTestBeamMonitoringCfg
198 ntupleFile = f
'{args.outputDirectory}/tiletb_{runNumber}{args.outputVersion}.aan.root'
199 offlineUnits = args.offline_units
201 if flags.Tile.RunType
in [TileRunType.PED, TileRunType.CIS]:
203 elif flags.Tile.RunType
in [TileRunType.LAS, TileRunType.MONOCIS]:
207 unitsName = {0:
"ADC", 1:
"pC", 2:
"Cesium pC", 3:
"MeV"}.
get(offlineUnits)
208 log.info(f
'Auto configure offline units: {offlineUnits} => {unitsName}')
210 calibrateEnergy = (offlineUnits != 0)
212 from TileTBRec.TileTBAANtupleConfig
import TileTBAANtupleCfg
213 cfg.merge(
TileTBAANtupleCfg(flags, outputFile=ntupleFile, OfflineUnits=offlineUnits, CalibrateEnergy=calibrateEnergy, NSamples=nSamples) )
216 if flags.Tile.RunType
in [TileRunType.CIS, TileRunType.MONOCIS]:
217 cisCalibFile = f
'{args.outputDirectory}/tileCalibCIS_{runNumber}_CIS{args.outputVersion}.root'
218 from TileCalibAlgs.TileCisCalibAlgConfig
import TileCisCalibAlgCfg
221 tileCisTool = cfg.getEventAlgo(
'TileCisCalibAlg').TileCalibTools[
'TileCisDefaultCalibTool']
222 if runNumber >= 2200000:
223 tileCisTool.FragIDsDemonstrators = [ 0x201, 0x402 ]
224 elif runNumber >= 2100000:
225 tileCisTool.FragIDsDemonstrators = [ 0x201 ]
228 if flags.Tile.RunType
is TileRunType.PED:
229 from TileCalibAlgs.TileDigiNoiseCalibAlgConfig
import TileDigiNoiseCalibAlgCfg
234 cfg.getCondAlgo(
'TileHid2RESrcIDCondAlg').RODStatusProxy =
None
238 log.info(f
'Process postInclude: {args.postInclude}')
239 from PyJobTransforms.TransformUtils
import processPostInclude
244 log.info(f
'Executing postExec: {args.postExec}')
248 cfg.printConfig(withDetails=
True, summariseProps=
True, printDefaults=
True)
251 cfg.store(
open(
'TileTestBeamMonitoring.pkl',
'wb'))
255 sys.exit(
not sc.isSuccess())