Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
InvariantMassTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // InvariantMassTool.cxx, (c) ATLAS Detector software
8 // Author: James Catmore (james.catmore@cern.ch)
9 //
10 
13 #include <vector>
14 #include <string>
15 
16 namespace DerivationFramework {
17 
19  const std::string& n,
20  const IInterface* p) :
21  base_class(t,n,p),
22  m_expression("true"),
23  m_expression2(""),
24  m_massHypothesis(0.0),
25  m_massHypothesis2(0.0)
26  {
27  declareProperty("ObjectRequirements", m_expression);
28  declareProperty("SecondObjectRequirements", m_expression2);
29  declareProperty("MassHypothesis", m_massHypothesis);
30  declareProperty("SecondMassHypothesis", m_massHypothesis2);
31  }
32 
34  {
35  if (m_sgName.key().empty()) {
36  ATH_MSG_ERROR("No SG name provided for the output of invariant mass tool!");
37  return StatusCode::FAILURE;
38  }
40 
42  ATH_CHECK(initializeParser({m_expression,m_expression2} ) );
43 
44  ATH_CHECK(m_containerName.initialize());
45  if (!m_containerName2.key().empty()) {
46  ATH_CHECK(m_containerName2.initialize());
47  }
48 
50 
51  return StatusCode::SUCCESS;
52  }
53 
55  {
56  ATH_CHECK( finalizeParser());
57  return StatusCode::SUCCESS;
58  }
59 
61  {
62  // Write masses to SG for access by downstream algs
63  if (evtStore()->contains<std::vector<float> >(m_sgName.key())) {
64  ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << m_sgName << " which already exists. Please use a different key");
65  return StatusCode::FAILURE;
66  }
67  std::unique_ptr<std::vector<float> > masses(new std::vector<float>());
69  //CHECK(evtStore()->record(std::move(masses), m_sgName));
71  ATH_CHECK(writeHandle.record(std::move(masses)));
72  return StatusCode::SUCCESS;
73  }
74 
76  {
77 
78  // check the relevant information is available
79  if (m_containerName.key().empty()) {
80  ATH_MSG_WARNING("Input container missing - returning zero");
81  masses->push_back(0.0);
82  return StatusCode::FAILURE;
83  }
84 
86 
87  bool from2Collections(false);
88  const xAOD::IParticleContainer* particles2{nullptr};
89  if (!m_containerName2.key().empty() && m_containerName2.key()!=m_containerName.key()) {
91  particles2=particleHdl2.cptr();
92  from2Collections = true;
93  }
94 
95  // get the positions of the elements which pass the requirement
96  std::vector<int> entries = m_parser[kInvariantMassToolParser1]->evaluateAsVector();
97  std::vector<int> entries2 = m_parser[kInvariantMassToolParser2]->evaluateAsVector();
98  unsigned int nEntries = entries.size();
99  unsigned int nEntries2 = entries2.size();
100 
101  // check the sizes are compatible
102  if (!from2Collections) {
103  if ( (particles->size() != nEntries) || (particles->size() != nEntries2) || (nEntries!=nEntries2) ) {
104  ATH_MSG_ERROR("Branch sizes incompatible - returning zero. Check your selection strings.");
105  masses->push_back(0.0);
106  return StatusCode::FAILURE;
107  }
108  }
109  if (from2Collections) {
110  if ( (particles->size() != nEntries) || (particles2->size() != nEntries2) ) {
111  ATH_MSG_ERROR("Branch sizes incompatible - returning zero. Check your selection strings.");
112  masses->push_back(0.0);
113  return StatusCode::FAILURE;
114  }
115  }
116 
117  // Double loop to get all possible index pairs
118  unsigned int outerIt, innerIt;
119  std::vector<std::vector<int> > pairs;
120  // Loop for case where both legs are from the same container
121  if (!from2Collections) {
122  for (outerIt=0; outerIt<nEntries; ++outerIt) {
123  for (innerIt=outerIt+1; innerIt<nEntries; ++innerIt) {
124  std::vector<int> tmpPair;
125  tmpPair.push_back(outerIt); tmpPair.push_back(innerIt);
126  pairs.push_back(tmpPair);
127  }
128  }
129  // Select the pairs for which the mass should be calculated, and then calculate it
130  std::vector<std::vector<int> >::iterator pairIt;
131  for (pairIt=pairs.begin(); pairIt!=pairs.end(); ++pairIt) {
132  unsigned int first = (*pairIt)[0];
133  unsigned int second = (*pairIt)[1];
134  if ( (entries[first]==1 && entries2[second]==1) || (entries2[first]==1 && entries[second]==1) ) {
135 
136  const float mass = calculateInvariantMass( ((*particles)[first])->p4().Vect(),
137  ((*particles)[second])->p4().Vect(),
140  masses->push_back(mass);
141  }
142  }
143  }
144 
145  // Loop for case where both legs are from different containers
146  if (from2Collections) {
147  for (outerIt=0; outerIt<nEntries; ++outerIt) {
148  if (entries[outerIt]==0) continue;
149  for (innerIt=0; innerIt<nEntries2; ++innerIt) {
150  if (entries2[innerIt]==0) continue;
151  std::vector<int> tmpPair;
152  tmpPair.push_back(outerIt); tmpPair.push_back(innerIt);
153  pairs.push_back(tmpPair);
154  }
155  }
156  // Select the pairs for which the mass should be calculated, and then calculate it
157  std::vector<std::vector<int> >::iterator pairIt;
158  for (pairIt=pairs.begin(); pairIt!=pairs.end(); ++pairIt) {
159  unsigned int first = (*pairIt)[0];
160  unsigned int second = (*pairIt)[1];
161  const float mass = calculateInvariantMass( ((*particles)[first])->p4().Vect(),
162  ((*particles2)[second])->p4().Vect(),
165  masses->push_back(mass);
166  }
167  }
168 
169  return StatusCode::SUCCESS;
170 
171  }
172  float InvariantMassTool::calculateInvariantMass(const TVector3& v1, const TVector3&v2,float M1,float M2) {
173  TLorentzVector p1(v1, M1 > 0 ? std::hypot(M1, v1.Mag()) : v1.Mag());
174  TLorentzVector p2(v2, M2 > 0 ? std::hypot(M2, v2.Mag()) : v2.Mag());
175  return (p1+p2).M();
176 
177  }
178 
179 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DerivationFramework::InvariantMassTool::InvariantMassTool
InvariantMassTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: InvariantMassTool.cxx:18
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
DerivationFramework::InvariantMassTool::m_containerName
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerName
Definition: InvariantMassTool.h:38
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
DerivationFramework::InvariantMassTool::getInvariantMasses
StatusCode getInvariantMasses(std::vector< float > *) const
Definition: InvariantMassTool.cxx:75
python.SystemOfUnits.second
float second
Definition: SystemOfUnits.py:134
DerivationFramework::InvariantMassTool::finalize
StatusCode finalize()
Definition: InvariantMassTool.cxx:54
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.CreateTierZeroArgdict.pairs
pairs
Definition: CreateTierZeroArgdict.py:201
DerivationFramework::InvariantMassTool::calculateInvariantMass
static float calculateInvariantMass(const TVector3 &v1, const TVector3 &v2, float M1, float M2)
Definition: InvariantMassTool.cxx:172
DerivationFramework::InvariantMassTool::initialize
StatusCode initialize()
Definition: InvariantMassTool.cxx:33
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
DerivationFramework::InvariantMassTool::m_expression2
std::string m_expression2
Definition: InvariantMassTool.h:35
DerivationFramework::InvariantMassTool::addBranches
virtual StatusCode addBranches() const
Definition: InvariantMassTool.cxx:60
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
InvariantMassTool.h
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
IParticleContainer.h
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
DerivationFramework::kInvariantMassToolParser2
@ kInvariantMassToolParser2
Definition: InvariantMassTool.h:24
DerivationFramework::InvariantMassTool::m_expression
std::string m_expression
Definition: InvariantMassTool.h:34
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::InvariantMassTool::m_containerName2
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerName2
Definition: InvariantMassTool.h:39
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ReadCellNoiseFromCoolCompare.v2
v2
Definition: ReadCellNoiseFromCoolCompare.py:364
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
DerivationFramework::InvariantMassTool::m_inputDecorNames
SG::ReadDecorHandleKeyArray< xAOD::IParticleContainer > m_inputDecorNames
Definition: InvariantMassTool.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DeMoScan.first
bool first
Definition: DeMoScan.py:536
DerivationFramework::InvariantMassTool::m_massHypothesis2
float m_massHypothesis2
Definition: InvariantMassTool.h:37
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
DerivationFramework::InvariantMassTool::m_massHypothesis
float m_massHypothesis
Definition: InvariantMassTool.h:37
entries
double entries
Definition: listroot.cxx:49
DerivationFramework::InvariantMassTool::m_sgName
SG::WriteHandleKey< std::vector< float > > m_sgName
Definition: InvariantMassTool.h:36
DerivationFramework::kInvariantMassToolParser1
@ kInvariantMassToolParser1
Definition: InvariantMassTool.h:24
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
SUSY_SimplifiedModel_PreInclude.masses
dictionary masses
Definition: SUSY_SimplifiedModel_PreInclude.py:7