8#include "art/Framework/Core/EDAnalyzer.h"
9#include "art/Framework/Core/ModuleMacros.h"
13#include "larcoreobj/SimpleTypesAndConstants/geo_types.h"
14#include "lardata/DetectorInfoServices/DetectorClocksService.h"
42 void analyze(
const art::Event& evt);
104 double GetUVW(
const geo::WireID& wireID)
const;
114 double YZtoU(
const unsigned int cstat,
115 const unsigned int tpc,
117 const double z)
const;
127 double YZtoV(
const unsigned int cstat,
128 const unsigned int tpc,
130 const double z)
const;
180#include "art/Framework/Principal/Event.h"
181#include "art/Framework/Principal/Handle.h"
182#include "art/Framework/Services/Registry/ServiceHandle.h"
183#include "art_root_io/TFileDirectory.h"
184#include "art_root_io/TFileService.h"
185#include "fhiclcpp/ParameterSet.h"
186#include "messagefacility/MessageLogger/MessageLogger.h"
188#include "larcore/Geometry/Geometry.h"
189#include "larcorealg/Geometry/CryostatGeo.h"
190#include "larcorealg/Geometry/PlaneGeo.h"
191#include "larcorealg/Geometry/TPCGeo.h"
192#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
193#include "lardata/DetectorInfoServices/LArPropertiesService.h"
194#include "lardata/Utilities/AssociationUtil.h"
195#include "lardataobj/RecoBase/Cluster.h"
196#include "lardataobj/RecoBase/Hit.h"
197#include "lardataobj/RecoBase/PFParticle.h"
198#include "lardataobj/RecoBase/Shower.h"
199#include "lardataobj/RecoBase/SpacePoint.h"
200#include "lardataobj/RecoBase/Track.h"
201#include "lardataobj/RecoBase/Wire.h"
202#include "nusimdata/SimulationBase/MCParticle.h"
203#include "nusimdata/SimulationBase/MCTruth.h"
223 m_trackLabel = pset.get<std::string>(
"TrackModule",
"pandoraTrack");
224 m_showerLabel = pset.get<std::string>(
"ShowerModule",
"pandoraShower");
225 m_particleLabel = pset.get<std::string>(
"PFParticleModule",
"pandora");
227 m_clusterLabel = pset.get<std::string>(
"ClusterModule",
"pandora");
229 m_calwireLabel = pset.get<std::string>(
"CalWireModule",
"caldata");
237 mf::LogDebug(
"LArPandora") <<
" *** PFParticleHitDumper::beginJob() *** " << std::endl;
240 art::ServiceHandle<art::TFileService const> tfs;
242 m_pRecoTracks = tfs->make<TTree>(
"pandoraTracks",
"LAr Reco Tracks");
250 m_pReco3D = tfs->make<TTree>(
"pandora3D",
"LAr Reco 3D");
265 m_pReco2D = tfs->make<TTree>(
"pandora2D",
"LAr Reco 2D");
278 m_pRecoComparison = tfs->make<TTree>(
"pandora2Dcomparison",
"LAr Reco 2D (comparison)");
289 m_pRecoWire = tfs->make<TTree>(
"rawdata",
"LAr Reco Wires");
309 if (
m_printDebug) std::cout <<
" *** PFParticleHitDumper::analyze(...) *** " << std::endl;
332 std::cout <<
" Run: " <<
m_run << std::endl;
333 std::cout <<
" Event: " <<
m_event << std::endl;
337 art::ServiceHandle<geo::Geometry const> theGeometry;
378 if (
m_printDebug) std::cout <<
" PFParticles: " << particleVector.size() << std::endl;
382 if (
m_printDebug) std::cout <<
" PFParticleHitDumper::FillRecoTracks(...) " << std::endl;
387 if (
m_printDebug) std::cout <<
" PFParticleHitDumper::FillReco3D(...) " << std::endl;
388 this->
FillReco3D(particleVector, particlesToSpacePoints, spacePointsToHits);
392 if (
m_printDebug) std::cout <<
" PFParticleHitDumper::FillReco2D(...) " << std::endl;
393 this->
FillReco2D(evt, hitVector, hitsToParticles);
398 std::cout <<
" PFParticleHitDumper::FillAssociated2DHits(...) " << std::endl;
402 particlesToHitsClusters,
410 if (
m_printDebug) std::cout <<
" PFParticleHitDumper::FillRecoWires(...) " << std::endl;
428 for (PFParticlesToTracks::const_iterator iter = particlesToTracks.begin(),
429 iterEnd = particlesToTracks.end();
432 const art::Ptr<recob::PFParticle> particle = iter->first;
437 if (!trackVector.empty()) {
439 std::cout <<
" Warning: Found particle with more than one associated track " << std::endl;
441 const art::Ptr<recob::Track> track = *(trackVector.begin());
444 std::cout <<
" PFPARTICLE [" <<
m_particle <<
"] (" << track->NumberTrajectoryPoints()
445 <<
" Trajectory Points)" << std::endl;
447 for (
unsigned int p = 0; p < track->NumberTrajectoryPoints(); ++p) {
448 const auto position(track->LocationAtPoint(p));
479 if (particleVector.empty()) {
m_pReco3D->Fill(); }
484 for (
unsigned int i = 0; i < particleVector.size(); ++i) {
485 const art::Ptr<recob::PFParticle> particle = particleVector.at(i);
486 theParticleMap[particle->Self()] = particle;
490 for (PFParticlesToSpacePoints::const_iterator iter1 = particlesToSpacePoints.begin(),
491 iterEnd1 = particlesToSpacePoints.end();
494 const art::Ptr<recob::PFParticle> particle = iter1->first;
501 if (particle->IsPrimary()) {
m_primary = 1; }
503 const size_t parentID(particle->Parent());
504 PFParticleMap::const_iterator pIter = theParticleMap.find(parentID);
505 if (theParticleMap.end() == pIter)
506 throw cet::exception(
"LArPandora")
507 <<
" PFParticleHitDumper::analyze --- Found particle with ID code";
509 const art::Ptr<recob::PFParticle> particleParent = pIter->second;
515 << spacepoints.size() <<
" Space Points)" << std::endl;
517 for (
unsigned int j = 0; j < spacepoints.size(); ++j) {
518 const art::Ptr<recob::SpacePoint> spacepoint = spacepoints.at(j);
520 m_x = spacepoint->XYZ()[0];
521 m_y = spacepoint->XYZ()[1];
522 m_z = spacepoint->XYZ()[2];
524 SpacePointsToHits::const_iterator iter2 = spacePointsToHits.find(spacepoint);
525 if (spacePointsToHits.end() == iter2)
526 throw cet::exception(
"LArPandora")
527 <<
" PFParticleHitDumper::analyze --- Found space point without associated hit";
529 const art::Ptr<recob::Hit> hit = iter2->second;
530 const geo::WireID& wireID(hit->WireID());
558 for (
unsigned int i = 0; i < particleVector.size(); ++i) {
566 const art::Ptr<recob::PFParticle> particle = particleVector.at(i);
570 PFParticlesToHits::const_iterator pIter = particlesToHits.find(particle);
571 PFParticlesToHits::const_iterator pIter2 = particlesToHitsClusters.find(particle);
573 if (particlesToHitsClusters.end() != pIter2)
m_hitsFromClusters = pIter2->second.size();
576 PFParticlesToTracks::const_iterator iter = particlesToTracks.find(particle);
577 const art::Ptr<recob::Track> track = *(iter->second.begin());
579 TracksToHits::const_iterator iter2 = tracksToHits.find(track);
580 if (tracksToHits.end() != iter2) {
581 const HitVector& hitVector = iter2->second;
586 PFParticlesToShowers::const_iterator iter = particlesToShowers.find(particle);
587 const art::Ptr<recob::Shower>
shower = *(iter->second.begin());
589 ShowersToHits::const_iterator iter2 = showersToHits.find(
shower);
590 if (showersToHits.end() != iter2) {
591 const HitVector& hitVector = iter2->second;
599 <<
" hits from clusters, and its recob::Track/Shower has "
624 if (hitVector.empty()) {
m_pReco2D->Fill(); }
627 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
630 for (
unsigned int i = 0; i < hitVector.size(); ++i) {
631 const art::Ptr<recob::Hit> hit = hitVector.at(i);
636 HitsToPFParticles::const_iterator pIter = hitsToParticles.find(hit);
637 if (hitsToParticles.end() != pIter) {
638 const art::Ptr<recob::PFParticle> particle = pIter->second;
643 const geo::WireID& wireID(hit->WireID());
649 m_q = hit->Integral();
650 m_x = detProp.ConvertTicksToX(hit->PeakTime(), wireID.Plane, wireID.TPC, wireID.Cryostat);
666 art::ServiceHandle<geo::Geometry const> theGeometry;
669 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
672 int signalCounter(0);
674 for (
unsigned int i = 0; i < wireVector.size(); ++i) {
675 const art::Ptr<recob::Wire> wire = wireVector.at(i);
677 const std::vector<float>& signals(wire->Signal());
678 const std::vector<geo::WireID> wireIds = theGeometry->ChannelToWire(wire->Channel());
681 std::cout <<
" numWires=" << wireVector.size() <<
" numSignals=" << signals.size()
688 for (std::vector<float>::const_iterator tIter = signals.begin(), tIterEnd = signals.end();
697 for (std::vector<geo::WireID>::const_iterator wIter = wireIds.begin(),
698 wIterEnd = wireIds.end();
701 const geo::WireID& wireID = *wIter;
707 m_x = detProp.ConvertTicksToX(time, wireID.Plane, wireID.TPC, wireID.Cryostat);
721 art::ServiceHandle<geo::Geometry const> theGeometry;
723 auto const xyzStart = theGeometry->Wire(wireID).GetStart();
724 const double ay(xyzStart.Y());
725 const double az(xyzStart.Z());
727 auto const xyzEnd = theGeometry->Wire(wireID).GetEnd();
728 const double by(xyzEnd.Y());
729 const double bz(xyzEnd.Z());
731 const double ny(by - ay);
732 const double nz(bz - az);
733 const double N2(ny * ny + nz * nz);
735 const double ry(ay - (ay * ny + az * nz) * ny / N2);
736 const double rz(az - (ay * ny + az * nz) * nz / N2);
737 const double sign((rz > 0.0) ? +1.0 : -1.0);
739 return sign * std::sqrt(ry * ry + rz * rz);
745 const unsigned int tpc,
747 const double z)
const
750 art::ServiceHandle<geo::Geometry const> theGeometry;
751 const double m_theta(theGeometry->WireAngleToVertical(geo::kU, geo::TPCID{cstat, tpc}));
752 return z * std::sin(m_theta) - y * std::cos(m_theta);
758 const unsigned int tpc,
760 const double z)
const
763 art::ServiceHandle<geo::Geometry const> theGeometry;
764 const double m_theta(theGeometry->WireAngleToVertical(geo::kV, geo::TPCID{cstat, tpc}));
765 return z * std::sin(m_theta) - y * std::cos(m_theta);
helper function for LArPandoraInterface producer module
static void CollectShowers(const art::Event &evt, const std::string &label, ShowerVector &showerVector, PFParticlesToShowers &particlesToShowers)
Collect the reconstructed PFParticles and associated Showers 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.
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.
static void CollectWires(const art::Event &evt, const std::string &label, WireVector &wireVector)
Collect the reconstructed wires 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.
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 bool IsNeutrino(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as a neutrino.
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.
PFParticleHitDumper class.
TTree * m_pRecoComparison
void analyze(const art::Event &evt)
void FillAssociated2DHits(const art::Event &evt, const PFParticleVector &particleVector, const PFParticlesToHits &particlesToHits, const PFParticlesToHits &particlesToHitsClusters, const PFParticlesToTracks &particlesToTracks, const TracksToHits &tracksToHits, const PFParticlesToShowers &particlesToShowers, const ShowersToHits &showersToHits)
Store number of 2D hits associated to PFParticle in different ways.
void FillRecoTracks(const PFParticlesToTracks &particlesToTracks)
Store 3D track hits.
std::string m_particleLabel
std::string m_hitfinderLabel
int m_hitsFromTrackOrShower
int m_hitsFromSpacePoints
virtual ~PFParticleHitDumper()
Destructor.
void FillReco2D(const art::Event &event, const HitVector &hitVector, const HitsToPFParticles &hitsToParticles)
Store 2D hits.
void FillRecoWires(const art::Event &event, const WireVector &wireVector)
Store raw data.
void FillReco3D(const PFParticleVector &particleVector, const PFParticlesToSpacePoints &particlesToSpacePoints, const SpacePointsToHits &spacePointsToHits)
Store 3D hits.
PFParticleHitDumper(fhicl::ParameterSet const &pset)
Constructor.
bool m_printDebug
switch for print statements (TODO: use message service!)
std::string m_clusterLabel
std::string m_calwireLabel
double YZtoU(const unsigned int cstat, const unsigned int tpc, const double y, const double z) const
Convert from (Y,Z) to U coordinate.
void reconfigure(fhicl::ParameterSet const &pset)
std::string m_spacepointLabel
double YZtoV(const unsigned int cstat, const unsigned int tpc, const double y, const double z) const
Convert from (Y,Z) to V coordinate.
double GetUVW(const geo::WireID &wireID) const
Conversion from wire ID to U/V/W coordinate.
std::string m_showerLabel
std::map< int, art::Ptr< recob::PFParticle > > PFParticleMap
std::vector< art::Ptr< recob::Track > > TrackVector
std::vector< art::Ptr< recob::Shower > > ShowerVector
std::map< art::Ptr< recob::PFParticle >, ShowerVector > PFParticlesToShowers
std::map< art::Ptr< recob::PFParticle >, SpacePointVector > PFParticlesToSpacePoints
std::map< art::Ptr< recob::PFParticle >, HitVector > PFParticlesToHits
std::vector< art::Ptr< recob::Hit > > HitVector
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
std::map< art::Ptr< recob::Shower >, HitVector > ShowersToHits
std::map< art::Ptr< recob::PFParticle >, TrackVector > PFParticlesToTracks
std::map< art::Ptr< recob::Track >, HitVector > TracksToHits
std::map< art::Ptr< recob::SpacePoint >, art::Ptr< recob::Hit > > SpacePointsToHits
std::vector< art::Ptr< recob::SpacePoint > > SpacePointVector
std::map< art::Ptr< recob::Hit >, art::Ptr< recob::PFParticle > > HitsToPFParticles
std::vector< art::Ptr< recob::Wire > > WireVector