LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 
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 
82 class LArMCParticleParameters : public object_creation::MCParticle::Parameters
83 {
84 public:
85  pandora::InputInt m_nuanceCode;
86  pandora::InputInt m_process;
87 };
88 
89 //------------------------------------------------------------------------------------------------------------------------------------------
90 
94 class LArMCParticle : public object_creation::MCParticle::Object
95 {
96 public:
102  LArMCParticle(const LArMCParticleParameters &parameters);
103 
109  int GetNuanceCode() const;
110 
116  void FillParameters(LArMCParticleParameters &parameters) const;
117 
123  MCProcess GetProcess() const;
124 
125 private:
127  int m_process;
128 };
129 
130 //------------------------------------------------------------------------------------------------------------------------------------------
131 
135 class LArMCParticleFactory : public pandora::ObjectFactory<object_creation::MCParticle::Parameters, object_creation::MCParticle::Object>
136 {
137 public:
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 
176 private:
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 
223 inline LArMCParticleFactory::LArMCParticleFactory(const unsigned int version) :
224  m_version(version)
225 {
226 }
227 
228 //------------------------------------------------------------------------------------------------------------------------------------------
229 
230 inline LArMCParticleFactory::Parameters *LArMCParticleFactory::NewParameters() const
231 {
232  return (new LArMCParticleParameters);
233 }
234 
235 //------------------------------------------------------------------------------------------------------------------------------------------
236 
237 inline pandora::StatusCode LArMCParticleFactory::Create(const Parameters &parameters, const Object *&pObject) const
238 {
239  const LArMCParticleParameters &larMCParticleParameters(dynamic_cast<const LArMCParticleParameters &>(parameters));
240  pObject = new LArMCParticle(larMCParticleParameters);
241 
242  return pandora::STATUS_CODE_SUCCESS;
243 }
244 
245 //------------------------------------------------------------------------------------------------------------------------------------------
246 
247 inline pandora::StatusCode LArMCParticleFactory::Read(Parameters &parameters, pandora::FileReader &fileReader) const
248 {
249  // ATTN: To receive this call-back must have already set file reader mc particle factory to this factory
250  int nuanceCode(0);
251  int process(0);
252 
253  if (pandora::BINARY == fileReader.GetFileType())
254  {
255  pandora::BinaryFileReader &binaryFileReader(dynamic_cast<pandora::BinaryFileReader &>(fileReader));
256  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(nuanceCode));
257 
258  if (m_version > 1)
259  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(process));
260  }
261  else if (pandora::XML == fileReader.GetFileType())
262  {
263  pandora::XmlFileReader &xmlFileReader(dynamic_cast<pandora::XmlFileReader &>(fileReader));
264  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("NuanceCode", nuanceCode));
265 
266  if (m_version > 1)
267  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("Process", process));
268  }
269  else
270  {
271  return pandora::STATUS_CODE_INVALID_PARAMETER;
272  }
273 
274  LArMCParticleParameters &larMCParticleParameters(dynamic_cast<LArMCParticleParameters &>(parameters));
275  larMCParticleParameters.m_nuanceCode = nuanceCode;
276  larMCParticleParameters.m_process = process;
277 
278  return pandora::STATUS_CODE_SUCCESS;
279 }
280 
281 //------------------------------------------------------------------------------------------------------------------------------------------
282 
283 inline pandora::StatusCode LArMCParticleFactory::Write(const Object *const pObject, pandora::FileWriter &fileWriter) const
284 {
285  // ATTN: To receive this call-back must have already set file writer mc particle factory to this factory
286  const LArMCParticle *const pLArMCParticle(dynamic_cast<const LArMCParticle *>(pObject));
287 
288  if (!pLArMCParticle)
289  return pandora::STATUS_CODE_INVALID_PARAMETER;
290 
291  if (pandora::BINARY == fileWriter.GetFileType())
292  {
293  pandora::BinaryFileWriter &binaryFileWriter(dynamic_cast<pandora::BinaryFileWriter &>(fileWriter));
294  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(pLArMCParticle->GetNuanceCode()));
295 
296  if (m_version > 1)
297  PANDORA_RETURN_RESULT_IF(
298  pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(static_cast<int>(pLArMCParticle->GetProcess())));
299  }
300  else if (pandora::XML == fileWriter.GetFileType())
301  {
302  pandora::XmlFileWriter &xmlFileWriter(dynamic_cast<pandora::XmlFileWriter &>(fileWriter));
303  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("NuanceCode", pLArMCParticle->GetNuanceCode()));
304 
305  if (m_version > 1)
306  PANDORA_RETURN_RESULT_IF(
307  pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("Process", static_cast<int>(pLArMCParticle->GetProcess())));
308  }
309  else
310  {
311  return pandora::STATUS_CODE_INVALID_PARAMETER;
312  }
313 
314  return pandora::STATUS_CODE_SUCCESS;
315 }
316 
317 } // namespace lar_content
318 
319 #endif // #ifndef LAR_MC_PARTICLE_H
int m_process
The process that created the particle.
Read("Flexi","livermore")
int GetNuanceCode() const
Get the nuance code.
MCProcess GetProcess() const
Get the process.
LArMCParticleFactory(const unsigned int version=2)
Constructor.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
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.
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) ...