ATLAS Offline Software
Loading...
Searching...
No Matches
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
62 ATH_CHECK(m_inClusterKey.initialize());
63 ATH_CHECK(m_outClusterKey.initialize());
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
208 if(!sc.isSuccess()) return 1;
209 break;
210 }
213 if(!sc.isSuccess()) return 1;
214 break;
215 }
216
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for recording to StoreGate.
static Double_t sc
Header file to be included by clients of the Monitored infrastructure.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
SG::ReadHandleKey< xAOD::FlowElementContainer > m_inChargedFEKey
StatusCode copyModRecord(const SG::ReadHandleKey< T > &, const SG::WriteHandleKey< T > &) const
helper function to cast, shallow copy and record a container.
ToolHandle< GenericMonitoringTool > m_monTool
Gaudi::Property< bool > m_byVertex
SG::WriteHandleKey< xAOD::PFOContainer > m_outChargedPFOKey
Gaudi::Property< std::string > m_outputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_outNeutralPFOKey
SG::ReadHandleKey< xAOD::PFOContainer > m_inChargedPFOKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
SG::WriteHandleKey< xAOD::PFOContainer > m_outAllPFOKey
SG::WriteHandleKey< xAOD::TrackCaloClusterContainer > m_outTCCKey
SG::WriteHandleKey< xAOD::FlowElementContainer > m_outAllFEKey
SG::WriteHandleKey< xAOD::FlowElementContainer > m_outNeutralFEKey
SG::ReadDecorHandleKeyArray< xAOD::FlowElementContainer > m_inChargedFEDecorKeys
SG::ReadHandleKey< xAOD::TrackCaloClusterContainer > m_inTCCKey
int execute() const
Method to be called for each event.
JetConstituentModSequence(const std::string &name)
StatusCode initialize()
Dummy implementation of the initialisation function.
ToolHandleArray< IJetConstituentModifier > m_modifiers
Gaudi::Property< std::string > m_inputContainer
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outClusterKey
SG::ReadHandleKey< xAOD::PFOContainer > m_inNeutralPFOKey
StatusCode copyModRecordFlowLike(const SG::ReadHandleKey< T > &, const SG::ReadHandleKey< T > &, const SG::WriteHandleKey< T > &, const SG::WriteHandleKey< T > &, const SG::WriteHandleKey< T > &) const
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_inClusterKey
SG::ReadDecorHandleKeyArray< xAOD::FlowElementContainer > m_inNeutralFEDecorKeys
SG::WriteHandleKey< xAOD::FlowElementContainer > m_outChargedFEKey
SG::ReadHandleKey< xAOD::FlowElementContainer > m_inNeutralFEKey
Group of local monitoring quantities and retain correlation when filling histograms
A monitored timer.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
@ ParticleFlow
The object is a particle-flow object.
Definition ObjectType.h:41
@ FlowElement
The object is a track-calo-cluster.
Definition ObjectType.h:52
@ CaloCluster
The object is a calorimeter cluster.
Definition ObjectType.h:39
@ TrackCaloCluster
The object is a track-calo-cluster.
Definition ObjectType.h:51