DeltaRayMatchingContainers.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArCosmicRay/DeltaRayMatchingContainers.cc
3  *
4  * @brief Implementation of the delta ray matching containers class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/PandoraEnumeratedTypes.h"
10 
11 #include "Objects/Cluster.h"
12 
15 
17 
18 using namespace pandora;
19 
20 namespace lar_content
21 {
22 
23 DeltaRayMatchingContainers::DeltaRayMatchingContainers() : m_searchRegion1D(3.f)
24 {
25 }
26 
27 //------------------------------------------------------------------------------------------------------------------------------------------
28 
29 void DeltaRayMatchingContainers::FillContainers(const PfoList &inputPfoList, const ClusterList &inputClusterList1,
30  const ClusterList &inputClusterList2, const ClusterList &inputClusterList3)
31 {
32  this->FillHitToClusterMap(inputClusterList1);
33  this->FillHitToClusterMap(inputClusterList2);
34  this->FillHitToClusterMap(inputClusterList3);
35 
36  this->FillClusterProximityMap(inputClusterList1);
37  this->FillClusterProximityMap(inputClusterList2);
38  this->FillClusterProximityMap(inputClusterList3);
39 
40  this->FillClusterToPfoMaps(inputPfoList);
41 }
42 
43 //------------------------------------------------------------------------------------------------------------------------------------------
44 
45 void DeltaRayMatchingContainers::FillHitToClusterMap(const ClusterList &inputClusterList)
46 {
47  for (const Cluster *const pCluster : inputClusterList)
48  this->AddToClusterMap(pCluster);
49 }
50 
51 //------------------------------------------------------------------------------------------------------------------------------------------
52 
53 void DeltaRayMatchingContainers::AddToClusterMap(const Cluster *const pCluster)
54 {
55  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
56  HitToClusterMap &hitToClusterMap((hitType == TPC_VIEW_U) ? m_hitToClusterMapU : (hitType == TPC_VIEW_V) ? m_hitToClusterMapV : m_hitToClusterMapW);
57 
58  CaloHitList caloHitList;
59  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
60 
61  for (const CaloHit *const pCaloHit : caloHitList)
62  hitToClusterMap[pCaloHit] = pCluster;
63 }
64 
65 //------------------------------------------------------------------------------------------------------------------------------------------
66 
67 void DeltaRayMatchingContainers::FillClusterProximityMap(const ClusterList &inputClusterList)
68 {
69  if (inputClusterList.empty())
70  return;
71 
72  const HitType hitType(LArClusterHelper::GetClusterHitType(inputClusterList.front()));
73 
74  this->BuildKDTree(hitType);
75 
76  for (const Cluster *const pCluster : inputClusterList)
77  this->AddToClusterProximityMap(pCluster);
78 }
79 
80 //------------------------------------------------------------------------------------------------------------------------------------------
81 
83 {
84  const HitToClusterMap &hitToClusterMap((hitType == TPC_VIEW_U) ? m_hitToClusterMapU : (hitType == TPC_VIEW_V) ? m_hitToClusterMapV : m_hitToClusterMapW);
85  HitKDTree2D &kdTree((hitType == TPC_VIEW_U) ? m_kdTreeU : (hitType == TPC_VIEW_V) ? m_kdTreeV : m_kdTreeW);
86 
87  CaloHitList allCaloHits;
88 
89  for (auto &entry : hitToClusterMap)
90  allCaloHits.push_back(entry.first);
91 
92  HitKDNode2DList hitKDNode2DList;
93  KDTreeBox hitsBoundingRegion2D(fill_and_bound_2d_kd_tree(allCaloHits, hitKDNode2DList));
94 
95  kdTree.build(hitKDNode2DList, hitsBoundingRegion2D);
96 }
97 
98 //------------------------------------------------------------------------------------------------------------------------------------------
99 
100 void DeltaRayMatchingContainers::AddToClusterProximityMap(const Cluster *const pCluster)
101 {
102  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
103  const HitToClusterMap &hitToClusterMap((hitType == TPC_VIEW_U) ? m_hitToClusterMapU : (hitType == TPC_VIEW_V) ? m_hitToClusterMapV : m_hitToClusterMapW);
104  HitKDTree2D &kdTree((hitType == TPC_VIEW_U) ? m_kdTreeU : (hitType == TPC_VIEW_V) ? m_kdTreeV : m_kdTreeW);
105  ClusterProximityMap &clusterProximityMap(
106  (hitType == TPC_VIEW_U) ? m_clusterProximityMapU : (hitType == TPC_VIEW_V) ? m_clusterProximityMapV : m_clusterProximityMapW);
107 
108  CaloHitList caloHitList;
109  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
110 
111  for (const CaloHit *const pCaloHit : caloHitList)
112  {
115 
116  kdTree.search(searchRegionHits, found);
117 
118  for (const auto &hit : found)
119  {
120  const Cluster *const pNearbyCluster(hitToClusterMap.at(hit.data));
121 
122  if (pNearbyCluster == pCluster)
123  continue;
124 
125  ClusterList &nearbyClusterList(clusterProximityMap[pCluster]);
126 
127  if (std::find(nearbyClusterList.begin(), nearbyClusterList.end(), pNearbyCluster) == nearbyClusterList.end())
128  nearbyClusterList.push_back(pNearbyCluster);
129 
130  ClusterList &invertedNearbyClusterList(clusterProximityMap[pNearbyCluster]);
131 
132  if (std::find(invertedNearbyClusterList.begin(), invertedNearbyClusterList.end(), pCluster) == invertedNearbyClusterList.end())
133  invertedNearbyClusterList.push_back(pCluster);
134  }
135  }
136 }
137 
138 //------------------------------------------------------------------------------------------------------------------------------------------
139 
140 void DeltaRayMatchingContainers::FillClusterToPfoMaps(const PfoList &inputPfoList)
141 {
142  for (const ParticleFlowObject *const pPfo : inputPfoList)
143  this->AddClustersToPfoMaps(pPfo);
144 }
145 
146 //------------------------------------------------------------------------------------------------------------------------------------------
147 
148 void DeltaRayMatchingContainers::AddClustersToPfoMaps(const ParticleFlowObject *const pPfo)
149 {
150  for (const HitType hitType : {TPC_VIEW_U, TPC_VIEW_V, TPC_VIEW_W})
151  {
152  ClusterList pfoClusters;
153  LArPfoHelper::GetClusters(pPfo, hitType, pfoClusters);
154 
155  ClusterToPfoMap &clusterToPfoMap((hitType == TPC_VIEW_U) ? m_clusterToPfoMapU : (hitType == TPC_VIEW_V) ? m_clusterToPfoMapV : m_clusterToPfoMapW);
156 
157  for (const Cluster *const pCluster : pfoClusters)
158  {
159  if (clusterToPfoMap.find(pCluster) != clusterToPfoMap.end())
160  continue;
161 
162  clusterToPfoMap[pCluster] = pPfo;
163  }
164  }
165 }
166 
167 //------------------------------------------------------------------------------------------------------------------------------------------
168 
169 void DeltaRayMatchingContainers::AddClustersToContainers(const ClusterVector &newClusterVector, const PfoVector &pfoVector)
170 {
171  for (const Cluster *const pNewCluster : newClusterVector)
172  this->AddToClusterMap(pNewCluster);
173 
174  for (unsigned int i = 0; i < newClusterVector.size(); i++)
175  {
176  const Cluster *const pNewCluster(newClusterVector.at(i));
177  const ParticleFlowObject *const pMuonPfo(pfoVector.at(i));
178 
179  this->AddToClusterProximityMap(pNewCluster);
180 
181  if (pMuonPfo)
182  this->AddClustersToPfoMaps(pMuonPfo);
183  }
184 }
185 
186 //------------------------------------------------------------------------------------------------------------------------------------------
187 
188 void DeltaRayMatchingContainers::RemoveClusterFromContainers(const Cluster *const pDeletedCluster)
189 {
190  const HitType hitType(LArClusterHelper::GetClusterHitType(pDeletedCluster));
191  HitToClusterMap &hitToClusterMap((hitType == TPC_VIEW_U) ? m_hitToClusterMapU : (hitType == TPC_VIEW_V) ? m_hitToClusterMapV : m_hitToClusterMapW);
192  ClusterProximityMap &clusterProximityMap(
193  (hitType == TPC_VIEW_U) ? m_clusterProximityMapU : (hitType == TPC_VIEW_V) ? m_clusterProximityMapV : m_clusterProximityMapW);
194  ClusterToPfoMap &clusterToPfoMap((hitType == TPC_VIEW_U) ? m_clusterToPfoMapU : (hitType == TPC_VIEW_V) ? m_clusterToPfoMapV : m_clusterToPfoMapW);
195 
196  CaloHitList caloHitList;
197  pDeletedCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
198 
199  for (const CaloHit *const pCaloHit : caloHitList)
200  {
201  const HitToClusterMap::const_iterator iter(hitToClusterMap.find(pCaloHit));
202 
203  if (iter == hitToClusterMap.end())
204  throw StatusCodeException(STATUS_CODE_FAILURE);
205 
206  hitToClusterMap.erase(iter);
207  }
208 
209  const ClusterProximityMap::const_iterator clusterProximityIter(clusterProximityMap.find(pDeletedCluster));
210 
211  if (clusterProximityIter != clusterProximityMap.end())
212  {
213  const ClusterList &nearbyClusterList(clusterProximityIter->second);
214 
215  for (const Cluster *const pNearbyCluster : nearbyClusterList)
216  {
217  const ClusterProximityMap::iterator iter(clusterProximityMap.find(pNearbyCluster));
218 
219  if (iter == clusterProximityMap.end())
220  continue;
221 
222  ClusterList &invertedCloseClusters(iter->second);
223 
224  ClusterList::iterator invertedIter(std::find(invertedCloseClusters.begin(), invertedCloseClusters.end(), pDeletedCluster));
225  invertedCloseClusters.erase(invertedIter);
226  }
227 
228  clusterProximityMap.erase(clusterProximityIter);
229  }
230 
231  const DeltaRayMatchingContainers::ClusterToPfoMap::const_iterator clusterToPfoIter(clusterToPfoMap.find(pDeletedCluster));
232 
233  if (clusterToPfoIter != clusterToPfoMap.end())
234  clusterToPfoMap.erase(clusterToPfoIter);
235 }
236 
237 //------------------------------------------------------------------------------------------------------------------------------------------
238 
240 {
241  m_hitToClusterMapU.clear();
242  m_hitToClusterMapV.clear();
243  m_hitToClusterMapW.clear();
244 
245  m_kdTreeU.clear();
246  m_kdTreeV.clear();
247  m_kdTreeW.clear();
248 
249  m_clusterProximityMapU.clear();
250  m_clusterProximityMapV.clear();
251  m_clusterProximityMapW.clear();
252 
253  m_clusterToPfoMapU.clear();
254  m_clusterToPfoMapV.clear();
255  m_clusterToPfoMapW.clear();
256 }
257 
258 } // namespace lar_content
intermediate_table::iterator iterator
std::map< const pandora::CaloHit *, const pandora::Cluster * > HitToClusterMap
HitKDTree2D m_kdTreeW
The KD tree (in the W view)
void FillHitToClusterMap(const pandora::ClusterList &inputClusterList)
Populate the hit to cluster map from a list of clusters.
std::map< const pandora::Cluster *, const pandora::ParticleFlowObject * > ClusterToPfoMap
Header file for the pfo helper class.
QList< Entry > entry
HitKDTree2D m_kdTreeV
The KD tree (in the V view)
static void GetClusters(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::ClusterList &clusterList)
Get a list of clusters of a particular hit type from a list of pfos.
enum cvn::HType HitType
HitToClusterMap m_hitToClusterMapW
The mapping of hits to the clusters to which they belong (in the W view)
Box structure used to define 2D field. It&#39;s used in KDTree building step to divide the detector space...
void AddClustersToPfoMaps(const pandora::ParticleFlowObject *const pPfo)
Add the clusters of a cosmic ray/delta ray pfo to the cluster to pfo maps.
Header file for the delta ray matching containers class.
void clear()
Clear all allocated structures.
intermediate_table::const_iterator const_iterator
HitToClusterMap m_hitToClusterMapU
The mapping of hits to the clusters to which they belong (in the U view)
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
void FillContainers(const pandora::PfoList &inputPfoList, const pandora::ClusterList &inputClusterList1, const pandora::ClusterList &inputClusterList2=pandora::ClusterList(), const pandora::ClusterList &inputClusterList3=pandora::ClusterList())
Fill the HitToClusterMap, the ClusterProximityMap and the ClusterToPfoMap in all input views...
ClusterProximityMap m_clusterProximityMapU
The mapping of clusters to their neighbouring clusters (in the U view)
QCollection::Item first()
Definition: qglist.cpp:807
void FillClusterProximityMap(const pandora::ClusterList &inputClusterList)
Populate the cluster proximity map from a list of clusters.
Header file for the cluster helper class.
ClusterProximityMap m_clusterProximityMapV
The mapping of clusters to their neighbouring clusters (in the V view)
void AddClustersToContainers(const pandora::ClusterVector &newClusterVector, const pandora::PfoVector &pfoVector)
Add a list of clusters to the hit to cluster and cluster proximity maps and, if appropriate, to the cluster to pfo map.
ClusterToPfoMap m_clusterToPfoMapU
The mapping of cosmic ray U clusters to the cosmic ray pfos to which they belong. ...
void build(std::vector< KDTreeNodeInfoT< DATA, DIM >> &eltList, const KDTreeBoxT< DIM > &region)
Build the KD tree from the "eltList" in the space define by "region".
void FillClusterToPfoMaps(const pandora::PfoList &pfoList)
Populate all cluster to pfo maps from a list of particle flow objects.
void AddToClusterMap(const pandora::Cluster *const pCluster)
Add the hits of a given cluster to the hit to cluster map.
void AddToClusterProximityMap(const pandora::Cluster *const pCluster)
Add a cluster to the cluster proximity map.
Detector simulation of raw signals on wires.
void BuildKDTree(const pandora::HitType hitType)
Build the KD tree.
ClusterToPfoMap m_clusterToPfoMapW
The mapping of cosmic ray W clusters to the cosmic ray pfos to which they belong. ...
HitKDTree2D m_kdTreeU
The KD tree (in the U view)
std::map< const pandora::Cluster *, pandora::ClusterList > ClusterProximityMap
HitToClusterMap m_hitToClusterMapV
The mapping of hits to the clusters to which they belong (in the V view)
ClusterProximityMap m_clusterProximityMapW
The mapping of clusters to their neighbouring clusters (in the W view)
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
std::vector< art::Ptr< recob::Cluster > > ClusterVector
void ClearContainers()
Empty all algorithm containers.
KDTreeBox build_2d_kd_search_region(const pandora::CaloHit *const point, const float x_span, const float z_span)
build_2d_kd_search_region
void search(const KDTreeBoxT< DIM > &searchBox, std::vector< KDTreeNodeInfoT< DATA, DIM >> &resRecHitList)
Search in the KDTree for all points that would be contained in the given searchbox The founded points...
void RemoveClusterFromContainers(const pandora::Cluster *const pDeletedCluster)
Remove an input cluster&#39;s hits from the hit to cluster and cluster proximity maps and...
float m_searchRegion1D
Search region, applied to each dimension, for look-up from kd-tree.
ClusterToPfoMap m_clusterToPfoMapV
The mapping of cosmic ray V clusters to the cosmic ray pfos to which they belong. ...