LArCaloHit.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArObjects/LArCaloHit.h
3  *
4  * @brief Header file for the lar calo hit class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_CALO_HIT_H
9 #define LAR_CALO_HIT_H 1
10 
11 #include "Objects/CaloHit.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 /**
25  * @brief LAr calo hit parameters
26  */
27 class LArCaloHitParameters : public object_creation::CaloHit::Parameters
28 {
29 public:
30  pandora::InputUInt m_larTPCVolumeId; ///< The lar tpc volume id
31  pandora::InputUInt m_daughterVolumeId; ///< The daughter volume id
32 };
33 
34 //------------------------------------------------------------------------------------------------------------------------------------------
35 
36 /**
37  * @brief LAr calo hit class
38  */
40 {
41 public:
42  /**
43  * @brief Constructor
44  *
45  * @param parameters the lar calo hit parameters
46  */
47  LArCaloHit(const LArCaloHitParameters &parameters);
48 
49  /**
50  * @brief Get the lar tpc volume id
51  *
52  * @return the lar tpc volume id
53  */
54  unsigned int GetLArTPCVolumeId() const;
55 
56  /**
57  * @brief Get the daughter volume id
58  *
59  * @return the daughter volume id
60  */
61  unsigned int GetDaughterVolumeId() const;
62 
63  /**
64  * @brief Fill the parameters associated with this calo hit
65  *
66  * @param parameters the output parameters
67  */
68  void FillParameters(LArCaloHitParameters &parameters) const;
69 
70  /**
71  * @brief Get the probability that the hit is track-like
72  *
73  * @return the probability the hit is track-like
74  */
75  float GetTrackProbability() const;
76 
77  /**
78  * @brief Get the probability that the hit is shower-like
79  *
80  * @return the probability the hit is shower-like
81  */
82  float GetShowerProbability() const;
83 
84  /**
85  * @brief Set the probability that the hit is track-like
86  *
87  * @param probability the probability the hit is track-like
88  */
89  void SetTrackProbability(const float probability);
90 
91  /**
92  * @brief Set the probability that the hit is shower-like
93  *
94  * @param probability the probability the hit is shower-like
95  */
96  void SetShowerProbability(const float probability);
97 
98 private:
99  unsigned int m_larTPCVolumeId; ///< The lar tpc volume id
100  unsigned int m_daughterVolumeId; ///< The daughter volume id
101  pandora::InputFloat m_pTrack; ///< The probability that the hit is track-like
102  pandora::InputFloat m_pShower; ///< The probability that the hit is shower-like
103 };
104 
105 //------------------------------------------------------------------------------------------------------------------------------------------
106 
107 /**
108  * @brief LArCaloHitFactory responsible for object creation
109  */
110 class LArCaloHitFactory : public pandora::ObjectFactory<object_creation::CaloHit::Parameters, object_creation::CaloHit::Object>
111 {
112 public:
113  /**
114  * @brief Constructor
115  *
116  * @param version the LArCaloHit version
117  */
118  LArCaloHitFactory(const unsigned int version = 1);
119 
120  /**
121  * @brief Create new parameters instance on the heap (memory-management to be controlled by user)
122  *
123  * @return the address of the new parameters instance
124  */
125  Parameters *NewParameters() const;
126 
127  /**
128  * @brief Read any additional (derived class only) object parameters from file using the specified file reader
129  *
130  * @param parameters the parameters to pass in constructor
131  * @param fileReader the file reader, used to extract any additional parameters from file
132  */
133  pandora::StatusCode Read(Parameters &parameters, pandora::FileReader &fileReader) const;
134 
135  /**
136  * @brief Persist any additional (derived class only) object parameters using the specified file writer
137  *
138  * @param pObject the address of the object to persist
139  * @param fileWriter the file writer
140  */
141  pandora::StatusCode Write(const Object *const pObject, pandora::FileWriter &fileWriter) const;
142 
143  /**
144  * @brief Create an object with the given parameters
145  *
146  * @param parameters the parameters to pass in constructor
147  * @param pObject to receive the address of the object created
148  */
149  pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const;
150 
151 private:
152  unsigned int m_version; ///< The LArCaloHit version
153 };
154 
155 //------------------------------------------------------------------------------------------------------------------------------------------
156 //------------------------------------------------------------------------------------------------------------------------------------------
157 
158 inline LArCaloHit::LArCaloHit(const LArCaloHitParameters &parameters) :
159  object_creation::CaloHit::Object(parameters),
160  m_larTPCVolumeId(parameters.m_larTPCVolumeId.Get()),
161  m_daughterVolumeId(parameters.m_daughterVolumeId.IsInitialized() ? parameters.m_daughterVolumeId.Get() : 0)
162 {
163 }
164 
165 //------------------------------------------------------------------------------------------------------------------------------------------
166 
167 inline unsigned int LArCaloHit::GetLArTPCVolumeId() const
168 {
169  return m_larTPCVolumeId;
170 }
171 
172 //------------------------------------------------------------------------------------------------------------------------------------------
173 
174 inline unsigned int LArCaloHit::GetDaughterVolumeId() const
175 {
176  return m_daughterVolumeId;
177 }
178 
179 //------------------------------------------------------------------------------------------------------------------------------------------
180 
181 inline void LArCaloHit::FillParameters(LArCaloHitParameters &parameters) const
182 {
183  parameters.m_positionVector = this->GetPositionVector();
184  parameters.m_expectedDirection = this->GetExpectedDirection();
185  parameters.m_cellNormalVector = this->GetCellNormalVector();
186  parameters.m_cellGeometry = this->GetCellGeometry();
187  parameters.m_cellSize0 = this->GetCellSize0();
188  parameters.m_cellSize1 = this->GetCellSize1();
189  parameters.m_cellThickness = this->GetCellThickness();
190  parameters.m_nCellRadiationLengths = this->GetNCellRadiationLengths();
191  parameters.m_nCellInteractionLengths = this->GetNCellInteractionLengths();
192  parameters.m_time = this->GetTime();
193  parameters.m_inputEnergy = this->GetInputEnergy();
194  parameters.m_mipEquivalentEnergy = this->GetMipEquivalentEnergy();
195  parameters.m_electromagneticEnergy = this->GetElectromagneticEnergy();
196  parameters.m_hadronicEnergy = this->GetHadronicEnergy();
197  parameters.m_isDigital = this->IsDigital();
198  parameters.m_hitType = this->GetHitType();
199  parameters.m_hitRegion = this->GetHitRegion();
200  parameters.m_layer = this->GetLayer();
201  parameters.m_isInOuterSamplingLayer = this->IsInOuterSamplingLayer();
202  // ATTN Set the parent address to the original owner of the calo hit
203  parameters.m_pParentAddress = static_cast<const void *>(this);
204  parameters.m_larTPCVolumeId = this->GetLArTPCVolumeId();
205  parameters.m_daughterVolumeId = this->GetDaughterVolumeId();
206 }
207 
208 //------------------------------------------------------------------------------------------------------------------------------------------
209 
211 {
212  return m_pTrack.Get();
213 }
214 
215 //------------------------------------------------------------------------------------------------------------------------------------------
216 
218 {
219  return m_pShower.Get();
220 }
221 
222 //------------------------------------------------------------------------------------------------------------------------------------------
223 
224 inline void LArCaloHit::SetTrackProbability(const float probability)
225 {
226  if (probability >= 0.f)
227  m_pTrack = probability;
228  else
229  throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
230 }
231 
232 //------------------------------------------------------------------------------------------------------------------------------------------
233 
234 inline void LArCaloHit::SetShowerProbability(const float probability)
235 {
236  if (probability >= 0.f)
237  m_pShower = probability;
238  else
239  throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
240 }
241 
242 //------------------------------------------------------------------------------------------------------------------------------------------
243 //------------------------------------------------------------------------------------------------------------------------------------------
244 
245 inline LArCaloHitFactory::LArCaloHitFactory(const unsigned int version) : m_version(version)
246 {
247 }
248 
249 //------------------------------------------------------------------------------------------------------------------------------------------
250 
251 inline LArCaloHitFactory::Parameters *LArCaloHitFactory::NewParameters() const
252 {
253  return (new LArCaloHitParameters);
254 }
255 
256 //------------------------------------------------------------------------------------------------------------------------------------------
257 
258 inline pandora::StatusCode LArCaloHitFactory::Create(const Parameters &parameters, const Object *&pObject) const
259 {
260  const LArCaloHitParameters &larCaloHitParameters(dynamic_cast<const LArCaloHitParameters &>(parameters));
261  pObject = new LArCaloHit(larCaloHitParameters);
262 
263  return pandora::STATUS_CODE_SUCCESS;
264 }
265 
266 //------------------------------------------------------------------------------------------------------------------------------------------
267 
268 inline pandora::StatusCode LArCaloHitFactory::Read(Parameters &parameters, pandora::FileReader &fileReader) const
269 {
270  // ATTN: To receive this call-back must have already set file reader mc particle factory to this factory
271  unsigned int larTPCVolumeId(std::numeric_limits<unsigned int>::max());
272  unsigned int daughterVolumeId(0);
273 
274  if (pandora::BINARY == fileReader.GetFileType())
275  {
276  pandora::BinaryFileReader &binaryFileReader(dynamic_cast<pandora::BinaryFileReader &>(fileReader));
277  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(larTPCVolumeId));
278  if (m_version > 1)
279  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(daughterVolumeId));
280  }
281  else if (pandora::XML == fileReader.GetFileType())
282  {
283  pandora::XmlFileReader &xmlFileReader(dynamic_cast<pandora::XmlFileReader &>(fileReader));
284  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("LArTPCVolumeId", larTPCVolumeId));
285  if (m_version > 1)
286  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("DaughterVolumeId", daughterVolumeId));
287  }
288  else
289  {
290  return pandora::STATUS_CODE_INVALID_PARAMETER;
291  }
292 
293  LArCaloHitParameters &larCaloHitParameters(dynamic_cast<LArCaloHitParameters &>(parameters));
294  larCaloHitParameters.m_larTPCVolumeId = larTPCVolumeId;
295  larCaloHitParameters.m_daughterVolumeId = daughterVolumeId;
296 
297  return pandora::STATUS_CODE_SUCCESS;
298 }
299 
300 //------------------------------------------------------------------------------------------------------------------------------------------
301 
302 inline pandora::StatusCode LArCaloHitFactory::Write(const Object *const pObject, pandora::FileWriter &fileWriter) const
303 {
304  // ATTN: To receive this call-back must have already set file writer mc particle factory to this factory
305  const LArCaloHit *const pLArCaloHit(dynamic_cast<const LArCaloHit *>(pObject));
306 
307  if (!pLArCaloHit)
308  return pandora::STATUS_CODE_INVALID_PARAMETER;
309 
310  if (pandora::BINARY == fileWriter.GetFileType())
311  {
312  pandora::BinaryFileWriter &binaryFileWriter(dynamic_cast<pandora::BinaryFileWriter &>(fileWriter));
313  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(pLArCaloHit->GetLArTPCVolumeId()));
314  if (m_version > 1)
315  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(pLArCaloHit->GetDaughterVolumeId()));
316  }
317  else if (pandora::XML == fileWriter.GetFileType())
318  {
319  pandora::XmlFileWriter &xmlFileWriter(dynamic_cast<pandora::XmlFileWriter &>(fileWriter));
320  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("LArTPCVolumeId", pLArCaloHit->GetLArTPCVolumeId()));
321  if (m_version > 1)
322  PANDORA_RETURN_RESULT_IF(
323  pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("DaughterVolumeId", pLArCaloHit->GetDaughterVolumeId()));
324  }
325  else
326  {
327  return pandora::STATUS_CODE_INVALID_PARAMETER;
328  }
329 
330  return pandora::STATUS_CODE_SUCCESS;
331 }
332 
333 } // namespace lar_content
334 
335 #endif // #ifndef LAR_CALO_HIT_H
Parameters * NewParameters() const
Create new parameters instance on the heap (memory-management to be controlled by user) ...
Definition: LArCaloHit.h:251
void SetShowerProbability(const float probability)
Set the probability that the hit is shower-like.
Definition: LArCaloHit.h:234
pandora::StatusCode Read(Parameters &parameters, pandora::FileReader &fileReader) const
Read any additional (derived class only) object parameters from file using the specified file reader...
Definition: LArCaloHit.h:268
pandora::InputFloat m_pTrack
The probability that the hit is track-like.
Definition: LArCaloHit.h:101
pandora::InputUInt m_larTPCVolumeId
The lar tpc volume id.
Definition: LArCaloHit.h:30
unsigned int GetLArTPCVolumeId() const
Get the lar tpc volume id.
Definition: LArCaloHit.h:167
unsigned int m_version
The LArCaloHit version.
Definition: LArCaloHit.h:152
LAr calo hit class.
Definition: LArCaloHit.h:39
pandora::InputFloat m_pShower
The probability that the hit is shower-like.
Definition: LArCaloHit.h:102
unsigned int m_larTPCVolumeId
The lar tpc volume id.
Definition: LArCaloHit.h:99
LArCaloHitFactory(const unsigned int version=1)
Constructor.
Definition: LArCaloHit.h:245
unsigned int m_daughterVolumeId
The daughter volume id.
Definition: LArCaloHit.h:100
LAr calo hit parameters.
Definition: LArCaloHit.h:27
float GetShowerProbability() const
Get the probability that the hit is shower-like.
Definition: LArCaloHit.h:217
pandora::InputUInt m_daughterVolumeId
The daughter volume id.
Definition: LArCaloHit.h:31
Definition: manual.c:13
void FillParameters(LArCaloHitParameters &parameters) const
Fill the parameters associated with this calo hit.
Definition: LArCaloHit.h:181
pandora::StatusCode Write(const Object *const pObject, pandora::FileWriter &fileWriter) const
Persist any additional (derived class only) object parameters using the specified file writer...
Definition: LArCaloHit.h:302
void SetTrackProbability(const float probability)
Set the probability that the hit is track-like.
Definition: LArCaloHit.h:224
static int max(int a, int b)
struct Object Object
Object type.
Definition: manual.c:5
pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const
Create an object with the given parameters.
Definition: LArCaloHit.h:258
LArCaloHitFactory responsible for object creation.
Definition: LArCaloHit.h:110
hadnt Write("hadnt")
unsigned int GetDaughterVolumeId() const
Get the daughter volume id.
Definition: LArCaloHit.h:174
LArCaloHit(const LArCaloHitParameters &parameters)
Constructor.
Definition: LArCaloHit.h:158
float GetTrackProbability() const
Get the probability that the hit is track-like.
Definition: LArCaloHit.h:210