ATLAS Offline Software
Loading...
Searching...
No Matches
lhe_cleaner.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3from ... import Logging
4from ...decorators import timed
5from ...utility import FileParser
6
7
8logger = Logging.logging.getLogger("PowhegControl")
9
10@timed("LHE file cleaning")
11def lhe_cleaner(powheg_LHE_output):
12 """Post-process LHE file to conform to what the parton-shower generator expects.
13
14 @param powheg_LHE_output Name of LHE file produced by PowhegBox.
15 """
16 logger.info("Starting to run PowhegControl LHE file cleaner")
17 import os
18 os.system('cp {0} unmodified_{0}'.format(powheg_LHE_output))
19
20
28
29 # Removing rwgt, pdf, and new weight comment lines if one such line looks buggy, i.e. if one NaN values is found
30 # Otherwise it would probably make Pythia crash (even versions which accept such comment lines)
31 pdf_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^#pdf", "NaN")
32 rwg_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^#rwgt", "NaN")
33 new_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^#new weight", "NaN")
34 matching_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^#matching", "NaN")
35 rdm_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^ #Random", "NaN") # this one starts with a space
36 emscales_removed = FileParser(powheg_LHE_output).text_remove_all_if_one_line_matches("^#emscales", "NaN")
37
38 if pdf_removed != 0:
39 logger.info("{} line(s) starting with '#pdf' were removed in {} since at least one looked buggy".format(pdf_removed, powheg_LHE_output))
40 if rwg_removed != 0:
41 logger.info("{} line(s) starting with '#rwgt' were removed in {} since at least one looked buggy".format(rwg_removed, powheg_LHE_output))
42 if new_removed != 0:
43 logger.info("{} line(s) starting with '#new weight' were removed in {} since at least one looked buggy".format(new_removed, powheg_LHE_output))
44 if matching_removed != 0:
45 logger.info("{} line(s) starting with '#matching' were removed in {} since at least one looked buggy".format(matching_removed, powheg_LHE_output))
46 if rdm_removed != 0:
47 logger.info("{} line(s) starting with ' #Random' were removed in {} since at least one looked buggy".format(rdm_removed, powheg_LHE_output)) # this one starts with a space
48 if emscales_removed != 0:
49 logger.info("{} line(s) starting with '#emscales' were removed in {} since at least one looked buggy".format(emscales_removed, powheg_LHE_output))
50
51 # Correct LHE version identification; otherwise Pythia will treat all files as v1
52 FileParser(powheg_LHE_output).text_replace('LesHouchesEvents version="1.0"', 'LesHouchesEvents version="3.0"')
Utility class to perform simple operations on files.