LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
OpHitFinder_module.cc
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 2; -*-
2 // Gleb Sinev, Duke, 2016
3 //
4 // This module finds periods of time-localized activity
5 // on each channel of the optical system and creates OpHits.
6 //
7 // Split from OpFlashFinder_module.cc
8 // by Ben Jones, MIT, 2013
9 //
10 
11 
12 #ifndef OpHitFinder_H
13 #define OpHitFinder_H 1
14 
15 // LArSoft includes
32 
33 // Framework includes
37 #include "fhiclcpp/ParameterSet.h"
41 
42 // ROOT includes
43 
44 // C++ Includes
45 #include <map>
46 #include <vector>
47 #include <string>
48 #include <memory>
49 
50 namespace opdet {
51 
52  class OpHitFinder : public art::EDProducer{
53  public:
54 
55  // Standard constructor and destructor for an ART module.
56  explicit OpHitFinder(const fhicl::ParameterSet&);
57  virtual ~OpHitFinder();
58 
59  void beginJob();
60  void endJob();
61  void reconfigure(fhicl::ParameterSet const& pset);
62 
63  // The producer routine, called once per event.
64  void produce(art::Event&);
65 
66  std::map< int, int > GetChannelMap();
67  std::vector< double > GetSPEScales();
68  std::vector< double > GetSPEShifts();
69 
70  private:
71 
72  // The parameters we'll read from the .fcl file.
73  std::string fInputModule; // Input tag for OpDetWaveform collection
74  std::string fGenModule;
75  std::vector< std::string > fInputLabels;
76  std::set< unsigned int > fChannelMasks;
77 
81 
82  Float_t fHitThreshold;
83  Bool_t fAreaToPE;
84  Float_t fSPEArea;
85  Float_t fSPEShift;
86 
87  unsigned int fMaxOpChannel;
88 
89  std::vector< double > fSPESize;
90  std::vector< double > fSPEShiftPerChan;
91 
92  };
93 
94 }
95 
96 namespace opdet {
98 }
99 
100 #endif
101 
102 namespace opdet {
103 
104  //----------------------------------------------------------------------------
105  // Constructor
107  fPulseRecoMgr()
108  {
109 
110  reconfigure(pset);
111 
112  // Initialize the hit finder algorithm
113  auto const hit_alg_pset = pset.get< fhicl::ParameterSet >("HitAlgoPset");
114  std::string threshAlgName = hit_alg_pset.get< std::string >("Name");
115  if (threshAlgName == "Threshold")
116  fThreshAlg = new pmtana::AlgoThreshold(hit_alg_pset);
117  else if (threshAlgName == "SiPM")
118  fThreshAlg = new pmtana::AlgoSiPM(hit_alg_pset);
119  else if (threshAlgName == "SlidingWindow")
120  fThreshAlg = new pmtana::AlgoSlidingWindow(hit_alg_pset);
121  else if (threshAlgName == "FixedWindow")
122  fThreshAlg = new pmtana::AlgoFixedWindow(hit_alg_pset);
123  else if (threshAlgName == "CFD" )
124  fThreshAlg = new pmtana::AlgoCFD(hit_alg_pset);
126  << "Cannot find implementation for "
127  << threshAlgName << " algorithm.\n";
128 
129  auto const ped_alg_pset = pset.get< fhicl::ParameterSet >("PedAlgoPset");
130  std::string pedAlgName = ped_alg_pset.get< std::string >("Name");
131  if (pedAlgName == "Edges")
132  fPedAlg = new pmtana::PedAlgoEdges(ped_alg_pset);
133  else if (pedAlgName == "RollingMean")
134  fPedAlg = new pmtana::PedAlgoRollingMean(ped_alg_pset);
135  else if (pedAlgName == "UB" )
136  fPedAlg = new pmtana::PedAlgoUB(ped_alg_pset);
138  << "Cannot find implementation for "
139  << pedAlgName << " algorithm.\n";
140 
141  produces< std::vector< recob::OpHit > >();
142 
145 
146  }
147 
148  //----------------------------------------------------------------------------
150  {
151 
152  // Indicate that the Input Module comes from .fcl
153  fInputModule = pset.get< std::string >("InputModule");
154  fGenModule = pset.get< std::string >("GenModule");
155  fInputLabels = pset.get< std::vector< std::string > >("InputLabels");
156 
157  for (auto const& ch : pset.get< std::vector< unsigned int > >
158  ("ChannelMasks", std::vector< unsigned int >()))
159  fChannelMasks.insert(ch);
160 
161  fHitThreshold = pset.get< float >("HitThreshold");
162  fAreaToPE = pset.get< bool > ("AreaToPE");
163  fSPEArea = pset.get< float >("SPEArea");
164  fSPEShift = pset.get< float >("SPEShift", 0.);
165 
166  auto const& geometry(*lar::providerFrom< geo::Geometry >());
167  fMaxOpChannel = geometry.MaxOpChannel();
168 
171 
172  }
173 
174  //----------------------------------------------------------------------------
175  // Destructor
177  {
178 
179  delete fThreshAlg;
180  delete fPedAlg;
181 
182  }
183 
184  //----------------------------------------------------------------------------
186  {
187  }
188 
189  //----------------------------------------------------------------------------
191  {
192  }
193 
194  //----------------------------------------------------------------------------
196  {
197 
198  // These is the storage pointer we will put in the event
199  std::unique_ptr< std::vector< recob::OpHit > >
200  HitPtr(new std::vector< recob::OpHit >);
201 
202  std::vector< const sim::BeamGateInfo* > beamGateArray;
203  try
204  {
205  evt.getView(fGenModule, beamGateArray);
206  }
207  catch (art::Exception const& err)
208  {
209  if ( err.categoryCode() != art::errors::ProductNotFound ) throw;
210  }
211 
212  auto const& geometry(*lar::providerFrom< geo::Geometry >());
213  auto const& detectorClocks
214  (*lar::providerFrom< detinfo::DetectorClocksService >());
215 
216  //
217  // Get the pulses from the event
218  //
219 
220  // Reserve a large enough array
221  int totalsize = 0;
222  for (auto label : fInputLabels)
223  {
225  evt.getByLabel(fInputModule, label, wfHandle);
226  if (!wfHandle.isValid()) continue; // Skip non-existent collections
227  totalsize += wfHandle->size();
228  }
229 
230  // Load pulses into WaveformVector
231  std::vector< raw::OpDetWaveform > WaveformVector;
232  WaveformVector.reserve(totalsize);
233  for (auto label : fInputLabels)
234  {
236  evt.getByLabel(fInputModule, label, wfHandle);
237  if (!wfHandle.isValid()) continue; // Skip non-existent collections
238 
239  //WaveformVector.insert(WaveformVector.end(),
240  // wfHandle->begin(), wfHandle->end());
241  for(auto const& wf : *wfHandle)
242  {
243  if (fChannelMasks.find(wf.ChannelNumber())
244  != fChannelMasks.end()) continue;
245  WaveformVector.push_back(wf);
246  }
247  }
248 
249  RunHitFinder(WaveformVector,
250  *HitPtr,
252  *fThreshAlg,
253  geometry,
255  detectorClocks,
256  fSPESize,
257  fAreaToPE,
259 
260  // Store results into the event
261  evt.put(std::move(HitPtr));
262 
263  }
264 
265  //----------------------------------------------------------------------------
266  std::vector< double > OpHitFinder::GetSPEScales()
267  {
268  // This will eventually interface to some kind of gain service
269  // or database. For now all SPE scales are set to 20 ADC.
270  // Alternatively all SPE scales are set to fSPEArea
271  // if hit area is used to calculate number of PEs
272 
273  if (fAreaToPE) return std::vector< double >(fMaxOpChannel + 1, fSPEArea);
274  else return std::vector< double >(fMaxOpChannel + 1, 20);
275  }
276 
277  std::vector< double > OpHitFinder::GetSPEShifts()
278  {
279  // For now every channel will have the same shift factor in the calibration.
280  // This function assigns the appropriate shift value for calibration to each
281  // channel. For now, every channel will have the same corresponding shift
282  // factor, which is configurable.
283  return std::vector< double >(fMaxOpChannel + 1, fSPEShift);
284 
285  }
286 
287 } // namespace opdet
std::set< unsigned int > fChannelMasks
const std::string label
void reconfigure(fhicl::ParameterSet const &pset)
unsigned int fMaxOpChannel
std::vector< double > GetSPEScales()
std::vector< std::string > fInputLabels
void AddRecoAlgo(pmtana::PMTPulseRecoBase *algo, PMTPedestalBase *ped_algo=nullptr)
A method to set pulse reconstruction algorithm.
OpHitFinder(const fhicl::ParameterSet &)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool isValid() const
Definition: Handle.h:190
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:474
std::map< int, int > GetChannelMap()
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Class definition file of PedAlgoRollingMean.
Class definition file of AlgoCFD.
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::vector< double > fSPEShiftPerChan
Class definition file of PedAlgoUB.
void RunHitFinder(std::vector< raw::OpDetWaveform > const &opDetWaveformVector, std::vector< recob::OpHit > &hitVector, pmtana::PulseRecoManager const &pulseRecoMgr, pmtana::PMTPulseRecoBase const &threshAlg, geo::GeometryCore const &geometry, float hitThreshold, detinfo::DetectorClocks const &detectorClocks, std::vector< double > const &SPESize, bool areaToPE, std::vector< double > const &SPEShiftPerChan)
Definition: OpHitAlg.cxx:18
pmtana::PMTPulseRecoBase * fThreshAlg
void produce(art::Event &)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Class definition file of AlgoFixedWindow.
std::vector< double > fSPESize
std::vector< double > GetSPEShifts()
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Class definition file of AlgoSlidingWindow.
Class definition file of AlgoThreshold.
pmtana::PulseRecoManager fPulseRecoMgr
void SetDefaultPedAlgo(pmtana::PMTPedestalBase *algo)
A method to set a choice of pedestal estimation method.
Class definition file of PMTPulseRecoBase.
Class definition file of PedAlgoEdges.
art framework interface to geometry description
pmtana::PMTPedestalBase * fPedAlg
Class definition file of PulseRecoManager.