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

#include <InvariantMassTool.h>

Inheritance diagram for DerivationFramework::InvariantMassTool:
Collaboration diagram for DerivationFramework::InvariantMassTool:

Public Member Functions

 InvariantMassTool (const std::string &t, const std::string &n, const IInterface *p)
 
StatusCode initialize ()
 
StatusCode finalize ()
 
virtual StatusCode addBranches (const EventContext &ctx) const
 

Private Member Functions

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

Static Private Member Functions

static float calculateInvariantMass (const TVector3 &v1, const TVector3 &v2, float M1, float M2)
 

Private Attributes

std::string m_expression
 
std::string m_expression2
 
SG::WriteHandleKey< std::vector< float > > m_sgName {this,"StoreGateEntryName","","SG key of output object"}
 
float m_massHypothesis
 
float m_massHypothesis2
 
SG::ReadHandleKey< xAOD::IParticleContainerm_containerName {this,"ContainerName","","SG key of first container"}
 
SG::ReadHandleKey< xAOD::IParticleContainerm_containerName2 {this,"SecondContainerName","","SG key of second container"}
 
SG::ReadDecorHandleKeyArray< xAOD::IParticleContainerm_inputDecorNames {this, "InputDecorNames",{},"SG keys for decorations of first (and second) container(s)"}
 

Detailed Description

Definition at line 30 of file InvariantMassTool.h.

Constructor & Destructor Documentation

◆ InvariantMassTool()

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

Definition at line 17 of file InvariantMassTool.cxx.

19  :
20  base_class(t,n,p),
21  m_expression("true"),
22  m_expression2(""),
23  m_massHypothesis(0.0),
25  {
26  declareProperty("ObjectRequirements", m_expression);
27  declareProperty("SecondObjectRequirements", m_expression2);
28  declareProperty("MassHypothesis", m_massHypothesis);
29  declareProperty("SecondMassHypothesis", m_massHypothesis2);
30  }

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::InvariantMassTool::addBranches ( const EventContext &  ctx) const
virtual

Definition at line 59 of file InvariantMassTool.cxx.

60  {
61  // Write masses to SG for access by downstream algs
62  if (evtStore()->contains<std::vector<float> >(m_sgName.key())) {
63  ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << m_sgName << " which already exists. Please use a different key");
64  return StatusCode::FAILURE;
65  }
66  std::unique_ptr<std::vector<float> > masses(new std::vector<float>());
67  ATH_CHECK(getInvariantMasses(masses.get(), ctx));
68  //CHECK(evtStore()->record(std::move(masses), m_sgName));
69  SG::WriteHandle<std::vector<float> > writeHandle(m_sgName, ctx);
70  ATH_CHECK(writeHandle.record(std::move(masses)));
71  return StatusCode::SUCCESS;
72  }

◆ calculateInvariantMass()

float DerivationFramework::InvariantMassTool::calculateInvariantMass ( const TVector3 &  v1,
const TVector3 &  v2,
float  M1,
float  M2 
)
staticprivate

Definition at line 160 of file InvariantMassTool.cxx.

160  {
161  TLorentzVector p1(v1, M1 > 0 ? std::hypot(M1, v1.Mag()) : v1.Mag());
162  TLorentzVector p2(v2, M2 > 0 ? std::hypot(M2, v2.Mag()) : v2.Mag());
163  return (p1+p2).M();
164 
165  }

◆ finalize()

StatusCode DerivationFramework::InvariantMassTool::finalize ( )

Definition at line 53 of file InvariantMassTool.cxx.

54  {
55  ATH_CHECK( finalizeParser());
56  return StatusCode::SUCCESS;
57  }

◆ getInvariantMasses()

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

Definition at line 74 of file InvariantMassTool.cxx.

75  {
76 
77  // check the relevant information is available
78  if (m_containerName.key().empty()) {
79  ATH_MSG_WARNING("Input container missing - returning zero");
80  masses->push_back(0.0);
81  return StatusCode::FAILURE;
82  }
83 
85 
86  bool from2Collections(false);
87  const xAOD::IParticleContainer* particles2{nullptr};
88  if (!m_containerName2.key().empty() && m_containerName2.key()!=m_containerName.key()) {
90  particles2=particleHdl2.cptr();
91  from2Collections = true;
92  }
93 
94  // get the positions of the elements which pass the requirement
95  std::vector<int> entries = m_parser[kInvariantMassToolParser1]->evaluateAsVector();
96  std::vector<int> entries2 = m_parser[kInvariantMassToolParser2]->evaluateAsVector();
97  unsigned int nEntries = entries.size();
98  unsigned int nEntries2 = entries2.size();
99 
100  // check the sizes are compatible
101  if (!from2Collections) {
102  if ( (particles->size() != nEntries) || (particles->size() != nEntries2) || (nEntries!=nEntries2) ) {
103  ATH_MSG_ERROR("Branch sizes incompatible - returning zero. Check your selection strings.");
104  masses->push_back(0.0);
105  return StatusCode::FAILURE;
106  }
107  }
108  if (from2Collections) {
109  if ( (particles->size() != nEntries) || (particles2->size() != nEntries2) ) {
110  ATH_MSG_ERROR("Branch sizes incompatible - returning zero. Check your selection strings.");
111  masses->push_back(0.0);
112  return StatusCode::FAILURE;
113  }
114  }
115 
116  // Double loop to get all possible index pairs
117  unsigned int outerIt, innerIt;
118  std::vector<std::pair<int, int> > pairs;
119  // Loop for case where both legs are from the same container
120  if (!from2Collections) {
121  for (outerIt=0; outerIt<nEntries; ++outerIt) {
122  for (innerIt=outerIt+1; innerIt<nEntries; ++innerIt) {
123  pairs.push_back({static_cast<int>(outerIt),static_cast<int>(innerIt)});
124  }
125  }
126  // Select the pairs for which the mass should be calculated, and then calculate it
127  for (const auto & [first, second]: pairs) {
128  if ( (entries[first]==1 && entries2[second]==1) || (entries2[first]==1 && entries[second]==1) ) {
129  const float mass = calculateInvariantMass( ((*particles)[first])->p4().Vect(),
130  ((*particles)[second])->p4().Vect(),
133  masses->push_back(mass);
134  }
135  }
136  }
137 
138  // Loop for case where both legs are from different containers
139  if (from2Collections) {
140  for (outerIt=0; outerIt<nEntries; ++outerIt) {
141  if (entries[outerIt]==0) continue;
142  for (innerIt=0; innerIt<nEntries2; ++innerIt) {
143  if (entries2[innerIt]==0) continue;
144  pairs.push_back({static_cast<int>(outerIt),static_cast<int>(innerIt)});
145  }
146  }
147  // Select the pairs for which the mass should be calculated, and then calculate it
148  for (const auto & [first, second]: pairs) {
149  const float mass = calculateInvariantMass( ((*particles)[first])->p4().Vect(),
150  ((*particles2)[second])->p4().Vect(),
153  masses->push_back(mass);
154  }
155  }
156 
157  return StatusCode::SUCCESS;
158 
159  }

◆ initialize()

StatusCode DerivationFramework::InvariantMassTool::initialize ( )

Definition at line 32 of file InvariantMassTool.cxx.

33  {
34  if (m_sgName.key().empty()) {
35  ATH_MSG_ERROR("No SG name provided for the output of invariant mass tool!");
36  return StatusCode::FAILURE;
37  }
39 
41  ATH_CHECK(initializeParser({m_expression,m_expression2} ) );
42 
43  ATH_CHECK(m_containerName.initialize());
44  if (!m_containerName2.key().empty()) {
45  ATH_CHECK(m_containerName2.initialize());
46  }
47 
49 
50  return StatusCode::SUCCESS;
51  }

Member Data Documentation

◆ m_containerName

SG::ReadHandleKey<xAOD::IParticleContainer> DerivationFramework::InvariantMassTool::m_containerName {this,"ContainerName","","SG key of first container"}
private

Definition at line 43 of file InvariantMassTool.h.

◆ m_containerName2

SG::ReadHandleKey<xAOD::IParticleContainer> DerivationFramework::InvariantMassTool::m_containerName2 {this,"SecondContainerName","","SG key of second container"}
private

Definition at line 44 of file InvariantMassTool.h.

◆ m_expression

std::string DerivationFramework::InvariantMassTool::m_expression
private

Definition at line 39 of file InvariantMassTool.h.

◆ m_expression2

std::string DerivationFramework::InvariantMassTool::m_expression2
private

Definition at line 40 of file InvariantMassTool.h.

◆ m_inputDecorNames

SG::ReadDecorHandleKeyArray<xAOD::IParticleContainer> DerivationFramework::InvariantMassTool::m_inputDecorNames {this, "InputDecorNames",{},"SG keys for decorations of first (and second) container(s)"}
private

Definition at line 45 of file InvariantMassTool.h.

◆ m_massHypothesis

float DerivationFramework::InvariantMassTool::m_massHypothesis
private

Definition at line 42 of file InvariantMassTool.h.

◆ m_massHypothesis2

float DerivationFramework::InvariantMassTool::m_massHypothesis2
private

Definition at line 42 of file InvariantMassTool.h.

◆ m_sgName

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

Definition at line 41 of file InvariantMassTool.h.


The documentation for this class was generated from the following files:
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:43
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
python.SystemOfUnits.second
float second
Definition: SystemOfUnits.py:135
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:160
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
DerivationFramework::InvariantMassTool::m_expression2
std::string m_expression2
Definition: InvariantMassTool.h:40
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:727
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:29
DerivationFramework::InvariantMassTool::m_expression
std::string m_expression
Definition: InvariantMassTool.h:39
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
DerivationFramework::InvariantMassTool::m_containerName2
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerName2
Definition: InvariantMassTool.h:44
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
DerivationFramework::InvariantMassTool::getInvariantMasses
StatusCode getInvariantMasses(std::vector< float > *, const EventContext &ctx) const
Definition: InvariantMassTool.cxx:74
ReadCellNoiseFromCoolCompare.v2
v2
Definition: ReadCellNoiseFromCoolCompare.py:364
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
DerivationFramework::InvariantMassTool::m_inputDecorNames
SG::ReadDecorHandleKeyArray< xAOD::IParticleContainer > m_inputDecorNames
Definition: InvariantMassTool.h:45
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DerivationFramework::InvariantMassTool::m_massHypothesis2
float m_massHypothesis2
Definition: InvariantMassTool.h:42
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
DerivationFramework::InvariantMassTool::m_massHypothesis
float m_massHypothesis
Definition: InvariantMassTool.h:42
entries
double entries
Definition: listroot.cxx:49
DerivationFramework::InvariantMassTool::m_sgName
SG::WriteHandleKey< std::vector< float > > m_sgName
Definition: InvariantMassTool.h:41
DerivationFramework::kInvariantMassToolParser1
@ kInvariantMassToolParser1
Definition: InvariantMassTool.h:29
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:72
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:27
SUSY_SimplifiedModel_PreInclude.masses
dictionary masses
Definition: SUSY_SimplifiedModel_PreInclude.py:7