ATLAS Offline Software
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 
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 
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 
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 
47  ANA_CHECK(m_eventInfoHandle.initialize(m_systematicsList));
48  ANA_CHECK(m_decoration.initialize(m_systematicsList, m_eventInfoHandle));
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 }
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
BootstrapGeneratorAlg.h
m_data
std::vector< T > m_data
Definition: TrackTruthMatchingBaseAlg.cxx:660
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
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:33
xAOD::mcChannelNumber
mcChannelNumber
Definition: EventInfo_v1.cxx:197
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
xAOD::EventInfo_v1::mcChannelNumber
uint32_t mcChannelNumber() const
The MC generator's channel number.
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
extractSporadic.h
list h
Definition: extractSporadic.py:97
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
CP::BootstrapGeneratorAlg::execute
StatusCode execute() override
Definition: BootstrapGeneratorAlg.cxx:54
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CP::BootstrapGeneratorAlg::initialize
StatusCode initialize() override
Definition: BootstrapGeneratorAlg.cxx:39
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
h
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
CP::BootstrapGeneratorAlg::BootstrapGeneratorAlg
BootstrapGeneratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
Definition: BootstrapGeneratorAlg.cxx:9
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:25
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:15