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