All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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:

Classes

struct  Config
 

Public Types

using Parameters = art::EDAnalyzer::Table< Config >
 

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
 

Private Attributes

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

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

using RecoProxyUsageExample::Parameters = art::EDAnalyzer::Table<Config>

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.

78  : EDAnalyzer(config)
79  , trkTag(config().trackInputTag())
80  , vtxTag(config().vertexInputTag())
81  , mcsTag(config().mcsInputTag())
82 {}
RecoProxyUsageExample::RecoProxyUsageExample ( RecoProxyUsageExample const &  )
delete
RecoProxyUsageExample::RecoProxyUsageExample ( RecoProxyUsageExample &&  )
delete

Member Function Documentation

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

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()
ClusterModuleLabel join with tracks
float propDist() const
process_name use argoneut_mc_hitfinder track
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
double chi2() const
Definition: Vertex.h:64
while getopts h
float bestMomentum() const
momentum for best direction fit
Definition: MCSFitResult.h:56
double Length(size_t p=0) const
Access to various track properties.
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
do i e
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 &quot;fitted&quot; track:
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: