LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::NeutrinoIdTool< T > Class Template Reference

NeutrinoIdTool class. More...

#include "NeutrinoIdTool.h"

Inheritance diagram for lar_content::NeutrinoIdTool< T >:
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...
 
float m_defaultProbability
 Default probability set if score could not be calculated. More...
 
unsigned int m_maxNeutrinos
 The maximum number of neutrinos to select in any one event. More...
 
bool m_persistFeatures
 If true, the mva features will be persisted in the metadata. More...
 
m_mva
 The mva. More...
 
std::string m_filePathEnvironmentVariable
 The environment variable providing a list of paths to mva files. More...
 

Detailed Description

template<typename T>
class lar_content::NeutrinoIdTool< T >

NeutrinoIdTool class.

Compares the neutrino and cosmic hypotheses of all of the slices in the event. Uses an MVA 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 MVA 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 33 of file NeutrinoIdTool.h.

Member Typedef Documentation

template<typename T>
typedef std::vector<SliceFeatures> lar_content::NeutrinoIdTool< T >::SliceFeaturesVector
private

Definition at line 163 of file NeutrinoIdTool.h.

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

Definition at line 162 of file NeutrinoIdTool.h.

Constructor & Destructor Documentation

template<typename T >
lar_content::NeutrinoIdTool< T >::NeutrinoIdTool ( )

Default constructor.

Definition at line 29 of file NeutrinoIdTool.cc.

29  :
30  m_useTrainingMode(false),
31  m_selectNuanceCode(false),
32  m_nuance(-std::numeric_limits<int>::max()),
33  m_minPurity(0.9f),
34  m_minCompleteness(0.9f),
35  m_minProbability(0.0f),
37  m_maxNeutrinos(1),
38  m_persistFeatures(false),
39  m_filePathEnvironmentVariable("FW_SEARCH_PATH")
40 {
41 }
float m_defaultProbability
Default probability set if score could not be calculated.
float m_minProbability
Minimum probability required to classify a slice as the neutrino.
float m_minCompleteness
Minimum completeness of the best slice to use event for training.
TFile f
Definition: plotHisto.C:6
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to mva files.
bool m_selectNuanceCode
Should select training events by nuance code.
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
int m_nuance
Nuance code to select for training.
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...
float m_minPurity
Minimum purity of the best slice to use event for training.
bool m_persistFeatures
If true, the mva features will be persisted in the metadata.

Member Function Documentation

template<typename T>
void lar_content::NeutrinoIdTool< T >::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 166 of file NeutrinoIdTool.cc.

References lar_content::LArPfoHelper::GetCaloHits().

Referenced by lar_content::NeutrinoIdTool< T >::GetBestMCSliceIndex().

167 {
168  CaloHitList collectedHits;
169  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_U, collectedHits);
170  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_V, collectedHits);
171  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_W, collectedHits);
172 
173  for (const CaloHit *const pCaloHit : collectedHits)
174  {
175  const CaloHit *const pParentHit = static_cast<const CaloHit *>(pCaloHit->GetParentAddress());
176  if (!reconstructableCaloHitSet.count(pParentHit))
177  continue;
178 
179  // Ensure no hits have been double counted
180  if (std::find(reconstructedCaloHitList.begin(), reconstructedCaloHitList.end(), pParentHit) == reconstructedCaloHitList.end())
181  reconstructedCaloHitList.push_back(pParentHit);
182  }
183 }
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.
template<typename T>
unsigned int lar_content::NeutrinoIdTool< T >::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 188 of file NeutrinoIdTool.cc.

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

Referenced by lar_content::NeutrinoIdTool< T >::GetBestMCSliceIndex().

189 {
190  unsigned int nNuHits(0);
191  for (const CaloHit *const pCaloHit : caloHitList)
192  {
193  try
194  {
195  if (LArMCParticleHelper::IsNeutrino(LArMCParticleHelper::GetParentMCParticle(MCParticleHelper::GetMainMCParticle(pCaloHit))))
196  nNuHits++;
197  }
198  catch (const StatusCodeException &)
199  {
200  }
201  }
202 
203  return nNuHits;
204 }
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.
template<typename T >
bool lar_content::NeutrinoIdTool< T >::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 98 of file NeutrinoIdTool.cc.

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

Referenced by lar_content::NeutrinoIdTool< T >::SelectOutputPfos().

100 {
101  unsigned int nHitsInBestSlice(0), nNuHitsInBestSlice(0);
102 
103  // Get all hits in all slices to find true number of mc hits
104  const CaloHitList *pAllReconstructedCaloHitList(nullptr);
105  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*pAlgorithm, pAllReconstructedCaloHitList));
106 
107  const MCParticleList *pMCParticleList(nullptr);
108  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*pAlgorithm, pMCParticleList));
109 
110  // Obtain map: [mc particle -> primary mc particle]
111  LArMCParticleHelper::MCRelationMap mcToPrimaryMCMap;
112  LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcToPrimaryMCMap);
113 
114  // Remove non-reconstructable hits, e.g. those downstream of a neutron
115  CaloHitList reconstructableCaloHitList;
116  LArMCParticleHelper::PrimaryParameters parameters;
117  LArMCParticleHelper::SelectCaloHits(pAllReconstructedCaloHitList, mcToPrimaryMCMap, reconstructableCaloHitList,
118  parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
119 
120  const int nuNHitsTotal(this->CountNeutrinoInducedHits(reconstructableCaloHitList));
121  const CaloHitSet reconstructableCaloHitSet(reconstructableCaloHitList.begin(), reconstructableCaloHitList.end());
122 
123  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
124  {
125  CaloHitList reconstructedCaloHitList;
126  this->Collect2DHits(crSliceHypotheses.at(sliceIndex), reconstructedCaloHitList, reconstructableCaloHitSet);
127 
128  for (const ParticleFlowObject *const pNeutrino : nuSliceHypotheses.at(sliceIndex))
129  {
130  const PfoList &nuFinalStates(pNeutrino->GetDaughterPfoList());
131  this->Collect2DHits(nuFinalStates, reconstructedCaloHitList, reconstructableCaloHitSet);
132  }
133 
134  const unsigned int nNuHits(this->CountNeutrinoInducedHits(reconstructedCaloHitList));
135 
136  if (nNuHits > nNuHitsInBestSlice)
137  {
138  nNuHitsInBestSlice = nNuHits;
139  nHitsInBestSlice = reconstructedCaloHitList.size();
140  bestSliceIndex = sliceIndex;
141  }
142  }
143 
144  // ATTN for events with no neutrino induced hits, default neutrino purity and completeness to zero
145  const float purity(nHitsInBestSlice > 0 ? static_cast<float>(nNuHitsInBestSlice) / static_cast<float>(nHitsInBestSlice) : 0.f);
146  const float completeness(nuNHitsTotal > 0 ? static_cast<float>(nNuHitsInBestSlice) / static_cast<float>(nuNHitsTotal) : 0.f);
147  return this->PassesQualityCuts(pAlgorithm, purity, completeness);
148 }
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...
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...
TFile f
Definition: plotHisto.C:6
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...
unsigned int CountNeutrinoInducedHits(const pandora::CaloHitList &caloHitList) const
Count the number of neutrino induced hits in a given list using MC information.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
static void SelectCaloHits(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToTargetMCMap, pandora::CaloHitList &selectedCaloHitList, const bool selectInputHits, const float maxPhotonPropagation)
Select a subset of calo hits representing those that represent "reconstructable" regions of the event...
template<typename T >
int lar_content::NeutrinoIdTool< T >::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 209 of file NeutrinoIdTool.cc.

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

Referenced by lar_content::NeutrinoIdTool< T >::PassesQualityCuts().

210 {
211  const MCParticleList *pMCParticleList = nullptr;
212  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*pAlgorithm, pMCParticleList));
213 
214  MCParticleVector trueNeutrinos;
215  LArMCParticleHelper::GetTrueNeutrinos(pMCParticleList, trueNeutrinos);
216 
217  if (trueNeutrinos.size() != 1)
218  {
219  std::cout << "NeutrinoIdTool::GetNuanceCode - Error: number of true neutrinos in event must be exactly one" << std::endl;
220  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
221  }
222 
223  return LArMCParticleHelper::GetNuanceCode(trueNeutrinos.front());
224 }
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static void GetTrueNeutrinos(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueNeutrinos)
Get neutrino MC particles from an input MC particle list.
template<typename T >
void lar_content::NeutrinoIdTool< T >::GetSliceFeatures ( const NeutrinoIdTool< T > *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 88 of file NeutrinoIdTool.cc.

Referenced by lar_content::NeutrinoIdTool< T >::SelectOutputPfos().

90 {
91  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
92  sliceFeaturesVector.push_back(SliceFeatures(nuSliceHypotheses.at(sliceIndex), crSliceHypotheses.at(sliceIndex), pTool));
93 }
template<typename T >
bool lar_content::NeutrinoIdTool< T >::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 153 of file NeutrinoIdTool.cc.

References lar_content::NeutrinoIdTool< T >::GetNuanceCode(), lar_content::NeutrinoIdTool< T >::m_minCompleteness, lar_content::NeutrinoIdTool< T >::m_minPurity, lar_content::NeutrinoIdTool< T >::m_nuance, and lar_content::NeutrinoIdTool< T >::m_selectNuanceCode.

Referenced by lar_content::NeutrinoIdTool< T >::GetBestMCSliceIndex().

154 {
155  if (purity < m_minPurity || completeness < m_minCompleteness)
156  return false;
157  if (m_selectNuanceCode && (this->GetNuanceCode(pAlgorithm) != m_nuance))
158  return false;
159 
160  return true;
161 }
int GetNuanceCode(const pandora::Algorithm *const pAlgorithm) const
Use the current MCParticle list to get the nuance code of the neutrino in the event.
float m_minCompleteness
Minimum completeness of the best slice to use event for training.
bool m_selectNuanceCode
Should select training events by nuance code.
int m_nuance
Nuance code to select for training.
float m_minPurity
Minimum purity of the best slice to use event for training.
template<typename T>
StatusCode lar_content::NeutrinoIdTool< T >::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 594 of file NeutrinoIdTool.cc.

References lar_content::LArFileHelper::FindFileInPath(), lar_content::NeutrinoIdTool< T >::m_defaultProbability, lar_content::NeutrinoIdTool< T >::m_filePathEnvironmentVariable, lar_content::NeutrinoIdTool< T >::m_maxNeutrinos, lar_content::NeutrinoIdTool< T >::m_minCompleteness, lar_content::NeutrinoIdTool< T >::m_minProbability, lar_content::NeutrinoIdTool< T >::m_minPurity, lar_content::NeutrinoIdTool< T >::m_mva, lar_content::NeutrinoIdTool< T >::m_nuance, lar_content::NeutrinoIdTool< T >::m_persistFeatures, lar_content::NeutrinoIdTool< T >::m_selectNuanceCode, lar_content::NeutrinoIdTool< T >::m_trainingOutputFile, and lar_content::NeutrinoIdTool< T >::m_useTrainingMode.

595 {
596  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "UseTrainingMode", m_useTrainingMode));
597 
598  if (m_useTrainingMode)
599  {
600  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "TrainingOutputFileName", m_trainingOutputFile));
601  }
602 
603  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumPurity", m_minPurity));
604 
605  PANDORA_RETURN_RESULT_IF_AND_IF(
606  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumCompleteness", m_minCompleteness));
607 
608  PANDORA_RETURN_RESULT_IF_AND_IF(
609  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SelectNuanceCode", m_selectNuanceCode));
610 
611  if (m_selectNuanceCode)
612  {
613  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "NuanceCode", m_nuance));
614  }
615 
616  PANDORA_RETURN_RESULT_IF_AND_IF(
617  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumNeutrinoProbability", m_minProbability));
618 
619  PANDORA_RETURN_RESULT_IF_AND_IF(
620  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "DefaultProbability", m_defaultProbability));
621 
622  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaximumNeutrinos", m_maxNeutrinos));
623 
624  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "PersistFeatures", m_persistFeatures));
625 
626  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
627  XmlHelper::ReadValue(xmlHandle, "FilePathEnvironmentVariable", m_filePathEnvironmentVariable));
628 
629  if (!m_useTrainingMode)
630  {
631  std::string mvaName;
632  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MvaName", mvaName));
633 
634  std::string mvaFileName;
635  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MvaFileName", mvaFileName));
636 
637  const std::string fullMvaFileName(LArFileHelper::FindFileInPath(mvaFileName, m_filePathEnvironmentVariable));
638  m_mva.Initialize(fullMvaFileName, mvaName);
639  }
640 
641  return STATUS_CODE_SUCCESS;
642 }
float m_defaultProbability
Default probability set if score could not be calculated.
float m_minProbability
Minimum probability required to classify a slice as the neutrino.
float m_minCompleteness
Minimum completeness of the best slice to use event for training.
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to mva files.
bool m_selectNuanceCode
Should select training events by nuance code.
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
int m_nuance
Nuance code to select for training.
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...
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...
bool m_persistFeatures
If true, the mva features will be persisted in the metadata.
std::string m_trainingOutputFile
Output file name for training examples.
template<typename T>
void lar_content::NeutrinoIdTool< T >::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 229 of file NeutrinoIdTool.cc.

References lar_content::NeutrinoIdTool< T >::SelectPfos().

Referenced by lar_content::NeutrinoIdTool< T >::SelectOutputPfos().

230 {
231  for (const PfoList &pfos : hypotheses)
232  {
233  for (const ParticleFlowObject *const pPfo : pfos)
234  {
235  object_creation::ParticleFlowObject::Metadata metadata;
236  metadata.m_propertiesToAdd["NuScore"] = -1.f;
237  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
238  }
239 
240  this->SelectPfos(pfos, selectedPfos);
241  }
242 }
void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
Add the given pfos to the selected Pfo list.
template<typename T>
void lar_content::NeutrinoIdTool< T >::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 46 of file NeutrinoIdTool.cc.

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

48 {
49  if (nuSliceHypotheses.size() != crSliceHypotheses.size())
50  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
51 
52  const unsigned int nSlices(nuSliceHypotheses.size());
53  if (nSlices == 0)
54  return;
55 
56  SliceFeaturesVector sliceFeaturesVector;
57  this->GetSliceFeatures(this, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector);
58 
60  {
61  // ATTN in training mode, just return everything as a cosmic-ray
62  this->SelectAllPfos(pAlgorithm, crSliceHypotheses, selectedPfos);
63 
64  unsigned int bestSliceIndex(std::numeric_limits<unsigned int>::max());
65  if (!this->GetBestMCSliceIndex(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, bestSliceIndex))
66  return;
67 
68  for (unsigned int sliceIndex = 0; sliceIndex < nSlices; ++sliceIndex)
69  {
70  const SliceFeatures &features(sliceFeaturesVector.at(sliceIndex));
71  if (!features.IsFeatureVectorAvailable())
72  continue;
73 
74  LArMvaHelper::MvaFeatureVector featureVector;
75  features.GetFeatureVector(featureVector);
76  LArMvaHelper::ProduceTrainingExample(m_trainingOutputFile, sliceIndex == bestSliceIndex, featureVector);
77  }
78 
79  return;
80  }
81 
82  this->SelectPfosByProbability(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector, selectedPfos);
83 }
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h: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.
static pandora::StatusCode ProduceTrainingExample(const std::string &trainingOutputFile, const bool result, TCONTAINER &&featureContainer)
Produce a training example with the given features and result.
Definition: LArMvaHelper.h:285
void SelectAllPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const
Select all pfos under the same hypothesis.
void GetSliceFeatures(const NeutrinoIdTool *const pTool, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const
Get the features of each slice.
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...
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.
std::vector< SliceFeatures > SliceFeaturesVector
std::string m_trainingOutputFile
Output file name for training examples.
template<typename T>
void lar_content::NeutrinoIdTool< T >::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 321 of file NeutrinoIdTool.cc.

Referenced by lar_content::NeutrinoIdTool< T >::SelectAllPfos(), and lar_content::NeutrinoIdTool< T >::SelectPfosByProbability().

322 {
323  selectedPfos.insert(selectedPfos.end(), pfos.begin(), pfos.end());
324 }
template<typename T>
void lar_content::NeutrinoIdTool< T >::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 247 of file NeutrinoIdTool.cc.

References lar_content::NeutrinoIdTool< T >::m_defaultProbability, lar_content::NeutrinoIdTool< T >::m_maxNeutrinos, lar_content::NeutrinoIdTool< T >::m_minProbability, lar_content::NeutrinoIdTool< T >::m_mva, lar_content::NeutrinoIdTool< T >::m_persistFeatures, lar_content::NeutrinoIdTool< T >::SelectPfos(), and value.

Referenced by lar_content::NeutrinoIdTool< T >::SelectOutputPfos().

249 {
250  // Calculate the probability of each slice that passes the minimum probability cut
251  std::vector<UintFloatPair> sliceIndexProbabilityPairs;
252  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
253  {
254  const float nuProbability(sliceFeaturesVector.at(sliceIndex).GetNeutrinoProbability(m_mva, m_defaultProbability));
255 
256  for (const ParticleFlowObject *const pPfo : crSliceHypotheses.at(sliceIndex))
257  {
258  object_creation::ParticleFlowObject::Metadata metadata;
259  metadata.m_propertiesToAdd["NuScore"] = nuProbability;
260 
261  if (m_persistFeatures && sliceFeaturesVector.at(sliceIndex).IsFeatureVectorAvailable())
262  {
263  LArMvaHelper::DoubleMap featureMap;
264  sliceFeaturesVector.at(sliceIndex).GetFeatureMap(featureMap);
265 
266  for (auto const &[name, value] : featureMap)
267  metadata.m_propertiesToAdd[name] = value;
268  }
269 
270  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
271  }
272 
273  for (const ParticleFlowObject *const pPfo : nuSliceHypotheses.at(sliceIndex))
274  {
275  object_creation::ParticleFlowObject::Metadata metadata;
276  metadata.m_propertiesToAdd["NuScore"] = nuProbability;
277 
278  if (m_persistFeatures && sliceFeaturesVector.at(sliceIndex).IsFeatureVectorAvailable())
279  {
280  LArMvaHelper::DoubleMap featureMap;
281  sliceFeaturesVector.at(sliceIndex).GetFeatureMap(featureMap);
282 
283  for (auto const &[name, value] : featureMap)
284  metadata.m_propertiesToAdd[name] = value;
285  }
286 
287  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
288  }
289 
290  if (nuProbability < m_minProbability)
291  {
292  this->SelectPfos(crSliceHypotheses.at(sliceIndex), selectedPfos);
293  continue;
294  }
295 
296  sliceIndexProbabilityPairs.push_back(UintFloatPair(sliceIndex, nuProbability));
297  }
298 
299  // Sort the slices by probability
300  std::sort(sliceIndexProbabilityPairs.begin(), sliceIndexProbabilityPairs.end(),
301  [](const UintFloatPair &a, const UintFloatPair &b) { return (a.second > b.second); });
302 
303  // Select the first m_maxNeutrinos as neutrinos, and the rest as cosmic
304  unsigned int nNuSlices(0);
305  for (const UintFloatPair &slice : sliceIndexProbabilityPairs)
306  {
307  if (nNuSlices < m_maxNeutrinos)
308  {
309  this->SelectPfos(nuSliceHypotheses.at(slice.first), selectedPfos);
310  nNuSlices++;
311  continue;
312  }
313 
314  this->SelectPfos(crSliceHypotheses.at(slice.first), selectedPfos);
315  }
316 }
float m_defaultProbability
Default probability set if score could not be calculated.
float m_minProbability
Minimum probability required to classify a slice as the neutrino.
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
std::pair< unsigned int, float > UintFloatPair
std::map< std::string, double > DoubleMap
Definition: LArMvaHelper.h:76
void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
Add the given pfos to the selected Pfo list.
double value
Definition: spectrum.C:18
bool m_persistFeatures
If true, the mva features will be persisted in the metadata.

Member Data Documentation

template<typename T>
float lar_content::NeutrinoIdTool< T >::m_defaultProbability
private

Default probability set if score could not be calculated.

Definition at line 269 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::ReadSettings(), and lar_content::NeutrinoIdTool< T >::SelectPfosByProbability().

template<typename T>
std::string lar_content::NeutrinoIdTool< T >::m_filePathEnvironmentVariable
private

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

Definition at line 275 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::ReadSettings().

template<typename T>
unsigned int lar_content::NeutrinoIdTool< T >::m_maxNeutrinos
private

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

Definition at line 270 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::ReadSettings(), and lar_content::NeutrinoIdTool< T >::SelectPfosByProbability().

template<typename T>
float lar_content::NeutrinoIdTool< T >::m_minCompleteness
private

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

Definition at line 265 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::PassesQualityCuts(), and lar_content::NeutrinoIdTool< T >::ReadSettings().

template<typename T>
float lar_content::NeutrinoIdTool< T >::m_minProbability
private

Minimum probability required to classify a slice as the neutrino.

Definition at line 268 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::ReadSettings(), and lar_content::NeutrinoIdTool< T >::SelectPfosByProbability().

template<typename T>
float lar_content::NeutrinoIdTool< T >::m_minPurity
private

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

Definition at line 264 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::PassesQualityCuts(), and lar_content::NeutrinoIdTool< T >::ReadSettings().

template<typename T>
T lar_content::NeutrinoIdTool< T >::m_mva
private
template<typename T>
int lar_content::NeutrinoIdTool< T >::m_nuance
private

Nuance code to select for training.

Definition at line 263 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::PassesQualityCuts(), and lar_content::NeutrinoIdTool< T >::ReadSettings().

template<typename T>
bool lar_content::NeutrinoIdTool< T >::m_persistFeatures
private

If true, the mva features will be persisted in the metadata.

Definition at line 272 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::ReadSettings(), and lar_content::NeutrinoIdTool< T >::SelectPfosByProbability().

template<typename T>
bool lar_content::NeutrinoIdTool< T >::m_selectNuanceCode
private

Should select training events by nuance code.

Definition at line 262 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::PassesQualityCuts(), and lar_content::NeutrinoIdTool< T >::ReadSettings().

template<typename T>
std::string lar_content::NeutrinoIdTool< T >::m_trainingOutputFile
private

Output file name for training examples.

Definition at line 261 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::ReadSettings(), and lar_content::NeutrinoIdTool< T >::SelectOutputPfos().

template<typename T>
bool lar_content::NeutrinoIdTool< T >::m_useTrainingMode
private

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

Definition at line 260 of file NeutrinoIdTool.h.

Referenced by lar_content::NeutrinoIdTool< T >::ReadSettings(), and lar_content::NeutrinoIdTool< T >::SelectOutputPfos().


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