CheatingSliceIdBaseTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArCheating/CheatingSliceIdBaseTool.cc
3  *
4  * @brief Implementation of the cheating slice id base tool class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
16 
17 using namespace pandora;
18 
19 namespace lar_content
20 {
21 
22 void CheatingSliceIdBaseTool::GetTargetParticleWeight(
23  const PfoList *const pPfoList, float &targetParticleWeight, float &totalWeight, std::function<bool(const MCParticle *const)> fCriteria)
24 {
25  targetParticleWeight = 0.f;
26  totalWeight = 0.f;
27 
28  for (const ParticleFlowObject *const pPfo : *pPfoList)
29  {
30  ClusterList twoDClusters;
31  LArPfoHelper::GetTwoDClusterList(pPfo, twoDClusters);
32 
33  CaloHitList caloHitList;
34 
35  for (const Cluster *const pCluster : twoDClusters)
36  {
37  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
38 
39  if ((TPC_VIEW_U != hitType) && (TPC_VIEW_V != hitType) && (TPC_VIEW_W != hitType))
40  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
41 
42  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
43  }
44 
45  for (const CaloHit *const pCaloHit : caloHitList)
46  {
47  float thisTargetParticleWeight = 0.f, thisTotalWeight = 0.f;
48  CheatingSliceIdBaseTool::GetTargetParticleWeight(pCaloHit, thisTargetParticleWeight, thisTotalWeight, fCriteria);
49 
50  targetParticleWeight += thisTargetParticleWeight;
51  totalWeight += thisTotalWeight;
52  }
53  }
54 }
55 
56 //------------------------------------------------------------------------------------------------------------------------------------------
57 
58 void CheatingSliceIdBaseTool::GetTargetParticleWeight(
59  const CaloHit *const pCaloHit, float &targetParticleWeight, float &totalWeight, std::function<bool(const MCParticle *const)> fCriteria)
60 {
61  targetParticleWeight = 0.f;
62  totalWeight = 0.f;
63  const MCParticleWeightMap &hitMCParticleWeightMap(pCaloHit->GetMCParticleWeightMap());
64 
65  if (hitMCParticleWeightMap.empty())
66  return;
67 
68  MCParticleList mcParticleList;
69  for (const auto &mapEntry : hitMCParticleWeightMap)
70  mcParticleList.push_back(mapEntry.first);
71  mcParticleList.sort(LArMCParticleHelper::SortByMomentum);
72 
73  for (const MCParticle *const pMCParticle : mcParticleList)
74  {
75  const float weight(hitMCParticleWeightMap.at(pMCParticle));
76  const MCParticle *const pParentMCParticle(LArMCParticleHelper::GetParentMCParticle(pMCParticle));
77 
78  if (fCriteria(pParentMCParticle))
79  targetParticleWeight += weight;
80 
81  totalWeight += weight;
82  }
83 
84  // ATTN normalise arbitrary input weights at this point
85  if (totalWeight > std::numeric_limits<float>::epsilon())
86  {
87  targetParticleWeight *= 1.f / totalWeight;
88  totalWeight = 1.f;
89  }
90  else
91  {
92  targetParticleWeight = 0.f;
93  totalWeight = 0.f;
94  }
95 }
96 
97 //------------------------------------------------------------------------------------------------------------------------------------------
98 
99 StatusCode CheatingSliceIdBaseTool::ReadSettings(const TiXmlHandle /*xmlHandle*/)
100 {
101  return STATUS_CODE_SUCCESS;
102 }
103 
104 } // namespace lar_content
Header file for the pfo helper class.
enum cvn::HType HitType
Header file for the cheating slice id base tool class.
weight
Definition: test.py:257
Header file for the lar monte carlo particle helper helper class.
Header file for the cluster helper class.
void function(int client, int *resource, int parblock, int *test, int p)