All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
12 #include "nusimdata/SimulationBase/MCParticle.h"
13 
14 // framework libraries
15 #include "art/Framework/Core/EDAnalyzer.h"
16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Principal/Event.h"
18 #include "art/Framework/Principal/Handle.h" // art::ValidHandle
19 #include "canvas/Persistency/Common/FindOneP.h"
20 #include "canvas/Persistency/Common/Assns.h"
21 #include "canvas/Persistency/Common/Ptr.h"
22 #include "canvas/Utilities/InputTag.h"
23 #include "messagefacility/MessageLogger/MessageLogger.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  */
55  class DumpCheatTracks: public art::EDAnalyzer {
56  public:
57 
58  struct Config {
59 
60  using Name = fhicl::Name;
61  using Comment = fhicl::Comment;
62 
63  fhicl::Atom<art::InputTag> tracks{
64  Name("tracks"),
65  Comment("label of the data product with the cheat tracks")
66  };
67 
68  fhicl::Atom<unsigned int> expectedCount{
69  Name("expectedCount"),
70  Comment("number of expected tracks in the data product")
71  };
72 
73  }; // Config
74 
75  using Parameters = art::EDAnalyzer::Table<Config>;
76 
77  /// Constructor; see the class documentation for the configuration
78  explicit DumpCheatTracks(Parameters const& config)
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 //---
106 void lar::example::tests::DumpCheatTracks::analyze(art::Event const& event) {
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 //------------------------------------------------------------------------------
140 DEFINE_ART_MODULE(lar::example::tests::DumpCheatTracks)
ClusterModuleLabel join with tracks
DumpCheatTracks(Parameters const &config)
Constructor; see the class documentation for the configuration.
void analyze(art::Event const &event) override
process_name use argoneut_mc_hitfinder track
Pseudo-track data product for TotallyCheatTracks example.
Pseudo-track object for TotallyCheatTracks example.
Definition: CheatTrack.h:52
art::EDAnalyzer::Table< Config > Parameters
BEGIN_PROLOG vertical distance to the surface Name
unsigned int fExpectedCount
Expected number of tracks.
Dumps lar::example::CheatTrack data product and associations.
art::InputTag fTrackTag
Label of the input data product.