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

#include <DeltaRTool.h>

Inheritance diagram for DerivationFramework::DeltaRTool:
Collaboration diagram for DerivationFramework::DeltaRTool:

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 getDeltaRs (std::vector< float > *, const EventContext &ctx) const

Static Private Member Functions

static float calculateDeltaR (float, float, float, float)

Private Attributes

Gaudi::Property< std::string > m_expression {this, "ObjectRequirements", ""}
Gaudi::Property< std::string > m_2ndExpression {this, "SecondObjectRequirements", ""}
SG::WriteHandleKey< std::vector< float > > m_sgName {this,"StoreGateEntryName","","SG key of output object"}
SG::ReadHandleKey< xAOD::IParticleContainerm_containerName {this,"ContainerName","","SG key of first container"}
SG::ReadHandleKey< xAOD::IParticleContainerm_containerName2 {this,"SecondContainerName","","SG key of first container"}

Detailed Description

Definition at line 24 of file DeltaRTool.h.

Member Function Documentation

◆ addBranches()

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

Definition at line 36 of file DeltaRTool.cxx.

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

◆ calculateDeltaR()

float DerivationFramework::DeltaRTool::calculateDeltaR ( float phi1,
float phi2,
float eta1,
float eta2 )
staticprivate

Definition at line 138 of file DeltaRTool.cxx.

139 {
140 float deltaPhi = fabs(phi1-phi2);
141 if (deltaPhi>TMath::Pi()) deltaPhi = 2.0*TMath::Pi() - deltaPhi;
143 float deltaEtaSq = (eta1-eta2)*(eta1-eta2);
144 float deltaR = sqrt(deltaPhiSq+deltaEtaSq);
145 return deltaR;
146 }
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
double deltaR(double eta1, double eta2, double phi1, double phi2)
double deltaEtaSq(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition P4Helpers.h:98
double deltaPhiSq(const I4Momentum &pA, const I4Momentum &pB)
delta Phi squared in range ([-pi,pi[)^2 from two I4momentum references
Definition P4Helpers.h:185
setEt setPhi setE277 setWeta2 eta1

◆ finalize()

StatusCode DerivationFramework::DeltaRTool::finalize ( )
finaloverridevirtual

Definition at line 30 of file DeltaRTool.cxx.

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

◆ getDeltaRs()

StatusCode DerivationFramework::DeltaRTool::getDeltaRs ( std::vector< float > * deltaRs,
const EventContext & ctx ) const
private

Definition at line 52 of file DeltaRTool.cxx.

53 {
54
55 // check the relevant information is available
56 if (m_containerName.key().empty()) {
57 ATH_MSG_WARNING("Input container missing - returning zero");
58 deltaRs->push_back(0.0);
59 return StatusCode::FAILURE;
60 }
61 bool secondContainer(false);
62 if (!m_containerName2.key().empty()) secondContainer=true;
63
64 // get the relevant branches
65 SG::ReadHandle<xAOD::IParticleContainer> particles{m_containerName, ctx};
66
67 const xAOD::IParticleContainer* secondParticles(nullptr);
68 if (secondContainer) {
69 SG::ReadHandle<xAOD::IParticleContainer> particleHdl2{m_containerName2, ctx};
70 secondParticles=particleHdl2.cptr();
71 }
72
73 // get the positions of the elements which pass the requirement
74 std::vector<int> entries, entries2;
75 if (!m_expression.empty()) {entries = m_parser[kDeltaRToolParser1]->evaluateAsVector();}
76 else {entries.assign(particles->size(),1);} // default: include all elements
77 unsigned int nEntries = entries.size();
78 // check the sizes are compatible
79 if (particles->size() != nEntries ) {
80 ATH_MSG_FATAL("Branch sizes incompatible");
81 return StatusCode::FAILURE;
82 }
83 unsigned int nEntries2(0);
84 if (secondContainer) {
85 if (!m_2ndExpression.empty()) {entries2 = m_parser[kDeltaRToolParser2]->evaluateAsVector();}
86 else {entries2.assign(secondParticles->size(),1);} // default: include all elements
87 nEntries2 = entries2.size();
88 // check the sizes are compatible
89 if (secondParticles->size() != nEntries2 ) {
90 ATH_MSG_FATAL("Branch sizes incompatible - returning zero");
91 return StatusCode::FAILURE;
92 }
93 }
94
95 // Double loop to get the pairs for which the mass should be calculated
96 std::vector<std::pair<unsigned, unsigned>> pairs;
97 if (!secondContainer) {
98 for (unsigned outerIt=0; outerIt<nEntries; ++outerIt) {
99 for (unsigned innerIt=outerIt+1; innerIt<nEntries; ++innerIt) {
100 if (entries[outerIt]==1 && entries[innerIt]==1) {
101 pairs.emplace_back(outerIt, innerIt);
102 }
103 }
104 }
105 }
106
107 if (secondContainer) {
108 for (unsigned coll1It=0; coll1It<nEntries; ++coll1It) {
109 for (unsigned coll2It=0; coll2It<nEntries2; ++coll2It) {
110 //coverity[copy_paste_error]
111 if (entries[coll1It]==1 && entries2[coll2It]==1) {
112 pairs.emplace_back(coll1It, coll2It);
113 }
114 }
115 }
116 }
117
118 // Loop over the pairs; calculate the mass; put into vector and return
119 for (const auto & [first, second] : pairs) {
120 if (!secondContainer) {
121 float phi1f = ((*particles)[first])->p4().Phi(); float phi2f = ((*particles)[second])->p4().Phi();
122 float eta1f = ((*particles)[first])->p4().Eta(); float eta2f = ((*particles)[second])->p4().Eta();
123 float deltaR = calculateDeltaR(phi1f,phi2f,eta1f,eta2f);
124 deltaRs->push_back(deltaR);
125 }
126 if (secondContainer) {
127 float phi1f = ((*particles)[first])->p4().Phi(); float phi2f = ((*secondParticles)[second])->p4().Phi();
128 float eta1f = ((*particles)[first])->p4().Eta(); float eta2f = ((*secondParticles)[second])->p4().Eta();
129 float deltaR = calculateDeltaR(phi1f,phi2f,eta1f,eta2f);
130 deltaRs->push_back(deltaR);
131 }
132 }
133
134 return StatusCode::SUCCESS;
135
136 }
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
Gaudi::Property< std::string > m_expression
Definition DeltaRTool.h:34
Gaudi::Property< std::string > m_2ndExpression
Definition DeltaRTool.h:35
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerName2
Definition DeltaRTool.h:38
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerName
Definition DeltaRTool.h:37
static float calculateDeltaR(float, float, float, float)
const_pointer_type cptr()
Dereference the pointer.
double entries
Definition listroot.cxx:49
bool first
Definition DeMoScan.py:534
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.

◆ initialize()

StatusCode DerivationFramework::DeltaRTool::initialize ( )
finaloverridevirtual

Definition at line 13 of file DeltaRTool.cxx.

14 {
15 if (m_sgName.key().empty()) {
16 ATH_MSG_ERROR("No SG name provided for the output of invariant mass tool!");
17 return StatusCode::FAILURE;
18 }
19 ATH_CHECK(m_sgName.initialize());
20 ATH_CHECK(m_containerName.initialize());
21
22 if (!m_containerName2.key().empty()) {
23 ATH_CHECK(m_containerName2.initialize());
24 }
25
26 ATH_CHECK(initializeParser( {m_expression, m_2ndExpression} ));
27 return StatusCode::SUCCESS;
28 }

Member Data Documentation

◆ m_2ndExpression

Gaudi::Property<std::string> DerivationFramework::DeltaRTool::m_2ndExpression {this, "SecondObjectRequirements", ""}
private

Definition at line 35 of file DeltaRTool.h.

35{this, "SecondObjectRequirements", ""};

◆ m_containerName

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

Definition at line 37 of file DeltaRTool.h.

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

◆ m_containerName2

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

Definition at line 38 of file DeltaRTool.h.

38{this,"SecondContainerName","","SG key of first container"};

◆ m_expression

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

Definition at line 34 of file DeltaRTool.h.

34{this, "ObjectRequirements", ""};

◆ m_sgName

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

Definition at line 36 of file DeltaRTool.h.

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

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