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

Classes

struct  Config
 

Public Types

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

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
 

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...
 

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

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

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.

67  : art::EDAnalyzer(config)
68  , tracksTag(config().tracksTag())
69  {}
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

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)
381  proxyUsageExample(event);
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()
void testTracks(art::Event const &event)
Performs the actual test.
process_name use argoneut_mc_hitfinder track
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.
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>
171  (event, tracksTag, proxy::withFitHitInfo());
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()
ClusterModuleLabel join with tracks
process_name use argoneut_mc_hitfinder track
art::InputTag tracksTag
Tag for the input tracks.
auto withFitHitInfo(art::InputTag const &inputTag)
Adds recob::TrackFitHitInfo information to the proxy.
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
process_name hit
Definition: cheaterreco.fcl:51
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()
process_name use argoneut_mc_hitfinder track
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track:
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>
147  (event, tracksTag, proxy::withFitHitInfo());
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()
ClusterModuleLabel join with tracks
art::InputTag tracksTag
Tag for the input tracks.
auto withFitHitInfo(art::InputTag const &inputTag)
Adds recob::TrackFitHitInfo information to the proxy.
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()
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
auto withOriginalTrajectory(art::InputTag const &inputTag)
Adds recob::TrackTrajectory information to the proxy.
then if[["$THISISATEST"==1]]
Definition: neoSmazza.sh:95
static constexpr Flag_t Suspicious
The point reconstruction is somehow questionable.
ClusterModuleLabel join with tracks
static constexpr Flag_t NoPoint
The trajectory point is not defined.
then echo unknown compiler flag
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
A trajectory in space reconstructed from hits.
Object storing per-hit information from a track fit.
for($it=0;$it< $RaceTrack_number;$it++)
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
static constexpr Flag_t HitIgnored
Hit was not included for the computation of the trajectory.
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
Represents a track trajectory before the final fit.
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.
Represents a track trajectory from the final fit.
Number of supported track types.
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

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: