ATLAS Offline Software
Loading...
Searching...
No Matches
BootstrapGeneratorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
10 ISvcLocator *pSvcLocator)
11 : EL::AnaAlgorithm(name, pSvcLocator)
12{
13}
14
15std::uint64_t CP::BootstrapGenerator::fnv1a_64(const void *buffer, size_t size, std::uint64_t offset_basis) {
16 std::uint64_t h = offset_basis;
17 const unsigned char *p = static_cast<const unsigned char *>(buffer);
18 for (size_t i = 0; i < size; i++) {
19 h ^= p[i];
20 h *= m_prime;
21 }
22 return h;
23}
24
25std::uint64_t CP::BootstrapGenerator::generateSeed(std::uint64_t eventNumber, std::uint32_t runNumber, std::uint32_t mcChannelNumber)
26{
27 std::uint64_t hash = fnv1a_64(&runNumber, sizeof(runNumber), m_offset);
28 hash = fnv1a_64(&eventNumber, sizeof(eventNumber), hash);
29 hash = fnv1a_64(&mcChannelNumber, sizeof(mcChannelNumber), hash);
30 return hash;
31}
32
33void CP::BootstrapGenerator::setSeed(std::uint64_t eventNumber, std::uint32_t runNumber, std::uint32_t mcChannelNumber)
34{
35 std::uint64_t seed = generateSeed(eventNumber, runNumber, mcChannelNumber);
36 m_rng.SetSeed(seed);
37}
38
40{
41 if (m_nReplicas < 0)
42 {
43 ANA_MSG_ERROR("The number of bootstrapped weights (toys) cannot be negative!");
44 return StatusCode::FAILURE;
45 }
46
49 ANA_CHECK(m_systematicsList.initialize());
50
51 return StatusCode::SUCCESS;
52}
53
55{
56 for (const auto &sys : m_systematicsList.systematicsVector())
57 {
58 // retrieve the EventInfo
59 const xAOD::EventInfo *evtInfo = nullptr;
60 ANA_CHECK(m_eventInfoHandle.retrieve(evtInfo, sys));
61
62 // generate a unique seed from runNumber, eventNumber and DSID!
63 m_bootstrap.setSeed(evtInfo->eventNumber(), evtInfo->runNumber(), m_data ? 0 : evtInfo->mcChannelNumber());
64
65 m_weights.resize(m_nReplicas);
66 // and fill it with Poisson(1)
67 for (int i = 0; i < m_nReplicas; i++)
68 {
69 m_weights.at(i) = m_bootstrap.getBootstrap();
70 }
71
72 // decorate weights onto EventInfo
73 m_decoration.set(*evtInfo, m_weights, sys);
74 }
75
76 return StatusCode::SUCCESS;
77}
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
Header file for AthHistogramAlgorithm.
SysListHandle m_systematicsList
the systematics list we run
BootstrapGeneratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
std::vector< std::uint8_t > m_weights
the vector of bootstrap replica weights
Gaudi::Property< int > m_nReplicas
the number of bootstrap replicas
BootstrapGenerator m_bootstrap
the bootstrap generator instance
SysWriteDecorHandle< std::vector< std::uint8_t > > m_decoration
the output decoration
SysReadHandle< xAOD::EventInfo > m_eventInfoHandle
the EventInfo container
Gaudi::Property< bool > m_data
flag whether we are running on data
std::uint64_t fnv1a_64(const void *buffer, size_t size, std::uint64_t offset_basis)
implementation of the hash function from https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo...
void setSeed(std::uint64_t eventNumber, std::uint32_t runNumber, std::uint32_t mcChannelNumber)
set the seed of the random number generator based on event properties
static constexpr std::uint64_t m_offset
constants for seed generation
TRandomRanluxpp m_rng
the random number generator (Ranlux++)
static constexpr std::uint64_t m_prime
std::uint64_t generateSeed(std::uint64_t eventNumber, std::uint32_t runNumber, std::uint32_t mcChannelNumber)
generate a unique seed based on event identifiers
AnaAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
uint32_t runNumber() const
The current event's run number.
uint32_t mcChannelNumber() const
The MC generator's channel number.
uint64_t eventNumber() const
The current event's event number.
This module defines the arguments passed from the BATCH driver to the BATCH worker.
EventInfo_v1 EventInfo
Definition of the latest event info version.