ATLAS Offline Software
EventInfoBranch.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
5 #include <StoreGate/ReadHandle.h>
7 #include <stdexcept>
8 namespace {
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 }
13 namespace MuonVal {
14 std::atomic<unsigned int> EventInfoBranch::s_num_lhe = 0;
15 void EventInfoBranch::setNumLHE(unsigned int n) { s_num_lhe = n;}
16 unsigned int EventInfoBranch::getNumLHE() { return s_num_lhe;}
18  MuonTesterBranch{tree, " event info "},
19  m_writemask{write_mask} {
20  if (m_writemask & WriteOpts::isMC) {
21  if (m_writemask & WriteOpts::writeLHE) {
22  for (unsigned int lhe = 1; lhe < s_num_lhe ; ++lhe ) {
23  std::shared_ptr<ScalarBranch<double>>& new_br = m_lhe_weights[lhe];
24  new_br = std::make_shared<ScalarBranch<double>>(tree.tree(), "mcEventWeight_LHE_" + std::to_string(lhe),0.);
25  if (!tree.addBranch(new_br)) {
26  THROW_EXCEPTION("EventInfoBranch: Failed to create Scalar branch in c'tor");
27  }
28  }
29  }
30  } else {
31  tree.disableBranch(m_mcChannel.name());
32  tree.disableBranch(m_weight.name());
33  m_writemask&= ~(WriteOpts::writePRW | WriteOpts::writeBeamSpot);
34  }
35 
36  if (m_writemask & WriteOpts::writePRW) {
37  m_prwKeys.emplace_back(m_key.key() + "." + SG::AuxTypeRegistry::instance().getName(acc_Random.auxid()));
38  m_prwKeys.emplace_back(m_key.key() + "." + SG::AuxTypeRegistry::instance().getName(acc_LumiBlock.auxid()));
39  m_prwKeys.emplace_back(m_key.key() + "." + SG::AuxTypeRegistry::instance().getName(acc_PuW.auxid()));
40  } else {
41  tree.disableBranch(m_prwWeight.name());
42  tree.disableBranch(m_rnd_run.name());
43  tree.disableBranch(m_rnd_lumi_block.name());
44  }
45  if (!(m_writemask & WriteOpts::writeBeamSpot)) tree.disableBranch(m_beamSpotWeight.name());
46  if (!(m_writemask & WriteOpts::writePileUp)) {
47  tree.disableBranch(m_average_mu.name());
48  tree.disableBranch(m_actual_mu.name());
49  }
50  if (!(m_writemask & WriteOpts::writeTrigger)) tree.disableBranch(m_l1id.name());
51 }
52 
53 
54 
55 bool EventInfoBranch::fill(const EventContext& ctx) {
57  if (!evt_info.isValid()) {
58  ATH_MSG_ERROR("Could not retrieve the EventInfo " << m_key.fullKey());
59  return false;
60  }
61 
62  m_evtNumber = evt_info->eventNumber();
63  m_runNumber = evt_info->runNumber();
64  m_lbNumber = evt_info->lumiBlock();
65  m_bcid = evt_info->bcid();
66 
67  m_average_mu = evt_info->averageInteractionsPerCrossing();
68  m_actual_mu = evt_info->actualInteractionsPerCrossing();
69  if (m_writemask & WriteOpts::writeTrigger) {
70  m_l1id = evt_info->extendedLevel1ID();
71  }
73  m_mcChannel = evt_info->mcChannelNumber();
74  m_weight = evt_info->mcEventWeight(0);
75  const unsigned int n_weights = evt_info->mcEventWeights().size();
76  for (auto & [lhe_idx, lhe_branch] : m_lhe_weights) {
77  (*lhe_branch) = lhe_idx < n_weights ? evt_info->mcEventWeight(lhe_idx) : 0.;
78  }
79  }
80  if (m_writemask & WriteOpts::writePRW) {
81  m_prwWeight = acc_PuW(*evt_info);
82  m_rnd_run = acc_Random(*evt_info);
83  m_rnd_lumi_block = acc_LumiBlock(*evt_info);
84  }
85  if (m_writemask & WriteOpts::writeBeamSpot) {
86  m_beamSpotWeight = evt_info->beamSpotWeight();
87  }
88  return true;
89 }
91  return declare_dependency(m_key) && std::find_if(m_prwKeys.begin(), m_prwKeys.end(),
92  [this](EvtInfoDecor& decor){
93  return !declare_dependency(decor);
94  }) == m_prwKeys.end();
95 }
96 }
MuonVal::EventInfoBranch::fill
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...
Definition: EventInfoBranch.cxx:55
throwExcept.h
MuonVal::EventInfoBranch::m_average_mu
ScalarBranch< float > & m_average_mu
Toggled by the Write PileUp flag.
Definition: EventInfoBranch.h:62
MuonVal::EventInfoBranch::setNumLHE
static void setNumLHE(unsigned int numLHE) ATLAS_THREAD_SAFE
Specify the number of LHE variations that are available in the sample.
Definition: EventInfoBranch.cxx:15
MuonVal::EventInfoBranch::m_mcChannel
ScalarBranch< uint32_t > & m_mcChannel
Definition: EventInfoBranch.h:67
MuonVal::EventInfoBranch::m_lbNumber
ScalarBranch< uint32_t > & m_lbNumber
Definition: EventInfoBranch.h:55
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:49
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonVal::EventInfoBranch::m_weight
ScalarBranch< double > & m_weight
Removed from output if writeLHE is switched on.
Definition: EventInfoBranch.h:69
SG::AuxTypeRegistry::getName
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
Definition: AuxTypeRegistry.cxx:277
MuonVal::MuonTesterBranch
Definition: MuonTesterBranch.h:21
tree
TChain * tree
Definition: tile_monitor.h:30
test_athena_ntuple_filter.evt_info
evt_info
Definition: test_athena_ntuple_filter.py:24
MuonVal::EventInfoBranch::m_key
SG::ReadHandleKey< xAOD::EventInfo > m_key
Common access to the EventInfo.
Definition: EventInfoBranch.h:45
EventInfoBranch.h
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
MuonVal::EventInfoBranch::EventInfoBranch
EventInfoBranch(MuonTesterTree &tree, unsigned int write_mask)
Definition: EventInfoBranch.cxx:17
THROW_EXCEPTION
#define THROW_EXCEPTION(MSG)
Definition: MMReadoutElement.cxx:48
MuonVal::EventInfoBranch::m_runNumber
ScalarBranch< uint32_t > & m_runNumber
Definition: EventInfoBranch.h:53
MuonVal::MuonTesterBranch::tree
TTree * tree() override final
Returns the underlying TTree object.
Definition: MuonTesterBranch.cxx:53
MuonVal::MuonTesterBranch::declare_dependency
bool declare_dependency(Key &key)
Declares the ReadHandle/ ReadCondHandleKey as data dependency of the algorithm.
MuonVal::EventInfoBranch::m_rnd_lumi_block
ScalarBranch< uint32_t > & m_rnd_lumi_block
Definition: EventInfoBranch.h:75
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonVal::MuonTesterTree
Definition: MuonTesterTree.h:30
beamspotman.n
n
Definition: beamspotman.py:731
MuonVal::EventInfoBranch::m_rnd_run
ScalarBranch< uint32_t > & m_rnd_run
Definition: EventInfoBranch.h:74
MuonVal::EventInfoBranch::m_actual_mu
ScalarBranch< float > & m_actual_mu
Definition: EventInfoBranch.h:63
MuonVal
Class to store array like branches into the n-tuples.
Definition: MuonTPMetaDataAlg.cxx:25
MuonVal::EventInfoBranch::m_l1id
ScalarBranch< uint32_t > & m_l1id
Toggled by the write trigger flag.
Definition: EventInfoBranch.h:59
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
MuonVal::EventInfoBranch::m_prwWeight
ScalarBranch< double > & m_prwWeight
Branches toggled by the write prw Flag.
Definition: EventInfoBranch.h:73
MuonVal::EventInfoBranch::m_beamSpotWeight
ScalarBranch< double > & m_beamSpotWeight
Definition: EventInfoBranch.h:76
MuonVal::EventInfoBranch::init
bool init() override final
The init method checks whether the branch name has already registered to the MuonTree and tries then ...
Definition: EventInfoBranch.cxx:90
MuonVal::EventInfoBranch::m_evtNumber
ScalarBranch< unsigned long long > & m_evtNumber
Definition: EventInfoBranch.h:52
MuonVal::EventInfoBranch::m_prwKeys
std::vector< EvtInfoDecor > m_prwKeys
Definition: EventInfoBranch.h:48
EventInfoRead.isMC
isMC
Definition: EventInfoRead.py:11
ReadHandle.h
Handle class for reading from StoreGate.
SG::ReadDecorHandleKey
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Definition: StoreGate/StoreGate/ReadDecorHandleKey.h:85
MuonVal::EventInfoBranch::getNumLHE
static unsigned int getNumLHE()
Definition: EventInfoBranch.cxx:16
MuonVal::EventInfoBranch::m_writemask
unsigned int m_writemask
Definition: EventInfoBranch.h:49
MuonVal::EventInfoBranch::m_bcid
ScalarBranch< uint32_t > & m_bcid
Definition: EventInfoBranch.h:56
MuonVal::EventInfoBranch::m_lhe_weights
std::map< unsigned int, std::shared_ptr< ScalarBranch< double > > > m_lhe_weights
Definition: EventInfoBranch.h:70