Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
lar_content::PreProcessingAlgorithm Class Reference

PreProcessingAlgorithm class. More...

#include <PreProcessingAlgorithm.h>

Inheritance diagram for lar_content::PreProcessingAlgorithm:

Public Member Functions

 PreProcessingAlgorithm ()
 Default constructor. More...
 

Private Types

typedef KDTreeLinkerAlgo< const pandora::CaloHit *, 2 > HitKDTree2D
 
typedef KDTreeNodeInfoT< const pandora::CaloHit *, 2 > HitKDNode2D
 
typedef std::vector< HitKDNode2DHitKDNode2DList
 

Private Member Functions

pandora::StatusCode Reset ()
 
pandora::StatusCode Run ()
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
void ProcessCaloHits ()
 Build separate CaloHitLists for each view. More...
 
void PopulateVoidCaloHitLists () noexcept
 Build empty calo hit lists. More...
 
void GetFilteredCaloHitList (const pandora::CaloHitList &inputList, pandora::CaloHitList &outputList)
 Clean up the input CaloHitList. More...
 
void ProcessMCParticles ()
 Build separate MCParticleLists for each view. More...
 

Private Attributes

pandora::CaloHitSet m_processedHits
 The set of all previously processed calo hits. More...
 
float m_mipEquivalentCut
 Minimum mip equivalent energy for calo hit. More...
 
float m_minCellLengthScale
 The minimum length scale for calo hit. More...
 
float m_maxCellLengthScale
 The maximum length scale for calo hit. More...
 
float m_searchRegion1D
 Search region, applied to each dimension, for look-up from kd-trees. More...
 
unsigned int m_maxEventHits
 The maximum number of hits in an event to proceed with the reconstruction. More...
 
bool m_onlyAvailableCaloHits
 Whether to only include available calo hits. More...
 
std::string m_inputCaloHitListName
 The input calo hit list name. More...
 
std::string m_outputCaloHitListNameU
 The output calo hit list name for TPC_VIEW_U hits. More...
 
std::string m_outputCaloHitListNameV
 The output calo hit list name for TPC_VIEW_V hits. More...
 
std::string m_outputCaloHitListNameW
 The output calo hit list name for TPC_VIEW_W hits. More...
 
std::string m_filteredCaloHitListName
 The output calo hit list name for all U, V and W hits. More...
 
std::string m_currentCaloHitListReplacement
 The name of the calo hit list to replace the current list (optional) More...
 

Detailed Description

PreProcessingAlgorithm class.

Definition at line 26 of file PreProcessingAlgorithm.h.

Member Typedef Documentation

typedef KDTreeNodeInfoT<const pandora::CaloHit *, 2> lar_content::PreProcessingAlgorithm::HitKDNode2D
private

Definition at line 36 of file PreProcessingAlgorithm.h.

Definition at line 37 of file PreProcessingAlgorithm.h.

typedef KDTreeLinkerAlgo<const pandora::CaloHit *, 2> lar_content::PreProcessingAlgorithm::HitKDTree2D
private

Definition at line 35 of file PreProcessingAlgorithm.h.

Constructor & Destructor Documentation

lar_content::PreProcessingAlgorithm::PreProcessingAlgorithm ( )

Default constructor.

Definition at line 22 of file PreProcessingAlgorithm.cc.

22  :
23  m_mipEquivalentCut(std::numeric_limits<float>::epsilon()),
24  m_minCellLengthScale(std::numeric_limits<float>::epsilon()),
26  m_searchRegion1D(0.1f),
29  m_inputCaloHitListName("Input")
30 {
31 }
float m_maxCellLengthScale
The maximum length scale for calo hit.
float m_mipEquivalentCut
Minimum mip equivalent energy for calo hit.
unsigned int m_maxEventHits
The maximum number of hits in an event to proceed with the reconstruction.
float m_minCellLengthScale
The minimum length scale for calo hit.
static int max(int a, int b)
std::string m_inputCaloHitListName
The input calo hit list name.
float m_searchRegion1D
Search region, applied to each dimension, for look-up from kd-trees.
bool m_onlyAvailableCaloHits
Whether to only include available calo hits.

Member Function Documentation

void lar_content::PreProcessingAlgorithm::GetFilteredCaloHitList ( const pandora::CaloHitList &  inputList,
pandora::CaloHitList &  outputList 
)
private

Clean up the input CaloHitList.

Parameters
inputListthe input CaloHitList
outputListthe output CaloHitList

Definition at line 189 of file PreProcessingAlgorithm.cc.

190 {
191  HitKDTree2D kdTree;
192  HitKDNode2DList hitKDNode2DList;
193 
194  KDTreeBox hitsBoundingRegion2D = fill_and_bound_2d_kd_tree(inputList, hitKDNode2DList);
195  kdTree.build(hitKDNode2DList, hitsBoundingRegion2D);
196 
197  // Remove hits that are in the same physical location!
198  for (const CaloHit *const pCaloHit1 : inputList)
199  {
200  bool isUnique(true);
202 
204  kdTree.search(searchRegionHits, found);
205 
206  for (const auto &hit : found)
207  {
208  const CaloHit *const pCaloHit2(hit.data);
209 
210  if (pCaloHit1 == pCaloHit2)
211  continue;
212 
213  const float displacementSquared((pCaloHit2->GetPositionVector() - pCaloHit1->GetPositionVector()).GetMagnitudeSquared());
214 
215  if (displacementSquared < std::numeric_limits<float>::epsilon())
216  {
217  const float deltaMip(pCaloHit2->GetMipEquivalentEnergy() > pCaloHit1->GetMipEquivalentEnergy());
218 
219  if ((deltaMip > std::numeric_limits<float>::epsilon()) ||
220  ((std::fabs(deltaMip) < std::numeric_limits<float>::epsilon()) &&
221  (outputList.end() != std::find(outputList.begin(), outputList.end(), pCaloHit2))))
222  {
223  isUnique = false;
224  break;
225  }
226  }
227  }
228 
229  if (isUnique)
230  {
231  outputList.push_back(pCaloHit1);
232  }
233  else
234  {
235  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
236  std::cout << "PreProcessingAlgorithm: found two hits in same location, will remove lowest pulse height" << std::endl;
237  }
238  }
239 }
std::vector< HitKDNode2D > HitKDNode2DList
KDTreeLinkerAlgo< const pandora::CaloHit *, 2 > HitKDTree2D
Detector simulation of raw signals on wires.
KDTreeBox fill_and_bound_2d_kd_tree(const MANAGED_CONTAINER< const T * > &points, std::vector< KDTreeNodeInfoT< const T *, 2 >> &nodes)
fill_and_bound_2d_kd_tree
float m_searchRegion1D
Search region, applied to each dimension, for look-up from kd-trees.
KDTreeBox build_2d_kd_search_region(const pandora::CaloHit *const point, const float x_span, const float z_span)
build_2d_kd_search_region
KDTreeBoxT< 2 > KDTreeBox
QTextStream & endl(QTextStream &s)
void lar_content::PreProcessingAlgorithm::PopulateVoidCaloHitLists ( )
privatenoexcept

Build empty calo hit lists.

Definition at line 163 of file PreProcessingAlgorithm.cc.

164 {
165  CaloHitList emptyList;
166 
167  try
168  {
169  if (!m_filteredCaloHitListName.empty())
170  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, emptyList, m_filteredCaloHitListName));
171 
172  if (!m_outputCaloHitListNameU.empty())
173  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, emptyList, m_outputCaloHitListNameU));
174 
175  if (!m_outputCaloHitListNameV.empty())
176  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, emptyList, m_outputCaloHitListNameV));
177 
178  if (!m_outputCaloHitListNameW.empty())
179  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, emptyList, m_outputCaloHitListNameW));
180  }
181  catch (...)
182  {
183  std::cout << "PreProcessingAlgorithm: Unable to create void calo hit lists" << std::endl;
184  }
185 }
std::string m_outputCaloHitListNameV
The output calo hit list name for TPC_VIEW_V hits.
std::string m_outputCaloHitListNameW
The output calo hit list name for TPC_VIEW_W hits.
std::string m_filteredCaloHitListName
The output calo hit list name for all U, V and W hits.
std::string m_outputCaloHitListNameU
The output calo hit list name for TPC_VIEW_U hits.
QTextStream & endl(QTextStream &s)
void lar_content::PreProcessingAlgorithm::ProcessCaloHits ( )
private

Build separate CaloHitLists for each view.

Definition at line 79 of file PreProcessingAlgorithm.cc.

80 {
81  const CaloHitList *pCaloHitList(nullptr);
82  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_inputCaloHitListName, pCaloHitList));
83 
84  if (pCaloHitList->empty())
85  return;
86 
87  if (pCaloHitList->size() > m_maxEventHits)
88  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
89 
90  CaloHitList selectedCaloHitListU, selectedCaloHitListV, selectedCaloHitListW;
91 
92  for (const CaloHit *const pCaloHit : *pCaloHitList)
93  {
94  if (m_processedHits.count(pCaloHit))
95  continue;
96 
97  (void)m_processedHits.insert(pCaloHit);
98 
99  if (m_onlyAvailableCaloHits && !PandoraContentApi::IsAvailable(*this, pCaloHit))
100  continue;
101 
102  if (pCaloHit->GetMipEquivalentEnergy() < m_mipEquivalentCut)
103  continue;
104 
105  if (pCaloHit->GetInputEnergy() < std::numeric_limits<float>::epsilon())
106  {
107  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
108  std::cout << "PreProcessingAlgorithm: found a hit with zero energy, will remove it" << std::endl;
109 
110  continue;
111  }
112 
113  if ((pCaloHit->GetCellLengthScale() < m_minCellLengthScale) || (pCaloHit->GetCellLengthScale() > m_maxCellLengthScale))
114  {
115  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
116  {
117  std::cout << "PreProcessingAlgorithm: found a hit with extent " << pCaloHit->GetCellLengthScale() << ", require ("
118  << m_minCellLengthScale << " - " << m_maxCellLengthScale << "), will remove it" << std::endl;
119  }
120 
121  continue;
122  }
123 
124  if (TPC_VIEW_U == pCaloHit->GetHitType())
125  {
126  selectedCaloHitListU.push_back(pCaloHit);
127  }
128  else if (TPC_VIEW_V == pCaloHit->GetHitType())
129  {
130  selectedCaloHitListV.push_back(pCaloHit);
131  }
132  else if (TPC_VIEW_W == pCaloHit->GetHitType())
133  {
134  selectedCaloHitListW.push_back(pCaloHit);
135  }
136  }
137 
138  CaloHitList filteredCaloHitListU, filteredCaloHitListV, filteredCaloHitListW;
139  this->GetFilteredCaloHitList(selectedCaloHitListU, filteredCaloHitListU);
140  this->GetFilteredCaloHitList(selectedCaloHitListV, filteredCaloHitListV);
141  this->GetFilteredCaloHitList(selectedCaloHitListW, filteredCaloHitListW);
142 
143  CaloHitList filteredInputList;
144  filteredInputList.insert(filteredInputList.end(), filteredCaloHitListU.begin(), filteredCaloHitListU.end());
145  filteredInputList.insert(filteredInputList.end(), filteredCaloHitListV.begin(), filteredCaloHitListV.end());
146  filteredInputList.insert(filteredInputList.end(), filteredCaloHitListW.begin(), filteredCaloHitListW.end());
147 
148  if (!filteredInputList.empty() && !m_filteredCaloHitListName.empty())
149  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, filteredInputList, m_filteredCaloHitListName));
150 
151  if (!filteredCaloHitListU.empty() && !m_outputCaloHitListNameU.empty())
152  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, filteredCaloHitListU, m_outputCaloHitListNameU));
153 
154  if (!filteredCaloHitListV.empty() && !m_outputCaloHitListNameV.empty())
155  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, filteredCaloHitListV, m_outputCaloHitListNameV));
156 
157  if (!filteredCaloHitListW.empty() && !m_outputCaloHitListNameW.empty())
158  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, filteredCaloHitListW, m_outputCaloHitListNameW));
159 }
std::string m_outputCaloHitListNameV
The output calo hit list name for TPC_VIEW_V hits.
void GetFilteredCaloHitList(const pandora::CaloHitList &inputList, pandora::CaloHitList &outputList)
Clean up the input CaloHitList.
float m_maxCellLengthScale
The maximum length scale for calo hit.
float m_mipEquivalentCut
Minimum mip equivalent energy for calo hit.
unsigned int m_maxEventHits
The maximum number of hits in an event to proceed with the reconstruction.
std::string m_outputCaloHitListNameW
The output calo hit list name for TPC_VIEW_W hits.
std::string m_filteredCaloHitListName
The output calo hit list name for all U, V and W hits.
float m_minCellLengthScale
The minimum length scale for calo hit.
std::string m_outputCaloHitListNameU
The output calo hit list name for TPC_VIEW_U hits.
std::string m_inputCaloHitListName
The input calo hit list name.
pandora::CaloHitSet m_processedHits
The set of all previously processed calo hits.
bool m_onlyAvailableCaloHits
Whether to only include available calo hits.
QTextStream & endl(QTextStream &s)
void lar_content::PreProcessingAlgorithm::ProcessMCParticles ( )
private

Build separate MCParticleLists for each view.

StatusCode lar_content::PreProcessingAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 243 of file PreProcessingAlgorithm.cc.

244 {
245  PANDORA_RETURN_RESULT_IF_AND_IF(
246  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MipEquivalentCut", m_mipEquivalentCut));
247 
248  PANDORA_RETURN_RESULT_IF_AND_IF(
249  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinCellLengthScale", m_minCellLengthScale));
250 
251  PANDORA_RETURN_RESULT_IF_AND_IF(
252  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxCellLengthScale", m_maxCellLengthScale));
253 
254  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SearchRegion1D", m_searchRegion1D));
255 
256  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxEventHits", m_maxEventHits));
257 
258  PANDORA_RETURN_RESULT_IF_AND_IF(
259  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "OnlyAvailableCaloHits", m_onlyAvailableCaloHits));
260 
261  PANDORA_RETURN_RESULT_IF_AND_IF(
262  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "InputCaloHitListName", m_inputCaloHitListName));
263 
264  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "OutputCaloHitListNameU", m_outputCaloHitListNameU));
265 
266  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "OutputCaloHitListNameV", m_outputCaloHitListNameV));
267 
268  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "OutputCaloHitListNameW", m_outputCaloHitListNameW));
269 
270  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "FilteredCaloHitListName", m_filteredCaloHitListName));
271 
272  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "CurrentCaloHitListReplacement", m_currentCaloHitListReplacement));
273 
274  return STATUS_CODE_SUCCESS;
275 }
std::string m_outputCaloHitListNameV
The output calo hit list name for TPC_VIEW_V hits.
float m_maxCellLengthScale
The maximum length scale for calo hit.
float m_mipEquivalentCut
Minimum mip equivalent energy for calo hit.
unsigned int m_maxEventHits
The maximum number of hits in an event to proceed with the reconstruction.
std::string m_currentCaloHitListReplacement
The name of the calo hit list to replace the current list (optional)
std::string m_outputCaloHitListNameW
The output calo hit list name for TPC_VIEW_W hits.
std::string m_filteredCaloHitListName
The output calo hit list name for all U, V and W hits.
float m_minCellLengthScale
The minimum length scale for calo hit.
std::string m_outputCaloHitListNameU
The output calo hit list name for TPC_VIEW_U hits.
std::string m_inputCaloHitListName
The input calo hit list name.
float m_searchRegion1D
Search region, applied to each dimension, for look-up from kd-trees.
bool m_onlyAvailableCaloHits
Whether to only include available calo hits.
StatusCode lar_content::PreProcessingAlgorithm::Reset ( void  )
private

Definition at line 35 of file PreProcessingAlgorithm.cc.

36 {
37  m_processedHits.clear();
38  return STATUS_CODE_SUCCESS;
39 }
pandora::CaloHitSet m_processedHits
The set of all previously processed calo hits.
StatusCode lar_content::PreProcessingAlgorithm::Run ( )
private

Definition at line 43 of file PreProcessingAlgorithm.cc.

44 {
45  if (!this->GetPandora().GetSettings()->SingleHitTypeClusteringMode())
46  {
47  std::cout << "PreProcessingAlgorithm: expect Pandora to be configured in SingleHitTypeClusteringMode." << std::endl;
48  return STATUS_CODE_FAILURE;
49  }
50 
51  try
52  {
53  this->ProcessCaloHits();
54  }
55  catch (const StatusCodeException &statusCodeException)
56  {
57  if (STATUS_CODE_OUT_OF_RANGE == statusCodeException.GetStatusCode())
58  {
59  std::cout << "PreProcessingAlgorithm: Excessive number of hits in event, skipping the reconstruction" << std::endl;
61  }
62  }
63 
65  {
66  if (STATUS_CODE_SUCCESS != PandoraContentApi::ReplaceCurrentList<CaloHit>(*this, m_currentCaloHitListReplacement))
67  {
68  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
69  std::cout << "PreProcessingAlgorithm: could not replace current calo hit list with list named: " << m_currentCaloHitListReplacement
70  << std::endl;
71  }
72  }
73 
74  return STATUS_CODE_SUCCESS;
75 }
std::string m_currentCaloHitListReplacement
The name of the calo hit list to replace the current list (optional)
void ProcessCaloHits()
Build separate CaloHitLists for each view.
void PopulateVoidCaloHitLists() noexcept
Build empty calo hit lists.
QTextStream & endl(QTextStream &s)

Member Data Documentation

std::string lar_content::PreProcessingAlgorithm::m_currentCaloHitListReplacement
private

The name of the calo hit list to replace the current list (optional)

Definition at line 80 of file PreProcessingAlgorithm.h.

std::string lar_content::PreProcessingAlgorithm::m_filteredCaloHitListName
private

The output calo hit list name for all U, V and W hits.

Definition at line 79 of file PreProcessingAlgorithm.h.

std::string lar_content::PreProcessingAlgorithm::m_inputCaloHitListName
private

The input calo hit list name.

Definition at line 75 of file PreProcessingAlgorithm.h.

float lar_content::PreProcessingAlgorithm::m_maxCellLengthScale
private

The maximum length scale for calo hit.

Definition at line 70 of file PreProcessingAlgorithm.h.

unsigned int lar_content::PreProcessingAlgorithm::m_maxEventHits
private

The maximum number of hits in an event to proceed with the reconstruction.

Definition at line 72 of file PreProcessingAlgorithm.h.

float lar_content::PreProcessingAlgorithm::m_minCellLengthScale
private

The minimum length scale for calo hit.

Definition at line 69 of file PreProcessingAlgorithm.h.

float lar_content::PreProcessingAlgorithm::m_mipEquivalentCut
private

Minimum mip equivalent energy for calo hit.

Definition at line 68 of file PreProcessingAlgorithm.h.

bool lar_content::PreProcessingAlgorithm::m_onlyAvailableCaloHits
private

Whether to only include available calo hits.

Definition at line 74 of file PreProcessingAlgorithm.h.

std::string lar_content::PreProcessingAlgorithm::m_outputCaloHitListNameU
private

The output calo hit list name for TPC_VIEW_U hits.

Definition at line 76 of file PreProcessingAlgorithm.h.

std::string lar_content::PreProcessingAlgorithm::m_outputCaloHitListNameV
private

The output calo hit list name for TPC_VIEW_V hits.

Definition at line 77 of file PreProcessingAlgorithm.h.

std::string lar_content::PreProcessingAlgorithm::m_outputCaloHitListNameW
private

The output calo hit list name for TPC_VIEW_W hits.

Definition at line 78 of file PreProcessingAlgorithm.h.

pandora::CaloHitSet lar_content::PreProcessingAlgorithm::m_processedHits
private

The set of all previously processed calo hits.

Definition at line 66 of file PreProcessingAlgorithm.h.

float lar_content::PreProcessingAlgorithm::m_searchRegion1D
private

Search region, applied to each dimension, for look-up from kd-trees.

Definition at line 71 of file PreProcessingAlgorithm.h.


The documentation for this class was generated from the following files: