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

Runs a test of proxy::Tracks interface. More...

Inheritance diagram for TrackProxyTest:
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

 TrackProxyTest (Parameters const &config)
 
 TrackProxyTest (TrackProxyTest const &)=delete
 
 TrackProxyTest (TrackProxyTest &&)=delete
 
TrackProxyTestoperator= (TrackProxyTest const &)=delete
 
TrackProxyTestoperator= (TrackProxyTest &&)=delete
 
virtual void analyze (art::Event const &event) 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 Member Functions

void proxyUsageExample (art::Event const &event) const
 An example of how to access the information via track proxy. More...
 
auto getLongTracks (art::Event const &event, double minLength) const
 Returns proxies to tracks longer than a certain length. More...
 
void testTracks (art::Event const &event)
 Performs the actual test. More...
 
template<typename Track >
void processTrack (Track const &track) const
 Single-track processing function example. More...
 
template<typename TrackPoint >
void processPoint (TrackPoint const &point) const
 Single-track-point processing function example. More...
 

Private Attributes

art::InputTag tracksTag
 Tag for the input tracks. More...
 

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

Runs a test of proxy::Tracks interface.

This module is that it uses Boost unit test library, and as such it must be run with lar_ut instead of lar.

Definition at line 50 of file TrackProxyTest_module.cc.

Member Typedef Documentation

Definition at line 64 of file TrackProxyTest_module.cc.

Constructor & Destructor Documentation

TrackProxyTest::TrackProxyTest ( Parameters const &  config)
inlineexplicit

Definition at line 66 of file TrackProxyTest_module.cc.

69  {}
static Config * config
Definition: config.cpp:1054
art::InputTag tracksTag
Tag for the input tracks.
TrackProxyTest::TrackProxyTest ( TrackProxyTest const &  )
delete
TrackProxyTest::TrackProxyTest ( TrackProxyTest &&  )
delete

Member Function Documentation

void TrackProxyTest::analyze ( art::Event const &  event)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 374 of file TrackProxyTest_module.cc.

374  {
375 
376  // "test" that track proxies survive their collection (part I)
377  const double minLength = 30.0;
378  auto const longTracks = getLongTracks(event, minLength);
379 
380  // usage example (supposed to be educational)
382 
383  // actual test
384  testTracks(event);
385 
386  // "test" that track proxies survive their collection (part II)
387  mf::LogVerbatim("TrackProxyTest")
388  << longTracks.size() << " tracks are longer than " << minLength << " cm:";
389  std::for_each(longTracks.begin(), longTracks.end(),
390  [this](auto const& track){ this->processTrack(track); });
391 
392 } // TrackProxyTest::analyze()
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
void testTracks(art::Event const &event)
Performs the actual test.
void proxyUsageExample(art::Event const &event) const
An example of how to access the information via track proxy.
auto getLongTracks(art::Event const &event, double minLength) const
Returns proxies to tracks longer than a certain length.
void processTrack(Track const &track) const
Single-track processing function example.
Event finding and building.
auto TrackProxyTest::getLongTracks ( art::Event const &  event,
double  minLength 
) const
private

Returns proxies to tracks longer than a certain length.

Definition at line 163 of file TrackProxyTest_module.cc.

164 {
165  //
166  // this code is not a particularly good practice, but it is aimed to check
167  // that after the proxy collection is out of scope, elements copied from it
168  // are still valid
169  //
170  auto tracks = proxy::getCollection<proxy::Tracks>
172 
173  std::vector<decltype(tracks)::element_proxy_t> longTracks;
174  for (auto track: tracks) {
175  if (track->Length() >= minLength) longTracks.push_back(track);
176  } // for track
177  return longTracks;
178 
179 } // TrackProxyTest::proxyUsageExample()
Definition: tracks.py:1
art::InputTag tracksTag
Tag for the input tracks.
auto withFitHitInfo(art::InputTag const &inputTag)
Adds recob::TrackFitHitInfo information to the proxy.
Definition: Track.h:1133
TrackProxyTest& TrackProxyTest::operator= ( TrackProxyTest const &  )
delete
TrackProxyTest& TrackProxyTest::operator= ( TrackProxyTest &&  )
delete
template<typename TrackPoint >
void TrackProxyTest::processPoint ( TrackPoint const &  point) const
private

Single-track-point processing function example.

Definition at line 104 of file TrackProxyTest_module.cc.

104  {
105 
106  mf::LogVerbatim log("TrackProxyTest");
107  log <<
108  " [#" << point.index() << "] at " << point.position()
109  << " (momentum: " << point.momentum() << "), flags: "
110  << point.flags();
111 
112  recob::Hit const* hit = point.hit();
113  if (hit) {
114  log << " with a Q=" << hit->Integral() << " hit on channel "
115  << hit->Channel() << " at tick " << hit->PeakTime()
116  << ", measured: " << point.fitInfoPtr()->hitMeas();
117  }
118  else
119  log << " (no associated hit)";
120 
121 } // TrackProxyTest::processPoint()
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
Detector simulation of raw signals on wires.
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
template<typename Track >
void TrackProxyTest::processTrack ( Track const &  track) const
private

Single-track processing function example.

Definition at line 126 of file TrackProxyTest_module.cc.

126  {
127 
128  recob::Track const& trackRef = track.track();
129 
130  mf::LogVerbatim("TrackProxyTest")
131  << "[#" << track.index() << "] track " << trackRef
132  << " " << track->Length() << " cm long, with "
133  << trackRef.NPoints() << " points and " << track.nHits()
134  << " hits:";
135 
136  for (auto point: track.points()) {
137  processPoint(point);
138  } // for points in track
139 
140 } // TrackProxyTest::processTrack()
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:167
size_t NPoints() const
Definition: Track.h:103
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
void processPoint(TrackPoint const &point) const
Single-track-point processing function example.
void TrackProxyTest::proxyUsageExample ( art::Event const &  event) const
private

An example of how to access the information via track proxy.

Definition at line 144 of file TrackProxyTest_module.cc.

144  {
145 
146  auto tracks = proxy::getCollection<proxy::Tracks>
148 
149  if (tracks.empty()) {
150  mf::LogVerbatim("TrackProxyTest") << "No tracks in '" << tracksTag.encode()
151  << "'";
152  return;
153  }
154 
155  mf::LogVerbatim("TrackProxyTest") << "Collection '" << tracksTag.encode()
156  << "' contains " << tracks.size() << " tracks.";
157 
158 } // TrackProxyTest::proxyUsageExample()
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Definition: tracks.py:1
art::InputTag tracksTag
Tag for the input tracks.
auto withFitHitInfo(art::InputTag const &inputTag)
Adds recob::TrackFitHitInfo information to the proxy.
Definition: Track.h:1133
void TrackProxyTest::testTracks ( art::Event const &  event)
private

Performs the actual test.

Definition at line 187 of file TrackProxyTest_module.cc.

187  {
188 
189  auto expectedTracksHandle
190  = event.getValidHandle<std::vector<recob::Track>>(tracksTag);
191  auto const& expectedTracks = *expectedTracksHandle;
192 
193  mf::LogInfo("TrackProxyTest")
194  << "Starting test on " << expectedTracks.size() << " tracks from '"
195  << tracksTag.encode() << "'";
196 
197  art::FindManyP<recob::Hit> hitsPerTrack
198  (expectedTracksHandle, event, tracksTag);
199 
200  art::FindOneP<recob::TrackTrajectory> trajectoryPerTrack
201  (expectedTracksHandle, event, tracksTag);
202 
203  auto const& expectedTrackFitHitInfo
204  = *(event.getValidHandle<std::vector<std::vector<recob::TrackFitHitInfo>>>
205  (tracksTag));
206 
207  auto tracks = proxy::getCollection<proxy::Tracks>(event, tracksTag
208  , proxy::withAssociatedAs<recob::Hit, tag::SpecialHits>()
211  );
212 
213  //
214  // we try to access something we did not "register" in the proxy: space points
215  //
216  static_assert(!tracks.has<recob::SpacePoint>(),
217  "Track proxy does NOT have space points available!!!");
218 
219  static_assert(
221  "recob::TrackFitHitInfo not found!!!"
222  );
223 
224 
225  BOOST_TEST(tracks.empty() == expectedTracks.empty());
226  BOOST_TEST(tracks.size() == expectedTracks.size());
227 
228  BOOST_TEST(tracks.size() == expectedTrackFitHitInfo.size());
229  decltype(auto) allFitHitInfo = tracks.get<recob::TrackFitHitInfo>();
230  static_assert(
231  std::is_lvalue_reference<decltype(allFitHitInfo)>(),
232  "Copy of parallel data!"
233  );
234  BOOST_TEST
235  (allFitHitInfo.data() == std::addressof(expectedTrackFitHitInfo));
236 
237  auto fitHitInfoSize
238  = std::distance(allFitHitInfo.begin(), allFitHitInfo.end());
239  BOOST_TEST(fitHitInfoSize == expectedTrackFitHitInfo.size());
240 
241  std::size_t iExpectedTrack = 0;
242  for (auto const& trackProxy: tracks) {
243  BOOST_TEST_CHECKPOINT("Track #" << trackProxy.index());
244 
245  auto const& expectedTrack = expectedTracks[iExpectedTrack];
246  auto const& expectedHits = hitsPerTrack.at(iExpectedTrack);
247  auto const& expectedFitHitInfo = expectedTrackFitHitInfo[iExpectedTrack];
248  auto const& expectedTrajPtr = trajectoryPerTrack.at(iExpectedTrack);
249  recob::TrackTrajectory const* expectedTrajCPtr
250  = expectedTrajPtr.isNull()? nullptr: expectedTrajPtr.get();
251 
252  recob::Track const& trackRef = *trackProxy;
253 
254  BOOST_TEST
255  (std::addressof(trackRef) == std::addressof(expectedTrack));
256  BOOST_TEST
257  (std::addressof(trackProxy.track()) == std::addressof(expectedTrack));
258  BOOST_TEST(trackProxy.nHits() == expectedHits.size());
259  BOOST_TEST(trackProxy.index() == iExpectedTrack);
260 
261  decltype(auto) fitHitInfo = trackProxy.get<recob::TrackFitHitInfo>();
262  static_assert(
263  std::is_lvalue_reference<decltype(fitHitInfo)>(),
264  "Copy of parallel data element!"
265  );
266  BOOST_TEST
267  (std::addressof(fitHitInfo), std::addressof(expectedFitHitInfo));
268  BOOST_TEST(fitHitInfo.size() == expectedFitHitInfo.size());
269 
270  BOOST_TEST
271  (trackProxy.get<tag::SpecialHits>().size(), expectedHits.size());
272 
273  // trajectory?
274  BOOST_TEST
275  (trackProxy.hasOriginalTrajectory() == !expectedTrajPtr.isNull());
276  if (expectedTrajCPtr) {
277  BOOST_TEST(trackProxy.originalTrajectoryPtr() == expectedTrajPtr);
278  BOOST_TEST(&trackProxy.originalTrajectory() == expectedTrajPtr.get());
279  }
280  else {
281  BOOST_TEST(!(trackProxy.originalTrajectoryPtr()));
282  }
283 
284  BOOST_TEST(
285  trackProxy(proxy::Tracks::Fitted) ==
286  std::addressof(expectedTrack.Trajectory())
287  );
288  BOOST_TEST(trackProxy(proxy::Tracks::Unfitted) == expectedTrajCPtr);
289  BOOST_TEST(trackProxy(proxy::Tracks::NTypes) == nullptr);
290 
291  // direct interface to recob::Track
292  BOOST_TEST(trackProxy->NPoints() == expectedTrack.NPoints());
293 
294 
295  std::array<unsigned int, recob::TrajectoryPointFlagTraits::maxFlags()>
296  flagCounts;
297  flagCounts.fill(0U);
298  std::size_t iPoint = 0;
299  for (auto const& pointInfo: trackProxy.points()) {
300  BOOST_TEST_CHECKPOINT(" point #" << pointInfo.index());
301 
302  decltype(auto) expectedPointFlags = expectedTrack.FlagsAtPoint(iPoint);
303 
304  BOOST_TEST(pointInfo.index() == iPoint);
305  BOOST_TEST(
306  pointInfo.position() ==
307  expectedTrack.Trajectory().LocationAtPoint(iPoint)
308  );
309  BOOST_TEST
310  (pointInfo.momentum() == expectedTrack.MomentumVectorAtPoint(iPoint));
311  BOOST_TEST(pointInfo.flags() == expectedPointFlags);
312  if (expectedPointFlags.hasOriginalHitIndex()) {
313  BOOST_TEST
314  (pointInfo.hitPtr().key() == expectedPointFlags.fromHit());
315  }
316  else {
317  BOOST_TEST(!pointInfo.hitPtr());
318  }
319 
320  // collect the count of each flag type
321  for (auto flag: {
326  })
327  {
328  if (!expectedPointFlags.isDefined(flag)) continue;
329  if (expectedPointFlags.isSet(flag)) ++flagCounts[flag.index()];
330  }
331 
332  BOOST_TEST
333  (fitHitInfo[iPoint].WireId() == expectedFitHitInfo[iPoint].WireId());
334  BOOST_TEST
335  (pointInfo.fitInfoPtr() == std::addressof(expectedFitHitInfo[iPoint]));
336  BOOST_TEST(
337  std::addressof(fitHitInfo[iPoint]) ==
338  std::addressof(expectedFitHitInfo[iPoint])
339  );
340 
341  ++iPoint;
342  } // for
343  BOOST_TEST(iPoint == expectedTrack.NPoints());
344 
345  // testing pointsWithFlags() with some single flags
346  for (auto flag: {
351  })
352  {
353  BOOST_TEST_CHECKPOINT(" flag: " << flag);
354  unsigned int flagCount = 0U;
355  for (auto const& pointInfo: trackProxy.pointsWithFlags(flag)) {
356 
357  BOOST_TEST_CHECKPOINT(" point #" << pointInfo.index());
358  BOOST_TEST(pointInfo.flags().isDefined(flag));
359  BOOST_TEST(pointInfo.flags().isSet(flag));
360 
361  ++flagCount;
362  } // for pointInfo
363  BOOST_TEST(flagCount == flagCounts[flag.index()]);
364  } // for flag
365 
366  ++iExpectedTrack;
367  } // for
368  BOOST_TEST(iExpectedTrack == expectedTracks.size());
369 
370 } // TrackProxyTest::testTracks()
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
auto withOriginalTrajectory(art::InputTag const &inputTag)
Adds recob::TrackTrajectory information to the proxy.
Definition: Track.h:1064
static constexpr Flag_t Suspicious
The point reconstruction is somehow questionable.
Reconstruction base classes.
static constexpr Flag_t NoPoint
The trajectory point is not defined.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
STL namespace.
std::string encode() const
Definition: InputTag.cc:97
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
A trajectory in space reconstructed from hits.
Object storing per-hit information from a track fit.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
static constexpr Flag_t HitIgnored
Hit was not included for the computation of the trajectory.
Definition: tracks.py:1
for(std::string line;std::getline(inFile, line);)
Definition: regex_t.cc:37
Represents a track trajectory before the final fit.
Definition: Track.h:514
art::InputTag tracksTag
Tag for the input tracks.
static constexpr Flag_t DetectorIssue
The hit is associated to a problematic channel.
auto withFitHitInfo(art::InputTag const &inputTag)
Adds recob::TrackFitHitInfo information to the proxy.
Definition: Track.h:1133
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
Represents a track trajectory from the final fit.
Definition: Track.h:515
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
def momentum(x1, x2, x3, scale=1.)
Number of supported track types.
Definition: Track.h:516
if(!yymsg) yymsg
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
Event finding and building.

Member Data Documentation

art::InputTag TrackProxyTest::tracksTag
private

Tag for the input tracks.

Definition at line 80 of file TrackProxyTest_module.cc.


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