117 typedef std::map<SimpleMCPrimary, SimpleMatchedPfoList>
134 MCParticleMatchingMap& mcParticleMatchingMap)
const;
148 const MCParticleMatchingMap& mcParticleMatchingMap,
149 SimpleMCPrimaryList& simpleMCPrimaryList)
const;
160 const MCParticleMatchingMap& mcParticleMatchingMap,
209 MatchingDetailsMap& matchingDetailsMap)
const;
224 MatchingDetailsMap& matchingDetailsMap)
const;
234 const IntSet& usedPfoIds,
235 MatchingDetailsMap& matchingDetailsMap)
const;
244 const MatchingDetailsMap& matchingDetailsMap)
const;
265 const SimpleMatchedPfoList& simpleMatchedPfoList,
266 const MatchingDetailsMap& matchingDetailsMap)
const;
414 if (hitsToMCParticles.empty()) {
416 throw cet::exception(
"LArPandora") <<
" PFParticleValidation::analyze - no sim channels " 417 "found, backtracker module must be set in FHiCL " 431 pfParticlesToHits, mcParticlesToHits, hitsToMCParticles, mcParticleMatchingMap);
435 evt, mcParticlesToHits, hitsToMCParticles, mcParticleMatchingMap, simpleMCPrimaryList);
439 simpleMCPrimaryList, mcParticleMatchingMap, pfParticlesToHits, mcPrimaryMatchingMap);
448 this->
PrintAllOutput(mcTruthVector, recoNeutrinoVector, mcPrimaryMatchingMap);
466 for (
const MCParticlesToHits::value_type& mcParticleToHitsEntry : mcParticlesToHits) {
467 if (!mcParticleToHitsEntry.second.empty())
468 (
void)mcParticleMatchingMap.insert(MCParticleMatchingMap::value_type(
473 for (
const PFParticlesToHits::value_type& recoParticleToHits : pfParticlesToHits) {
475 const HitVector& hitVector(recoParticleToHits.second);
480 if (hitsToMCParticles.end() == mcParticleIter)
continue;
483 mcParticleMatchingMap[pTrueParticle][pRecoParticle].push_back(pHit);
502 for (
const MCParticlesToHits::value_type& mapEntry : mcParticlesToHits) {
512 simpleMCPrimary.
m_energy = pMCPrimary->
E();
516 if (mcParticlesToHits.end() != trueHitsIter) {
517 const HitVector& hitVector(trueHitsIter->second);
526 if (mcParticleMatchingMap.end() != matchedPfoIter)
529 simpleMCPrimaryList.push_back(simpleMCPrimary);
532 std::sort(simpleMCPrimaryList.begin(),
533 simpleMCPrimaryList.end(),
538 simpleMCPrimary.m_id = mcPrimaryId++;
549 if (artMCParticlesToMCTruth.end() == iter)
return false;
569 iterEnd = mcParticleMatchingMap.end();
572 if (simpleMCPrimary.m_pAddress == iter->first.get()) {
573 matchedPfoIter = iter;
578 if (mcParticleMatchingMap.end() != matchedPfoIter) {
579 for (
const PFParticleToMatchedHits::value_type& contribution : matchedPfoIter->second) {
581 const HitVector& matchedHitVector(contribution.second);
585 simpleMatchedPfo.
m_id = pMatchedPfo->
Self();
592 iterEnd = pfParticlesToHits.end();
595 if (pMatchedPfo->
Parent() == iter->first->Self()) {
596 parentPfoIter = iter;
601 if ((pfParticlesToHits.end() != parentPfoIter) &&
603 simpleMatchedPfo.
m_parentId = parentPfoIter->first->Self();
613 if (pfParticlesToHits.end() == pfoHitsIter)
615 <<
" PFParticleValidation::analyze --- Presence of PFParticle in map mandatory.";
617 const HitVector& pfoHitVector(pfoHitsIter->second);
624 simpleMatchedPfoList.push_back(simpleMatchedPfo);
629 std::sort(simpleMatchedPfoList.begin(),
630 simpleMatchedPfoList.end(),
633 if (!mcPrimaryMatchingMap
634 .insert(MCPrimaryMatchingMap::value_type(simpleMCPrimary, simpleMatchedPfoList))
637 <<
" PFParticleValidation::analyze --- Double-counting MC primaries.";
650 for (
const auto& mapEntry : artMCTruthToMCParticles) {
655 if (mcTruthVector.end() == std::find(mcTruthVector.begin(), mcTruthVector.end(), truth))
656 mcTruthVector.push_back(truth);
676 std::cout <<
"---RAW-MATCHING-OUTPUT-----------------------------------------------------------" 681 std::cout <<
"MCNeutrino, PDG " << pMCTruth->GetNeutrino().Nu().PdgCode()
682 <<
", InteractionType " << pMCTruth->GetNeutrino().InteractionType() << std::endl;
686 std::cout <<
"RecoNeutrino, PDG " << pPfo->PdgCode() <<
", nDaughters " 687 << pPfo->NumDaughters() << std::endl;
690 for (
const MCPrimaryMatchingMap::value_type& mapValue : mcPrimaryMatchingMap) {
693 std::cout << std::endl
694 <<
"Primary " << simpleMCPrimary.
m_id <<
", PDG " << simpleMCPrimary.
m_pdgCode 697 << simpleMCPrimary.
m_nMCHitsW <<
")" << std::endl;
700 std::cout <<
"-MatchedPfo " << simpleMatchedPfo.
m_id;
703 std::cout <<
", ParentPfo " << simpleMatchedPfo.
m_parentId;
705 std::cout <<
", PDG " << simpleMatchedPfo.
m_pdgCode <<
", nMatchedHits " 711 << simpleMatchedPfo.
m_nPfoHitsW <<
")" << std::endl;
715 std::cout <<
"---------------------------------------------------------------------------------" 726 IntSet usedMCIds, usedPfoIds;
727 while (
GetStrongestPfoMatch(mcPrimaryMatchingMap, usedMCIds, usedPfoIds, matchingDetailsMap)) {}
740 int bestPfoMatchId(-1);
743 for (
const MCPrimaryMatchingMap::value_type& mapValue : mcPrimaryMatchingMap) {
748 if (usedMCIds.count(simpleMCPrimary.
m_id))
continue;
751 if (usedPfoIds.count(simpleMatchedPfo.
m_id))
continue;
753 if (!this->
IsGoodMatch(simpleMCPrimary, simpleMatchedPfo))
continue;
756 bestPfoMatchId = simpleMatchedPfo.
m_id;
766 if (bestPfoMatchId > -1) {
767 matchingDetailsMap[bestPfoMatchId] = bestMatchingDetails;
769 usedPfoIds.insert(bestPfoMatchId);
783 for (
const MCPrimaryMatchingMap::value_type& mapValue : mcPrimaryMatchingMap) {
789 if (usedPfoIds.count(simpleMatchedPfo.
m_id))
continue;
809 std::cout <<
"---PROCESSED-MATCHING-OUTPUT-----------------------------------------------------" 819 bool isCorrect(
true), isCalculable(
false);
821 for (
const MCPrimaryMatchingMap::value_type& mapValue : mcPrimaryMatchingMap) {
823 const bool hasMatch(this->
HasMatch(simpleMCPrimary, mapValue.second, matchingDetailsMap));
827 if (!hasMatch && !isTargetPrimary)
continue;
829 std::cout << std::endl
830 << (!isTargetPrimary ?
"(Non target) " :
"") <<
"Primary " << simpleMCPrimary.
m_id 831 <<
", PDG " << simpleMCPrimary.
m_pdgCode <<
", nMCHits " 836 if (2112 != simpleMCPrimary.
m_pdgCode) isCalculable =
true;
838 unsigned int nMatches(0);
841 if (matchingDetailsMap.count(simpleMatchedPfo.
m_id) &&
842 (simpleMCPrimary.
m_id ==
843 matchingDetailsMap.at(simpleMatchedPfo.
m_id).m_matchedPrimaryId)) {
844 const bool isGoodMatch(this->
IsGoodMatch(simpleMCPrimary, simpleMatchedPfo));
846 if (isGoodMatch) ++nMatches;
847 std::cout <<
"-" << (!isGoodMatch ?
"(Below threshold) " :
"") <<
"MatchedPfo " 848 << simpleMatchedPfo.
m_id;
851 std::cout <<
", ParentPfo " << simpleMatchedPfo.
m_parentId;
853 std::cout <<
", PDG " << simpleMatchedPfo.
m_pdgCode <<
", nMatchedHits " 859 << simpleMatchedPfo.
m_nPfoHitsW <<
")" << std::endl;
863 if (isTargetPrimary && (1 != nMatches)) isCorrect =
false;
866 std::cout << std::endl <<
"Is correct? " << (isCorrect && isCalculable) << std::endl;
867 std::cout <<
"---------------------------------------------------------------------------------" 895 if (matchingDetailsMap.count(simpleMatchedPfo.m_id) &&
896 (simpleMCPrimary.
m_id == matchingDetailsMap.at(simpleMatchedPfo.m_id).m_matchedPrimaryId))
926 unsigned int nHitsOfSpecifiedType(0);
929 if (view == pHit->View()) ++nHitsOfSpecifiedType;
932 return nHitsOfSpecifiedType;
971 , m_pAddress(nullptr)
978 if (
this == &rhs)
return false;
994 , m_nMatchedHitsTotal(0)
1005 : m_matchedPrimaryId(-1), m_nMatchedHits(0), m_completeness(0.
f)
double E(const int i=0) const
static void BuildPFParticleHitMaps(const PFParticleVector &particleVector, const PFParticlesToSpacePoints &particlesToSpacePoints, const SpacePointsToHits &spacePointsToHits, PFParticlesToHits &particlesToHits, HitsToPFParticles &hitsToParticles, const DaughterMode daughterMode=kUseDaughters)
Build mapping between PFParticles and Hits using PFParticle/SpacePoint/Hit maps.
bool GetStrongestPfoMatch(const MCPrimaryMatchingMap &mcPrimaryMatchingMap, IntSet &usedMCIds, IntSet &usedPfoIds, MatchingDetailsMap &matchingDetailsMap) const
Get the strongest pfo match (most matched hits) between an available mc primary and an available pfo...
int m_pdgCode
The pdg code.
std::vector< art::Ptr< simb::MCTruth > > MCTruthVector
void GetMCParticleMatchingMap(const PFParticlesToHits &recoParticlesToHits, const MCParticlesToHits &trueParticlesToHits, const HitsToMCParticles &hitsToTrueParticles, MCParticleMatchingMap &mcParticleMatchingMap) const
Performing matching between true and reconstructed particles.
std::map< art::Ptr< recob::Hit >, art::Ptr< simb::MCParticle > > HitsToMCParticles
bool HasMatch(const SimpleMCPrimary &simpleMCPrimary, const SimpleMatchedPfoList &simpleMatchedPfoList, const MatchingDetailsMap &matchingDetailsMap) const
Whether a provided mc primary has a match, of any quality (use simple matched pfo list and informatio...
bool IsNeutrinoInduced(const art::Ptr< simb::MCParticle > pMCParticle, const MCParticlesToMCTruth &artMCParticlesToMCTruth) const
Whether a mc particle is neutrino induced.
int m_nMCHitsU
The number of u mc hits.
int m_nMCHitsTotal
The total number of mc hits.
int m_pdgCode
The pdg code.
void PrintMatchingOutput(const MCPrimaryMatchingMap &mcPrimaryMatchingMap, const MatchingDetailsMap &matchingDetailsMap) const
Print the results of the matching procedure.
void PerformMatching(const MCPrimaryMatchingMap &mcPrimaryMatchingMap, MatchingDetailsMap &matchingDetailsMap) const
Apply a well-defined matching procedure to the comprehensive matches in the provided mc primary match...
int m_nPfoHitsV
The number of v pfo hits.
int m_nPfoHitsTotal
The total number of pfo hits.
std::map< SimpleMCPrimary, SimpleMatchedPfoList > MCPrimaryMatchingMap
size_t Self() const
Returns the index of this particle.
PFParticleValidation(fhicl::ParameterSet const &pset)
Constructor.
float m_matchingMinCompleteness
The minimum particle completeness to declare a match.
const simb::MCParticle * m_pAddress
The address of the mc primary.
static bool IsNeutrino(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as a neutrino.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
void GetRecoNeutrinos(const art::Event &evt, PFParticleVector &recoNeutrinoVector) const
Obtain a vector of reco neutrinos.
SimpleMatchedPfo()
Constructor.
Declaration of signal hit object.
bool m_neutrinoInducedOnly
Whether to consider only mc particles that were neutrino induced.
std::map< art::Ptr< simb::MCParticle >, art::Ptr< simb::MCTruth > > MCParticlesToMCTruth
simb::Origin_t Origin() const
int m_matchingMinPrimaryHits
The minimum number of good mc primary hits used in matching scheme.
void GetSimpleMCPrimaryList(const art::Event &evt, const MCParticlesToHits &mcParticlesToHits, const HitsToMCParticles &hitsToMCParticles, const MCParticleMatchingMap &mcParticleMatchingMap, SimpleMCPrimaryList &simpleMCPrimaryList) const
Extract details of each mc primary (ordered by number of true hits)
float m_energy
The energy.
std::map< art::Ptr< recob::PFParticle >, HitVector > PFParticleToMatchedHits
int m_nMatchedHitsW
The number of w matched hits.
int m_nMatchedHitsU
The number of u matched hits.
int PdgCode() const
Return the type of particle as a PDG ID.
SimpleMCPrimary()
Constructor.
std::map< int, MatchingDetails > MatchingDetailsMap
EDAnalyzer(fhicl::ParameterSet const &pset)
int m_nMCHitsW
The number of w mc hits.
const recob::PFParticle * m_pAddress
The address of the pf primary.
void PrintAllOutput(const MCTruthVector &mcTruthVector, const PFParticleVector &recoNeutrinoVector, const MCPrimaryMatchingMap &mcPrimaryMatchingMap) const
Print all the raw matching output to screen.
std::string m_particleLabel
The name/label of the particle producer module.
int m_nMatchedPfos
The number of matched pfos.
int m_id
The unique identifier.
bool m_useSmallPrimaries
Whether to consider matches to mc primaries with fewer than m_matchingMinPrimaryHits.
std::vector< SimpleMCPrimary > SimpleMCPrimaryList
int m_nPfoHitsW
The number of w pfo hits.
bool m_printMatchingToScreen
Whether to print matching output to screen.
void GetMCTruth(const art::Event &evt, MCTruthVector &mcTruthVector) const
Obtain a vector of mc truth.
#define DEFINE_ART_MODULE(klass)
bool IsGoodMatch(const SimpleMCPrimary &simpleMCPrimary, const SimpleMatchedPfo &simpleMatchedPfo) const
Whether a provided mc primary and pfo are deemed to be a good match.
int m_nMatchedHitsTotal
The total number of matched hits.
std::map< art::Ptr< simb::MCParticle >, HitVector > MCParticlesToHits
bool m_printAllToScreen
Whether to print all/raw matching details to screen.
int m_nMatchedHits
The number of times the primary has 0 pfo matches.
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
void analyze(const art::Event &evt)
std::map< art::Ptr< simb::MCTruth >, MCParticleVector > MCTruthToMCParticles
float m_matchingMinPurity
The minimum particle purity to declare a match.
PFParticleValidation class.
T get(std::string const &key) const
std::string m_backtrackerLabel
The name/label of the back-tracker module.
int m_nMCHitsV
The number of v mc hits.
std::map< art::Ptr< recob::PFParticle >, HitVector > PFParticlesToHits
float m_completeness
The completeness of the match.
int m_matchedPrimaryId
The total number of occurences.
MatchingDetails()
Default constructor.
int m_matchingMinSharedHits
The minimum number of shared hits used in matching scheme.
int m_matchingMinPrimaryGoodViews
The minimum number of good views for a mc primary.
void GetRemainingPfoMatches(const MCPrimaryMatchingMap &mcPrimaryMatchingMap, const IntSet &usedPfoIds, MatchingDetailsMap &matchingDetailsMap) const
Get the best matches for any pfos left-over after the strong matching procedure.
std::vector< SimpleMatchedPfo > SimpleMatchedPfoList
static bool SortSimpleMatchedPfos(const SimpleMatchedPfo &lhs, const SimpleMatchedPfo &rhs)
Sort simple matched pfos by number of matched hits.
Definition of data types for geometry description.
static void CollectPFParticles(const art::Event &evt, const std::string &label, PFParticleVector &particleVector)
Collect the reconstructed PFParticles from the ART event record.
static void CollectHits(const art::Event &evt, const std::string &label, HitVector &hitVector)
Collect the reconstructed Hits from the ART event record.
int m_nMatchedHitsV
The number of v matched hits.
static void SelectNeutrinoPFParticles(const PFParticleVector &inputParticles, PFParticleVector &outputParticles)
Select reconstructed neutrino particles from a list of all reconstructed particles.
std::vector< art::Ptr< recob::Hit > > HitVector
bool IsGoodMCPrimary(const SimpleMCPrimary &simpleMCPrimary) const
Whether a provided mc primary passes selection, based on number of "good" hits.
Hierarchical representation of particle flow.
int m_matchingMinHitsForGoodView
The minimum number of good mc primary hits in given view to declare view to be good.
int m_nPfoHitsU
The number of u pfo hits.
std::map< art::Ptr< recob::Hit >, art::Ptr< recob::PFParticle > > HitsToPFParticles
static bool SortSimpleMCPrimaries(const SimpleMCPrimary &lhs, const SimpleMCPrimary &rhs)
Sort simple mc primaries by number of mc hits.
virtual ~PFParticleValidation()
Destructor.
void reconfigure(fhicl::ParameterSet const &pset)
void GetMCPrimaryMatchingMap(const SimpleMCPrimaryList &simpleMCPrimaryList, const MCParticleMatchingMap &mcParticleMatchingMap, const PFParticlesToHits &pfParticlesToHits, MCPrimaryMatchingMap &mcPrimaryMatchingMap) const
Obtain a sorted list of matched pfos for each mc primary.
Planes which measure W (third view for Bo, MicroBooNE, etc).
bool operator<(const SimpleMCPrimary &rhs) const
operator <
std::string m_geantModuleLabel
The name/label of the geant module.
static void BuildMCParticleHitMaps(const art::Event &evt, const HitVector &hitVector, const SimChannelVector &simChannelVector, HitsToTrackIDEs &hitsToTrackIDEs)
Collect the links from reconstructed hits to their true energy deposits.
static void CollectMCParticles(const art::Event &evt, const std::string &label, MCParticleVector &particleVector)
Collect a vector of MCParticle objects from the ART event record.
helper function for LArPandoraInterface producer module
std::map< art::Ptr< simb::MCParticle >, PFParticleToMatchedHits > MCParticleMatchingMap
unsigned int CountHitsByType(const geo::View_t view, const HitVector &hitVector) const
Count the number of hits, in a provided vector, of a specified view.
int m_id
The unique identifier.
std::string m_hitfinderLabel
The name/label of the hit producer module.
cet::coded_exception< error, detail::translate > exception
int m_parentId
The unique identifier of the parent pfo (-1 if no parent set)