Have a look at BeamSpotReweightingAlg and try to write the configuration fragment for it. This time make sure you configure all the dependencies and properties. There are two event-level inputs, one conditions input, one decoration output and one other property.
Some notes:
BeamSpotCondAlgCfg
).EventInfo
and InputMcEventCollection
usually come from the input file so explicit algorithmic dependencies do not need to be set up. It is good to set input keys for all inputs, so data dependencies are also clear from the configuration side, but they are often omitted for common inputs like EventInfo
.Input_beam_sigma_z
can be set from flags.Digitization.InputBeamSigmaZ
.addEventAlgo
should be used.CompFactory.Simulation.BeamSpotReweightingAlg
is the full access path to this algorithm.Compare your result with the current implementation in athena. What do you observe?
def BeamSpotReweightingAlgCfg(flags, name="BeamSpotReweightingAlg", **kwargs):
# conditions dependency
from BeamSpotConditions.BeamSpotConditionsConfig import BeamSpotCondAlgCfg
acc = BeamSpotCondAlgCfg(flags)
# properties from flags
kwargs.setdefault("Input_beam_sigma_z", flags.Digitization.InputBeamSigmaZ)
# data handles
kwargs.setdefault("InputMcEventCollection", "TruthEvent")
kwargs.setdefault("EventInfo", "EventInfo")
kwargs.setdefault("BeamSpotKey", "BeamSpotData")
kwargs.setdefault("beamSpotWeight", "EventInfo.beamSpotWeight")
acc.addEventAlgo(CompFactory.Simulation.BeamSpotReweightingAlg(name, **kwargs))
return acc
Add the algorithm to the job. You will see that by default the algorithm does nothing as flags.Digitization.InputBeamSigmaZ
is set to -1
. You should and play with the properties a bit and look what happens:
cfg.getEventAlgo("BeamSpotReweightingAlg").OutputLevel = DEBUG
(you may need to import DEBUG
from AthenaCommon.Constants
)flags.Digitization.InputBeamSigmaZ
to 50
beamSpotWeightForTutorial
BeamSpotCondAlgCfg
from the main job and see what happensWe learned how to configure an algorithm and change its properties. next section you will learn a bit more about inspecting the changes in the configuration. The final configuration should look something like this:
#!/usr/bin/env python
from AthenaConfiguration.ComponentFactory import CompFactory
def BeamSpotReweightingAlgCfg(flags, name="BeamSpotReweightingAlg", **kwargs):
# conditions dependency
from BeamSpotConditions.BeamSpotConditionsConfig import BeamSpotCondAlgCfg
acc = BeamSpotCondAlgCfg(flags)
# properties from flags
kwargs.setdefault("Input_beam_sigma_z", flags.Digitization.InputBeamSigmaZ)
# data handles
kwargs.setdefault("InputMcEventCollection", "TruthEvent")
kwargs.setdefault("EventInfo", "EventInfo")
kwargs.setdefault("BeamSpotKey", "BeamSpotData")
kwargs.setdefault("beamSpotWeight", "EventInfo.beamSpotWeightForTutorial")
acc.addEventAlgo(CompFactory.Simulation.BeamSpotReweightingAlg(name, **kwargs))
return acc
if __name__ == "__main__":
from AthenaConfiguration.AllConfigFlags import initConfigFlags
from AthenaConfiguration.TestDefaults import defaultTestFiles
flags = initConfigFlags()
flags.Input.Files = defaultTestFiles.HITS
flags.Output.RDOFileName = "myRDO.pool.root"
flags.Digitization.InputBeamSigmaZ = 50
flags.lock()
from AthenaConfiguration.MainServicesConfig import MainServicesCfg
cfg = MainServicesCfg(flags)
from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
cfg.merge(PoolReadCfg(flags))
# Check if running on legacy HITS
if "EventInfo" not in flags.Input.Collections:
from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
cfg.merge(EventInfoCnvAlgCfg(flags))
cfg.merge(BeamSpotReweightingAlgCfg(flags))
if flags.Output.doWriteRDO:
from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
cfg.merge(OutputStreamCfg(flags, "RDO", ItemList=[
"xAOD::EventInfo#EventInfo",
"xAOD::EventAuxInfo#EventInfoAux.",
]))
from AthenaCommon.Constants import DEBUG
cfg.getEventAlgo("BeamSpotReweightingAlg").OutputLevel = DEBUG
with open("BeamSpot.pkl", "wb") as f:
cfg.store(f)
import sys
sys.exit(not cfg.run(maxEvents=3).isSuccess())