ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | 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)
 
virtual StatusCode initialize () override final
 
virtual StatusCode addBranches (const EventContext &ctx) const override final
 

Private Types

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

Private Member Functions

StatusCode TransferLink (const xAOD::Jet &jet, const xAOD::Jet &jet_external, const EventContext &ctx) const
 

Private Attributes

SG::ReadHandleKey< xAOD::JetContainerm_containerName {this, "InputJets", ""}
 Properties. More...
 
SG::ReadHandleKey< xAOD::JetContainerm_ExternalJetCollectionName {this, "ExternalJetCollectionName", ""}
 
Gaudi::Property< std::string > m_momentPrefix {this, "MomentPrefix", ""}
 
Gaudi::Property< std::vector< std::string > > m_VectorOfOldLinkNames {this, "ListOfOldLinkNames", {}}
 
Gaudi::Property< std::vector< std::string > > m_VectorOfNewLinkNames {this, "ListOfNewLinkNames", {}}
 
SG::WriteDecorHandleKeyArray< xAOD::JetContainerm_dec_keys {this, "DecKeys", {}, "SG keys for external decorations"}
 
Gaudi::Property< bool > m_dRMatch {this, "DeltaRMatch", false}
 
Gaudi::Property< double > m_dRCut {this, "DeltaRCut", 0.01}
 

Detailed Description

Definition at line 29 of file JetExternalAssocTool.h.

Member Typedef Documentation

◆ type_el

decoration pointers

Definition at line 52 of file JetExternalAssocTool.h.

◆ type_ghostlink

Definition at line 53 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  {
17  }

Member Function Documentation

◆ addBranches()

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

Definition at line 45 of file JetExternalAssocTool.cxx.

45  {
46  // get jet collection to be decorated
48  if (!jets.isValid()) {
49  ATH_MSG_ERROR("Unable to retrieve jet collection: " << m_containerName << "!");
50  return StatusCode::FAILURE;
51  }
52 
53  // get external jet collection
55  if (!ExternalJetCollection.isValid()) {
56  ATH_MSG_ERROR("Unable to find external jet collection: " << m_ExternalJetCollectionName << "!");
57  return StatusCode::FAILURE;
58  }
59 
60  if(!m_dRMatch){
61  // 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
62 
63  // basic sanity check
64  if(jets->size() != ExternalJetCollection->size()){
65  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");
66  return StatusCode::FAILURE;
67  }
68 
69  for (unsigned int index = 0; index < jets->size(); index++) {
70  auto jet = jets->at(index);
71  auto jet_external = ExternalJetCollection->at(index);
72 
73  if( std::abs(jet->pt() - jet_external->pt()) > 0.1 ){ // 0.1 is hard-coded in
74  ATH_MSG_WARNING("Potential inconsistency between two jet collections: " << jet->pt() << " v.s. " << jet_external->pt());
75  }
76 
77  if (TransferLink(*jet, *jet_external, ctx).isFailure()) {
78  ATH_MSG_ERROR("Failure when transferring link from external jet to current jet!");
79  return StatusCode::FAILURE;
80  }
81  }
82  }
83  else{
84  // simple dR matching
85 
86  // initialize list of un-assigned external jets
87  std::vector<const xAOD::Jet*> UnAssignedExternalJets;
88  for (auto jet_external : *ExternalJetCollection) {
89  UnAssignedExternalJets.push_back(jet_external);
90  }
91 
92  // loop
93  for (auto jet : *jets) {
94  // get associated jet
95  double mindR = 9e9;
96  const xAOD::Jet* associated_jet = 0;
97  std::vector<const xAOD::Jet*>::iterator associated_iter = UnAssignedExternalJets.begin(); // random assignment
98 
99  for(auto external_iter = UnAssignedExternalJets.begin(); external_iter != UnAssignedExternalJets.end(); external_iter++){
100  auto jet_external = (*external_iter);
101 
102  double dR = jet->p4().DeltaR(jet_external->p4());
103  if(dR > m_dRCut) continue;
104  if(dR < mindR){
105  mindR = dR;
106  associated_jet = jet_external;
107  associated_iter = external_iter;
108  }
109  }
110 
111  if(associated_jet == 0){
112  ATH_MSG_WARNING("Unable to find associated external jet! This jet will be skipped");
113  continue;
114  }
115  else{
116  // sanity check
117  if(associated_jet != (*associated_iter)){
118  ATH_MSG_ERROR("Sanity check after association fails!");
119  return StatusCode::FAILURE;
120  }
121 
122  // remove associated jet from unasigned jet list
123  UnAssignedExternalJets.erase(associated_iter);
124  }
125 
126  // transfer the link
127  if (TransferLink(*jet, *associated_jet, ctx).isFailure()) {
128  ATH_MSG_ERROR("Failure when transferring link from external jet to current jet!");
129  return StatusCode::FAILURE;
130  }
131  }
132  }
133 
134  return StatusCode::SUCCESS;
135  }

◆ initialize()

StatusCode DerivationFramework::JetExternalAssocTool::initialize ( )
finaloverridevirtual

Definition at line 21 of file JetExternalAssocTool.cxx.

21  {
24  // get link names
25  if(m_VectorOfNewLinkNames.empty()) m_VectorOfNewLinkNames = m_VectorOfOldLinkNames; // FIXME Properties should be set properly in the configuration layer.
26 
27  // sanity check
29  ATH_MSG_ERROR("Vector size between old and new link names does not agree!");
30  return StatusCode::FAILURE;
31  }
32 
33  // setup vector of decorator
34  for(const std::string& NewLinkName : m_VectorOfNewLinkNames){
35  m_dec_keys.emplace_back( m_containerName.key() + "." + m_momentPrefix.value() + NewLinkName); // FIXME HandleKeys should be set properly in the configuration layer.
36  }
37 
38  ATH_CHECK(m_dec_keys.initialize());
39 
40  return StatusCode::SUCCESS;
41  }

◆ TransferLink()

StatusCode DerivationFramework::JetExternalAssocTool::TransferLink ( const xAOD::Jet jet,
const xAOD::Jet jet_external,
const EventContext &  ctx 
) const
private

Definition at line 137 of file JetExternalAssocTool.cxx.

137  {
138 
139  for(unsigned int index_link = 0; index_link < m_VectorOfOldLinkNames.size(); index_link++){
140  const auto & OldLinkName = m_VectorOfOldLinkNames[index_link];
141 
142 
143  // assume we are always dealing a list of IParticles
144  std::vector<const xAOD::IParticle*> targetObjs;
145  if (!jet_external.getAssociatedObjects<xAOD::IParticle>(OldLinkName, targetObjs)){
146  ATH_MSG_ERROR("Unable to fetch link " << OldLinkName << " under associated external jet");
147  return StatusCode::FAILURE;
148  }
149 
150  // put it under my jet
151  type_ghostlink targetLinks;
152  for(auto obj : targetObjs){
153  type_el el_obj;
154  el_obj.toIndexedElement(*(static_cast<const xAOD::IParticleContainer*>(obj->container())), obj->index());
155 
156  targetLinks.push_back(el_obj);
157  }
158 
160  *dec_handle(jet) = std::move(targetLinks);
161 
162  }
163 
164  return StatusCode::SUCCESS;
165  }

Member Data Documentation

◆ m_containerName

SG::ReadHandleKey<xAOD::JetContainer> DerivationFramework::JetExternalAssocTool::m_containerName {this, "InputJets", ""}
private

Properties.

Definition at line 41 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 46 of file JetExternalAssocTool.h.

◆ m_dRCut

Gaudi::Property<double> DerivationFramework::JetExternalAssocTool::m_dRCut {this, "DeltaRCut", 0.01}
private

Definition at line 49 of file JetExternalAssocTool.h.

◆ m_dRMatch

Gaudi::Property<bool> DerivationFramework::JetExternalAssocTool::m_dRMatch {this, "DeltaRMatch", false}
private

Definition at line 48 of file JetExternalAssocTool.h.

◆ m_ExternalJetCollectionName

SG::ReadHandleKey<xAOD::JetContainer> DerivationFramework::JetExternalAssocTool::m_ExternalJetCollectionName {this, "ExternalJetCollectionName", ""}
private

Definition at line 42 of file JetExternalAssocTool.h.

◆ m_momentPrefix

Gaudi::Property<std::string> DerivationFramework::JetExternalAssocTool::m_momentPrefix {this, "MomentPrefix", ""}
private

Definition at line 43 of file JetExternalAssocTool.h.

◆ m_VectorOfNewLinkNames

Gaudi::Property<std::vector<std::string> > DerivationFramework::JetExternalAssocTool::m_VectorOfNewLinkNames {this, "ListOfNewLinkNames", {}}
private

Definition at line 45 of file JetExternalAssocTool.h.

◆ m_VectorOfOldLinkNames

Gaudi::Property<std::vector<std::string> > DerivationFramework::JetExternalAssocTool::m_VectorOfOldLinkNames {this, "ListOfOldLinkNames", {}}
private

Definition at line 44 of file JetExternalAssocTool.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DerivationFramework::JetExternalAssocTool::m_ExternalJetCollectionName
SG::ReadHandleKey< xAOD::JetContainer > m_ExternalJetCollectionName
Definition: JetExternalAssocTool.h:42
DerivationFramework::JetExternalAssocTool::m_momentPrefix
Gaudi::Property< std::string > m_momentPrefix
Definition: JetExternalAssocTool.h:43
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
index
Definition: index.py:1
DerivationFramework::JetExternalAssocTool::m_containerName
SG::ReadHandleKey< xAOD::JetContainer > m_containerName
Properties.
Definition: JetExternalAssocTool.h:41
DerivationFramework::JetExternalAssocTool::m_dec_keys
SG::WriteDecorHandleKeyArray< xAOD::JetContainer > m_dec_keys
Definition: JetExternalAssocTool.h:46
defineDB.jets
jets
Definition: JetTagCalibration/share/defineDB.py:24
DerivationFramework::JetExternalAssocTool::m_dRMatch
Gaudi::Property< bool > m_dRMatch
Definition: JetExternalAssocTool.h:48
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
DerivationFramework::JetExternalAssocTool::type_ghostlink
std::vector< type_el > type_ghostlink
Definition: JetExternalAssocTool.h:53
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
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:52
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DerivationFramework::JetExternalAssocTool::m_VectorOfNewLinkNames
Gaudi::Property< std::vector< std::string > > m_VectorOfNewLinkNames
Definition: JetExternalAssocTool.h:45
beamspotman.n
n
Definition: beamspotman.py:727
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
DerivationFramework::JetExternalAssocTool::TransferLink
StatusCode TransferLink(const xAOD::Jet &jet, const xAOD::Jet &jet_external, const EventContext &ctx) const
Definition: JetExternalAssocTool.cxx:137
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::JetExternalAssocTool::m_VectorOfOldLinkNames
Gaudi::Property< std::vector< std::string > > m_VectorOfOldLinkNames
Definition: JetExternalAssocTool.h:44
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:795
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_dRCut
Gaudi::Property< double > m_dRCut
Definition: JetExternalAssocTool.h:49
python.PyAthena.obj
obj
Definition: PyAthena.py:132