1 #include "gallery/ValidHandle.h"
2 #include "canvas/Utilities/InputTag.h"
3 #include "canvas/Persistency/Common/FindMany.h"
5 #include "nusimdata/SimulationBase/MCParticle.h"
22 fTracks.reco_tracks.clear();
23 fTracks.reco_showers.clear();
24 fTracks.truth.clear();
27 std::map<int, unsigned> trackID_to_index;
30 const std::vector<simb::MCParticle> mcparticles = *ev.getValidHandle<std::vector<simb::MCParticle>>(
"largeant");
33 for (
const simb::MCParticle &mc_particle: mcparticles) {
34 trackID_to_index[mc_particle.TrackId()] = ind;
38 for (
const simb::MCParticle &mc_particle: mcparticles) {
40 particle.
pid = mc_particle.PdgCode();
41 particle.
process = mc_particle.Process();
42 for (
unsigned i = 0; i < mc_particle.NumberDaughters(); i++) {
43 int daughter_id = mc_particle.Daughter(i);
44 if (trackID_to_index.count(daughter_id)) particle.
daughters.push_back(trackID_to_index.at(daughter_id));
46 particle.
energy = mc_particle.E();
48 if (mc_particle.NumberTrajectoryPoints() > 0) {
49 for (
unsigned i = 0; i < mc_particle.NumberTrajectoryPoints(); i++) {
50 const TVector3 &pos = mc_particle.Position(i).Vect();
51 std::array<float, 3> traj {(float)pos.X(), (float)pos.Y(), (float)pos.Z()};
56 const TVector3 &pos = mc_particle.Position().Vect();
57 std::array<float, 3> traj {(float)pos.X(), (float)pos.Y(), (float)pos.Z()};
61 std::cout <<
"Particle: " << mc_particle.TrackId() <<
" PID: " << mc_particle.PdgCode() <<
" process: " << mc_particle.Process() <<
" energy: " << mc_particle.E() << std::endl;
62 fTracks.truth.push_back(std::move(particle));
66 const auto &track_handle = ev.getValidHandle<std::vector<recob::Track>>(
"pandoraTrack");
67 const auto &shower_handle = ev.getValidHandle<std::vector<recob::Shower>>(
"pandoraShower");
69 art::FindManyP<recob::Hit> tracks_to_hits(track_handle, ev,
"pandoraTrack");
70 art::FindManyP<recob::PFParticle> tracks_to_particles(track_handle, ev,
"pandoraTrack");
72 art::FindManyP<recob::PFParticle> showers_to_particles(shower_handle, ev,
"pandoraShower");
73 art::FindManyP<recob::Hit> showers_to_hits(shower_handle, ev,
"pandoraShower");
76 std::map<unsigned, unsigned> particle_to_showerID;
77 std::map<unsigned, unsigned> particle_to_trackID;
78 for (
unsigned track_id = 0; track_id < track_handle->size(); track_id++) {
79 unsigned particleID = tracks_to_particles.at(track_id).at(0)->Self();
80 std::cout <<
"track: " << track_id <<
" to particle: " << particleID << std::endl;
81 particle_to_trackID[particleID] = track_id;
84 for (
unsigned shower_id = 0; shower_id < shower_handle->size(); shower_id++) {
85 unsigned particleID = showers_to_particles.at(shower_id).at(0)->Self();
86 std::cout <<
"shower: " << shower_id <<
" to particle: " << particleID << std::endl;
87 particle_to_showerID[particleID] = shower_id;
90 for (
unsigned track_id = 0; track_id < track_handle->size(); track_id++) {
91 const recob::Track &rb_track = (*track_handle)[track_id];
97 std::vector<art::Ptr<recob::Hit>> hits = tracks_to_hits.at(track_id);
101 if (trackID_to_index.count(mcp_track_id)) track.
truth_match = trackID_to_index.at(mcp_track_id);
106 for (
unsigned daughter: pfparticle.
Daughters()) {
107 std::cout <<
"Daughter! " << daughter << std::endl;
108 if (particle_to_trackID.count(daughter)) track.
track_daughters.push_back(particle_to_trackID.at(daughter));
109 else if (particle_to_showerID.count(daughter)) track.
shower_daughters.push_back(particle_to_showerID.at(daughter));
114 fTracks.reco_tracks.push_back(track);
117 for (
unsigned shower_id = 0; shower_id < shower_handle->size(); shower_id++) {
118 const recob::Shower &rb_shower = (*shower_handle)[shower_id];
125 std::vector<art::Ptr<recob::Hit>> hits = showers_to_hits.at(shower_id);
129 if (trackID_to_index.count(mcp_track_id)) shower.
truth_match = trackID_to_index.at(mcp_track_id);
134 for (
unsigned daughter: pfparticle.
Daughters()) {
135 std::cout <<
"Daughter! " << daughter << std::endl;
136 if (particle_to_trackID.count(daughter)) shower.
track_daughters.push_back(particle_to_trackID.at(daughter));
137 else if (particle_to_showerID.count(daughter)) shower.
shower_daughters.push_back(particle_to_showerID.at(daughter));
140 fTracks.reco_showers.push_back(shower);
142 std::cout <<
"Match to: " << mcp_track_id << std::endl;
float start_err[3]
Error in start location of shower [cm].
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
std::vector< std::array< float, 3 > > trajectory
True trajectory of the particle [cm].
std::vector< std::array< float, 3 > > trajectory
The reconstructed trajectory [cm].
std::vector< unsigned > shower_daughters
The list of "daughter" showers to this one. Each entry is the index into the reco list of each daught...
const TVector3 & Direction() const
Declaration of signal hit object.
int truth_match
Match to true particle. -1 if no truth match exists. Otherwise, is the index into the truth list...
Point_t const & LocationAtPoint(size_t i) const
TTree * fTree
The output ROOT tree.
void Initialize(fhicl::ParameterSet *config=NULL)
process_name use argoneut_mc_hitfinder track
std::vector< unsigned > track_daughters
The list of "daughter" tracks to this one. Each entry is the index into the reco list of each daughte...
unsigned int CountValidPoints() const
float energy
Initial energy of the particle [GeV].
float start[3]
Start location of shower [cm].
process_name standard_reco_uboone reco
std::string process
Process which created this particle.
std::vector< unsigned > track_daughters
The list of "daughter" tracks to this one. Each entry is the index into the reco list of each daughte...
const TVector3 & DirectionErr() const
int TrueParticleIDFromTotalTrueEnergy(const core::ProviderManager &manager, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
#define DECLARE_SBN_PROCESSOR(classname)
Provides recob::Track data product.
int truth_match
Match to true particle. -1 if no truth match exists. Otherwise, is the index into the truth list...
Hierarchical representation of particle flow.
float direction_err[3]
Error in initial direction of shower.
const TVector3 & ShowerStart() const
std::vector< unsigned > shower_daughters
The list of "daughter" showers to this one. Each entry is the index into the reco list of each daught...
std::vector< unsigned > daughters
The list of true "daughter" particles to this one. Each entry is the index into the truth list of eac...
const TVector3 & ShowerStartErr() const
float direction[3]
Initialial direction of shower (unit vector)
BEGIN_PROLOG could also be cout
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
bool ProcessEvent(const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)