LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::NeutrinoIdTool Class Reference

NeutrinoIdTool class. More...

#include "NeutrinoIdTool.h"

Inheritance diagram for lar_content::NeutrinoIdTool:
lar_content::SliceIdBaseTool

Classes

class  SliceFeatures
 Slice features class. More...
 

Public Member Functions

 NeutrinoIdTool ()
 Default constructor. More...
 
void SelectOutputPfos (const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, pandora::PfoList &selectedPfos)
 Select which reconstruction hypotheses to use; neutrino outcomes or cosmic-ray muon outcomes for each slice. More...
 

Private Types

typedef std::pair< unsigned int, float > UintFloatPair
 
typedef std::vector< SliceFeaturesSliceFeaturesVector
 

Private Member Functions

void GetSliceFeatures (const NeutrinoIdTool *const pTool, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const
 Get the features of each slice. More...
 
bool GetBestMCSliceIndex (const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, unsigned int &bestSliceIndex) const
 Get the slice with the most neutrino induced hits using Monte-Carlo information. More...
 
bool PassesQualityCuts (const pandora::Algorithm *const pAlgorithm, const float purity, const float completeness) const
 Determine if the event passes the selection cuts for training and has the required NUANCE code. More...
 
void Collect2DHits (const pandora::PfoList &pfos, pandora::CaloHitList &reconstructedCaloHitList, const pandora::CaloHitSet &reconstructableCaloHitSet) const
 Collect all 2D hits in a supplied list of Pfos and push them on to an existing hit list, check so not to double count. More...
 
unsigned int CountNeutrinoInducedHits (const pandora::CaloHitList &caloHitList) const
 Count the number of neutrino induced hits in a given list using MC information. More...
 
int GetNuanceCode (const pandora::Algorithm *const pAlgorithm) const
 Use the current MCParticle list to get the nuance code of the neutrino in the event. More...
 
void SelectAllPfos (const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const
 Select all pfos under the same hypothesis. More...
 
void SelectPfosByProbability (const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, const SliceFeaturesVector &sliceFeaturesVector, pandora::PfoList &selectedPfos) const
 Select pfos based on the probability that their slice contains a neutrino interaction. More...
 
void SelectPfos (const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
 Add the given pfos to the selected Pfo list. More...
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 

Private Attributes

bool m_useTrainingMode
 Should use training mode. If true, training examples will be written to the output file. More...
 
std::string m_trainingOutputFile
 Output file name for training examples. More...
 
bool m_selectNuanceCode
 Should select training events by nuance code. More...
 
int m_nuance
 Nuance code to select for training. More...
 
float m_minPurity
 Minimum purity of the best slice to use event for training. More...
 
float m_minCompleteness
 Minimum completeness of the best slice to use event for training. More...
 
float m_minProbability
 Minimum probability required to classify a slice as the neutrino. More...
 
unsigned int m_maxNeutrinos
 The maximum number of neutrinos to select in any one event. More...
 
SupportVectorMachine m_supportVectorMachine
 The support vector machine. More...
 
std::string m_filePathEnvironmentVariable
 The environment variable providing a list of paths to svm files. More...
 

Detailed Description

NeutrinoIdTool class.

Compares the neutrino and cosmic hypotheses of all of the slices in the event. Uses an SVM to calculate the probability of each slice containing a neutrino interaction. The N slices with the highest probabilities are identified as a neutrino (if sufficiently probable) all other slices are deemed cosmogenic.

If training mode is switched on, then the tool will write SVM training exmples to the specified output file. The events selected for training must pass (user configurable) slicing quality cuts. Users may also select events based on their interaction type (nuance code).

Definition at line 30 of file NeutrinoIdTool.h.

Member Typedef Documentation

Definition at line 149 of file NeutrinoIdTool.h.

typedef std::pair<unsigned int, float> lar_content::NeutrinoIdTool::UintFloatPair
private

Definition at line 148 of file NeutrinoIdTool.h.

Constructor & Destructor Documentation

lar_content::NeutrinoIdTool::NeutrinoIdTool ( )

Default constructor.

Definition at line 28 of file NeutrinoIdTool.cc.

28  :
29  m_useTrainingMode(false),
30  m_selectNuanceCode(false),
32  m_minPurity(0.9f),
33  m_minCompleteness(0.9f),
34  m_minProbability(0.0f),
35  m_maxNeutrinos(1),
36  m_filePathEnvironmentVariable("FW_SEARCH_PATH")
37 {
38 }
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to svm files.
bool m_selectNuanceCode
Should select training events by nuance code.
float m_minCompleteness
Minimum completeness of the best slice to use event for training.
int m_nuance
Nuance code to select for training.
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
float m_minPurity
Minimum purity of the best slice to use event for training.
TFile f
Definition: plotHisto.C:6
Int_t max
Definition: plot.C:27
float m_minProbability
Minimum probability required to classify a slice as the neutrino.
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...

Member Function Documentation

void lar_content::NeutrinoIdTool::Collect2DHits ( const pandora::PfoList &  pfos,
pandora::CaloHitList &  reconstructedCaloHitList,
const pandora::CaloHitSet &  reconstructableCaloHitSet 
) const
private

Collect all 2D hits in a supplied list of Pfos and push them on to an existing hit list, check so not to double count.

Parameters
pfosinput list of pfos
reconstructedCaloHitListoutput list of all 2d hits in the input pfos
reconstructableCaloHitSetset of reconstructable calo hits

Definition at line 150 of file NeutrinoIdTool.cc.

References lar_content::LArPfoHelper::GetCaloHits().

Referenced by GetBestMCSliceIndex().

151 {
152  CaloHitList collectedHits;
153  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_U, collectedHits);
154  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_V, collectedHits);
155  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_W, collectedHits);
156 
157  for (const CaloHit *const pCaloHit : collectedHits)
158  {
159  if (!reconstructableCaloHitSet.count(pCaloHit))
160  continue;
161 
162  // Ensure no hits have been double counted
163  if (std::find(reconstructedCaloHitList.begin(), reconstructedCaloHitList.end(), pCaloHit) == reconstructedCaloHitList.end())
164  reconstructedCaloHitList.push_back(pCaloHit);
165  }
166 }
static void GetCaloHits(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::CaloHitList &caloHitList)
Get a list of calo hits of a particular hit type from a list of pfos.
unsigned int lar_content::NeutrinoIdTool::CountNeutrinoInducedHits ( const pandora::CaloHitList &  caloHitList) const
private

Count the number of neutrino induced hits in a given list using MC information.

Parameters
caloHitSetinput list of calo hits
Returns
the number of neutrino induced hits in the input list

Definition at line 170 of file NeutrinoIdTool.cc.

References lar_content::LArMCParticleHelper::GetParentMCParticle(), and lar_content::LArMCParticleHelper::IsNeutrino().

Referenced by GetBestMCSliceIndex().

171 {
172  unsigned int nNuHits(0);
173  for (const CaloHit *const pCaloHit : caloHitList)
174  {
175  try
176  {
177  if (LArMCParticleHelper::IsNeutrino(LArMCParticleHelper::GetParentMCParticle(MCParticleHelper::GetMainMCParticle(pCaloHit))))
178  nNuHits++;
179  }
180  catch (const StatusCodeException &)
181  {
182  }
183  }
184 
185  return nNuHits;
186 }
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
static bool IsNeutrino(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is a neutrino or antineutrino.
bool lar_content::NeutrinoIdTool::GetBestMCSliceIndex ( const pandora::Algorithm *const  pAlgorithm,
const SliceHypotheses nuSliceHypotheses,
const SliceHypotheses crSliceHypotheses,
unsigned int &  bestSliceIndex 
) const
private

Get the slice with the most neutrino induced hits using Monte-Carlo information.

Parameters
pAlgorithmaddress of the master algorithm
nuSliceHypothesesthe input neutrino slice hypotheses
crSliceHypothesesthe input cosmic slice hypotheses
bestSliceIndexthe index of the slice with the most neutrino hits
Returns
does the best slice pass the quality cuts for training?

Definition at line 87 of file NeutrinoIdTool.cc.

References Collect2DHits(), CountNeutrinoInducedHits(), f, lar_content::LArMCParticleHelper::GetMCPrimaryMap(), lar_content::LArMCParticleHelper::PrimaryParameters::m_maxPhotonPropagation, lar_content::LArMCParticleHelper::PrimaryParameters::m_selectInputHits, PassesQualityCuts(), and lar_content::LArMCParticleHelper::SelectCaloHits().

Referenced by SelectOutputPfos().

88 {
89  unsigned int nHitsInBestSlice(0), nNuHitsInBestSlice(0);
90 
91  // Get all hits in all slices to find true number of mc hits
92  const CaloHitList *pAllReconstructedCaloHitList(nullptr);
93  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*pAlgorithm, pAllReconstructedCaloHitList));
94 
95  const MCParticleList *pMCParticleList(nullptr);
96  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*pAlgorithm, pMCParticleList));
97 
98  // Obtain map: [mc particle -> primary mc particle]
99  LArMCParticleHelper::MCRelationMap mcToPrimaryMCMap;
100  LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcToPrimaryMCMap);
101 
102  // Remove non-reconstructable hits, e.g. those downstream of a neutron
103  CaloHitList reconstructableCaloHitList;
104  LArMCParticleHelper::PrimaryParameters parameters;
105  LArMCParticleHelper::SelectCaloHits(pAllReconstructedCaloHitList, mcToPrimaryMCMap, reconstructableCaloHitList, parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
106 
107  const int nuNHitsTotal(this->CountNeutrinoInducedHits(reconstructableCaloHitList));
108  const CaloHitSet reconstructableCaloHitSet(reconstructableCaloHitList.begin(), reconstructableCaloHitList.end());
109 
110  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
111  {
112  CaloHitList reconstructedCaloHitList;
113  this->Collect2DHits(crSliceHypotheses.at(sliceIndex), reconstructedCaloHitList, reconstructableCaloHitSet);
114 
115  for (const ParticleFlowObject *const pNeutrino : nuSliceHypotheses.at(sliceIndex))
116  {
117  const PfoList &nuFinalStates(pNeutrino->GetDaughterPfoList());
118  this->Collect2DHits(nuFinalStates, reconstructedCaloHitList, reconstructableCaloHitSet);
119  }
120 
121  const unsigned int nNuHits(this->CountNeutrinoInducedHits(reconstructedCaloHitList));
122 
123  if (nNuHits > nNuHitsInBestSlice)
124  {
125  nNuHitsInBestSlice = nNuHits;
126  nHitsInBestSlice = reconstructedCaloHitList.size();
127  bestSliceIndex = sliceIndex;
128  }
129  }
130 
131  // ATTN for events with no neutrino induced hits, default neutrino purity and completeness to zero
132  const float purity(nHitsInBestSlice > 0 ? static_cast<float>(nNuHitsInBestSlice) / static_cast<float>(nHitsInBestSlice) : 0.f);
133  const float completeness(nuNHitsTotal > 0 ? static_cast<float>(nNuHitsInBestSlice) / static_cast<float>(nuNHitsTotal) : 0.f);
134 
135  return this->PassesQualityCuts(pAlgorithm, purity, completeness);
136 }
static void GetMCPrimaryMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcPrimaryMap)
Get mapping from individual mc particles (in a provided list) and their primary parent mc particles...
static void SelectCaloHits(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToPrimaryMCMap, pandora::CaloHitList &selectedCaloHitList, const bool selectInputHits, const float maxPhotonPropagation)
Select a subset of calo hits representing those that represent "reconstructable" regions of the event...
TFile f
Definition: plotHisto.C:6
unsigned int CountNeutrinoInducedHits(const pandora::CaloHitList &caloHitList) const
Count the number of neutrino induced hits in a given list using MC information.
void Collect2DHits(const pandora::PfoList &pfos, pandora::CaloHitList &reconstructedCaloHitList, const pandora::CaloHitSet &reconstructableCaloHitSet) const
Collect all 2D hits in a supplied list of Pfos and push them on to an existing hit list...
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
bool PassesQualityCuts(const pandora::Algorithm *const pAlgorithm, const float purity, const float completeness) const
Determine if the event passes the selection cuts for training and has the required NUANCE code...
int lar_content::NeutrinoIdTool::GetNuanceCode ( const pandora::Algorithm *const  pAlgorithm) const
private

Use the current MCParticle list to get the nuance code of the neutrino in the event.

Parameters
pAlgorithmaddress of the master algorithm
Returns
the nuance code of the event

Definition at line 190 of file NeutrinoIdTool.cc.

References lar_content::LArMCParticleHelper::GetNuanceCode(), and lar_content::LArMCParticleHelper::GetTrueNeutrinos().

Referenced by PassesQualityCuts().

191 {
192  const MCParticleList *pMCParticleList = nullptr;
193  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*pAlgorithm, pMCParticleList));
194 
195  MCParticleVector trueNeutrinos;
196  LArMCParticleHelper::GetTrueNeutrinos(pMCParticleList, trueNeutrinos);
197 
198  if (trueNeutrinos.size() != 1)
199  {
200  std::cout << "NeutrinoIdTool::GetNuanceCode - Error: number of true neutrinos in event must be exactly one" << std::endl;
201  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
202  }
203 
204  return LArMCParticleHelper::GetNuanceCode(trueNeutrinos.front());
205 }
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
static void GetTrueNeutrinos(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueNeutrinos)
Get neutrino MC particles from an input MC particle list.
void lar_content::NeutrinoIdTool::GetSliceFeatures ( const NeutrinoIdTool *const  pTool,
const SliceHypotheses nuSliceHypotheses,
const SliceHypotheses crSliceHypotheses,
SliceFeaturesVector sliceFeaturesVector 
) const
private

Get the features of each slice.

Parameters
pToolthe address of the this NeutrinoId tool
nuSliceHypothesesthe input neutrino slice hypotheses
crSliceHypothesesthe input cosmic slice hypotheses
sliceFeaturesVectorvector to hold the slice features

Definition at line 79 of file NeutrinoIdTool.cc.

Referenced by SelectOutputPfos().

80 {
81  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
82  sliceFeaturesVector.push_back(SliceFeatures(nuSliceHypotheses.at(sliceIndex), crSliceHypotheses.at(sliceIndex), pTool));
83 }
bool lar_content::NeutrinoIdTool::PassesQualityCuts ( const pandora::Algorithm *const  pAlgorithm,
const float  purity,
const float  completeness 
) const
private

Determine if the event passes the selection cuts for training and has the required NUANCE code.

Parameters
pAlgorithmaddress of the master algorithm
puritypurity of best slice
completenesscompleteness of best slice
Returns
does the evenr pass the quality cuts on purity and completeness and has the required NUANCE code

Definition at line 140 of file NeutrinoIdTool.cc.

References GetNuanceCode(), m_minCompleteness, m_minPurity, m_nuance, and m_selectNuanceCode.

Referenced by GetBestMCSliceIndex().

141 {
142  if (purity < m_minPurity || completeness < m_minCompleteness) return false;
143  if (m_selectNuanceCode && (this->GetNuanceCode(pAlgorithm) != m_nuance)) return false;
144 
145  return true;
146 }
bool m_selectNuanceCode
Should select training events by nuance code.
float m_minCompleteness
Minimum completeness of the best slice to use event for training.
int m_nuance
Nuance code to select for training.
float m_minPurity
Minimum purity of the best slice to use event for training.
int GetNuanceCode(const pandora::Algorithm *const pAlgorithm) const
Use the current MCParticle list to get the nuance code of the neutrino in the event.
StatusCode lar_content::NeutrinoIdTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 515 of file NeutrinoIdTool.cc.

References lar_content::LArFileHelper::FindFileInPath(), lar_content::SupportVectorMachine::Initialize(), m_filePathEnvironmentVariable, m_maxNeutrinos, m_minCompleteness, m_minProbability, m_minPurity, m_nuance, m_selectNuanceCode, m_supportVectorMachine, m_trainingOutputFile, and m_useTrainingMode.

516 {
517  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
518  "UseTrainingMode", m_useTrainingMode));
519 
520  if (m_useTrainingMode)
521  {
522  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
523  "TrainingOutputFileName", m_trainingOutputFile));
524  }
525 
526  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
527  "MinimumPurity", m_minPurity));
528 
529  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
530  "MinimumCompleteness", m_minCompleteness));
531 
532  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
533  "SelectNuanceCode", m_selectNuanceCode));
534 
535  if (m_selectNuanceCode)
536  {
537  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
538  "NuanceCode", m_nuance));
539  }
540 
541  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
542  "MinimumNeutrinoProbability", m_minProbability));
543 
544  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
545  "MaximumNeutrinos", m_maxNeutrinos));
546 
547  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
548  "FilePathEnvironmentVariable", m_filePathEnvironmentVariable));
549 
550  if (!m_useTrainingMode)
551  {
552  std::string svmName;
553  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
554  "SvmName", svmName));
555 
556  std::string svmFileName;
557  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
558  "SvmFileName", svmFileName));
559 
560  const std::string fullSvmFileName(LArFileHelper::FindFileInPath(svmFileName, m_filePathEnvironmentVariable));
561  m_supportVectorMachine.Initialize(fullSvmFileName, svmName);
562  }
563 
564  return STATUS_CODE_SUCCESS;
565 }
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to svm files.
bool m_selectNuanceCode
Should select training events by nuance code.
float m_minCompleteness
Minimum completeness of the best slice to use event for training.
int m_nuance
Nuance code to select for training.
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
float m_minPurity
Minimum purity of the best slice to use event for training.
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...
pandora::StatusCode Initialize(const std::string &parameterLocation, const std::string &svmName)
Initialize the svm using a serialized model.
std::string m_trainingOutputFile
Output file name for training examples.
float m_minProbability
Minimum probability required to classify a slice as the neutrino.
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...
SupportVectorMachine m_supportVectorMachine
The support vector machine.
void lar_content::NeutrinoIdTool::SelectAllPfos ( const pandora::Algorithm *const  pAlgorithm,
const SliceHypotheses hypotheses,
pandora::PfoList &  selectedPfos 
) const
private

Select all pfos under the same hypothesis.

Parameters
pAlgorithmaddress of the master algorithm
hypothesesthe lists of slices under a certain hypothesis
selectedPfosthe list of pfos to populate

Definition at line 209 of file NeutrinoIdTool.cc.

References SelectPfos().

Referenced by SelectOutputPfos().

210 {
211  for (const PfoList &pfos : hypotheses)
212  {
213  for (const ParticleFlowObject *const pPfo : pfos)
214  {
215  object_creation::ParticleFlowObject::Metadata metadata;
216  metadata.m_propertiesToAdd["TestBeamScore"] = -1.f;
217  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
218  }
219 
220  this->SelectPfos(pfos, selectedPfos);
221  }
222 }
void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
Add the given pfos to the selected Pfo list.
void lar_content::NeutrinoIdTool::SelectOutputPfos ( const pandora::Algorithm *const  pAlgorithm,
const SliceHypotheses nuSliceHypotheses,
const SliceHypotheses crSliceHypotheses,
pandora::PfoList &  selectedPfos 
)
virtual

Select which reconstruction hypotheses to use; neutrino outcomes or cosmic-ray muon outcomes for each slice.

Parameters
pAlgorithmthe address of the master instance, used to access MCParticles when in training mode
nuSliceHypothesesthe parent pfos representing the neutrino outcome for each slice
crSliceHypothesesthe parent pfos representing the cosmic-ray muon outcome for each slice
sliceNuPfosto receive the list of selected pfos

Implements lar_content::SliceIdBaseTool.

Definition at line 42 of file NeutrinoIdTool.cc.

References GetBestMCSliceIndex(), lar_content::NeutrinoIdTool::SliceFeatures::GetFeatureVector(), GetSliceFeatures(), m_trainingOutputFile, m_useTrainingMode, max, lar_content::LArMvaHelper::ProduceTrainingExample(), SelectAllPfos(), and SelectPfosByProbability().

43 {
44  if (nuSliceHypotheses.size() != crSliceHypotheses.size())
45  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
46 
47  const unsigned int nSlices(nuSliceHypotheses.size());
48  if (nSlices == 0) return;
49 
50  SliceFeaturesVector sliceFeaturesVector;
51  this->GetSliceFeatures(this, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector);
52 
54  {
55  // ATTN in training mode, just return everything as a cosmic-ray
56  this->SelectAllPfos(pAlgorithm, crSliceHypotheses, selectedPfos);
57 
58  unsigned int bestSliceIndex(std::numeric_limits<unsigned int>::max());
59  if (!this->GetBestMCSliceIndex(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, bestSliceIndex)) return;
60 
61  for (unsigned int sliceIndex = 0; sliceIndex < nSlices; ++sliceIndex)
62  {
63  const SliceFeatures &features(sliceFeaturesVector.at(sliceIndex));
64  if (!features.IsFeatureVectorAvailable()) continue;
65 
66  LArMvaHelper::MvaFeatureVector featureVector;
67  features.GetFeatureVector(featureVector);
68  LArMvaHelper::ProduceTrainingExample(m_trainingOutputFile, sliceIndex == bestSliceIndex, featureVector);
69  }
70 
71  return;
72  }
73 
74  this->SelectPfosByProbability(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector, selectedPfos);
75 }
bool GetBestMCSliceIndex(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, unsigned int &bestSliceIndex) const
Get the slice with the most neutrino induced hits using Monte-Carlo information.
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
void SelectPfosByProbability(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, const SliceFeaturesVector &sliceFeaturesVector, pandora::PfoList &selectedPfos) const
Select pfos based on the probability that their slice contains a neutrino interaction.
Int_t max
Definition: plot.C:27
static pandora::StatusCode ProduceTrainingExample(const std::string &trainingOutputFile, const bool result, TLISTS &&...featureLists)
Produce a training example with the given features and result.
Definition: LArMvaHelper.h:197
void SelectAllPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const
Select all pfos under the same hypothesis.
std::vector< SliceFeatures > SliceFeaturesVector
void GetSliceFeatures(const NeutrinoIdTool *const pTool, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const
Get the features of each slice.
std::string m_trainingOutputFile
Output file name for training examples.
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...
void lar_content::NeutrinoIdTool::SelectPfos ( const pandora::PfoList &  pfos,
pandora::PfoList &  selectedPfos 
) const
private

Add the given pfos to the selected Pfo list.

Parameters
pfosthe pfos to select
selectedPfosthe list of pfos to populate

Definition at line 280 of file NeutrinoIdTool.cc.

Referenced by SelectAllPfos(), and SelectPfosByProbability().

281 {
282  selectedPfos.insert(selectedPfos.end(), pfos.begin(), pfos.end());
283 }
void lar_content::NeutrinoIdTool::SelectPfosByProbability ( const pandora::Algorithm *const  pAlgorithm,
const SliceHypotheses nuSliceHypotheses,
const SliceHypotheses crSliceHypotheses,
const SliceFeaturesVector sliceFeaturesVector,
pandora::PfoList &  selectedPfos 
) const
private

Select pfos based on the probability that their slice contains a neutrino interaction.

Parameters
pAlgorithmaddress of the master algorithm
nuSliceHypothesesthe input neutrino slice hypotheses
crSliceHypothesesthe input cosmic slice hypotheses
sliceFeaturesVectorvector holding the slice features
selectedPfosthe list of pfos to populate

Definition at line 226 of file NeutrinoIdTool.cc.

References m_maxNeutrinos, m_minProbability, m_supportVectorMachine, and SelectPfos().

Referenced by SelectOutputPfos().

227 {
228  // Calculate the probability of each slice that passes the minimum probability cut
229  std::vector<UintFloatPair> sliceIndexProbabilityPairs;
230  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
231  {
232  const float nuProbability(sliceFeaturesVector.at(sliceIndex).GetNeutrinoProbability(m_supportVectorMachine));
233 
234  for (const ParticleFlowObject *const pPfo : crSliceHypotheses.at(sliceIndex))
235  {
236  object_creation::ParticleFlowObject::Metadata metadata;
237  metadata.m_propertiesToAdd["NuScore"] = nuProbability;
238  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
239  }
240 
241  for (const ParticleFlowObject *const pPfo : nuSliceHypotheses.at(sliceIndex))
242  {
243  object_creation::ParticleFlowObject::Metadata metadata;
244  metadata.m_propertiesToAdd["NuScore"] = nuProbability;
245  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
246  }
247 
248  if (nuProbability < m_minProbability)
249  {
250  this->SelectPfos(crSliceHypotheses.at(sliceIndex), selectedPfos);
251  continue;
252  }
253 
254  sliceIndexProbabilityPairs.push_back(UintFloatPair(sliceIndex, nuProbability));
255  }
256 
257  // Sort the slices by probability
258  std::sort(sliceIndexProbabilityPairs.begin(), sliceIndexProbabilityPairs.end(), [] (const UintFloatPair &a, const UintFloatPair &b)
259  {
260  return (a.second > b.second);
261  });
262 
263  // Select the first m_maxNeutrinos as neutrinos, and the rest as cosmic
264  unsigned int nNuSlices(0);
265  for (const UintFloatPair &slice : sliceIndexProbabilityPairs)
266  {
267  if (nNuSlices < m_maxNeutrinos)
268  {
269  this->SelectPfos(nuSliceHypotheses.at(slice.first), selectedPfos);
270  nNuSlices++;
271  continue;
272  }
273 
274  this->SelectPfos(crSliceHypotheses.at(slice.first), selectedPfos);
275  }
276 }
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
std::pair< unsigned int, float > UintFloatPair
float m_minProbability
Minimum probability required to classify a slice as the neutrino.
void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
Add the given pfos to the selected Pfo list.
SupportVectorMachine m_supportVectorMachine
The support vector machine.

Member Data Documentation

std::string lar_content::NeutrinoIdTool::m_filePathEnvironmentVariable
private

The environment variable providing a list of paths to svm files.

Definition at line 254 of file NeutrinoIdTool.h.

Referenced by ReadSettings().

unsigned int lar_content::NeutrinoIdTool::m_maxNeutrinos
private

The maximum number of neutrinos to select in any one event.

Definition at line 251 of file NeutrinoIdTool.h.

Referenced by ReadSettings(), and SelectPfosByProbability().

float lar_content::NeutrinoIdTool::m_minCompleteness
private

Minimum completeness of the best slice to use event for training.

Definition at line 247 of file NeutrinoIdTool.h.

Referenced by PassesQualityCuts(), and ReadSettings().

float lar_content::NeutrinoIdTool::m_minProbability
private

Minimum probability required to classify a slice as the neutrino.

Definition at line 250 of file NeutrinoIdTool.h.

Referenced by ReadSettings(), and SelectPfosByProbability().

float lar_content::NeutrinoIdTool::m_minPurity
private

Minimum purity of the best slice to use event for training.

Definition at line 246 of file NeutrinoIdTool.h.

Referenced by PassesQualityCuts(), and ReadSettings().

int lar_content::NeutrinoIdTool::m_nuance
private

Nuance code to select for training.

Definition at line 245 of file NeutrinoIdTool.h.

Referenced by PassesQualityCuts(), and ReadSettings().

bool lar_content::NeutrinoIdTool::m_selectNuanceCode
private

Should select training events by nuance code.

Definition at line 244 of file NeutrinoIdTool.h.

Referenced by PassesQualityCuts(), and ReadSettings().

SupportVectorMachine lar_content::NeutrinoIdTool::m_supportVectorMachine
private

The support vector machine.

Definition at line 253 of file NeutrinoIdTool.h.

Referenced by ReadSettings(), and SelectPfosByProbability().

std::string lar_content::NeutrinoIdTool::m_trainingOutputFile
private

Output file name for training examples.

Definition at line 243 of file NeutrinoIdTool.h.

Referenced by ReadSettings(), and SelectOutputPfos().

bool lar_content::NeutrinoIdTool::m_useTrainingMode
private

Should use training mode. If true, training examples will be written to the output file.

Definition at line 242 of file NeutrinoIdTool.h.

Referenced by ReadSettings(), and SelectOutputPfos().


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