All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WireAna_module.cc
Go to the documentation of this file.
1 // WireAna_module.cc
2 //
3 // The aim of this ana module is to do some basic analysis of RawDigit
4 // waveforms to better understand issues...
5 //
6 
7 #ifndef WireAna_module
8 #define WireAna_module
9 
10 // LArSoft includes
12 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
15 #include "lardataobj/RawData/raw.h"
18 
19 //#include "cetlib/search_path.h"
20 #include "cetlib/cpu_timer.h"
24 
25 // Framework includes
26 #include "art/Framework/Core/EDAnalyzer.h"
27 #include "art/Framework/Principal/Event.h"
28 #include "art/Framework/Principal/Handle.h"
29 #include "art/Framework/Principal/View.h"
30 #include "art/Framework/Services/Registry/ServiceHandle.h"
31 #include "art_root_io/TFileService.h"
32 #include "art/Framework/Core/ModuleMacros.h"
33 #include "art/Utilities/make_tool.h"
34 #include "canvas/Utilities/InputTag.h"
35 #include "canvas/Persistency/Common/FindManyP.h"
36 #include "messagefacility/MessageLogger/MessageLogger.h"
37 #include "fhiclcpp/ParameterSet.h"
38 #include "cetlib_except/exception.h"
39 
41 
42 // C++ Includes
43 #include <map>
44 #include <vector>
45 #include <tuple>
46 #include <algorithm>
47 #include <iostream>
48 #include <string>
49 #include <cmath>
50 
51 #include <iostream>
52 #include <fstream>
53 
54 namespace WireAna
55 {
56 //-----------------------------------------------------------------------
57 //-----------------------------------------------------------------------
58 // class definition
59 
60 class WireAna : public art::EDAnalyzer
61 {
62 public:
63 
64  // Standard constructor and destructor for an ART module.
65  explicit WireAna(fhicl::ParameterSet const& pset);
66  virtual ~WireAna();
67 
68  // This method is called once, at the start of the job. In this
69  // example, it will define the histograms and n-tuples we'll write.
70  void beginJob() override;
71  void endJob() override;
72 
73  // This method is called once, at the start of each run. It's a
74  // good place to read databases or files that may have
75  // run-dependent information.
76  void beginRun(const art::Run& run) override;
77 
78  // This method reads in any parameters from the .fcl files. This
79  // method is called 'reconfigure' because it might be called in the
80  // middle of a job; e.g., if the user changes parameter values in an
81  // interactive event display.
82  void reconfigure(fhicl::ParameterSet const& pset);
83 
84  // The analysis routine, called once per event.
85  void analyze (const art::Event& evt) override;
86 
87 private:
88 
89  // The parameters we'll read from the .fcl file.
90  std::vector<art::InputTag> fWireProducerLabelVec;
91  art::InputTag fSimChannelProducerLabel;
92 
93  // The variables that will go into the n-tuple.
94  int fEvent;
95  int fRun;
96  int fSubRun;
98 
99  // Keep track of the hit histogramming tools here
100  std::vector<std::unique_ptr<IWireHistogramTool>> fWireHistogramToolVec;
101 
102  std::vector<std::vector<double>> fChannelPedVec;
103 
104  // Other variables that will be shared between different methods.
105  const geo::GeometryCore* fGeometry; // pointer to Geometry service
106  const lariov::DetPedestalProvider& fPedestalRetrievalAlg; ///< Keep track of an instance to the pedestal retrieval alg
107 }; // class WireAna
108 
109 
110 //-----------------------------------------------------------------------
111 //-----------------------------------------------------------------------
112 // class implementation
113 
114 //-----------------------------------------------------------------------
115 // Constructor
116 WireAna::WireAna(fhicl::ParameterSet const& parameterSet)
117  : EDAnalyzer(parameterSet),
118  fPedestalRetrievalAlg(*lar::providerFrom<lariov::DetPedestalService>())
119 
120 {
121  fGeometry = lar::providerFrom<geo::Geometry>();
122 
123  // Read in the parameters from the .fcl file.
124  this->reconfigure(parameterSet);
125 }
126 
127 //-----------------------------------------------------------------------
128 // Destructor
129 WireAna::~WireAna()
130 {}
131 
132 //-----------------------------------------------------------------------
133 void WireAna::beginJob()
134 {
135  // Get the detector length, to determine the maximum bin edge of one
136  // of the histograms.
137  //double detectorLength = fGeometry->DetLength();
138 
139  // Access ART's TFileService, which will handle creating and writing
140  // histograms and n-tuples for us.
141  art::ServiceHandle<art::TFileService> tfs;
142 
143  // The arguments to 'make<whatever>' are the same as those passed
144  // to the 'whatever' constructor, provided 'whatever' is a ROOT
145  // class that TFileService recognizes.
146  for (auto& wireHistTool : fWireHistogramToolVec) wireHistTool->initializeHists(tfs, "WireAna");
147 
148  // zero out the event counter
149  fNumEvents = 0;
150 }
151 
152 //-----------------------------------------------------------------------
153 void WireAna::beginRun(const art::Run& /*run*/)
154 {
155  // How to convert from number of electrons to GeV. The ultimate
156  // source of this conversion factor is
157  // ${LARSIM_DIR}/include/SimpleTypesAndConstants/PhysicalConstants.h.
158 // art::ServiceHandle<sim::LArG4Parameters> larParameters;
159 // fElectronsToGeV = 1./larParameters->GeVToElectrons();
160 }
161 
162 //-----------------------------------------------------------------------
163 void WireAna::reconfigure(fhicl::ParameterSet const& p)
164 {
165  // Read parameters from the .fcl file. The names in the arguments
166  // to p.get<TYPE> must match names in the .fcl file.
167  fWireProducerLabelVec = p.get< std::vector<art::InputTag> >("WireModuleLabel", std::vector<art::InputTag>() = {"recowire"});
168  fSimChannelProducerLabel = p.get< std::string >("SimChannelModuleLabel", "daq" );
169 
170  // Implement the tools for handling the responses
171  const std::vector<fhicl::ParameterSet>& wireHistogramToolVec = p.get<std::vector<fhicl::ParameterSet>>("WireHistogramToolList");
172 
173  for(auto& wireHistogramTool : wireHistogramToolVec)
174  fWireHistogramToolVec.push_back(art::make_tool<IWireHistogramTool>(wireHistogramTool));
175 
176  return;
177 }
178 
179 //-----------------------------------------------------------------------
180 void WireAna::analyze(const art::Event& event)
181 {
182  // Start by fetching some basic event information for our n-tuple.
183  fEvent = event.id().event();
184  fRun = event.run();
185  fSubRun = event.subRun();
186 
187  fNumEvents++;
188 
189  // Loop over input list of wire producers
190  for(const auto& wireLabel : fWireProducerLabelVec)
191  {
192  // Make a pass through all hits to make contrasting plots
193  art::Handle< std::vector<recob::Wire> > wireHandle;
194  event.getByLabel(wireLabel, wireHandle);
195 
196  // Recover sim channels (if they exist) so we know when a
197  // channel has signal (or not)
198  art::Handle<std::vector<sim::SimChannel>> simChannelHandle;
199  event.getByLabel(fSimChannelProducerLabel, simChannelHandle);
200 
201  // Recover list of simChannels mapped by channel to make
202  // look up easier below
204 
205  if (simChannelHandle.isValid())
206  {
207  for(const auto& simChannel : *simChannelHandle) channelMap[simChannel.Channel()] = &simChannel;
208 // {
209 // raw::ChannelID_t channel = simChannel.Channel();
210 // const sim::SimChannel* simChannelPtr = &simChannel;
211 //
212 // channelMap.at(channel) = simChannelPtr;
213 // }
214  }
215 
216  if (wireHandle.isValid())
217  {
219  art::fill_ptr_vector(wireVec, wireHandle);
220 
221  for(auto& wireHistTool : fWireHistogramToolVec) wireHistTool->fillHistograms(wireVec,channelMap,fNumEvents);
222  }
223  }
224 
225  return;
226 }
227 
228 void WireAna::endJob()
229 {
230  // Make a call to normalize histograms if so desired
231  for(auto& wireHistTool : fWireHistogramToolVec) wireHistTool->endJob(fNumEvents);
232 
233  return;
234 }
235 
236 // This macro has to be defined for this module to be invoked from a
237 // .fcl file; see WireAna.fcl for more information.
238 DEFINE_ART_MODULE(WireAna)
239 
240 } // namespace WireAna
241 
242 #endif // WireAna_module
const geo::GeometryCore * fGeometry
process_name opflashCryo1 flashfilter analyze
std::vector< std::unique_ptr< IWireHistogramTool > > fWireHistogramToolVec
Utilities related to art service access.
T::provider_type const * providerFrom()
Returns a constant pointer to the provider of specified service.
Definition: ServiceUtil.h:77
pdgs p
Definition: selectors.fcl:22
void analyze(const art::Event &evt) override
for pfile in ack l reconfigure(.*) override"` do echo "checking $
void beginJob() override
Collect all the RawData header files together.
std::vector< art::Ptr< recob::Wire >> WirePtrVec
Interface for filling histograms.
std::vector< std::vector< double > > fChannelPedVec
std::vector< art::InputTag > fWireProducerLabelVec
Description of geometry of one entire detector.
Definition of data types for geometry description.
void reconfigure(fhicl::ParameterSet const &pset)
WireAna(fhicl::ParameterSet const &pset)
void beginRun(const art::Run &run) override
std::map< raw::ChannelID_t, const sim::SimChannel * > SimChannelMap
art::InputTag fSimChannelProducerLabel
Declaration of basic channel signal object.
art::ServiceHandle< art::TFileService > tfs
TCEvent evt
Definition: DataStructs.cxx:8
const lariov::DetPedestalProvider & fPedestalRetrievalAlg
Keep track of an instance to the pedestal retrieval alg.
void endJob() override
art framework interface to geometry description