ATLAS Offline Software
Loading...
Searching...
No Matches
RunGeantinoStepRecordingITk.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3"""
4Run geantino processing for material step creation
5"""
6
7from argparse import ArgumentParser
8from AthenaCommon.Logging import log
9from AthenaConfiguration.AllConfigFlags import initConfigFlags
10from AthenaConfiguration.MainServicesConfig import MainServicesCfg
11from AthenaConfiguration.ComponentFactory import CompFactory
12
13# Argument parsing
14parser = ArgumentParser("RunGeantinoStepRecordingITk.py")
15parser.add_argument("detectors", metavar="detectors", type=str, nargs="*",
16 help="Specify the list of detectors")
17parser.add_argument("--simulate", default=True, action="store_true",
18 help="Run Simulation")
19parser.add_argument("--localgeo", default=False, action="store_true",
20 help="Use local geometry Xml files")
21parser.add_argument("-V", "--verboseAccumulators", default=False,
22 action="store_true",
23 help="Print full details of the AlgSequence")
24parser.add_argument("-S", "--verboseStoreGate", default=False,
25 action="store_true",
26 help="Dump the StoreGate(s) each event iteration")
27parser.add_argument("--maxEvents",default=10, type=int,
28 help="The number of events to run. 0 skips execution")
29parser.add_argument("--skipEvents",default=0, type=int,
30 help="The number of events to skip")
31from AthenaConfiguration.TestDefaults import defaultGeometryTags
32parser.add_argument("--geometrytag",default=defaultGeometryTags.RUN4, type=str,
33 help="The geometry tag to use")
34parser.add_argument("--inputevntfile",
35 default="/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/PhaseIIUpgrade/EVNT/mc15_14TeV.singlegeantino_E10GeV_etaFlatnp0_6.5M.evgen.EVNT.pool.root",
36 help="The input EVNT file to use")
37parser.add_argument("--outputhitsfile",default="myHITS.pool.root", type=str,
38 help="The output HITS filename")
39args = parser.parse_args()
40
41
42# Some info about the job
43print("----GeantinoStepRecording for ITk geometry----")
44print()
45print("Using Geometry Tag: "+args.geometrytag)
46if args.localgeo:
47 print("...overridden by local Geometry Xml files")
48print("Input EVNT File:"+args.inputevntfile)
49if not args.detectors:
50 print("Running complete detector")
51else:
52 print("Running with: {}".format(", ".join(args.detectors)))
53print()
54
55# Configure
56flags = initConfigFlags()
57if args.localgeo:
58 flags.ITk.Geometry.AllLocal = True
59
60flags.Input.Files = [args.inputevntfile]
61flags.Output.HITSFileName = args.outputhitsfile
62
63flags.GeoModel.AtlasVersion = args.geometrytag
64from AthenaConfiguration.TestDefaults import defaultConditionsTags
65flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
66flags.GeoModel.Align.Dynamic = False
67
68flags.Exec.SkipEvents = args.skipEvents
69
70from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
71detectors = args.detectors if 'detectors' in args and args.detectors else ['ITkPixel', 'ITkStrip', 'HGTD']
72detectors.append('Bpipe') # always run with beam pipe
73setupDetectorFlags(flags, detectors, toggle_geometry=True)
74
75from AthenaConfiguration.Enums import ProductionStep
76flags.Common.ProductionStep = ProductionStep.Simulation
77
78log.debug('Lock config flags now.')
79flags.lock()
80
81# Construct our accumulator to run
82acc = MainServicesCfg(flags)
83
84
85if args.verboseAccumulators:
86 acc.printConfig(withDetails=True)
87if args.verboseStoreGate:
88 acc.getService("StoreGateSvc").Dump = True
89
90log.debug('Dumping of ConfigFlags now.')
91flags.dump()
92
93from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
94acc.merge(PoolReadCfg(flags))
95
96# add BeamEffectsAlg
97from BeamEffects.BeamEffectsAlgConfig import BeamEffectsAlgCfg
98acc.merge(BeamEffectsAlgCfg(flags))
99
100beamcond = acc.getCondAlgo("BeamSpotCondAlg")
101
102beamcond.useDB=False
103beamcond.posX=0.0
104beamcond.posY=0.0
105beamcond.posZ=0.0
106beamcond.sigmaX=0.0
107beamcond.sigmaY=0.0
108beamcond.sigmaZ=0.0
109beamcond.tiltX=0.0
110beamcond.tiltY=0.0
111
112kwargs = {}
113svcName = "G4UA::MaterialStepRecorderUserActionSvc"
114from TrkG4UserActions.TrkG4UserActionsConfig import MaterialStepRecorderUserActionSvcCfg
115userAction = acc.getPrimaryAndMerge(MaterialStepRecorderUserActionSvcCfg(flags,svcName,**kwargs))
116kwargs.update(UserActionSvc=userAction)
117
118if args.simulate:
119 from G4AtlasAlg.G4AtlasAlgConfig import G4AtlasAlgCfg
120 acc.merge(G4AtlasAlgCfg(flags, "ITkG4AtlasAlg", **kwargs))
121 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
122 from SimuJobTransforms.SimOutputConfig import getStreamHITS_ItemList
123 acc.merge( OutputStreamCfg(flags,"HITS", ItemList=getStreamHITS_ItemList(flags), disableEventTag=True, AcceptAlgs=['ITkG4AtlasAlg']) )
124
125from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
126acc.merge(EventInfoCnvAlgCfg(flags))
127
128AthenaOutputStream=CompFactory.AthenaOutputStream
129AthenaOutputStreamTool=CompFactory.AthenaOutputStreamTool
130writingTool = AthenaOutputStreamTool( "MaterialStepCollectionStreamTool",
131 TopLevelContainerName = "",
132 SubLevelBranchName = "<type>/<key>" )
133
134outputStream = AthenaOutputStream(name = "MaterialStepCollectionStream",
135 WritingTool = writingTool,
136 ItemList=['EventInfo#*', 'Trk::MaterialStepCollection#*'],
137 MetadataItemList = [ "EventStreamInfo#MaterialStepCollectionStream", "IOVMetaDataContainer#*" ],
138 OutputFile = "MaterialStepCollection.root")
139
140StoreGateSvc=CompFactory.StoreGateSvc
141acc.addService(StoreGateSvc("MetaDataStore"))
142outputStream.MetadataStore = acc.getService("MetaDataStore")
143
144MakeEventStreamInfo=CompFactory.MakeEventStreamInfo
145streamInfoTool = MakeEventStreamInfo( "MaterialStepCollectionStream_MakeEventStreamInfo" )
146streamInfoTool.Key = "MaterialStepCollectionStream"
147streamInfoTool.EventInfoKey = "EventInfo"
148outputStream.HelperTools.append(streamInfoTool)
149
150acc.addEventAlgo(outputStream)
151
152acc.printConfig(withDetails = True, summariseProps = True)
153
154acc.run(maxEvents=args.maxEvents)
155
void print(char *figname, TCanvas *c1)
This is the implementation of IAthenaOutputStreamTool.
algorithm that marks for write data objects in SG
This class provides an algorithm to make the EventStreamInfo object and update it.
The Athena Transient Store API.