ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFramework::InvariantMassTool Class Reference

#include <InvariantMassTool.h>

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

Public Member Functions

virtual StatusCode initialize () override final
virtual StatusCode finalize () override final
virtual StatusCode addBranches (const EventContext &ctx) const override final

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

Gaudi::Property< std::string > m_expression {this, "ObjectRequirements", "true"}
Gaudi::Property< std::string > m_expression2 {this, "SecondObjectRequirements", ""}
SG::WriteHandleKey< std::vector< float > > m_sgName {this,"StoreGateEntryName","","SG key of output object"}
Gaudi::Property< float > m_massHypothesis {this, "MassHypothesis", 0.0}
Gaudi::Property< float > m_massHypothesis2 {this, "SecondMassHypothesis", 2.0}
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 26 of file InvariantMassTool.h.

Member Function Documentation

◆ addBranches()

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

Definition at line 37 of file InvariantMassTool.cxx.

38 {
39 // Write masses to SG for access by downstream algs
40 if (evtStore()->contains<std::vector<float> >(m_sgName.key())) {
41 ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << m_sgName << " which already exists. Please use a different key");
42 return StatusCode::FAILURE;
43 }
44 std::unique_ptr<std::vector<float> > masses(new std::vector<float>());
46 SG::WriteHandle<std::vector<float> > writeHandle(m_sgName, ctx);
47 ATH_CHECK(writeHandle.record(std::move(masses)));
48 return StatusCode::SUCCESS;
49 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
SG::WriteHandleKey< std::vector< float > > m_sgName
StatusCode getInvariantMasses(std::vector< float > *, const EventContext &ctx) const
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114

◆ calculateInvariantMass()

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

Definition at line 138 of file InvariantMassTool.cxx.

138 {
139 TLorentzVector p1(v1, M1 > 0 ? std::hypot(M1, v1.Mag()) : v1.Mag());
140 TLorentzVector p2(v2, M2 > 0 ? std::hypot(M2, v2.Mag()) : v2.Mag());
141 return (p1+p2).M();
142
143 }

◆ finalize()

StatusCode DerivationFramework::InvariantMassTool::finalize ( )
finaloverridevirtual

Definition at line 31 of file InvariantMassTool.cxx.

32 {
33 ATH_CHECK( finalizeParser());
34 return StatusCode::SUCCESS;
35 }

◆ getInvariantMasses()

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

Definition at line 51 of file InvariantMassTool.cxx.

52 {
53
54 // check the relevant information is available
55 if (m_containerName.key().empty()) {
56 ATH_MSG_WARNING("Input container missing - returning zero");
57 masses->push_back(0.0);
58 return StatusCode::FAILURE;
59 }
60
61 SG::ReadHandle<xAOD::IParticleContainer> particles{m_containerName, ctx};
62
63 bool from2Collections(false);
64 const xAOD::IParticleContainer* particles2{nullptr};
65 if (!m_containerName2.key().empty() && m_containerName2.key()!=m_containerName.key()) {
66 SG::ReadHandle<xAOD::IParticleContainer> particleHdl2{m_containerName2, ctx};
67 particles2=particleHdl2.cptr();
68 from2Collections = true;
69 }
70
71 // get the positions of the elements which pass the requirement
72 std::vector<int> entries = m_parser[kInvariantMassToolParser1]->evaluateAsVector();
73 std::vector<int> entries2 = m_parser[kInvariantMassToolParser2]->evaluateAsVector();
74 unsigned int nEntries = entries.size();
75 unsigned int nEntries2 = entries2.size();
76
77 // check the sizes are compatible
78 if (!from2Collections) {
79 if ( (particles->size() != nEntries) || (particles->size() != nEntries2) || (nEntries!=nEntries2) ) {
80 ATH_MSG_ERROR("Branch sizes incompatible - returning zero. Check your selection strings.");
81 masses->push_back(0.0);
82 return StatusCode::FAILURE;
83 }
84 }
85 if (from2Collections) {
86 if ( (particles->size() != nEntries) || (particles2->size() != nEntries2) ) {
87 ATH_MSG_ERROR("Branch sizes incompatible - returning zero. Check your selection strings.");
88 masses->push_back(0.0);
89 return StatusCode::FAILURE;
90 }
91 }
92
93 // Double loop to get all possible index pairs
94 unsigned int outerIt, innerIt;
95 std::vector<std::pair<int, int> > pairs;
96 // Loop for case where both legs are from the same container
97 if (!from2Collections) {
98 for (outerIt=0; outerIt<nEntries; ++outerIt) {
99 for (innerIt=outerIt+1; innerIt<nEntries; ++innerIt) {
100 pairs.push_back({static_cast<int>(outerIt),static_cast<int>(innerIt)});
101 }
102 }
103 // Select the pairs for which the mass should be calculated, and then calculate it
104 for (const auto & [first, second]: pairs) {
105 if ( (entries[first]==1 && entries2[second]==1) || (entries2[first]==1 && entries[second]==1) ) {
106 const float mass = calculateInvariantMass( ((*particles)[first])->p4().Vect(),
107 ((*particles)[second])->p4().Vect(),
110 masses->push_back(mass);
111 }
112 }
113 }
114
115 // Loop for case where both legs are from different containers
116 if (from2Collections) {
117 for (outerIt=0; outerIt<nEntries; ++outerIt) {
118 if (entries[outerIt]==0) continue;
119 for (innerIt=0; innerIt<nEntries2; ++innerIt) {
120 if (entries2[innerIt]==0) continue;
121 pairs.push_back({static_cast<int>(outerIt),static_cast<int>(innerIt)});
122 }
123 }
124 // Select the pairs for which the mass should be calculated, and then calculate it
125 for (const auto & [first, second]: pairs) {
126 const float mass = calculateInvariantMass( ((*particles)[first])->p4().Vect(),
127 ((*particles2)[second])->p4().Vect(),
130 masses->push_back(mass);
131 }
132 }
133
134 return StatusCode::SUCCESS;
135
136 }
#define ATH_MSG_WARNING(x)
size_type size() const noexcept
Returns the number of elements in the collection.
Gaudi::Property< float > m_massHypothesis
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerName
Gaudi::Property< float > m_massHypothesis2
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerName2
static float calculateInvariantMass(const TVector3 &v1, const TVector3 &v2, float M1, float M2)
const_pointer_type cptr()
Dereference the pointer.
double entries
Definition listroot.cxx:49
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.

◆ initialize()

StatusCode DerivationFramework::InvariantMassTool::initialize ( )
finaloverridevirtual

Definition at line 13 of file InvariantMassTool.cxx.

14 {
15 ATH_CHECK(m_sgName.initialize());
16
17 if (m_expression2.empty()) {
18 ATH_CHECK(initializeParser( {m_expression.value(), m_expression.value()} ));
19 }
20 else {
21 ATH_CHECK(initializeParser( {m_expression.value(),m_expression2.value()} ));
22 }
23
24 ATH_CHECK(m_containerName.initialize());
27
28 return StatusCode::SUCCESS;
29 }
SG::ReadDecorHandleKeyArray< xAOD::IParticleContainer > m_inputDecorNames
Gaudi::Property< std::string > m_expression2
Gaudi::Property< std::string > m_expression

Member Data Documentation

◆ m_containerName

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

Definition at line 41 of file InvariantMassTool.h.

41{this,"ContainerName","","SG key of first container"};

◆ m_containerName2

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

Definition at line 42 of file InvariantMassTool.h.

42{this,"SecondContainerName","","SG key of second container"};

◆ m_expression

Gaudi::Property<std::string> DerivationFramework::InvariantMassTool::m_expression {this, "ObjectRequirements", "true"}
private

Definition at line 36 of file InvariantMassTool.h.

36{this, "ObjectRequirements", "true"};

◆ m_expression2

Gaudi::Property<std::string> DerivationFramework::InvariantMassTool::m_expression2 {this, "SecondObjectRequirements", ""}
private

Definition at line 37 of file InvariantMassTool.h.

37{this, "SecondObjectRequirements", ""};

◆ 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 43 of file InvariantMassTool.h.

43{this, "InputDecorNames",{},"SG keys for decorations of first (and second) container(s)"};

◆ m_massHypothesis

Gaudi::Property<float> DerivationFramework::InvariantMassTool::m_massHypothesis {this, "MassHypothesis", 0.0}
private

Definition at line 39 of file InvariantMassTool.h.

39{this, "MassHypothesis", 0.0};

◆ m_massHypothesis2

Gaudi::Property<float> DerivationFramework::InvariantMassTool::m_massHypothesis2 {this, "SecondMassHypothesis", 2.0}
private

Definition at line 40 of file InvariantMassTool.h.

40{this, "SecondMassHypothesis", 2.0};

◆ m_sgName

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

Definition at line 38 of file InvariantMassTool.h.

38{this,"StoreGateEntryName","","SG key of output object"};

The documentation for this class was generated from the following files: