8 #include "Pandora/AlgorithmHeaders.h" 22 SvmPfoCharacterisationAlgorithm::SvmPfoCharacterisationAlgorithm() :
23 m_trainingSetMode(false),
24 m_enableProbability(true),
25 m_useThreeDInformation(true),
26 m_minProbabilityCut(0.5
f),
28 m_filePathEnvironmentVariable(
"FW_SEARCH_PATH")
43 bool isTrueTrack(
false);
47 const MCParticle *
const pMCParticle(MCParticleHelper::GetMainMCParticle(pCluster));
48 isTrueTrack = ((PHOTON != pMCParticle->GetParticleId()) && (E_MINUS != std::abs(pMCParticle->GetParticleId())));
50 catch (
const StatusCodeException &) {}
75 object_creation::ParticleFlowObject::Metadata metadata;
76 metadata.m_propertiesToAdd[
"TrackScore"] = -1.f;
77 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*
this, pPfo, metadata));
79 return (pPfo->GetParticleId() == MU_MINUS);
82 ClusterList wClusterList;
88 bool isTrueTrack(
false);
89 bool isMainMCParticleSet(
false);
94 isTrueTrack = ((PHOTON != pMCParticle->GetParticleId()) && (E_MINUS != std::abs(pMCParticle->GetParticleId())));
95 isMainMCParticleSet = (pMCParticle->GetParticleId() != 0);
97 catch (
const StatusCodeException &) {}
99 if (isMainMCParticleSet)
101 std::string outputFile;
103 const std::string
end=((wClusterList.empty()) ?
"noChargeInfo.txt" :
".txt");
104 outputFile.append(end);
113 if (!featureValue.IsInitialized())
117 object_creation::ParticleFlowObject::Metadata metadata;
118 metadata.m_propertiesToAdd[
"TrackScore"] = -1.f;
119 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*
this, pPfo, metadata));
121 return (pPfo->GetParticleId() == MU_MINUS);
133 object_creation::ParticleFlowObject::Metadata metadata;
134 metadata.m_propertiesToAdd[
"TrackScore"] = score;
135 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*
this, pPfo, metadata));
144 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
147 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
150 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
153 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
156 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
159 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
164 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
167 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
171 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
174 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
179 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"TrainingOutputFileName",
m_trainingOutputFile));
185 std::cout <<
"SvmPfoCharacterisationAlgorithm: SvmFileName and SvmName must be set if in classification mode " << std::endl;
186 return STATUS_CODE_INVALID_PARAMETER;
196 std::cout <<
"SvmPfoCharacterisationAlgorithm: SvmFileName and SvmName must be set if in classification mode for no charge info in 3D mode " << std::endl;
197 return STATUS_CODE_INVALID_PARAMETER;
204 AlgorithmToolVector algorithmToolVector;
205 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithmToolList(*
this, xmlHandle,
"FeatureTools", algorithmToolVector));
209 AlgorithmToolVector algorithmToolVectorNoChargeInfo;
210 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithmToolList(*
this, xmlHandle,
"FeatureToolsNoChargeInfo", algorithmToolVectorNoChargeInfo));
211 for (AlgorithmTool *
const pAlgorithmTool : algorithmToolVector)
213 for (AlgorithmTool *
const pAlgorithmTool : algorithmToolVectorNoChargeInfo)
218 for (AlgorithmTool *
const pAlgorithmTool : algorithmToolVector)
std::string m_svmFileNameNoChargeInfo
The svm input file for PFOs missing the W view, and thus charge info.
bool m_useThreeDInformation
Whether to use 3D information.
static double CalculateProbability(const MvaInterface &classifier, TLISTS &&...featureLists)
Use the trained mva to calculate a classification probability for an example.
static bool IsThreeD(const pandora::ParticleFlowObject *const pPfo)
Does Pfo contain 3D clusters.
Header file for the pfo helper class.
MvaTypes::MvaFeatureVector MvaFeatureVector
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.
std::string m_trainingOutputFile
The training output file.
virtual bool IsClearTrack(const pandora::ParticleFlowObject *const pPfo) const
Whether pfo is identified as a clear track.
static bool Classify(const MvaInterface &classifier, TLISTS &&...featureLists)
Use the trained classifier to predict the boolean class of an example.
PfoCharacterisationFeatureTool::FeatureToolVector m_featureToolVectorNoChargeInfo
The feature tool map for missing W view.
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to svm files.
SupportVectorMachine m_supportVectorMachineNoChargeInfo
The support vector machine for missing W view.
static const pandora::MCParticle * GetMainMCParticle(const pandora::ParticleFlowObject *const pPfo)
Find the mc particle making the largest contribution to 2D clusters in a specified pfo...
Header file for the svm pfo characterisation algorithm class.
std::string m_svmNameNoChargeInfo
The name of the svm to find for PFOs missing the W view, and thus charge info.
PfoCharacterisationFeatureTool::FeatureToolVector m_featureToolVectorThreeD
The feature tool map for 3D info.
SupportVectorMachine m_supportVectorMachine
The support vector machine.
std::string m_svmFileName
The svm input file.
static pandora::StatusCode ProduceTrainingExample(const std::string &trainingOutputFile, const bool result, TLISTS &&...featureLists)
Produce a training example with the given features and result.
InitializedDouble class used to define mva features.
std::string m_svmName
The name of the svm to find.
Header file for the lar monte carlo particle helper helper class.
unsigned int m_minCaloHitsCut
The minimum number of calo hits to qualify as a track.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
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.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
pandora::StatusCode Initialize(const std::string ¶meterLocation, const std::string &svmName)
Initialize the svm using a serialized model.
bool m_trainingSetMode
Whether to train.
bool m_enableProbability
Whether to use probabilities instead of binary classification.
static MvaFeatureVector CalculateFeatures(const MvaFeatureToolVector< Ts... > &featureToolVector, TARGS &&...args)
Calculate the features in a given feature tool vector.
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
float m_minProbabilityCut
The minimum probability to label a cluster as track-like.
ClusterCharacterisationFeatureTool::FeatureToolVector m_featureToolVector
The feature tool map.