All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArMCParticle.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArObjects/LArMCParticle.h
3  *
4  * @brief Header file for the lar mc particle class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_MC_PARTICLE_H
9 #define LAR_MC_PARTICLE_H 1
10 
11 #include "Objects/MCParticle.h"
12 
13 #include "Pandora/ObjectCreation.h"
14 #include "Pandora/PandoraObjectFactories.h"
15 
16 #include "Persistency/BinaryFileReader.h"
17 #include "Persistency/BinaryFileWriter.h"
18 #include "Persistency/XmlFileReader.h"
19 #include "Persistency/XmlFileWriter.h"
20 
21 namespace 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
26 {
77 };
78 
79 /**
80  * @brief LAr mc particle parameters
81  */
83 {
84 public:
85  pandora::InputInt m_nuanceCode; ///< The nuance code
86  pandora::InputInt m_process; ///< The process creating the particle
87 };
88 
89 //------------------------------------------------------------------------------------------------------------------------------------------
90 
91 /**
92  * @brief LAr mc particle class
93  */
94 class LArMCParticle : public object_creation::MCParticle::Object
95 {
96 public:
97  /**
98  * @brief Constructor
99  *
100  * @param parameters the lar mc particle parameters
101  */
102  LArMCParticle(const LArMCParticleParameters &parameters);
103 
104  /**
105  * @brief Get the nuance code
106  *
107  * @return the nuance code
108  */
109  int GetNuanceCode() const;
110 
111  /**
112  * @brief Fill the parameters associated with this MC particle
113  *
114  * @param parameters the output parameters
115  */
116  void FillParameters(LArMCParticleParameters &parameters) const;
117 
118  /**
119  * @brief Get the process
120  *
121  * @return the process
122  */
123  MCProcess GetProcess() const;
124 
125 private:
126  int m_nuanceCode; ///< The nuance code
127  int m_process; ///< The process that created the particle
128 };
129 
130 //------------------------------------------------------------------------------------------------------------------------------------------
131 
132 /**
133  * @brief LArMCParticleFactory responsible for object creation
134  */
135 class LArMCParticleFactory : public pandora::ObjectFactory<object_creation::MCParticle::Parameters, object_creation::MCParticle::Object>
136 {
137 public:
138  /**
139  * @brief Constructor
140  *
141  * @param version the LArMCParticle version
142  */
143  LArMCParticleFactory(const unsigned int version = 2);
144 
145  /**
146  * @brief Create new parameters instance on the heap (memory-management to be controlled by user)
147  *
148  * @return the address of the new parameters instance
149  */
150  Parameters *NewParameters() const;
151 
152  /**
153  * @brief Read any additional (derived class only) object parameters from file using the specified file reader
154  *
155  * @param parameters the parameters to pass in constructor
156  * @param fileReader the file reader, used to extract any additional parameters from file
157  */
158  pandora::StatusCode Read(Parameters &parameters, pandora::FileReader &fileReader) const;
159 
160  /**
161  * @brief Persist any additional (derived class only) object parameters using the specified file writer
162  *
163  * @param pObject the address of the object to persist
164  * @param fileWriter the file writer
165  */
166  pandora::StatusCode Write(const Object *const pObject, pandora::FileWriter &fileWriter) const;
167 
168  /**
169  * @brief Create an object with the given parameters
170  *
171  * @param parameters the parameters to pass in constructor
172  * @param pObject to receive the address of the object created
173  */
174  pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const;
175 
176 private:
177  unsigned int m_version; ///< The LArMCParticle 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 
223 inline LArMCParticleFactory::LArMCParticleFactory(const unsigned int version) : m_version(version)
224 {
225 }
226 
227 //------------------------------------------------------------------------------------------------------------------------------------------
228 
230 {
231  return (new LArMCParticleParameters);
232 }
233 
234 //------------------------------------------------------------------------------------------------------------------------------------------
235 
236 inline 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 
246 inline pandora::StatusCode LArMCParticleFactory::Read(Parameters &parameters, pandora::FileReader &fileReader) const
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 
282 inline 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)
296  PANDORA_RETURN_RESULT_IF(
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)
305  PANDORA_RETURN_RESULT_IF(
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
int m_process
The process that created the particle.
int GetNuanceCode() const
Get the nuance code.
MCProcess GetProcess() const
Get the process.
LArMCParticleFactory(const unsigned int version=2)
Constructor.
int m_nuanceCode
The nuance code.
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::InputInt m_process
The process creating the particle.
Definition: LArMCParticle.h:86
void FillParameters(LArMCParticleParameters &parameters) const
Fill the parameters associated with this MC particle.
LAr mc particle class.
Definition: LArMCParticle.h:94
pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const
Create an object with the given parameters.
unsigned int m_version
The LArMCParticle version.
pandora::StatusCode Read(Parameters &parameters, pandora::FileReader &fileReader) const
Read any additional (derived class only) object parameters from file using the specified file reader...
LArMCParticleFactory responsible for object creation.
fhicl::Table< sbnd::crt::CRTDetSimParams > Parameters
LAr mc particle parameters.
Definition: LArMCParticle.h:82
pandora::InputInt m_nuanceCode
The nuance code.
Definition: LArMCParticle.h:85
LArMCParticle(const LArMCParticleParameters &parameters)
Constructor.
Parameters * NewParameters() const
Create new parameters instance on the heap (memory-management to be controlled by user) ...