ATLAS Offline Software
JetConstituentModSequence.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Source file for the JetConstituentModSequence.h
6 // Michael Nelson, CERN & University of Oxford
7 // Will later add the intermediate step
8 
18 
19 
21 
22 #ifndef XAOD_ANALYSIS
24 #endif
25 
27  asg::AsgTool(name) {
28 
29 #ifdef ASG_TOOL_ATHENA
30  declareInterface<IJetConstituentModifier>(this);
31 #endif
32  declareProperty("InputType", m_inputType, "The xAOD type name for the input container.");
33  declareProperty("SaveAsShallow", m_saveAsShallow=true, "Save as shallow copy");
34 
35 }
36 
38  ATH_MSG_INFO("Initializing tool " << name() << "...");
39  ATH_MSG_DEBUG("initializing version with data handles");
40 
41 
42  ATH_CHECK( m_modifiers.retrieve() );
44 
45  // Shallow copies are not supported for by-vertex jet reconstruction
46  if (m_byVertex){
47  m_saveAsShallow = false;
48  }
49 
50 #ifndef XAOD_ANALYSIS
51  ATH_CHECK( m_monTool.retrieve( DisableTool{m_monTool.empty()} ) );
52 #endif
53 
54  // Set and initialise DataHandleKeys only for the correct input type
55  // Die if the input type is unsupported
56  switch(m_inputType) {
58  {
61 
64  break;
65  }
67  {
68  std::string inputContainerBase = m_inputContainer;
69  std::string outputContainerBase = m_outputContainer;
70 
71  // Know what the user means if they give the full input/output container name in this format
72  size_t pos = inputContainerBase.find("ParticleFlowObjects");
73  if(pos != std::string::npos) inputContainerBase.erase(pos);
74 
75  pos = outputContainerBase.find("ParticleFlowObjects");
76  if(pos != std::string::npos) outputContainerBase.erase(pos);
77 
78  m_inChargedPFOKey = inputContainerBase + "ChargedParticleFlowObjects";
79  m_inNeutralPFOKey = inputContainerBase + "NeutralParticleFlowObjects";
80 
81  m_outChargedPFOKey = outputContainerBase + "ChargedParticleFlowObjects";
82  m_outNeutralPFOKey = outputContainerBase + "NeutralParticleFlowObjects";
83  m_outAllPFOKey = outputContainerBase + "ParticleFlowObjects";
84 
85  ATH_CHECK(m_inChargedPFOKey.initialize());
86  ATH_CHECK(m_inNeutralPFOKey.initialize());
87  ATH_CHECK(m_outChargedPFOKey.initialize());
88  ATH_CHECK(m_outNeutralPFOKey.initialize());
89  ATH_CHECK(m_outAllPFOKey.initialize());
90  break;
91  }
92  break;
96 
97  ATH_CHECK(m_inTCCKey.initialize());
98  ATH_CHECK(m_outTCCKey.initialize());
99  break;
101  {
102  // TODO: This assumes a PFlow-style neutral and charged collection.
103  // More general FlowElements (e.g. CaloClusters) may necessitate a rework here later.
104 
105  const std::string subString = "ParticleFlowObjects";
106  const std::string subStringCharged = "ChargedParticleFlowObjects";
107  const std::string subStringNeutral = "NeutralParticleFlowObjects";
108 
109  std::string inputContainerBase = m_inputContainer;
110  std::string outputContainerBase = m_outputContainer;
111 
112  m_inChargedFEKey = inputContainerBase;
113  m_inNeutralFEKey = inputContainerBase;
114 
115  m_outChargedFEKey = outputContainerBase;
116  m_outNeutralFEKey = outputContainerBase;
117 
118  //For both the input and output container basenames we first check if the string
119  //contains "ParticleFlowObjects". If it does we swap this for "ChargedParticleFlowObjects"
120  //and "NeutralParticleFlowObjects" respectively. If it doesn't we just append these two
121  //substrings to the end of the strings.
122 
123  size_t pos = inputContainerBase.find(subString);
124  if(pos != std::string::npos) {
125  std::string inChargedString = m_inChargedFEKey.key();
126  m_inChargedFEKey = inChargedString.replace(pos,subString.size(),subStringCharged);
127  std::string inNeutralString = m_inNeutralFEKey.key();
128  m_inNeutralFEKey = inNeutralString.replace(pos,subString.size(),subStringNeutral);
129  }
130  else {
131  m_inChargedFEKey = inputContainerBase + subStringCharged;
132  m_inNeutralFEKey = inputContainerBase + subStringNeutral;
133  }
134 
135  pos = outputContainerBase.find(subString);
136  if(pos != std::string::npos) {
137  std::string outChargedString = m_outChargedFEKey.key();
138  m_outChargedFEKey = outChargedString.replace(pos,subString.size(),subStringCharged);
139  std::string outNeutralString = m_outNeutralFEKey.key();
140  m_outNeutralFEKey = outNeutralString.replace(pos,subString.size(),subStringNeutral);
141  }
142  else{
143  m_outChargedFEKey = outputContainerBase + subStringCharged;
144  m_outNeutralFEKey = outputContainerBase + subStringNeutral;
145  }
146 
147  //The all FE container is a bit different. If the input container base contains
148  //"ParticleFlowObjects" we do nothing, otherwise we add this string onto the end.
149  pos = outputContainerBase.find(subString);
150  if(pos == std::string::npos) m_outAllFEKey = outputContainerBase + subString;
151  else m_outAllFEKey = outputContainerBase;
152 
153  ATH_CHECK(m_inChargedFEKey.initialize());
154  ATH_CHECK(m_inNeutralFEKey.initialize());
155 
156  ATH_CHECK(m_outChargedFEKey.initialize());
157  ATH_CHECK(m_outNeutralFEKey.initialize());
158  ATH_CHECK(m_outAllFEKey.initialize());
159 
160  // It is enough to initialise the ReadDecorHandleKeys for thread-safety
161  // We are not actually accessing the decorations, only ensuring they are present at runtime
162  // Hence, ReadDecorHandles are not explicitly required to be created
163 
164  // Prepend the FE input container name to the decorations
165  for (auto& key : m_inChargedFEDecorKeys) {
166  const std::string keyString = m_inChargedFEKey.key() + "." + key.key();
167  ATH_CHECK(key.assign(keyString));
168 
169  }
170 
171  for (auto& key : m_inNeutralFEDecorKeys) {
172  const std::string keyString = m_inNeutralFEKey.key() + "." + key.key();
173  ATH_CHECK(key.assign(keyString));
174  }
175 
176  ATH_CHECK(m_inChargedFEDecorKeys.initialize());
177  ATH_CHECK(m_inNeutralFEDecorKeys.initialize());
178 
179  break;
180  }
181  default:
182  ATH_MSG_ERROR(" Unsupported input type "<< m_inputType );
183  return StatusCode::FAILURE;
184  }
185 
186  return StatusCode::SUCCESS;
187 }
188 
190 
191 #ifndef XAOD_ANALYSIS
192  // Define monitored quantities
193  auto t_exec = Monitored::Timer<std::chrono::milliseconds>( "TIME_constitmod" );
194 #endif
195 
196  // Create the shallow copy according to the input type
197  switch(m_inputType){
198 
202  if(!sc.isSuccess()) return 1;
203  break;
204  }
205 
207  auto sc = copyModRecordFlowLike<xAOD::PFOContainer, xAOD::PFO>(m_inNeutralPFOKey, m_inChargedPFOKey, m_outNeutralPFOKey, m_outChargedPFOKey, m_outAllPFOKey);
208  if(!sc.isSuccess()) return 1;
209  break;
210  }
212  auto sc = copyModRecordFlowLike<xAOD::FlowElementContainer, xAOD::FlowElement>(m_inNeutralFEKey, m_inChargedFEKey, m_outNeutralFEKey, m_outChargedFEKey, m_outAllFEKey);
213  if(!sc.isSuccess()) return 1;
214  break;
215  }
216 
218  auto sc = copyModRecord(m_inTCCKey,
219  m_outTCCKey);
220  if(!sc.isSuccess()){return 1;}
221  break;
222  }
223 
224  default: {
225  ATH_MSG_WARNING( "Unsupported input type " << m_inputType );
226  }
227 
228  }
229 
230  #ifndef XAOD_ANALYSIS
231  auto mon = Monitored::Group(m_monTool, t_exec);
232  #endif
233  return 0;
234 }
235 
WriteHandle.h
Handle class for recording to StoreGate.
JetConstituentModSequence::m_inTCCKey
SG::ReadHandleKey< xAOD::TrackCaloClusterContainer > m_inTCCKey
Definition: JetConstituentModSequence.h:83
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
JetConstituentModSequence::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: JetConstituentModSequence.h:74
JetConstituentModSequence::m_modifiers
ToolHandleArray< IJetConstituentModifier > m_modifiers
Definition: JetConstituentModSequence.h:71
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
JetConstituentModSequence::m_byVertex
Gaudi::Property< bool > m_byVertex
Definition: JetConstituentModSequence.h:62
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TruthParticleContainer.h
JetConstituentModSequence::m_outputContainer
Gaudi::Property< std::string > m_outputContainer
Definition: JetConstituentModSequence.h:61
asg
Definition: DataHandleTestTool.h:28
JetConstituentModSequence::m_outChargedFEKey
SG::WriteHandleKey< xAOD::FlowElementContainer > m_outChargedFEKey
Definition: JetConstituentModSequence.h:95
JetConstituentModSequence::m_inClusterKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_inClusterKey
Definition: JetConstituentModSequence.h:80
JetConstituentModSequence::m_inNeutralFEKey
SG::ReadHandleKey< xAOD::FlowElementContainer > m_inNeutralFEKey
Definition: JetConstituentModSequence.h:97
CaloClusterAuxContainer.h
JetConstituentModSequence::m_vertexContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
Definition: JetConstituentModSequence.h:63
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
JetConstituentModSequence::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetConstituentModSequence.cxx:37
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
xAOD::TrackCaloCluster
TrackCaloCluster_v1 TrackCaloCluster
Reference the current persistent version:
Definition: TrackCaloCluster.h:12
TruthParticleAuxContainer.h
JetConstituentModSequence::m_outClusterKey
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outClusterKey
Definition: JetConstituentModSequence.h:81
JetConstituentModSequence::m_outChargedPFOKey
SG::WriteHandleKey< xAOD::PFOContainer > m_outChargedPFOKey
Definition: JetConstituentModSequence.h:87
JetConstituentModSequence::JetConstituentModSequence
JetConstituentModSequence(const std::string &name)
Definition: JetConstituentModSequence.cxx:26
JetConstituentModSequence::m_inputType
unsigned short m_inputType
Definition: JetConstituentModSequence.h:68
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrackParticleAuxContainer.h
JetConstituentModSequence::m_outAllPFOKey
SG::WriteHandleKey< xAOD::PFOContainer > m_outAllPFOKey
Definition: JetConstituentModSequence.h:92
JetConstituentModSequence::m_outNeutralPFOKey
SG::WriteHandleKey< xAOD::PFOContainer > m_outNeutralPFOKey
Definition: JetConstituentModSequence.h:90
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::FlowElement
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition: FlowElement.h:16
JetConstituentModSequence::m_inNeutralFEDecorKeys
SG::ReadDecorHandleKeyArray< xAOD::FlowElementContainer > m_inNeutralFEDecorKeys
Definition: JetConstituentModSequence.h:105
JetConstituentModSequence::m_saveAsShallow
bool m_saveAsShallow
Definition: JetConstituentModSequence.h:77
JetConstituentModSequence.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAODType::ParticleFlow
@ ParticleFlow
The object is a particle-flow object.
Definition: ObjectType.h:41
JetConstituentModSequence::m_inNeutralPFOKey
SG::ReadHandleKey< xAOD::PFOContainer > m_inNeutralPFOKey
Definition: JetConstituentModSequence.h:89
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
JetConstituentModSequence::m_outNeutralFEKey
SG::WriteHandleKey< xAOD::FlowElementContainer > m_outNeutralFEKey
Definition: JetConstituentModSequence.h:98
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
JetConstituentModSequence::copyModRecord
StatusCode copyModRecord(const SG::ReadHandleKey< T > &, const SG::WriteHandleKey< T > &) const
helper function to cast, shallow copy and record a container.
Definition: JetConstituentModSequence.h:121
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
JetConstituentModSequence::execute
int execute() const
Method to be called for each event.
Definition: JetConstituentModSequence.cxx:189
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
JetConstituentModSequence::m_inChargedPFOKey
SG::ReadHandleKey< xAOD::PFOContainer > m_inChargedPFOKey
Definition: JetConstituentModSequence.h:86
TrackParticle.h
JetConstituentModSequence::m_inChargedFEKey
SG::ReadHandleKey< xAOD::FlowElementContainer > m_inChargedFEKey
Definition: JetConstituentModSequence.h:94
VertexContainer.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:67
JetConstituentModSequence::m_outAllFEKey
SG::WriteHandleKey< xAOD::FlowElementContainer > m_outAllFEKey
Definition: JetConstituentModSequence.h:100
JetConstituentModSequence::m_outTCCKey
SG::WriteHandleKey< xAOD::TrackCaloClusterContainer > m_outTCCKey
Definition: JetConstituentModSequence.h:84
TruthParticle.h
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
TrackParticleContainer.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
JetConstituentModSequence::m_inChargedFEDecorKeys
SG::ReadDecorHandleKeyArray< xAOD::FlowElementContainer > m_inChargedFEDecorKeys
Definition: JetConstituentModSequence.h:104
JetConstituentModSequence::m_inputContainer
Gaudi::Property< std::string > m_inputContainer
Definition: JetConstituentModSequence.h:60