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