DumpHits_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpHits_module.cc
3  * @brief Dumps on screen the content of the hits
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date Match 9th, 2015
6  */
7 
8 // C//C++ standard libraries
9 #include <string>
10 
11 // support libraries
12 #include "fhiclcpp/types/Atom.h"
13 #include "fhiclcpp/types/Name.h"
14 #include "fhiclcpp/types/Comment.h"
15 
16 // art libraries
20 #include "canvas/Persistency/Common/FindOne.h"
22 
23 // ... plus see below ...
24 
25 namespace hit {
26 
27  /**
28  * @brief Prints the content of all the hits on screen
29  *
30  * This analyser prints the content of all the hits into the
31  * LogInfo/LogVerbatim stream.
32  *
33  * Configuration parameters
34  * =========================
35  *
36  * - *HitModuleLabel* (string): label of the producer used to create the
37  * recob::Hit collection
38  * - *OutputCategory* (string, default: "DumpHits"): the category
39  * used for the output (useful for filtering)
40  * - *CheckWireAssociation* (string, default: false): if set, verifies
41  * that the associated wire are on the same channel as the hit
42  * - *CheckRawDigitAssociation* (string, default: false): if set, verifies
43  * that the associated raw digits are on the same channel as the hit
44  *
45  */
46  class DumpHits: public art::EDAnalyzer {
47  public:
48 
49  struct Config {
50  using Name = fhicl::Name;
52 
54  Name("HitModuleLabel"),
55  Comment("tag of the producer used to create the recob::Hit collection")
56  };
57 
59  Name("OutputCategory"),
60  Comment("the messagefacility category used for the output"),
61  "DumpHits"
62  };
63 
65  Name("CheckRawDigitAssociation"),
66  Comment("verify the associated raw digits are on the same channel as the hit"),
67  false
68  }; // CheckRawDigitAssociation
69 
71  Name("CheckWireAssociation"),
72  Comment("verify the associated wire is on the same channel as the hit"),
73  false
74  }; // CheckWireAssociation
75 
76  }; // Config
77 
79 
80 
81  /// Default constructor
82  explicit DumpHits(Parameters const& config);
83 
84  /// Does the printing
85  void analyze (const art::Event& evt);
86 
87  private:
88 
89  art::InputTag fHitsModuleLabel; ///< name of module that produced the hits
90  std::string fOutputCategory; ///< category for LogInfo output
91  bool bCheckRawDigits; ///< check associations with raw digits
92  bool bCheckWires; ///< check associations with wires
93 
94  }; // class DumpHits
95 
96 } // namespace hit
97 
98 
99 //------------------------------------------------------------------------------
100 //--- module implementation
101 //---
102 // C//C++ standard libraries
103 #include <memory> // std::unique_ptr<>
104 
105 // support libraries
107 
108 // art libraries
110 
111 // LArSoft includes
112 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
113 #include "lardataobj/RecoBase/Hit.h"
116 
117 
118 namespace hit {
119 
120  //-------------------------------------------------
122  : EDAnalyzer (config)
123  , fHitsModuleLabel (config().HitModuleLabel())
124  , fOutputCategory (config().OutputCategory())
126  , bCheckWires (config().CheckWireAssociation())
127  {}
128 
129 
130  //-------------------------------------------------
132 
133  // fetch the data to be dumped on screen
134  auto Hits = evt.getValidHandle<std::vector<recob::Hit>>(fHitsModuleLabel);
135 
137  << "The event contains " << Hits->size() << " '"
138  << fHitsModuleLabel.encode() << "' hits";
139 
140  std::unique_ptr<art::FindOne<raw::RawDigit>> HitToRawDigit;
141  if (bCheckRawDigits) {
142  HitToRawDigit.reset
143  (new art::FindOne<raw::RawDigit>(Hits, evt, fHitsModuleLabel));
144  if (!HitToRawDigit->isValid()) {
146  << "DumpHits: can't find associations between raw digits and hits from '"
147  << fHitsModuleLabel << "'";
148  }
149  } // if check raw digits
150 
151  std::unique_ptr<art::FindOne<recob::Wire>> HitToWire;
152  if (bCheckWires) {
153  HitToWire.reset(new art::FindOne<recob::Wire>(Hits, evt, fHitsModuleLabel));
154  if (!HitToWire->isValid()) {
156  << "DumpHits: can't find associations between wires and hits from '"
157  << fHitsModuleLabel << "'";
158  }
159  } // if check wires
160 
161  unsigned int iHit = 0;
162  for (const recob::Hit& hit: *Hits) {
163 
164  // print a header for the cluster
166  << "Hit #" << iHit << ": " << hit;
167 
168  if (HitToRawDigit) {
169  raw::ChannelID_t assChannelID = HitToRawDigit->at(iHit).ref().Channel();
170  if (assChannelID != hit.Channel()) {
172  << "Hit #" << iHit << " on channel " << hit.Channel()
173  << " is associated with raw digit on channel " << assChannelID
174  << "!!";
175  } // mismatch
176  } // raw digit check
177 
178  if (HitToWire) {
179  raw::ChannelID_t assChannelID = HitToWire->at(iHit).ref().Channel();
180  if (assChannelID != hit.Channel()) {
182  << "Hit #" << iHit << " on channel " << hit.Channel()
183  << " is associated with wire on channel " << assChannelID
184  << "!!";
185  } // mismatch
186  } // wire check
187 
188  ++iHit;
189  } // for hits
190 
191  } // DumpHits::analyze()
192 
194 
195 } // namespace hit
fhicl::Atom< bool > CheckWireAssociation
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
art::InputTag fHitsModuleLabel
name of module that produced the hits
fhicl::Atom< bool > CheckRawDigitAssociation
Prints the content of all the hits on screen.
fhicl::Atom< art::InputTag > HitModuleLabel
fhicl::Comment Comment
void analyze(const art::Event &evt)
Does the printing.
std::string fOutputCategory
category for LogInfo output
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
ChannelGroupService::Name Name
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
fhicl::Atom< std::string > OutputCategory
std::string encode() const
Definition: InputTag.cc:97
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
details::FindAllP< recob::Hit, recob::Wire > HitToWire
Query object connecting a hit to a wire.
Definition: HitUtils.h:56
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
size_type size() const
Definition: PtrVector.h:302
Detector simulation of raw signals on wires.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::PtrVector< recob::Hit > Hits
Declaration of signal hit object.
bool bCheckWires
check associations with wires
#define Comment
bool bCheckRawDigits
check associations with raw digits
DumpHits(Parameters const &config)
Default constructor.
Declaration of basic channel signal object.
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28