9 #include "Pandora/PdgTable.h" 11 #include "Objects/CaloHit.h" 12 #include "Objects/MCParticle.h" 13 #include "Objects/ParticleFlowObject.h" 15 #include "Helpers/MCParticleHelper.h" 28 unsigned int LArMonitoringHelper::CountHitsByType(
const HitType hitType,
const CaloHitList &caloHitList)
30 unsigned int nHitsOfSpecifiedType(0);
32 for (
const CaloHit *
const pCaloHit : caloHitList)
34 if (hitType == pCaloHit->GetHitType())
35 ++nHitsOfSpecifiedType;
38 return nHitsOfSpecifiedType;
47 if (mcParticleToGoodHitsMap.empty())
51 std::vector<LArMCParticleHelper::MCParticleCaloHitListPair> mcParticleToGoodHitsVect;
52 std::copy(mcParticleToGoodHitsMap.begin(), mcParticleToGoodHitsMap.end(), std::back_inserter(mcParticleToGoodHitsVect));
58 const bool isANuFinalState(LArMCParticleHelper::IsBeamNeutrinoFinalState(a.first)), isBNuFinalState(LArMCParticleHelper::IsBeamNeutrinoFinalState(b.first));
60 if (isANuFinalState != isBNuFinalState)
61 return isANuFinalState;
63 const bool isABeamParticle(LArMCParticleHelper::IsBeamParticle(a.first)), isBBeamParticle(LArMCParticleHelper::IsBeamParticle(b.first));
65 if (isABeamParticle != isBBeamParticle)
66 return isABeamParticle;
69 if (a.second.size() != b.second.size())
70 return (a.second.size() > b.second.size());
73 return LArMCParticleHelper::SortByMomentum(a.first, b.first);
77 orderedMCParticleVector.push_back(mcParticleCaloHitPair.first);
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);
91 std::vector<LArMCParticleHelper::PfoCaloHitListPair> pfoToReconstructable2DHitsVect;
92 std::copy(pfoToReconstructable2DHitsMap.begin(), pfoToReconstructable2DHitsMap.end(), std::back_inserter(pfoToReconstructable2DHitsVect));
98 const bool isANuFinalState(LArPfoHelper::IsNeutrinoFinalState(a.first)), isBNuFinalState(LArPfoHelper::IsNeutrinoFinalState(b.first));
100 if (isANuFinalState != isBNuFinalState)
101 return isANuFinalState;
103 if (a.second.size() != b.second.size())
104 return (a.second.size() > b.second.size());
107 return LArPfoHelper::SortByNHits(a.first, b.first);
111 orderedPfoVector.push_back(pfoCaloHitPair.first);
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);
123 if (selectedMCParticleToGoodHitsMap.empty())
125 std::cout <<
"No MCParticles supplied." << std::endl;
129 LArFormattingHelper::Table table({
"ID",
"NUANCE",
"TYPE",
"",
"E",
"dist",
"",
"nGoodHits",
"U",
"V",
"W"});
131 unsigned int usedParticleCount(0);
132 for (
unsigned int id = 0;
id < orderedMCParticleVector.size(); ++id)
134 const MCParticle *
const pMCParticle(orderedMCParticleVector.at(
id));
137 if (selectedMCParticleToGoodHitsMap.end() == it)
141 table.AddElement(
id + 1);
142 table.AddElement(LArMCParticleHelper::GetNuanceCode(pMCParticle));
143 table.AddElement(PdgTable::GetParticleName(pMCParticle->GetParticleId()));
145 table.AddElement(pMCParticle->GetEnergy());
146 table.AddElement((pMCParticle->GetEndpoint() - pMCParticle->GetVertex()).GetMagnitude());
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));
157 if (usedParticleCount != selectedMCParticleToGoodHitsMap.size())
158 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
167 if (pfoToReconstructable2DHitsMap.empty())
169 std::cout <<
"No Pfos supplied." << std::endl;
175 for (
unsigned int id = 0;
id < orderedPfoVector.size(); ++id)
177 const ParticleFlowObject *
const pPfo(orderedPfoVector.at(
id));
180 if (pfoToReconstructable2DHitsMap.end() == it)
181 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
184 table.AddElement(
id + 1);
185 table.AddElement(pPfo->GetParticleId());
186 table.AddElement(LArPfoHelper::IsNeutrinoFinalState(pPfo));
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));
201 if (orderedPfoVector.empty())
203 std::cout <<
"No Pfos supplied." << std::endl;
207 if (orderedMCParticleVector.empty())
209 std::cout <<
"No MCParticles supplied." << std::endl;
214 unsigned int maxMatches(0);
215 for (
const auto &entry : mcParticleToPfoHitSharingMap)
216 maxMatches =
std::max(static_cast<unsigned int>(entry.second.size()), maxMatches);
218 const bool showOthersColumn(maxMatches > nMatches);
219 const unsigned int nMatchesToShow(
std::min(maxMatches, nMatches));
222 std::vector<std::string> tableHeaders({
"MCParticle",
""});
223 for (
unsigned int i = 0; i < nMatchesToShow; ++i)
225 tableHeaders.push_back(
"");
226 tableHeaders.push_back(
"Pfo");
227 tableHeaders.push_back(
"nSharedHits");
230 if (showOthersColumn)
232 tableHeaders.push_back(
"");
233 tableHeaders.push_back(
"");
234 tableHeaders.push_back(
"nOtherPfos");
235 tableHeaders.push_back(
"nSharedHits");
241 for (
unsigned int mcParticleId = 0; mcParticleId < orderedMCParticleVector.size(); ++mcParticleId)
244 if (it == mcParticleToPfoHitSharingMap.end())
245 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
247 const MCParticle *
const pMCParticle(it->first);
249 LArMCParticleHelper::IsBeamNeutrinoFinalState(pMCParticle) ?
250 LArFormattingHelper::LIGHT_GREEN : (LArMCParticleHelper::IsBeamParticle(pMCParticle) ?
251 LArFormattingHelper::LIGHT_BLUE : LArFormattingHelper::LIGHT_RED
256 table.
AddElement(mcParticleId + 1, LArFormattingHelper::REGULAR, mcCol);
259 unsigned int nPfosShown(0);
260 unsigned int nOtherHits(0);
261 for (
const auto &pfoNSharedHitsPair : it->second)
263 for (
unsigned int pfoId = 0; pfoId < orderedPfoVector.size(); ++pfoId)
265 if (pfoNSharedHitsPair.first != orderedPfoVector.at(pfoId))
continue;
267 if (nPfosShown < nMatchesToShow)
270 const LArFormattingHelper::Color pfoCol(LArPfoHelper::IsNeutrinoFinalState(pfoNSharedHitsPair.first) ? LArFormattingHelper::LIGHT_GREEN : LArFormattingHelper::LIGHT_RED);
271 table.
AddElement(pfoId + 1, LArFormattingHelper::REGULAR, pfoCol);
272 table.
AddElement(pfoNSharedHitsPair.second.size(), LArFormattingHelper::REGULAR, pfoCol);
277 nOtherHits += pfoNSharedHitsPair.second.size();
284 for (
unsigned int i = 0; i < nMatchesToShow - nPfosShown; ++i)
291 if (!showOthersColumn)
continue;
295 table.
AddElement(it->second.size() - nPfosShown);
Header file for the pfo helper class.
Header file for the lar monitoring helper helper class.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
Color
Style code enumeration.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
std::map< const pandora::MCParticle *, PfoToSharedHitsVector > MCParticleToPfoHitSharingMap
void AddElement(const T &value, const Style style=REGULAR, const Color color=DEFAULT)
Add an element to the table into the next (non-separator) column.
std::vector< MCContributionMap > MCContributionMapVector
std::pair< const pandora::MCParticle *, pandora::CaloHitList > MCParticleCaloHitListPair
void Print() const
Print the table.
std::unordered_map< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoContributionMap
std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair