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

StitchingCosmicRayMergingTool class. More...

#include "StitchingCosmicRayMergingTool.h"

Inheritance diagram for lar_content::StitchingCosmicRayMergingTool:
lar_content::StitchingBaseTool

Classes

class  PfoAssociation
 PfoAssociation class. More...
 

Public Member Functions

 StitchingCosmicRayMergingTool ()
 Default constructor. More...
 
void Run (const MasterAlgorithm *const pAlgorithm, const pandora::PfoList *const pMultiPfoList, PfoToLArTPCMap &pfoToLArTPCMap, PfoToFloatMap &stitchedPfosToX0Map)
 Run the algorithm tool. More...
 

Private Types

typedef std::unordered_map< const pandora::ParticleFlowObject *, LArPointingClusterThreeDPointingClusterMap
 
typedef std::unordered_map< const pandora::LArTPC *, pandora::PfoList > LArTPCToPfoMap
 
typedef std::unordered_map< const pandora::ParticleFlowObject *, PfoAssociationPfoAssociationMap
 
typedef std::unordered_map< const pandora::ParticleFlowObject *, PfoAssociationMapPfoAssociationMatrix
 
typedef std::unordered_map< const pandora::ParticleFlowObject *, pandora::PfoList > PfoMergeMap
 

Private Member Functions

pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
void SelectPrimaryPfos (const pandora::PfoList *pInputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, pandora::PfoList &outputPfoList) const
 Select primary Pfos from the input list of Pfos. More...
 
void BuildPointingClusterMaps (const pandora::PfoList &inputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, ThreeDPointingClusterMap &pointingClusterMap) const
 Build a 3D pointing cluster for each Pfo. More...
 
void BuildTPCMaps (const pandora::PfoList &inputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, LArTPCToPfoMap &larTPCToPfoMap) const
 Build a list of Pfos for each tpc. More...
 
void CreatePfoMatches (const LArTPCToPfoMap &larTPCToPfoMap, const ThreeDPointingClusterMap &pointingClusterMap, PfoAssociationMatrix &pfoAssociationMatrix) const
 Create associations between Pfos using 3D pointing clusters. More...
 
void CreatePfoMatches (const pandora::LArTPC &larTPC1, const pandora::LArTPC &larTPC2, const pandora::ParticleFlowObject *const pPfo1, const pandora::ParticleFlowObject *const pPfo2, const ThreeDPointingClusterMap &pointingClusterMap, PfoAssociationMatrix &pfoAssociationMatrix) const
 Create associations between Pfos using 3D pointing clusters. More...
 
void SelectPfoMatches (const PfoAssociationMatrix &pfoAssociationMatrix, PfoMergeMap &pfoSelectedMatches) const
 Select the best associations between Pfos; create a mapping between associated Pfos, handling any ambiguities. More...
 
void SelectPfoMerges (const PfoMergeMap &pfoMatches, PfoMergeMap &pfoMerges) const
 Create an initial map of Pfo merges to be made. More...
 
void CollectAssociatedPfos (const pandora::ParticleFlowObject *const pSeedPfo, const pandora::ParticleFlowObject *const pCurrentPfo, const PfoMergeMap &pfoMerges, const pandora::PfoSet &vetoSet, pandora::PfoList &associatedList) const
 Collect up associations between Pfos. More...
 
void OrderPfoMerges (const PfoToLArTPCMap &pfoToLArTPCMap, const ThreeDPointingClusterMap &pointingClusterMap, const PfoMergeMap &inputPfoMerges, PfoMergeMap &outputPfoMerges) const
 Identify the vertex Pfo and then re-order the map of merges so that the vertex Pfo will be enlarged. More...
 
void StitchPfos (const MasterAlgorithm *const pAlgorithm, const ThreeDPointingClusterMap &pointingClusterMap, const PfoMergeMap &pfoMerges, PfoToLArTPCMap &pfoToLArTPCMap, PfoToFloatMap &stitchedPfosToX0Map) const
 Apply X0 corrections, and then stitch together Pfos. More...
 
void CalculateX0 (const PfoToLArTPCMap &pfoToLArTPCMap, const ThreeDPointingClusterMap &pointingClusterMap, const pandora::PfoVector &pfoVector, float &x0) const
 Calculate x0 shift for a group of associated Pfos. More...
 

Private Attributes

bool m_useXcoordinate
 
int m_halfWindowLayers
 
float m_minLengthSquared
 
float m_minCosRelativeAngle
 
float m_maxLongitudinalDisplacementX
 
float m_maxTransverseDisplacement
 
float m_relaxCosRelativeAngle
 
float m_relaxTransverseDisplacement
 

Detailed Description

Member Typedef Documentation

typedef std::unordered_map<const pandora::LArTPC*, pandora::PfoList> lar_content::StitchingCosmicRayMergingTool::LArTPCToPfoMap
private

Definition at line 109 of file StitchingCosmicRayMergingTool.h.

typedef std::unordered_map<const pandora::ParticleFlowObject*, PfoAssociation> lar_content::StitchingCosmicRayMergingTool::PfoAssociationMap
private

Definition at line 120 of file StitchingCosmicRayMergingTool.h.

typedef std::unordered_map<const pandora::ParticleFlowObject*, PfoAssociationMap> lar_content::StitchingCosmicRayMergingTool::PfoAssociationMatrix
private

Definition at line 121 of file StitchingCosmicRayMergingTool.h.

typedef std::unordered_map<const pandora::ParticleFlowObject*, pandora::PfoList> lar_content::StitchingCosmicRayMergingTool::PfoMergeMap
private

Definition at line 146 of file StitchingCosmicRayMergingTool.h.

typedef std::unordered_map<const pandora::ParticleFlowObject*, LArPointingCluster> lar_content::StitchingCosmicRayMergingTool::ThreeDPointingClusterMap
private

Definition at line 98 of file StitchingCosmicRayMergingTool.h.

Constructor & Destructor Documentation

lar_content::StitchingCosmicRayMergingTool::StitchingCosmicRayMergingTool ( )

Default constructor.

Definition at line 24 of file StitchingCosmicRayMergingTool.cc.

Member Function Documentation

void lar_content::StitchingCosmicRayMergingTool::BuildPointingClusterMaps ( const pandora::PfoList &  inputPfoList,
const PfoToLArTPCMap pfoToLArTPCMap,
ThreeDPointingClusterMap pointingClusterMap 
) const
private

Build a 3D pointing cluster for each Pfo.

Parameters
inputPfoListthe input list of Pfos
pfoToLArTPCMapthe input mapping between Pfos and tpc
pointingClusterMapthe mapping between Pfos and their corresponding 3D pointing clusters

Definition at line 93 of file StitchingCosmicRayMergingTool.cc.

References lar_content::LArPfoHelper::GetThreeDClusterList(), and m_halfWindowLayers.

Referenced by Run().

94 {
95  for (const ParticleFlowObject *const pPfo : inputPfoList)
96  {
97  try
98  {
99  PfoToLArTPCMap::const_iterator tpcIter(pfoToLArTPCMap.find(pPfo));
100 
101  if (pfoToLArTPCMap.end() == tpcIter)
102  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
103 
104  const float slidingFitPitch(tpcIter->second->GetWirePitchW());
105 
106  ClusterList clusterList;
107  LArPfoHelper::GetThreeDClusterList(pPfo, clusterList);
108 
109  if (1 != clusterList.size())
110  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
111 
112  const ThreeDSlidingFitResult slidingFitResult(clusterList.front(), m_halfWindowLayers, slidingFitPitch);
113  (void) pointingClusterMap.insert(ThreeDPointingClusterMap::value_type(pPfo, LArPointingCluster(slidingFitResult)));
114  }
115  catch (const StatusCodeException &) {}
116  }
117 }
intermediate_table::const_iterator const_iterator
static void GetThreeDClusterList(const pandora::ParticleFlowObject *const pPfo, pandora::ClusterList &clusterList)
Get the list of 3D clusters from an input pfo.
void lar_content::StitchingCosmicRayMergingTool::BuildTPCMaps ( const pandora::PfoList &  inputPfoList,
const PfoToLArTPCMap pfoToLArTPCMap,
LArTPCToPfoMap larTPCToPfoMap 
) const
private

Build a list of Pfos for each tpc.

Parameters
inputPfoListthe input list of Pfos
pfoToLArTPCMapthe input mapping between Pfos and tpc
larTPCToPfoMapthe output mapping between tpc and Pfos

Definition at line 121 of file StitchingCosmicRayMergingTool.cc.

Referenced by Run().

122 {
123  for (const ParticleFlowObject *const pPfo : inputPfoList)
124  {
125  PfoToLArTPCMap::const_iterator iter(pfoToLArTPCMap.find(pPfo));
126 
127  if (pfoToLArTPCMap.end() != iter)
128  larTPCToPfoMap[iter->second].push_back(pPfo);
129  }
130 }
intermediate_table::const_iterator const_iterator
void lar_content::StitchingCosmicRayMergingTool::CalculateX0 ( const PfoToLArTPCMap pfoToLArTPCMap,
const ThreeDPointingClusterMap pointingClusterMap,
const pandora::PfoVector &  pfoVector,
float &  x0 
) const
private

Calculate x0 shift for a group of associated Pfos.

Parameters
pfoToLArTPCMapthe mapping between pfos and tpc
pointingClusterMapthe mapping between Pfos and their corresponding 3D pointing clusters
pfoVectorthe vector of parent Pfos to stitch together
x0the output x0 value

Definition at line 557 of file StitchingCosmicRayMergingTool.cc.

References lar_content::LArStitchingHelper::CalculateX0(), lar_content::LArStitchingHelper::CanTPCsBeStitched(), f, and lar_content::LArStitchingHelper::GetClosestVertices().

Referenced by StitchPfos().

559 {
560  float sumX(0.f), sumN(0.f);
561 
562  for (PfoVector::const_iterator iter1 = pfoVector.begin(), iterEnd = pfoVector.end(); iter1 != iterEnd; ++iter1)
563  {
564  const ParticleFlowObject *const pPfo1(*iter1);
565  PfoToLArTPCMap::const_iterator tpcIter1 = pfoToLArTPCMap.find(pPfo1);
566  ThreeDPointingClusterMap::const_iterator pointingIter1 = pointingClusterMap.find(pPfo1);
567 
568  if (pfoToLArTPCMap.end() == tpcIter1 || pointingClusterMap.end() == pointingIter1)
569  throw StatusCodeException(STATUS_CODE_FAILURE);
570 
571  const LArTPC *const pLArTPC1(tpcIter1->second);
572  const LArPointingCluster &pointingCluster1(pointingIter1->second);
573 
574  for (PfoVector::const_iterator iter2 = iter1; iter2 != iterEnd; ++iter2)
575  {
576  const ParticleFlowObject *const pPfo2(*iter2);
577  PfoToLArTPCMap::const_iterator tpcIter2 = pfoToLArTPCMap.find(pPfo2);
578  ThreeDPointingClusterMap::const_iterator pointingIter2 = pointingClusterMap.find(pPfo2);
579 
580  if (pfoToLArTPCMap.end() == tpcIter2 || pointingClusterMap.end() == pointingIter2)
581  throw StatusCodeException(STATUS_CODE_FAILURE);
582 
583  const LArTPC *const pLArTPC2(tpcIter2->second);
584  const LArPointingCluster &pointingCluster2(pointingIter2->second);
585 
586  if (!LArStitchingHelper::CanTPCsBeStitched(*pLArTPC1, *pLArTPC2))
587  continue;
588 
589  // Calculate X0 for the closest pair of vertices
590  LArPointingCluster::Vertex pointingVertex1, pointingVertex2;
591 
592  try
593  {
594  LArStitchingHelper::GetClosestVertices(*pLArTPC1, *pLArTPC2, pointingCluster1, pointingCluster2,
595  pointingVertex1, pointingVertex2);
596 
597  const float thisX0(LArStitchingHelper::CalculateX0(*pLArTPC1, *pLArTPC2, pointingVertex1, pointingVertex2));
598  sumX += thisX0; sumN += 1.f;
599  }
600  catch (const pandora::StatusCodeException &) {}
601  }
602  }
603 
604  if ((sumN < std::numeric_limits<float>::epsilon()) || (std::fabs(sumX) < std::numeric_limits<float>::epsilon()))
605  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
606 
607  x0 = (sumX / sumN);
608 }
static float CalculateX0(const pandora::LArTPC &firstTPC, const pandora::LArTPC &secondTPC, const LArPointingCluster::Vertex &firstVertex, const LArPointingCluster::Vertex &secondVertex)
Calculate X0 for a pair of vertices.
TFile f
Definition: plotHisto.C:6
intermediate_table::const_iterator const_iterator
static bool CanTPCsBeStitched(const pandora::LArTPC &firstTPC, const pandora::LArTPC &secondTPC)
Whether particles from a given pair of tpcs can be stitched together.
static void GetClosestVertices(const pandora::LArTPC &larTPC1, const pandora::LArTPC &larTPC2, const LArPointingCluster &pointingCluster1, const LArPointingCluster &pointingCluster2, LArPointingCluster::Vertex &closestVertex1, LArPointingCluster::Vertex &closestVertex2)
Given a pair of pointing clusters, find the pair of vertices with smallest yz-separation.
void lar_content::StitchingCosmicRayMergingTool::CollectAssociatedPfos ( const pandora::ParticleFlowObject *const  pSeedPfo,
const pandora::ParticleFlowObject *const  pCurrentPfo,
const PfoMergeMap pfoMerges,
const pandora::PfoSet &  vetoSet,
pandora::PfoList &  associatedList 
) const
private

Collect up associations between Pfos.

Parameters
pSeedPfothe seed Pfo (will be enlarged after merging)
pCurrentPfothe target Pfo (will be deleted after merging)
pfoMergesthe list of associations between Pfos
vetoSetthe set of associated Pfos that have already been considered
associatedListthe output list of associated Pfos

Definition at line 408 of file StitchingCosmicRayMergingTool.cc.

Referenced by SelectPfoMerges().

410 {
411  if (vetoSet.count(pCurrentPfo))
412  return;
413 
414  PfoMergeMap::const_iterator iter1 = pfoMergeMap.find(pCurrentPfo);
415 
416  if (pfoMergeMap.end() == iter1)
417  return;
418 
419  for (PfoList::const_iterator iter2 = iter1->second.begin(), iterEnd2 = iter1->second.end(); iter2 != iterEnd2; ++iter2)
420  {
421  const ParticleFlowObject *const pAssociatedPfo = *iter2;
422 
423  if (pAssociatedPfo == pSeedPfo)
424  continue;
425 
426  if (associatedList.end() != std::find(associatedList.begin(), associatedList.end(), pAssociatedPfo))
427  continue;
428 
429  associatedList.push_back(pAssociatedPfo);
430 
431  this->CollectAssociatedPfos(pSeedPfo, pAssociatedPfo, pfoMergeMap, vetoSet, associatedList);
432  }
433 }
void CollectAssociatedPfos(const pandora::ParticleFlowObject *const pSeedPfo, const pandora::ParticleFlowObject *const pCurrentPfo, const PfoMergeMap &pfoMerges, const pandora::PfoSet &vetoSet, pandora::PfoList &associatedList) const
Collect up associations between Pfos.
intermediate_table::const_iterator const_iterator
void lar_content::StitchingCosmicRayMergingTool::CreatePfoMatches ( const LArTPCToPfoMap larTPCToPfoMap,
const ThreeDPointingClusterMap pointingClusterMap,
PfoAssociationMatrix pfoAssociationMatrix 
) const
private

Create associations between Pfos using 3D pointing clusters.

Parameters
larTPCToPfoMapthe input mapping between tpc and Pfos
pointingClusterMapthe mapping between Pfos and their corresponding 3D pointing clusters
pfoAssociationMatrixthe output matrix of associations between Pfos

Definition at line 134 of file StitchingCosmicRayMergingTool.cc.

References lar_content::LArStitchingHelper::CanTPCsBeStitched(), f, lar_content::LArStitchingHelper::GetClosestVertices(), lar_content::LArPointingCluster::Vertex::GetDirection(), lar_content::LArPointingClusterHelper::GetImpactParameters(), lar_content::LArPointingClusterHelper::GetImpactParametersInYZ(), lar_content::LArPointingCluster::GetLengthSquared(), lar_content::LArPointingCluster::Vertex::GetPosition(), lar_content::LArStitchingHelper::GetTPCBoundaryCenterX(), lar_content::LArStitchingHelper::GetTPCBoundaryWidthX(), lar_content::StitchingCosmicRayMergingTool::PfoAssociation::INNER, lar_content::LArPointingCluster::Vertex::IsInnerVertex(), m_maxLongitudinalDisplacementX, m_maxTransverseDisplacement, m_minCosRelativeAngle, m_minLengthSquared, m_relaxCosRelativeAngle, m_relaxTransverseDisplacement, m_useXcoordinate, max, min, lar_content::StitchingCosmicRayMergingTool::PfoAssociation::OUTER, and lar_content::LArStitchingHelper::SortTPCs().

Referenced by Run().

136 {
137  LArTPCVector larTPCVector;
138  for (const auto &mapEntry : larTPCToPfoMap) larTPCVector.push_back(mapEntry.first);
139  std::sort(larTPCVector.begin(), larTPCVector.end(), LArStitchingHelper::SortTPCs);
140 
141  for (LArTPCVector::const_iterator tpcIter1 = larTPCVector.begin(), tpcIterEnd = larTPCVector.end(); tpcIter1 != tpcIterEnd; ++tpcIter1)
142  {
143  const LArTPC *const pLArTPC1(*tpcIter1);
144  const PfoList &pfoList1(larTPCToPfoMap.at(pLArTPC1));
145 
146  for (LArTPCVector::const_iterator tpcIter2 = tpcIter1; tpcIter2 != tpcIterEnd; ++tpcIter2)
147  {
148  const LArTPC *const pLArTPC2(*tpcIter2);
149  const PfoList &pfoList2(larTPCToPfoMap.at(pLArTPC2));
150 
151  if (!LArStitchingHelper::CanTPCsBeStitched(*pLArTPC1, *pLArTPC2))
152  continue;
153 
154  for (const ParticleFlowObject *const pPfo1 : pfoList1)
155  {
156  for (const ParticleFlowObject *const pPfo2 : pfoList2)
157  this->CreatePfoMatches(*pLArTPC1, *pLArTPC2, pPfo1, pPfo2, pointingClusterMap, pfoAssociationMatrix);
158  }
159  }
160  }
161 }
void CreatePfoMatches(const LArTPCToPfoMap &larTPCToPfoMap, const ThreeDPointingClusterMap &pointingClusterMap, PfoAssociationMatrix &pfoAssociationMatrix) const
Create associations between Pfos using 3D pointing clusters.
intermediate_table::const_iterator const_iterator
static bool CanTPCsBeStitched(const pandora::LArTPC &firstTPC, const pandora::LArTPC &secondTPC)
Whether particles from a given pair of tpcs can be stitched together.
static bool SortTPCs(const pandora::LArTPC *const pLhs, const pandora::LArTPC *const pRhs)
Sort tpcs by central positions.
void lar_content::StitchingCosmicRayMergingTool::CreatePfoMatches ( const pandora::LArTPC &  larTPC1,
const pandora::LArTPC &  larTPC2,
const pandora::ParticleFlowObject *const  pPfo1,
const pandora::ParticleFlowObject *const  pPfo2,
const ThreeDPointingClusterMap pointingClusterMap,
PfoAssociationMatrix pfoAssociationMatrix 
) const
private

Create associations between Pfos using 3D pointing clusters.

Parameters
larTPC1the tpc description for the first Pfo
larTPC2the tpc description for the second Pfo
pPfo1the first Pfo
pPfo2the second Pfo
pointingClusterMapthe mapping between Pfos and their corresponding 3D pointing clusters
pfoAssociationMatrixthe output matrix of associations between Pfos
void lar_content::StitchingCosmicRayMergingTool::OrderPfoMerges ( const PfoToLArTPCMap pfoToLArTPCMap,
const ThreeDPointingClusterMap pointingClusterMap,
const PfoMergeMap inputPfoMerges,
PfoMergeMap outputPfoMerges 
) const
private

Identify the vertex Pfo and then re-order the map of merges so that the vertex Pfo will be enlarged.

Parameters
pfoToLArTPCMapthe mapping between pfos and tpc
pointingClusterMapthe mapping between Pfos and their corresponding 3D pointing clusters
inputPfoMergesthe input map of Pfo merges
outputPfoMergesthe re-ordered map of Pfo merges

Definition at line 437 of file StitchingCosmicRayMergingTool.cc.

References evd::details::begin(), f, lar_content::LArStitchingHelper::GetClosestVertices(), lar_content::LArPointingCluster::GetInnerVertex(), lar_content::LArPointingCluster::GetOuterVertex(), lar_content::LArStitchingHelper::GetTPCDisplacement(), lar_content::LArPointingCluster::Vertex::IsInnerVertex(), and lar_content::LArPfoHelper::SortByNHits().

Referenced by Run().

439 {
440  PfoVector inputPfoVector;
441  for (const auto &mapEntry : inputPfoMerges) inputPfoVector.push_back(mapEntry.first);
442  std::sort(inputPfoVector.begin(), inputPfoVector.end(), LArPfoHelper::SortByNHits);
443 
444  for (const ParticleFlowObject *const pInputPfo : inputPfoVector)
445  {
446  const PfoList &pfoList(inputPfoMerges.at(pInputPfo));
447 
448  float bestLength(0.f);
449  const ParticleFlowObject *pVertexPfo = nullptr;
450 
451  for (PfoList::const_iterator iter1 = pfoList.begin(), iterEnd = pfoList.end(); iter1 != iterEnd; ++iter1)
452  {
453  const ParticleFlowObject *const pPfo1(*iter1);
454  PfoToLArTPCMap::const_iterator tpcIter1 = pfoToLArTPCMap.find(pPfo1);
455  ThreeDPointingClusterMap::const_iterator pointingIter1 = pointingClusterMap.find(pPfo1);
456 
457  if (pfoToLArTPCMap.end() == tpcIter1 || pointingClusterMap.end() == pointingIter1)
458  throw StatusCodeException(STATUS_CODE_FAILURE);
459 
460  const LArTPC *const pLArTPC1(tpcIter1->second);
461  const LArPointingCluster &pointingCluster1(pointingIter1->second);
462 
463  for (PfoList::const_iterator iter2 = iter1; iter2 != iterEnd; ++iter2)
464  {
465  const ParticleFlowObject *const pPfo2(*iter2);
466  PfoToLArTPCMap::const_iterator tpcIter2 = pfoToLArTPCMap.find(pPfo2);
467  ThreeDPointingClusterMap::const_iterator pointingIter2 = pointingClusterMap.find(pPfo2);
468 
469  if (pfoToLArTPCMap.end() == tpcIter2 || pointingClusterMap.end() == pointingIter2)
470  throw StatusCodeException(STATUS_CODE_FAILURE);
471 
472  const LArTPC *const pLArTPC2(tpcIter2->second);
473  const LArPointingCluster &pointingCluster2(pointingIter2->second);
474 
475  if (pLArTPC1 == pLArTPC2)
476  continue;
477 
478  const float thisLength(LArStitchingHelper::GetTPCDisplacement(*pLArTPC1, *pLArTPC2));
479 
480  if (thisLength < bestLength)
481  continue;
482 
483  bestLength = thisLength;
484 
485  try
486  {
487  pVertexPfo = nullptr;
488 
489  LArPointingCluster::Vertex nearVertex1, nearVertex2;
490  LArStitchingHelper::GetClosestVertices(*pLArTPC1, *pLArTPC2, pointingCluster1, pointingCluster2, nearVertex1, nearVertex2);
491 
492  const LArPointingCluster::Vertex &farVertex1(nearVertex1.IsInnerVertex() ? pointingCluster1.GetOuterVertex() : pointingCluster1.GetInnerVertex());
493  const LArPointingCluster::Vertex &farVertex2(nearVertex2.IsInnerVertex() ? pointingCluster2.GetOuterVertex() : pointingCluster2.GetInnerVertex());
494  const float deltaY(farVertex1.GetPosition().GetY() - farVertex2.GetPosition().GetY());
495 
496  if (std::fabs(deltaY) < std::numeric_limits<float>::epsilon())
497  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
498 
499  pVertexPfo = ((deltaY > 0.f) ? pPfo1 : pPfo2);
500  }
501  catch (const pandora::StatusCodeException &) {}
502  }
503  }
504 
505  if (pVertexPfo)
506  outputPfoMerges[pVertexPfo].insert(outputPfoMerges[pVertexPfo].begin(), pfoList.begin(), pfoList.end());
507  }
508 }
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
TFile f
Definition: plotHisto.C:6
intermediate_table::const_iterator const_iterator
static float GetTPCDisplacement(const pandora::LArTPC &firstTPC, const pandora::LArTPC &secondTPC)
Calculate distance between central positions of a pair of tpcs.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
static void GetClosestVertices(const pandora::LArTPC &larTPC1, const pandora::LArTPC &larTPC2, const LArPointingCluster &pointingCluster1, const LArPointingCluster &pointingCluster2, LArPointingCluster::Vertex &closestVertex1, LArPointingCluster::Vertex &closestVertex2)
Given a pair of pointing clusters, find the pair of vertices with smallest yz-separation.
StatusCode lar_content::StitchingCosmicRayMergingTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 644 of file StitchingCosmicRayMergingTool.cc.

References m_halfWindowLayers, m_maxLongitudinalDisplacementX, m_maxTransverseDisplacement, m_minCosRelativeAngle, m_minLengthSquared, m_relaxCosRelativeAngle, m_relaxTransverseDisplacement, and m_useXcoordinate.

645 {
646  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
647  "ThreeDStitchingMode", m_useXcoordinate));
648 
649  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
650  "HalfWindowLayers", m_halfWindowLayers));
651 
652  float minLength(std::sqrt(m_minLengthSquared));
653  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
654  "MinPfoLength", minLength));
655  m_minLengthSquared = minLength * minLength;
656 
657  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
658  "MinCosRelativeAngle", m_minCosRelativeAngle));
659 
660  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
661  "MaxLongitudinalDisplacementX", m_maxLongitudinalDisplacementX));
662 
663  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
664  "MaxTransverseDisplacement", m_maxTransverseDisplacement));
665 
666  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
667  "LooserMinCosRelativeAngle", m_relaxCosRelativeAngle));
668 
669  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
670  "LooserMaxTransverseDisplacement", m_relaxTransverseDisplacement));
671 
672  return STATUS_CODE_SUCCESS;
673 }
void lar_content::StitchingCosmicRayMergingTool::Run ( const MasterAlgorithm *const  pAlgorithm,
const pandora::PfoList *const  pMultiPfoList,
PfoToLArTPCMap pfoToLArTPCMap,
PfoToFloatMap stitchedPfosToX0Map 
)
virtual

Run the algorithm tool.

Parameters
pAlgorithmaddress of the calling algorithm
pMultiPfoListthe list of pfos in multiple lar tpcs
pfoToLArTPCMapthe pfo to lar tpc map
stitchedPfosToX0Mapa map of cosmic-ray pfos that have been stitched between lar tpcs to the X0 shift

Implements lar_content::StitchingBaseTool.

Definition at line 38 of file StitchingCosmicRayMergingTool.cc.

References BuildPointingClusterMaps(), BuildTPCMaps(), CreatePfoMatches(), OrderPfoMerges(), SelectPfoMatches(), SelectPfoMerges(), SelectPrimaryPfos(), and StitchPfos().

39 {
40  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
41  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
42 
43  if (this->GetPandora().GetGeometry()->GetLArTPCMap().size() < 2)
44  return;
45 
46  if (pfoToLArTPCMap.empty())
47  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
48 
49  PfoList primaryPfos;
50  this->SelectPrimaryPfos(pMultiPfoList, pfoToLArTPCMap, primaryPfos);
51 
52  ThreeDPointingClusterMap pointingClusterMap;
53  this->BuildPointingClusterMaps(primaryPfos, pfoToLArTPCMap, pointingClusterMap);
54 
55  LArTPCToPfoMap larTPCToPfoMap;
56  this->BuildTPCMaps(primaryPfos, pfoToLArTPCMap, larTPCToPfoMap);
57 
58  PfoAssociationMatrix pfoAssociationMatrix;
59  this->CreatePfoMatches(larTPCToPfoMap, pointingClusterMap, pfoAssociationMatrix);
60 
61  PfoMergeMap pfoSelectedMatches;
62  this->SelectPfoMatches(pfoAssociationMatrix, pfoSelectedMatches);
63 
64  PfoMergeMap pfoSelectedMerges;
65  this->SelectPfoMerges(pfoSelectedMatches, pfoSelectedMerges);
66 
67  PfoMergeMap pfoOrderedMerges;
68  this->OrderPfoMerges(pfoToLArTPCMap, pointingClusterMap, pfoSelectedMerges, pfoOrderedMerges);
69 
70  this->StitchPfos(pAlgorithm, pointingClusterMap, pfoOrderedMerges, pfoToLArTPCMap, stitchedPfosToX0Map);
71 }
std::unordered_map< const pandora::ParticleFlowObject *, LArPointingCluster > ThreeDPointingClusterMap
void SelectPrimaryPfos(const pandora::PfoList *pInputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, pandora::PfoList &outputPfoList) const
Select primary Pfos from the input list of Pfos.
std::unordered_map< const pandora::ParticleFlowObject *, pandora::PfoList > PfoMergeMap
std::unordered_map< const pandora::LArTPC *, pandora::PfoList > LArTPCToPfoMap
void CreatePfoMatches(const LArTPCToPfoMap &larTPCToPfoMap, const ThreeDPointingClusterMap &pointingClusterMap, PfoAssociationMatrix &pfoAssociationMatrix) const
Create associations between Pfos using 3D pointing clusters.
void BuildTPCMaps(const pandora::PfoList &inputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, LArTPCToPfoMap &larTPCToPfoMap) const
Build a list of Pfos for each tpc.
void OrderPfoMerges(const PfoToLArTPCMap &pfoToLArTPCMap, const ThreeDPointingClusterMap &pointingClusterMap, const PfoMergeMap &inputPfoMerges, PfoMergeMap &outputPfoMerges) const
Identify the vertex Pfo and then re-order the map of merges so that the vertex Pfo will be enlarged...
void StitchPfos(const MasterAlgorithm *const pAlgorithm, const ThreeDPointingClusterMap &pointingClusterMap, const PfoMergeMap &pfoMerges, PfoToLArTPCMap &pfoToLArTPCMap, PfoToFloatMap &stitchedPfosToX0Map) const
Apply X0 corrections, and then stitch together Pfos.
void BuildPointingClusterMaps(const pandora::PfoList &inputPfoList, const PfoToLArTPCMap &pfoToLArTPCMap, ThreeDPointingClusterMap &pointingClusterMap) const
Build a 3D pointing cluster for each Pfo.
void SelectPfoMatches(const PfoAssociationMatrix &pfoAssociationMatrix, PfoMergeMap &pfoSelectedMatches) const
Select the best associations between Pfos; create a mapping between associated Pfos, handling any ambiguities.
void SelectPfoMerges(const PfoMergeMap &pfoMatches, PfoMergeMap &pfoMerges) const
Create an initial map of Pfo merges to be made.
std::unordered_map< const pandora::ParticleFlowObject *, PfoAssociationMap > PfoAssociationMatrix
void lar_content::StitchingCosmicRayMergingTool::SelectPfoMatches ( const PfoAssociationMatrix pfoAssociationMatrix,
PfoMergeMap pfoSelectedMatches 
) const
private

Select the best associations between Pfos; create a mapping between associated Pfos, handling any ambiguities.

Parameters
pfoAssociationMatrixthe input list of all associations between Pfos
pfoSelectedMatchesthe output list of good associations between pfos (candidates for merging)

Definition at line 272 of file StitchingCosmicRayMergingTool.cc.

References f, lar_content::StitchingCosmicRayMergingTool::PfoAssociation::GetDaughter(), lar_content::StitchingCosmicRayMergingTool::PfoAssociation::GetFigureOfMerit(), lar_content::StitchingCosmicRayMergingTool::PfoAssociation::GetParent(), lar_content::StitchingCosmicRayMergingTool::PfoAssociation::INNER, lar_content::StitchingCosmicRayMergingTool::PfoAssociation::OUTER, lar_content::LArPfoHelper::SortByNHits(), and lar_content::StitchingCosmicRayMergingTool::PfoAssociation::UNDEFINED.

Referenced by Run().

273 {
274  // First step: loop over association matrix and find best associations A -> X and B -> Y
275  // =====================================================================================
276  PfoAssociationMatrix bestAssociationMatrix;
277 
278  PfoVector pfoVector1;
279  for (const auto &mapEntry : pfoAssociationMatrix) pfoVector1.push_back(mapEntry.first);
280  std::sort(pfoVector1.begin(), pfoVector1.end(), LArPfoHelper::SortByNHits);
281 
282  for (const ParticleFlowObject *const pPfo1 : pfoVector1)
283  {
284  const PfoAssociationMap &pfoAssociationMap(pfoAssociationMatrix.at(pPfo1));
285 
286  const ParticleFlowObject *pBestPfoInner(nullptr);
287  PfoAssociation bestAssociationInner(PfoAssociation::UNDEFINED, PfoAssociation::UNDEFINED, 0.f);
288 
289  const ParticleFlowObject *pBestPfoOuter(nullptr);
290  PfoAssociation bestAssociationOuter(PfoAssociation::UNDEFINED, PfoAssociation::UNDEFINED, 0.f);
291 
292  PfoVector pfoVector2;
293  for (const auto &mapEntry : pfoAssociationMap) pfoVector2.push_back(mapEntry.first);
294  std::sort(pfoVector2.begin(), pfoVector2.end(), LArPfoHelper::SortByNHits);
295 
296  for (const ParticleFlowObject *const pPfo2 : pfoVector2)
297  {
298  const PfoAssociation &pfoAssociation(pfoAssociationMap.at(pPfo2));
299 
300  // Inner associations
301  if (pfoAssociation.GetParent() == PfoAssociation::INNER)
302  {
303  if (pfoAssociation.GetFigureOfMerit() > bestAssociationInner.GetFigureOfMerit())
304  {
305  bestAssociationInner = pfoAssociation;
306  pBestPfoInner = pPfo2;
307  }
308  }
309 
310  // Outer associations
311  if (pfoAssociation.GetParent() == PfoAssociation::OUTER)
312  {
313  if (pfoAssociation.GetFigureOfMerit() > bestAssociationOuter.GetFigureOfMerit())
314  {
315  bestAssociationOuter = pfoAssociation;
316  pBestPfoOuter = pPfo2;
317  }
318  }
319  }
320 
321  if (pBestPfoInner)
322  (void) bestAssociationMatrix[pPfo1].insert(PfoAssociationMap::value_type(pBestPfoInner, bestAssociationInner));
323 
324  if (pBestPfoOuter)
325  (void) bestAssociationMatrix[pPfo1].insert(PfoAssociationMap::value_type(pBestPfoOuter, bestAssociationOuter));
326  }
327 
328  // Second step: make the merge if A -> X and B -> Y is in fact A -> B and B -> A
329  // =============================================================================
330  PfoVector pfoVector3;
331  for (const auto &mapEntry : bestAssociationMatrix) pfoVector3.push_back(mapEntry.first);
332  std::sort(pfoVector3.begin(), pfoVector3.end(), LArPfoHelper::SortByNHits);
333 
334  for (const ParticleFlowObject *const pParentPfo : pfoVector3)
335  {
336  const PfoAssociationMap &parentAssociationMap(bestAssociationMatrix.at(pParentPfo));
337 
338  PfoVector pfoVector4;
339  for (const auto &mapEntry : parentAssociationMap) pfoVector4.push_back(mapEntry.first);
340  std::sort(pfoVector4.begin(), pfoVector4.end(), LArPfoHelper::SortByNHits);
341 
342  for (const ParticleFlowObject *const pDaughterPfo : pfoVector4)
343  {
344  const PfoAssociation &parentToDaughterAssociation(parentAssociationMap.at(pDaughterPfo));
345  PfoAssociationMatrix::const_iterator iter5 = bestAssociationMatrix.find(pDaughterPfo);
346 
347  if (bestAssociationMatrix.end() == iter5)
348  continue;
349 
350  const PfoAssociationMap &daughterAssociationMap(iter5->second);
351 
352  PfoAssociationMap::const_iterator iter6 = daughterAssociationMap.find(pParentPfo);
353  if (daughterAssociationMap.end() == iter6)
354  continue;
355 
356  const PfoAssociation &daughterToParentAssociation(iter6->second);
357 
358  if (parentToDaughterAssociation.GetParent() == daughterToParentAssociation.GetDaughter() &&
359  parentToDaughterAssociation.GetDaughter() == daughterToParentAssociation.GetParent())
360  {
361  pfoMatches[pParentPfo].push_back(pDaughterPfo);
362  }
363  }
364  }
365 }
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
TFile f
Definition: plotHisto.C:6
intermediate_table::const_iterator const_iterator
std::unordered_map< const pandora::ParticleFlowObject *, PfoAssociation > PfoAssociationMap
std::unordered_map< const pandora::ParticleFlowObject *, PfoAssociationMap > PfoAssociationMatrix
void lar_content::StitchingCosmicRayMergingTool::SelectPfoMerges ( const PfoMergeMap pfoMatches,
PfoMergeMap pfoMerges 
) const
private

Create an initial map of Pfo merges to be made.

Parameters
pfoMatchesthe input list of associated Pfos
pfoMergesthe output mapping between Pfos to enlarge and Pfos to delete

Definition at line 369 of file StitchingCosmicRayMergingTool.cc.

References CollectAssociatedPfos(), and lar_content::LArPfoHelper::SortByNHits().

Referenced by Run().

370 {
371  PfoSet vetoSet;
372 
373  PfoVector inputPfoVector;
374  for (const auto &mapEntry : pfoMatches) inputPfoVector.push_back(mapEntry.first);
375  std::sort(inputPfoVector.begin(), inputPfoVector.end(), LArPfoHelper::SortByNHits);
376 
377  for (const ParticleFlowObject *const pInputPfo : inputPfoVector)
378  {
379  const PfoList &pfoList(pfoMatches.at(pInputPfo));
380 
381  for (const ParticleFlowObject *const pSeedPfo : pfoList)
382  {
383  if (vetoSet.count(pSeedPfo))
384  continue;
385 
386  PfoList mergeList;
387  this->CollectAssociatedPfos(pSeedPfo, pSeedPfo, pfoMatches, vetoSet, mergeList);
388 
389  vetoSet.insert(pSeedPfo);
390  PfoList &selectedPfoList(pfoMerges[pSeedPfo]);
391  selectedPfoList.push_back(pSeedPfo);
392 
393  for (const ParticleFlowObject *const pAssociatedPfo : mergeList)
394  {
395  // Check if particle has already been counted
396  if (vetoSet.count(pAssociatedPfo) || (selectedPfoList.end() != std::find(selectedPfoList.begin(), selectedPfoList.end(), pAssociatedPfo)))
397  throw StatusCodeException(STATUS_CODE_FAILURE);
398 
399  vetoSet.insert(pAssociatedPfo);
400  selectedPfoList.push_back(pAssociatedPfo);
401  }
402  }
403  }
404 }
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
void CollectAssociatedPfos(const pandora::ParticleFlowObject *const pSeedPfo, const pandora::ParticleFlowObject *const pCurrentPfo, const PfoMergeMap &pfoMerges, const pandora::PfoSet &vetoSet, pandora::PfoList &associatedList) const
Collect up associations between Pfos.
void lar_content::StitchingCosmicRayMergingTool::SelectPrimaryPfos ( const pandora::PfoList *  pInputPfoList,
const PfoToLArTPCMap pfoToLArTPCMap,
pandora::PfoList &  outputPfoList 
) const
private

Select primary Pfos from the input list of Pfos.

Parameters
pInputPfoListthe input list of Pfos
pfoToLArTPCMapthe input mapping between Pfos and tpc
outputPfoListthe output list of Pfos

Definition at line 75 of file StitchingCosmicRayMergingTool.cc.

References lar_content::LArPfoHelper::IsFinalState(), lar_content::LArPfoHelper::IsTrack(), and lar_content::LArPfoHelper::SortByNHits().

Referenced by Run().

76 {
77  for (const ParticleFlowObject *const pPfo : *pInputPfoList)
78  {
80  continue;
81 
82  if (!pfoToLArTPCMap.count(pPfo))
83  continue;
84 
85  outputPfoList.push_back(pPfo);
86  }
87 
88  outputPfoList.sort(LArPfoHelper::SortByNHits);
89 }
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
static bool IsFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a primary parent particle.
void lar_content::StitchingCosmicRayMergingTool::StitchPfos ( const MasterAlgorithm *const  pAlgorithm,
const ThreeDPointingClusterMap pointingClusterMap,
const PfoMergeMap pfoMerges,
PfoToLArTPCMap pfoToLArTPCMap,
PfoToFloatMap stitchedPfosToX0Map 
) const
private

Apply X0 corrections, and then stitch together Pfos.

Parameters
pAlgorithmthe address of the parent stitching algorithm
pointingClusterMapthe mapping between Pfos and their corresponding 3D pointing clusters
pfoMergesthe input map of Pfo merges
pfoToLArTPCMapthe pfo to lar tpc map
stitchedPfosToX0Mapa map of cosmic-ray pfos that have been stitched between lar tpcs to the X0 shift

Definition at line 512 of file StitchingCosmicRayMergingTool.cc.

References CalculateX0(), f, m_useXcoordinate, lar_content::MasterAlgorithm::ShiftPfoHierarchy(), lar_content::LArPfoHelper::SortByNHits(), and lar_content::MasterAlgorithm::StitchPfos().

Referenced by Run().

514 {
515  PfoVector pfoVectorToEnlarge;
516  for (const auto &mapEntry : pfoMerges) pfoVectorToEnlarge.push_back(mapEntry.first);
517  std::sort(pfoVectorToEnlarge.begin(), pfoVectorToEnlarge.end(), LArPfoHelper::SortByNHits);
518 
519  for (const ParticleFlowObject *const pPfoToEnlarge : pfoVectorToEnlarge)
520  {
521  const PfoList &pfoList(pfoMerges.at(pPfoToEnlarge));
522 
523  PfoVector pfoVector;
524  for (const ParticleFlowObject *const pPfo : pfoList) pfoVector.push_back(pPfo);
525  std::sort(pfoVector.begin(), pfoVector.end(), LArPfoHelper::SortByNHits);
526 
527  float x0(0.f);
528 
529  if (!m_useXcoordinate)
530  {
531  try
532  {
533  this->CalculateX0(pfoToLArTPCMap, pointingClusterMap, pfoVector, x0);
534  }
535  catch (const pandora::StatusCodeException &)
536  {
537  continue;
538  }
539 
540  for (const ParticleFlowObject *const pPfoToShift : pfoVector)
541  pAlgorithm->ShiftPfoHierarchy(pPfoToShift, pfoToLArTPCMap, x0);
542  }
543 
544  for (const ParticleFlowObject *const pPfoToDelete : pfoVector)
545  {
546  if (pPfoToEnlarge == pPfoToDelete)
547  continue;
548 
549  pAlgorithm->StitchPfos(pPfoToEnlarge, pPfoToDelete, pfoToLArTPCMap);
550  stitchedPfosToX0Map.insert(PfoToFloatMap::value_type(pPfoToEnlarge, x0));
551  }
552  }
553 }
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
TFile f
Definition: plotHisto.C:6
void CalculateX0(const PfoToLArTPCMap &pfoToLArTPCMap, const ThreeDPointingClusterMap &pointingClusterMap, const pandora::PfoVector &pfoVector, float &x0) const
Calculate x0 shift for a group of associated Pfos.

Member Data Documentation

int lar_content::StitchingCosmicRayMergingTool::m_halfWindowLayers
private

Definition at line 211 of file StitchingCosmicRayMergingTool.h.

Referenced by BuildPointingClusterMaps(), and ReadSettings().

float lar_content::StitchingCosmicRayMergingTool::m_maxLongitudinalDisplacementX
private

Definition at line 214 of file StitchingCosmicRayMergingTool.h.

Referenced by CreatePfoMatches(), and ReadSettings().

float lar_content::StitchingCosmicRayMergingTool::m_maxTransverseDisplacement
private

Definition at line 215 of file StitchingCosmicRayMergingTool.h.

Referenced by CreatePfoMatches(), and ReadSettings().

float lar_content::StitchingCosmicRayMergingTool::m_minCosRelativeAngle
private

Definition at line 213 of file StitchingCosmicRayMergingTool.h.

Referenced by CreatePfoMatches(), and ReadSettings().

float lar_content::StitchingCosmicRayMergingTool::m_minLengthSquared
private

Definition at line 212 of file StitchingCosmicRayMergingTool.h.

Referenced by CreatePfoMatches(), and ReadSettings().

float lar_content::StitchingCosmicRayMergingTool::m_relaxCosRelativeAngle
private

Definition at line 216 of file StitchingCosmicRayMergingTool.h.

Referenced by CreatePfoMatches(), and ReadSettings().

float lar_content::StitchingCosmicRayMergingTool::m_relaxTransverseDisplacement
private

Definition at line 217 of file StitchingCosmicRayMergingTool.h.

Referenced by CreatePfoMatches(), and ReadSettings().

bool lar_content::StitchingCosmicRayMergingTool::m_useXcoordinate
private

Definition at line 210 of file StitchingCosmicRayMergingTool.h.

Referenced by CreatePfoMatches(), ReadSettings(), and StitchPfos().


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