LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DumpSpacePoints_module.cc
Go to the documentation of this file.
1 
8 // LArSoft includes
9 #include "lardata/ArtDataHelper/Dumpers/NewLine.h" // recob::dumper::makeNewLine()
12 
13 // art libraries
17 
18 // support libraries
19 #include "fhiclcpp/types/Atom.h" // also pulls in fhicl::Name and fhicl::Comment
20 
21 // C//C++ standard libraries
22 #include <string>
23 
24 // ... and more in the implementation part
25 
26 namespace recob {
27 
46  public:
48  struct Config {
49  using Name = fhicl::Name;
51 
53  Name("SpacePointModuleLabel"),
54  Comment(
55  "label of the producer used to create the recob::SpacePoint collection to be dumped")};
57  Name("OutputCategory"),
58  Comment("the category used for the output (useful for filtering) [\"DumpSpacePoints\"]"),
59  "DumpSpacePoints" /* default value */
60  };
62  Name("PrintHexFloats"),
63  Comment("print floating point numbers in base 16 [false]"),
64  false /* default value */
65  };
66 
67  }; // struct Config
68 
70 
72  explicit DumpSpacePoints(Parameters const& config);
73 
75  virtual void analyze(const art::Event& evt) override;
76 
77  private:
79  std::string fOutputCategory;
81 
82  }; // class DumpSpacePoints
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 
104 namespace {
105 
106  //----------------------------------------------------------------------------
107  class SpacePointDumper {
108  public:
109  using PrintOptions_t = recob::dumper::SpacePointPrintOptions_t;
110 
112  SpacePointDumper(std::vector<recob::SpacePoint> const& point_list,
113  PrintOptions_t const& printOptions = {})
114  : points(point_list), options(printOptions)
115  {}
116 
118  void SetHits(art::FindMany<recob::Hit> const* hit_query) { hits = hit_query; }
119 
121  template <typename Stream>
122  void DumpSpacePoint(Stream&& out, size_t iPoint) const
123  {
124  DumpSpacePoint(std::forward<Stream>(out), iPoint, options);
125  }
126 
128  template <typename Stream>
129  void DumpSpacePoint(Stream&& out, size_t iPoint, std::string indentstr) const
130  {
131  PrintOptions_t localOptions(options);
132  localOptions.indent.indent = indentstr;
133  DumpSpacePoint(std::forward<Stream>(out), iPoint, localOptions);
134  }
135 
137  template <typename Stream>
138  void DumpSpacePoint(Stream&& out, size_t iPoint, PrintOptions_t const& localOptions) const
139  {
140  recob::SpacePoint const& point = points.at(iPoint);
141 
142  //
143  // intro
144  //
145  auto first_nl = recob::dumper::makeNewLine(out, localOptions.indent);
146  first_nl() << "[#" << iPoint << "] ";
147 
148  PrintOptions_t indentedOptions(localOptions);
149  indentedOptions.indent.appendIndentation(" ");
150  recob::dumper::DumpSpacePoint(std::forward<Stream>(out), point, indentedOptions);
151 
152  //
153  // hits
154  //
155  if (hits) {
156  std::vector<recob::Hit const*> myHits = hits->at(iPoint);
157  if (myHits.empty()) { out << "; no associated hits"; }
158  else {
159  auto nl = recob::dumper::makeNewLine(out, indentedOptions.indent);
160  out << "; " << myHits.size() << " hits:";
161  for (recob::Hit const* hit : myHits) {
162  nl() << " on " << hit->WireID() << ", peak at tick " << hit->PeakTime() << ", "
163  << hit->PeakAmplitude() << " ADC, RMS: " << hit->RMS()
164  << " (channel: " << hit->Channel() << ")";
165  } // for hits
166  } // if we have hits
167  } // if we have hit information
168 
169  //
170  // done
171  //
172 
173  } // DumpSpacePoints()
174 
176  template <typename Stream>
177  void DumpAllSpacePoints(Stream&& out, std::string indentstr = "") const
178  {
179  auto localOptions = options;
180  localOptions.indent.appendIndentation(indentstr);
181  size_t const nPoints = points.size();
182  for (size_t iPoint = 0; iPoint < nPoints; ++iPoint)
183  DumpSpacePoint(std::forward<Stream>(out), iPoint, localOptions);
184  } // DumpAllSpacePoints()
185 
186  protected:
187  std::vector<recob::SpacePoint> const& points;
188  PrintOptions_t options;
189 
191  art::FindMany<recob::Hit> const* hits = nullptr;
192 
193  }; // SpacePointDumper
194 
195  //----------------------------------------------------------------------------
196 
197 } // local namespace
198 
199 namespace recob {
200 
201  //----------------------------------------------------------------------------
203  : EDAnalyzer(config)
204  , fInputTag(config().SpacePointModuleLabel())
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 SpacePoints = evt.getValidHandle<std::vector<recob::SpacePoint>>(fInputTag);
218 
219  art::FindMany<recob::Hit> const PointHits(SpacePoints, evt, fInputTag);
220 
221  size_t const nPoints = SpacePoints->size();
222  mf::LogInfo(fOutputCategory) << "The event contains " << nPoints << " space points from '"
223  << fInputTag.encode() << "'";
224 
225  // prepare the dumper
226  SpacePointDumper dumper(*SpacePoints);
227  if (PointHits.isValid())
228  dumper.SetHits(&PointHits);
229  else
230  mf::LogWarning("DumpSpacePoints") << "hit information not avaialble";
231 
232  dumper.DumpAllSpacePoints(mf::LogVerbatim(fOutputCategory), " ");
233 
234  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
235 
236  } // DumpSpacePoints::analyze()
237 
239 
240 } // namespace recob
DumpSpacePoints(Parameters const &config)
Default constructor.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
bool fPrintHexFloats
whether to print floats in base 16
Reconstruction base classes.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
Prints the content of all the space points on screen.
Functions dumping space points.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
std::string encode() const
Definition: InputTag.cc:97
std::string fOutputCategory
category for LogInfo output
fhicl::Atom< std::string > OutputCategory
virtual void analyze(const art::Event &evt) override
Does the printing.
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Simple class managing a repetitive output task.
Detector simulation of raw signals on wires.
fhicl::Atom< art::InputTag > SpacePointModuleLabel
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
art::InputTag fInputTag
input tag of the SpacePoint product
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
NewLine< Stream > makeNewLine(Stream &stream, std::string indent, bool followLine=false)
Convenience function to create a temporary NewLine.
Definition: NewLine.h:148
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
TCEvent evt
Definition: DataStructs.cxx:8
std::string nl(std::size_t i=1)
auto DumpSpacePoint(Stream &&out, recob::SpacePoint const &sp, SpacePointPrintOptions_t const &options={}) -> std::enable_if_t< std::is_same< NewLine< std::decay_t< Stream >>, std::decay_t< NewLineRef >>::value >
Dumps the content of the specified space point into a stream.
Collection of available printing style options.