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" 341 m_pRecoTree = tfs->make<TTree>(
"pandora",
"LAr Reco vs True");
516 evt,
m_particleLabel, spacePointVector, spacePointsToHits, hitsToSpacePoints);
562 std::cout <<
" RecoNeutrinos: " << recoNeutrinoVector.size() <<
std::endl;
563 std::cout <<
" RecoParticles: " << recoParticleVector.size() <<
std::endl;
586 LArPandoraHelper::kUseDaughters) :
587 LArPandoraHelper::kIgnoreDaughters));
589 if (trueHitsToParticles.empty()) {
591 throw cet::exception(
"LArPandora") <<
" PFParticleMonitoring::analyze - no sim channels " 592 "found, backtracker module must be set in FHiCL " 603 LArPandoraHelper::kUseDaughters) :
604 LArPandoraHelper::kIgnoreDaughters));
609 std::cout <<
" TrueParticles: " << particlesToTruth.size() <<
std::endl;
610 std::cout <<
" TrueEvents: " << truthToParticles.size() <<
std::endl;
611 std::cout <<
" MatchedParticles: " << trueParticlesToHits.size() <<
std::endl;
614 if (trueParticlesToHits.empty()) {
634 iterEnd = recoParticleVector.end();
655 recoParticleMap, recoParticlesToHits, recoNeutrinosToHits, recoHitsToNeutrinos);
657 truthToParticles, trueParticlesToHits, trueNeutrinosToHits, trueHitsToNeutrinos);
662 recoNeutrinosToHits, trueHitsToNeutrinos, matchedNeutrinos, matchedNeutrinoHits);
665 iterEnd = trueNeutrinosToHits.end();
669 const HitVector& trueHitVector = iter->second;
671 if (trueHitVector.empty())
continue;
679 m_mcPdg = trueParticle.PdgCode();
694 m_mcDirX = trueParticle.Px() / trueParticle.P();
695 m_mcDirY = trueParticle.Py() / trueParticle.P();
696 m_mcDirZ = trueParticle.Pz() / trueParticle.P();
747 hIterEnd1 = trueHitVector.end();
750 if (recoHitsToNeutrinos.find(*hIter1) == recoHitsToNeutrinos.end())
755 if (matchedNeutrinos.end() != pIter1) {
765 std::cout <<
" Warning: Found neutrino with an invalid PDG code " <<
std::endl;
768 if (recoParticlesToHits.end() != pIter2) {
769 const HitVector& recoHitVector = pIter2->second;
772 hIterEnd2 = recoHitVector.end();
775 if (trueHitsToNeutrinos.find(*hIter2) == trueHitsToNeutrinos.end())
780 if (matchedNeutrinoHits.end() != pIter3) {
781 const HitVector& matchedHitVector = pIter3->second;
794 recoParticlesToVertices.find(recoParticle);
795 if (recoParticlesToVertices.end() != pIter4) {
797 if (!vertexVector.empty()) {
799 std::cout <<
" Warning: Found particle with more than one associated vertex " 803 double xyz[3] = {0.0, 0.0, 0.0};
804 recoVertex->
XYZ(xyz);
824 std::cout <<
" MCNeutrino [" <<
m_index <<
"]" 840 recoParticlesToHits, trueHitsToParticles, matchedParticles, matchedParticleHits);
844 iterEnd = trueParticlesToHits.end();
848 const HitVector& trueHitVector = iter->second;
850 if (trueHitVector.empty())
continue;
943 const double Ptot(trueParticle->
P(startT));
957 if (particlesToTruth.end() == nuIter)
958 throw cet::exception(
"LArPandora") <<
" PFParticleMonitoring::analyze --- Found a true " 959 "particle without any ancestry information ";
984 bool foundSpacePoints(
false);
987 hIterEnd1 = trueHitVector.end();
993 if (hitsToSpacePoints.end() == hIter2)
continue;
996 const double X(spacepoint->
XYZ()[0]);
998 if (!foundSpacePoints) {
1001 foundSpacePoints =
true;
1011 hIterEnd1 = trueHitVector.end();
1012 hIter1 != hIterEnd1;
1014 if (recoHitsToParticles.find(*hIter1) == recoHitsToParticles.end())
1025 if (matchedParticles.end() != pIter1) {
1040 if (recoParticlesToHits.end() == pIter2)
1042 <<
" PFParticleMonitoring::analyze --- Found a reco particle without any hits ";
1044 const HitVector& recoHitVector = pIter2->second;
1047 hIterEnd2 = recoHitVector.end();
1048 hIter2 != hIterEnd2;
1050 if (trueHitsToParticles.find(*hIter2) == trueHitsToParticles.end())
1055 if (matchedParticleHits.end() == pIter3)
1056 throw cet::exception(
"LArPandora") <<
" PFParticleMonitoring::analyze --- Found a " 1057 "matched true particle without matched hits ";
1059 const HitVector& matchedHitVector = pIter3->second;
1072 if (recoParticlesToVertices.end() != pIter4) {
1074 if (!vertexVector.empty()) {
1076 std::cout <<
" Warning: Found particle with more than one associated vertex " 1080 double xyz[3] = {0.0, 0.0, 0.0};
1081 recoVertex->
XYZ(xyz);
1091 if (recoParticlesToTracks.end() != pIter5) {
1093 if (!trackVector.empty()) {
1095 std::cout <<
" Warning: Found particle with more than one associated track " 1099 const auto& vtxPosition = recoTrack->
Vertex();
1100 const auto& endPosition = recoTrack->
End();
1118 m_pfoIsStitched = (particlesToT0s.end() != particlesToT0s.find(recoParticle));
1129 std::cout <<
" MCParticle [" <<
m_index <<
"]" 1150 iterEnd1 = truthToParticles.end();
1157 iterEnd2 = trueParticleVector.end();
1161 if (trueParticlesToHits.end() == iter3)
continue;
1163 const HitVector& hitVector = iter3->second;
1169 trueHitsToNeutrinos[
hit] = trueNeutrino;
1170 trueNeutrinosToHits[trueNeutrino].push_back(hit);
1185 iterEnd1 = recoParticleMap.end();
1195 if (recoParticlesToHits.end() == iter2)
continue;
1197 const HitVector& hitVector = iter2->second;
1203 recoHitsToNeutrinos[
hit] = recoNeutrino;
1204 recoNeutrinosToHits[recoNeutrino].push_back(hit);
1221 trueHitsToNeutrinos,
1223 matchedNeutrinoHits,
1238 bool foundMatches(
false);
1241 iterEnd1 = recoNeutrinosToHits.end();
1245 if (vetoReco.count(recoNeutrino) > 0)
continue;
1247 const HitVector& hitVector = iter1->second;
1257 if (trueHitsToNeutrinos.end() == iter3)
continue;
1260 if (vetoTrue.count(trueNeutrino) > 0)
continue;
1262 truthContributionMap[trueNeutrino].push_back(hit);
1268 iterEnd4 = truthContributionMap.end();
1271 if ((truthContributionMap.end() == mIter) ||
1272 (iter4->second.size() > mIter->second.size())) {
1277 if (truthContributionMap.end() != mIter) {
1282 if ((matchedNeutrinoHits.end() == iter5) || (mIter->second.size() > iter5->second.size())) {
1283 matchedNeutrinos[trueNeutrino] = recoNeutrino;
1284 matchedNeutrinoHits[trueNeutrino] = mIter->second;
1285 foundMatches =
true;
1290 if (!foundMatches)
return;
1293 pIterEnd = matchedNeutrinos.end();
1296 vetoTrue.insert(pIter->first);
1297 vetoReco.insert(pIter->second);
1302 trueHitsToNeutrinos,
1304 matchedNeutrinoHits,
1321 recoParticlesToHits, trueHitsToParticles, matchedParticles, matchedHits, recoVeto, trueVeto);
1334 bool foundMatches(
false);
1337 iterEnd1 = recoParticlesToHits.end();
1341 if (vetoReco.count(recoParticle) > 0)
continue;
1343 const HitVector& hitVector = iter1->second;
1353 if (trueHitsToParticles.end() == iter3)
continue;
1356 if (vetoTrue.count(trueParticle) > 0)
continue;
1358 truthContributionMap[trueParticle].push_back(hit);
1364 iterEnd4 = truthContributionMap.end();
1367 if ((truthContributionMap.end() == mIter) ||
1368 (iter4->second.size() > mIter->second.size())) {
1373 if (truthContributionMap.end() != mIter) {
1378 if ((matchedHits.end() == iter5) || (mIter->second.size() > iter5->second.size())) {
1379 matchedParticles[trueParticle] = recoParticle;
1380 matchedHits[trueParticle] = mIter->second;
1381 foundMatches =
true;
1386 if (!foundMatches)
return;
1389 pIterEnd = matchedParticles.end();
1392 vetoTrue.insert(pIter->first);
1393 vetoReco.insert(pIter->second);
1398 trueHitsToParticles,
1416 if (hit->
View() == view) ++nHits;
1431 bool foundStartPosition(
false);
1435 for (
int nt = 0; nt < numTrajectoryPoints; ++nt) {
1437 double pos[3] = {particle->
Vx(nt), particle->
Vy(nt), particle->
Vz(nt)};
1445 if (!foundStartPosition) {
1447 foundStartPosition =
true;
1463 const int endT)
const 1465 if (endT <= startT)
return 0.0;
1469 for (
int nt = startT; nt < endT; ++nt) {
1470 const double dx(particle->
Vx(nt + 1) - particle->
Vx(nt));
1471 const double dy(particle->
Vy(nt + 1) - particle->
Vy(nt));
1472 const double dz(particle->
Vz(nt + 1) - particle->
Vz(nt));
1473 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
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
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
art framework interface to geometry description
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.
geo::TPCGeo const & PositionToTPC(geo::Point_t const &point) const
Returns the TPC at specified location.
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
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
std::vector< art::Ptr< recob::Track > > TrackVector
static int max(int a, int b)
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
std::vector< art::Ptr< recob::Hit > > HitVector
Declaration of signal hit object.
double m_pfoStraightLength
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
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
Provides recob::Track data product.
double Vz(const int i=0) const
const Double32_t * XYZ() const
std::vector< art::Ptr< recob::Vertex > > VertexVector
EventNumber_t event() const
Point_t const & End() const
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.
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
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.
QTextStream & endl(QTextStream &s)
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.