ATLAS Offline Software
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
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  }

◆ 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;
142  float deltaPhiSq = deltaPhi*deltaPhi;
143  float deltaEtaSq = (eta1-eta2)*(eta1-eta2);
144  float deltaR = sqrt(deltaPhiSq+deltaEtaSq);
145  return deltaR;
146  }

◆ 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
66 
67  const xAOD::IParticleContainer* secondParticles(nullptr);
68  if (secondContainer) {
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  }

◆ 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  }
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.

◆ 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.

◆ 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.

◆ m_expression

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

Definition at line 34 of file DeltaRTool.h.

◆ 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.


The documentation for this class was generated from the following files:
DerivationFramework::kDeltaRToolParser1
@ kDeltaRToolParser1
Definition: DeltaRTool.h:23
P4Helpers::deltaEtaSq
double deltaEtaSq(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition: P4Helpers.h:98
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DerivationFramework::DeltaRTool::m_containerName
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerName
Definition: DeltaRTool.h:37
ParticleGun_SamplingFraction.eta2
eta2
Definition: ParticleGun_SamplingFraction.py:96
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:161
DerivationFramework::DeltaRTool::m_containerName2
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerName2
Definition: DeltaRTool.h:38
python.SystemOfUnits.second
float second
Definition: SystemOfUnits.py:135
xAOD::eta1
setEt setPhi setE277 setWeta2 eta1
Definition: TrigEMCluster_v1.cxx:41
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::DeltaRTool::calculateDeltaR
static float calculateDeltaR(float, float, float, float)
Definition: DeltaRTool.cxx:138
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:114
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::DeltaRTool::m_2ndExpression
Gaudi::Property< std::string > m_2ndExpression
Definition: DeltaRTool.h:35
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::DeltaRTool::getDeltaRs
StatusCode getDeltaRs(std::vector< float > *, const EventContext &ctx) const
Definition: DeltaRTool.cxx:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
DerivationFramework::DeltaRTool::m_expression
Gaudi::Property< std::string > m_expression
Definition: DeltaRTool.h:34
P4Helpers::deltaPhiSq
double deltaPhiSq(const I4Momentum &pA, const I4Momentum &pB)
delta Phi squared in range ([-pi,pi[)^2 from two I4momentum references
Definition: P4Helpers.h:185
DerivationFramework::kDeltaRToolParser2
@ kDeltaRToolParser2
Definition: DeltaRTool.h:23
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
DerivationFramework::DeltaRTool::m_sgName
SG::WriteHandleKey< std::vector< float > > m_sgName
Definition: DeltaRTool.h:36
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DeMoScan.first
bool first
Definition: DeMoScan.py:534
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
entries
double entries
Definition: listroot.cxx:49
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:72
DerivationFramework::deltaR
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: HIJetAugmentationTool.cxx:47