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  const std::string& evtKey):
19  MuonTesterBranch{tree, " event info "},
20  m_key{evtKey},
21  m_writemask{write_mask}{
22  if (m_writemask & WriteOpts::isMC) {
23  if (m_writemask & WriteOpts::writeLHE) {
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());
35  m_writemask&= ~(WriteOpts::writePRW | WriteOpts::writeBeamSpot);
36  }
37 
38  if (m_writemask & WriteOpts::writePRW) {
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());
48  if (!(m_writemask & WriteOpts::writePileUp)) {
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 
57 bool 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();
71  if (m_writemask & WriteOpts::writeTrigger) {
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  }
82  if (m_writemask & WriteOpts::writePRW) {
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  }
87  if (m_writemask & WriteOpts::writeBeamSpot) {
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 }
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:57
throwExcept.h
MuonVal::EventInfoBranch::m_average_mu
ScalarBranch< float > & m_average_mu
Toggled by the Write PileUp flag.
Definition: EventInfoBranch.h:63
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:68
MuonVal::EventInfoBranch::EventInfoBranch
EventInfoBranch(MuonTesterTree &tree, unsigned int write_mask, const std::string &evtKey="EventInfo")
Definition: EventInfoBranch.cxx:17
MuonVal::EventInfoBranch::m_lbNumber
ScalarBranch< uint32_t > & m_lbNumber
Definition: EventInfoBranch.h:56
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
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:70
SG::AuxTypeRegistry::getName
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
Definition: AuxTypeRegistry.cxx:882
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:46
EventInfoBranch.h
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
THROW_EXCEPTION
#define THROW_EXCEPTION(MSG)
Definition: MMReadoutElement.cxx:48
MuonVal::EventInfoBranch::m_runNumber
ScalarBranch< uint32_t > & m_runNumber
Definition: EventInfoBranch.h:54
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:76
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:75
MuonVal::EventInfoBranch::m_actual_mu
ScalarBranch< float > & m_actual_mu
Definition: EventInfoBranch.h:64
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:60
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:74
MuonVal::EventInfoBranch::m_beamSpotWeight
ScalarBranch< double > & m_beamSpotWeight
Definition: EventInfoBranch.h:77
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:92
MuonVal::EventInfoBranch::m_evtNumber
ScalarBranch< unsigned long long > & m_evtNumber
Definition: EventInfoBranch.h:53
MuonVal::EventInfoBranch::m_prwKeys
std::vector< EvtInfoDecor > m_prwKeys
Definition: EventInfoBranch.h:49
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:50
MuonVal::EventInfoBranch::m_bcid
ScalarBranch< uint32_t > & m_bcid
Definition: EventInfoBranch.h:57
MuonVal::EventInfoBranch::m_lhe_weights
std::map< unsigned int, std::shared_ptr< ScalarBranch< double > > > m_lhe_weights
Definition: EventInfoBranch.h:71