ATLAS Offline Software
Loading...
Searching...
No Matches
JZCombineWeightNtupler.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9using Athena::Units::GeV;
10
11JZCombineWeightNtupler::JZCombineWeightNtupler(const std::string& name, ISvcLocator* pSvcLocator)
12 : RatesAnalysisAlg(name, pSvcLocator) {}
13
15
17 // Check and retrieve emulated triggers
18 ATH_CHECK(m_triggers.retrieve());
19
20 // Ntuple output
22 m_tree = new TTree("analysis", "Ntuple for JZ combine weight calculation");
23 m_tree->Branch("event_number", &m_event_number);
24 m_tree->Branch("weight_eb", &m_weight_eb);
25 m_tree->Branch("mu_actual", &m_mu_actual);
26 m_tree->Branch("pt_j0_AK4HS", &m_pt_j0_AK4HS);
27 m_tree->Branch("index_JZ", &m_index_JZ);
28 m_tree->Branch("n_pileup_records", &m_n_pileup_records);
29 m_tree->Branch("pt_j0_AK4PU", &m_pt_j0_AK4PU);
30 m_tree->Branch("pileup_event_number", &m_pileup_event_number);
32 ATH_CHECK(histSvc()->regTree("/RATESTREAM/analysis", m_tree));
33
34 // Set JZ index once
35 const xAOD::EventInfo* evt {nullptr};
36 ATH_CHECK(evtStore()->retrieve(evt, "EventInfo"));
37 m_index_JZ = evt->mcChannelNumber() - m_dsid_JZ0;
38
39 return StatusCode::SUCCESS;
40}
41
44
45 // Event level variables
46 const xAOD::EventInfo* evt {nullptr};
47 ATH_CHECK(evtStore()->retrieve(evt, "EventInfo"));
48
49 m_event_number = evt->eventNumber();
50 m_weight_eb = m_weightingValues.m_enhancedBiasWeight; // this is exactly MC weight for MC
51 m_mu_actual = std::ceil(evt->actualInteractionsPerCrossing()); // half integer to integer
52
53 // Truth jets are only valid for MC
54 bool isMC = evt->eventTypeBitmask() & xAOD::EventInfo::IS_SIMULATION;
55 if (isMC) {
56 // HS jets
57 const xAOD::JetContainer* hs_jets {nullptr};
58 ATH_CHECK(evtStore()->retrieve(hs_jets, m_jetCollectionHS));
59 if (hs_jets->size()) {
60 auto iter_jet = std::max_element(hs_jets->begin(), hs_jets->end(),
61 [](const xAOD::Jet* j0, const xAOD::Jet* j1){ return j0->pt() < j1->pt(); });
62 m_pt_j0_AK4HS = (*iter_jet)->pt() / GeV;
63 }
64
65 // PU jets
66 const xAOD::JetContainer* pu_jets {nullptr};
67 ATH_CHECK(evtStore()->retrieve(pu_jets, m_jetCollectionPU));
68 std::unordered_map<int, double> leading_pts;
69 if (pu_jets->size()) {
70 for (const xAOD::Jet* pu_jet : *pu_jets) {
71 SG::ConstAccessor<int> pu_enum_acc("pileupEventNumber");
72 const uint32_t pu_enum = static_cast<uint32_t>(pu_enum_acc.withDefault(*pu_jet, 0));
73 double pu_jet_pt = pu_jet->pt() / GeV;
74 if (!leading_pts.contains(pu_enum) || leading_pts.at(pu_enum) < pu_jet_pt) {
75 leading_pts[pu_enum] = pu_jet_pt;
76 }
77 }
78 }
79 m_n_pileup_records = leading_pts.size();
80
81 for (const auto& [pu_enum, pu_jet_pt] : leading_pts) {
82 m_pt_j0_AK4PU.push_back(pu_jet_pt);
83 m_pileup_event_number.push_back(pu_enum);
84 }
85 }
86
87 // Add extra branches for emulated triggers if required
89
90 m_tree->Fill();
91 return StatusCode::SUCCESS;
92}
93
95 return StatusCode::SUCCESS;
96}
97
99 for (auto& trigger : m_triggers) {
100 const std::string& name = trigger->branchName();
101 if (m_thresholds.contains(name)) {
102 ATH_MSG_WARNING(name << " already exists! Will skip");
103 continue;
104 }
105 ATH_MSG_INFO("Add new branch - " << name);
106 m_tree->Branch(name.c_str(), &m_thresholds[name]);
107 }
108 return StatusCode::SUCCESS;
109}
110
112 for (auto& trigger : m_triggers) {
113 const std::string& name = trigger->branchName();
114 ATH_CHECK(trigger->updateThresholdValue());
115 if (!m_thresholds.contains(name)) {
116 ATH_MSG_ERROR(name << " does not exist! Please check `Triggers`!");
117 return StatusCode::FAILURE;
118 }
119 m_thresholds.at(name) = trigger->thresholdValue();
120 }
121 return StatusCode::SUCCESS;
122}
123
125 m_event_number = 0;
126 m_weight_eb = 1.0;
127 m_mu_actual = 0.0;
128 m_pt_j0_AK4HS = 5.0; // GeV, JETMiss example uses this value
130 m_pt_j0_AK4PU.clear();
131 m_pileup_event_number.clear();
132 return StatusCode::SUCCESS;
133}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
Wrapper to avoid constant divisions when using units.
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual StatusCode ratesInitialize() override
To be implemented by the user.
JZCombineWeightNtupler(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode ratesExecute() override
To be implemented by the user.
ToolHandleArray< IEmulatedTrigger > m_triggers
User can extend the output tree with customised emulated triggers.
Gaudi::Property< std::string > m_jetCollectionPU
std::vector< uint32_t > m_pileup_event_number
virtual StatusCode ratesFinalize() override
To be implemented by the user.
Gaudi::Property< std::string > m_jetCollectionHS
std::unordered_map< std::string, double > m_thresholds
std::vector< double > m_pt_j0_AK4PU
Gaudi::Property< uint32_t > m_dsid_JZ0
RatesAnalysisAlg(const std::string &name, ISvcLocator *pSvcLocator)
WeightingValuesSummary_t m_weightingValues
Possible weighting & lumi extrapolation values for the current event.
Helper class to provide constant type-safe access to aux data.
const_reference_type withDefault(const ELT &e, const T &deflt) const
Fetch the variable for one element, as a const reference, with a default.
@ IS_SIMULATION
true: simulation, false: data
Jet_v1 Jet
Definition of the current "jet version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
JetContainer_v1 JetContainer
Definition of the current "jet container version".