LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 
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) mcParticleVector.push_back(mapEntry.first);
41  std::sort(mcParticleVector.begin(), mcParticleVector.end(), LArMCParticleHelper::SortByMomentum);
42 
43  for (const MCParticle *const pMCParticle : mcParticleVector)
44  {
45  const Slice &slice(mcParticleToSliceMap.at(pMCParticle));
46 
47  if (!slice.m_caloHitListU.empty() || !slice.m_caloHitListV.empty() || !slice.m_caloHitListW.empty())
48  sliceList.push_back(slice);
49  }
50 }
51 
52 //------------------------------------------------------------------------------------------------------------------------------------------
53 
54 void CheatingEventSlicingTool::InitializeMCParticleToSliceMap(const Algorithm *const pAlgorithm, const HitTypeToNameMap &caloHitListNames,
55  MCParticleToSliceMap &mcParticleToSliceMap) const
56 {
57  for (const auto &mapEntry : caloHitListNames)
58  {
59  const CaloHitList *pCaloHitList(nullptr);
60  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*pAlgorithm, mapEntry.second, pCaloHitList));
61 
62  for (const CaloHit *const pCaloHit : *pCaloHitList)
63  {
64  MCParticleVector mcParticleVector;
65  for (const auto &weightMapEntry : pCaloHit->GetMCParticleWeightMap()) mcParticleVector.push_back(weightMapEntry.first);
66  std::sort(mcParticleVector.begin(), mcParticleVector.end(), LArMCParticleHelper::SortByMomentum);
67 
68  for (const MCParticle *const pMCParticle : mcParticleVector)
69  {
70  const MCParticle *const pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle));
71 
72  if (mcParticleToSliceMap.count(pParentMCParticle))
73  continue;
74 
75  if (!mcParticleToSliceMap.insert(MCParticleToSliceMap::value_type(pParentMCParticle, Slice())).second)
76  throw StatusCodeException(STATUS_CODE_FAILURE);
77  }
78  }
79  }
80 }
81 
82 //------------------------------------------------------------------------------------------------------------------------------------------
83 
84 void CheatingEventSlicingTool::FillSlices(const Algorithm *const pAlgorithm, const HitType hitType, const HitTypeToNameMap &caloHitListNames,
85  MCParticleToSliceMap &mcParticleToSliceMap) const
86 {
87  if ((TPC_VIEW_U != hitType) && (TPC_VIEW_V != hitType) && (TPC_VIEW_W != hitType))
88  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
89 
90  const CaloHitList *pCaloHitList(nullptr);
91  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*pAlgorithm, caloHitListNames.at(hitType), pCaloHitList));
92 
93  for (const CaloHit *const pCaloHit : *pCaloHitList)
94  {
95  try
96  {
97  const MCParticle *const pMainMCParticle(MCParticleHelper::GetMainMCParticle(pCaloHit));
98  const MCParticle *const pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(pMainMCParticle));
99 
100  MCParticleToSliceMap::iterator mapIter = mcParticleToSliceMap.find(pParentMCParticle);
101 
102  if (mcParticleToSliceMap.end() == mapIter)
103  throw StatusCodeException(STATUS_CODE_FAILURE);
104 
105  Slice &slice(mapIter->second);
106  CaloHitList &caloHitList((TPC_VIEW_U == hitType) ? slice.m_caloHitListU : (TPC_VIEW_V == hitType) ? slice.m_caloHitListV : 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
SlicingAlgorithm::Slice Slice
intermediate_table::iterator iterator
SlicingAlgorithm::SliceList SliceList
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
Header file for the cheating event slicing tool class.
Header file for the lar monte carlo particle helper helper class.
pandora::CaloHitList m_caloHitListU
The u calo hit list.
SlicingAlgorithm::HitTypeToNameMap HitTypeToNameMap
pandora::CaloHitList m_caloHitListW
The w calo hit list.
std::vector< Slice > SliceList
std::unordered_map< const pandora::MCParticle *, SlicingAlgorithm::Slice > MCParticleToSliceMap
std::map< pandora::HitType, std::string > HitTypeToNameMap
pandora::CaloHitList m_caloHitListV
The v calo hit list.