9 #include "Pandora/AlgorithmHeaders.h" 34 SvmVertexSelectionAlgorithm::SvmVertexSelectionAlgorithm() :
36 m_filePathEnvironmentVariable(
"FW_SEARCH_PATH"),
37 m_trainingSetMode(false),
38 m_allowClassifyDuringTraining(false),
39 m_mcVertexXCorrection(0.
f),
40 m_minClusterCaloHits(12),
41 m_slidingFitWindow(100),
42 m_minShowerSpineLength(15.
f),
43 m_beamDeweightingConstant(0.4),
44 m_localAsymmetryConstant(3.
f),
45 m_globalAsymmetryConstant(1.
f),
46 m_showerAsymmetryConstant(1.
f),
47 m_energyKickConstant(0.06),
48 m_showerClusteringDistance(3.
f),
49 m_minShowerClusterHits(1),
50 m_useShowerClusteringApproximation(false),
52 m_rPhiFineTuningRadius(2.
f),
53 m_maxTrueVertexRadius(1.
f),
54 m_useRPhiFeatureForRegion(false),
55 m_dropFailedRPhiFastScoreCandidates(true)
64 ClusterList clustersU, clustersV, clustersW;
79 {TPC_VIEW_V, clustersV},
80 {TPC_VIEW_W, clustersV}};
83 {TPC_VIEW_V, slidingFitDataListV},
84 {TPC_VIEW_W, slidingFitDataListW}};
87 {TPC_VIEW_V, showerClusterListV},
88 {TPC_VIEW_W, showerClusterListW}};
90 const KDTreeMap kdTreeMap{{TPC_VIEW_U, kdTreeU},
91 {TPC_VIEW_V, kdTreeV},
92 {TPC_VIEW_W, kdTreeW}};
101 for (
const Vertex *
const pVertex : vertexVector)
104 vertexFeatureInfoMap);
109 for (
const Vertex *
const pVertex : vertexVector)
116 this->
ProduceTrainingSets(vertexVector, bestRegionVertices, vertexFeatureInfoMap, eventFeatureList, kdTreeMap);
126 for (
const Vertex *
const pVertex : vertexVector)
128 if (pVertex == pBestRegionVertex)
131 if ((pBestRegionVertex->GetPosition() - pVertex->GetPosition()).GetMagnitude() <
m_regionRadius)
132 regionalVertices.push_back(pVertex);
137 if (!regionalVertices.empty())
151 ClusterList showerLikeClusters;
155 ClusterList availableShowerLikeClusters(showerLikeClusters.begin(), showerLikeClusters.end());
161 this->
PopulateKdTree(availableShowerLikeClusters, kdTree, hitToClusterMap);
163 while (!availableShowerLikeClusters.empty())
165 ClusterList showerCluster;
166 showerCluster.push_back(availableShowerLikeClusters.back());
167 availableShowerLikeClusters.pop_back();
169 bool addedCluster(
true);
170 while (addedCluster && !availableShowerLikeClusters.empty())
172 addedCluster =
false;
173 for (
const Cluster *
const pCluster : showerCluster)
177 addedCluster = this->
AddClusterToShower(kdTree, hitToClusterMap, availableShowerLikeClusters, pCluster, showerCluster);
181 addedCluster = this->
AddClusterToShower(clusterEndPointsMap, availableShowerLikeClusters, pCluster, showerCluster);
189 unsigned int totHits(0);
190 for (
const Cluster *
const pCluster : showerCluster)
191 totHits += pCluster->GetNCaloHits();
205 for (
const Cluster *
const pCluster : clusterList)
211 showerLikeClusters.push_back(pCluster);
213 CaloHitList clusterCaloHitList;
214 pCluster->GetOrderedCaloHitList().FillCaloHitList(clusterCaloHitList);
216 CaloHitVector clusterCaloHitVector(clusterCaloHitList.begin(), clusterCaloHitList.end());
219 if (clusterCaloHitVector.empty())
222 ClusterEndPoints clusterEndPoints(clusterCaloHitVector.front()->GetPositionVector(), clusterCaloHitVector.back()->GetPositionVector());
223 clusterEndPointsMap.emplace(pCluster, clusterEndPoints);
231 CaloHitList allCaloHits;
233 for (
const Cluster *
const pCluster : clusterList)
235 CaloHitList daughterHits;
236 pCluster->GetOrderedCaloHitList().FillCaloHitList(daughterHits);
237 allCaloHits.insert(allCaloHits.end(), daughterHits.begin(), daughterHits.end());
239 for (
const CaloHit *
const pCaloHit : daughterHits)
240 (void) hitToClusterMap.insert(HitToClusterMap::value_type(pCaloHit, pCluster));
245 kdTree.
build(hitKDNode2DList, hitsBoundingRegion2D);
251 const Cluster *
const pCluster, ClusterList &showerCluster)
const 253 const auto existingEndPointsIter(clusterEndPointsMap.find(pCluster));
254 if (existingEndPointsIter == clusterEndPointsMap.end())
257 const ClusterEndPoints &existingClusterEndPoints(existingEndPointsIter->second);
259 for (
auto iter = availableShowerLikeClusters.begin(); iter != availableShowerLikeClusters.end(); ++iter)
261 const Cluster *
const pAvailableShowerLikeCluster(*iter);
262 const auto &newEndPointsIter(clusterEndPointsMap.find(pAvailableShowerLikeCluster));
264 if (newEndPointsIter == clusterEndPointsMap.end())
268 const float startStartDistance((newClusterEndPoints.first - existingClusterEndPoints.first).GetMagnitude());
269 const float startEndDistance((newClusterEndPoints.first - existingClusterEndPoints.second).GetMagnitude());
270 const float endStartDistance((newClusterEndPoints.second - existingClusterEndPoints.first).GetMagnitude());
271 const float endEndDistance((newClusterEndPoints.second - existingClusterEndPoints.second).GetMagnitude());
273 const float smallestDistance(
std::min(
std::min(startStartDistance, startEndDistance),
std::min(endStartDistance, endEndDistance)));
277 showerCluster.push_back(pAvailableShowerLikeCluster);
278 availableShowerLikeClusters.erase(iter);
289 ClusterList &availableShowerLikeClusters,
const Cluster *
const pCluster, ClusterList &showerCluster)
const 291 ClusterSet nearbyClusters;
292 CaloHitList daughterHits;
293 pCluster->GetOrderedCaloHitList().FillCaloHitList(daughterHits);
295 for (
const CaloHit *
const pCaloHit : daughterHits)
300 kdTree.
search(searchRegionHits, found);
302 for (
const auto &
hit : found)
303 (void) nearbyClusters.insert(hitToClusterMap.at(
hit.data));
306 for (
auto iter = availableShowerLikeClusters.begin(); iter != availableShowerLikeClusters.end(); ++iter)
308 const Cluster *
const pAvailableShowerLikeCluster(*iter);
310 if ((pAvailableShowerLikeCluster != pCluster) && nearbyClusters.count(pAvailableShowerLikeCluster))
312 showerCluster.push_back(pAvailableShowerLikeCluster);
313 availableShowerLikeClusters.erase(iter);
324 const ClusterList &clusterListV,
const ClusterList &clusterListW,
const VertexVector &vertexVector)
const 326 float eventEnergy(0.
f);
327 unsigned int nShoweryHits(0), nHits(0);
333 const unsigned int nClusters(clusterListU.size() + clusterListV.size() + clusterListW.size());
334 const float eventShoweryness((nHits > 0) ? static_cast<float>(nShoweryHits) / static_cast<float>(nHits) : 0.
f);
336 ClusterList allClusters(clusterListU);
337 allClusters.insert(allClusters.end(), clusterListV.begin(), clusterListV.end());
338 allClusters.insert(allClusters.end(), clusterListW.begin(), clusterListW.end());
340 float eventVolume(0.f), longitudinality(0.f);
343 return EventFeatureInfo(eventShoweryness, eventEnergy, eventVolume, longitudinality, nHits, nClusters, vertexVector.size());
349 float &eventEnergy)
const 351 for (
const Cluster *
const pCluster : clusterList)
354 nShoweryHits += pCluster->GetNCaloHits();
356 eventEnergy += pCluster->GetElectromagneticEnergy();
357 nHits += pCluster->GetNCaloHits();
372 InputFloat xMin, yMin, zMin, xMax, yMax, zMax;
374 for (
const Cluster *
const pCluster : clusterList)
376 CartesianVector minPosition(0.
f, 0.
f, 0.
f), maxPosition(0.
f, 0.
f, 0.
f);
389 if ((xSpan > std::numeric_limits<float>::epsilon()) && (ySpan > std::numeric_limits<float>::epsilon()))
391 eventVolume = xSpan * ySpan * zSpan;
392 longitudinality = zSpan / (xSpan + ySpan);
395 else if (ySpan > std::numeric_limits<float>::epsilon())
397 eventVolume = ySpan * ySpan * zSpan;
398 longitudinality = zSpan / (ySpan + ySpan);
401 else if (xSpan > std::numeric_limits<float>::epsilon())
403 eventVolume = xSpan * xSpan * zSpan;
404 longitudinality = zSpan / (xSpan + xSpan);
411 InputFloat &maxCoord)
const 413 if (!minCoord.IsInitialized() || minPositionCoord < minCoord.Get())
414 minCoord = minPositionCoord;
416 if (!maxCoord.IsInitialized() || maxPositionCoord > maxCoord.Get())
417 maxCoord = maxPositionCoord;
424 if (minCoord.IsInitialized() && maxCoord.IsInitialized())
425 return std::fabs(maxCoord.Get() - minCoord.Get());
436 featureVector.push_back(static_cast<double>(eventFeatureInfo.
m_eventEnergy));
437 featureVector.push_back(static_cast<double>(eventFeatureInfo.
m_eventVolume));
438 featureVector.push_back(static_cast<double>(eventFeatureInfo.
m_longitudinality));
439 featureVector.push_back(static_cast<double>(eventFeatureInfo.
m_nHits));
440 featureVector.push_back(static_cast<double>(eventFeatureInfo.
m_nClusters));
441 featureVector.push_back(static_cast<double>(eventFeatureInfo.
m_nCandidates));
454 const double energyKick(LArMvaHelper::CalculateFeaturesOfType<EnergyKickFeatureTool>(
m_featureToolVector,
this, pVertex,
455 slidingFitDataListMap, clusterListMap, kdTreeMap, showerClusterListMap, beamDeweighting, bestFastScore).at(0).
Get());
457 const double localAsymmetry(LArMvaHelper::CalculateFeaturesOfType<LocalAsymmetryFeatureTool>(
m_featureToolVector,
this, pVertex,
458 slidingFitDataListMap, clusterListMap, kdTreeMap, showerClusterListMap, beamDeweighting, bestFastScore).at(0).
Get());
460 const double globalAsymmetry(LArMvaHelper::CalculateFeaturesOfType<GlobalAsymmetryFeatureTool>(
m_featureToolVector,
this, pVertex,
461 slidingFitDataListMap, clusterListMap, kdTreeMap, showerClusterListMap, beamDeweighting, bestFastScore).at(0).
Get());
463 const double showerAsymmetry(LArMvaHelper::CalculateFeaturesOfType<ShowerAsymmetryFeatureTool>(
m_featureToolVector,
this, pVertex,
464 slidingFitDataListMap, clusterListMap, kdTreeMap, showerClusterListMap, beamDeweighting, bestFastScore).at(0).
Get());
469 VertexFeatureInfo vertexFeatureInfo(beamDeweighting, 0.
f, energyKick, localAsymmetry, globalAsymmetry, showerAsymmetry);
470 vertexFeatureInfoMap.emplace(pVertex, vertexFeatureInfo);
486 initialScoreList.emplace_back(pVertex, beamDeweightingScore + energyKickScore + localAsymmetryScore + globalAsymmetryScore + showerAsymmetryScore);
493 std::sort(initialScoreList.begin(), initialScoreList.end());
495 for (
const VertexScore &vertexScore : initialScoreList)
497 const Vertex *
const pVertex(vertexScore.GetVertex());
498 bool farEnoughAway(
true);
500 for (
const Vertex *
const pRegionVertex: bestRegionVertices)
502 if (pRegionVertex == pVertex)
504 farEnoughAway =
false;
508 const float distance = (pRegionVertex->GetPosition() - pVertex->GetPosition()).GetMagnitude();
512 farEnoughAway =
false;
518 bestRegionVertices.push_back(pVertex);
527 if (vertexVector.empty())
531 std::random_device device;
532 std::mt19937 generator(device());
533 std::bernoulli_distribution coinFlip(0.5);
538 const Vertex *
const pBestRegionVertex(this->
ProduceTrainingExamples(bestRegionVertices, vertexFeatureInfoMap, coinFlip, generator,
543 for (
const Vertex *
const pVertex : vertexVector)
545 if (pVertex == pBestRegionVertex)
548 if ((pBestRegionVertex->GetPosition() - pVertex->GetPosition()).GetMagnitude() <
m_regionRadius)
549 regionalVertices.push_back(pVertex);
555 if (!regionalVertices.empty())
569 for (
auto iter = vertexVector.begin(); iter != vertexVector.end(); )
574 bestFastScore).at(0).Get());
577 iter = vertexVector.erase(iter);
589 const MCParticleList *pMCParticleList(
nullptr);
590 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_mcParticleListName, pMCParticleList));
592 const CaloHitList *pCaloHitList(
nullptr);
593 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_caloHitListName, pCaloHitList));
600 MCParticleList mcPrimaryList;
601 for (
const auto &mapEntry : nuMCParticlesToGoodHitsMap) mcPrimaryList.push_back(mapEntry.first);
611 const VertexFeatureInfoMap &vertexFeatureInfoMap, std::bernoulli_distribution &coinFlip, std::mt19937 &generator,
613 const float maxRadius,
const bool useRPhi)
const 615 const Vertex *pBestVertex(
nullptr);
619 this->
GetBestVertex(vertexVector, pBestVertex, bestVertexDr);
624 for (
const Vertex *
const pVertex : vertexVector)
626 if (pVertex == pBestVertex)
633 if (pBestVertex && (bestVertexDr < maxRadius))
635 if (coinFlip(generator))
638 bestVertexFeatureList, featureList);
644 bestVertexFeatureList);
657 const MCParticleList *pMCParticleList(
nullptr);
658 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_mcParticleListName, pMCParticleList));
664 for (
const Vertex *
const pVertex : vertexVector)
667 for (
const MCParticle *
const pMCNeutrino : mcNeutrinoVector)
669 const CartesianVector mcNeutrinoPosition(pMCNeutrino->GetEndpoint().GetX() +
m_mcVertexXCorrection, pMCNeutrino->GetEndpoint().GetY(),
670 pMCNeutrino->GetEndpoint().GetZ());
672 const float dr = (mcNeutrinoPosition - pVertex->GetPosition()).GetMagnitude();
677 if (mcVertexDr < bestVertexDr)
679 bestVertexDr = mcVertexDr;
680 pBestVertex = pVertex;
690 featureVector.push_back(static_cast<double>(vertexFeatureInfo.
m_beamDeweighting));
691 featureVector.push_back(static_cast<double>(vertexFeatureInfo.
m_energyKick));
692 featureVector.push_back(static_cast<double>(vertexFeatureInfo.
m_globalAsymmetry));
693 featureVector.push_back(static_cast<double>(vertexFeatureInfo.
m_localAsymmetry));
694 featureVector.push_back(static_cast<double>(vertexFeatureInfo.
m_showerAsymmetry));
697 featureVector.push_back(static_cast<double>(vertexFeatureInfo.
m_rPhiFeature));
705 const Vertex *pBestVertex(vertexVector.front());
711 for (
const Vertex *
const pVertex : vertexVector)
713 if (pVertex == pBestVertex)
722 pBestVertex = pVertex;
723 chosenFeatureList = featureList;
735 if (pFavouriteVertex)
737 const CartesianVector vertexPosition(pFavouriteVertex->GetPosition());
739 for (
const Vertex *
const pVertex : vertexVector)
743 const float rPhiScore(vertexFeatureInfoMap.at(pVertex).m_rPhiFeature);
744 finalVertexScoreList.emplace_back(pVertex, rPhiScore);
755 AlgorithmToolVector algorithmToolVector;
756 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithmToolList(*
this, xmlHandle,
"FeatureTools", algorithmToolVector));
758 for (AlgorithmTool *
const pAlgorithmTool : algorithmToolVector)
761 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
764 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
767 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
770 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
773 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
776 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
783 std::cout <<
"SvmVertexSelectionAlgorithm: SvmFileName, RegionSvmName and VertexSvmName must be set if training set mode is" <<
784 "off or we allow classification during training" << std::endl;
785 return STATUS_CODE_INVALID_PARAMETER;
794 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
797 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
800 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
805 std::cout <<
"SvmVertexSelectionAlgorithm: TrainingOutputFileRegion and TrainingOutputFileVertex are required for training set " <<
807 return STATUS_CODE_INVALID_PARAMETER;
810 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
813 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
818 std::cout <<
"SvmVertexSelectionAlgorithm: MCParticleListName and CaloHitListName are required for training set mode" << std::endl;
819 return STATUS_CODE_INVALID_PARAMETER;
822 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadVectorOfValues(xmlHandle,
825 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
828 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
831 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
834 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
837 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
840 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
843 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
846 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
849 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
852 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
855 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
858 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
861 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
864 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
867 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
870 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
std::string m_vertexSvmName
The name of the vertex Svm to find.
std::map< const pandora::Vertex *const, VertexFeatureInfo > VertexFeatureInfoMap
Header file for the kd tree linker algo template class.
void PopulateFinalVertexScoreList(const VertexFeatureInfoMap &vertexFeatureInfoMap, const pandora::Vertex *const pFavouriteVertex, const pandora::VertexVector &vertexVector, VertexScoreList &finalVertexScoreList) const
Populate the final vertex score list using the r/phi score to find the best vertex in the vicinity...
SupportVectorMachine class.
void GetBestRegionVertices(VertexScoreList &initialScoreList, pandora::VertexVector &bestRegionVertices) const
Get the list of top-N separated vertices.
MvaTypes::MvaFeatureVector MvaFeatureVector
unsigned int m_nCandidates
The total number of vertex candidates.
void IncrementShoweryParameters(const pandora::ClusterList &clusterList, unsigned int &nShoweryHits, unsigned int &nHits, float &eventEnergy) const
Increment the showery hit parameters for a cluster list.
std::vector< ShowerCluster > ShowerClusterList
Header file for the interaction type helper class.
float m_beamDeweighting
The beam deweighting feature.
unsigned int m_minShowerClusterHits
The minimum number of shower cluster hits.
float m_globalAsymmetryConstant
The global asymmetry constant for the initial region score list.
void GetClusterLists(const pandora::StringVector &inputClusterListNames, pandora::ClusterList &clusterListU, pandora::ClusterList &clusterListV, pandora::ClusterList &clusterListW) const
Get the cluster lists.
Class that implements the KDTree partition of 2D space and a closest point search algorithm...
void CalculateClusterSlidingFits(const pandora::ClusterList &inputClusterList, const unsigned int minClusterCaloHits, const unsigned int slidingFitWindow, SlidingFitDataList &slidingFitDataList) const
Calculate the cluster sliding fits.
Box structure used to define 2D field. It's used in KDTree building step to divide the detector space...
void CalculateRPhiScores(pandora::VertexVector &vertexVector, VertexFeatureInfoMap &vertexFeatureInfoMap, const KDTreeMap &kdTreeMap) const
Calculate the r/phi scores for the vertices in a vector, possibly erasing those that fail the fast sc...
std::unordered_map< const pandora::CaloHit *, const pandora::Cluster * > HitToClusterMap
const pandora::Vertex * ProduceTrainingExamples(const pandora::VertexVector &vertexVector, const VertexFeatureInfoMap &vertexFeatureInfoMap, std::bernoulli_distribution &coinFlip, std::mt19937 &generator, const std::string &interactionType, const std::string &trainingOutputFile, const LArMvaHelper::MvaFeatureVector &eventFeatureList, const float maxRadius, const bool useRPhi) const
Produce a set of training examples for a binary classifier.
void GetVertexScoreList(const pandora::VertexVector &vertexVector, const BeamConstants &beamConstants, HitKDTree2D &kdTreeU, HitKDTree2D &kdTreeV, HitKDTree2D &kdTreeW, VertexScoreList &vertexScoreList) const
Get the vertex score list.
bool m_dropFailedRPhiFastScoreCandidates
Whether to drop candidates that fail the r/phi fast score test.
static bool Classify(const MvaInterface &classifier, TLISTS &&...featureLists)
Use the trained classifier to predict the boolean class of an example.
std::vector< HitKDNode2D > HitKDNode2DList
float m_energyKick
The energy kick feature.
Vertex feature info class.
float GetCoordinateSpan(const pandora::InputFloat &minCoord, const pandora::InputFloat &maxCoord) const
Get the coordinate span.
float m_maxTrueVertexRadius
The maximum distance at which a vertex candidate can be considered the 'true' vertex.
float m_showerAsymmetryConstant
The shower asymmetry constant for the initial region score list.
bool m_allowClassifyDuringTraining
Whether classification is allowed during training.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static InteractionType GetInteractionType(const pandora::MCParticleList &mcPrimaryList)
Get the interaction type of an event.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
bool IsClusterShowerLike(const pandora::Cluster *const pCluster) const
Find whether a cluster is shower-like.
std::vector< SlidingFitData > SlidingFitDataList
float m_localAsymmetryConstant
The local asymmetry constant for the initial region score list.
void ProduceTrainingSets(const pandora::VertexVector &vertexVector, const pandora::VertexVector &bestRegionVertices, VertexFeatureInfoMap &vertexFeatureInfoMap, const LArMvaHelper::MvaFeatureVector &eventFeatureList, const KDTreeMap &kdTreeMap) const
Produce the region and vertex training sets.
Header file for the geometry helper class.
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
float m_regionRadius
The radius for a vertex region.
static void GetClusterBoundingBox(const pandora::Cluster *const pCluster, pandora::CartesianVector &minimumCoordinate, pandora::CartesianVector &maximumCoordinate)
Get minimum and maximum X, Y and Z positions of the calo hits in a cluster.
float m_eventEnergy
The event energy.
std::map< const pandora::Cluster *const, ClusterEndPoints > ClusterEndPointsMap
std::string GetInteractionType() const
Get the interaction type string.
static void SelectReconstructableMCParticles(const pandora::MCParticleList *pMCParticleList, const pandora::CaloHitList *pCaloHitList, const PrimaryParameters ¶meters, std::function< bool(const pandora::MCParticle *const)> fCriteria, MCContributionMap &selectedMCParticlesToHitsMap)
Select primary, reconstructable mc particles that match given criteria.
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...
static pandora::StatusCode ProduceTrainingExample(const std::string &trainingOutputFile, const bool result, TLISTS &&...featureLists)
Produce a training example with the given features and result.
std::pair< pandora::CartesianVector, pandora::CartesianVector > ClusterEndPoints
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
void GetEventShapeFeatures(const pandora::ClusterList &clusterList, float &eventVolume, float &longitudinality) const
Get the event shape features.
Header file for the lar monte carlo particle helper helper class.
float m_eventShoweryness
The event showeryness feature.
static bool SortHitsByPosition(const pandora::CaloHit *const pLhs, const pandora::CaloHit *const pRhs)
Sort calo hits by their position (use Z, followed by X, followed by Y)
Header file for the cluster helper class.
bool m_useRPhiFeatureForRegion
Whether to use the r/phi feature for the region vertex.
static std::string ToString(const InteractionType interactionType)
Get a string representation of an interaction type.
SupportVectorMachine m_svMachineVertex
The vertex support vector machine.
std::map< pandora::HitType, const pandora::ClusterList & > ClusterListMap
Map array of cluster lists for passing to tools.
SupportVectorMachine m_svMachineRegion
The region support vector machine.
float m_minShowerSpineLength
The minimum length at which all are considered to be tracks.
std::string m_mcParticleListName
The MC particle list for creating training examples.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
VertexSelectionBaseAlgorithm class.
static float GetLength(const pandora::Cluster *const pCluster)
Get length of cluster.
float m_globalAsymmetry
The global asymmetry feature.
static pandora::StatusCode AddFeatureToolToVector(pandora::AlgorithmTool *const pFeatureTool, MvaFeatureToolVector< Ts... > &featureToolVector)
Add a feature tool to a vector of feature tools.
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...
Header file for the file helper class.
float m_mcVertexXCorrection
The correction to the x-coordinate of the MC vertex position.
float m_energyKickConstant
The energy kick constant for the initial region score list.
void PopulateInitialScoreList(VertexFeatureInfoMap &vertexFeatureInfoMap, const pandora::Vertex *const pVertex, VertexScoreList &initialScoreList) const
Populate the initial vertex score list for a given vertex.
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to svm files.
std::vector< VertexScore > VertexScoreList
void PopulateVertexFeatureInfoMap(const BeamConstants &beamConstants, const ClusterListMap &clusterListMap, const SlidingFitDataListMap &slidingFitDataListMap, const ShowerClusterListMap &showerClusterListMap, const KDTreeMap &kdTreeMap, const pandora::Vertex *const pVertex, VertexFeatureInfoMap &vertexFeatureInfoMap) const
Populate the vertex feature info map for a given vertex.
InteractionType
InteractionType enum.
float m_localAsymmetry
The local asymmetry feature.
void AddEventFeaturesToVector(const EventFeatureInfo &eventFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector) const
Add the event features to a vector in the correct order.
Detector simulation of raw signals on wires.
float m_eventVolume
The volume of the event.
std::string m_caloHitListName
The 2D CaloHit list name.
Header file for the svm vertex selection algorithm class.
float m_showerClusteringDistance
The shower clustering distance.
void AddVertexFeaturesToVector(const VertexFeatureInfo &vertexFeatureInfo, LArMvaHelper::MvaFeatureVector &featureVector, const bool useRPhi) const
Add the vertex features to a vector in the correct order.
std::string m_trainingOutputFileVertex
The training output file for the vertex Svm.
void GetBestVertex(const pandora::VertexVector &vertexVector, const pandora::Vertex *&pBestVertex, float &bestVertexDr) const
Use the MC information to get the best vertex from a list.
pandora::StatusCode Initialize(const std::string ¶meterLocation, const std::string &svmName)
Initialize the svm using a serialized model.
bool m_useShowerClusteringApproximation
Whether to use the shower clustering distance approximation.
float m_beamDeweightingConstant
The beam deweighting constant for the initial region score list.
const pandora::Vertex * CompareVertices(const pandora::VertexVector &vertexVector, const VertexFeatureInfoMap &vertexFeatureInfoMap, const LArMvaHelper::MvaFeatureVector &eventFeatureList, const SupportVectorMachine &supportVectorMachine, const bool useRPhi) const
Used a binary classifier to compare a set of vertices and pick the best one.
static void GetTrueNeutrinos(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueNeutrinos)
Get neutrino MC particles from an input MC particle list.
bool AddClusterToShower(const ClusterEndPointsMap &clusterEndPointsMap, pandora::ClusterList &availableShowerLikeClusters, const pandora::Cluster *const pCluster, pandora::ClusterList &showerCluster) const
Try to add an available cluster to a given shower cluster, using shower clustering approximation...
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
unsigned int m_nHits
The number of hits in the event.
void PopulateKdTree(const pandora::ClusterList &clusterList, HitKDTree2D &kdTree, HitToClusterMap &hitToClusterMap) const
Populate kd tree with information about hits in a provided list of clusters.
float m_longitudinality
The longitudinality of the event.
std::string m_svmFileName
The Svm file name.
std::string m_trainingOutputFileRegion
The training output file for the region Svm.
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
bool m_trainingSetMode
Whether to train.
void UpdateSpanCoordinate(const float minPositionCoord, const float maxPositionCoord, pandora::InputFloat &minCoord, pandora::InputFloat &maxCoord) const
Update the min/max coordinate spans.
std::string m_regionSvmName
The name of the region Svm to find.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
VertexFeatureTool::FeatureToolVector m_featureToolVector
The feature tool vector.
float GetBeamDeweightingScore(const BeamConstants &beamConstants, const pandora::Vertex *const pVertex) const
Get the beam deweighting score for a vertex.
float m_showerAsymmetry
The shower asymmetry feature.
void CalculateShowerClusterList(const pandora::ClusterList &inputClusterList, ShowerClusterList &showerClusterList) const
Calculate the shower cluster map for a cluster list.
EventFeatureInfo CalculateEventFeatures(const pandora::ClusterList &clusterListU, const pandora::ClusterList &clusterListV, const pandora::ClusterList &clusterListW, const pandora::VertexVector &vertexVector) const
Calculate the event parameters.
unsigned int m_minClusterCaloHits
The min number of hits parameter in the energy score.
void GetShowerLikeClusterEndPoints(const pandora::ClusterList &clusterList, pandora::ClusterList &showerLikeClusters, ClusterEndPointsMap &clusterEndPointsMap) const
Add the endpoints of any shower-like clusters to the map.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
KDTreeBox build_2d_kd_search_region(const pandora::CaloHit *const point, const float x_span, const float z_span)
build_2d_kd_search_region
unsigned int m_nClusters
The number of clusters in the event.
float m_rPhiFineTuningRadius
The maximum distance the r/phi tune can move a vertex.
Event feature info class.
void build(std::vector< KDTreeNodeInfoT< DATA, DIM > > &eltList, const KDTreeBoxT< DIM > ®ion)
Build the KD tree from the "eltList" in the space define by "region".
std::vector< art::Ptr< recob::Vertex > > VertexVector
pandora::StringVector m_inputClusterListNames
The list of cluster list names.
float m_rPhiFeature
The r/phi feature.