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

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

Definition at line 153 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),
33  m_minPurity(0.9f),
34  m_minCompleteness(0.9f),
35  m_minProbability(0.0f),
36  m_maxNeutrinos(1),
37  m_filePathEnvironmentVariable("FW_SEARCH_PATH")
38 {
39 }
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 int max(int a, int b)

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 164 of file NeutrinoIdTool.cc.

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

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

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

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

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

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

551 {
552  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "UseTrainingMode", m_useTrainingMode));
553 
554  if (m_useTrainingMode)
555  {
556  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "TrainingOutputFileName", m_trainingOutputFile));
557  }
558 
559  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumPurity", m_minPurity));
560 
561  PANDORA_RETURN_RESULT_IF_AND_IF(
562  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumCompleteness", m_minCompleteness));
563 
564  PANDORA_RETURN_RESULT_IF_AND_IF(
565  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SelectNuanceCode", m_selectNuanceCode));
566 
567  if (m_selectNuanceCode)
568  {
569  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "NuanceCode", m_nuance));
570  }
571 
572  PANDORA_RETURN_RESULT_IF_AND_IF(
573  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumNeutrinoProbability", m_minProbability));
574 
575  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaximumNeutrinos", m_maxNeutrinos));
576 
577  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
578  XmlHelper::ReadValue(xmlHandle, "FilePathEnvironmentVariable", m_filePathEnvironmentVariable));
579 
580  if (!m_useTrainingMode)
581  {
582  std::string mvaName;
583  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MvaName", mvaName));
584 
585  std::string mvaFileName;
586  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MvaFileName", mvaFileName));
587 
588  const std::string fullMvaFileName(LArFileHelper::FindFileInPath(mvaFileName, m_filePathEnvironmentVariable));
589  m_mva.Initialize(fullMvaFileName, mvaName);
590  }
591 
592  return STATUS_CODE_SUCCESS;
593 }
std::string string
Definition: nybbler.cc:12
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...
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 227 of file NeutrinoIdTool.cc.

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

46 {
47  if (nuSliceHypotheses.size() != crSliceHypotheses.size())
48  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
49 
50  const unsigned int nSlices(nuSliceHypotheses.size());
51  if (nSlices == 0)
52  return;
53 
54  SliceFeaturesVector sliceFeaturesVector;
55  this->GetSliceFeatures(this, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector);
56 
58  {
59  // ATTN in training mode, just return everything as a cosmic-ray
60  this->SelectAllPfos(pAlgorithm, crSliceHypotheses, selectedPfos);
61 
62  unsigned int bestSliceIndex(std::numeric_limits<unsigned int>::max());
63  if (!this->GetBestMCSliceIndex(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, bestSliceIndex))
64  return;
65 
66  for (unsigned int sliceIndex = 0; sliceIndex < nSlices; ++sliceIndex)
67  {
68  const SliceFeatures &features(sliceFeaturesVector.at(sliceIndex));
69  if (!features.IsFeatureVectorAvailable())
70  continue;
71 
72  LArMvaHelper::MvaFeatureVector featureVector;
73  features.GetFeatureVector(featureVector);
74  LArMvaHelper::ProduceTrainingExample(m_trainingOutputFile, sliceIndex == bestSliceIndex, featureVector);
75  }
76 
77  return;
78  }
79 
80  this->SelectPfosByProbability(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector, selectedPfos);
81 }
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
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.
void SelectAllPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const
Select all pfos under the same hypothesis.
const char features[]
Definition: feature_tests.c:2
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 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...
static int max(int a, int b)
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 299 of file NeutrinoIdTool.cc.

300 {
301  selectedPfos.insert(selectedPfos.end(), pfos.begin(), pfos.end());
302 }
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 245 of file NeutrinoIdTool.cc.

247 {
248  // Calculate the probability of each slice that passes the minimum probability cut
249  std::vector<UintFloatPair> sliceIndexProbabilityPairs;
250  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
251  {
252  const float nuProbability(sliceFeaturesVector.at(sliceIndex).GetNeutrinoProbability(m_mva));
253 
254  for (const ParticleFlowObject *const pPfo : crSliceHypotheses.at(sliceIndex))
255  {
256  object_creation::ParticleFlowObject::Metadata metadata;
257  metadata.m_propertiesToAdd["NuScore"] = nuProbability;
258  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
259  }
260 
261  for (const ParticleFlowObject *const pPfo : nuSliceHypotheses.at(sliceIndex))
262  {
263  object_creation::ParticleFlowObject::Metadata metadata;
264  metadata.m_propertiesToAdd["NuScore"] = nuProbability;
265  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
266  }
267 
268  if (nuProbability < m_minProbability)
269  {
270  this->SelectPfos(crSliceHypotheses.at(sliceIndex), selectedPfos);
271  continue;
272  }
273 
274  sliceIndexProbabilityPairs.push_back(UintFloatPair(sliceIndex, nuProbability));
275  }
276 
277  // Sort the slices by probability
278  std::sort(sliceIndexProbabilityPairs.begin(), sliceIndexProbabilityPairs.end(),
279  [](const UintFloatPair &a, const UintFloatPair &b) { return (a.second > b.second); });
280 
281  // Select the first m_maxNeutrinos as neutrinos, and the rest as cosmic
282  unsigned int nNuSlices(0);
283  for (const UintFloatPair &slice : sliceIndexProbabilityPairs)
284  {
285  if (nNuSlices < m_maxNeutrinos)
286  {
287  this->SelectPfos(nuSliceHypotheses.at(slice.first), selectedPfos);
288  nNuSlices++;
289  continue;
290  }
291 
292  this->SelectPfos(crSliceHypotheses.at(slice.first), selectedPfos);
293  }
294 }
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
void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
Add the given pfos to the selected Pfo list.
const double a
static bool * b
Definition: config.cpp:1043

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 263 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 260 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 256 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 259 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 255 of file NeutrinoIdTool.h.

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

The mva.

Definition at line 262 of file NeutrinoIdTool.h.

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

Nuance code to select for training.

Definition at line 254 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 253 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 252 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 251 of file NeutrinoIdTool.h.


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