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;
43 void LArMonitoringHelper::GetOrderedMCParticleVector(
48 if (mcParticleToGoodHitsMap.empty())
52 std::vector<LArMCParticleHelper::MCParticleCaloHitListPair> mcParticleToGoodHitsVect;
53 std::copy(mcParticleToGoodHitsMap.begin(), mcParticleToGoodHitsMap.end(), std::back_inserter(mcParticleToGoodHitsVect));
56 std::sort(mcParticleToGoodHitsVect.begin(), mcParticleToGoodHitsVect.end(),
59 const bool isANuFinalState(LArMCParticleHelper::IsBeamNeutrinoFinalState(a.first)),
60 isBNuFinalState(LArMCParticleHelper::IsBeamNeutrinoFinalState(
b.first));
62 if (isANuFinalState != isBNuFinalState)
63 return isANuFinalState;
65 const bool isABeamParticle(LArMCParticleHelper::IsBeamParticle(a.first)),
66 isBBeamParticle(LArMCParticleHelper::IsBeamParticle(
b.first));
68 if (isABeamParticle != isBBeamParticle)
69 return isABeamParticle;
72 if (a.second.size() !=
b.second.size())
73 return (a.second.size() >
b.second.size());
76 return LArMCParticleHelper::SortByMomentum(a.first,
b.first);
80 orderedMCParticleVector.push_back(mcParticleCaloHitPair.first);
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);
94 std::vector<LArMCParticleHelper::PfoCaloHitListPair> pfoToReconstructable2DHitsVect;
95 std::copy(pfoToReconstructable2DHitsMap.begin(), pfoToReconstructable2DHitsMap.end(), std::back_inserter(pfoToReconstructable2DHitsVect));
98 std::sort(pfoToReconstructable2DHitsVect.begin(), pfoToReconstructable2DHitsVect.end(),
101 const bool isANuFinalState(LArPfoHelper::IsNeutrinoFinalState(a.first)), isBNuFinalState(LArPfoHelper::IsNeutrinoFinalState(
b.first));
103 if (isANuFinalState != isBNuFinalState)
104 return isANuFinalState;
106 if (a.second.size() !=
b.second.size())
107 return (a.second.size() >
b.second.size());
110 return LArPfoHelper::SortByNHits(a.first,
b.first);
114 orderedPfoVector.push_back(pfoCaloHitPair.first);
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);
124 void LArMonitoringHelper::PrintMCParticleTable(
127 if (selectedMCParticleToGoodHitsMap.empty())
129 std::cout <<
"No MCParticles supplied." <<
std::endl;
133 LArFormattingHelper::Table table({
"ID",
"NUANCE",
"TYPE",
"",
"E",
"dist",
"",
"nGoodHits",
"U",
"V",
"W"});
135 unsigned int usedParticleCount(0);
136 for (
unsigned int id = 0;
id < orderedMCParticleVector.size(); ++id)
138 const MCParticle *
const pMCParticle(orderedMCParticleVector.at(
id));
141 if (selectedMCParticleToGoodHitsMap.end() == it)
145 table.AddElement(
id + 1);
146 table.AddElement(LArMCParticleHelper::GetNuanceCode(pMCParticle));
147 table.AddElement(PdgTable::GetParticleName(pMCParticle->GetParticleId()));
149 table.AddElement(pMCParticle->GetEnergy());
150 table.AddElement((pMCParticle->GetEndpoint() - pMCParticle->GetVertex()).GetMagnitude());
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));
161 if (usedParticleCount != selectedMCParticleToGoodHitsMap.size())
162 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
171 if (pfoToReconstructable2DHitsMap.empty())
173 std::cout <<
"No Pfos supplied." <<
std::endl;
179 for (
unsigned int id = 0;
id < orderedPfoVector.size(); ++id)
181 const ParticleFlowObject *
const pPfo(orderedPfoVector.at(
id));
184 if (pfoToReconstructable2DHitsMap.end() == it)
185 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
188 table.AddElement(
id + 1);
189 table.AddElement(pPfo->GetParticleId());
190 table.AddElement(LArPfoHelper::IsNeutrinoFinalState(pPfo));
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));
203 void LArMonitoringHelper::PrintMatchingTable(
const PfoVector &orderedPfoVector,
const MCParticleVector &orderedMCParticleVector,
206 if (orderedPfoVector.empty())
208 std::cout <<
"No Pfos supplied." <<
std::endl;
212 if (orderedMCParticleVector.empty())
214 std::cout <<
"No MCParticles supplied." <<
std::endl;
219 unsigned int maxMatches(0);
220 for (
const auto &
entry : mcParticleToPfoHitSharingMap)
221 maxMatches =
std::max(static_cast<unsigned int>(
entry.second.size()), maxMatches);
223 const bool showOthersColumn(maxMatches > nMatches);
224 const unsigned int nMatchesToShow(
std::min(maxMatches, nMatches));
227 std::vector<std::string> tableHeaders({
"MCParticle",
""});
228 for (
unsigned int i = 0; i < nMatchesToShow; ++i)
230 tableHeaders.push_back(
"");
231 tableHeaders.push_back(
"Pfo");
232 tableHeaders.push_back(
"nSharedHits");
235 if (showOthersColumn)
237 tableHeaders.push_back(
"");
238 tableHeaders.push_back(
"");
239 tableHeaders.push_back(
"nOtherPfos");
240 tableHeaders.push_back(
"nSharedHits");
246 for (
unsigned int mcParticleId = 0; mcParticleId < orderedMCParticleVector.size(); ++mcParticleId)
248 const MCParticle *
const pMCParticle(orderedMCParticleVector.at(mcParticleId));
252 if (it != mcParticleToPfoHitSharingMap.end())
253 pfoToSharedHitsVector = it->second;
256 LArMCParticleHelper::IsBeamNeutrinoFinalState(pMCParticle)
257 ? LArFormattingHelper::LIGHT_GREEN
258 : (LArMCParticleHelper::IsBeamParticle(pMCParticle) ? LArFormattingHelper::LIGHT_BLUE : LArFormattingHelper::LIGHT_RED));
261 table.
AddElement(mcParticleId + 1, LArFormattingHelper::REGULAR, mcCol);
264 unsigned int nPfosShown(0);
265 unsigned int nOtherHits(0);
266 for (
const auto &pfoNSharedHitsPair : pfoToSharedHitsVector)
268 for (
unsigned int pfoId = 0; pfoId < orderedPfoVector.size(); ++pfoId)
270 if (pfoNSharedHitsPair.first != orderedPfoVector.at(pfoId))
273 if (nPfosShown < nMatchesToShow)
277 LArPfoHelper::IsNeutrinoFinalState(pfoNSharedHitsPair.first) ? LArFormattingHelper::LIGHT_GREEN : LArFormattingHelper::LIGHT_RED);
278 table.
AddElement(pfoId + 1, LArFormattingHelper::REGULAR, pfoCol);
279 table.
AddElement(pfoNSharedHitsPair.second.size(), LArFormattingHelper::REGULAR, pfoCol);
284 nOtherHits += pfoNSharedHitsPair.second.size();
291 for (
unsigned int i = 0; i < nMatchesToShow - nPfosShown; ++i)
298 if (!showOthersColumn)
303 table.
AddElement(pfoToSharedHitsVector.size() - nPfosShown);
Header file for the pfo helper class.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
std::pair< const pandora::MCParticle *, pandora::CaloHitList > MCParticleCaloHitListPair
std::map< const pandora::MCParticle *, PfoToSharedHitsVector > MCParticleToPfoHitSharingMap
std::vector< PfoCaloHitListPair > PfoToSharedHitsVector
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
Header file for the lar monitoring helper helper class.
Color
Style code enumeration.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
static int max(int a, int b)
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
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair
void Print() const
Print the table.
std::unordered_map< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoContributionMap
QTextStream & endl(QTextStream &s)