ATLAS Offline Software
EGTransverseMassTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // EGTransverseMassTool.cxx, (c) ATLAS Detector software
7 // Author: Giovanni Marchiori (giovanni.marchiori@cern.ch)
8 //
9 // The tool computes the transverse mass between the MET and the
10 // particles belonging to some collection.
11 // The MET met and phi values can either be stored in SG under
12 // keys specified with METPtBranchName and METPhiBranchName,
13 // otherwise the met() and phi() of the MET object stored in
14 // SG under the METContainerName (default = MET_LocHadTopo)
15 // will be used.
16 // A MET>METmin cut can be applied.
17 // For the particles, only those passing the ObjectRequirements
18 // selection are retained. Their pt and phi can be stored
19 // in SG under keys specified with ObjectPtBranchName and
20 // ObjectPhiBranchName, otherwise the Pt() and Phi() methods
21 // of the IParticles object of the containred stored in SG
22 // with the key specified by ObjectContainerName will be used
24 
26 
27 #include <cmath>
28 using std::abs;
29 using std::sqrt;
30 
31 #include "TLorentzVector.h"
32 
33 namespace DerivationFramework {
34 
36  const std::string& n,
37  const IInterface* p)
38  : base_class(t, n, p)
39  , m_expression1("true")
40  , m_METmin(-999.)
41  , m_mass1Hypothesis(0.0)
42 {
43  declareProperty("ObjectRequirements", m_expression1);
44  declareProperty("METmin", m_METmin);
45  declareProperty("ObjectMassHypothesis", m_mass1Hypothesis);
46 }
47 
50 {
51  if (m_sgName.key().empty()) {
53  "No SG name provided for the output of the transverse mass tool!");
54  return StatusCode::FAILURE;
55  }
57 
58  if (!m_container1Name.key().empty()) {
59  ATH_CHECK(m_container1Name.initialize());
60  }
61  if (!m_container2Name.key().empty()) {
62  ATH_CHECK(m_container2Name.initialize());
63  }
64  if (!m_pt1BranchName.key().empty()) {
66  }
67  if (!m_phi1BranchName.key().empty()) {
69  }
70  if (!m_pt2BranchName.key().empty()) {
72  }
73  if (!m_phi2BranchName.key().empty()) {
75  }
76 
77  ATH_CHECK(initializeParser(m_expression1));
78 
79  return StatusCode::SUCCESS;
80 }
81 
84 {
85  const EventContext& ctx = Gaudi::Hive::currentContext();
86  SG::WriteHandle<std::vector<float>> writeHandle{ m_sgName, ctx };
87 
88  // create the vector which will hold the values invariant masses
89  auto masses = std::make_unique<std::vector<float>>();
90  // compute the invariant mass values
92 
93  ATH_CHECK(writeHandle.record(std::move(masses)));
94 
95  return StatusCode::SUCCESS;
96 }
97 
100  std::vector<float>& masses) const
101 {
102  // Get optional payload
103  const std::vector<float>* pt1 = nullptr;
104  if (!m_pt1BranchName.key().empty()) {
106  pt1 = readHandle.ptr();
107  }
108  const std::vector<float>* pt2 = nullptr;
109  if (!m_pt2BranchName.key().empty()) {
111  pt2 = readHandle.ptr();
112  }
113 
114  const std::vector<float>* phi1 = nullptr;
115  if (!m_phi1BranchName.key().empty()) {
117  phi1 = readHandle.ptr();
118  }
119  const std::vector<float>* phi2 = nullptr;
120  if (!m_phi2BranchName.key().empty()) {
122  phi2 = readHandle.ptr();
123  }
124 
125  // Get the input particle and MET
127  ctx };
129  ctx };
130  const xAOD::IParticleContainer* particles1 = inputParticles1.ptr();
131  const xAOD::MissingETContainer* particles2 = inputParticles2.ptr();
132 
133  // compute MET
134  if (particles2->empty()) {
135  if (!pt2) {
136  ATH_MSG_WARNING("No MET info found");
137  return StatusCode::SUCCESS;
138  }
139  if (pt2->empty()) {
140  ATH_MSG_WARNING("No MET info found");
141  return StatusCode::SUCCESS;
142  }
143  }
144 
145  float MET = pt2 ? (*pt2)[0] : particles2->at(0)->met();
146  float MET_phi = phi2 ? (*phi2)[0] : particles2->at(0)->phi();
147 
148  // apply MET requirement
149  if (MET < m_METmin)
150  return StatusCode::SUCCESS;
151 
152  // get the positions of the particles which pass the requirement
153  std::vector<int> entries1 = m_parser->evaluateAsVector();
154  unsigned int nEntries1 = entries1.size();
155 
156  // if there are no particles in one of the two lists to combine, just leave
157  // function
158  if (nEntries1 == 0)
159  return StatusCode::SUCCESS;
160 
161  // check that the sizes are compatible
162  if (particles1->size() != nEntries1) {
163  ATH_MSG_ERROR("Branch sizes incompatible - returning zero");
164  return StatusCode::FAILURE;
165  }
166  if ((pt1 && pt1->size() != nEntries1) ||
167  (phi1 && phi1->size() != nEntries1)) {
168  ATH_MSG_ERROR("Branch sizes incompatible - returning zero");
169  return StatusCode::FAILURE;
170  }
171 
172  // Loop over the objects and calculate the transverse mass
173  unsigned int iter;
174  for (iter = 0; iter < nEntries1; ++iter) {
175  if (entries1[iter] != 1)
176  continue;
177  float apt1 = pt1 ? (*pt1)[iter] : ((*particles1)[iter])->p4().Pt();
178  float aphi1 = phi1 ? (*phi1)[iter] : ((*particles1)[iter])->p4().Phi();
179 
180  TLorentzVector v1, v2;
181  v1.SetPtEtaPhiM(apt1, 0., aphi1, m_mass1Hypothesis);
182  v2.SetPtEtaPhiM(MET, 0., MET_phi, 0.);
183  float mass = (v1 + v2).M();
184  masses.push_back(mass);
185  }
186  return StatusCode::SUCCESS;
187 }
188 }
DerivationFramework::EGTransverseMassTool::m_METmin
float m_METmin
Definition: EGTransverseMassTool.h:43
createLinkingScheme.iter
iter
Definition: createLinkingScheme.py:62
EGTransverseMassTool.h
DerivationFramework::EGTransverseMassTool::m_container1Name
SG::ReadHandleKey< xAOD::IParticleContainer > m_container1Name
Definition: EGTransverseMassTool.h:51
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework::EGTransverseMassTool::m_pt1BranchName
SG::ReadHandleKey< std::vector< float > > m_pt1BranchName
Definition: EGTransverseMassTool.h:64
DerivationFramework::EGTransverseMassTool::m_mass1Hypothesis
float m_mass1Hypothesis
Definition: EGTransverseMassTool.h:44
DerivationFramework::EGTransverseMassTool::m_phi2BranchName
SG::ReadHandleKey< std::vector< float > > m_phi2BranchName
Definition: EGTransverseMassTool.h:85
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
DerivationFramework::EGTransverseMassTool::getTransverseMasses
StatusCode getTransverseMasses(const EventContext &ctx, std::vector< float > &) const
Definition: EGTransverseMassTool.cxx:99
DerivationFramework::EGTransverseMassTool::m_container2Name
SG::ReadHandleKey< xAOD::MissingETContainer > m_container2Name
Definition: EGTransverseMassTool.h:57
DerivationFramework::EGTransverseMassTool::m_expression1
std::string m_expression1
Definition: EGTransverseMassTool.h:42
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:729
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::EGTransverseMassTool::addBranches
virtual StatusCode addBranches() const override final
Definition: EGTransverseMassTool.cxx:83
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DerivationFramework::EGTransverseMassTool::EGTransverseMassTool
EGTransverseMassTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: EGTransverseMassTool.cxx:35
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
DerivationFramework::EGTransverseMassTool::m_sgName
SG::WriteHandleKey< std::vector< float > > m_sgName
Definition: EGTransverseMassTool.h:46
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
MET
Definition: MET.py:1
DerivationFramework::EGTransverseMassTool::initialize
virtual StatusCode initialize() override final
Definition: EGTransverseMassTool.cxx:49
ReadCellNoiseFromCoolCompare.v2
v2
Definition: ReadCellNoiseFromCoolCompare.py:364
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
DerivationFramework::EGTransverseMassTool::m_phi1BranchName
SG::ReadHandleKey< std::vector< float > > m_phi1BranchName
Definition: EGTransverseMassTool.h:71
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
SUSY_SimplifiedModel_PreInclude.masses
dictionary masses
Definition: SUSY_SimplifiedModel_PreInclude.py:7
DerivationFramework::EGTransverseMassTool::m_pt2BranchName
SG::ReadHandleKey< std::vector< float > > m_pt2BranchName
Definition: EGTransverseMassTool.h:78