DumpSeeds_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpSeeds_module.cc
3  * @brief Dumps on screen the content of seeds
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date September 29th, 2015
6  */
7 
8 // LArSoft includes
11 
12 // art libraries
16 
17 // support libraries
18 #include "fhiclcpp/types/Atom.h"
19 #include "fhiclcpp/types/Table.h"
20 #include "fhiclcpp/types/Name.h"
21 #include "fhiclcpp/types/Comment.h"
22 
23 // C//C++ standard libraries
24 #include <string>
25 
26 // ... and more in the implementation part
27 
28 namespace recob {
29 
30  /**
31  * @brief Prints the content of all the seeds on screen
32  *
33  * This analyser prints the content of all the seeds into the
34  * LogInfo/LogVerbatim stream.
35  *
36  * Configuration parameters
37  * =========================
38  *
39  * - *SeedModuleLabel* (art::InputTag, mandatory): label of the
40  * producer used to create the recob::Seed collection to be dumped
41  * - *OutputCategory* (string, default: "DumpSeeds"): the category used
42  * for the output (useful for filtering)
43  * - *PrintHexFloats* (boolean, default: `false`): print all the floating
44  * point numbers in base 16
45  *
46  */
47  class DumpSeeds: public art::EDAnalyzer {
48  public:
49 
50  struct Config {
51 
52  using Name = fhicl::Name;
54 
56  Name("SeedModuleLabel"),
57  Comment("tag of the recob::Seed collection data product to be dumped")
58  };
59 
61  Name("OutputCategory"),
62  Comment("name of the message facility category to be used for output"),
63  "DumpSeeds"
64  };
65 
67  Name("PrintHexFloats"),
68  Comment("print all the floating point numbers in base 16"),
69  false
70  };
71 
72  }; // struct Config
73 
75 
76  /// Default constructor
77  explicit DumpSeeds(Parameters const& config);
78 
79  /// Does the printing
80  virtual void analyze (const art::Event& evt) override;
81 
82  private:
83 
84  art::InputTag fInputTag; ///< input tag of the Seed product
85  std::string fOutputCategory; ///< category for LogInfo output
86  bool fPrintHexFloats; ///< whether to print floats in base 16
87 
88  }; // class DumpSeeds
89 
90 } // namespace recob
91 
92 
93 //==============================================================================
94 //=== Implementation section
95 //==============================================================================
96 
97 // LArSoft includes
100 
101 // art libraries
103 #include "canvas/Persistency/Common/FindMany.h"
105 
106 // support libraries
108 
109 // C//C++ standard libraries
110 #include <array>
111 
112 
113 namespace {
114 
115  //----------------------------------------------------------------------------
116  class SeedDumper {
117  public:
118 
119  /// Collection of available printing style options
120  struct PrintOptions_t {
121  bool hexFloats = false; ///< print all floating point numbers in base 16
122  std::string indent; ///< indentation string
123  }; // PrintOptions_t
124 
125 
126  /// Constructor; will dump seeds from the specified list.
127  SeedDumper(std::vector<recob::Seed> const& seed_list)
128  : SeedDumper(seed_list, {})
129  {}
130 
131  /// Constructor; will dump seeds from the specified list
132  SeedDumper
133  (std::vector<recob::Seed> const& seed_list, PrintOptions_t print_options)
134  : seeds(seed_list)
135  , options(print_options)
136  {}
137 
138 
139  /// Sets the hits associated to each seed
140  void SetHits(art::FindMany<recob::Hit> const* hit_query)
141  { hits = hit_query; }
142 
143 
144  /// Dump a seed specified by its index in the input particle list
145  template <typename Stream>
146  void DumpSeed(Stream&& out, size_t iSeed) const
147  {
148  lar::OptionalHexFloat hexfloat(options.hexFloats);
149  std::string const& indentstr = options.indent;
150 
151  recob::Seed const& seed = seeds.at(iSeed);
152  //
153  // intro
154  //
155  out << "\n" << indentstr
156  << "[#" << iSeed << "]";
157  if (!seed.IsValid()) out << " invalid!";
158  else {
159  std::array<double, 3> start, dir;
160  seed.GetDirection(dir.data(), nullptr);
161  seed.GetPoint(start.data(), nullptr);
162  out
163  << " starts at (" << hexfloat(start[0])
164  << "," << hexfloat(start[1]) << "," << hexfloat(start[2])
165  << ") toward (" << hexfloat(dir[0]) << "," << hexfloat(dir[1])
166  << "," << hexfloat(dir[2])
167  << "); length: " << hexfloat(seed.GetLength()) << " cm"
168  ;
169  }
170 
171  //
172  // hits
173  //
174  if (hits) {
175  std::vector<recob::Hit const*> myHits = hits->at(iSeed);
176  if (!myHits.empty()) {
177  // we do not honour the base 16 printout requirement here, because
178  // these data members are single precision and there is no printf()
179  // flag taking a float as an argument;, and a promotion to double
180  // would silently occurr, which we want to avoid
181  out
182  << "; " << myHits.size() << " hits:";
183  for (recob::Hit const* hit: myHits) {
184  out << "\n" << indentstr
185  << " on " << hit->WireID()
186  << ", peak at tick " << hit->PeakTime()
187  << ", " << hit->PeakAmplitude()
188  << " ADC, RMS: " << hit->RMS()
189  << " (channel: " << hit->Channel() << ")";
190  } // for hits
191  } // if we have hits
192  } // if we have hit information
193 
194  //
195  // done
196  //
197 
198  } // DumpSeed()
199 
200 
201  /// Dumps all seeds in the input list
202  template <typename Stream>
203  void DumpAllSeeds(Stream&& out) const
204  {
205  size_t const nSeeds = seeds.size();
206  for (size_t iSeed = 0; iSeed < nSeeds; ++iSeed)
207  DumpSeed(out, iSeed);
208  } // DumpAllSeeds()
209 
210 
211 
212  protected:
213  std::vector<recob::Seed> const& seeds; ///< input list
214 
215  PrintOptions_t options; ///< printing and formatting options
216 
217  /// Associated hits (expected same order as for seeds)
218  art::FindMany<recob::Hit> const* hits = nullptr;
219 
220  }; // SeedDumper
221 
222 
223  //----------------------------------------------------------------------------
224 
225 
226 } // local namespace
227 
228 
229 
230 namespace recob {
231 
232  //----------------------------------------------------------------------------
234  : EDAnalyzer(config)
235  , fInputTag(config().SeedModuleLabel())
236  , fOutputCategory(config().OutputCategory())
237  , fPrintHexFloats(config().PrintHexFloats())
238  {}
239 
240 
241  //----------------------------------------------------------------------------
243 
244  //
245  // collect all the available information
246  //
247  // fetch the data to be dumped on screen
248  auto Seeds = evt.getValidHandle<std::vector<recob::Seed>>(fInputTag);
249 
250  art::FindMany<recob::Hit> const SeedHits(Seeds, evt, fInputTag);
251 
252  size_t const nSeeds = Seeds->size();
253  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id()
254  << " contains " << nSeeds << " seeds from '"
255  << fInputTag.encode() << "'";
256 
257  // prepare the dumper
258  SeedDumper::PrintOptions_t options;
259  options.hexFloats = fPrintHexFloats;
260  options.indent = " ";
261  SeedDumper dumper(*Seeds, options);
262 
263  if (SeedHits.isValid()) dumper.SetHits(&SeedHits);
264  else mf::LogWarning("DumpSeeds") << "hit information not avaialble";
265 
266  dumper.DumpAllSeeds(mf::LogVerbatim(fOutputCategory));
267 
268  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
269 
270  } // DumpSeeds::analyze()
271 
273 
274 } // namespace recob
fhicl::Atom< std::string > OutputCategory
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Reconstruction base classes.
bool IsValid() const
Definition: Seed.cxx:70
std::string string
Definition: nybbler.cc:12
void GetPoint(double *Pt, double *Err) const
Definition: Seed.cxx:108
ChannelGroupService::Name Name
art::InputTag fInputTag
input tag of the Seed product
string dir
Prints the content of all the seeds on screen.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
virtual void analyze(const art::Event &evt) override
Does the printing.
std::string encode() const
Definition: InputTag.cc:97
fhicl::Atom< bool > PrintHexFloats
DumpSeeds(Parameters const &config)
Default constructor.
fhicl::Atom< art::InputTag > SeedModuleLabel
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
std::string fOutputCategory
category for LogInfo output
bool fPrintHexFloats
whether to print floats in base 16
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
Helper for formatting floats in base 16.
Definition: hexfloat.h:105
Detector simulation of raw signals on wires.
std::vector< TrajPoint > seeds
Definition: DataStructs.cxx:13
Declaration of signal hit object.
#define Comment
Helper to support output of real numbers in base 16.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:7
void GetDirection(double *Dir, double *Err) const
Definition: Seed.cxx:98
EventID id() const
Definition: Event.cc:34
double GetLength() const
Definition: Seed.cxx:155