ATLAS Offline Software
Loading...
Searching...
No Matches
quark_colour_fixer.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 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("quark colour fixer")
13def quark_colour_fixer(process, powheg_LHE_output):
14 """! Post-process existing events to ensure that all quarks are coloured.
15
16 @param process PowhegBox process.
17 @param powheg_LHE_output Name of LHE file produced by PowhegBox.
18
19 @author James Robinson <james.robinson@cern.ch>
20 """
21 # Check whether vdecaymode is one of the hadronic modes
22 if all(p.value in [0, 10] for p in process.parameters_by_keyword("vdecaymode")):
23 logger.info("Checking for presence of colourless quarks!")
24
25 # Get opening and closing strings
26 preamble = LHE.preamble(powheg_LHE_output)
27 postamble = LHE.postamble(powheg_LHE_output)
28
29 # Check events for colourless final-state quarks and colour them
30 n_events = 0
31 logger.info("Checking events for colourless final-state quarks")
32 powheg_LHE_recoloured = "{}.recoloured".format(powheg_LHE_output)
33 with open(powheg_LHE_recoloured, "w") as f_output:
34 f_output.write("{}\n".format(preamble))
35 for input_event in LHE.event_iterator(powheg_LHE_output):
36 is_event_changed, output_event = LHE.ensure_coloured_quarks(input_event)
37 f_output.write(output_event)
38 n_events += [0, 1][is_event_changed]
39 f_output.write(postamble)
40 logger.info("Re-coloured final-state quarks in {} events!".format(n_events))
41
42 # Make a backup of the original events
43 shutil.move(powheg_LHE_output, "{}.quark_colour_fixer_backup".format(powheg_LHE_output))
44 shutil.move(powheg_LHE_recoloured, powheg_LHE_output)