All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CheatingEventSlicingTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArCheating/CheatingEventSlicingTool.cc
3  *
4  * @brief Implementation of the cheating event slicing tool class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
14 
15 using namespace pandora;
16 
17 namespace lar_content
18 {
19 
23 
24 //------------------------------------------------------------------------------------------------------------------------------------------
25 
26 void CheatingEventSlicingTool::RunSlicing(const Algorithm *const pAlgorithm, const HitTypeToNameMap &caloHitListNames,
27  const HitTypeToNameMap & /*clusterListNames*/, SliceList &sliceList)
28 {
29  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
30  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
31 
32  MCParticleToSliceMap mcParticleToSliceMap;
33  this->InitializeMCParticleToSliceMap(pAlgorithm, caloHitListNames, mcParticleToSliceMap);
34 
35  this->FillSlices(pAlgorithm, TPC_VIEW_U, caloHitListNames, mcParticleToSliceMap);
36  this->FillSlices(pAlgorithm, TPC_VIEW_V, caloHitListNames, mcParticleToSliceMap);
37  this->FillSlices(pAlgorithm, TPC_VIEW_W, caloHitListNames, mcParticleToSliceMap);
38 
39  MCParticleVector mcParticleVector;
40  for (const auto &mapEntry : mcParticleToSliceMap)
41  mcParticleVector.push_back(mapEntry.first);
42  std::sort(mcParticleVector.begin(), mcParticleVector.end(), LArMCParticleHelper::SortByMomentum);
43 
44  for (const MCParticle *const pMCParticle : mcParticleVector)
45  {
46  const Slice &slice(mcParticleToSliceMap.at(pMCParticle));
47 
48  if (!slice.m_caloHitListU.empty() || !slice.m_caloHitListV.empty() || !slice.m_caloHitListW.empty())
49  sliceList.push_back(slice);
50  }
51 }
52 
53 //------------------------------------------------------------------------------------------------------------------------------------------
54 
55 void CheatingEventSlicingTool::InitializeMCParticleToSliceMap(
56  const Algorithm *const pAlgorithm, const HitTypeToNameMap &caloHitListNames, MCParticleToSliceMap &mcParticleToSliceMap) const
57 {
58  for (const auto &mapEntry : caloHitListNames)
59  {
60  const CaloHitList *pCaloHitList(nullptr);
61  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*pAlgorithm, mapEntry.second, pCaloHitList));
62 
63  for (const CaloHit *const pCaloHit : *pCaloHitList)
64  {
65  MCParticleVector mcParticleVector;
66  for (const auto &weightMapEntry : pCaloHit->GetMCParticleWeightMap())
67  mcParticleVector.push_back(weightMapEntry.first);
68  std::sort(mcParticleVector.begin(), mcParticleVector.end(), LArMCParticleHelper::SortByMomentum);
69 
70  for (const MCParticle *const pMCParticle : mcParticleVector)
71  {
72  const MCParticle *const pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle));
73 
74  if (mcParticleToSliceMap.count(pParentMCParticle))
75  continue;
76 
77  if (!mcParticleToSliceMap.insert(MCParticleToSliceMap::value_type(pParentMCParticle, Slice())).second)
78  throw StatusCodeException(STATUS_CODE_FAILURE);
79  }
80  }
81  }
82 }
83 
84 //------------------------------------------------------------------------------------------------------------------------------------------
85 
86 void CheatingEventSlicingTool::FillSlices(const Algorithm *const pAlgorithm, const HitType hitType,
87  const HitTypeToNameMap &caloHitListNames, MCParticleToSliceMap &mcParticleToSliceMap) const
88 {
89  if ((TPC_VIEW_U != hitType) && (TPC_VIEW_V != hitType) && (TPC_VIEW_W != hitType))
90  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
91 
92  const CaloHitList *pCaloHitList(nullptr);
93  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*pAlgorithm, caloHitListNames.at(hitType), pCaloHitList));
94 
95  for (const CaloHit *const pCaloHit : *pCaloHitList)
96  {
97  try
98  {
99  const MCParticle *const pMainMCParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
100  const MCParticle *const pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(pMainMCParticle));
101 
102  MCParticleToSliceMap::iterator mapIter = mcParticleToSliceMap.find(pParentMCParticle);
103 
104  if (mcParticleToSliceMap.end() == mapIter)
105  throw StatusCodeException(STATUS_CODE_FAILURE);
106 
107  Slice &slice(mapIter->second);
108  CaloHitList &caloHitList((TPC_VIEW_U == hitType) ? slice.m_caloHitListU : (TPC_VIEW_V == hitType) ? slice.m_caloHitListV : slice.m_caloHitListW);
109  caloHitList.push_back(pCaloHit);
110  }
111  catch (const StatusCodeException &statusCodeException)
112  {
113  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
114  throw statusCodeException;
115  }
116  }
117 }
118 
119 //------------------------------------------------------------------------------------------------------------------------------------------
120 
121 StatusCode CheatingEventSlicingTool::ReadSettings(const TiXmlHandle /*xmlHandle*/)
122 {
123  return STATUS_CODE_SUCCESS;
124 }
125 
126 } // namespace lar_content
SlicingAlgorithm::Slice Slice
SlicingAlgorithm::SliceList SliceList
std::unordered_map< const pandora::MCParticle *, SlicingAlgorithm::Slice > MCParticleToSliceMap
Header file for the cheating event slicing tool class.
Header file for the lar monte carlo particle helper helper class.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
pandora::CaloHitList m_caloHitListU
The u calo hit list.
SlicingAlgorithm::HitTypeToNameMap HitTypeToNameMap
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
pandora::CaloHitList m_caloHitListW
The w calo hit list.
std::vector< Slice > SliceList
std::map< pandora::HitType, std::string > HitTypeToNameMap
pandora::CaloHitList m_caloHitListV
The v calo hit list.
BEGIN_PROLOG could also be cout