All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
sbnana::TrackReducer Class Reference

#include <TrackReducer.h>

Inheritance diagram for sbnana::TrackReducer:
core::SelectionBase core::ProcessorBase

Public Member Functions

void Initialize (fhicl::ParameterSet *config=NULL)
 
void Finalize ()
 
bool ProcessEvent (const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)
 
- Public Member Functions inherited from core::SelectionBase
 SelectionBase ()
 
virtual ~SelectionBase ()
 
- Public Member Functions inherited from core::ProcessorBase
 ProcessorBase ()
 
virtual ~ProcessorBase ()
 
virtual void FillTree ()
 
virtual void FillRecoTree ()
 
virtual void EventCleanup ()
 
template<class T >
TBranch * AddBranch (std::string name, T *obj)
 
template<class T >
TBranch * AddRecoBranch (std::string name, T *obj)
 

Private Attributes

Tracks fTracks
 

Additional Inherited Members

- Public Attributes inherited from core::ProcessorBase
std::vector
< event::RecoInteraction > * 
fReco
 Reco interaction list. More...
 
- Protected Member Functions inherited from core::ProcessorBase
virtual void Initialize (char *config=NULL)
 
virtual void Setup (char *config=NULL)
 
virtual void Setup (fhicl::ParameterSet *config=NULL)
 
virtual void Teardown ()
 
void BuildEventTree (gallery::Event &ev)
 
void SetupServices (gallery::Event &ev)
 
void UpdateSubRuns (gallery::Event &ev)
 
void UpdateFileMeta (gallery::Event &ev)
 
- Protected Attributes inherited from core::ProcessorBase
unsigned long fEventIndex
 An incrementing index. More...
 
Experiment fExperimentID
 Experiment identifier. More...
 
ProviderManagerfProviderManager
 Interface for provider access. More...
 
std::string fOutputFilename
 The output filename. More...
 
std::string fProviderConfig
 A custom provider config fcl file. More...
 
std::vector< geo::BoxBoundedGeofActiveVolumes
 List of active volumes in configured detector. More...
 
bool fWriteTree
 Enable writing of the main tree. More...
 
TFile * fOutputFile
 The output ROOT file. More...
 
TTree * fTree
 The output ROOT tree. More...
 
event::EventfEvent
 The standard output event data structure. More...
 
bool fWriteRecoTree
 Enable writing of the reco tree. More...
 
TTree * fRecoTree
 The output reco ROOT tree. More...
 
event::RecoEventfRecoEvent
 The standard output reco event data structure. More...
 
TTree * fSubRunTree
 Subrun output tree. More...
 
SubRunfSubRun
 Standard output subrun structure. More...
 
TTree * fFileMetaTree
 File metadata output tree. More...
 
FileMetafFileMeta
 standard output file metadata structure More...
 
TParameter< int > * fExperimentParameter
 Saves value of experiment enum. More...
 
std::set< std::pair< int, int > > fSubRunCache
 Cache stored subruns. More...
 
art::InputTag fTruthTag
 art tag for MCTruth information More...
 
art::InputTag fFluxTag
 art tag for MCFlux information More...
 
std::vector< art::InputTag > fWeightTags
 art tag(s) for MCEventWeight information More...
 
art::InputTag fMCTrackTag
 art tag for MCTrack More...
 
art::InputTag fMCShowerTag
 art tag for MCShower More...
 
art::InputTag fMCParticleTag
 art tag for MCParticle More...
 
std::string fGeneratorProcess
 process_name of process used to run genie. Used to extract subrun/POT information More...
 

Detailed Description

Definition at line 11 of file TrackReducer.h.

Member Function Documentation

void sbnana::TrackReducer::Finalize ( )
inlinevirtual

Perform user-level finalization.

Implements core::ProcessorBase.

Definition at line 14 of file TrackReducer.h.

14 {}
void sbnana::TrackReducer::Initialize ( fhicl::ParameterSet *  config = NULL)
virtual

Perform user-level initialization.

Parameters
configA configuration, as a JSON object.

Implements core::ProcessorBase.

Definition at line 16 of file TrackReducer.cxx.

16  {
17  fTree->Branch("tracks", &fTracks);
18 }
TTree * fTree
The output ROOT tree.
bool sbnana::TrackReducer::ProcessEvent ( const gallery::Event &  ev,
const std::vector< event::Interaction > &  truth,
std::vector< event::RecoInteraction > &  reco 
)
virtual

Process one event.

This also serves as a filter: if the function results false, it acts as a filter and the event is not written out.

Parameters
evThe event, as a gallery::Event
recoReco interactions, to be populated by the user
Returns
True if event passes filter

Implements core::ProcessorBase.

Definition at line 20 of file TrackReducer.cxx.

20  {
21  std::cout << "New Event!\n";
22  fTracks.reco_tracks.clear();
23  fTracks.reco_showers.clear();
24  fTracks.truth.clear();
25 
26  // map of particle track ID's to indices
27  std::map<int, unsigned> trackID_to_index;
28 
29  // get the important truth stuff
30  const std::vector<simb::MCParticle> mcparticles = *ev.getValidHandle<std::vector<simb::MCParticle>>("largeant");
31 
32  unsigned ind = 0;
33  for (const simb::MCParticle &mc_particle: mcparticles) {
34  trackID_to_index[mc_particle.TrackId()] = ind;
35  ind ++;
36  }
37 
38  for (const simb::MCParticle &mc_particle: mcparticles) {
39  TrueParticle particle;
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));
45  }
46  particle.energy = mc_particle.E();
47 
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()};
52  particle.trajectory.push_back(traj);
53  }
54  }
55  else {
56  const TVector3 &pos = mc_particle.Position().Vect();
57  std::array<float, 3> traj {(float)pos.X(), (float)pos.Y(), (float)pos.Z()};
58  particle.trajectory.push_back(traj);
59  }
60 
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));
63 
64  }
65 
66  const auto &track_handle = ev.getValidHandle<std::vector<recob::Track>>("pandoraTrack");
67  const auto &shower_handle = ev.getValidHandle<std::vector<recob::Shower>>("pandoraShower");
68 
69  art::FindManyP<recob::Hit> tracks_to_hits(track_handle, ev, "pandoraTrack");
70  art::FindManyP<recob::PFParticle> tracks_to_particles(track_handle, ev, "pandoraTrack");
71 
72  art::FindManyP<recob::PFParticle> showers_to_particles(shower_handle, ev, "pandoraShower");
73  art::FindManyP<recob::Hit> showers_to_hits(shower_handle, ev, "pandoraShower");
74 
75  // setup ID mappings
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;
82  }
83 
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;
88  }
89 
90  for (unsigned track_id = 0; track_id < track_handle->size(); track_id++) {
91  const recob::Track &rb_track = (*track_handle)[track_id];
92  Track track;
93  for (unsigned i = 0; i < rb_track.CountValidPoints(); i++) {
94  std::array<float, 3> traj {(float)rb_track.LocationAtPoint(i).X(), (float)rb_track.LocationAtPoint(i).Y(), (float)rb_track.LocationAtPoint(i).Z()};
95  track.trajectory.push_back(traj);
96  }
97  std::vector<art::Ptr<recob::Hit>> hits = tracks_to_hits.at(track_id);
98 
99  // truth match
100  int mcp_track_id = SBNRecoUtils::TrueParticleIDFromTotalTrueEnergy(*fProviderManager, hits, true);
101  if (trackID_to_index.count(mcp_track_id)) track.truth_match = trackID_to_index.at(mcp_track_id);
102  else track.truth_match = -1;
103 
104  // get daughters
105  const recob::PFParticle &pfparticle = *tracks_to_particles.at(track_id).at(0);
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));
110  }
111 
112  std::cout << "New Track! n traj: " << track.trajectory.size() << std::endl;;
113 
114  fTracks.reco_tracks.push_back(track);
115  }
116 
117  for (unsigned shower_id = 0; shower_id < shower_handle->size(); shower_id++) {
118  const recob::Shower &rb_shower = (*shower_handle)[shower_id];
119  Shower shower;
120  rb_shower.Direction().GetXYZ(shower.direction);
121  rb_shower.DirectionErr().GetXYZ(shower.direction_err);
122  rb_shower.ShowerStart().GetXYZ(shower.start);
123  rb_shower.ShowerStartErr().GetXYZ(shower.start_err);
124 
125  std::vector<art::Ptr<recob::Hit>> hits = showers_to_hits.at(shower_id);
126 
127  // truth match
128  int mcp_track_id = SBNRecoUtils::TrueParticleIDFromTotalTrueEnergy(*fProviderManager, hits, true);
129  if (trackID_to_index.count(mcp_track_id)) shower.truth_match = trackID_to_index.at(mcp_track_id);
130  else shower.truth_match = -1;
131 
132  // get daughters
133  const recob::PFParticle &pfparticle = *showers_to_particles.at(shower_id).at(0);
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));
138  }
139 
140  fTracks.reco_showers.push_back(shower);
141  std::cout << "New Shower! at: " << rb_shower.ShowerStart().X() << std::endl;
142  std::cout << "Match to: " << mcp_track_id << std::endl;
143  }
144 
145  return true;
146 }
float start_err[3]
Error in start location of shower [cm].
Definition: Data.h:16
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:114
std::vector< std::array< float, 3 > > trajectory
True trajectory of the particle [cm].
Definition: Data.h:27
std::vector< std::array< float, 3 > > trajectory
The reconstructed trajectory [cm].
Definition: Data.h:8
std::vector< unsigned > shower_daughters
The list of &quot;daughter&quot; showers to this one. Each entry is the index into the reco list of each daught...
Definition: Data.h:20
const TVector3 & Direction() const
Definition: Shower.h:189
int truth_match
Match to true particle. -1 if no truth match exists. Otherwise, is the index into the truth list...
Definition: Data.h:11
Point_t const & LocationAtPoint(size_t i) const
process_name use argoneut_mc_hitfinder track
Definition: Data.h:14
process_name shower
Definition: cheaterreco.fcl:51
Definition: Data.h:7
std::vector< unsigned > track_daughters
The list of &quot;daughter&quot; tracks to this one. Each entry is the index into the reco list of each daughte...
Definition: Data.h:9
unsigned int CountValidPoints() const
float energy
Initial energy of the particle [GeV].
Definition: Data.h:26
float start[3]
Start location of shower [cm].
Definition: Data.h:15
std::string process
Process which created this particle.
Definition: Data.h:29
std::vector< unsigned > track_daughters
The list of &quot;daughter&quot; tracks to this one. Each entry is the index into the reco list of each daughte...
Definition: Data.h:19
const TVector3 & DirectionErr() const
Definition: Shower.h:190
int TrueParticleIDFromTotalTrueEnergy(const core::ProviderManager &manager, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
int truth_match
Match to true particle. -1 if no truth match exists. Otherwise, is the index into the truth list...
Definition: Data.h:21
std::vector< TrueParticle > truth
Definition: Data.h:35
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
std::vector< Track > reco_tracks
Definition: Data.h:34
ProviderManager * fProviderManager
Interface for provider access.
float direction_err[3]
Error in initial direction of shower.
Definition: Data.h:18
const TVector3 & ShowerStart() const
Definition: Shower.h:192
int pid
Particle ID.
Definition: Data.h:25
std::vector< unsigned > shower_daughters
The list of &quot;daughter&quot; showers to this one. Each entry is the index into the reco list of each daught...
Definition: Data.h:10
std::vector< unsigned > daughters
The list of true &quot;daughter&quot; particles to this one. Each entry is the index into the truth list of eac...
Definition: Data.h:28
const TVector3 & ShowerStartErr() const
Definition: Shower.h:193
float direction[3]
Initialial direction of shower (unit vector)
Definition: Data.h:17
std::vector< Shower > reco_showers
Definition: Data.h:33
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 &quot;fitted&quot; track:

Member Data Documentation

Tracks sbnana::TrackReducer::fTracks
private

Definition at line 18 of file TrackReducer.h.


The documentation for this class was generated from the following files: