ATLAS Offline Software
Loading...
Searching...
No Matches
cross_section_calculator.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
6
7
8logger = Logging.logging.getLogger("PowhegControl")
9
10
11@timed("cross section calculator")
12def cross_section_calculator(powheg_LHE_output):
13 """! Calculate the cross-section (mean event weight) of pre-generated Powheg events.
14
15 @param powheg_LHE_output Name of LHE file produced by PowhegBox.
16
17 @author James Robinson <james.robinson@cern.ch>
18 """
19 logger.info("Born-level suppression is enabled so the cross-section MUST be recalculated!")
20 # LHEUtils returns a generator, since the input file may be large
21 sum_of_weights, n_events = 0., 0
22 for event_weight in LHE.event_weight_iterator(powheg_LHE_output):
23 sum_of_weights += event_weight
24 n_events += 1
25 # import numpy as np
26 # import itertools as it
27 # sum_of_weights, n_events = reduce(np.add, it.izip(LHEUtils.event_weight_iterator(LHE_file_name), it.repeat(1)))
28
29 # Print statistics to logger
30 logger.info("... sum of event weights is: {}".format(sum_of_weights))
31 logger.info("... number of events generated: {}".format(int(n_events)))
32 logger.info("... mean event weight: {}".format((sum_of_weights / n_events if n_events != 0 else 0)))
33 logger.info("MetaData: cross-section (nb) = {:.3E}".format((sum_of_weights / (1000 * n_events) if n_events != 0 else 0)))