All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
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
< SliceFeatures
SliceFeaturesVector
 

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...
 
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 32 of file NeutrinoIdTool.h.

Member Typedef Documentation

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

Definition at line 162 of file NeutrinoIdTool.h.

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

Definition at line 161 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),
36  m_maxNeutrinos(1),
37  m_persistFeatures(false),
38  m_filePathEnvironmentVariable("FW_SEARCH_PATH")
39 {
40 }
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.
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 165 of file NeutrinoIdTool.cc.

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

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

99 {
100  unsigned int nHitsInBestSlice(0), nNuHitsInBestSlice(0);
101 
102  // Get all hits in all slices to find true number of mc hits
103  const CaloHitList *pAllReconstructedCaloHitList(nullptr);
104  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*pAlgorithm, pAllReconstructedCaloHitList));
105 
106  const MCParticleList *pMCParticleList(nullptr);
107  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*pAlgorithm, pMCParticleList));
108 
109  // Obtain map: [mc particle -> primary mc particle]
110  LArMCParticleHelper::MCRelationMap mcToPrimaryMCMap;
111  LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcToPrimaryMCMap);
112 
113  // Remove non-reconstructable hits, e.g. those downstream of a neutron
114  CaloHitList reconstructableCaloHitList;
115  LArMCParticleHelper::PrimaryParameters parameters;
116  LArMCParticleHelper::SelectCaloHits(pAllReconstructedCaloHitList, mcToPrimaryMCMap, reconstructableCaloHitList,
117  parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
118 
119  const int nuNHitsTotal(this->CountNeutrinoInducedHits(reconstructableCaloHitList));
120  const CaloHitSet reconstructableCaloHitSet(reconstructableCaloHitList.begin(), reconstructableCaloHitList.end());
121 
122  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
123  {
124  CaloHitList reconstructedCaloHitList;
125  this->Collect2DHits(crSliceHypotheses.at(sliceIndex), reconstructedCaloHitList, reconstructableCaloHitSet);
126 
127  for (const ParticleFlowObject *const pNeutrino : nuSliceHypotheses.at(sliceIndex))
128  {
129  const PfoList &nuFinalStates(pNeutrino->GetDaughterPfoList());
130  this->Collect2DHits(nuFinalStates, reconstructedCaloHitList, reconstructableCaloHitSet);
131  }
132 
133  const unsigned int nNuHits(this->CountNeutrinoInducedHits(reconstructedCaloHitList));
134 
135  if (nNuHits > nNuHitsInBestSlice)
136  {
137  nNuHitsInBestSlice = nNuHits;
138  nHitsInBestSlice = reconstructedCaloHitList.size();
139  bestSliceIndex = sliceIndex;
140  }
141  }
142 
143  // ATTN for events with no neutrino induced hits, default neutrino purity and completeness to zero
144  const float purity(nHitsInBestSlice > 0 ? static_cast<float>(nNuHitsInBestSlice) / static_cast<float>(nHitsInBestSlice) : 0.f);
145  const float completeness(nuNHitsTotal > 0 ? static_cast<float>(nNuHitsInBestSlice) / static_cast<float>(nuNHitsTotal) : 0.f);
146  return this->PassesQualityCuts(pAlgorithm, purity, completeness);
147 }
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...
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 &quot;reconstructable&quot; 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 208 of file NeutrinoIdTool.cc.

209 {
210  const MCParticleList *pMCParticleList = nullptr;
211  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*pAlgorithm, pMCParticleList));
212 
213  MCParticleVector trueNeutrinos;
214  LArMCParticleHelper::GetTrueNeutrinos(pMCParticleList, trueNeutrinos);
215 
216  if (trueNeutrinos.size() != 1)
217  {
218  std::cout << "NeutrinoIdTool::GetNuanceCode - Error: number of true neutrinos in event must be exactly one" << std::endl;
219  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
220  }
221 
222  return LArMCParticleHelper::GetNuanceCode(trueNeutrinos.front());
223 }
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.
BEGIN_PROLOG could also be cout
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 87 of file NeutrinoIdTool.cc.

89 {
90  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
91  sliceFeaturesVector.push_back(SliceFeatures(nuSliceHypotheses.at(sliceIndex), crSliceHypotheses.at(sliceIndex), pTool));
92 }
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 152 of file NeutrinoIdTool.cc.

153 {
154  if (purity < m_minPurity || completeness < m_minCompleteness)
155  return false;
156  if (m_selectNuanceCode && (this->GetNuanceCode(pAlgorithm) != m_nuance))
157  return false;
158 
159  return true;
160 }
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 593 of file NeutrinoIdTool.cc.

594 {
595  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "UseTrainingMode", m_useTrainingMode));
596 
597  if (m_useTrainingMode)
598  {
599  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "TrainingOutputFileName", m_trainingOutputFile));
600  }
601 
602  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumPurity", m_minPurity));
603 
604  PANDORA_RETURN_RESULT_IF_AND_IF(
605  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumCompleteness", m_minCompleteness));
606 
607  PANDORA_RETURN_RESULT_IF_AND_IF(
608  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SelectNuanceCode", m_selectNuanceCode));
609 
610  if (m_selectNuanceCode)
611  {
612  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "NuanceCode", m_nuance));
613  }
614 
615  PANDORA_RETURN_RESULT_IF_AND_IF(
616  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumNeutrinoProbability", m_minProbability));
617 
618  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaximumNeutrinos", m_maxNeutrinos));
619 
620  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "PersistFeatures", m_persistFeatures));
621 
622  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
623  XmlHelper::ReadValue(xmlHandle, "FilePathEnvironmentVariable", m_filePathEnvironmentVariable));
624 
625  if (!m_useTrainingMode)
626  {
627  std::string mvaName;
628  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MvaName", mvaName));
629 
630  std::string mvaFileName;
631  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MvaFileName", mvaFileName));
632 
633  const std::string fullMvaFileName(LArFileHelper::FindFileInPath(mvaFileName, m_filePathEnvironmentVariable));
634  m_mva.Initialize(fullMvaFileName, mvaName);
635  }
636 
637  return STATUS_CODE_SUCCESS;
638 }
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 228 of file NeutrinoIdTool.cc.

229 {
230  for (const PfoList &pfos : hypotheses)
231  {
232  for (const ParticleFlowObject *const pPfo : pfos)
233  {
234  object_creation::ParticleFlowObject::Metadata metadata;
235  metadata.m_propertiesToAdd["NuScore"] = -1.f;
236  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
237  }
238 
239  this->SelectPfos(pfos, selectedPfos);
240  }
241 }
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 45 of file NeutrinoIdTool.cc.

47 {
48  if (nuSliceHypotheses.size() != crSliceHypotheses.size())
49  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
50 
51  const unsigned int nSlices(nuSliceHypotheses.size());
52  if (nSlices == 0)
53  return;
54 
55  SliceFeaturesVector sliceFeaturesVector;
56  this->GetSliceFeatures(this, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector);
57 
59  {
60  // ATTN in training mode, just return everything as a cosmic-ray
61  this->SelectAllPfos(pAlgorithm, crSliceHypotheses, selectedPfos);
62 
63  unsigned int bestSliceIndex(std::numeric_limits<unsigned int>::max());
64  if (!this->GetBestMCSliceIndex(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, bestSliceIndex))
65  return;
66 
67  for (unsigned int sliceIndex = 0; sliceIndex < nSlices; ++sliceIndex)
68  {
69  const SliceFeatures &features(sliceFeaturesVector.at(sliceIndex));
70  if (!features.IsFeatureVectorAvailable())
71  continue;
72 
73  LArMvaHelper::MvaFeatureVector featureVector;
74  features.GetFeatureVector(featureVector);
75  LArMvaHelper::ProduceTrainingExample(m_trainingOutputFile, sliceIndex == bestSliceIndex, featureVector);
76  }
77 
78  return;
79  }
80 
81  this->SelectPfosByProbability(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector, selectedPfos);
82 }
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:72
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:282
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 320 of file NeutrinoIdTool.cc.

321 {
322  selectedPfos.insert(selectedPfos.end(), pfos.begin(), pfos.end());
323 }
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 246 of file NeutrinoIdTool.cc.

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

Member Data Documentation

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 273 of file NeutrinoIdTool.h.

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 268 of file NeutrinoIdTool.h.

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 264 of file NeutrinoIdTool.h.

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

Minimum probability required to classify a slice as the neutrino.

Definition at line 267 of file NeutrinoIdTool.h.

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 263 of file NeutrinoIdTool.h.

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

The mva.

Definition at line 272 of file NeutrinoIdTool.h.

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

Nuance code to select for training.

Definition at line 262 of file NeutrinoIdTool.h.

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 270 of file NeutrinoIdTool.h.

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

Should select training events by nuance code.

Definition at line 261 of file NeutrinoIdTool.h.

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

Output file name for training examples.

Definition at line 260 of file NeutrinoIdTool.h.

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 259 of file NeutrinoIdTool.h.


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