LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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/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 
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 
77  explicit DumpSeeds(Parameters const& config);
78 
80  virtual void analyze (const art::Event& evt) override;
81 
82  private:
83 
85  std::string fOutputCategory;
87 
88  }; // class DumpSeeds
89 
90 } // namespace recob
91 
92 
93 //==============================================================================
94 //=== Implementation section
95 //==============================================================================
96 
97 // LArSoft includes
100 
101 // art libraries
105 
106 // support libraries
108 
109 // C//C++ standard libraries
110 #include <vector>
111 #include <array>
112 
113 
114 namespace {
115 
116  //----------------------------------------------------------------------------
117  class SeedDumper {
118  public:
119 
121  struct PrintOptions_t {
122  bool hexFloats = false;
123  std::string indent;
124  }; // PrintOptions_t
125 
126 
128  SeedDumper(std::vector<recob::Seed> const& seed_list)
129  : SeedDumper(seed_list, {})
130  {}
131 
133  SeedDumper
134  (std::vector<recob::Seed> const& seed_list, PrintOptions_t print_options)
135  : seeds(seed_list)
136  , options(print_options)
137  {}
138 
139 
141  void SetHits(art::FindMany<recob::Hit> const* hit_query)
142  { hits = hit_query; }
143 
144 
146  template <typename Stream>
147  void DumpSeed(Stream&& out, size_t iSeed) const
148  {
149  lar::OptionalHexFloat hexfloat(options.hexFloats);
150  std::string const& indentstr = options.indent;
151 
152  recob::Seed const& seed = seeds.at(iSeed);
153  //
154  // intro
155  //
156  out << "\n" << indentstr
157  << "[#" << iSeed << "]";
158  if (!seed.IsValid()) out << " invalid!";
159  else {
160  std::array<double, 3> start, dir;
161  seed.GetDirection(dir.data(), nullptr);
162  seed.GetPoint(start.data(), nullptr);
163  out
164  << " starts at (" << hexfloat(start[0])
165  << "," << hexfloat(start[1]) << "," << hexfloat(start[2])
166  << ") toward (" << hexfloat(dir[0]) << "," << hexfloat(dir[1])
167  << "," << hexfloat(dir[2])
168  << "); length: " << hexfloat(seed.GetLength()) << " cm"
169  ;
170  }
171 
172  //
173  // hits
174  //
175  if (hits) {
176  std::vector<recob::Hit const*> myHits = hits->at(iSeed);
177  if (!myHits.empty()) {
178  // we do not honour the base 16 printout requirement here, because
179  // these data members are single precision and there is no printf()
180  // flag taking a float as an argument;, and a promotion to double
181  // would silently occurr, which we want to avoid
182  out
183  << "; " << myHits.size() << " hits:";
184  for (recob::Hit const* hit: myHits) {
185  out << "\n" << indentstr
186  << " on " << hit->WireID()
187  << ", peak at tick " << hit->PeakTime()
188  << ", " << hit->PeakAmplitude()
189  << " ADC, RMS: " << hit->RMS()
190  << " (channel: " << hit->Channel() << ")";
191  } // for hits
192  } // if we have hits
193  } // if we have hit information
194 
195  //
196  // done
197  //
198 
199  } // DumpSeed()
200 
201 
203  template <typename Stream>
204  void DumpAllSeeds(Stream&& out) const
205  {
206  size_t const nSeeds = seeds.size();
207  for (size_t iSeed = 0; iSeed < nSeeds; ++iSeed)
208  DumpSeed(out, iSeed);
209  } // DumpAllSeeds()
210 
211 
212 
213  protected:
214  std::vector<recob::Seed> const& seeds;
215 
216  PrintOptions_t options;
217 
219  art::FindMany<recob::Hit> const* hits = nullptr;
220 
221  }; // SeedDumper
222 
223 
224  //----------------------------------------------------------------------------
225 
226 
227 } // local namespace
228 
229 
230 
231 namespace recob {
232 
233  //----------------------------------------------------------------------------
235  : EDAnalyzer(config)
236  , fInputTag(config().SeedModuleLabel())
237  , fOutputCategory(config().OutputCategory())
238  , fPrintHexFloats(config().PrintHexFloats())
239  {}
240 
241 
242  //----------------------------------------------------------------------------
243  void DumpSeeds::analyze(const art::Event& evt) {
244 
245  //
246  // collect all the available information
247  //
248  // fetch the data to be dumped on screen
249  auto Seeds = evt.getValidHandle<std::vector<recob::Seed>>(fInputTag);
250 
251  art::FindMany<recob::Hit> const SeedHits(Seeds, evt, fInputTag);
252 
253  size_t const nSeeds = Seeds->size();
254  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id()
255  << " contains " << nSeeds << " seeds from '"
256  << fInputTag.encode() << "'";
257 
258  // prepare the dumper
259  SeedDumper::PrintOptions_t options;
260  options.hexFloats = fPrintHexFloats;
261  options.indent = " ";
262  SeedDumper dumper(*Seeds, options);
263 
264  if (SeedHits.isValid()) dumper.SetHits(&SeedHits);
265  else mf::LogWarning("DumpSeeds") << "hit information not avaialble";
266 
267  dumper.DumpAllSeeds(mf::LogVerbatim(fOutputCategory));
268 
269  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
270 
271  } // DumpSeeds::analyze()
272 
274 
275 } // namespace recob
fhicl::Atom< std::string > OutputCategory
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Reconstruction base classes.
bool IsValid() const
Definition: Seed.cxx:74
Declaration of signal hit object.
void GetPoint(double *Pt, double *Err) const
Definition: Seed.cxx:112
art::InputTag fInputTag
input tag of the Seed product
Prints the content of all the seeds on screen.
virtual void analyze(const art::Event &evt) override
Does the printing.
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:42
long seed
Definition: chem4.cc:68
std::string fOutputCategory
category for LogInfo output
std::string encode() const
Definition: InputTag.cc:36
bool fPrintHexFloats
whether to print floats in base 16
std::string indent(std::size_t const i)
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Helper for formatting floats in base 16.
Definition: hexfloat.h:105
Detector simulation of raw signals on wires.
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:49
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
void GetDirection(double *Dir, double *Err) const
Definition: Seed.cxx:102
EventID id() const
Definition: Event.h:56
double GetLength() const
Definition: Seed.cxx:159