101 PFParticleSet& recoVeto,
102 MCTruthSet& trueVeto)
const;
131 PFParticleSet& recoVeto,
132 MCParticleSet& trueVeto)
const;
162 const int endT)
const;
274 #include "art_root_io/TFileDirectory.h" 275 #include "art_root_io/TFileService.h" 334 mf::LogDebug(
"LArPandora") <<
" *** PFParticleMonitoring::beginJob() *** " << std::endl;
339 m_pRecoTree = tfs->make<TTree>(
"pandora",
"LAr Reco vs True");
416 if (
m_printDebug) std::cout <<
" *** PFParticleMonitoring::analyze(...) *** " << std::endl;
494 std::cout <<
" Run: " <<
m_run << std::endl;
495 std::cout <<
" Event: " <<
m_event << std::endl;
503 if (
m_printDebug) std::cout <<
" Hits: " << hitVector.size() << std::endl;
511 evt,
m_particleLabel, spacePointVector, spacePointsToHits, hitsToSpacePoints);
513 if (
m_printDebug) std::cout <<
" SpacePoints: " << spacePointVector.size() << std::endl;
521 if (
m_printDebug) std::cout <<
" Tracks: " << recoTrackVector.size() << std::endl;
536 if (
m_printDebug) std::cout <<
" Vertices: " << recoVertexVector.size() << std::endl;
557 std::cout <<
" RecoNeutrinos: " << recoNeutrinoVector.size() << std::endl;
558 std::cout <<
" RecoParticles: " << recoParticleVector.size() << std::endl;
581 LArPandoraHelper::kUseDaughters) :
582 LArPandoraHelper::kIgnoreDaughters));
584 if (trueHitsToParticles.empty()) {
586 throw cet::exception(
"LArPandora") <<
" PFParticleMonitoring::analyze - no sim channels " 587 "found, backtracker module must be set in FHiCL " 598 LArPandoraHelper::kUseDaughters) :
599 LArPandoraHelper::kIgnoreDaughters));
604 std::cout <<
" TrueParticles: " << particlesToTruth.size() << std::endl;
605 std::cout <<
" TrueEvents: " << truthToParticles.size() << std::endl;
606 std::cout <<
" MatchedParticles: " << trueParticlesToHits.size() << std::endl;
609 if (trueParticlesToHits.empty()) {
629 iterEnd = recoParticleVector.end();
650 recoParticleMap, recoParticlesToHits, recoNeutrinosToHits, recoHitsToNeutrinos);
652 truthToParticles, trueParticlesToHits, trueNeutrinosToHits, trueHitsToNeutrinos);
657 recoNeutrinosToHits, trueHitsToNeutrinos, matchedNeutrinos, matchedNeutrinoHits);
660 iterEnd = trueNeutrinosToHits.end();
664 const HitVector& trueHitVector = iter->second;
666 if (trueHitVector.empty())
continue;
674 m_mcPdg = trueParticle.PdgCode();
689 m_mcDirX = trueParticle.Px() / trueParticle.P();
690 m_mcDirY = trueParticle.Py() / trueParticle.P();
691 m_mcDirZ = trueParticle.Pz() / trueParticle.P();
742 hIterEnd1 = trueHitVector.end();
745 if (recoHitsToNeutrinos.find(*hIter1) == recoHitsToNeutrinos.end())
750 if (matchedNeutrinos.end() != pIter1) {
760 std::cout <<
" Warning: Found neutrino with an invalid PDG code " << std::endl;
763 if (recoParticlesToHits.end() != pIter2) {
764 const HitVector& recoHitVector = pIter2->second;
767 hIterEnd2 = recoHitVector.end();
770 if (trueHitsToNeutrinos.find(*hIter2) == trueHitsToNeutrinos.end())
775 if (matchedNeutrinoHits.end() != pIter3) {
776 const HitVector& matchedHitVector = pIter3->second;
789 recoParticlesToVertices.find(recoParticle);
790 if (recoParticlesToVertices.end() != pIter4) {
792 if (!vertexVector.empty()) {
794 std::cout <<
" Warning: Found particle with more than one associated vertex " 798 double xyz[3] = {0.0, 0.0, 0.0};
799 recoVertex->
XYZ(xyz);
819 std::cout <<
" MCNeutrino [" <<
m_index <<
"]" 835 recoParticlesToHits, trueHitsToParticles, matchedParticles, matchedParticleHits);
839 iterEnd = trueParticlesToHits.end();
843 const HitVector& trueHitVector = iter->second;
845 if (trueHitVector.empty())
continue;
938 const double Ptot(trueParticle->
P(startT));
952 if (particlesToTruth.end() == nuIter)
953 throw cet::exception(
"LArPandora") <<
" PFParticleMonitoring::analyze --- Found a true " 954 "particle without any ancestry information ";
979 bool foundSpacePoints(
false);
982 hIterEnd1 = trueHitVector.end();
988 if (hitsToSpacePoints.end() == hIter2)
continue;
991 const double X(spacepoint->
XYZ()[0]);
993 if (!foundSpacePoints) {
996 foundSpacePoints =
true;
1006 hIterEnd1 = trueHitVector.end();
1007 hIter1 != hIterEnd1;
1009 if (recoHitsToParticles.find(*hIter1) == recoHitsToParticles.end())
1020 if (matchedParticles.end() != pIter1) {
1035 if (recoParticlesToHits.end() == pIter2)
1037 <<
" PFParticleMonitoring::analyze --- Found a reco particle without any hits ";
1039 const HitVector& recoHitVector = pIter2->second;
1042 hIterEnd2 = recoHitVector.end();
1043 hIter2 != hIterEnd2;
1045 if (trueHitsToParticles.find(*hIter2) == trueHitsToParticles.end())
1050 if (matchedParticleHits.end() == pIter3)
1051 throw cet::exception(
"LArPandora") <<
" PFParticleMonitoring::analyze --- Found a " 1052 "matched true particle without matched hits ";
1054 const HitVector& matchedHitVector = pIter3->second;
1067 if (recoParticlesToVertices.end() != pIter4) {
1069 if (!vertexVector.empty()) {
1071 std::cout <<
" Warning: Found particle with more than one associated vertex " 1075 double xyz[3] = {0.0, 0.0, 0.0};
1076 recoVertex->
XYZ(xyz);
1086 if (recoParticlesToTracks.end() != pIter5) {
1088 if (!trackVector.empty()) {
1090 std::cout <<
" Warning: Found particle with more than one associated track " 1094 const auto& vtxPosition = recoTrack->
Vertex();
1095 const auto& endPosition = recoTrack->
End();
1113 m_pfoIsStitched = (particlesToT0s.end() != particlesToT0s.find(recoParticle));
1124 std::cout <<
" MCParticle [" <<
m_index <<
"]" 1144 iterEnd1 = truthToParticles.end();
1151 iterEnd2 = trueParticleVector.end();
1155 if (trueParticlesToHits.end() == iter3)
continue;
1157 const HitVector& hitVector = iter3->second;
1163 trueHitsToNeutrinos[hit] = trueNeutrino;
1164 trueNeutrinosToHits[trueNeutrino].push_back(hit);
1178 iterEnd1 = recoParticleMap.end();
1188 if (recoParticlesToHits.end() == iter2)
continue;
1190 const HitVector& hitVector = iter2->second;
1196 recoHitsToNeutrinos[hit] = recoNeutrino;
1197 recoNeutrinosToHits[recoNeutrino].push_back(hit);
1213 trueHitsToNeutrinos,
1215 matchedNeutrinoHits,
1229 bool foundMatches(
false);
1232 iterEnd1 = recoNeutrinosToHits.end();
1236 if (vetoReco.count(recoNeutrino) > 0)
continue;
1238 const HitVector& hitVector = iter1->second;
1248 if (trueHitsToNeutrinos.end() == iter3)
continue;
1251 if (vetoTrue.count(trueNeutrino) > 0)
continue;
1253 truthContributionMap[trueNeutrino].push_back(hit);
1259 iterEnd4 = truthContributionMap.end();
1262 if ((truthContributionMap.end() == mIter) ||
1263 (iter4->second.size() > mIter->second.size())) {
1268 if (truthContributionMap.end() != mIter) {
1273 if ((matchedNeutrinoHits.end() == iter5) || (mIter->second.size() > iter5->second.size())) {
1274 matchedNeutrinos[trueNeutrino] = recoNeutrino;
1275 matchedNeutrinoHits[trueNeutrino] = mIter->second;
1276 foundMatches =
true;
1281 if (!foundMatches)
return;
1284 pIterEnd = matchedNeutrinos.end();
1287 vetoTrue.insert(pIter->first);
1288 vetoReco.insert(pIter->second);
1293 trueHitsToNeutrinos,
1295 matchedNeutrinoHits,
1311 recoParticlesToHits, trueHitsToParticles, matchedParticles, matchedHits, recoVeto, trueVeto);
1323 bool foundMatches(
false);
1326 iterEnd1 = recoParticlesToHits.end();
1330 if (vetoReco.count(recoParticle) > 0)
continue;
1332 const HitVector& hitVector = iter1->second;
1342 if (trueHitsToParticles.end() == iter3)
continue;
1345 if (vetoTrue.count(trueParticle) > 0)
continue;
1347 truthContributionMap[trueParticle].push_back(hit);
1353 iterEnd4 = truthContributionMap.end();
1356 if ((truthContributionMap.end() == mIter) ||
1357 (iter4->second.size() > mIter->second.size())) {
1362 if (truthContributionMap.end() != mIter) {
1367 if ((matchedHits.end() == iter5) || (mIter->second.size() > iter5->second.size())) {
1368 matchedParticles[trueParticle] = recoParticle;
1369 matchedHits[trueParticle] = mIter->second;
1370 foundMatches =
true;
1375 if (!foundMatches)
return;
1378 pIterEnd = matchedParticles.end();
1381 vetoTrue.insert(pIter->first);
1382 vetoReco.insert(pIter->second);
1387 trueHitsToParticles,
1404 if (hit->
View() == view) ++nHits;
1418 bool foundStartPosition(
false);
1422 for (
int nt = 0; nt < numTrajectoryPoints; ++nt) {
1429 if (!foundStartPosition) {
1431 foundStartPosition =
true;
1442 const int endT)
const 1444 if (endT <= startT)
return 0.0;
1448 for (
int nt = startT; nt < endT; ++nt) {
1449 const double dx(particle->
Vx(nt + 1) - particle->
Vx(nt));
1450 const double dy(particle->
Vy(nt + 1) - particle->
Vy(nt));
1451 const double dz(particle->
Vz(nt + 1) - particle->
Vz(nt));
1452 length += sqrt(dx * dx + dy * dy + dz * dz);
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.
void XYZ(double *xyz) const
Legacy method to access vertex position, preserved to avoid breaking code. Please try to use Vertex::...
unsigned int NumberTrajectoryPoints() const
void analyze(const art::Event &evt)
std::map< art::Ptr< recob::Hit >, art::Ptr< simb::MCParticle > > HitsToMCParticles
const simb::MCNeutrino & GetNeutrino() const
int CountHitsByType(const int view, const HitVector &hitVector) const
Count the number of reconstructed hits in a given wire plane.
static void BuildPFParticleMap(const PFParticleVector &particleVector, PFParticleMap &particleMap)
Build particle maps for reconstructed particles.
double Py(const int i=0) const
static int GetParentNeutrino(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Return the parent neutrino PDG code (or zero for cosmics) for a given reconstructed particle...
bool m_useDaughterPFParticles
Encapsulate the construction of a single cyostat.
void GetRecoToTrueMatches(const PFParticlesToHits &recoNeutrinosToHits, const HitsToMCTruth &trueHitsToNeutrinos, MCTruthToPFParticles &matchedNeutrinos, MCTruthToHits &matchedNeutrinoHits) const
Perform matching between true and reconstructed neutrino events.
std::set< art::Ptr< recob::PFParticle > > PFParticleSet
static bool IsNeutrino(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as a neutrino.
std::string m_backtrackerLabel
std::map< art::Ptr< simb::MCTruth >, HitVector > MCTruthToHits
Declaration of signal hit object.
std::map< art::Ptr< simb::MCParticle >, art::Ptr< simb::MCTruth > > MCParticlesToMCTruth
std::string m_geantModuleLabel
static art::Ptr< recob::PFParticle > GetFinalStatePFParticle(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Return the final-state parent particle by navigating up the chain of parent/daughter associations...
double Px(const int i=0) const
Vector_t VertexDirection() const
Access to track direction at different points.
std::map< art::Ptr< simb::MCParticle >, art::Ptr< recob::PFParticle > > MCParticlesToPFParticles
int PdgCode() const
Return the type of particle as a PDG ID.
geo::View_t View() const
View for the plane of the hit.
bool m_addDaughterMCParticles
EDAnalyzer(fhicl::ParameterSet const &pset)
std::string Process() const
static art::Ptr< recob::PFParticle > GetParentPFParticle(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Return the top-level parent particle by navigating up the chain of parent/daughter associations...
std::map< art::Ptr< recob::PFParticle >, TrackVector > PFParticlesToTracks
std::map< art::Ptr< recob::PFParticle >, VertexVector > PFParticlesToVertices
std::map< int, art::Ptr< recob::PFParticle > > PFParticleMap
void BuildTrueNeutrinoHitMaps(const MCTruthToMCParticles &truthToParticles, const MCParticlesToHits &trueParticlesToHits, MCTruthToHits &trueNeutrinosToHits, HitsToMCTruth &trueHitsToNeutrinos) const
Build mapping from true neutrinos to hits.
std::map< int, art::Ptr< simb::MCParticle > > MCParticleMap
bool m_useDaughterMCParticles
std::set< art::Ptr< simb::MCTruth > > MCTruthSet
std::string m_hitfinderLabel
static void CollectSpacePoints(const art::Event &evt, const std::string &label, SpacePointVector &spacePointVector, SpacePointsToHits &spacePointsToHits)
Collect the reconstructed SpacePoints and associated hits from the ART event record.
double GetLength(const art::Ptr< simb::MCParticle > trueParticle, const int startT, const int endT) const
Find the length of the true particle trajectory through the active region of the detector.
int m_nTrueWithoutRecoHits
True hits which don't belong to any reconstructed particle - "available".
std::map< art::Ptr< recob::PFParticle >, T0Vector > PFParticlesToT0s
std::map< art::Ptr< recob::Hit >, art::Ptr< simb::MCTruth > > HitsToMCTruth
double Length(size_t p=0) const
Access to various track properties.
static art::Ptr< simb::MCParticle > GetParentMCParticle(const MCParticleMap &particleMap, const art::Ptr< simb::MCParticle > daughterParticle)
Return the top-level parent particle by navigating up the chain of parent/daughter associations...
void BuildRecoNeutrinoHitMaps(const PFParticleMap &recoParticleMap, const PFParticlesToHits &recoParticlesToHits, PFParticlesToHits &recoNeutrinosToHits, HitsToPFParticles &recoHitsToNeutrinos) const
Build mapping from reconstructed neutrinos to hits.
#define DEFINE_ART_MODULE(klass)
std::map< art::Ptr< simb::MCParticle >, HitVector > MCParticlesToHits
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
std::map< art::Ptr< simb::MCTruth >, MCParticleVector > MCTruthToMCParticles
std::map< art::Ptr< simb::MCTruth >, art::Ptr< recob::PFParticle > > MCTruthToPFParticles
double P(const int i=0) const
T get(std::string const &key) const
std::vector< art::Ptr< recob::SpacePoint > > SpacePointVector
std::map< art::Ptr< recob::PFParticle >, HitVector > PFParticlesToHits
Point_t const & Vertex() const
Access to track position at different points.
bool m_printDebug
switch for print statements (TODO: use message service!)
static void CollectVertices(const art::Event &evt, const std::string &label, VertexVector &vertexVector, PFParticlesToVertices &particlesToVertices)
Collect the reconstructed PFParticles and associated Vertices from the ART event record.
PFParticleMonitoring(fhicl::ParameterSet const &pset)
Constructor.
std::map< art::Ptr< recob::Hit >, art::Ptr< recob::SpacePoint > > HitsToSpacePoints
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
Provides recob::Track data product.
const Double32_t * XYZ() const
std::vector< art::Ptr< recob::Track > > TrackVector
Declaration of cluster object.
static void CollectTracks(const art::Event &evt, const std::string &label, TrackVector &trackVector, PFParticlesToTracks &particlesToTracks)
Collect the reconstructed PFParticles and associated Tracks from the ART event record.
static void CollectPFParticles(const art::Event &evt, const std::string &label, PFParticleVector &particleVector)
Collect the reconstructed PFParticles from the ART event record.
void GetStartAndEndPoints(const art::Ptr< simb::MCParticle > trueParticle, int &startT, int &endT) const
Find the start and end points of the true particle in the active region of detector.
static void CollectHits(const art::Event &evt, const std::string &label, HitVector &hitVector)
Collect the reconstructed Hits from the ART event record.
Detector simulation of raw signals on wires.
static void SelectNeutrinoPFParticles(const PFParticleVector &inputParticles, PFParticleVector &outputParticles)
Select reconstructed neutrino particles from a list of all reconstructed particles.
std::string m_particleLabel
double Vx(const int i=0) const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
std::vector< art::Ptr< recob::Hit > > HitVector
double m_pfoStraightLength
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
std::map< art::Ptr< recob::Hit >, art::Ptr< recob::PFParticle > > HitsToPFParticles
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
double m_mcStraightLength
double Pz(const int i=0) const
double Vz(const int i=0) const
std::vector< art::Ptr< recob::Vertex > > VertexVector
EventNumber_t event() const
Point_t const & End() const
Access to track position at different points.
void reconfigure(fhicl::ParameterSet const &pset)
std::set< art::Ptr< simb::MCParticle > > MCParticleSet
Planes which measure W (third view for Bo, MicroBooNE, etc).
std::vector< art::Ptr< anab::T0 > > T0Vector
PFParticleMonitoring class.
static void CollectT0s(const art::Event &evt, const std::string &label, T0Vector &t0Vector, PFParticlesToT0s &particlesToT0s)
Collect a vector of T0s from the ART event record.
bool m_addDaughterPFParticles
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.
Event generator information.
static void CollectMCParticles(const art::Event &evt, const std::string &label, MCParticleVector &particleVector)
Collect a vector of MCParticle objects from the ART event record.
TPCGeo const * PositionToTPCptr(Point_t const &point) const
Returns the TPC at specified location.
helper function for LArPandoraInterface producer module
static art::Ptr< simb::MCParticle > GetFinalStateMCParticle(const MCParticleMap &particleMap, const art::Ptr< simb::MCParticle > daughterParticle)
Return the final-state parent particle by navigating up the chain of parent/daughter associations...
int m_nRecoWithoutTrueHits
Reconstructed hits which don't belong to any true particle - "missing".
double Vy(const int i=0) const
art framework interface to geometry description
static bool IsFinalState(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Determine whether a particle has been reconstructed as a final-state particle.
std::map< art::Ptr< recob::SpacePoint >, art::Ptr< recob::Hit > > SpacePointsToHits
cet::coded_exception< error, detail::translate > exception
bool m_disableRealDataCheck
Whether to check if the input file contains real data before accessing MC information.
Encapsulate the construction of a single detector plane.
virtual ~PFParticleMonitoring()
Destructor.
static void BuildMCParticleMap(const MCParticleVector &particleVector, MCParticleMap &particleMap)
Build particle maps for true particles.