Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
MvaVertexSelectionAlgorithm.cc
Go to the documentation of this file.
1
10
17
23
25
27
28#include <random>
29
30using namespace pandora;
31
32namespace lar_content
33{
34
35template <typename T>
38 m_filePathEnvironmentVariable("FW_SEARCH_PATH")
39{
40}
41
42//------------------------------------------------------------------------------------------------------------------------------------------
43
44template <typename T>
46 HitKDTree2D &kdTreeU, HitKDTree2D &kdTreeV, HitKDTree2D &kdTreeW, VertexScoreList &vertexScoreList) const
47{
48 ClusterList clustersU, clustersV, clustersW;
49 this->GetClusterLists(m_inputClusterListNames, clustersU, clustersV, clustersW);
50
51 SlidingFitDataList slidingFitDataListU, slidingFitDataListV, slidingFitDataListW;
52 this->CalculateClusterSlidingFits(clustersU, m_minClusterCaloHits, m_slidingFitWindow, slidingFitDataListU);
53 this->CalculateClusterSlidingFits(clustersV, m_minClusterCaloHits, m_slidingFitWindow, slidingFitDataListV);
54 this->CalculateClusterSlidingFits(clustersW, m_minClusterCaloHits, m_slidingFitWindow, slidingFitDataListW);
55
56 ShowerClusterList showerClusterListU, showerClusterListV, showerClusterListW;
57 this->CalculateShowerClusterList(clustersU, showerClusterListU);
58 this->CalculateShowerClusterList(clustersV, showerClusterListV);
59 this->CalculateShowerClusterList(clustersW, showerClusterListW);
60
61 // Create maps from hit types to objects for passing to feature tools.
62 const ClusterListMap clusterListMap{{TPC_VIEW_U, clustersU}, {TPC_VIEW_V, clustersV}, {TPC_VIEW_W, clustersW}};
63
64 const SlidingFitDataListMap slidingFitDataListMap{
65 {TPC_VIEW_U, slidingFitDataListU}, {TPC_VIEW_V, slidingFitDataListV}, {TPC_VIEW_W, slidingFitDataListW}};
66
67 const ShowerClusterListMap showerClusterListMap{{TPC_VIEW_U, showerClusterListU}, {TPC_VIEW_V, showerClusterListV}, {TPC_VIEW_W, showerClusterListW}};
68
69 const KDTreeMap kdTreeMap{{TPC_VIEW_U, kdTreeU}, {TPC_VIEW_V, kdTreeV}, {TPC_VIEW_W, kdTreeW}};
70
71 // Calculate the event feature list and the vertex feature map.
72 EventFeatureInfo eventFeatureInfo(this->CalculateEventFeatures(clustersU, clustersV, clustersW, vertexVector));
73
74 LArMvaHelper::MvaFeatureVector eventFeatureList;
75 this->AddEventFeaturesToVector(eventFeatureInfo, eventFeatureList);
76
77 VertexFeatureInfoMap vertexFeatureInfoMap;
78 for (const Vertex *const pVertex : vertexVector)
79 {
80 this->PopulateVertexFeatureInfoMap(
81 beamConstants, clusterListMap, slidingFitDataListMap, showerClusterListMap, kdTreeMap, pVertex, vertexFeatureInfoMap);
82 }
83
84 // Use a simple score to get the list of vertices representing good regions.
85 VertexScoreList initialScoreList;
86 for (const Vertex *const pVertex : vertexVector)
87 PopulateInitialScoreList(vertexFeatureInfoMap, pVertex, initialScoreList);
88
89 VertexVector bestRegionVertices;
90 this->GetBestRegionVertices(initialScoreList, bestRegionVertices);
91
92 if (m_trainingSetMode)
93 this->ProduceTrainingSets(vertexVector, bestRegionVertices, vertexFeatureInfoMap, eventFeatureList, kdTreeMap);
94
95 if ((!m_trainingSetMode || m_allowClassifyDuringTraining) && !bestRegionVertices.empty())
96 {
97 // Use mva to choose the region.
98 const Vertex *const pBestRegionVertex(
99 this->CompareVertices(bestRegionVertices, vertexFeatureInfoMap, eventFeatureList, kdTreeMap, m_mvaRegion, m_useRPhiFeatureForRegion));
100
101 // Get all the vertices in the best region.
102 VertexVector regionalVertices{pBestRegionVertex};
103 for (const Vertex *const pVertex : vertexVector)
104 {
105 if (pVertex == pBestRegionVertex)
106 continue;
107
108 if ((pBestRegionVertex->GetPosition() - pVertex->GetPosition()).GetMagnitude() < m_regionRadius)
109 regionalVertices.push_back(pVertex);
110 }
111
112 this->CalculateRPhiScores(regionalVertices, vertexFeatureInfoMap, kdTreeMap);
113
114 if (!regionalVertices.empty())
115 {
116 // Use mva to choose the vertex and then fine-tune using the RPhi score.
117 const Vertex *const pBestVertex(
118 this->CompareVertices(regionalVertices, vertexFeatureInfoMap, eventFeatureList, kdTreeMap, m_mvaVertex, true));
119 this->PopulateFinalVertexScoreList(vertexFeatureInfoMap, pBestVertex, vertexVector, vertexScoreList);
120 }
121 }
122}
123
124//------------------------------------------------------------------------------------------------------------------------------------------
125
126template <typename T>
128 const LArMvaHelper::MvaFeatureVector &eventFeatureList, const KDTreeMap &kdTreeMap, const T &t, const bool useRPhi) const
129{
130 const Vertex *pBestVertex(vertexVector.front());
131 LArMvaHelper::MvaFeatureVector chosenFeatureList;
132
133 VertexFeatureInfo chosenVertexFeatureInfo(vertexFeatureInfoMap.at(pBestVertex));
134 this->AddVertexFeaturesToVector(chosenVertexFeatureInfo, chosenFeatureList, useRPhi);
135
136 for (const Vertex *const pVertex : vertexVector)
137 {
138 if (pVertex == pBestVertex)
139 continue;
140
142 VertexFeatureInfo vertexFeatureInfo(vertexFeatureInfoMap.at(pVertex));
143 this->AddVertexFeaturesToVector(vertexFeatureInfo, featureList, useRPhi);
144
145 if (!m_legacyVariables)
146 {
147 LArMvaHelper::MvaFeatureVector sharedFeatureList;
148 float separation(0.f), axisHits(0.f);
149 this->GetSharedFeatures(pVertex, pBestVertex, kdTreeMap, separation, axisHits);
150 VertexSharedFeatureInfo sharedFeatureInfo(separation, axisHits);
151 this->AddSharedFeaturesToVector(sharedFeatureInfo, sharedFeatureList);
152
153 if (LArMvaHelper::Classify(t, LArMvaHelper::ConcatenateFeatureLists(eventFeatureList, featureList, chosenFeatureList, sharedFeatureList)))
154 {
155 pBestVertex = pVertex;
156 chosenFeatureList = featureList;
157 }
158 }
159 else
160 {
161 if (LArMvaHelper::Classify(t, LArMvaHelper::ConcatenateFeatureLists(eventFeatureList, featureList, chosenFeatureList)))
162 {
163 pBestVertex = pVertex;
164 chosenFeatureList = featureList;
165 }
166 }
167 }
168
169 return pBestVertex;
170}
171
172//------------------------------------------------------------------------------------------------------------------------------------------
173
174template <typename T>
176{
177 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
178 XmlHelper::ReadValue(xmlHandle, "FilePathEnvironmentVariable", m_filePathEnvironmentVariable));
179
180 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MvaFileName", m_mvaFileName));
181
182 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "RegionMvaName", m_regionMvaName));
183
184 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "VertexMvaName", m_vertexMvaName));
185
186 // ATTN : Need access to base class member variables at this point, so call read settings prior to end of this function
188
189 if ((!m_trainingSetMode || m_allowClassifyDuringTraining))
190 {
191 if (m_mvaFileName.empty() || m_regionMvaName.empty() || m_vertexMvaName.empty())
192 {
193 std::cout << "MvaVertexSelectionAlgorithm: MvaFileName, RegionMvaName and VertexMvaName must be set if training set mode is"
194 << "off or we allow classification during training" << std::endl;
195 return STATUS_CODE_INVALID_PARAMETER;
196 }
197
198 const std::string fullMvaFileName(LArFileHelper::FindFileInPath(m_mvaFileName, m_filePathEnvironmentVariable));
199 m_mvaRegion.Initialize(fullMvaFileName, m_regionMvaName);
200 m_mvaVertex.Initialize(fullMvaFileName, m_vertexMvaName);
201 }
202
203 return STATUS_CODE_SUCCESS;
204}
205
208
209} // namespace lar_content
Grouping of header files for many classes of use in particle flow algorithms.
Header file for the energy kick feature tool class.
Header file for the global asymmetry feature tool class.
Header file for the kd tree linker algo template class.
Header file for the cluster helper class.
Header file for the file helper class.
Header file for the geometry helper class.
Header file for the interaction type helper class.
Header file for the lar monte carlo particle helper helper class.
Header file for the local asymmetry feature tool class.
Header file for the mva vertex selection algorithm class.
Header file for the r/phi feature tool class.
Header file for the shower asymmetry feature tool class.
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
Definition StatusCodes.h:31
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
static std::string FindFileInPath(const std::string &unqualifiedFileName, const std::string &environmentVariable, const std::string &delimiter=":")
Find the fully-qualified file name by searching through a list of delimiter-separated paths in a name...
MvaTypes::MvaFeatureVector MvaFeatureVector
static MvaFeatureVector ConcatenateFeatureLists()
Recursively concatenate vectors of features (terminating method)
static bool Classify(const MvaInterface &classifier, TCONTAINER &&featureContainer)
Use the trained classifier to predict the boolean class of an example.
void GetVertexScoreList(const pandora::VertexVector &vertexVector, const BeamConstants &beamConstants, HitKDTree2D &kdTreeU, HitKDTree2D &kdTreeV, HitKDTree2D &kdTreeW, VertexScoreList &vertexScoreList) const
Get the vertex score list.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
const pandora::Vertex * CompareVertices(const pandora::VertexVector &vertexVector, const VertexFeatureInfoMap &vertexFeatureInfoMap, const LArMvaHelper::MvaFeatureVector &eventFeatureList, const KDTreeMap &kdTreeMap, const T &t, const bool useRPhi) const
Used a binary classifier to compare a set of vertices and pick the best one.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
std::map< const pandora::Vertex *const, VertexFeatureInfo > VertexFeatureInfoMap
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
std::map< pandora::HitType, const pandora::ClusterList & > ClusterListMap
Map array of cluster lists for passing to tools.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
Vertex class.
Definition Vertex.h:26
const CartesianVector & GetPosition() const
Get the vertex position.
Definition Vertex.h:103
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
Definition XmlHelper.h:136
MANAGED_CONTAINER< const Cluster * > ClusterList
StatusCode
The StatusCode enum.
std::vector< const Vertex * > VertexVector