LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
DumpChannelMap_module.cc
Go to the documentation of this file.
1 
9 // LArSoft libraries
14 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
15 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::WireID
16 
17 // framework libraries
22 #include "fhiclcpp/types/Atom.h"
23 #include "fhiclcpp/types/Comment.h"
24 #include "fhiclcpp/types/Name.h"
26 
27 // C/C++ standard libraries
28 #include <string>
29 
30 namespace {
31  //------------------------------------------------------------------------------
32  void dumpChannelToWires(std::string const& OutputCategory,
33  geo::WireReadoutGeom const& wireReadoutGeom,
34  raw::ChannelID_t FirstChannel,
35  raw::ChannelID_t LastChannel)
36  {
38  unsigned int const NChannels = wireReadoutGeom.Nchannels();
39 
40  if (NChannels == 0) {
41  mf::LogError(OutputCategory) << "Nice detector we have here, with no channels.";
42  return;
43  }
44 
45  raw::ChannelID_t const PrintFirst =
46  raw::isValidChannelID(FirstChannel) ? FirstChannel : raw::ChannelID_t(0);
47  raw::ChannelID_t const PrintLast =
48  raw::isValidChannelID(LastChannel) ? LastChannel : raw::ChannelID_t(NChannels - 1);
49 
50  // print intro
51  unsigned int const NPrintedChannels = (PrintLast - PrintFirst) + 1;
52  if (NPrintedChannels == NChannels) {
53  mf::LogInfo(OutputCategory) << "Printing all " << NChannels << " channels";
54  }
55  else {
56  mf::LogInfo(OutputCategory) << "Printing channels from " << PrintFirst << " to "
57  << LastChannel << " (" << NPrintedChannels << " channels out of "
58  << NChannels << ")";
59  }
60 
61  // print map
62  mf::LogVerbatim log(OutputCategory);
63  for (raw::ChannelID_t channel = PrintFirst; channel <= PrintLast; ++channel) {
64  std::vector<geo::WireID> const Wires = wireReadoutGeom.ChannelToWire(channel);
65 
66  log << "\n " << ((int)channel) << " ->";
67  switch (Wires.size()) {
68  case 0: log << " no wires"; break;
69  case 1: break;
70  default: log << " [" << Wires.size() << " wires]"; break;
71  }
72 
73  for (geo::WireID const& wireID : Wires) {
74  log << " { " << std::string(wireID) << " };";
75  }
76  }
77  }
78 
79  //------------------------------------------------------------------------------
80  void dumpWireToChannel(std::string const& OutputCategory,
81  geo::WireReadoutGeom const& wireReadoutGeom)
82  {
84  unsigned int const NChannels = wireReadoutGeom.Nchannels();
85 
86  if (NChannels == 0) {
87  mf::LogError(OutputCategory) << "Nice detector we have here, with no channels.";
88  return;
89  }
90 
91  // print intro
92  mf::LogInfo(OutputCategory) << "Printing wire channels for up to " << NChannels << " channels";
93 
94  // print map
95  mf::LogVerbatim log(OutputCategory);
96  for (geo::WireID const& wireID : wireReadoutGeom.Iterate<geo::WireID>()) {
97  raw::ChannelID_t channel = wireReadoutGeom.PlaneWireToChannel(wireID);
98  log << "\n { " << std::string(wireID) << " } => ";
99  if (raw::isValidChannelID(channel))
100  log << channel;
101  else
102  log << "invalid!";
103  } // for
104  }
105 
106  //------------------------------------------------------------------------------
107  geo::OpDetGeo const* getOpticalDetector(geo::WireReadoutGeom const& wireReadoutGeom,
108  unsigned int channelID)
109  {
110  try {
111  return &wireReadoutGeom.OpDetGeoFromOpChannel(channelID);
112  }
113  catch (cet::exception const&) {
114  return nullptr;
115  }
116  }
117 
118  //------------------------------------------------------------------------------
119  void dumpOpticalDetectorChannels(std::string const& OutputCategory,
120  geo::WireReadoutGeom const& wireReadoutGeom)
121  {
123  unsigned int const NChannels = wireReadoutGeom.NOpChannels();
124 
125  if (NChannels == 0) {
126  mf::LogError(OutputCategory) << "Nice detector we have here, with no optical channels.";
127  return;
128  }
129 
130  // print intro
131  mf::LogInfo(OutputCategory) << "Printing optical detectors for up to " << NChannels
132  << " channels";
133 
134  // print map
135  mf::LogVerbatim log(OutputCategory);
136  for (unsigned int channelID = 0; channelID < NChannels; ++channelID) {
137  log << "\nChannel " << channelID << " => ";
138  geo::OpDetGeo const* opDet = getOpticalDetector(wireReadoutGeom, channelID);
139  if (!opDet) {
140  log << "invalid";
141  continue;
142  }
143  log << opDet->ID() << " at " << opDet->GetCenter() << " cm";
144  } // for
145  }
146 }
147 
148 namespace geo {
149  class DumpChannelMap;
150 }
151 
177 public:
179  struct Config {
180  using Name = fhicl::Name;
182 
183  fhicl::Atom<std::string> OutputCategory{
184  Name("OutputCategory"),
185  Comment("output category used by the message facility to output information (INFO level)"),
186  "DumpChannelMap"};
187 
189  Comment("print all the wires corresponding to each channel"),
190  true};
191 
193  Comment("print which channel covers each wire"),
194  false};
195 
197  Name("OpDetChannels"),
198  Comment("print for each optical detector channel ID the optical detector ID and its center"),
199  false};
200 
202  Name("FirstChannel"),
203  Comment("ID of the lowest channel to be printed (default: no limit)"),
205 
207  Name("LastChannel"),
208  Comment("ID of the highest channel to be printed (default: no limit)"),
210 
211  }; // Config
212 
214 
215  explicit DumpChannelMap(Parameters const& config);
216 
217  // Plugins should not be copied or assigned.
218  DumpChannelMap(DumpChannelMap const&) = delete;
219  DumpChannelMap(DumpChannelMap&&) = delete;
220  DumpChannelMap& operator=(DumpChannelMap const&) = delete;
222 
223  // Required functions
224  void analyze(art::Event const&) override {}
225 
227  void beginRun(art::Run const&) override;
228 
229 private:
230  std::string OutputCategory;
234 
237 
238 }; // geo::DumpChannelMap
239 
240 //------------------------------------------------------------------------------
242  : art::EDAnalyzer(config)
243  , OutputCategory(config().OutputCategory())
244  , DoChannelToWires(config().ChannelToWires())
245  , DoWireToChannel(config().WireToChannel())
246  , DoOpDetChannels(config().OpDetChannels())
247  , FirstChannel(config().FirstChannel())
248  , LastChannel(config().LastChannel())
249 {}
250 
251 //------------------------------------------------------------------------------
253 {
255 
256  if (DoChannelToWires) {
257  dumpChannelToWires(OutputCategory, wireReadoutGeom, FirstChannel, LastChannel);
258  }
259  if (DoWireToChannel) { dumpWireToChannel(OutputCategory, wireReadoutGeom); }
260  if (DoOpDetChannels) { dumpOpticalDetectorChannels(OutputCategory, wireReadoutGeom); }
261 }
262 
bool DoOpDetChannels
Dump optical detector channel -> optical detector.
std::string OutputCategory
Name of the category for output.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
virtual unsigned int Nchannels() const =0
Returns the total number of channels present (not necessarily contiguous)
Point_t const & GetCenter() const
Definition: OpDetGeo.h:71
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
Definition: Run.h:37
DumpChannelMap & operator=(DumpChannelMap const &)=delete
Access the description of the physical detector geometry.
OpDetGeo const & OpDetGeoFromOpChannel(unsigned int opChannel) const
Returns the optical detector the specified optical channel belongs.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:31
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Interface for a class providing readout channel mapping to geometry.
void beginRun(art::Run const &) override
Drives the dumping.
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:35
virtual raw::ChannelID_t PlaneWireToChannel(WireID const &wireID) const =0
Returns the channel ID a wire is connected to.
bool DoWireToChannel
Dump wire -> channel mapping.
Definition of data types for geometry description.
bool DoChannelToWires
Dump channel -> wires mapping.
raw::ChannelID_t LastChannel
Last channel to be printed.
OpDetID const & ID() const
Returns the geometry ID of this optical detector.
Definition: OpDetGeo.h:69
Encapsulate the geometry of an optical detector.
virtual std::vector< WireID > ChannelToWire(raw::ChannelID_t channel) const =0
virtual unsigned int NOpChannels(unsigned int NOpDets) const
Returns the number of optical channels contained in some detectors.
range_type< T > Iterate() const
Definition: Iterable.h:121
Prints on screen the current channel-wire and optical detector maps.
Definition: MVAAlg.h:12
raw::ChannelID_t FirstChannel
First channel to be printed.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
DumpChannelMap(Parameters const &config)
ROOT libraries.
void analyze(art::Event const &) override
Interface to geometry for wire readouts .
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33