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

Selects tracks with time information. More...

Inheritance diagram for sbn::TimedTrackSelector:

Classes

struct  Config
 Module configuration parameters. More...
 

Public Types

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

Public Member Functions

 TimedTrackSelector (Parameters const &params, art::ProcessingFrame const &)
 
bool filter (art::Event &event, art::ProcessingFrame const &) override
 
void endJob (art::ProcessingFrame const &) override
 Prints end-job summary. More...
 

Static Public Attributes

static constexpr double NoMinTime { std::numeric_limits<double>::lowest() }
 
static constexpr double NoMaxTime { std::numeric_limits<double>::max() }
 
static constexpr unsigned int NoMinTracks { 0U }
 
static constexpr unsigned int NoMaxTracks { std::numeric_limits<unsigned int>::max() }
 

Private Member Functions

unsigned int selectTracks (art::Assns< anab::T0, recob::PFParticle > const &timeTracks, std::vector< art::Ptr< recob::PFParticle >> &selectedTracks) const
 Adds to selectedTracks qualifying tracks from timeTracks. More...
 
bool isTrackSelected (recob::PFParticle const &track, anab::T0 const &time) const
 Returns whether the specified track (with specified time) qualifies. More...
 
bool selectedTracksRequirement (unsigned int nTracks) const
 Returns if the number of tracks nTracks satisfies filter requirements. More...
 

Static Private Member Functions

static bool isTrack (recob::PFParticle const &particle)
 Returns whether the specified particle flow object is a track. More...
 

Private Attributes

std::vector< art::InputTag > const fTrackTimeTags
 List of track-time association input tags. More...
 
double const fMinT0
 Minimum track time for track selection. More...
 
double const fMaxT0
 Maximum track time for track selection. More...
 
unsigned int const fMinTracks
 Minimum selected tracks for event selection. More...
 
unsigned int const fMaxTracks
 Maximum selected tracks for event selection. More...
 
bool const fOnlyPandoraTracks
 Save only tracks identified as such. More...
 
bool const fSaveTracks
 Whether to save selected tracks into the event. More...
 
std::string const fLogCategory
 Message facility stream name. More...
 
icarus::ns::util::PassCounter fPassRate
 Counter of passed events (not thread-safe). More...
 

Detailed Description

Selects tracks with time information.

This module produces a list of "tracks" that are associated to a time. Optionally, it can select only the tracks with that time in a specified range.

This module is a filter that will return true for an event if at least one of its tracks is selected. This threshold can be adjusted by configuration.

Input

The input file is expected to contain the time information and association to "tracks", which are actually represented by recob::PFParticle rather than recob::Track. Note that the track data products are not explicitly required.

Output

The filter produces a list of pointers to the selected tracks; the list will mix tracks from different data products if multiple input collections are specified. A track is selected if all the following apply:

  1. the track is associated to a time;
  2. only if a time range is specified, that track time must fall within.

The filter passes the event if:

Configuration options

Definition at line 111 of file TimedTrackSelector_module.cc.

Member Typedef Documentation

using sbn::TimedTrackSelector::Parameters = art::SharedFilter::Table<Config>

Definition at line 182 of file TimedTrackSelector_module.cc.

Constructor & Destructor Documentation

sbn::TimedTrackSelector::TimedTrackSelector ( Parameters const &  params,
art::ProcessingFrame const &   
)
explicit

Definition at line 255 of file TimedTrackSelector_module.cc.

256  : art::SharedFilter{ params }
257  , fTrackTimeTags{ params().TrackTimeTags() }
258  , fMinT0{ params().MinT0() }
259  , fMaxT0{ params().MaxT0() }
260  , fMinTracks{ params().MinTracks() }
261  , fMaxTracks{ params().MaxTracks() }
262  , fOnlyPandoraTracks{ params().OnlyPandoraTracks() }
263  , fSaveTracks{ params().SaveTracks() }
264  , fLogCategory{ params().LogCategory() }
265 {
266  async<art::InEvent>();
267 
268  if (fSaveTracks)
269  produces<std::vector<art::Ptr<recob::PFParticle>>>();
270 
271  //
272  // configuration dump
273  //
274  {
275  mf::LogInfo log{ fLogCategory };
276  log << "Configuration:"
277  << "\n * tracks required to be associated to a time (cathode-crossers)"
278  ;
279  log << "\n * track time:";
280  if (fMinT0 == NoMinTime) {
281  if (fMaxT0 == NoMaxTime) log << " any";
282  else log << " before " << fMaxT0;
283  }
284  else {
285  log << " from " << fMinT0;
286  if (fMaxT0 == NoMaxTime) log << " on";
287  else log << " to " << fMaxT0;
288  }
289 
290  log << "\n * selected tracks per event: ";
291  if (fMinTracks == NoMinTracks) {
292  if (fMaxTracks == NoMaxTracks) log << "any";
293  else log << fMaxTracks << " or less";
294  }
295  else {
296  if (fMaxTracks == NoMaxTracks) log << fMinTracks << " or more";
297  else log << "between " << fMinTracks << " and " << fMaxTracks;
298  }
299  log << "\n * selected tracks will" << (fSaveTracks? "": " not")
300  << " be saved";
301  } // end local scope
302 
303 } // sbn::TimedTrackSelector::TimedTrackSelector()
std::string const fLogCategory
Message facility stream name.
static constexpr unsigned int NoMinTracks
unsigned int const fMaxTracks
Maximum selected tracks for event selection.
double const fMinT0
Minimum track time for track selection.
double const fMaxT0
Maximum track time for track selection.
std::vector< art::InputTag > const fTrackTimeTags
List of track-time association input tags.
bool const fOnlyPandoraTracks
Save only tracks identified as such.
bool const fSaveTracks
Whether to save selected tracks into the event.
static constexpr double NoMaxTime
unsigned int const fMinTracks
Minimum selected tracks for event selection.
static constexpr double NoMinTime
static constexpr unsigned int NoMaxTracks

Member Function Documentation

void sbn::TimedTrackSelector::endJob ( art::ProcessingFrame const &  )
override

Prints end-job summary.

Definition at line 371 of file TimedTrackSelector_module.cc.

371  {
372 
373  mf::LogInfo(fLogCategory) << "Selected " << fPassRate.passed()
374  << '/' << fPassRate.total() << " events with qualifying tracks.";
375 
376 } // sbn::TimedTrackSelector::endJob()
std::string const fLogCategory
Message facility stream name.
icarus::ns::util::PassCounter fPassRate
Counter of passed events (not thread-safe).
Count_t total() const
Returns the total number of registered events.
Definition: PassCounter.h:60
Count_t passed() const
Returns the number of events which &quot;passed&quot;.
Definition: PassCounter.h:54
bool sbn::TimedTrackSelector::filter ( art::Event &  event,
art::ProcessingFrame const &   
)
override

Definition at line 308 of file TimedTrackSelector_module.cc.

309 {
310 
311  mf::LogDebug(fLogCategory) << "Processing " << event.id();
312 
313  //
314  // select tracks from each of the input tags
315  //
316  std::vector<art::Ptr<recob::PFParticle>> selectedTracks;
317  for (art::InputTag const& inputTag: fTrackTimeTags) {
318  auto const& T0toTrack
319  = event.getProduct<art::Assns<anab::T0, recob::PFParticle>>(inputTag);
320  unsigned int const newTracks = selectTracks(T0toTrack, selectedTracks);
321 
322  mf::LogTrace(fLogCategory)
323  << "From '" << inputTag.encode() << "': "
324  << newTracks << " tracks selected"
325  ;
326 
327  } // for
328 
329  unsigned int const nSelectedTracks = selectedTracks.size();
330 
331 
332  //
333  // save track list in the event
334  //
335 
336  // after this, selectedTracks may be empty. JCZ: Not quite, I think the access to selectedTracks[0] in the log statement throws a segfault it it's empty, now fixed
337  if (fSaveTracks) {
338  event.put(
339  std::make_unique<std::vector<art::Ptr<recob::PFParticle>>>(selectedTracks)
340  );
341  if(selectedTracks.size() > 0)
342  {
343  mf::LogTrace(fLogCategory)
344  << "InputTag for this product is: "
345  << event.getProductDescription(selectedTracks[0].id())->inputTag();
346  }
347  }
348 
349 
350  //
351  // filter logic
352  //
353 
354  bool const passed = selectedTracksRequirement(nSelectedTracks);
355  fPassRate.add(passed);
356  mf::LogTrace(fLogCategory) << event.id()
357  << ' ' << (passed? "passed": "rejected") << " (" << nSelectedTracks
358  << " selected tracks)."; // funny fact: we don't know the total track count, JCZ: I think I fixed that fact although I could be completely wrong
359 
360 
361  mf::LogDebug(fLogCategory) << "Completed " << event.id();
362 
363  mf::LogDebug(fLogCategory) << "There are now " << fTotalTracks << " total tracks selected.";
364 
365  return passed;
366 
367 } // sbn::TimedTrackSelector::filter()
std::string const fLogCategory
Message facility stream name.
icarus::ns::util::PassCounter fPassRate
Counter of passed events (not thread-safe).
bool selectedTracksRequirement(unsigned int nTracks) const
Returns if the number of tracks nTracks satisfies filter requirements.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< art::InputTag > const fTrackTimeTags
List of track-time association input tags.
void add(bool pass)
Adds a single event, specifying whether it &quot;passes&quot; or not.
Definition: PassCounter.h:112
bool const fSaveTracks
Whether to save selected tracks into the event.
unsigned int selectTracks(art::Assns< anab::T0, recob::PFParticle > const &timeTracks, std::vector< art::Ptr< recob::PFParticle >> &selectedTracks) const
Adds to selectedTracks qualifying tracks from timeTracks.
bool sbn::TimedTrackSelector::isTrack ( recob::PFParticle const &  particle)
staticprivate

Returns whether the specified particle flow object is a track.

Definition at line 431 of file TimedTrackSelector_module.cc.

431  {
432 
433  switch (std::abs(particle.PdgCode())) {
434  case 13: // muon
435  case 211: // charged pion
436  case 321: // charged kaon
437  case 2212: // proton
438  return true;
439  default:
440  return false;
441  } // switch
442 
443 } // sbn::TimedTrackSelector::isTrack()
T abs(T value)
bool sbn::TimedTrackSelector::isTrackSelected ( recob::PFParticle const &  track,
anab::T0 const &  time 
) const
private

Returns whether the specified track (with specified time) qualifies.

Definition at line 408 of file TimedTrackSelector_module.cc.

409 {
410 
411  double const T0 = time.Time();
412  MF_LOG_TRACE(fLogCategory) << "Track time: " << T0;
413 
414  if (fOnlyPandoraTracks && !isTrack(track)) {
415  MF_LOG_TRACE(fLogCategory) << "Not a track (ID=" << track.PdgCode()
416  << ") => discarded!";
417  return false;
418  }
419 
420  if ((T0 < fMinT0) || (T0 >= fMaxT0)) {
421  MF_LOG_TRACE(fLogCategory) << "Time out of range [ " << fMinT0 << "; "
422  << fMaxT0 << " ] => discarded!";
423  return false;
424  }
425 
426  return true;
427 } // sbn::TimedTrackSelector::isTrackSelected()
std::string const fLogCategory
Message facility stream name.
process_name use argoneut_mc_hitfinder track
double const fMinT0
Minimum track time for track selection.
double const fMaxT0
Maximum track time for track selection.
bool const fOnlyPandoraTracks
Save only tracks identified as such.
static bool isTrack(recob::PFParticle const &particle)
Returns whether the specified particle flow object is a track.
process_name opdaq physics producers generator physics producers generator physics producers generator physics producers generator physics producers generator physics producers generator physics producers generator physics producers generator T0
Definition: gen_protons.fcl:45
bool sbn::TimedTrackSelector::selectedTracksRequirement ( unsigned int  nTracks) const
private

Returns if the number of tracks nTracks satisfies filter requirements.

Definition at line 448 of file TimedTrackSelector_module.cc.

449 {
450  return (nTracks >= fMinTracks) && (nTracks <= fMaxTracks);
451 } // sbn::TimedTrackSelector::selectedTracks()
unsigned int const fMaxTracks
Maximum selected tracks for event selection.
unsigned int const fMinTracks
Minimum selected tracks for event selection.
unsigned int sbn::TimedTrackSelector::selectTracks ( art::Assns< anab::T0, recob::PFParticle > const &  timeTracks,
std::vector< art::Ptr< recob::PFParticle >> &  selectedTracks 
) const
private

Adds to selectedTracks qualifying tracks from timeTracks.

Parameters
timeTrackstime/track associations
[out]selectedTrackscollection to expand with the qualifying tracks
Returns
the number of qualifying tracks found in timeTracks and added

Definition at line 380 of file TimedTrackSelector_module.cc.

382  {
383 
384  unsigned int nSelectedTracks { 0U };
385  for (auto const& [ t0Ptr, trackPtr ]: timeTracks) {
386 
387  // if fOnlyPandoraTracks is false, we don't need the track, so we avoid
388  // dereferencing the pointer: a reference from a null pointer will be
389  // passed around and will cause a segmentation violation at the first access
390  recob::PFParticle const* track = fOnlyPandoraTracks? &*trackPtr: nullptr;
391 
392  if (!isTrackSelected(*track, *t0Ptr)) continue;
393 
394  MF_LOG_TRACE(fLogCategory) << "Track #" << trackPtr.key() << " selected.";
395 
396  selectedTracks.push_back(trackPtr);
397  ++nSelectedTracks;
398  ++fTotalTracks;
399  } // for
400 
401  return nSelectedTracks;
402 
403 } // sbn::TimedTrackSelector::selectTracks()
std::string const fLogCategory
Message facility stream name.
process_name use argoneut_mc_hitfinder track
bool isTrackSelected(recob::PFParticle const &track, anab::T0 const &time) const
Returns whether the specified track (with specified time) qualifies.
bool const fOnlyPandoraTracks
Save only tracks identified as such.
Hierarchical representation of particle flow.
Definition: PFParticle.h:44

Member Data Documentation

std::string const sbn::TimedTrackSelector::fLogCategory
private

Message facility stream name.

Definition at line 211 of file TimedTrackSelector_module.cc.

double const sbn::TimedTrackSelector::fMaxT0
private

Maximum track time for track selection.

Definition at line 201 of file TimedTrackSelector_module.cc.

unsigned int const sbn::TimedTrackSelector::fMaxTracks
private

Maximum selected tracks for event selection.

Definition at line 206 of file TimedTrackSelector_module.cc.

double const sbn::TimedTrackSelector::fMinT0
private

Minimum track time for track selection.

Definition at line 200 of file TimedTrackSelector_module.cc.

unsigned int const sbn::TimedTrackSelector::fMinTracks
private

Minimum selected tracks for event selection.

Definition at line 204 of file TimedTrackSelector_module.cc.

bool const sbn::TimedTrackSelector::fOnlyPandoraTracks
private

Save only tracks identified as such.

Definition at line 208 of file TimedTrackSelector_module.cc.

icarus::ns::util::PassCounter sbn::TimedTrackSelector::fPassRate
private

Counter of passed events (not thread-safe).

Definition at line 219 of file TimedTrackSelector_module.cc.

bool const sbn::TimedTrackSelector::fSaveTracks
private

Whether to save selected tracks into the event.

Definition at line 209 of file TimedTrackSelector_module.cc.

std::vector<art::InputTag> const sbn::TimedTrackSelector::fTrackTimeTags
private

List of track-time association input tags.

Definition at line 198 of file TimedTrackSelector_module.cc.

constexpr double sbn::TimedTrackSelector::NoMaxTime { std::numeric_limits<double>::max() }
static

Definition at line 116 of file TimedTrackSelector_module.cc.

constexpr unsigned int sbn::TimedTrackSelector::NoMaxTracks { std::numeric_limits<unsigned int>::max() }
static

Definition at line 119 of file TimedTrackSelector_module.cc.

constexpr double sbn::TimedTrackSelector::NoMinTime { std::numeric_limits<double>::lowest() }
static

Definition at line 115 of file TimedTrackSelector_module.cc.

constexpr unsigned int sbn::TimedTrackSelector::NoMinTracks { 0U }
static

Definition at line 117 of file TimedTrackSelector_module.cc.


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