Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Private Types | Private Attributes | List of all members
DerivationFramework::JetExternalAssocTool Class Reference

#include <JetExternalAssocTool.h>

Inheritance diagram for DerivationFramework::JetExternalAssocTool:
Collaboration diagram for DerivationFramework::JetExternalAssocTool:

Public Member Functions

 JetExternalAssocTool (const std::string &t, const std::string &n, const IInterface *p)
 
StatusCode initialize ()
 
StatusCode finalize ()
 
virtual StatusCode addBranches () const
 
bool TransferLink (const xAOD::Jet &jet, const xAOD::Jet &jet_external) const
 

Private Types

typedef ElementLink< xAOD::IParticleContainertype_el
 decoration pointers More...
 
typedef std::vector< type_eltype_ghostlink
 

Private Attributes

std::string m_momentPrefix
 Properties. More...
 
std::string m_containerName
 
std::string m_ExternalJetCollectionName
 
std::vector< std::string > m_VectorOfOldLinkNames
 
std::vector< std::string > m_VectorOfNewLinkNames
 
bool m_dRMatch
 
double m_dRCut
 
SG::WriteDecorHandleKeyArray< xAOD::JetContainerm_dec_keys {this, "DecKeys", {}, "SG keys for external decorations"}
 

Detailed Description

Definition at line 31 of file JetExternalAssocTool.h.

Member Typedef Documentation

◆ type_el

decoration pointers

Definition at line 55 of file JetExternalAssocTool.h.

◆ type_ghostlink

Definition at line 56 of file JetExternalAssocTool.h.

Constructor & Destructor Documentation

◆ JetExternalAssocTool()

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

Definition at line 14 of file JetExternalAssocTool.cxx.

14  :
15  base_class(t,n,p),
16  m_momentPrefix(""),
17  m_containerName(""),
21  m_dRMatch(false),
22  m_dRCut(0.01)
23 {
24 
25  declareProperty("MomentPrefix" , m_momentPrefix);
26  declareProperty("InputJets" , m_containerName);
27 
28  declareProperty("ExternalJetCollectionName", m_ExternalJetCollectionName);
29  declareProperty("ListOfOldLinkNames" , m_VectorOfOldLinkNames);
30  declareProperty("ListOfNewLinkNames" , m_VectorOfNewLinkNames);
31 
32  declareProperty("DeltaRMatch" , m_dRMatch);
33  declareProperty("DeltaRCut" , m_dRCut);
34 }

Member Function Documentation

◆ addBranches()

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

Definition at line 66 of file JetExternalAssocTool.cxx.

66  {
67 
68  // get jet collection to be decorated
69  const xAOD::JetContainer* jets = 0;
70  if(evtStore()->retrieve(jets, m_containerName).isFailure()){
71  ATH_MSG_ERROR("Unable to retrieve jet collection: " << m_containerName << "!");
72  return StatusCode::FAILURE;
73  }
74 
75  // get external jet collection
76  const xAOD::JetContainer* ExternalJetCollection = 0;
77  if(evtStore()->retrieve(ExternalJetCollection, m_ExternalJetCollectionName).isFailure()){
78  ATH_MSG_ERROR("Unable to find external jet collection: " << m_ExternalJetCollectionName << "!");
79  return StatusCode::FAILURE;
80  }
81 
82  if(!m_dRMatch){
83  // Here we are assuming there is a strict one-to-one correspondence between two jet collections and both jet collections have been sorted by pT
84 
85  // basic sanity check
86  if(jets->size() != ExternalJetCollection->size()){
87  ATH_MSG_ERROR("Size not the same between collection " << m_containerName << " and " << m_ExternalJetCollectionName << ". Please either double check your jet collections, or turn on dRMatch option");
88  return StatusCode::FAILURE;
89  }
90 
91  for(unsigned int index = 0; index < jets->size(); index++){
92  auto jet = jets->at(index);
93  auto jet_external = ExternalJetCollection->at(index);
94 
95  if( std::abs(jet->pt() - jet_external->pt()) > 0.1 ){ // 0.1 is hard-coded in
96  ATH_MSG_WARNING("Potential inconsistency between two jet collections: " << jet->pt() << " v.s. " << jet_external->pt());
97  }
98 
99  if(!TransferLink(*jet, *jet_external)){
100  ATH_MSG_ERROR("Failure when transferring link from external jet to current jet!");
101  return StatusCode::FAILURE;
102  }
103  }
104  }
105  else{
106  // simple dR matching
107 
108  // initialize list of un-assigned external jets
109  std::vector<const xAOD::Jet*> UnAssignedExternalJets;
110  for(auto jet_external : *ExternalJetCollection){
111  UnAssignedExternalJets.push_back(jet_external);
112  }
113 
114  // loop
115  for(auto jet : *jets){
116  // get associated jet
117  double mindR = 9e9;
118  const xAOD::Jet* associated_jet = 0;
119  std::vector<const xAOD::Jet*>::iterator associated_iter = UnAssignedExternalJets.begin(); // random assignment
120 
121  for(auto external_iter = UnAssignedExternalJets.begin(); external_iter != UnAssignedExternalJets.end(); external_iter++){
122  auto jet_external = (*external_iter);
123 
124  double dR = jet->p4().DeltaR(jet_external->p4());
125  if(dR > m_dRCut) continue;
126  if(dR < mindR){
127  mindR = dR;
128  associated_jet = jet_external;
129  associated_iter = external_iter;
130  }
131  }
132 
133  if(associated_jet == 0){
134  ATH_MSG_WARNING("Unable to find associated external jet! This jet will be skipped");
135  continue;
136  }
137  else{
138  // sanity check
139  if(associated_jet != (*associated_iter)){
140  ATH_MSG_ERROR("Sanity check after association fails!");
141  return StatusCode::FAILURE;
142  }
143 
144  // remove associated jet from unasigned jet list
145  UnAssignedExternalJets.erase(associated_iter);
146  }
147 
148  // transfer the link
149  if(!TransferLink(*jet, *associated_jet)){
150  ATH_MSG_ERROR("Failure when transferring link from external jet to current jet!");
151  return StatusCode::FAILURE;
152  }
153  }
154  }
155 
156  return StatusCode::SUCCESS;
157 }

◆ finalize()

StatusCode DerivationFramework::JetExternalAssocTool::finalize ( )

Definition at line 59 of file JetExternalAssocTool.cxx.

59  {
60 
61  return StatusCode::SUCCESS;
62 }

◆ initialize()

StatusCode DerivationFramework::JetExternalAssocTool::initialize ( )

Definition at line 38 of file JetExternalAssocTool.cxx.

38  {
39 
40  // get link names
42 
43  // sanity check
45  ATH_MSG_ERROR("Vector size between old and new link names does not agree!");
46  return StatusCode::FAILURE;
47  }
48 
49  // setup vector of decorator
50  for(const std::string& NewLinkName : m_VectorOfNewLinkNames){
51  m_dec_keys.emplace_back( m_containerName + "." + m_momentPrefix + NewLinkName);
52  }
53 
54  ATH_CHECK(m_dec_keys.initialize());
55 
56  return StatusCode::SUCCESS;
57 }

◆ TransferLink()

bool DerivationFramework::JetExternalAssocTool::TransferLink ( const xAOD::Jet jet,
const xAOD::Jet jet_external 
) const

Definition at line 159 of file JetExternalAssocTool.cxx.

159  {
160 
161  for(unsigned int index_link = 0; index_link < m_VectorOfOldLinkNames.size(); index_link++){
162  auto OldLinkName = m_VectorOfOldLinkNames[index_link];
163  auto NewLinkName = m_VectorOfNewLinkNames[index_link];
164 
165  // assume we are always dealing a list of IParticles
166  std::vector<const xAOD::IParticle*> targetObjs;
167  if(!jet_external.getAssociatedObjects<xAOD::IParticle>(OldLinkName, targetObjs)){
168  ATH_MSG_WARNING("Unable to fetch link " << OldLinkName << " under associated external jet");
169  continue;
170  }
171 
172  // put it under my jet
173  type_ghostlink targetLinks;
174  for(auto obj : targetObjs){
175  type_el el_obj;
176  el_obj.toIndexedElement(*(static_cast<const xAOD::IParticleContainer*>(obj->container())), obj->index());
177 
178  targetLinks.push_back(el_obj);
179  }
180 
182  *dec_handle(jet) = targetLinks;
183 
184  }
185 
186  return true;
187 }

Member Data Documentation

◆ m_containerName

std::string DerivationFramework::JetExternalAssocTool::m_containerName
private

Definition at line 45 of file JetExternalAssocTool.h.

◆ m_dec_keys

SG::WriteDecorHandleKeyArray<xAOD::JetContainer> DerivationFramework::JetExternalAssocTool::m_dec_keys {this, "DecKeys", {}, "SG keys for external decorations"}
private

Definition at line 58 of file JetExternalAssocTool.h.

◆ m_dRCut

double DerivationFramework::JetExternalAssocTool::m_dRCut
private

Definition at line 52 of file JetExternalAssocTool.h.

◆ m_dRMatch

bool DerivationFramework::JetExternalAssocTool::m_dRMatch
private

Definition at line 51 of file JetExternalAssocTool.h.

◆ m_ExternalJetCollectionName

std::string DerivationFramework::JetExternalAssocTool::m_ExternalJetCollectionName
private

Definition at line 47 of file JetExternalAssocTool.h.

◆ m_momentPrefix

std::string DerivationFramework::JetExternalAssocTool::m_momentPrefix
private

Properties.

Definition at line 44 of file JetExternalAssocTool.h.

◆ m_VectorOfNewLinkNames

std::vector<std::string> DerivationFramework::JetExternalAssocTool::m_VectorOfNewLinkNames
private

Definition at line 49 of file JetExternalAssocTool.h.

◆ m_VectorOfOldLinkNames

std::vector<std::string> DerivationFramework::JetExternalAssocTool::m_VectorOfOldLinkNames
private

Definition at line 48 of file JetExternalAssocTool.h.


The documentation for this class was generated from the following files:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DerivationFramework::JetExternalAssocTool::m_momentPrefix
std::string m_momentPrefix
Properties.
Definition: JetExternalAssocTool.h:44
DerivationFramework::JetExternalAssocTool::m_ExternalJetCollectionName
std::string m_ExternalJetCollectionName
Definition: JetExternalAssocTool.h:47
index
Definition: index.py:1
DerivationFramework::JetExternalAssocTool::m_dec_keys
SG::WriteDecorHandleKeyArray< xAOD::JetContainer > m_dec_keys
Definition: JetExternalAssocTool.h:58
defineDB.jets
jets
Definition: JetTagCalibration/share/defineDB.py:24
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::JetExternalAssocTool::type_ghostlink
std::vector< type_el > type_ghostlink
Definition: JetExternalAssocTool.h:56
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
DerivationFramework::JetExternalAssocTool::TransferLink
bool TransferLink(const xAOD::Jet &jet, const xAOD::Jet &jet_external) const
Definition: JetExternalAssocTool.cxx:159
xAOD::Jet_v1::getAssociatedObjects
std::vector< const T * > getAssociatedObjects(const std::string &name) const
get associated objects as a vector<object> this compact form throws an exception if the object is not...
DerivationFramework::JetExternalAssocTool::type_el
ElementLink< xAOD::IParticleContainer > type_el
decoration pointers
Definition: JetExternalAssocTool.h:55
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
DerivationFramework::JetExternalAssocTool::m_VectorOfNewLinkNames
std::vector< std::string > m_VectorOfNewLinkNames
Definition: JetExternalAssocTool.h:49
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
DerivationFramework::JetExternalAssocTool::m_dRCut
double m_dRCut
Definition: JetExternalAssocTool.h:52
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
DerivationFramework::JetExternalAssocTool::m_dRMatch
bool m_dRMatch
Definition: JetExternalAssocTool.h:51
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DerivationFramework::JetExternalAssocTool::m_VectorOfOldLinkNames
std::vector< std::string > m_VectorOfOldLinkNames
Definition: JetExternalAssocTool.h:48
DerivationFramework::JetExternalAssocTool::m_containerName
std::string m_containerName
Definition: JetExternalAssocTool.h:45
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.