Classes | Public Types | Public Member Functions | Private Attributes | List of all members
RecoProxyUsageExample Class Reference

Example of analyzer accessing vertices, tracks, and hits, using RecoBaseProxy. More...

Inheritance diagram for RecoProxyUsageExample:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Classes

struct  Config
 

Public Types

using Parameters = art::EDAnalyzer::Table< Config >
 
- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 RecoProxyUsageExample (Parameters const &p)
 
 RecoProxyUsageExample (RecoProxyUsageExample const &)=delete
 
 RecoProxyUsageExample (RecoProxyUsageExample &&)=delete
 
RecoProxyUsageExampleoperator= (RecoProxyUsageExample const &)=delete
 
RecoProxyUsageExampleoperator= (RecoProxyUsageExample &&)=delete
 
void analyze (art::Event const &e) override
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

art::InputTag trkTag
 
art::InputTag vtxTag
 
art::InputTag mcsTag
 

Additional Inherited Members

- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Example of analyzer accessing vertices, tracks, and hits, using RecoBaseProxy.

The corresponding code without using RecoBaseProxy is also provided as a reference.

See also
LArSoftProxies.
Author
G. Cerati (FNAL, MicroBooNE)
Date
2018
Version
1.0

Definition at line 37 of file RecoProxyUsageExample_module.cc.

Member Typedef Documentation

Definition at line 55 of file RecoProxyUsageExample_module.cc.

Constructor & Destructor Documentation

RecoProxyUsageExample::RecoProxyUsageExample ( Parameters const &  p)
explicit

Definition at line 77 of file RecoProxyUsageExample_module.cc.

79  , trkTag(config().trackInputTag())
80  , vtxTag(config().vertexInputTag())
81  , mcsTag(config().mcsInputTag())
82 {}
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
static Config * config
Definition: config.cpp:1054
RecoProxyUsageExample::RecoProxyUsageExample ( RecoProxyUsageExample const &  )
delete
RecoProxyUsageExample::RecoProxyUsageExample ( RecoProxyUsageExample &&  )
delete

Member Function Documentation

void RecoProxyUsageExample::analyze ( art::Event const &  e)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 84 of file RecoProxyUsageExample_module.cc.

85 {
86 
87  //
88  // Example using proxies.
89  //
90 
91  //
92  // Get vertex collection proxy and associated tracks, with meta data
93  auto const& vertices = proxy::getCollection<std::vector<recob::Vertex> >(e,vtxTag,proxy::withAssociatedMeta<recob::Track, recob::VertexAssnMeta>());
94  //
95  // Get track collection proxy and parallel mcs fit data (associated hits loaded by default)
96  // Note: if tracks were produced from a TrackTrajectory collection you could access the original trajectories adding ',proxy::withOriginalTrajectory()' to the list of arguments
97  auto const& tracks = proxy::getCollection<proxy::Tracks>(e,trkTag,proxy::withParallelData<recob::MCSFitResult>(mcsTag));
98  //
99  // Loop over vertex proxies (get recob::Vertex with '->')
100  for (const auto& v : vertices) {
101  mf::LogVerbatim("ProxyExample") << "vertex pos=" << v->position() << " chi2=" << v->chi2();
102  //
103  // Get tracks(+meta) associated to vertex, and loop over them
104  const auto& assocTracks = v.get<recob::Track>();
105  for (const auto& trackAssn : assocTracks) {
106  //
107  // Note that here we access the methods of recob::Track using '->' and that we get the recob::VertexAssnMeta with '.data()'
108  mf::LogVerbatim("ProxyExample") << "track with key=" << trackAssn.key() << " and length=" << trackAssn->Length() << " has propDist from vertex=" << trackAssn.data().propDist();
109  //
110  // Now get the track proxy from the key, and use it to access the parallel MCSFitResult; note that the track proxy has already access to the associated hits
111  const auto& track = tracks[trackAssn.key()];
112  const recob::MCSFitResult& assocMCS = track.get<recob::MCSFitResult>();
113  //
114  // Print some information; here we access the methods of recob::Track using '->' and proxy::Track with '.'
115  // Note: if the original trajectories were associated to the proxy, you could get the original/unfitted length with 'track(proxy::Tracks::Unfitted)->Length()'
116  mf::LogVerbatim("ProxyExample") << "\tCountValidPoints=" << track->CountValidPoints() << " and nHits=" << track.nHits() << " and MCSMom=" << assocMCS.bestMomentum();
117  //
118  // Now loop over the associated hits from the track proxy
119  if (track.nHits()<50) {
120  for (const art::Ptr<recob::Hit>& h : track.hits()) {
121  mf::LogVerbatim("ProxyExample") << "\t\thit wire=" << h->WireID() << " peak time=" << h->PeakTime();
122  }
123  }
124  } // for associated tracks
125  } // for vertices
126 
127  //
128  // Same example without using proxies.
129  //
130 
131  //
132  // Get vertex collection handle and get associated tracks with meta data using FindManyP
133  auto const& vertexHandle = e.getValidHandle<std::vector<recob::Vertex> >(vtxTag);
134  auto const& vertexColl = *vertexHandle;
135  art::FindManyP<recob::Track, recob::VertexAssnMeta> assocTracksWithMeta(vertexHandle, e, vtxTag);
136  //
137  // Get track collection handle, get associated hits using FindMany, and get mcs collection (parallel to track collection)
138  auto const& trackHandle = e.getValidHandle<std::vector<recob::Track> >(trkTag);
139  art::FindMany<recob::Hit> assocHits(trackHandle, e, trkTag);
140  auto const& mcsColl = *(e.getValidHandle<std::vector<recob::MCSFitResult> >(mcsTag));
141  //
142  // Loop over the vertex collection
143  for (size_t iv=0; iv<vertexColl.size(); ++iv) {
144  const recob::Vertex& v = vertexColl[iv];
145  mf::LogVerbatim("ProxyExample") << "vertex pos=" << v.position() << " chi2=" << v.chi2();
146  //
147  // Get tracks(+meta) associated to vertex, and loop over them
148  auto const& assocTks = assocTracksWithMeta.at(iv);
149  auto const& assocTksMeta = assocTracksWithMeta.data(iv);
150  for (size_t itk=0;itk<assocTks.size();++itk) {
151  //
152  // Get the recob::Track and VertexAssnMeta instance
153  const art::Ptr<recob::Track>& trackAssn = assocTks[itk];
154  const recob::VertexAssnMeta* trackMeta = assocTksMeta[itk];
155  mf::LogVerbatim("ProxyExample") << "track with key=" << trackAssn.key() << " and length=" << trackAssn->Length() << " has propDist from vertex=" << trackMeta->propDist();
156  //
157  // Get the associated recob::Hit and the MCSFitResult
158  const recob::MCSFitResult& assocMCS = mcsColl[trackAssn.key()];
159  const std::vector<recob::Hit const*>& hits = assocHits.at(trackAssn.key());
160  //
161  // Print some information
162  mf::LogVerbatim("ProxyExample") << "\tCountValidPoints=" << trackAssn->CountValidPoints() << " and nHits=" << hits.size() << " and MCSMom=" << assocMCS.bestMomentum();
163  //
164  // Now loop over the associated hits
165  if (hits.size()<50) {
166  for (const recob::Hit* h : hits) {
167  mf::LogVerbatim("ProxyExample") << "\t\thit wire=" << h->WireID() << " peak time=" << h->PeakTime();
168  }
169  }
170  } // for track
171  } // for vertex
172 
173 } // RecoProxyUsageExample::analyze()
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
float propDist() const
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
double chi2() const
Definition: Vertex.h:64
unsigned int CountValidPoints() const
Definition: Track.h:112
float bestMomentum() const
momentum for best direction fit
Definition: MCSFitResult.h:56
const double e
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:167
key_type key() const noexcept
Definition: Ptr.h:216
Class storing the meta-data for track-vertex association: status, propagation distance, impact parameter, impact parameter error, chi2.
Class storing the result of the Maximum Likelihood fit of Multiple Coulomb Scattering angles between ...
Definition: MCSFitResult.h:19
Definition: tracks.py:1
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
const Point_t & position() const
Return vertex 3D position.
Definition: Vertex.h:60
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
RecoProxyUsageExample& RecoProxyUsageExample::operator= ( RecoProxyUsageExample const &  )
delete
RecoProxyUsageExample& RecoProxyUsageExample::operator= ( RecoProxyUsageExample &&  )
delete

Member Data Documentation

art::InputTag RecoProxyUsageExample::mcsTag
private

Definition at line 73 of file RecoProxyUsageExample_module.cc.

art::InputTag RecoProxyUsageExample::trkTag
private

Definition at line 73 of file RecoProxyUsageExample_module.cc.

art::InputTag RecoProxyUsageExample::vtxTag
private

Definition at line 73 of file RecoProxyUsageExample_module.cc.


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