ATLAS Offline Software
Loading...
Searching...
No Matches
gg4l_emu2all.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3from AthenaCommon import Logging
4from ...decorators import timed
5from ...utility import LHE
6import shutil
7
8
9logger = Logging.logging.getLogger("PowhegControl")
10
11
12@timed("gg4l_emu2all")
13def gg4l_emu2all(powheg_LHE_output):
14 """! Post-process existing events from electrons to muons
15
16 @param powheg_LHE_output Name of LHE file produced by PowhegBox.
17
18 @author Guglielmo Frattari <guglielmo.frattari@cern.ch>
19 """
20 logger.warning("Converting LHE events from 2e2mu to 2l2l' or 4l final states.")
21
22 # Get opening and closing strings
23 preamble = LHE.preamble(powheg_LHE_output)
24 postamble = LHE.postamble(powheg_LHE_output)
25
26 n_events = 0
27 powheg_LHE_2e2mu = "{}.mod".format(powheg_LHE_output)
28 with open(powheg_LHE_2e2mu, "w") as f_output:
29 f_output.write("{}\n".format(preamble))
30 for input_event in LHE.event_iterator(powheg_LHE_output):
31 is_event_changed, output_event = LHE.gg4l_emu2all(input_event)
32 f_output.write(output_event)
33 n_events += [0, 1][is_event_changed]
34 f_output.write(postamble)
35 logger.info("Changed 2e2mu final state to 2l2'/4l in {} events!".format(n_events))
36
37 # Make a backup of the original events
38 shutil.move(powheg_LHE_output, "{}.mod_backup".format(powheg_LHE_output))
39 shutil.move(powheg_LHE_2e2mu, powheg_LHE_output)