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

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

Private Member Functions

StatusCode getDeltaRs (std::vector< float > *) const
 

Static Private Member Functions

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

Private Attributes

std::string m_expression
 
std::string m_2ndExpression
 
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 26 of file DeltaRTool.h.

Constructor & Destructor Documentation

◆ DeltaRTool()

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

Definition at line 18 of file DeltaRTool.cxx.

20  :
21  base_class(t,n,p),
22  m_expression(""),
23  m_2ndExpression("")
24  {
25  declareProperty("ObjectRequirements", m_expression);
26  declareProperty("SecondObjectRequirements", m_2ndExpression);
27  }

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::DeltaRTool::addBranches ( ) const
virtual

Definition at line 52 of file DeltaRTool.cxx.

53  {
54  // Write deltaRs to SG for access by downstream algs
55  if (evtStore()->contains<std::vector<float> >(m_sgName.key())) {
56  ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << m_sgName << " which already exists. Please use a different key");
57  return StatusCode::FAILURE;
58  }
59  std::unique_ptr<std::vector<float> > deltaRs(new std::vector<float>());
60  ATH_CHECK(getDeltaRs(deltaRs.get()));
61 
63  ATH_CHECK(writeHandle.record(std::move(deltaRs)));
64 
65  return StatusCode::SUCCESS;
66  }

◆ calculateDeltaR()

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

Definition at line 162 of file DeltaRTool.cxx.

163  {
164  float deltaPhi = fabs(phi1-phi2);
165  if (deltaPhi>TMath::Pi()) deltaPhi = 2.0*TMath::Pi() - deltaPhi;
166  float deltaPhiSq = deltaPhi*deltaPhi;
167  float deltaEtaSq = (eta1-eta2)*(eta1-eta2);
168  float deltaR = sqrt(deltaPhiSq+deltaEtaSq);
169  return deltaR;
170  }

◆ finalize()

StatusCode DerivationFramework::DeltaRTool::finalize ( )

Definition at line 46 of file DeltaRTool.cxx.

47  {
48  ATH_CHECK(finalizeParser());
49  return StatusCode::SUCCESS;
50  }

◆ getDeltaRs()

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

Definition at line 68 of file DeltaRTool.cxx.

69  {
70 
71  // check the relevant information is available
72  if (m_containerName.key().empty()) {
73  ATH_MSG_WARNING("Input container missing - returning zero");
74  deltaRs->push_back(0.0);
75  return StatusCode::FAILURE;
76  }
77  bool secondContainer(false);
78  if (!m_containerName2.key().empty()) secondContainer=true;
79 
80  // get the relevant branches
82 
83  const xAOD::IParticleContainer* secondParticles(nullptr);
84  if (secondContainer) {
86  secondParticles=particleHdl2.cptr();
87  }
88 
89  // get the positions of the elements which pass the requirement
90  std::vector<int> entries, entries2;
91  if (!m_expression.empty()) {entries = m_parser[kDeltaRToolParser1]->evaluateAsVector();}
92  else {entries.assign(particles->size(),1);} // default: include all elements
93  unsigned int nEntries = entries.size();
94  // check the sizes are compatible
95  if (particles->size() != nEntries ) {
96  ATH_MSG_FATAL("Branch sizes incompatible");
97  return StatusCode::FAILURE;
98  }
99  unsigned int nEntries2(0);
100  if (secondContainer) {
101  if (!m_2ndExpression.empty()) {entries2 = m_parser[kDeltaRToolParser2]->evaluateAsVector();}
102  else {entries2.assign(secondParticles->size(),1);} // default: include all elements
103  nEntries2 = entries2.size();
104  // check the sizes are compatible
105  if (secondParticles->size() != nEntries2 ) {
106  ATH_MSG_FATAL("Branch sizes incompatible - returning zero");
107  return StatusCode::FAILURE;
108  }
109  }
110 
111  // Double loop to get the pairs for which the mass should be calculated
112  std::vector<std::vector<int> > pairs;
113  if (!secondContainer) {
114  unsigned int outerIt, innerIt;
115  for (outerIt=0; outerIt<nEntries; ++outerIt) {
116  for (innerIt=outerIt+1; innerIt<nEntries; ++innerIt) {
117  std::vector<int> tmpPair;
118  if (entries[outerIt]==1 && entries[innerIt]==1) {
119  tmpPair.push_back(outerIt); tmpPair.push_back(innerIt);
120  pairs.push_back(tmpPair);
121  }
122  }
123  }
124  }
125 
126  if (secondContainer) {
127  unsigned int coll1It, coll2It;
128  for (coll1It=0; coll1It<nEntries; ++coll1It) {
129  for (coll2It=0; coll2It<nEntries2; ++coll2It) {
130  std::vector<int> tmpPair;
131  if (entries[coll1It]==1 && entries2[coll2It]==1) {
132  tmpPair.push_back(coll1It); tmpPair.push_back(coll2It);
133  pairs.push_back(tmpPair);
134  }
135  }
136  }
137  }
138 
139  // Loop over the pairs; calculate the mass; put into vector and return
140  std::vector<std::vector<int> >::iterator pairIt;
141  for (pairIt=pairs.begin(); pairIt!=pairs.end(); ++pairIt) {
142  unsigned int first = (*pairIt)[0];
143  unsigned int second = (*pairIt)[1];
144  if (!secondContainer) {
145  float phi1f = ((*particles)[first])->p4().Phi(); float phi2f = ((*particles)[second])->p4().Phi();
146  float eta1f = ((*particles)[first])->p4().Eta(); float eta2f = ((*particles)[second])->p4().Eta();
147  float deltaR = calculateDeltaR(phi1f,phi2f,eta1f,eta2f);
148  deltaRs->push_back(deltaR);
149  }
150  if (secondContainer) {
151  float phi1f = ((*particles)[first])->p4().Phi(); float phi2f = ((*secondParticles)[second])->p4().Phi();
152  float eta1f = ((*particles)[first])->p4().Eta(); float eta2f = ((*secondParticles)[second])->p4().Eta();
153  float deltaR = calculateDeltaR(phi1f,phi2f,eta1f,eta2f);
154  deltaRs->push_back(deltaR);
155  }
156  }
157 
158  return StatusCode::SUCCESS;
159 
160  }

◆ initialize()

StatusCode DerivationFramework::DeltaRTool::initialize ( )

Definition at line 29 of file DeltaRTool.cxx.

30  {
31  if (m_sgName.key().empty()) {
32  ATH_MSG_ERROR("No SG name provided for the output of invariant mass tool!");
33  return StatusCode::FAILURE;
34  }
36  ATH_CHECK(m_containerName.initialize());
37 
38  if (!m_containerName2.key().empty()) {
39  ATH_CHECK(m_containerName2.initialize());
40  }
41 
42  ATH_CHECK(initializeParser( {m_expression, m_2ndExpression} ));
43  return StatusCode::SUCCESS;
44  }

Member Data Documentation

◆ m_2ndExpression

std::string DerivationFramework::DeltaRTool::m_2ndExpression
private

Definition at line 36 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 38 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 39 of file DeltaRTool.h.

◆ m_expression

std::string DerivationFramework::DeltaRTool::m_expression
private

Definition at line 35 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 37 of file DeltaRTool.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DerivationFramework::kDeltaRToolParser1
@ kDeltaRToolParser1
Definition: DeltaRTool.h:25
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
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:38
DerivationFramework::DeltaRTool::m_2ndExpression
std::string m_2ndExpression
Definition: DeltaRTool.h:36
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:160
DerivationFramework::DeltaRTool::m_containerName2
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerName2
Definition: DeltaRTool.h:39
xAOD::eta1
setEt setPhi setE277 setWeta2 eta1
Definition: TrigEMCluster_v1.cxx:41
DerivationFramework::DeltaRTool::m_expression
std::string m_expression
Definition: DeltaRTool.h:35
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
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
DerivationFramework::DeltaRTool::calculateDeltaR
static float calculateDeltaR(float, float, float, float)
Definition: DeltaRTool.cxx:162
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
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:25
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
DerivationFramework::DeltaRTool::m_sgName
SG::WriteHandleKey< std::vector< float > > m_sgName
Definition: DeltaRTool.h:37
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DeMoScan.first
bool first
Definition: DeMoScan.py:536
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
entries
double entries
Definition: listroot.cxx:49
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
makeComparison.deltaR
float deltaR
Definition: makeComparison.py:36
DerivationFramework::DeltaRTool::getDeltaRs
StatusCode getDeltaRs(std::vector< float > *) const
Definition: DeltaRTool.cxx:68