ATLAS Offline Software
Loading...
Searching...
No Matches
EventInfoBranch.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
7#include <stdexcept>
8namespace {
9 static const SG::AuxElement::ConstAccessor<unsigned int> acc_Random("RandomRunNumber");
10 static const SG::AuxElement::ConstAccessor<unsigned int> acc_LumiBlock("RandomLumiBlockNumber");
11 static const SG::AuxElement::ConstAccessor<float> acc_PuW("PileupWeight");
12}
13namespace MuonVal {
14std::atomic<unsigned int> EventInfoBranch::s_num_lhe = 0;
15void EventInfoBranch::setNumLHE(unsigned int n) { s_num_lhe = n;}
16unsigned int EventInfoBranch::getNumLHE() { return s_num_lhe;}
18 const std::string& evtKey):
19 MuonTesterBranch{tree, " event info "},
20 m_key{evtKey},
21 m_writemask{write_mask}{
24 for (unsigned int lhe = 1; lhe < s_num_lhe ; ++lhe ) {
25 std::shared_ptr<ScalarBranch<double>>& new_br = m_lhe_weights[lhe];
26 new_br = std::make_shared<ScalarBranch<double>>(tree.tree(), "mcEventWeight_LHE_" + std::to_string(lhe),0.);
27 if (!tree.addBranch(new_br)) {
28 THROW_EXCEPTION("EventInfoBranch: Failed to create Scalar branch in c'tor");
29 }
30 }
31 }
32 } else {
33 tree.disableBranch(m_mcChannel.name());
34 tree.disableBranch(m_weight.name());
36 }
37
39 m_prwKeys.emplace_back(m_key.key() + "." + SG::AuxTypeRegistry::instance().getName(acc_Random.auxid()));
40 m_prwKeys.emplace_back(m_key.key() + "." + SG::AuxTypeRegistry::instance().getName(acc_LumiBlock.auxid()));
41 m_prwKeys.emplace_back(m_key.key() + "." + SG::AuxTypeRegistry::instance().getName(acc_PuW.auxid()));
42 } else {
43 tree.disableBranch(m_prwWeight.name());
44 tree.disableBranch(m_rnd_run.name());
45 tree.disableBranch(m_rnd_lumi_block.name());
46 }
47 if (!(m_writemask & WriteOpts::writeBeamSpot)) tree.disableBranch(m_beamSpotWeight.name());
49 tree.disableBranch(m_average_mu.name());
50 tree.disableBranch(m_actual_mu.name());
51 }
52 if (!(m_writemask & WriteOpts::writeTrigger)) tree.disableBranch(m_l1id.name());
53}
54
55
56
57bool EventInfoBranch::fill(const EventContext& ctx) {
59 if (!evt_info.isValid()) {
60 ATH_MSG_ERROR("Could not retrieve the EventInfo " << m_key.fullKey());
61 return false;
62 }
63
64 m_evtNumber = evt_info->eventNumber();
65 m_runNumber = evt_info->runNumber();
66 m_lbNumber = evt_info->lumiBlock();
67 m_bcid = evt_info->bcid();
68
69 m_average_mu = evt_info->averageInteractionsPerCrossing();
70 m_actual_mu = evt_info->actualInteractionsPerCrossing();
72 m_l1id = evt_info->extendedLevel1ID();
73 }
75 m_mcChannel = evt_info->mcChannelNumber();
76 m_weight = evt_info->mcEventWeight(0);
77 const unsigned int n_weights = evt_info->mcEventWeights().size();
78 for (auto & [lhe_idx, lhe_branch] : m_lhe_weights) {
79 (*lhe_branch) = lhe_idx < n_weights ? evt_info->mcEventWeight(lhe_idx) : 0.;
80 }
81 }
83 m_prwWeight = acc_PuW(*evt_info);
84 m_rnd_run = acc_Random(*evt_info);
85 m_rnd_lumi_block = acc_LumiBlock(*evt_info);
86 }
88 m_beamSpotWeight = evt_info->beamSpotWeight();
89 }
90 return true;
91}
93 return declare_dependency(m_key) && std::find_if(m_prwKeys.begin(), m_prwKeys.end(),
94 [this](EvtInfoDecor& decor){
95 return !declare_dependency(decor);
96 }) == m_prwKeys.end();
97}
98}
#define ATH_MSG_ERROR(x)
Handle class for reading from StoreGate.
ScalarBranch< uint32_t > & m_mcChannel
###################################################################### Disabled if the job runs on da...
ScalarBranch< uint32_t > & m_rnd_lumi_block
ScalarBranch< float > & m_average_mu
Toggled by the Write PileUp flag.
bool init() override final
The init method checks whether the branch name has already registered to the MuonTree and tries then ...
EventInfoBranch(MuonTesterTree &tree, unsigned int write_mask, const std::string &evtKey="EventInfo")
static void setNumLHE(unsigned int numLHE) ATLAS_THREAD_SAFE
Specify the number of LHE variations that are available in the sample.
ScalarBranch< uint32_t > & m_rnd_run
ScalarBranch< double > & m_weight
Removed from output if writeLHE is switched on.
static unsigned int getNumLHE()
@ writePileUp
Write pile-up information.
@ writeTrigger
Write the trigger information.
@ writePRW
Write the corrected pile-up.
@ isMC
Flag determining whether the branch is simulation.
@ writeLHE
Write each of the LHE weights.
@ writeBeamSpot
Write the beamspot weight.
ScalarBranch< uint32_t > & m_runNumber
ScalarBranch< uint32_t > & m_bcid
std::vector< EvtInfoDecor > m_prwKeys
ScalarBranch< double > & m_prwWeight
Branches toggled by the write prw Flag.
bool fill(const EventContext &ctx) override final
The fill method checks if enough information is provided such that the branch is cleared from the inf...
ScalarBranch< unsigned long long > & m_evtNumber
std::map< unsigned int, std::shared_ptr< ScalarBranch< double > > > m_lhe_weights
ScalarBranch< float > & m_actual_mu
ScalarBranch< double > & m_beamSpotWeight
SG::ReadDecorHandleKey< xAOD::EventInfo > EvtInfoDecor
Access to the pile up weights if requested.
SG::ReadHandleKey< xAOD::EventInfo > m_key
Common access to the EventInfo.
ScalarBranch< uint32_t > & m_l1id
Toggled by the write trigger flag.
ScalarBranch< uint32_t > & m_lbNumber
MuonTesterBranch(MuonTesterTree &tree, const std::string &br_name)
bool declare_dependency(Key &key)
Declares the ReadHandle/ ReadCondHandleKey as data dependency of the algorithm.
TTree * tree() override final
Returns the underlying TTree object.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Class to store array like branches into the n-tuples.
Definition HitValAlg.cxx:19
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10