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

BdtBeamParticleIdTool class. More...

#include "BdtBeamParticleIdTool.h"

Inheritance diagram for lar_content::BdtBeamParticleIdTool:
lar_content::SliceIdBaseTool

Classes

class  Plane
 Plane class. More...
 
class  SliceFeatureParameters
 SliceFeatureParameters class. More...
 
class  SliceFeatures
 Slice features class. More...
 

Public Member Functions

 BdtBeamParticleIdTool ()
 Constructor. More...
 
 BdtBeamParticleIdTool (const BdtBeamParticleIdTool &rhs)=default
 Copy constructor. More...
 
BdtBeamParticleIdTooloperator= (const BdtBeamParticleIdTool &rhs)=default
 Assignment operator. More...
 
 ~BdtBeamParticleIdTool ()=default
 Destructor. More...
 
void SelectOutputPfos (const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &beamSliceHypotheses, 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::vector< PlanePlaneVector
 
typedef std::vector< SliceFeaturesSliceFeaturesVector
 
typedef std::pair< unsigned int, float > UintFloatPair
 
typedef std::unordered_map< const pandora::MCParticle *, int > MCParticleToIntMap
 

Private Member Functions

pandora::StatusCode Initialize ()
 
void GetSliceFeatures (const BdtBeamParticleIdTool *const pTool, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const
 Get the features of each slice. More...
 
void SelectAllPfos (const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const
 Select all pfos under the same hypothesis. More...
 
void SelectPfos (const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
 Add the given pfos to the selected Pfo list. More...
 
void GetBestMCSliceIndices (const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, pandora::IntVector &bestSliceIndices) const
 Get the slice with the most neutrino induced hits using Monte-Carlo information. More...
 
void PopulateMCParticleToHitsMap (MCParticleToIntMap &mcParticleToIntMap, const pandora::CaloHitList &caloHitList) const
 Fill mc particle to nHits map from calo hit list. More...
 
void Collect2DHits (const pandora::PfoList &pfos, pandora::CaloHitList &caloHitList, 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...
 
bool PassesQualityCuts (const float purity, const float completeness) const
 Determine if the event passes the selection cuts for training. More...
 
void SelectPfosByAdaBDTScore (const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, const SliceFeaturesVector &sliceFeaturesVector, pandora::PfoList &selectedPfos) const
 Select pfos based on the AdaBDT score that the slice contains a beam particle interaction. 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...
 
std::string m_caloHitListName
 Name of input calo hit list. More...
 
std::string m_mcParticleListName
 Name of input MC particle list. 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...
 
AdaBoostDecisionTree m_adaBoostDecisionTree
 The adaptive boost decision tree. More...
 
std::string m_filePathEnvironmentVariable
 The environment variable providing a list of paths to bdt files. More...
 
unsigned int m_maxNeutrinos
 The maximum number of neutrinos to select in any one event. More...
 
float m_minAdaBDTScore
 Minimum score required to classify a slice as a beam particle. More...
 
SliceFeatureParameters m_sliceFeatureParameters
 Geometry information block. More...
 

Detailed Description

BdtBeamParticleIdTool class.

Definition at line 23 of file BdtBeamParticleIdTool.h.

Member Typedef Documentation

typedef std::unordered_map<const pandora::MCParticle*, int> lar_content::BdtBeamParticleIdTool::MCParticleToIntMap
private

Definition at line 311 of file BdtBeamParticleIdTool.h.

Definition at line 81 of file BdtBeamParticleIdTool.h.

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

Definition at line 310 of file BdtBeamParticleIdTool.h.

Constructor & Destructor Documentation

lar_content::BdtBeamParticleIdTool::BdtBeamParticleIdTool ( )

Constructor.

Definition at line 23 of file BdtBeamParticleIdTool.cc.

23  :
24  m_useTrainingMode(false),
26  m_minPurity(0.8f),
27  m_minCompleteness(0.8f),
28  m_adaBoostDecisionTree(AdaBoostDecisionTree()),
29  m_filePathEnvironmentVariable("FW_SEARCH_PATH"),
32  m_sliceFeatureParameters(SliceFeatureParameters())
33 {
34 }
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to bdt files.
float m_minAdaBDTScore
Minimum score required to classify a slice as a beam particle.
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...
TFile f
Definition: plotHisto.C:6
Int_t max
Definition: plot.C:27
std::string m_trainingOutputFile
Output file name for training examples.
float m_minPurity
Minimum purity of the best slice to use event for training.
float m_minCompleteness
Minimum completeness of the best slice to use event for training.
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
AdaBoostDecisionTree m_adaBoostDecisionTree
The adaptive boost decision tree.
SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.
lar_content::BdtBeamParticleIdTool::BdtBeamParticleIdTool ( const BdtBeamParticleIdTool rhs)
default

Copy constructor.

Parameters
rhsthe BdtBeamParticleIdTool to copy
lar_content::BdtBeamParticleIdTool::~BdtBeamParticleIdTool ( )
default

Destructor.

Member Function Documentation

void lar_content::BdtBeamParticleIdTool::Collect2DHits ( const pandora::PfoList &  pfos,
pandora::CaloHitList &  caloHitList,
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
caloHitListoutput list of all 2d hits in the input pfos
reconstructableCaloHitSetto check if part of before adding

Definition at line 260 of file BdtBeamParticleIdTool.cc.

References lar_content::LArPfoHelper::GetCaloHits().

Referenced by GetBestMCSliceIndices().

261 {
262  CaloHitList collectedHits;
263  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_U, collectedHits);
264  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_V, collectedHits);
265  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_W, collectedHits);
266 
267  for (const CaloHit *const pCaloHit : collectedHits)
268  {
269  // ATTN hits collected from Pfos are copies of hits passed from master instance, we need to access their parent to use MC info
270  const CaloHit *pParentCaloHit(static_cast<const CaloHit *>(pCaloHit->GetParentAddress()));
271 
272  if (!reconstructableCaloHitSet.count(pParentCaloHit))
273  continue;
274 
275  // Ensure no hits have been double counted
276  if (std::find(reconstructedCaloHitList.begin(), reconstructedCaloHitList.end(), pParentCaloHit) == reconstructedCaloHitList.end())
277  reconstructedCaloHitList.push_back(pParentCaloHit);
278  }
279 }
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.
void lar_content::BdtBeamParticleIdTool::GetBestMCSliceIndices ( const pandora::Algorithm *const  pAlgorithm,
const SliceHypotheses nuSliceHypotheses,
const SliceHypotheses crSliceHypotheses,
pandora::IntVector bestSliceIndices 
) 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
bestSliceIndicesvector of slice indices passing quality cuts

Definition at line 159 of file BdtBeamParticleIdTool.cc.

References Collect2DHits(), f, lar_content::LArMCParticleHelper::GetMCPrimaryMap(), lar_content::LArMCParticleHelper::GetNuanceCode(), m_caloHitListName, lar_content::LArMCParticleHelper::PrimaryParameters::m_maxPhotonPropagation, m_mcParticleListName, lar_content::LArMCParticleHelper::PrimaryParameters::m_selectInputHits, PassesQualityCuts(), PopulateMCParticleToHitsMap(), and lar_content::LArMCParticleHelper::SelectCaloHits().

Referenced by SelectOutputPfos().

160 {
161  // Get all hits in all slices to find true number of mc hits
162  const CaloHitList *pAllReconstructedCaloHitList(nullptr);
163  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*pAlgorithm, m_caloHitListName, pAllReconstructedCaloHitList));
164 
165  const MCParticleList *pMCParticleList(nullptr);
166  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*pAlgorithm, m_mcParticleListName, pMCParticleList));
167 
168  // Obtain map: [mc particle -> primary mc particle]
169  LArMCParticleHelper::MCRelationMap mcToPrimaryMCMap;
170  LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcToPrimaryMCMap);
171 
172  // Remove non-reconstructable hits, e.g. those downstream of a neutron
173  CaloHitList reconstructableCaloHitList;
174  LArMCParticleHelper::PrimaryParameters parameters;
175  LArMCParticleHelper::SelectCaloHits(pAllReconstructedCaloHitList, mcToPrimaryMCMap, reconstructableCaloHitList, parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
176 
177  MCParticleToIntMap mcParticleToReconstructableHitsMap;
178  this->PopulateMCParticleToHitsMap(mcParticleToReconstructableHitsMap, reconstructableCaloHitList);
179 
180  const CaloHitSet reconstructableCaloHitSet(reconstructableCaloHitList.begin(), reconstructableCaloHitList.end());
181 
182  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
183  {
184  // All hits in a slice - No double counting
185  CaloHitList reconstructedCaloHitList;
186  this->Collect2DHits(crSliceHypotheses.at(sliceIndex), reconstructedCaloHitList, reconstructableCaloHitSet);
187 
188  if (nuSliceHypotheses.at(sliceIndex).size() == 1)
189  {
190  const PfoList &nuFinalStates(nuSliceHypotheses.at(sliceIndex).front()->GetDaughterPfoList());
191  this->Collect2DHits(nuFinalStates, reconstructedCaloHitList, reconstructableCaloHitSet);
192  }
193 
194  const unsigned int nRecoHits(reconstructedCaloHitList.size());
195 
196  // MCParticle to hits in slice map
197  MCParticleToIntMap mcParticleToHitsInSliceMap;
198  this->PopulateMCParticleToHitsMap(mcParticleToHitsInSliceMap, reconstructedCaloHitList);
199 
200  if (mcParticleToHitsInSliceMap.empty())
201  continue;
202 
203  // Get best mc particle for slice
204  const MCParticle *pBestMCParticle(nullptr);
205  unsigned int nSharedHits(0);
206 
207  for (const auto &iter : mcParticleToHitsInSliceMap)
208  {
209  if (iter.second > static_cast<int>(nSharedHits))
210  {
211  pBestMCParticle = iter.first;
212  nSharedHits = iter.second;
213  }
214  }
215 
216  // Only consider if target beam particles
217  if (2001 != LArMCParticleHelper::GetNuanceCode(pBestMCParticle))
218  continue;
219 
220  const unsigned int nMCHits(mcParticleToReconstructableHitsMap.at(pBestMCParticle));
221  const float purity(nRecoHits > 0 ? static_cast<float>(nSharedHits) / static_cast<float>(nRecoHits) : 0.f);
222  const float completeness(nMCHits > 0 ? static_cast<float>(nSharedHits) / static_cast<float>(nMCHits) : 0.f);
223 
224  if (this->PassesQualityCuts(purity, completeness))
225  bestSliceIndices.push_back(sliceIndex);
226  }
227  return;
228 }
std::string m_mcParticleListName
Name of input MC particle list.
static void GetMCPrimaryMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcPrimaryMap)
Get mapping from individual mc particles (in a provided list) and their primary parent mc particles...
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
bool PassesQualityCuts(const float purity, const float completeness) const
Determine if the event passes the selection cuts for training.
static void SelectCaloHits(const pandora::CaloHitList *const pCaloHitList, const MCRelationMap &mcToPrimaryMCMap, pandora::CaloHitList &selectedCaloHitList, const bool selectInputHits, const float maxPhotonPropagation)
Select a subset of calo hits representing those that represent "reconstructable" regions of the event...
TFile f
Definition: plotHisto.C:6
void Collect2DHits(const pandora::PfoList &pfos, pandora::CaloHitList &caloHitList, const pandora::CaloHitSet &reconstructableCaloHitSet) const
Collect all 2D hits in a supplied list of Pfos and push them on to an existing hit list...
void PopulateMCParticleToHitsMap(MCParticleToIntMap &mcParticleToIntMap, const pandora::CaloHitList &caloHitList) const
Fill mc particle to nHits map from calo hit list.
std::unordered_map< const pandora::MCParticle *, int > MCParticleToIntMap
std::string m_caloHitListName
Name of input calo hit list.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
void lar_content::BdtBeamParticleIdTool::GetSliceFeatures ( const BdtBeamParticleIdTool *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 127 of file BdtBeamParticleIdTool.cc.

References m_sliceFeatureParameters.

Referenced by SelectOutputPfos().

128 {
129  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
130  sliceFeaturesVector.push_back(SliceFeatures(nuSliceHypotheses.at(sliceIndex), crSliceHypotheses.at(sliceIndex), pTool, m_sliceFeatureParameters));
131 }
SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.
StatusCode lar_content::BdtBeamParticleIdTool::Initialize ( )
private

Definition at line 38 of file BdtBeamParticleIdTool.cc.

References lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::Initialize(), m_sliceFeatureParameters, max, and min.

39 {
40  // Get global LArTPC geometry information
41  const LArTPCMap &larTPCMap(this->GetPandora().GetGeometry()->GetLArTPCMap());
42  const LArTPC *const pFirstLArTPC(larTPCMap.begin()->second);
43  float parentMinX(pFirstLArTPC->GetCenterX() - 0.5f * pFirstLArTPC->GetWidthX());
44  float parentMaxX(pFirstLArTPC->GetCenterX() + 0.5f * pFirstLArTPC->GetWidthX());
45  float parentMinY(pFirstLArTPC->GetCenterY() - 0.5f * pFirstLArTPC->GetWidthY());
46  float parentMaxY(pFirstLArTPC->GetCenterY() + 0.5f * pFirstLArTPC->GetWidthY());
47  float parentMinZ(pFirstLArTPC->GetCenterZ() - 0.5f * pFirstLArTPC->GetWidthZ());
48  float parentMaxZ(pFirstLArTPC->GetCenterZ() + 0.5f * pFirstLArTPC->GetWidthZ());
49 
50  for (const LArTPCMap::value_type &mapEntry : larTPCMap)
51  {
52  const LArTPC *const pLArTPC(mapEntry.second);
53  parentMinX = std::min(parentMinX, pLArTPC->GetCenterX() - 0.5f * pLArTPC->GetWidthX());
54  parentMaxX = std::max(parentMaxX, pLArTPC->GetCenterX() + 0.5f * pLArTPC->GetWidthX());
55  parentMinY = std::min(parentMinY, pLArTPC->GetCenterY() - 0.5f * pLArTPC->GetWidthY());
56  parentMaxY = std::max(parentMaxY, pLArTPC->GetCenterY() + 0.5f * pLArTPC->GetWidthY());
57  parentMinZ = std::min(parentMinZ, pLArTPC->GetCenterZ() - 0.5f * pLArTPC->GetWidthZ());
58  parentMaxZ = std::max(parentMaxZ, pLArTPC->GetCenterZ() + 0.5f * pLArTPC->GetWidthZ());
59  }
60 
61  try
62  {
63  m_sliceFeatureParameters.Initialize(parentMinX, parentMaxX, parentMinY, parentMaxY, parentMinZ, parentMaxZ);
64  }
65  catch (const StatusCodeException &statusCodeException)
66  {
67  std::cout << "BdtBeamParticleIdTool::Initialize - unable to initialize LArTPC geometry parameters" << std::endl;
68  return STATUS_CODE_FAILURE;
69  }
70 
71  return STATUS_CODE_SUCCESS;
72 }
Int_t max
Definition: plot.C:27
void Initialize(const float larTPCMinX, const float larTPCMaxX, const float larTPCMinY, const float larTPCMaxY, const float larTPCMinZ, const float larTPCMaxZ)
Set LArTPC geometry information.
Int_t min
Definition: plot.C:26
SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.
BdtBeamParticleIdTool& lar_content::BdtBeamParticleIdTool::operator= ( const BdtBeamParticleIdTool rhs)
default

Assignment operator.

Parameters
rhsthe BdtBeamParticleIdTool to assign
bool lar_content::BdtBeamParticleIdTool::PassesQualityCuts ( const float  purity,
const float  completeness 
) const
private

Determine if the event passes the selection cuts for training.

Parameters
puritypurity of best slice
completenesscompleteness of best slice
Returns
does the evenr pass the quality cuts on purity and completeness

Definition at line 283 of file BdtBeamParticleIdTool.cc.

References m_minCompleteness, and m_minPurity.

Referenced by GetBestMCSliceIndices().

284 {
285  if ((purity < m_minPurity) || (completeness < m_minCompleteness)) return false;
286 
287  return true;
288 }
float m_minPurity
Minimum purity of the best slice to use event for training.
float m_minCompleteness
Minimum completeness of the best slice to use event for training.
void lar_content::BdtBeamParticleIdTool::PopulateMCParticleToHitsMap ( MCParticleToIntMap mcParticleToIntMap,
const pandora::CaloHitList &  caloHitList 
) const
private

Fill mc particle to nHits map from calo hit list.

Parameters
mcParticleToIntMapmap to fill
caloHitListthe input calo hits

Definition at line 232 of file BdtBeamParticleIdTool.cc.

References lar_content::LArMCParticleHelper::GetParentMCParticle().

Referenced by GetBestMCSliceIndices().

233 {
234  for (const CaloHit *const pCaloHit : caloHitList)
235  {
236  try
237  {
238  const MCParticle *pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(MCParticleHelper::GetMainMCParticle(pCaloHit)));
239  MCParticleToIntMap::iterator iter(mcParticleToIntMap.find(pParentMCParticle));
240 
241  if (iter != mcParticleToIntMap.end())
242  {
243  (*iter).second += 1;
244  }
245  else
246  {
247  mcParticleToIntMap.insert(MCParticleToIntMap::value_type(pParentMCParticle, 1));
248  }
249  }
250  catch (const StatusCodeException &statusCodeException)
251  {
252  if (STATUS_CODE_NOT_INITIALIZED != statusCodeException.GetStatusCode())
253  throw statusCodeException;
254  }
255  }
256 }
intermediate_table::iterator iterator
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
StatusCode lar_content::BdtBeamParticleIdTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 673 of file BdtBeamParticleIdTool.cc.

References f, lar_content::LArFileHelper::FindFileInPath(), lar_content::AdaBoostDecisionTree::Initialize(), m_adaBoostDecisionTree, m_caloHitListName, m_filePathEnvironmentVariable, m_maxNeutrinos, m_mcParticleListName, m_minAdaBDTScore, m_minCompleteness, m_minPurity, m_sliceFeatureParameters, m_trainingOutputFile, m_useTrainingMode, lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::SetBeamDirection(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::SetBeamLArTPCIntersection(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::SetContainmentLimit(), lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::SetNSelectedHits(), and lar_content::BdtBeamParticleIdTool::SliceFeatureParameters::SetSelectedFraction().

674 {
675  // BDT Settings
676  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
677  "UseTrainingMode", m_useTrainingMode));
678 
679  if (m_useTrainingMode)
680  {
681  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
682  "TrainingOutputFileName", m_trainingOutputFile));
683 
684  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
685  "CaloHitListName", m_caloHitListName));
686 
687  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
688  "MCParticleListName", m_mcParticleListName));
689  }
690  else
691  {
692  std::string bdtName;
693  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
694  "BdtName", bdtName));
695 
696  std::string bdtFileName;
697  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
698  "BdtFileName", bdtFileName));
699 
700  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
701  "MinAdaBDTScore", m_minAdaBDTScore));
702 
703  const std::string fullBdtFileName(LArFileHelper::FindFileInPath(bdtFileName, m_filePathEnvironmentVariable));
704  const StatusCode statusCode(m_adaBoostDecisionTree.Initialize(fullBdtFileName, bdtName));
705 
706  if (STATUS_CODE_SUCCESS != statusCode)
707  {
708  std::cout << "BdtBeamParticleIdTool::ReadSettings - unable to load bdt" << std::endl;
709  return statusCode;
710  }
711  }
712 
713  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
714  "MinimumPurity", m_minPurity));
715 
716  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
717  "MinimumCompleteness", m_minCompleteness));
718 
719  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
720  "FilePathEnvironmentVariable", m_filePathEnvironmentVariable));
721 
722  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
723  "MaximumNeutrinos", m_maxNeutrinos));
724 
725  // Geometry Information for training
726  FloatVector beamLArTPCIntersection;
727  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle,
728  "BeamTPCIntersection", beamLArTPCIntersection));
729 
730  if (3 == beamLArTPCIntersection.size())
731  {
732  pandora::CartesianVector beamLArTPCIntersectionCartesianVector(beamLArTPCIntersection.at(0), beamLArTPCIntersection.at(1), beamLArTPCIntersection.at(2));
733  m_sliceFeatureParameters.SetBeamLArTPCIntersection(beamLArTPCIntersectionCartesianVector);
734  }
735  else if (!beamLArTPCIntersection.empty())
736  {
737  std::cout << "BdtBeamParticleIdTool::ReadSettings - invalid BeamTPCIntersection specified " << std::endl;
738  return STATUS_CODE_INVALID_PARAMETER;
739  }
740  else
741  {
742  // Default for protoDUNE.
743  pandora::CartesianVector beamLArTPCIntersectionCartesianVector(-33.051f, 461.06f, 0.f);
744  m_sliceFeatureParameters.SetBeamLArTPCIntersection(beamLArTPCIntersectionCartesianVector);
745  }
746 
747  FloatVector beamDirection;
748  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle,
749  "BeamDirection", beamDirection));
750 
751  if (3 == beamDirection.size())
752  {
753  CartesianVector beamDirectionCartesianVector(beamDirection.at(0), beamDirection.at(1), beamDirection.at(2));
754  m_sliceFeatureParameters.SetBeamDirection(beamDirectionCartesianVector);
755  }
756  else if (!beamDirection.empty())
757  {
758  std::cout << "BdtBeamParticleIdTool::ReadSettings - invalid BeamDirection specified " << std::endl;
759  return STATUS_CODE_INVALID_PARAMETER;
760  }
761  else
762  {
763  // Default for protoDUNE.
764  const float thetaXZ0(-11.844f * M_PI / 180.f);
765  CartesianVector beamDirectionCartesianVector(std::sin(thetaXZ0), 0.f, std::cos(thetaXZ0));
766  m_sliceFeatureParameters.SetBeamDirection(beamDirectionCartesianVector);
767  }
768 
769  float selectedFraction(0.f);
770 
771  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
772  "SelectedFraction", selectedFraction));
773 
774  if (selectedFraction > std::numeric_limits<float>::epsilon())
776 
777  unsigned int nSelectedHits(0);
778 
779  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
780  "NSelectedHits", nSelectedHits));
781 
782  if (nSelectedHits > 0)
784 
785  float containmentLimit(0.f);
786 
787  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
788  "ContainmentLimit", containmentLimit));
789 
790  if (containmentLimit < 0.f)
791  {
792  std::cout << "BdtBeamParticleIdTool::ReadSettings - invalid ContainmentLimit specified " << std::endl;
793  return STATUS_CODE_INVALID_PARAMETER;
794  }
795  else if (containmentLimit > 0.f)
796  {
798  }
799 
800  return STATUS_CODE_SUCCESS;
801 }
void SetBeamLArTPCIntersection(const pandora::CartesianVector &beamLArTPCIntersection)
Set m_beamLArTPCIntersection.
std::string m_filePathEnvironmentVariable
The environment variable providing a list of paths to bdt files.
std::string m_mcParticleListName
Name of input MC particle list.
float m_minAdaBDTScore
Minimum score required to classify a slice as a beam particle.
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...
TFile f
Definition: plotHisto.C:6
void SetBeamDirection(const pandora::CartesianVector &beamDirection)
Set m_beamDirection.
void SetNSelectedHits(const unsigned int nSelectedHits)
Set m_nSelectedHits.
std::string m_trainingOutputFile
Output file name for training examples.
void SetSelectedFraction(const float selectedFraction)
Set m_selectedFraction.
float m_minPurity
Minimum purity of the best slice to use event for training.
float m_minCompleteness
Minimum completeness 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...
void SetContainmentLimit(const float containmentLimit)
Set m_containmentLimit.
pandora::StatusCode Initialize(const std::string &parameterLocation, const std::string &bdtName)
Initialize the bdt model.
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
std::string m_caloHitListName
Name of input calo hit list.
AdaBoostDecisionTree m_adaBoostDecisionTree
The adaptive boost decision tree.
SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.
void lar_content::BdtBeamParticleIdTool::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 135 of file BdtBeamParticleIdTool.cc.

References SelectPfos().

Referenced by SelectOutputPfos().

136 {
137  for (const PfoList &pfos : hypotheses)
138  {
139  for (const ParticleFlowObject *const pPfo : pfos)
140  {
141  object_creation::ParticleFlowObject::Metadata metadata;
142  metadata.m_propertiesToAdd["TestBeamScore"] = -1.f;
143  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
144  }
145 
146  this->SelectPfos(pfos, selectedPfos);
147  }
148 }
void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
Add the given pfos to the selected Pfo list.
void lar_content::BdtBeamParticleIdTool::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 76 of file BdtBeamParticleIdTool.cc.

References lar_content::BdtBeamParticleIdTool::SliceFeatures::FillFeatureVector(), GetBestMCSliceIndices(), GetSliceFeatures(), m_trainingOutputFile, m_useTrainingMode, lar_content::LArMvaHelper::ProduceTrainingExample(), SelectAllPfos(), and SelectPfosByAdaBDTScore().

77 {
78  if (nuSliceHypotheses.size() != crSliceHypotheses.size())
79  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
80 
81  const unsigned int nSlices(nuSliceHypotheses.size());
82  if (nSlices == 0) return;
83 
84  SliceFeaturesVector sliceFeaturesVector;
85  this->GetSliceFeatures(this, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector);
86 
88  {
89  // ATTN in training mode, just return everything as a cosmic-ray
90  this->SelectAllPfos(pAlgorithm, crSliceHypotheses, selectedPfos);
91 
92  pandora::IntVector bestSliceIndices;
93  this->GetBestMCSliceIndices(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, bestSliceIndices);
94 
95  for (unsigned int sliceIndex = 0; sliceIndex < nSlices; ++sliceIndex)
96  {
97  const SliceFeatures &features(sliceFeaturesVector.at(sliceIndex));
98  if (!features.IsFeatureVectorAvailable()) continue;
99 
100  LArMvaHelper::MvaFeatureVector featureVector;
101 
102  try
103  {
104  features.FillFeatureVector(featureVector);
105  }
106  catch (const StatusCodeException &statusCodeException)
107  {
108  std::cout << "BdtBeamParticleIdTool::SelectOutputPfos - unable to fill feature vector" << std::endl;
109  continue;
110  }
111 
112  bool isGoodTrainingSlice(false);
113  if (std::find(bestSliceIndices.begin(), bestSliceIndices.end(), sliceIndex) != bestSliceIndices.end())
114  isGoodTrainingSlice = true;
115 
116  LArMvaHelper::ProduceTrainingExample(m_trainingOutputFile, isGoodTrainingSlice, featureVector);
117  }
118 
119  return;
120  }
121 
122  this->SelectPfosByAdaBDTScore(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector, selectedPfos);
123 }
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:58
bool m_useTrainingMode
Should use training mode. If true, training examples will be written to the output file...
void SelectPfosByAdaBDTScore(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, const SliceFeaturesVector &sliceFeaturesVector, pandora::PfoList &selectedPfos) const
Select pfos based on the AdaBDT score that the slice contains a beam particle interaction.
std::vector< SliceFeatures > SliceFeaturesVector
void SelectAllPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &hypotheses, pandora::PfoList &selectedPfos) const
Select all pfos under the same hypothesis.
std::vector< int > IntVector
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
std::string m_trainingOutputFile
Output file name for training examples.
void GetBestMCSliceIndices(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, pandora::IntVector &bestSliceIndices) const
Get the slice with the most neutrino induced hits using Monte-Carlo information.
void GetSliceFeatures(const BdtBeamParticleIdTool *const pTool, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const
Get the features of each slice.
void lar_content::BdtBeamParticleIdTool::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 152 of file BdtBeamParticleIdTool.cc.

Referenced by SelectAllPfos(), and SelectPfosByAdaBDTScore().

153 {
154  selectedPfos.insert(selectedPfos.end(), pfos.begin(), pfos.end());
155 }
void lar_content::BdtBeamParticleIdTool::SelectPfosByAdaBDTScore ( const pandora::Algorithm *const  pAlgorithm,
const SliceHypotheses nuSliceHypotheses,
const SliceHypotheses crSliceHypotheses,
const SliceFeaturesVector sliceFeaturesVector,
pandora::PfoList &  selectedPfos 
) const
private

Select pfos based on the AdaBDT score that the slice contains a beam particle 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 292 of file BdtBeamParticleIdTool.cc.

References m_adaBoostDecisionTree, m_maxNeutrinos, m_minAdaBDTScore, and SelectPfos().

Referenced by SelectOutputPfos().

293 {
294  // Calculate the probability of each slice that passes the minimum probability cut
295  std::vector<UintFloatPair> sliceIndexAdaBDTScorePairs;
296  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
297  {
298  const float nuAdaBDTScore(sliceFeaturesVector.at(sliceIndex).GetAdaBoostDecisionTreeScore(m_adaBoostDecisionTree));
299 
300  for (const ParticleFlowObject *const pPfo : crSliceHypotheses.at(sliceIndex))
301  {
302  object_creation::ParticleFlowObject::Metadata metadata;
303  metadata.m_propertiesToAdd["TestBeamScore"] = nuAdaBDTScore;
304  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
305  }
306 
307  for (const ParticleFlowObject *const pPfo : nuSliceHypotheses.at(sliceIndex))
308  {
309  object_creation::ParticleFlowObject::Metadata metadata;
310  metadata.m_propertiesToAdd["TestBeamScore"] = nuAdaBDTScore;
311  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
312  }
313 
314  if (nuAdaBDTScore < m_minAdaBDTScore)
315  {
316  this->SelectPfos(crSliceHypotheses.at(sliceIndex), selectedPfos);
317  continue;
318  }
319 
320  sliceIndexAdaBDTScorePairs.push_back(UintFloatPair(sliceIndex, nuAdaBDTScore));
321  }
322 
323  // Sort the slices by probability
324  std::sort(sliceIndexAdaBDTScorePairs.begin(), sliceIndexAdaBDTScorePairs.end(), [] (const UintFloatPair &a, const UintFloatPair &b)
325  {
326  return (a.second > b.second);
327  });
328 
329  // Select the first m_maxNeutrinos as neutrinos, and the rest as cosmic
330  unsigned int nNuSlices(0);
331  for (const UintFloatPair &slice : sliceIndexAdaBDTScorePairs)
332  {
333  if (nNuSlices < m_maxNeutrinos)
334  {
335  this->SelectPfos(nuSliceHypotheses.at(slice.first), selectedPfos);
336  nNuSlices++;
337  continue;
338  }
339 
340  this->SelectPfos(crSliceHypotheses.at(slice.first), selectedPfos);
341  }
342 }
float m_minAdaBDTScore
Minimum score required to classify a slice as a beam particle.
void SelectPfos(const pandora::PfoList &pfos, pandora::PfoList &selectedPfos) const
Add the given pfos to the selected Pfo list.
unsigned int m_maxNeutrinos
The maximum number of neutrinos to select in any one event.
std::pair< unsigned int, float > UintFloatPair
AdaBoostDecisionTree m_adaBoostDecisionTree
The adaptive boost decision tree.

Member Data Documentation

AdaBoostDecisionTree lar_content::BdtBeamParticleIdTool::m_adaBoostDecisionTree
private

The adaptive boost decision tree.

Definition at line 401 of file BdtBeamParticleIdTool.h.

Referenced by ReadSettings(), and SelectPfosByAdaBDTScore().

std::string lar_content::BdtBeamParticleIdTool::m_caloHitListName
private

Name of input calo hit list.

Definition at line 395 of file BdtBeamParticleIdTool.h.

Referenced by GetBestMCSliceIndices(), and ReadSettings().

std::string lar_content::BdtBeamParticleIdTool::m_filePathEnvironmentVariable
private

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

Definition at line 402 of file BdtBeamParticleIdTool.h.

Referenced by ReadSettings().

unsigned int lar_content::BdtBeamParticleIdTool::m_maxNeutrinos
private

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

Definition at line 403 of file BdtBeamParticleIdTool.h.

Referenced by ReadSettings(), and SelectPfosByAdaBDTScore().

std::string lar_content::BdtBeamParticleIdTool::m_mcParticleListName
private

Name of input MC particle list.

Definition at line 396 of file BdtBeamParticleIdTool.h.

Referenced by GetBestMCSliceIndices(), and ReadSettings().

float lar_content::BdtBeamParticleIdTool::m_minAdaBDTScore
private

Minimum score required to classify a slice as a beam particle.

Definition at line 404 of file BdtBeamParticleIdTool.h.

Referenced by ReadSettings(), and SelectPfosByAdaBDTScore().

float lar_content::BdtBeamParticleIdTool::m_minCompleteness
private

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

Definition at line 398 of file BdtBeamParticleIdTool.h.

Referenced by PassesQualityCuts(), and ReadSettings().

float lar_content::BdtBeamParticleIdTool::m_minPurity
private

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

Definition at line 397 of file BdtBeamParticleIdTool.h.

Referenced by PassesQualityCuts(), and ReadSettings().

std::string lar_content::BdtBeamParticleIdTool::m_trainingOutputFile
private

Output file name for training examples.

Definition at line 394 of file BdtBeamParticleIdTool.h.

Referenced by ReadSettings(), and SelectOutputPfos().

bool lar_content::BdtBeamParticleIdTool::m_useTrainingMode
private

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

Definition at line 393 of file BdtBeamParticleIdTool.h.

Referenced by ReadSettings(), and SelectOutputPfos().


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