Static Public Member Functions | List of all members
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.

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.

45 {
46  for (const LArMCParticleHelper::MCContributionMap &mcParticleToGoodHitsMap : selectedMCParticleToGoodHitsMaps)
47  {
48  if (mcParticleToGoodHitsMap.empty())
49  continue;
50 
51  // Copy map contents to vector it can be sorted
52  std::vector<LArMCParticleHelper::MCParticleCaloHitListPair> mcParticleToGoodHitsVect;
53  std::copy(mcParticleToGoodHitsMap.begin(), mcParticleToGoodHitsMap.end(), std::back_inserter(mcParticleToGoodHitsVect));
54 
55  // Sort by number of hits descending
56  std::sort(mcParticleToGoodHitsVect.begin(), mcParticleToGoodHitsVect.end(),
58  // Neutrinos, then beam particles, then cosmic rays
59  const bool isANuFinalState(LArMCParticleHelper::IsBeamNeutrinoFinalState(a.first)),
60  isBNuFinalState(LArMCParticleHelper::IsBeamNeutrinoFinalState(b.first));
61 
62  if (isANuFinalState != isBNuFinalState)
63  return isANuFinalState;
64 
65  const bool isABeamParticle(LArMCParticleHelper::IsBeamParticle(a.first)),
66  isBBeamParticle(LArMCParticleHelper::IsBeamParticle(b.first));
67 
68  if (isABeamParticle != isBBeamParticle)
69  return isABeamParticle;
70 
71  // Then sort by numbers of true hits
72  if (a.second.size() != b.second.size())
73  return (a.second.size() > b.second.size());
74 
75  // Default to normal MCParticle sorting
76  return LArMCParticleHelper::SortByMomentum(a.first, b.first);
77  });
78 
79  for (const LArMCParticleHelper::MCParticleCaloHitListPair &mcParticleCaloHitPair : mcParticleToGoodHitsVect)
80  orderedMCParticleVector.push_back(mcParticleCaloHitPair.first);
81  }
82 
83  // Check that all elements of the vector are unique
84  const unsigned int nMCParticles(orderedMCParticleVector.size());
85  if (std::distance(orderedMCParticleVector.begin(), std::unique(orderedMCParticleVector.begin(), orderedMCParticleVector.end())) != nMCParticles)
86  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
87 }
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
std::pair< const pandora::MCParticle *, pandora::CaloHitList > MCParticleCaloHitListPair
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
const double a
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
T copy(T const &v)
static bool * b
Definition: config.cpp:1043
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 91 of file LArMonitoringHelper.cc.

92 {
93  // Copy map contents to vector it can be sorted
94  std::vector<LArMCParticleHelper::PfoCaloHitListPair> pfoToReconstructable2DHitsVect;
95  std::copy(pfoToReconstructable2DHitsMap.begin(), pfoToReconstructable2DHitsMap.end(), std::back_inserter(pfoToReconstructable2DHitsVect));
96 
97  // Sort by number of hits descending putting neutrino final states first
98  std::sort(pfoToReconstructable2DHitsVect.begin(), pfoToReconstructable2DHitsVect.end(),
100  // Neutrinos before cosmic rays
101  const bool isANuFinalState(LArPfoHelper::IsNeutrinoFinalState(a.first)), isBNuFinalState(LArPfoHelper::IsNeutrinoFinalState(b.first));
102 
103  if (isANuFinalState != isBNuFinalState)
104  return isANuFinalState;
105 
106  if (a.second.size() != b.second.size())
107  return (a.second.size() > b.second.size());
108 
109  // Default to normal pfo sorting
110  return LArPfoHelper::SortByNHits(a.first, b.first);
111  });
112 
113  for (const LArMCParticleHelper::PfoCaloHitListPair &pfoCaloHitPair : pfoToReconstructable2DHitsVect)
114  orderedPfoVector.push_back(pfoCaloHitPair.first);
115 
116  // Check that all elements of the vector are unique
117  const unsigned int nPfos(orderedPfoVector.size());
118  if (std::distance(orderedPfoVector.begin(), std::unique(orderedPfoVector.begin(), orderedPfoVector.end())) != nPfos)
119  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
120 }
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
const double a
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair
T copy(T const &v)
static bool * b
Definition: config.cpp:1043
static bool IsNeutrinoFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a final-state particle from a neutrino (or antineutrino) interaction.
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 203 of file LArMonitoringHelper.cc.

205 {
206  if (orderedPfoVector.empty())
207  {
208  std::cout << "No Pfos supplied." << std::endl;
209  return;
210  }
211 
212  if (orderedMCParticleVector.empty())
213  {
214  std::cout << "No MCParticles supplied." << std::endl;
215  return;
216  }
217 
218  // Get the maximum number of MCParticle to Pfos matches that need to be shown
219  unsigned int maxMatches(0);
220  for (const auto &entry : mcParticleToPfoHitSharingMap)
221  maxMatches = std::max(static_cast<unsigned int>(entry.second.size()), maxMatches);
222 
223  const bool showOthersColumn(maxMatches > nMatches);
224  const unsigned int nMatchesToShow(std::min(maxMatches, nMatches));
225 
226  // Set up the table headers
227  std::vector<std::string> tableHeaders({"MCParticle", ""});
228  for (unsigned int i = 0; i < nMatchesToShow; ++i)
229  {
230  tableHeaders.push_back("");
231  tableHeaders.push_back("Pfo");
232  tableHeaders.push_back("nSharedHits");
233  }
234 
235  if (showOthersColumn)
236  {
237  tableHeaders.push_back("");
238  tableHeaders.push_back("");
239  tableHeaders.push_back("nOtherPfos");
240  tableHeaders.push_back("nSharedHits");
241  }
242 
243  LArFormattingHelper::Table table(tableHeaders);
244 
245  // Make a new row for each MCParticle
246  for (unsigned int mcParticleId = 0; mcParticleId < orderedMCParticleVector.size(); ++mcParticleId)
247  {
248  const MCParticle *const pMCParticle(orderedMCParticleVector.at(mcParticleId));
249  LArMCParticleHelper::MCParticleToPfoHitSharingMap::const_iterator it = mcParticleToPfoHitSharingMap.find(pMCParticle);
250  LArMCParticleHelper::PfoToSharedHitsVector pfoToSharedHitsVector;
251 
252  if (it != mcParticleToPfoHitSharingMap.end())
253  pfoToSharedHitsVector = it->second;
254 
255  const LArFormattingHelper::Color mcCol(
259 
260  // ATTN enumerate from 1 to match event validation algorithm
261  table.AddElement(mcParticleId + 1, LArFormattingHelper::REGULAR, mcCol);
262 
263  // Get the matched Pfos
264  unsigned int nPfosShown(0);
265  unsigned int nOtherHits(0);
266  for (const auto &pfoNSharedHitsPair : pfoToSharedHitsVector)
267  {
268  for (unsigned int pfoId = 0; pfoId < orderedPfoVector.size(); ++pfoId)
269  {
270  if (pfoNSharedHitsPair.first != orderedPfoVector.at(pfoId))
271  continue;
272 
273  if (nPfosShown < nMatchesToShow)
274  {
275  // ATTN enumerate from 1 to match event validation algorithm
276  const LArFormattingHelper::Color pfoCol(
278  table.AddElement(pfoId + 1, LArFormattingHelper::REGULAR, pfoCol);
279  table.AddElement(pfoNSharedHitsPair.second.size(), LArFormattingHelper::REGULAR, pfoCol);
280  nPfosShown++;
281  }
282  else
283  {
284  nOtherHits += pfoNSharedHitsPair.second.size();
285  }
286  break;
287  }
288  }
289 
290  // Pad the rest of the row with empty entries
291  for (unsigned int i = 0; i < nMatchesToShow - nPfosShown; ++i)
292  {
293  table.AddElement("");
294  table.AddElement("");
295  }
296 
297  // Print any remaining matches
298  if (!showOthersColumn)
299  continue;
300 
301  if (nOtherHits != 0)
302  {
303  table.AddElement(pfoToSharedHitsVector.size() - nPfosShown);
304  table.AddElement(nOtherHits);
305  }
306  else
307  {
308  table.AddElement("");
309  table.AddElement("");
310  }
311  }
312  table.Print();
313 }
QList< Entry > entry
std::vector< PfoCaloHitListPair > PfoToSharedHitsVector
intermediate_table::const_iterator const_iterator
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
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.
QTextStream & endl(QTextStream &s)
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 124 of file LArMonitoringHelper.cc.

126 {
127  if (selectedMCParticleToGoodHitsMap.empty())
128  {
129  std::cout << "No MCParticles supplied." << std::endl;
130  return;
131  }
132 
133  LArFormattingHelper::Table table({"ID", "NUANCE", "TYPE", "", "E", "dist", "", "nGoodHits", "U", "V", "W"});
134 
135  unsigned int usedParticleCount(0);
136  for (unsigned int id = 0; id < orderedMCParticleVector.size(); ++id)
137  {
138  const MCParticle *const pMCParticle(orderedMCParticleVector.at(id));
139 
140  LArMCParticleHelper::MCContributionMap::const_iterator it = selectedMCParticleToGoodHitsMap.find(pMCParticle);
141  if (selectedMCParticleToGoodHitsMap.end() == it)
142  continue; // ATTN MCParticles in selectedMCParticleToGoodHitsMap may be a subset of orderedMCParticleVector
143 
144  // ATTN enumerate from 1 to match event validation algorithm
145  table.AddElement(id + 1);
146  table.AddElement(LArMCParticleHelper::GetNuanceCode(pMCParticle));
147  table.AddElement(PdgTable::GetParticleName(pMCParticle->GetParticleId()));
148 
149  table.AddElement(pMCParticle->GetEnergy());
150  table.AddElement((pMCParticle->GetEndpoint() - pMCParticle->GetVertex()).GetMagnitude());
151 
152  table.AddElement(it->second.size());
153  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, it->second));
154  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, it->second));
155  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, it->second));
156 
157  usedParticleCount++;
158  }
159 
160  // Check every MCParticle in selectedMCParticleToGoodHitsMap has been printed
161  if (usedParticleCount != selectedMCParticleToGoodHitsMap.size())
162  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
163 
164  table.Print();
165 }
intermediate_table::const_iterator const_iterator
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
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.
QTextStream & endl(QTextStream &s)
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 169 of file LArMonitoringHelper.cc.

170 {
171  if (pfoToReconstructable2DHitsMap.empty())
172  {
173  std::cout << "No Pfos supplied." << std::endl;
174  return;
175  }
176 
177  LArFormattingHelper::Table table({"ID", "PID", "Is Nu FS", "", "nGoodHits", "U", "V", "W"});
178 
179  for (unsigned int id = 0; id < orderedPfoVector.size(); ++id)
180  {
181  const ParticleFlowObject *const pPfo(orderedPfoVector.at(id));
182 
183  LArMCParticleHelper::PfoContributionMap::const_iterator it = pfoToReconstructable2DHitsMap.find(pPfo);
184  if (pfoToReconstructable2DHitsMap.end() == it)
185  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
186 
187  // ATTN enumerate from 1 to match event validation algorithm
188  table.AddElement(id + 1);
189  table.AddElement(pPfo->GetParticleId());
190  table.AddElement(LArPfoHelper::IsNeutrinoFinalState(pPfo));
191 
192  table.AddElement(it->second.size());
193  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, it->second));
194  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, it->second));
195  table.AddElement(LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, it->second));
196  }
197 
198  table.Print();
199 }
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.
QTextStream & endl(QTextStream &s)

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