ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DerivationFramework::EGInvariantMassTool Class Reference

#include <EGInvariantMassTool.h>

Inheritance diagram for DerivationFramework::EGInvariantMassTool:
Collaboration diagram for DerivationFramework::EGInvariantMassTool:

Public Member Functions

 EGInvariantMassTool (const std::string &t, const std::string &n, const IInterface *p)
 
virtual StatusCode initialize () override final
 
virtual StatusCode addBranches () const override final
 

Private Member Functions

StatusCode getInvariantMasses (const EventContext &ctx, std::vector< float > &) const
 

Private Attributes

std::string m_expression1
 
std::string m_expression2
 
SG::WriteHandleKey< std::vector< float > > m_sgName
 
SG::ReadHandleKey< xAOD::IParticleContainerm_container1Name
 
SG::ReadHandleKey< xAOD::IParticleContainerm_container2Name
 
SG::ReadHandleKey< std::vector< float > > m_pt1BranchName
 
SG::ReadHandleKey< std::vector< float > > m_eta1BranchName
 
SG::ReadHandleKey< std::vector< float > > m_phi1BranchName
 
SG::ReadHandleKey< std::vector< float > > m_pt2BranchName
 
SG::ReadHandleKey< std::vector< float > > m_eta2BranchName
 
SG::ReadHandleKey< std::vector< float > > m_phi2BranchName
 
float m_mass1Hypothesis
 
float m_mass2Hypothesis
 
float m_mindR
 
bool m_checkCharge
 
bool m_doTransverseMass
 

Detailed Description

Definition at line 31 of file EGInvariantMassTool.h.

Constructor & Destructor Documentation

◆ EGInvariantMassTool()

DerivationFramework::EGInvariantMassTool::EGInvariantMassTool ( const std::string &  t,
const std::string &  n,
const IInterface *  p 
)

Definition at line 21 of file EGInvariantMassTool.cxx.

24  : base_class(t, n, p)
25  , m_expression1("true")
26  , m_expression2("true")
27  , m_mass1Hypothesis(0.0)
28  , m_mass2Hypothesis(0.0)
29  , m_mindR(0.0)
30  , m_checkCharge(true)
31  , m_doTransverseMass(false)
32 {
33  declareProperty("Object1Requirements", m_expression1);
34  declareProperty("Object2Requirements", m_expression2);
35  declareProperty("Mass1Hypothesis", m_mass1Hypothesis);
36  declareProperty("Mass2Hypothesis", m_mass2Hypothesis);
37  declareProperty("CheckCharge", m_checkCharge);
38  declareProperty("MinDeltaR", m_mindR);
39  declareProperty("DoTransverseMass", m_doTransverseMass);
40 }

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::EGInvariantMassTool::addBranches ( ) const
finaloverridevirtual

Definition at line 82 of file EGInvariantMassTool.cxx.

83 {
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 }

◆ getInvariantMasses()

StatusCode DerivationFramework::EGInvariantMassTool::getInvariantMasses ( const EventContext &  ctx,
std::vector< float > &  masses 
) const
private

Definition at line 99 of file EGInvariantMassTool.cxx.

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>* eta1 = nullptr;
115  if (!m_eta1BranchName.key().empty()) {
117  eta1 = readHandle.ptr();
118  }
119  const std::vector<float>* eta2 = nullptr;
120  if (!m_eta2BranchName.key().empty()) {
122  eta2 = readHandle.ptr();
123  }
124 
125  const std::vector<float>* phi1 = nullptr;
126  if (!m_phi1BranchName.key().empty()) {
128  phi1 = readHandle.ptr();
129  }
130  const std::vector<float>* phi2 = nullptr;
131  if (!m_phi2BranchName.key().empty()) {
133  phi2 = readHandle.ptr();
134  }
135  // Get the input particles
137  ctx };
139  ctx };
140  const xAOD::IParticleContainer* particles1 = inputParticles1.ptr();
141  const xAOD::IParticleContainer* particles2 = inputParticles2.ptr();
142 
143  // get the positions of the elements which pass the requirement
144  std::vector<int> entries1 = m_parser[kParser1]->evaluateAsVector();
145  unsigned int nEntries1 = entries1.size();
146  std::vector<int> entries2 = m_parser[kParser2]->evaluateAsVector();
147  unsigned int nEntries2 = entries2.size();
148 
149  // if there are no particles in one of the two lists to combine,
150  // just leave the function
151  if (nEntries1 == 0 || nEntries2 == 0) {
152  return StatusCode::SUCCESS;
153  }
154 
155  // check the sizes are compatible
156  if (particles1->size() != nEntries1) {
157  ATH_MSG_ERROR("Branch sizes incompatible - returning zero");
158  return StatusCode::FAILURE;
159  }
160  if (particles2->size() != nEntries2) {
161  ATH_MSG_ERROR("Branch sizes incompatible - returning zero");
162  return StatusCode::FAILURE;
163  }
164  if ((pt1 && pt1->size() != nEntries1) ||
165  ((!m_doTransverseMass || (m_mindR > 0.0)) && eta1 &&
166  eta1->size() != nEntries1) ||
167  (phi1 && phi1->size() != nEntries1)) {
168  ATH_MSG_ERROR("Branch sizes incompatible - returning zero");
169  return StatusCode::FAILURE;
170  }
171  if ((pt2 && pt2->size() != nEntries2) ||
172  ((!m_doTransverseMass || (m_mindR > 0.0)) && eta2 &&
173  eta2->size() != nEntries2) ||
174  (phi2 && phi2->size() != nEntries2)) {
175  ATH_MSG_ERROR("Branch sizes incompatible - returning zero");
176  return StatusCode::FAILURE;
177  }
178 
179  // Double loop to get the pairs for which the mass should be calculated
180  unsigned int outerIt, innerIt;
181  std::vector<std::vector<int>> pairs;
182  for (outerIt = 0; outerIt < nEntries1; ++outerIt) {
183  for (innerIt = 0; innerIt < nEntries2; ++innerIt) {
184  std::vector<int> tmpPair;
185  if (entries1[outerIt] == 1 && entries2[innerIt] == 1) {
186  tmpPair.push_back(outerIt);
187  tmpPair.push_back(innerIt);
188  pairs.push_back(tmpPair);
189  }
190  }
191  }
192 
193  // since IParticle interface does not provide charge() method
194  // we need to identify the particle type in case we want to check
195  // its charge (through a type cast)
196  xAOD::Type::ObjectType type1 = xAOD::Type::Other;
197  xAOD::Type::ObjectType type2 = xAOD::Type::Other;
198  if (m_checkCharge) {
199  type1 = ((*particles1)[0])->type();
200  type2 = ((*particles2)[0])->type();
201  if ((type1 != xAOD::Type::Electron && type1 != xAOD::Type::Muon) ||
202  (type2 != xAOD::Type::Electron && type2 != xAOD::Type::Muon)) {
204  "Cannot check charge for particles not of type electron or muon");
205  return StatusCode::FAILURE;
206  }
207  }
208 
209  for (const auto& pair : pairs) {
210  unsigned int first = pair[0];
211  unsigned int second = pair[1];
212  float apt1 = pt1 ? (*pt1)[first] : ((*particles1)[first])->p4().Pt();
213  float apt2 = pt2 ? (*pt2)[second] : ((*particles2)[second])->p4().Pt();
214  float aeta1(-999.), aeta2(-999.);
215  if (!m_doTransverseMass || (m_mindR > 0.0)) {
216  aeta1 = eta1 ? (*eta1)[first] : ((*particles1)[first])->p4().Eta();
217  aeta2 = eta2 ? (*eta2)[second] : ((*particles2)[second])->p4().Eta();
218  }
219  float aphi1 = phi1 ? (*phi1)[first] : ((*particles1)[first])->p4().Phi();
220  float aphi2 = phi2 ? (*phi2)[second] : ((*particles2)[second])->p4().Phi();
221 
222  if (m_mindR > 0.0) {
223  float deta = aeta1 - aeta2;
224  float dphi = abs(aphi1 - aphi2);
225  if (dphi > TMath::Pi()) {
226  dphi = TMath::TwoPi() - dphi;
227  }
228  if (sqrt(deta * deta + dphi * dphi) < m_mindR) {
229  continue;
230  }
231  }
232 
233  if (m_checkCharge) {
234  float q1(0.), q2(0.);
235  if (type1 == xAOD::Type::Electron) {
236  q1 = ((xAOD::Electron*)((*particles1)[first]))->charge();
237  } else if (type1 == xAOD::Type::Muon) {
238  q1 = ((xAOD::Muon*)((*particles1)[first]))
239  ->primaryTrackParticle()
240  ->charge();
241  }
242  if (type2 == xAOD::Type::Electron) {
243  q2 = ((xAOD::Electron*)((*particles2)[second]))->charge();
244  } else if (type2 == xAOD::Type::Muon) {
245  q2 = ((xAOD::Muon*)((*particles2)[second]))
246  ->primaryTrackParticle()
247  ->charge();
248  }
249  if (q1 * q2 > 0.) {
250  continue;
251  }
252  }
253  TLorentzVector v1, v2, v;
254  if (m_doTransverseMass) {
255  v1.SetPtEtaPhiM(apt1, 0., aphi1, m_mass1Hypothesis);
256  v2.SetPtEtaPhiM(apt2, 0., aphi2, m_mass2Hypothesis);
257  } else {
258  v1.SetPtEtaPhiM(apt1, aeta1, aphi1, m_mass1Hypothesis);
259  v2.SetPtEtaPhiM(apt2, aeta2, aphi2, m_mass2Hypothesis);
260  }
261  float mass = (v1 + v2).M();
262  masses.push_back(mass);
263  }
264  return StatusCode::SUCCESS;
265 }

◆ initialize()

StatusCode DerivationFramework::EGInvariantMassTool::initialize ( )
finaloverridevirtual

Definition at line 43 of file EGInvariantMassTool.cxx.

44 {
45  if (m_sgName.key().empty()) {
46  ATH_MSG_ERROR("No SG name provided for the output of EGInvariantMassTool!");
47  return StatusCode::FAILURE;
48  }
50 
51  if (!m_container1Name.key().empty()) {
52  ATH_CHECK(m_container1Name.initialize());
53  }
54  if (!m_container2Name.key().empty()) {
55  ATH_CHECK(m_container2Name.initialize());
56  }
57  if (!m_pt1BranchName.key().empty()) {
59  }
60  if (!m_eta1BranchName.key().empty()) {
62  }
63  if (!m_phi1BranchName.key().empty()) {
65  }
66  if (!m_pt2BranchName.key().empty()) {
68  }
69  if (!m_eta2BranchName.key().empty()) {
71  }
72  if (!m_phi2BranchName.key().empty()) {
74  }
75 
76  ATH_CHECK(initializeParser({ m_expression1, m_expression2 }));
77 
78  return StatusCode::SUCCESS;
79 }

Member Data Documentation

◆ m_checkCharge

bool DerivationFramework::EGInvariantMassTool::m_checkCharge
private

Definition at line 108 of file EGInvariantMassTool.h.

◆ m_container1Name

SG::ReadHandleKey<xAOD::IParticleContainer> DerivationFramework::EGInvariantMassTool::m_container1Name
private
Initial value:
{
this,
"Container1Name",
"",
"SG key of first container"
}

Definition at line 51 of file EGInvariantMassTool.h.

◆ m_container2Name

SG::ReadHandleKey<xAOD::IParticleContainer> DerivationFramework::EGInvariantMassTool::m_container2Name
private
Initial value:
{
this,
"Container2Name",
"",
"SG key of second container"
}

Definition at line 57 of file EGInvariantMassTool.h.

◆ m_doTransverseMass

bool DerivationFramework::EGInvariantMassTool::m_doTransverseMass
private

Definition at line 109 of file EGInvariantMassTool.h.

◆ m_eta1BranchName

SG::ReadHandleKey<std::vector<float> > DerivationFramework::EGInvariantMassTool::m_eta1BranchName
private
Initial value:
{
this,
"Eta1BranchName",
"",
"Eta1 if different than default"
}

Definition at line 71 of file EGInvariantMassTool.h.

◆ m_eta2BranchName

SG::ReadHandleKey<std::vector<float> > DerivationFramework::EGInvariantMassTool::m_eta2BranchName
private
Initial value:
{
this,
"Eta2BranchName",
"",
"Eta2 if different than default"
}

Definition at line 92 of file EGInvariantMassTool.h.

◆ m_expression1

std::string DerivationFramework::EGInvariantMassTool::m_expression1
private

Definition at line 45 of file EGInvariantMassTool.h.

◆ m_expression2

std::string DerivationFramework::EGInvariantMassTool::m_expression2
private

Definition at line 45 of file EGInvariantMassTool.h.

◆ m_mass1Hypothesis

float DerivationFramework::EGInvariantMassTool::m_mass1Hypothesis
private

Definition at line 106 of file EGInvariantMassTool.h.

◆ m_mass2Hypothesis

float DerivationFramework::EGInvariantMassTool::m_mass2Hypothesis
private

Definition at line 106 of file EGInvariantMassTool.h.

◆ m_mindR

float DerivationFramework::EGInvariantMassTool::m_mindR
private

Definition at line 107 of file EGInvariantMassTool.h.

◆ m_phi1BranchName

SG::ReadHandleKey<std::vector<float> > DerivationFramework::EGInvariantMassTool::m_phi1BranchName
private
Initial value:
{
this,
"Phi1BranchName",
"",
"Phi1 if different than default"
}

Definition at line 78 of file EGInvariantMassTool.h.

◆ m_phi2BranchName

SG::ReadHandleKey<std::vector<float> > DerivationFramework::EGInvariantMassTool::m_phi2BranchName
private
Initial value:
{
this,
"Phi2BranchName",
"",
"Phi2 if different than default"
}

Definition at line 99 of file EGInvariantMassTool.h.

◆ m_pt1BranchName

SG::ReadHandleKey<std::vector<float> > DerivationFramework::EGInvariantMassTool::m_pt1BranchName
private
Initial value:
{
this,
"Pt1BranchName",
"",
"Pt1 if different than default"
}

Definition at line 64 of file EGInvariantMassTool.h.

◆ m_pt2BranchName

SG::ReadHandleKey<std::vector<float> > DerivationFramework::EGInvariantMassTool::m_pt2BranchName
private
Initial value:
{
this,
"Pt2BranchName",
"",
"Pt2 if different than default"
}

Definition at line 85 of file EGInvariantMassTool.h.

◆ m_sgName

SG::WriteHandleKey<std::vector<float> > DerivationFramework::EGInvariantMassTool::m_sgName
private
Initial value:
{ this,
"StoreGateEntryName",
"",
"SG key of output object" }

Definition at line 46 of file EGInvariantMassTool.h.


The documentation for this class was generated from the following files:
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
DerivationFramework::EGInvariantMassTool::m_phi1BranchName
SG::ReadHandleKey< std::vector< float > > m_phi1BranchName
Definition: EGInvariantMassTool.h:78
DerivationFramework::EGInvariantMassTool::m_mass1Hypothesis
float m_mass1Hypothesis
Definition: EGInvariantMassTool.h:106
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
ParticleGun_SamplingFraction.eta2
eta2
Definition: ParticleGun_SamplingFraction.py:96
DerivationFramework::EGInvariantMassTool::m_container2Name
SG::ReadHandleKey< xAOD::IParticleContainer > m_container2Name
Definition: EGInvariantMassTool.h:57
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
ObjectType
ObjectType
Definition: BaseObject.h:11
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework::kParser2
@ kParser2
Definition: EGInvariantMassTool.h:28
DerivationFramework::EGInvariantMassTool::m_doTransverseMass
bool m_doTransverseMass
Definition: EGInvariantMassTool.h:109
xAOD::eta1
setEt setPhi setE277 setWeta2 eta1
Definition: TrigEMCluster_v1.cxx:41
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
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
DerivationFramework::EGInvariantMassTool::m_expression2
std::string m_expression2
Definition: EGInvariantMassTool.h:45
DerivationFramework::kParser1
@ kParser1
Definition: EGInvariantMassTool.h:27
python.CreateTierZeroArgdict.pairs
pairs
Definition: CreateTierZeroArgdict.py:201
DerivationFramework::EGInvariantMassTool::m_expression1
std::string m_expression1
Definition: EGInvariantMassTool.h:45
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
DerivationFramework::EGInvariantMassTool::getInvariantMasses
StatusCode getInvariantMasses(const EventContext &ctx, std::vector< float > &) const
Definition: EGInvariantMassTool.cxx:99
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
DerivationFramework::EGInvariantMassTool::m_mindR
float m_mindR
Definition: EGInvariantMassTool.h:107
DerivationFramework::EGInvariantMassTool::m_mass2Hypothesis
float m_mass2Hypothesis
Definition: EGInvariantMassTool.h:106
DerivationFramework::EGInvariantMassTool::m_pt2BranchName
SG::ReadHandleKey< std::vector< float > > m_pt2BranchName
Definition: EGInvariantMassTool.h:85
DerivationFramework::EGInvariantMassTool::m_phi2BranchName
SG::ReadHandleKey< std::vector< float > > m_phi2BranchName
Definition: EGInvariantMassTool.h:99
xAOD::Electron_v1
Definition: Electron_v1.h:34
Muon
struct TBPatternUnitContext Muon
DerivationFramework::EGInvariantMassTool::m_checkCharge
bool m_checkCharge
Definition: EGInvariantMassTool.h:108
ReadCellNoiseFromCoolCompare.v2
v2
Definition: ReadCellNoiseFromCoolCompare.py:364
python.PyAthena.v
v
Definition: PyAthena.py:154
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
DerivationFramework::EGInvariantMassTool::m_pt1BranchName
SG::ReadHandleKey< std::vector< float > > m_pt1BranchName
Definition: EGInvariantMassTool.h:64
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DerivationFramework::EGInvariantMassTool::m_container1Name
SG::ReadHandleKey< xAOD::IParticleContainer > m_container1Name
Definition: EGInvariantMassTool.h:51
DeMoScan.first
bool first
Definition: DeMoScan.py:536
DerivationFramework::EGInvariantMassTool::m_eta1BranchName
SG::ReadHandleKey< std::vector< float > > m_eta1BranchName
Definition: EGInvariantMassTool.h:71
DerivationFramework::EGInvariantMassTool::m_eta2BranchName
SG::ReadHandleKey< std::vector< float > > m_eta2BranchName
Definition: EGInvariantMassTool.h:92
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DerivationFramework::EGInvariantMassTool::m_sgName
SG::WriteHandleKey< std::vector< float > > m_sgName
Definition: EGInvariantMassTool.h:46
SUSY_SimplifiedModel_PreInclude.masses
dictionary masses
Definition: SUSY_SimplifiedModel_PreInclude.py:7