LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::LArMonitoringHelper Class Reference

LArMonitoringHelper class. More...

#include "LArMonitoringHelper.h"

Static Public Member Functions

static unsigned int CountHitsByType (const pandora::HitType hitType, const pandora::CaloHitList &caloHitList)
 Count the number of calo hits, in a provided list, of a specified type. More...
 
static void GetOrderedMCParticleVector (const LArMCParticleHelper::MCContributionMapVector &selectedMCParticleToGoodHitsMaps, pandora::MCParticleVector &orderedMCParticleVector)
 Order input MCParticles by their number of hits. More...
 
static void GetOrderedPfoVector (const LArMCParticleHelper::PfoContributionMap &pfoToReconstructable2DHitsMap, pandora::PfoVector &orderedPfoVector)
 Order input Pfos by their number of hits. More...
 
static void PrintMCParticleTable (const LArMCParticleHelper::MCContributionMap &selectedMCParticleToGoodHitsMaps, const pandora::MCParticleVector &orderedMCParticleVector)
 Print details of selected MCParticles to the terminal in a table. More...
 
static void PrintPfoTable (const LArMCParticleHelper::PfoContributionMap &pfoToReconstructable2DHitsMap, const pandora::PfoVector &orderedPfoVector)
 Print details of input Pfos to the terminal in a table. More...
 
static void PrintMatchingTable (const pandora::PfoVector &orderedPfoVector, const pandora::MCParticleVector &orderedMCParticleVector, const LArMCParticleHelper::MCParticleToPfoHitSharingMap &mcParticleToPfoHitSharingMap, const unsigned int nMatches)
 Print the shared good hits between all Pfos and MCParticles. More...
 

Detailed Description

LArMonitoringHelper class.

Definition at line 21 of file LArMonitoringHelper.h.

Member Function Documentation

unsigned int lar_content::LArMonitoringHelper::CountHitsByType ( const pandora::HitType  hitType,
const pandora::CaloHitList &  caloHitList 
)
static

Count the number of calo hits, in a provided list, of a specified type.

Parameters
hitTypethe hit type
caloHitListthe calo hit list
Returns
the number of calo hits of the specified type

Definition at line 28 of file LArMonitoringHelper.cc.

Referenced by lar_content::MCParticleMonitoringAlgorithm::PrintMCParticle(), lar_content::CosmicRayTaggingMonitoringTool::PrintPfoTable(), lar_content::MCParticleMonitoringAlgorithm::PrintPrimaryMCParticles(), lar_content::EventValidationAlgorithm::ProcessOutput(), and lar_content::LArMCParticleHelper::SelectParticlesByHitCount().

29 {
30  unsigned int nHitsOfSpecifiedType(0);
31 
32  for (const CaloHit *const pCaloHit : caloHitList)
33  {
34  if (hitType == pCaloHit->GetHitType())
35  ++nHitsOfSpecifiedType;
36  }
37 
38  return nHitsOfSpecifiedType;
39 }
void lar_content::LArMonitoringHelper::GetOrderedMCParticleVector ( const LArMCParticleHelper::MCContributionMapVector selectedMCParticleToGoodHitsMaps,
pandora::MCParticleVector &  orderedMCParticleVector 
)
static

Order input MCParticles by their number of hits.

Parameters
selectedMCParticleToGoodHitsMapsthe input vector of mappings from selected reconstructable MCParticles to their good hits
orderedMCParticleVectorthe output vector of ordered MCParticles

Definition at line 43 of file LArMonitoringHelper.cc.

Referenced by lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::EventValidationAlgorithm::InterpretMatching(), lar_content::MCParticleMonitoringAlgorithm::PrintPrimaryMCParticles(), lar_content::EventValidationAlgorithm::ProcessOutput(), and lar_content::PfoValidationAlgorithm::Run().

44 {
45  for (const LArMCParticleHelper::MCContributionMap &mcParticleToGoodHitsMap : selectedMCParticleToGoodHitsMaps)
46  {
47  if (mcParticleToGoodHitsMap.empty())
48  continue;
49 
50  // Copy map contents to vector it can be sorted
51  std::vector<LArMCParticleHelper::MCParticleCaloHitListPair> mcParticleToGoodHitsVect;
52  std::copy(mcParticleToGoodHitsMap.begin(), mcParticleToGoodHitsMap.end(), std::back_inserter(mcParticleToGoodHitsVect));
53 
54  // Sort by number of hits descending
55  std::sort(mcParticleToGoodHitsVect.begin(), mcParticleToGoodHitsVect.end(), [] (const LArMCParticleHelper::MCParticleCaloHitListPair &a, const LArMCParticleHelper::MCParticleCaloHitListPair &b) -> bool
56  {
57  // Neutrinos, then beam particles, then cosmic rays
58  const bool isANuFinalState(LArMCParticleHelper::IsBeamNeutrinoFinalState(a.first)), isBNuFinalState(LArMCParticleHelper::IsBeamNeutrinoFinalState(b.first));
59 
60  if (isANuFinalState != isBNuFinalState)
61  return isANuFinalState;
62 
63  const bool isABeamParticle(LArMCParticleHelper::IsBeamParticle(a.first)), isBBeamParticle(LArMCParticleHelper::IsBeamParticle(b.first));
64 
65  if (isABeamParticle != isBBeamParticle)
66  return isABeamParticle;
67 
68  // Then sort by numbers of true hits
69  if (a.second.size() != b.second.size())
70  return (a.second.size() > b.second.size());
71 
72  // Default to normal MCParticle sorting
73  return LArMCParticleHelper::SortByMomentum(a.first, b.first);
74  });
75 
76  for (const LArMCParticleHelper::MCParticleCaloHitListPair &mcParticleCaloHitPair : mcParticleToGoodHitsVect)
77  orderedMCParticleVector.push_back(mcParticleCaloHitPair.first);
78  }
79 
80  // Check that all elements of the vector are unique
81  const unsigned int nMCParticles(orderedMCParticleVector.size());
82  if (std::distance(orderedMCParticleVector.begin(), std::unique(orderedMCParticleVector.begin(), orderedMCParticleVector.end())) != nMCParticles)
83  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
84 }
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
std::pair< const pandora::MCParticle *, pandora::CaloHitList > MCParticleCaloHitListPair
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
void lar_content::LArMonitoringHelper::GetOrderedPfoVector ( const LArMCParticleHelper::PfoContributionMap pfoToReconstructable2DHitsMap,
pandora::PfoVector &  orderedPfoVector 
)
static

Order input Pfos by their number of hits.

Parameters
pfoToReconstructable2DHitsMapthe input vector of mappings from Pfos to their reconstructable hits
orderedPfoVectorthe output vector of ordered Pfos

Definition at line 88 of file LArMonitoringHelper.cc.

Referenced by lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), lar_content::EventValidationAlgorithm::ProcessOutput(), and lar_content::PfoValidationAlgorithm::Run().

89 {
90  // Copy map contents to vector it can be sorted
91  std::vector<LArMCParticleHelper::PfoCaloHitListPair> pfoToReconstructable2DHitsVect;
92  std::copy(pfoToReconstructable2DHitsMap.begin(), pfoToReconstructable2DHitsMap.end(), std::back_inserter(pfoToReconstructable2DHitsVect));
93 
94  // Sort by number of hits descending putting neutrino final states first
95  std::sort(pfoToReconstructable2DHitsVect.begin(), pfoToReconstructable2DHitsVect.end(), [] (const LArMCParticleHelper::PfoCaloHitListPair &a, const LArMCParticleHelper::PfoCaloHitListPair &b) -> bool
96  {
97  // Neutrinos before cosmic rays
98  const bool isANuFinalState(LArPfoHelper::IsNeutrinoFinalState(a.first)), isBNuFinalState(LArPfoHelper::IsNeutrinoFinalState(b.first));
99 
100  if (isANuFinalState != isBNuFinalState)
101  return isANuFinalState;
102 
103  if (a.second.size() != b.second.size())
104  return (a.second.size() > b.second.size());
105 
106  // Default to normal pfo sorting
107  return LArPfoHelper::SortByNHits(a.first, b.first);
108  });
109 
110  for (const LArMCParticleHelper::PfoCaloHitListPair &pfoCaloHitPair : pfoToReconstructable2DHitsVect)
111  orderedPfoVector.push_back(pfoCaloHitPair.first);
112 
113  // Check that all elements of the vector are unique
114  const unsigned int nPfos(orderedPfoVector.size());
115  if (std::distance(orderedPfoVector.begin(), std::unique(orderedPfoVector.begin(), orderedPfoVector.end())) != nPfos)
116  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
117 }
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
static bool IsNeutrinoFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a final-state particle from a neutrino (or antineutrino) interaction.
std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair
void lar_content::LArMonitoringHelper::PrintMatchingTable ( const pandora::PfoVector &  orderedPfoVector,
const pandora::MCParticleVector &  orderedMCParticleVector,
const LArMCParticleHelper::MCParticleToPfoHitSharingMap mcParticleToPfoHitSharingMap,
const unsigned int  nMatches 
)
static

Print the shared good hits between all Pfos and MCParticles.

Parameters
orderedPfoVectorthe input vector of ordered Pfos
orderedMCParticleVectorthe input vector of ordered MCParticles
mcParticleToPfoHitSharingMapthe output mapping from selected reconstructable MCParticles to Pfos and the number hits shared
nMatchesthe maximum number of Pfo matches to show

Definition at line 199 of file LArMonitoringHelper.cc.

References lar_content::LArFormattingHelper::Table::AddElement(), max, min, and lar_content::LArFormattingHelper::Table::Print().

Referenced by lar_content::PfoValidationAlgorithm::Run().

200 {
201  if (orderedPfoVector.empty())
202  {
203  std::cout << "No Pfos supplied." << std::endl;
204  return;
205  }
206 
207  if (orderedMCParticleVector.empty())
208  {
209  std::cout << "No MCParticles supplied." << std::endl;
210  return;
211  }
212 
213  // Get the maximum number of MCParticle to Pfos matches that need to be shown
214  unsigned int maxMatches(0);
215  for (const auto &entry : mcParticleToPfoHitSharingMap)
216  maxMatches = std::max(static_cast<unsigned int>(entry.second.size()), maxMatches);
217 
218  const bool showOthersColumn(maxMatches > nMatches);
219  const unsigned int nMatchesToShow(std::min(maxMatches, nMatches));
220 
221  // Set up the table headers
222  std::vector<std::string> tableHeaders({"MCParticle",""});
223  for (unsigned int i = 0; i < nMatchesToShow; ++i)
224  {
225  tableHeaders.push_back("");
226  tableHeaders.push_back("Pfo");
227  tableHeaders.push_back("nSharedHits");
228  }
229 
230  if (showOthersColumn)
231  {
232  tableHeaders.push_back("");
233  tableHeaders.push_back("");
234  tableHeaders.push_back("nOtherPfos");
235  tableHeaders.push_back("nSharedHits");
236  }
237 
238  LArFormattingHelper::Table table(tableHeaders);
239 
240  // Make a new row for each MCParticle
241  for (unsigned int mcParticleId = 0; mcParticleId < orderedMCParticleVector.size(); ++mcParticleId)
242  {
243  LArMCParticleHelper::MCParticleToPfoHitSharingMap::const_iterator it = mcParticleToPfoHitSharingMap.find(orderedMCParticleVector.at(mcParticleId));
244  if (it == mcParticleToPfoHitSharingMap.end())
245  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
246 
247  const MCParticle *const pMCParticle(it->first);
248  const LArFormattingHelper::Color mcCol(
252  )
253  );
254 
255  // ATTN enumerate from 1 to match event validation algorithm
256  table.AddElement(mcParticleId + 1, LArFormattingHelper::REGULAR, mcCol);
257 
258  // Get the matched Pfos
259  unsigned int nPfosShown(0);
260  unsigned int nOtherHits(0);
261  for (const auto &pfoNSharedHitsPair : it->second)
262  {
263  for (unsigned int pfoId = 0; pfoId < orderedPfoVector.size(); ++pfoId)
264  {
265  if (pfoNSharedHitsPair.first != orderedPfoVector.at(pfoId)) continue;
266 
267  if (nPfosShown < nMatchesToShow)
268  {
269  // ATTN enumerate from 1 to match event validation algorithm
271  table.AddElement(pfoId + 1, LArFormattingHelper::REGULAR, pfoCol);
272  table.AddElement(pfoNSharedHitsPair.second.size(), LArFormattingHelper::REGULAR, pfoCol);
273  nPfosShown++;
274  }
275  else
276  {
277  nOtherHits += pfoNSharedHitsPair.second.size();
278  }
279  break;
280  }
281  }
282 
283  // Pad the rest of the row with empty entries
284  for (unsigned int i = 0; i < nMatchesToShow - nPfosShown; ++i)
285  {
286  table.AddElement("");
287  table.AddElement("");
288  }
289 
290  // Print any remaining matches
291  if (!showOthersColumn) continue;
292 
293  if (nOtherHits != 0)
294  {
295  table.AddElement(it->second.size() - nPfosShown);
296  table.AddElement(nOtherHits);
297  }
298  else
299  {
300  table.AddElement("");
301  table.AddElement("");
302  }
303  }
304  table.Print();
305 }
Int_t max
Definition: plot.C:27
intermediate_table::const_iterator const_iterator
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
Int_t min
Definition: plot.C:26
static bool IsNeutrinoFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a final-state particle from a neutrino (or antineutrino) interaction.
static bool IsBeamNeutrinoFinalState(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary neutrino final state MCParticle.
void lar_content::LArMonitoringHelper::PrintMCParticleTable ( const LArMCParticleHelper::MCContributionMap selectedMCParticleToGoodHitsMaps,
const pandora::MCParticleVector &  orderedMCParticleVector 
)
static

Print details of selected MCParticles to the terminal in a table.

Parameters
selectedMCParticleToGoodHitsMapthe input mapping from selected reconstructable MCParticles to their good hits
orderedMCParticleVectorthe input vector of ordered MCParticles

Definition at line 121 of file LArMonitoringHelper.cc.

Referenced by lar_content::CosmicRayTaggingMonitoringTool::FindAmbiguousPfos(), and lar_content::PfoValidationAlgorithm::Run().

122 {
123  if (selectedMCParticleToGoodHitsMap.empty())
124  {
125  std::cout << "No MCParticles supplied." << std::endl;
126  return;
127  }
128 
129  LArFormattingHelper::Table table({"ID", "NUANCE", "TYPE", "", "E", "dist", "", "nGoodHits", "U", "V", "W"});
130 
131  unsigned int usedParticleCount(0);
132  for (unsigned int id = 0; id < orderedMCParticleVector.size(); ++id)
133  {
134  const MCParticle *const pMCParticle(orderedMCParticleVector.at(id));
135 
136  LArMCParticleHelper::MCContributionMap::const_iterator it = selectedMCParticleToGoodHitsMap.find(pMCParticle);
137  if (selectedMCParticleToGoodHitsMap.end() == it)
138  continue; // ATTN MCParticles in selectedMCParticleToGoodHitsMap may be a subset of orderedMCParticleVector
139 
140  // ATTN enumerate from 1 to match event validation algorithm
141  table.AddElement(id + 1);
142  table.AddElement(LArMCParticleHelper::GetNuanceCode(pMCParticle));
143  table.AddElement(PdgTable::GetParticleName(pMCParticle->GetParticleId()));
144 
145  table.AddElement(pMCParticle->GetEnergy());
146  table.AddElement((pMCParticle->GetEndpoint() - pMCParticle->GetVertex()).GetMagnitude());
147 
148  table.AddElement(it->second.size());
149  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, it->second));
150  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, it->second));
151  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, it->second));
152 
153  usedParticleCount++;
154  }
155 
156  // Check every MCParticle in selectedMCParticleToGoodHitsMap has been printed
157  if (usedParticleCount != selectedMCParticleToGoodHitsMap.size())
158  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
159 
160  table.Print();
161 }
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
intermediate_table::const_iterator const_iterator
static unsigned int CountHitsByType(const pandora::HitType hitType, const pandora::CaloHitList &caloHitList)
Count the number of calo hits, in a provided list, of a specified type.
void lar_content::LArMonitoringHelper::PrintPfoTable ( const LArMCParticleHelper::PfoContributionMap pfoToReconstructable2DHitsMap,
const pandora::PfoVector &  orderedPfoVector 
)
static

Print details of input Pfos to the terminal in a table.

Parameters
pfoToReconstructable2DHitsMapthe input vector of mappings from Pfos to their reconstructable hits
orderedPfoVectorthe input vector of ordered Pfos

Definition at line 165 of file LArMonitoringHelper.cc.

Referenced by lar_content::PfoValidationAlgorithm::Run().

166 {
167  if (pfoToReconstructable2DHitsMap.empty())
168  {
169  std::cout << "No Pfos supplied." << std::endl;
170  return;
171  }
172 
173  LArFormattingHelper::Table table({"ID", "PID", "Is Nu FS", "", "nGoodHits", "U", "V", "W"});
174 
175  for (unsigned int id = 0; id < orderedPfoVector.size(); ++id)
176  {
177  const ParticleFlowObject *const pPfo(orderedPfoVector.at(id));
178 
179  LArMCParticleHelper::PfoContributionMap::const_iterator it = pfoToReconstructable2DHitsMap.find(pPfo);
180  if (pfoToReconstructable2DHitsMap.end() == it)
181  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
182 
183  // ATTN enumerate from 1 to match event validation algorithm
184  table.AddElement(id + 1);
185  table.AddElement(pPfo->GetParticleId());
186  table.AddElement(LArPfoHelper::IsNeutrinoFinalState(pPfo));
187 
188  table.AddElement(it->second.size());
189  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, it->second));
190  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, it->second));
191  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, it->second));
192  }
193 
194  table.Print();
195 }
intermediate_table::const_iterator const_iterator
static bool IsNeutrinoFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a final-state particle from a neutrino (or antineutrino) interaction.
static unsigned int CountHitsByType(const pandora::HitType hitType, const pandora::CaloHitList &caloHitList)
Count the number of calo hits, in a provided list, of a specified type.

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