LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DumpSeeds_module.cc
Go to the documentation of this file.
1 
8 // LArSoft includes
11 
12 // art libraries
16 
17 // support libraries
18 #include "fhiclcpp/types/Atom.h"
19 #include "fhiclcpp/types/Comment.h"
20 #include "fhiclcpp/types/Name.h"
21 #include "fhiclcpp/types/Table.h"
22 
23 // C//C++ standard libraries
24 #include <string>
25 
26 // ... and more in the implementation part
27 
28 namespace recob {
29 
47  class DumpSeeds : public art::EDAnalyzer {
48  public:
49  struct Config {
50 
51  using Name = fhicl::Name;
53 
55  Name("SeedModuleLabel"),
56  Comment("tag of the recob::Seed collection data product to be dumped")};
57 
59  Name("OutputCategory"),
60  Comment("name of the message facility category to be used for output"),
61  "DumpSeeds"};
62 
64  Comment("print all the floating point numbers in base 16"),
65  false};
66 
67  }; // struct Config
68 
70 
72  explicit DumpSeeds(Parameters const& config);
73 
75  virtual void analyze(const art::Event& evt) override;
76 
77  private:
79  std::string fOutputCategory;
81 
82  }; // class DumpSeeds
83 
84 } // namespace recob
85 
86 //==============================================================================
87 //=== Implementation section
88 //==============================================================================
89 
90 // LArSoft includes
93 
94 // art libraries
98 
99 // support libraries
101 
102 // C//C++ standard libraries
103 #include <array>
104 
105 namespace {
106 
107  //----------------------------------------------------------------------------
108  class SeedDumper {
109  public:
111  struct PrintOptions_t {
112  bool hexFloats = false;
113  std::string indent;
114  }; // PrintOptions_t
115 
117  SeedDumper(std::vector<recob::Seed> const& seed_list) : SeedDumper(seed_list, {}) {}
118 
120  SeedDumper(std::vector<recob::Seed> const& seed_list, PrintOptions_t print_options)
121  : seeds(seed_list), options(print_options)
122  {}
123 
125  void SetHits(art::FindMany<recob::Hit> const* hit_query) { hits = hit_query; }
126 
128  template <typename Stream>
129  void DumpSeed(Stream&& out, size_t iSeed) const
130  {
131  lar::OptionalHexFloat hexfloat(options.hexFloats);
132  std::string const& indentstr = options.indent;
133 
134  recob::Seed const& seed = seeds.at(iSeed);
135  //
136  // intro
137  //
138  out << "\n" << indentstr << "[#" << iSeed << "]";
139  if (!seed.IsValid())
140  out << " invalid!";
141  else {
142  std::array<double, 3> start, dir;
143  seed.GetDirection(dir.data(), nullptr);
144  seed.GetPoint(start.data(), nullptr);
145  out << " starts at (" << hexfloat(start[0]) << "," << hexfloat(start[1]) << ","
146  << hexfloat(start[2]) << ") toward (" << hexfloat(dir[0]) << "," << hexfloat(dir[1])
147  << "," << hexfloat(dir[2]) << "); length: " << hexfloat(seed.GetLength()) << " cm";
148  }
149 
150  //
151  // hits
152  //
153  if (hits) {
154  std::vector<recob::Hit const*> myHits = hits->at(iSeed);
155  if (!myHits.empty()) {
156  // we do not honour the base 16 printout requirement here, because
157  // these data members are single precision and there is no printf()
158  // flag taking a float as an argument;, and a promotion to double
159  // would silently occurr, which we want to avoid
160  out << "; " << myHits.size() << " hits:";
161  for (recob::Hit const* hit : myHits) {
162  out << "\n"
163  << indentstr << " on " << hit->WireID() << ", peak at tick " << hit->PeakTime()
164  << ", " << hit->PeakAmplitude() << " ADC, RMS: " << hit->RMS()
165  << " (channel: " << hit->Channel() << ")";
166  } // for hits
167  } // if we have hits
168  } // if we have hit information
169 
170  //
171  // done
172  //
173 
174  } // DumpSeed()
175 
177  template <typename Stream>
178  void DumpAllSeeds(Stream&& out) const
179  {
180  size_t const nSeeds = seeds.size();
181  for (size_t iSeed = 0; iSeed < nSeeds; ++iSeed)
182  DumpSeed(out, iSeed);
183  } // DumpAllSeeds()
184 
185  protected:
186  std::vector<recob::Seed> const& seeds;
187 
188  PrintOptions_t options;
189 
191  art::FindMany<recob::Hit> const* hits = nullptr;
192 
193  }; // SeedDumper
194 
195  //----------------------------------------------------------------------------
196 
197 } // local namespace
198 
199 namespace recob {
200 
201  //----------------------------------------------------------------------------
203  : EDAnalyzer(config)
204  , fInputTag(config().SeedModuleLabel())
205  , fOutputCategory(config().OutputCategory())
206  , fPrintHexFloats(config().PrintHexFloats())
207  {}
208 
209  //----------------------------------------------------------------------------
211  {
212 
213  //
214  // collect all the available information
215  //
216  // fetch the data to be dumped on screen
217  auto Seeds = evt.getValidHandle<std::vector<recob::Seed>>(fInputTag);
218 
219  art::FindMany<recob::Hit> const SeedHits(Seeds, evt, fInputTag);
220 
221  size_t const nSeeds = Seeds->size();
222  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id() << " contains " << nSeeds
223  << " seeds from '" << fInputTag.encode() << "'";
224 
225  // prepare the dumper
226  SeedDumper::PrintOptions_t options;
227  options.hexFloats = fPrintHexFloats;
228  options.indent = " ";
229  SeedDumper dumper(*Seeds, options);
230 
231  if (SeedHits.isValid())
232  dumper.SetHits(&SeedHits);
233  else
234  mf::LogWarning("DumpSeeds") << "hit information not avaialble";
235 
236  dumper.DumpAllSeeds(mf::LogVerbatim(fOutputCategory));
237 
238  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
239 
240  } // DumpSeeds::analyze()
241 
243 
244 } // namespace recob
fhicl::Atom< std::string > OutputCategory
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Reconstruction base classes.
bool IsValid() const
Definition: Seed.cxx:58
Declaration of signal hit object.
void GetPoint(double *Pt, double *Err) const
Definition: Seed.cxx:89
art::InputTag fInputTag
input tag of the Seed product
Prints the content of all the seeds on screen.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
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.
void hits()
Definition: readHits.C:15
fhicl::Atom< art::InputTag > SeedModuleLabel
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
long seed
Definition: chem4.cc:67
std::string fOutputCategory
category for LogInfo output
bool fPrintHexFloats
whether to print floats in base 16
std::string indent(std::size_t const i)
Helper for formatting floats in base 16.
Definition: hexfloat.h:109
Detector simulation of raw signals on wires.
std::vector< TrajPoint > seeds
Definition: DataStructs.cxx:14
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
TDirectory * dir
Definition: macro.C:5
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:46
TCEvent evt
Definition: DataStructs.cxx:8
void GetDirection(double *Dir, double *Err) const
Definition: Seed.cxx:80
EventID id() const
Definition: Event.cc:23
double GetLength() const
Definition: Seed.cxx:132