LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArCaloHit.h
Go to the documentation of this file.
1 
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 
27 class LArCaloHitParameters : public object_creation::CaloHit::Parameters
28 {
29 public:
30  pandora::InputUInt m_larTPCVolumeId;
31  pandora::InputUInt m_daughterVolumeId;
32 };
33 
34 //------------------------------------------------------------------------------------------------------------------------------------------
35 
39 class LArCaloHit : public object_creation::CaloHit::Object
40 {
41 public:
47  LArCaloHit(const LArCaloHitParameters &parameters);
48 
54  unsigned int GetLArTPCVolumeId() const;
55 
61  unsigned int GetDaughterVolumeId() const;
62 
68  void FillParameters(LArCaloHitParameters &parameters) const;
69 
75  float GetTrackProbability() const;
76 
82  float GetShowerProbability() const;
83 
89  void SetTrackProbability(const float probability);
90 
96  void SetShowerProbability(const float probability);
97 
98 private:
99  unsigned int m_larTPCVolumeId;
100  unsigned int m_daughterVolumeId;
101  pandora::InputFloat m_pTrack;
102  pandora::InputFloat m_pShower;
103 };
104 
105 //------------------------------------------------------------------------------------------------------------------------------------------
106 
110 class LArCaloHitFactory : public pandora::ObjectFactory<object_creation::CaloHit::Parameters, object_creation::CaloHit::Object>
111 {
112 public:
118  LArCaloHitFactory(const unsigned int version = 1);
119 
125  Parameters *NewParameters() const;
126 
133  pandora::StatusCode Read(Parameters &parameters, pandora::FileReader &fileReader) const;
134 
141  pandora::StatusCode Write(const Object *const pObject, pandora::FileWriter &fileWriter) const;
142 
149  pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const;
150 
151 private:
152  unsigned int m_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) :
246  m_version(version)
247 {
248 }
249 
250 //------------------------------------------------------------------------------------------------------------------------------------------
251 
252 inline LArCaloHitFactory::Parameters *LArCaloHitFactory::NewParameters() const
253 {
254  return (new LArCaloHitParameters);
255 }
256 
257 //------------------------------------------------------------------------------------------------------------------------------------------
258 
259 inline pandora::StatusCode LArCaloHitFactory::Create(const Parameters &parameters, const Object *&pObject) const
260 {
261  const LArCaloHitParameters &larCaloHitParameters(dynamic_cast<const LArCaloHitParameters &>(parameters));
262  pObject = new LArCaloHit(larCaloHitParameters);
263 
264  return pandora::STATUS_CODE_SUCCESS;
265 }
266 
267 //------------------------------------------------------------------------------------------------------------------------------------------
268 
269 inline pandora::StatusCode LArCaloHitFactory::Read(Parameters &parameters, pandora::FileReader &fileReader) const
270 {
271  // ATTN: To receive this call-back must have already set file reader mc particle factory to this factory
272  unsigned int larTPCVolumeId(std::numeric_limits<unsigned int>::max());
273  unsigned int daughterVolumeId(0);
274 
275  if (pandora::BINARY == fileReader.GetFileType())
276  {
277  pandora::BinaryFileReader &binaryFileReader(dynamic_cast<pandora::BinaryFileReader &>(fileReader));
278  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(larTPCVolumeId));
279  if (m_version > 1)
280  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(daughterVolumeId));
281  }
282  else if (pandora::XML == fileReader.GetFileType())
283  {
284  pandora::XmlFileReader &xmlFileReader(dynamic_cast<pandora::XmlFileReader &>(fileReader));
285  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("LArTPCVolumeId", larTPCVolumeId));
286  if (m_version > 1)
287  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("DaughterVolumeId", daughterVolumeId));
288  }
289  else
290  {
291  return pandora::STATUS_CODE_INVALID_PARAMETER;
292  }
293 
294  LArCaloHitParameters &larCaloHitParameters(dynamic_cast<LArCaloHitParameters &>(parameters));
295  larCaloHitParameters.m_larTPCVolumeId = larTPCVolumeId;
296  larCaloHitParameters.m_daughterVolumeId = daughterVolumeId;
297 
298  return pandora::STATUS_CODE_SUCCESS;
299 }
300 
301 //------------------------------------------------------------------------------------------------------------------------------------------
302 
303 inline pandora::StatusCode LArCaloHitFactory::Write(const Object *const pObject, pandora::FileWriter &fileWriter) const
304 {
305  // ATTN: To receive this call-back must have already set file writer mc particle factory to this factory
306  const LArCaloHit *const pLArCaloHit(dynamic_cast<const LArCaloHit *>(pObject));
307 
308  if (!pLArCaloHit)
309  return pandora::STATUS_CODE_INVALID_PARAMETER;
310 
311  if (pandora::BINARY == fileWriter.GetFileType())
312  {
313  pandora::BinaryFileWriter &binaryFileWriter(dynamic_cast<pandora::BinaryFileWriter &>(fileWriter));
314  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(pLArCaloHit->GetLArTPCVolumeId()));
315  if (m_version > 1)
316  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(pLArCaloHit->GetDaughterVolumeId()));
317  }
318  else if (pandora::XML == fileWriter.GetFileType())
319  {
320  pandora::XmlFileWriter &xmlFileWriter(dynamic_cast<pandora::XmlFileWriter &>(fileWriter));
321  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("LArTPCVolumeId", pLArCaloHit->GetLArTPCVolumeId()));
322  if (m_version > 1)
323  PANDORA_RETURN_RESULT_IF(
324  pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("DaughterVolumeId", pLArCaloHit->GetDaughterVolumeId()));
325  }
326  else
327  {
328  return pandora::STATUS_CODE_INVALID_PARAMETER;
329  }
330 
331  return pandora::STATUS_CODE_SUCCESS;
332 }
333 
334 } // namespace lar_content
335 
336 #endif // #ifndef LAR_CALO_HIT_H
Read("Flexi","livermore")
Parameters * NewParameters() const
Create new parameters instance on the heap (memory-management to be controlled by user) ...
Definition: LArCaloHit.h:252
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:269
pandora::InputFloat m_pTrack
The probability that the hit is track-like.
Definition: LArCaloHit.h:101
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
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
TFile f
Definition: plotHisto.C:6
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
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:303
void SetTrackProbability(const float probability)
Set the probability that the hit is track-like.
Definition: LArCaloHit.h:224
pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const
Create an object with the given parameters.
Definition: LArCaloHit.h:259
LArCaloHitFactory responsible for object creation.
Definition: LArCaloHit.h:110
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