ATLAS Offline Software
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 
3 from AthenaCommon import Logging
4 from ...decorators import timed
5 from ...utility import LHE
6 
7 
8 logger = Logging.logging.getLogger("PowhegControl")
9 
10 
11 @timed("cross section calculator")
12 def 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)))
python.decorators.timed.timed
def timed(name)
Decorator to output function execution time.
Definition: timed.py:12
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.algorithms.postprocessors.cross_section_calculator.cross_section_calculator
def cross_section_calculator(powheg_LHE_output)
Calculate the cross-section (mean event weight) of pre-generated Powheg events.
Definition: cross_section_calculator.py:12