DumpCheatTracks_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpCheatTracks_module.cc
3  * @brief Dumps a `lar::example::CheatTrack` collection and associations.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date December 27, 2017
6  * @ingroup TotallyCheatTracks
7  *
8  */
9 
10 // LArSoft libraries
13 
14 // framework libraries
18 #include "art/Framework/Principal/Handle.h" // art::ValidHandle
19 #include "canvas/Persistency/Common/FindOneP.h"
24 #include "fhiclcpp/types/Atom.h"
25 #include "cetlib_except/exception.h"
26 
27 // Boost
28 #include <boost/test/test_tools.hpp> // BOOST_CHECK_EQUAL()
29 
30 // C/C++ standard libraries
31 
32 
33 namespace lar::example::tests {
34 
35  // BEGIN TotallyCheatTracks group ----------------------------------------
36  /// @ingroup TotallyCheatTracks
37  /// @{
38 
39  /**
40  * @brief Dumps `lar::example::CheatTrack` data product and associations.
41  *
42  * The expectation can be expressed directly as a number of elements in the
43  * collection, or indirectly as the requirement that the tested collection
44  * has the same size as another one (still of `recob::SpacePoint`).
45  *
46  * Configuration parameters
47  * =========================
48  *
49  * * *tracks* (input tag, _mandatory_): label of the data product with
50  * the collection of cheat tracks (and associations to particles)
51  * * *expectedCount* (integer, _mandatory_): expected number of tracks in
52  * the collection
53  *
54  */
56  public:
57 
58  struct Config {
59 
60  using Name = fhicl::Name;
62 
64  Name("tracks"),
65  Comment("label of the data product with the cheat tracks")
66  };
67 
69  Name("expectedCount"),
70  Comment("number of expected tracks in the data product")
71  };
72 
73  }; // Config
74 
76 
77  /// Constructor; see the class documentation for the configuration
79  : art::EDAnalyzer(config)
80  , fTrackTag(config().tracks())
81  , fExpectedCount(config().expectedCount())
82  {
83  consumes<std::vector<lar::example::CheatTrack>>(fTrackTag);
84  consumes<art::Assns<lar::example::CheatTrack, simb::MCParticle>>
85  (fTrackTag);
86  }
87 
88  private:
89  void analyze(art::Event const& event) override;
90 
91  art::InputTag fTrackTag; ///< Label of the input data product.
92  unsigned int fExpectedCount; ///< Expected number of tracks.
93  }; // class DumpCheatTracks
94 
95 
96  /// @}
97  // END TotallyCheatTracks group ------------------------------------------
98 
99 } // namespace lar::example::tests
100 
101 
102 
103 //------------------------------------------------------------------------------
104 //--- DumpCheatTracks
105 //---
107 
108  //
109  // read the input
110  //
111  auto const& trackHandle
112  = event.getValidHandle<std::vector<lar::example::CheatTrack>>(fTrackTag);
113  auto const& tracks = *trackHandle;
114  art::FindOneP<simb::MCParticle> trackToPart{ trackHandle, event, fTrackTag };
115 
116  std::size_t const nTracks = tracks.size();
117  BOOST_TEST(nTracks == fExpectedCount);
118 
119 
120  for (std::size_t iTrack = 0U; iTrack < nTracks; ++iTrack) {
121 
122  lar::example::CheatTrack const& track = tracks[iTrack];
123  art::Ptr<simb::MCParticle> const& partPtr = trackToPart.at(iTrack);
124 
125  mf::LogVerbatim log("DumpCheatTracks");
126  log << "[#" << iTrack << "] " << track;
127  if (partPtr) {
128  log << " associated to particle:\n " << *partPtr;
129  }
130  else {
131  log << " not associated to any particle";
132  }
133 
134  } // for (iTrack)
135 
136 } // lar::example::tests::DumpCheatTracks::analyze()
137 
138 
139 //------------------------------------------------------------------------------
ChannelGroupService::Name Name
DumpCheatTracks(Parameters const &config)
Constructor; see the class documentation for the configuration.
void analyze(art::Event const &event) override
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
Particle class.
Pseudo-track data product for TotallyCheatTracks example.
Pseudo-track object for TotallyCheatTracks example.
Definition: CheatTrack.h:52
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
Definition: tracks.py:1
unsigned int fExpectedCount
Expected number of tracks.
Dumps lar::example::CheatTrack data product and associations.
#define Comment
art::InputTag fTrackTag
Label of the input data product.
Tests for LArSoft examples.
Definition: namespaces.h:20
Event finding and building.