All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
17 #include "art/Framework/Core/EDAnalyzer.h"
18 #include "art/Framework/Core/ModuleMacros.h"
19 #include "art/Framework/Principal/Event.h"
20 #include "canvas/Persistency/Common/FindOne.h"
21 #include "canvas/Utilities/InputTag.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;
51  using Comment = fhicl::Comment;
52 
53  fhicl::Atom<art::InputTag> HitModuleLabel{
54  Name("HitModuleLabel"),
55  Comment("tag of the producer used to create the recob::Hit collection")
56  };
57 
58  fhicl::Atom<std::string> OutputCategory{
59  Name("OutputCategory"),
60  Comment("the messagefacility category used for the output"),
61  "DumpHits"
62  };
63 
64  fhicl::Atom<bool> CheckRawDigitAssociation{
65  Name("CheckRawDigitAssociation"),
66  Comment("verify the associated raw digits are on the same channel as the hit"),
67  false
68  }; // CheckRawDigitAssociation
69 
70  fhicl::Atom<bool>CheckWireAssociation{
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 
78  using Parameters = art::EDAnalyzer::Table<Config>;
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
106 #include "messagefacility/MessageLogger/MessageLogger.h"
107 
108 // art libraries
109 #include "art/Framework/Principal/Handle.h"
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())
125  , bCheckRawDigits (config().CheckRawDigitAssociation())
126  , bCheckWires (config().CheckWireAssociation())
127  {}
128 
129 
130  //-------------------------------------------------
131  void DumpHits::analyze(const art::Event& evt) {
132 
133  // fetch the data to be dumped on screen
134  auto Hits = evt.getValidHandle<std::vector<recob::Hit>>(fHitsModuleLabel);
135 
136  mf::LogInfo(fOutputCategory)
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()) {
145  throw art::Exception(art::errors::ProductNotFound)
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()) {
155  throw art::Exception(art::errors::ProductNotFound)
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
165  mf::LogVerbatim(fOutputCategory)
166  << "Hit #" << iHit << ": " << hit;
167 
168  if (HitToRawDigit) {
169  raw::ChannelID_t assChannelID = HitToRawDigit->at(iHit).ref().Channel();
170  if (assChannelID != hit.Channel()) {
171  throw art::Exception(art::errors::DataCorruption)
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()) {
181  throw art::Exception(art::errors::DataCorruption)
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 
193  DEFINE_ART_MODULE(DumpHits)
194 
195 } // namespace hit
fhicl::Atom< bool > CheckWireAssociation
art::InputTag fHitsModuleLabel
name of module that produced the hits
fhicl::Atom< bool > CheckRawDigitAssociation
art::EDAnalyzer::Table< Config > Parameters
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
Declaration of signal hit object.
Definition of basic raw digits.
process_name hit
Definition: cheaterreco.fcl:51
fhicl::Atom< std::string > OutputCategory
details::FindAllP< recob::Hit, recob::Wire > HitToWire
Query object connecting a hit to a wire.
Definition: HitUtils.h:56
BEGIN_PROLOG vertical distance to the surface Name
art::PtrVector< recob::Hit > Hits
bool bCheckWires
check associations with wires
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:8
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28