Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
LArMCParticle.h
Go to the documentation of this file.
1
8#ifndef LAR_MC_PARTICLE_H
9#define LAR_MC_PARTICLE_H 1
10
11#include "Objects/MCParticle.h"
12
15
20
21namespace lar_content
22{
23
24// Enumeration maps onto G4 process IDs from QGSP_BERT and EM standard physics lists, plus an ID for the incident neutrino
78
88
89//------------------------------------------------------------------------------------------------------------------------------------------
90
95{
96public:
102 LArMCParticle(const LArMCParticleParameters &parameters);
103
109 int GetNuanceCode() const;
110
116 void FillParameters(LArMCParticleParameters &parameters) const;
117
123 MCProcess GetProcess() const;
124
125private:
128};
129
130//------------------------------------------------------------------------------------------------------------------------------------------
131
135class LArMCParticleFactory : public pandora::ObjectFactory<object_creation::MCParticle::Parameters, object_creation::MCParticle::Object>
136{
137public:
143 LArMCParticleFactory(const unsigned int version = 2);
144
150 Parameters *NewParameters() const;
151
158 pandora::StatusCode Read(Parameters &parameters, pandora::FileReader &fileReader) const;
159
166 pandora::StatusCode Write(const Object *const pObject, pandora::FileWriter &fileWriter) const;
167
174 pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const;
175
176private:
177 unsigned int m_version;
178};
179
180//------------------------------------------------------------------------------------------------------------------------------------------
181//------------------------------------------------------------------------------------------------------------------------------------------
182
184 object_creation::MCParticle::Object(parameters),
185 m_nuanceCode(parameters.m_nuanceCode.Get()),
186 m_process(parameters.m_process.Get())
187{
188}
189
190//------------------------------------------------------------------------------------------------------------------------------------------
191
193{
194 return m_nuanceCode;
195}
196
197//------------------------------------------------------------------------------------------------------------------------------------------
198
200{
201 parameters.m_nuanceCode = this->GetNuanceCode();
202 parameters.m_process = this->GetProcess();
203 parameters.m_energy = this->GetEnergy();
204 parameters.m_momentum = this->GetMomentum();
205 parameters.m_vertex = this->GetVertex();
206 parameters.m_endpoint = this->GetEndpoint();
207 parameters.m_particleId = this->GetParticleId();
208 parameters.m_mcParticleType = this->GetMCParticleType();
209 // ATTN Set the parent address to the original owner of the mc particle
210 parameters.m_pParentAddress = static_cast<const void *>(this);
211}
212
213//------------------------------------------------------------------------------------------------------------------------------------------
214
216{
217 return MCProcess(m_process);
218}
219
220//------------------------------------------------------------------------------------------------------------------------------------------
221//------------------------------------------------------------------------------------------------------------------------------------------
222
223inline LArMCParticleFactory::LArMCParticleFactory(const unsigned int version) : m_version(version)
224{
225}
226
227//------------------------------------------------------------------------------------------------------------------------------------------
228
233
234//------------------------------------------------------------------------------------------------------------------------------------------
235
236inline pandora::StatusCode LArMCParticleFactory::Create(const Parameters &parameters, const Object *&pObject) const
237{
238 const LArMCParticleParameters &larMCParticleParameters(dynamic_cast<const LArMCParticleParameters &>(parameters));
239 pObject = new LArMCParticle(larMCParticleParameters);
240
241 return pandora::STATUS_CODE_SUCCESS;
242}
243
244//------------------------------------------------------------------------------------------------------------------------------------------
245
247{
248 // ATTN: To receive this call-back must have already set file reader mc particle factory to this factory
249 int nuanceCode(0);
250 int process(0);
251
252 if (pandora::BINARY == fileReader.GetFileType())
253 {
254 pandora::BinaryFileReader &binaryFileReader(dynamic_cast<pandora::BinaryFileReader &>(fileReader));
255 PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(nuanceCode));
256
257 if (m_version > 1)
258 PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(process));
259 }
260 else if (pandora::XML == fileReader.GetFileType())
261 {
262 pandora::XmlFileReader &xmlFileReader(dynamic_cast<pandora::XmlFileReader &>(fileReader));
263 PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("NuanceCode", nuanceCode));
264
265 if (m_version > 1)
266 PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("Process", process));
267 }
268 else
269 {
270 return pandora::STATUS_CODE_INVALID_PARAMETER;
271 }
272
273 LArMCParticleParameters &larMCParticleParameters(dynamic_cast<LArMCParticleParameters &>(parameters));
274 larMCParticleParameters.m_nuanceCode = nuanceCode;
275 larMCParticleParameters.m_process = process;
276
277 return pandora::STATUS_CODE_SUCCESS;
278}
279
280//------------------------------------------------------------------------------------------------------------------------------------------
281
282inline pandora::StatusCode LArMCParticleFactory::Write(const Object *const pObject, pandora::FileWriter &fileWriter) const
283{
284 // ATTN: To receive this call-back must have already set file writer mc particle factory to this factory
285 const LArMCParticle *const pLArMCParticle(dynamic_cast<const LArMCParticle *>(pObject));
286
287 if (!pLArMCParticle)
288 return pandora::STATUS_CODE_INVALID_PARAMETER;
289
290 if (pandora::BINARY == fileWriter.GetFileType())
291 {
292 pandora::BinaryFileWriter &binaryFileWriter(dynamic_cast<pandora::BinaryFileWriter &>(fileWriter));
293 PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(pLArMCParticle->GetNuanceCode()));
294
295 if (m_version > 1)
297 pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(static_cast<int>(pLArMCParticle->GetProcess())));
298 }
299 else if (pandora::XML == fileWriter.GetFileType())
300 {
301 pandora::XmlFileWriter &xmlFileWriter(dynamic_cast<pandora::XmlFileWriter &>(fileWriter));
302 PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("NuanceCode", pLArMCParticle->GetNuanceCode()));
303
304 if (m_version > 1)
306 pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("Process", static_cast<int>(pLArMCParticle->GetProcess())));
307 }
308 else
309 {
310 return pandora::STATUS_CODE_INVALID_PARAMETER;
311 }
312
313 return pandora::STATUS_CODE_SUCCESS;
314}
315
316} // namespace lar_content
317
318#endif // #ifndef LAR_MC_PARTICLE_H
Header file for the binary file reader class.
Header file for the binary file writer class.
Header file for the mc particle class.
Header file for pandora object creation classes.
Header file for the pandora object factories classes.
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
Header file for the xml file reader class.
Header file for the xml file writer class.
Parameters class.
Definition Validation.h:20
LArMCParticleFactory responsible for object creation.
LArMCParticleFactory(const unsigned int version=2)
Constructor.
Parameters * NewParameters() const
Create new parameters instance on the heap (memory-management to be controlled by user)
pandora::StatusCode Write(const Object *const pObject, pandora::FileWriter &fileWriter) const
Persist any additional (derived class only) object parameters using the specified file writer.
pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const
Create an object with the given parameters.
pandora::StatusCode Read(Parameters &parameters, pandora::FileReader &fileReader) const
Read any additional (derived class only) object parameters from file using the specified file reader.
unsigned int m_version
The LArMCParticle version.
LAr mc particle class.
void FillParameters(LArMCParticleParameters &parameters) const
Fill the parameters associated with this MC particle.
int m_nuanceCode
The nuance code.
MCProcess GetProcess() const
Get the process.
int GetNuanceCode() const
Get the nuance code.
int m_process
The process that created the particle.
LArMCParticle(const LArMCParticleParameters &parameters)
Constructor.
LAr mc particle parameters.
pandora::InputInt m_nuanceCode
The nuance code.
pandora::InputInt m_process
The process creating the particle.
BinaryFileReader class.
StatusCode ReadVariable(T &t)
Read a variable from the file.
BinaryFileWriter class.
StatusCode WriteVariable(const T &t)
Write a variable to the file.
FileReader class.
Definition FileReader.h:29
FileWriter class.
Definition FileWriter.h:29
MCParticle class.
Definition MCParticle.h:26
ObjectFactory class responsible for extended pandora object creation.
FileType GetFileType() const
Get the file type.
Definition Persistency.h:97
XmlFileReader class.
StatusCode ReadVariable(const std::string &xmlKey, T &t)
Read a variable from the file.
XmlFileWriter class.
StatusCode WriteVariable(const std::string &xmlKey, const T &t)
Write a variable to the file.
@ MC_PROC_HAD_BERTINI_CAPTURE_AT_REST
@ MC_PROC_NEUTRON_INELASTIC
@ MC_PROC_ALPHA_INELASTIC
@ MC_PROC_DEUTERON_INELASTIC
@ MC_PROC_TRITON_INELASTIC
@ MC_PROC_ANTI_DEUTERON_INELASTIC
@ MC_PROC_PI_PLUS_INELASTIC
@ MC_PROC_ANTI_NEUTRON_INELASTIC
@ MC_PROC_ANTI_ALPHA_INELASTIC
@ MC_PROC_CHIPS_NUCLEAR_CAPTURE_AT_REST
@ MC_PROC_PRIMARY_BACKGROUND
@ MC_PROC_ANTI_TRITON_INELASTIC
@ MC_PROC_ELECTRON_NUCLEAR
@ MC_PROC_ANTI_PROTON_INELASTIC
@ MC_PROC_PI_MINUS_INELASTIC
@ MC_PROC_PROTON_INELASTIC
@ MC_PROC_PHOTON_INELASTIC
@ MC_PROC_MU_MINUS_CAPTURE_AT_REST
@ MC_PROC_HAD_FRITIOF_CAPTURE_AT_REST
@ MC_PROC_KAON_PLUS_INELASTIC
@ MC_PROC_LAMBDA_INELASTIC
@ MC_PROC_ANTI_HE3_INELASTIC
@ MC_PROC_KAON_MINUS_INELASTIC
StatusCode
The StatusCode enum.