ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
AsgAnalysisAlgorithms
Root
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
7
#include <
AsgAnalysisAlgorithms/BootstrapGeneratorAlg.h
>
8
#include <
AsgDataHandles/ReadHandle.h
>
9
#include <
AsgDataHandles/WriteDecorHandle.h
>
10
11
std::uint64_t
CP::BootstrapGenerator::fnv1a_64
(
const
void
*buffer,
size_t
size
, std::uint64_t offset_basis) {
12
std::uint64_t
h
= offset_basis;
13
const
unsigned
char
*p =
static_cast<
const
unsigned
char
*
>
(buffer);
14
for
(
size_t
i = 0; i <
size
; i++) {
15
h
^= p[i];
16
h
*=
m_prime
;
17
}
18
return
h
;
19
}
20
21
std::uint64_t
CP::BootstrapGenerator::generateSeed
(std::uint64_t
eventNumber
, std::uint32_t runNumber, std::uint32_t
mcChannelNumber
)
22
{
23
std::uint64_t hash =
fnv1a_64
(&runNumber,
sizeof
(runNumber),
m_offset
);
24
hash =
fnv1a_64
(&
eventNumber
,
sizeof
(
eventNumber
), hash);
25
hash =
fnv1a_64
(&
mcChannelNumber
,
sizeof
(
mcChannelNumber
), hash);
26
return
hash;
27
}
28
29
void
CP::BootstrapGenerator::setSeed
(std::uint64_t
eventNumber
, std::uint32_t runNumber, std::uint32_t
mcChannelNumber
)
30
{
31
std::uint64_t seed =
generateSeed
(
eventNumber
, runNumber,
mcChannelNumber
);
32
m_rng
.SetSeed(seed);
33
}
34
35
StatusCode
CP::BootstrapGeneratorAlg::initialize
()
36
{
37
if
(
m_nReplicas
< 0)
38
{
39
ANA_MSG_ERROR
(
"The number of bootstrapped weights (toys) cannot be negative!"
);
40
return
StatusCode::FAILURE;
41
}
42
43
ANA_CHECK
(
m_eventInfoKey
.initialize());
44
ANA_CHECK
(
m_decorationKey
.initialize());
45
46
return
StatusCode::SUCCESS;
47
}
48
49
StatusCode
CP::BootstrapGeneratorAlg::execute
(
const
EventContext& ctx)
const
50
{
51
SG::ReadHandle<xAOD::EventInfo>
evtInfo(
m_eventInfoKey
, ctx);
52
ANA_CHECK
(evtInfo.
isValid
());
53
54
// generate a unique seed from runNumber, eventNumber and DSID!
55
BootstrapGenerator
bootstrap;
56
bootstrap.
setSeed
(evtInfo->eventNumber(), evtInfo->runNumber(),
m_data
? 0 : evtInfo->mcChannelNumber());
57
58
// and fill it with Poisson(1)
59
std::vector<std::uint8_t>
weights
(
m_nReplicas
);
60
for
(std::uint8_t& weight :
weights
)
61
{
62
weight = bootstrap.
getBootstrap
();
63
}
64
65
// decorate weights onto EventInfo
66
SG::WriteDecorHandle<xAOD::EventInfo, std::vector<std::uint8_t>
> dec(
m_decorationKey
, ctx);
67
dec(*evtInfo) = std::move(
weights
);
68
69
return
StatusCode::SUCCESS;
70
}
ReadHandle.h
Handle class for reading from StoreGate.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
BootstrapGeneratorAlg.h
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:295
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:325
size
size_t size() const
Number of registered mappings.
h
Header file for AthHistogramAlgorithm.
CP::BootstrapGeneratorAlg::m_decorationKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decorationKey
the output decoration
Definition
BootstrapGeneratorAlg.h:82
CP::BootstrapGeneratorAlg::m_nReplicas
Gaudi::Property< int > m_nReplicas
the number of bootstrap replicas
Definition
BootstrapGeneratorAlg.h:74
CP::BootstrapGeneratorAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
the EventInfo container
Definition
BootstrapGeneratorAlg.h:69
CP::BootstrapGeneratorAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition
BootstrapGeneratorAlg.cxx:49
CP::BootstrapGeneratorAlg::m_data
Gaudi::Property< bool > m_data
flag whether we are running on data
Definition
BootstrapGeneratorAlg.h:78
CP::BootstrapGeneratorAlg::initialize
StatusCode initialize() override
Definition
BootstrapGeneratorAlg.cxx:35
CP::BootstrapGenerator
a class to generate random numbers with a unique seed
Definition
BootstrapGeneratorAlg.h:22
CP::BootstrapGenerator::fnv1a_64
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...
Definition
BootstrapGeneratorAlg.cxx:11
CP::BootstrapGenerator::setSeed
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
Definition
BootstrapGeneratorAlg.cxx:29
CP::BootstrapGenerator::m_offset
static constexpr std::uint64_t m_offset
constants for seed generation
Definition
BootstrapGeneratorAlg.h:45
CP::BootstrapGenerator::m_rng
TRandomRanluxpp m_rng
the random number generator (Ranlux++)
Definition
BootstrapGeneratorAlg.h:50
CP::BootstrapGenerator::m_prime
static constexpr std::uint64_t m_prime
Definition
BootstrapGeneratorAlg.h:46
CP::BootstrapGenerator::getBootstrap
std::uint8_t getBootstrap()
get the next bootstrap weight
Definition
BootstrapGeneratorAlg.h:41
CP::BootstrapGenerator::generateSeed
std::uint64_t generateSeed(std::uint64_t eventNumber, std::uint32_t runNumber, std::uint32_t mcChannelNumber)
generate a unique seed based on event identifiers
Definition
BootstrapGeneratorAlg.cxx:21
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:66
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::eventNumber
eventNumber
Definition
EventInfo_v1.cxx:95
xAOD::mcChannelNumber
mcChannelNumber
Definition
EventInfo_v1.cxx:168
weights
Definition
herwig7_interface.h:38
Generated on
for ATLAS Offline Software by
1.17.0