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::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 &)=default
 Copy constructor. More...
 
BdtBeamParticleIdTooloperator= (const BdtBeamParticleIdTool &)=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
< SliceFeatures
SliceFeaturesVector
 
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 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 304 of file BdtBeamParticleIdTool.h.

Definition at line 82 of file BdtBeamParticleIdTool.h.

Definition at line 302 of file BdtBeamParticleIdTool.h.

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

Definition at line 303 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"),
30  m_maxNeutrinos(std::numeric_limits<int>::max()),
31  m_minAdaBDTScore(0.f),
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...
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 )
default

Copy constructor.

Parameters
BdtBeamParticleIdToolto 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 266 of file BdtBeamParticleIdTool.cc.

267 {
268  CaloHitList collectedHits;
269  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_U, collectedHits);
270  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_V, collectedHits);
271  LArPfoHelper::GetCaloHits(pfos, TPC_VIEW_W, collectedHits);
272 
273  for (const CaloHit *const pCaloHit : collectedHits)
274  {
275  // ATTN hits collected from Pfos are copies of hits passed from master instance, we need to access their parent to use MC info
276  const CaloHit *pParentCaloHit(static_cast<const CaloHit *>(pCaloHit->GetParentAddress()));
277 
278  if (!reconstructableCaloHitSet.count(pParentCaloHit))
279  continue;
280 
281  // Ensure no hits have been double counted
282  if (std::find(reconstructedCaloHitList.begin(), reconstructedCaloHitList.end(), pParentCaloHit) == reconstructedCaloHitList.end())
283  reconstructedCaloHitList.push_back(pParentCaloHit);
284  }
285 }
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 163 of file BdtBeamParticleIdTool.cc.

165 {
166  // Get all hits in all slices to find true number of mc hits
167  const CaloHitList *pAllReconstructedCaloHitList(nullptr);
168  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*pAlgorithm, m_caloHitListName, pAllReconstructedCaloHitList));
169 
170  const MCParticleList *pMCParticleList(nullptr);
171  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*pAlgorithm, m_mcParticleListName, pMCParticleList));
172 
173  // Obtain map: [mc particle -> primary mc particle]
174  LArMCParticleHelper::MCRelationMap mcToPrimaryMCMap;
175  LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcToPrimaryMCMap);
176 
177  // Remove non-reconstructable hits, e.g. those downstream of a neutron
178  CaloHitList reconstructableCaloHitList;
179  LArMCParticleHelper::PrimaryParameters parameters;
180  LArMCParticleHelper::SelectCaloHits(pAllReconstructedCaloHitList, mcToPrimaryMCMap, reconstructableCaloHitList,
181  parameters.m_selectInputHits, parameters.m_maxPhotonPropagation);
182 
183  MCParticleToIntMap mcParticleToReconstructableHitsMap;
184  this->PopulateMCParticleToHitsMap(mcParticleToReconstructableHitsMap, reconstructableCaloHitList);
185 
186  const CaloHitSet reconstructableCaloHitSet(reconstructableCaloHitList.begin(), reconstructableCaloHitList.end());
187 
188  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
189  {
190  // All hits in a slice - No double counting
191  CaloHitList reconstructedCaloHitList;
192  this->Collect2DHits(crSliceHypotheses.at(sliceIndex), reconstructedCaloHitList, reconstructableCaloHitSet);
193 
194  if (nuSliceHypotheses.at(sliceIndex).size() == 1)
195  {
196  const PfoList &nuFinalStates(nuSliceHypotheses.at(sliceIndex).front()->GetDaughterPfoList());
197  this->Collect2DHits(nuFinalStates, reconstructedCaloHitList, reconstructableCaloHitSet);
198  }
199 
200  const unsigned int nRecoHits(reconstructedCaloHitList.size());
201 
202  // MCParticle to hits in slice map
203  MCParticleToIntMap mcParticleToHitsInSliceMap;
204  this->PopulateMCParticleToHitsMap(mcParticleToHitsInSliceMap, reconstructedCaloHitList);
205 
206  if (mcParticleToHitsInSliceMap.empty())
207  continue;
208 
209  // Get best mc particle for slice
210  const MCParticle *pBestMCParticle(nullptr);
211  unsigned int nSharedHits(0);
212 
213  for (const auto &iter : mcParticleToHitsInSliceMap)
214  {
215  if (iter.second > static_cast<int>(nSharedHits))
216  {
217  pBestMCParticle = iter.first;
218  nSharedHits = iter.second;
219  }
220  }
221 
222  // Only consider if target beam particles
223  if (2001 != LArMCParticleHelper::GetNuanceCode(pBestMCParticle))
224  continue;
225 
226  const unsigned int nMCHits(mcParticleToReconstructableHitsMap.at(pBestMCParticle));
227  const float purity(nRecoHits > 0 ? static_cast<float>(nSharedHits) / static_cast<float>(nRecoHits) : 0.f);
228  const float completeness(nMCHits > 0 ? static_cast<float>(nSharedHits) / static_cast<float>(nMCHits) : 0.f);
229 
230  if (this->PassesQualityCuts(purity, completeness))
231  bestSliceIndices.push_back(sliceIndex);
232  }
233  return;
234 }
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.
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
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...
void lar_content::BdtBeamParticleIdTool::GetSliceFeatures ( const SliceHypotheses nuSliceHypotheses,
const SliceHypotheses crSliceHypotheses,
SliceFeaturesVector sliceFeaturesVector 
) const
private

Get the features of each slice.

Parameters
nuSliceHypothesesthe input neutrino slice hypotheses
crSliceHypothesesthe input cosmic slice hypotheses
sliceFeaturesVectorvector to hold the slice features

Definition at line 130 of file BdtBeamParticleIdTool.cc.

132 {
133  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
134  sliceFeaturesVector.push_back(SliceFeatures(nuSliceHypotheses.at(sliceIndex), crSliceHypotheses.at(sliceIndex), m_sliceFeatureParameters));
135 }
SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.
StatusCode lar_content::BdtBeamParticleIdTool::Initialize ( )
private

Definition at line 38 of file BdtBeamParticleIdTool.cc.

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 }
void Initialize(const float larTPCMinX, const float larTPCMaxX, const float larTPCMinY, const float larTPCMaxY, const float larTPCMinZ, const float larTPCMaxZ)
Set LArTPC geometry information.
BEGIN_PROLOG could also be cout
SliceFeatureParameters m_sliceFeatureParameters
Geometry information block.
BdtBeamParticleIdTool& lar_content::BdtBeamParticleIdTool::operator= ( const BdtBeamParticleIdTool )
default

Assignment operator.

Parameters
TheBdtBeamParticleIdTool 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 289 of file BdtBeamParticleIdTool.cc.

290 {
291  if ((purity < m_minPurity) || (completeness < m_minCompleteness))
292  return false;
293 
294  return true;
295 }
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 238 of file BdtBeamParticleIdTool.cc.

239 {
240  for (const CaloHit *const pCaloHit : caloHitList)
241  {
242  try
243  {
244  const MCParticle *pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(MCParticleHelper::GetMainMCParticle(pCaloHit)));
245  MCParticleToIntMap::iterator iter(mcParticleToIntMap.find(pParentMCParticle));
246 
247  if (iter != mcParticleToIntMap.end())
248  {
249  (*iter).second += 1;
250  }
251  else
252  {
253  mcParticleToIntMap.insert(MCParticleToIntMap::value_type(pParentMCParticle, 1));
254  }
255  }
256  catch (const StatusCodeException &statusCodeException)
257  {
258  if (STATUS_CODE_NOT_INITIALIZED != statusCodeException.GetStatusCode())
259  throw statusCodeException;
260  }
261  }
262 }
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 692 of file BdtBeamParticleIdTool.cc.

693 {
694  // BDT Settings
695  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "UseTrainingMode", m_useTrainingMode));
696 
697  if (m_useTrainingMode)
698  {
699  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "TrainingOutputFileName", m_trainingOutputFile));
700 
701  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "CaloHitListName", m_caloHitListName));
702 
703  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MCParticleListName", m_mcParticleListName));
704  }
705  else
706  {
707  std::string bdtName;
708  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "BdtName", bdtName));
709 
710  std::string bdtFileName;
711  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "BdtFileName", bdtFileName));
712 
713  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MinAdaBDTScore", m_minAdaBDTScore));
714 
715  const std::string fullBdtFileName(LArFileHelper::FindFileInPath(bdtFileName, m_filePathEnvironmentVariable));
716  const StatusCode statusCode(m_adaBoostDecisionTree.Initialize(fullBdtFileName, bdtName));
717 
718  if (STATUS_CODE_SUCCESS != statusCode)
719  {
720  std::cout << "BdtBeamParticleIdTool::ReadSettings - unable to load bdt" << std::endl;
721  return statusCode;
722  }
723  }
724 
725  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumPurity", m_minPurity));
726 
727  PANDORA_RETURN_RESULT_IF_AND_IF(
728  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumCompleteness", m_minCompleteness));
729 
730  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
731  XmlHelper::ReadValue(xmlHandle, "FilePathEnvironmentVariable", m_filePathEnvironmentVariable));
732 
733  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaximumNeutrinos", m_maxNeutrinos));
734 
735  // Geometry Information for training
736  FloatVector beamLArTPCIntersection;
737  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
738  XmlHelper::ReadVectorOfValues(xmlHandle, "BeamTPCIntersection", beamLArTPCIntersection));
739 
740  if (3 == beamLArTPCIntersection.size())
741  {
742  pandora::CartesianVector beamLArTPCIntersectionCartesianVector(
743  beamLArTPCIntersection.at(0), beamLArTPCIntersection.at(1), beamLArTPCIntersection.at(2));
744  m_sliceFeatureParameters.SetBeamLArTPCIntersection(beamLArTPCIntersectionCartesianVector);
745  }
746  else if (!beamLArTPCIntersection.empty())
747  {
748  std::cout << "BdtBeamParticleIdTool::ReadSettings - invalid BeamTPCIntersection specified " << std::endl;
749  return STATUS_CODE_INVALID_PARAMETER;
750  }
751  else
752  {
753  // Default for protoDUNE.
754  pandora::CartesianVector beamLArTPCIntersectionCartesianVector(-33.051f, 461.06f, 0.f);
755  m_sliceFeatureParameters.SetBeamLArTPCIntersection(beamLArTPCIntersectionCartesianVector);
756  }
757 
758  FloatVector beamDirection;
759  PANDORA_RETURN_RESULT_IF_AND_IF(
760  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "BeamDirection", beamDirection));
761 
762  if (3 == beamDirection.size())
763  {
764  CartesianVector beamDirectionCartesianVector(beamDirection.at(0), beamDirection.at(1), beamDirection.at(2));
765  m_sliceFeatureParameters.SetBeamDirection(beamDirectionCartesianVector);
766  }
767  else if (!beamDirection.empty())
768  {
769  std::cout << "BdtBeamParticleIdTool::ReadSettings - invalid BeamDirection specified " << std::endl;
770  return STATUS_CODE_INVALID_PARAMETER;
771  }
772  else
773  {
774  // Default for protoDUNE.
775  const float thetaXZ0(-11.844f * M_PI / 180.f);
776  CartesianVector beamDirectionCartesianVector(std::sin(thetaXZ0), 0.f, std::cos(thetaXZ0));
777  m_sliceFeatureParameters.SetBeamDirection(beamDirectionCartesianVector);
778  }
779 
780  float selectedFraction(0.f);
781 
782  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SelectedFraction", selectedFraction));
783 
784  if (selectedFraction > std::numeric_limits<float>::epsilon())
786 
787  unsigned int nSelectedHits(0);
788 
789  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "NSelectedHits", nSelectedHits));
790 
791  if (nSelectedHits > 0)
793 
794  float containmentLimit(0.f);
795 
796  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "ContainmentLimit", containmentLimit));
797 
798  if (containmentLimit < 0.f)
799  {
800  std::cout << "BdtBeamParticleIdTool::ReadSettings - invalid ContainmentLimit specified " << std::endl;
801  return STATUS_CODE_INVALID_PARAMETER;
802  }
803  else if (containmentLimit > 0.f)
804  {
806  }
807 
808  return STATUS_CODE_SUCCESS;
809 }
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...
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.
BEGIN_PROLOG could also be cout
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 139 of file BdtBeamParticleIdTool.cc.

140 {
141  for (const PfoList &pfos : hypotheses)
142  {
143  for (const ParticleFlowObject *const pPfo : pfos)
144  {
145  object_creation::ParticleFlowObject::Metadata metadata;
146  metadata.m_propertiesToAdd["TestBeamScore"] = -1.f;
147  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
148  }
149 
150  this->SelectPfos(pfos, selectedPfos);
151  }
152 }
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.

78 {
79  if (nuSliceHypotheses.size() != crSliceHypotheses.size())
80  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
81 
82  const unsigned int nSlices(nuSliceHypotheses.size());
83  if (nSlices == 0)
84  return;
85 
86  SliceFeaturesVector sliceFeaturesVector;
87  this->GetSliceFeatures(nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector);
88 
90  {
91  // ATTN in training mode, just return everything as a cosmic-ray
92  this->SelectAllPfos(pAlgorithm, crSliceHypotheses, selectedPfos);
93 
94  pandora::IntVector bestSliceIndices;
95  this->GetBestMCSliceIndices(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, bestSliceIndices);
96 
97  for (unsigned int sliceIndex = 0; sliceIndex < nSlices; ++sliceIndex)
98  {
99  const SliceFeatures &features(sliceFeaturesVector.at(sliceIndex));
100  if (!features.IsFeatureVectorAvailable())
101  continue;
102 
103  LArMvaHelper::MvaFeatureVector featureVector;
104 
105  try
106  {
107  features.FillFeatureVector(featureVector);
108  }
109  catch (const StatusCodeException &statusCodeException)
110  {
111  std::cout << "BdtBeamParticleIdTool::SelectOutputPfos - unable to fill feature vector" << std::endl;
112  continue;
113  }
114 
115  bool isGoodTrainingSlice(false);
116  if (std::find(bestSliceIndices.begin(), bestSliceIndices.end(), sliceIndex) != bestSliceIndices.end())
117  isGoodTrainingSlice = true;
118 
119  LArMvaHelper::ProduceTrainingExample(m_trainingOutputFile, isGoodTrainingSlice, featureVector);
120  }
121 
122  return;
123  }
124 
125  this->SelectPfosByAdaBDTScore(pAlgorithm, nuSliceHypotheses, crSliceHypotheses, sliceFeaturesVector, selectedPfos);
126 }
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:72
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
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
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 SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, SliceFeaturesVector &sliceFeaturesVector) const
Get the features of each slice.
BEGIN_PROLOG could also be cout
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 156 of file BdtBeamParticleIdTool.cc.

157 {
158  selectedPfos.insert(selectedPfos.end(), pfos.begin(), pfos.end());
159 }
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 299 of file BdtBeamParticleIdTool.cc.

301 {
302  // Calculate the probability of each slice that passes the minimum probability cut
303  std::vector<UintFloatPair> sliceIndexAdaBDTScorePairs;
304  for (unsigned int sliceIndex = 0, nSlices = nuSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
305  {
306  const float nuAdaBDTScore(sliceFeaturesVector.at(sliceIndex).GetAdaBoostDecisionTreeScore(m_adaBoostDecisionTree));
307 
308  for (const ParticleFlowObject *const pPfo : crSliceHypotheses.at(sliceIndex))
309  {
310  object_creation::ParticleFlowObject::Metadata metadata;
311  metadata.m_propertiesToAdd["TestBeamScore"] = nuAdaBDTScore;
312  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
313  }
314 
315  for (const ParticleFlowObject *const pPfo : nuSliceHypotheses.at(sliceIndex))
316  {
317  object_creation::ParticleFlowObject::Metadata metadata;
318  metadata.m_propertiesToAdd["TestBeamScore"] = nuAdaBDTScore;
319  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*pAlgorithm, pPfo, metadata));
320  }
321 
322  if (nuAdaBDTScore < m_minAdaBDTScore)
323  {
324  this->SelectPfos(crSliceHypotheses.at(sliceIndex), selectedPfos);
325  continue;
326  }
327 
328  sliceIndexAdaBDTScorePairs.push_back(UintFloatPair(sliceIndex, nuAdaBDTScore));
329  }
330 
331  // Sort the slices by probability
332  std::sort(sliceIndexAdaBDTScorePairs.begin(), sliceIndexAdaBDTScorePairs.end(),
333  [](const UintFloatPair &a, const UintFloatPair &b) { return (a.second > b.second); });
334 
335  // Select the first m_maxNeutrinos as neutrinos, and the rest as cosmic
336  unsigned int nNuSlices(0);
337  for (const UintFloatPair &slice : sliceIndexAdaBDTScorePairs)
338  {
339  if (nNuSlices < m_maxNeutrinos)
340  {
341  this->SelectPfos(nuSliceHypotheses.at(slice.first), selectedPfos);
342  nNuSlices++;
343  continue;
344  }
345 
346  this->SelectPfos(crSliceHypotheses.at(slice.first), selectedPfos);
347  }
348 }
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.
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
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 396 of file BdtBeamParticleIdTool.h.

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

Name of input calo hit list.

Definition at line 390 of file BdtBeamParticleIdTool.h.

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

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

Definition at line 397 of file BdtBeamParticleIdTool.h.

unsigned int lar_content::BdtBeamParticleIdTool::m_maxNeutrinos
private

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

Definition at line 398 of file BdtBeamParticleIdTool.h.

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

Name of input MC particle list.

Definition at line 391 of file BdtBeamParticleIdTool.h.

float lar_content::BdtBeamParticleIdTool::m_minAdaBDTScore
private

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

Definition at line 399 of file BdtBeamParticleIdTool.h.

float lar_content::BdtBeamParticleIdTool::m_minCompleteness
private

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

Definition at line 393 of file BdtBeamParticleIdTool.h.

float lar_content::BdtBeamParticleIdTool::m_minPurity
private

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

Definition at line 392 of file BdtBeamParticleIdTool.h.

SliceFeatureParameters lar_content::BdtBeamParticleIdTool::m_sliceFeatureParameters
private

Geometry information block.

Definition at line 400 of file BdtBeamParticleIdTool.h.

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

Output file name for training examples.

Definition at line 389 of file BdtBeamParticleIdTool.h.

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 388 of file BdtBeamParticleIdTool.h.


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