LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
hit::GausHitFinder Class Reference
Inheritance diagram for hit::GausHitFinder:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 GausHitFinder (fhicl::ParameterSet const &pset)
 
void produce (art::Event &evt) override
 
void beginJob () override
 
void endJob () override
 
void reconfigure (fhicl::ParameterSet const &p)
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > consumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > consumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > mayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > mayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Member Functions

void FillOutHitParameterVector (const std::vector< double > &input, std::vector< double > &output)
 

Private Attributes

bool fFilterHits
 
std::string fCalDataModuleLabel
 
std::string fAllHitsInstanceName
 
std::vector< int > fLongMaxHitsVec
 Maximum number hits on a really long pulse train. More...
 
std::vector< int > fLongPulseWidthVec
 Sets width of hits used to describe long pulses. More...
 
size_t fMaxMultiHit
 maximum hits for multi fit More...
 
int fAreaMethod
 Type of area calculation. More...
 
std::vector< double > fAreaNormsVec
 factors for converting area to same units as peak height More...
 
bool fTryNplus1Fits
 whether we will (true) or won't (false) try n+1 fits More...
 
double fChi2NDF
 
std::vector< float > fPulseHeightCuts
 maximum Chisquared / NDF allowed for a hit to be saved More...
 
std::vector< float > fPulseWidthCuts
 
std::vector< float > fPulseRatioCuts
 
size_t fEventCount
 
std::vector< std::unique_ptr< reco_tool::ICandidateHitFinder > > fHitFinderToolVec
 For finding candidate hits. More...
 
std::unique_ptr< reco_tool::IPeakFitterfPeakFitterTool
 Perform fit to candidate peaks. More...
 
std::unique_ptr< HitFilterAlgfHitFilterAlg
 algorithm used to filter out noise hits More...
 
TH1F * fFirstChi2
 
TH1F * fChi2
 

Detailed Description

Definition at line 70 of file GausHitFinder_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

hit::GausHitFinder::GausHitFinder ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 118 of file GausHitFinder_module.cc.

References recob::HitAndAssociationsWriterBase::declare_products(), fAllHitsInstanceName, and reconfigure().

119 {
120  this->reconfigure(pset);
121 
122  // let HitCollectionCreator declare that we are going to produce
123  // hits and associations with wires and raw digits
124  // We want the option to output two hit collections, one filtered
125  // and one with all hits. The key to doing this will be a non-null
126  // instance name for the second collection
127  // (with no particular product label)
129 
130  // and now the filtered hits...
132 
133  return;
134 } // GausHitFinder::GausHitFinder()
static void declare_products(ModuleType &producer, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.h:1117
void reconfigure(fhicl::ParameterSet const &p)
std::string fAllHitsInstanceName

Member Function Documentation

void hit::GausHitFinder::beginJob ( )
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 213 of file GausHitFinder_module.cc.

References fChi2, fFirstChi2, and art::TFileDirectory::make().

214 {
215  // get access to the TFile service
217 
218 
219  // ======================================
220  // === Hit Information for Histograms ===
221  fFirstChi2 = tfs->make<TH1F>("fFirstChi2", "#chi^{2}", 10000, 0, 5000);
222  fChi2 = tfs->make<TH1F>("fChi2", "#chi^{2}", 10000, 0, 5000);
223 }
T * make(ARGS...args) const
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 147 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

148 {
149  if (!moduleContext_)
150  return ProductToken<T>::invalid();
151 
152  consumables_[BT].emplace_back(ConsumableType::Product,
153  TypeID{typeid(T)},
154  it.label(),
155  it.instance(),
156  it.process());
157  return ProductToken<T>{it};
158 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 162 of file Consumer.h.

163 {
164  if (!moduleContext_)
165  return;
166 
167  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
168 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 172 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

173 {
174  if (!moduleContext_)
175  return ViewToken<T>::invalid();
176 
177  consumables_[BT].emplace_back(ConsumableType::ViewElement,
178  TypeID{typeid(T)},
179  it.label(),
180  it.instance(),
181  it.process());
182  return ViewToken<T>{it};
183 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited

Definition at line 32 of file EngineCreator.cc.

References art::EngineCreator::rng().

34 {
35  return rng()->createEngine(
36  placeholder_schedule_id(), seed, kind_of_engine_to_make);
37 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited

Definition at line 40 of file EngineCreator.cc.

References art::EngineCreator::rng().

43 {
44  return rng()->createEngine(
45  placeholder_schedule_id(), seed, kind_of_engine_to_make, engine_label);
46 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
CurrentProcessingContext const * art::EDProducer::currentContext ( ) const
protectedinherited

Definition at line 120 of file EDProducer.cc.

References art::EDProducer::current_context_.

121  {
122  return current_context_.get();
123  }
CPC_exempt_ptr current_context_
Definition: EDProducer.h:116
void hit::GausHitFinder::endJob ( )
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 227 of file GausHitFinder_module.cc.

228 {
229 
230 }
void hit::GausHitFinder::FillOutHitParameterVector ( const std::vector< double > &  input,
std::vector< double > &  output 
)
private

Definition at line 139 of file GausHitFinder_module.cc.

References geo::GeometryCore::Nplanes().

Referenced by reconfigure().

141 {
142  if(input.size()==0)
143  throw std::runtime_error("GausHitFinder::FillOutHitParameterVector ERROR! Input config vector has zero size.");
144 
146  const unsigned int N_PLANES = geom->Nplanes();
147 
148  if(input.size()==1)
149  output.resize(N_PLANES,input[0]);
150  else if(input.size()==N_PLANES)
151  output = input;
152  else
153  throw std::runtime_error("GausHitFinder::FillOutHitParameterVector ERROR! Input config vector size !=1 and !=N_PLANES.");
154 
155 }
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
EngineCreator::seed_t EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited

Definition at line 49 of file EngineCreator.cc.

References fhicl::ParameterSet::get().

Referenced by art::MixFilter< T >::initEngine_().

52 {
53  auto const& explicit_seeds = pset.get<std::vector<int>>(key, {});
54  return explicit_seeds.empty() ? implicit_seed : explicit_seeds.front();
55 }
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References B, and art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
Int_t B
Definition: plot.C:25
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 190 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

191 {
192  if (!moduleContext_)
193  return ProductToken<T>::invalid();
194 
195  consumables_[BT].emplace_back(ConsumableType::Product,
196  TypeID{typeid(T)},
197  it.label(),
198  it.instance(),
199  it.process());
200  return ProductToken<T>{it};
201 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 205 of file Consumer.h.

206 {
207  if (!moduleContext_)
208  return;
209 
210  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
211 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 215 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

216 {
217  if (!moduleContext_)
218  return ViewToken<T>::invalid();
219 
220  consumables_[BT].emplace_back(ConsumableType::ViewElement,
221  TypeID{typeid(T)},
222  it.label(),
223  it.instance(),
224  it.process());
225  return ViewToken<T>{it};
226 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID().

41  {
42  return true;
43  }
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited

Definition at line 89 of file Consumer.cc.

References fhicl::ParameterSet::get_if_present().

Referenced by art::EDProducer::doBeginJob(), art::EDFilter::doBeginJob(), and art::EDAnalyzer::doBeginJob().

90 {
91  if (!moduleContext_)
92  return;
93 
94  pset.get_if_present("errorOnMissingConsumes", requireConsumes_);
95  for (auto& consumablesPerBranch : consumables_) {
96  cet::sort_all(consumablesPerBranch);
97  }
98 }
bool requireConsumes_
Definition: Consumer.h:137
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
void hit::GausHitFinder::produce ( art::Event evt)
overridevirtual

Implements art::EDProducer.

Definition at line 236 of file GausHitFinder_module.cc.

References recob::Wire::Channel(), geo::GeometryCore::ChannelToWire(), recob::HitCreator::copy(), DEFINE_ART_MODULE, recob::HitCollectionCreator::emplace_back(), fAllHitsInstanceName, fAreaMethod, fAreaNormsVec, fCalDataModuleLabel, fChi2, fChi2NDF, fEventCount, fFilterHits, fFirstChi2, fHitFilterAlg, fHitFinderToolVec, fLongMaxHitsVec, fLongPulseWidthVec, fMaxMultiHit, fPeakFitterTool, fPulseHeightCuts, fPulseRatioCuts, fPulseWidthCuts, lar::sparse_vector< T >::get_ranges(), art::DataViewImpl::getByLabel(), raw::InvalidChannelID, art::left(), min, recob::HitCreator::move(), geo::PlaneID::Plane, recob::HitCollectionCreator::put_into(), art::right(), and recob::Wire::SignalROI().

237 {
238  //==================================================================================================
239 
240  TH1::AddDirectory(kFALSE);
241 
242  // Instantiate and Reset a stop watch
243  //TStopwatch StopWatch;
244  //StopWatch.Reset();
245 
246  // ################################
247  // ### Calling Geometry service ###
248  // ################################
250 
251  // ###############################################
252  // ### Making a ptr vector to put on the event ###
253  // ###############################################
254  // this contains the hit collection
255  // and its associations to wires and raw digits
256  recob::HitCollectionCreator allHitCol(*this, evt, fAllHitsInstanceName);
257 
258  // Handle the filtered hits collection...
259  recob::HitCollectionCreator hcol(*this, evt);
260  recob::HitCollectionCreator* filteredHitCol = 0;
261 
262  if( fFilterHits ) filteredHitCol = &hcol;
263 // if (fAllHitsInstanceName != "") filteredHitCol = &hcol;
264 
265  // ##########################################
266  // ### Reading in the Wire List object(s) ###
267  // ##########################################
269  evt.getByLabel(fCalDataModuleLabel,wireVecHandle);
270 
271  // #################################################################
272  // ### Reading in the RawDigit associated with these wires, too ###
273  // #################################################################
275  (wireVecHandle, evt, fCalDataModuleLabel);
276 
277  // Channel Number
279 
280  //#################################################
281  //### Set the charge determination method ###
282  //### Default is to compute the normalized area ###
283  //#################################################
284  std::function<double (double,double,double,double,int,int)> chargeFunc = [](double peakMean, double peakAmp, double peakWidth, double areaNorm, int low, int hi){return std::sqrt(2*TMath::Pi())*peakAmp*peakWidth/areaNorm;};
285 
286  //##############################################
287  //### Alternative is to integrate over pulse ###
288  //##############################################
289  if (fAreaMethod == 0)
290  chargeFunc = [](double peakMean, double peakAmp, double peakWidth, double areaNorm, int low, int hi)
291  {
292  double charge(0);
293  for(int sigPos = low; sigPos < hi; sigPos++)
294  charge += peakAmp * TMath::Gaus(sigPos,peakMean,peakWidth);
295  return charge;
296  };
297 
298  //##############################
299  //### Looping over the wires ###
300  //##############################
301  for(size_t wireIter = 0; wireIter < wireVecHandle->size(); wireIter++)
302  {
303  // ####################################
304  // ### Getting this particular wire ###
305  // ####################################
306  art::Ptr<recob::Wire> wire(wireVecHandle, wireIter);
307  art::Ptr<raw::RawDigit> rawdigits = RawDigits.at(wireIter);
308 
309  // --- Setting Channel Number and Signal type ---
310  channel = wire->Channel();
311 
312  // get the WireID for this hit
313  std::vector<geo::WireID> wids = geom->ChannelToWire(channel);
314  // for now, just take the first option returned from ChannelToWire
315  geo::WireID wid = wids[0];
316  // We need to know the plane to look up parameters
317  geo::PlaneID::PlaneID_t plane = wid.Plane;
318 
319  // ----------------------------------------------------------
320  // -- Setting the appropriate signal widths and thresholds --
321  // -- for the right plane. --
322  // ----------------------------------------------------------
323 
324  // #################################################
325  // ### Set up to loop over ROI's for this wire ###
326  // #################################################
327  const recob::Wire::RegionsOfInterest_t& signalROI = wire->SignalROI();
328 
329  for(const auto& range : signalROI.get_ranges())
330  {
331  // #################################################
332  // ### Getting a vector of signals for this wire ###
333  // #################################################
334  //std::vector<float> signal(wire->Signal());
335 
336  const std::vector<float>& signal = range.data();
337 
338  // ##########################################################
339  // ### Making an iterator for the time ticks of this wire ###
340  // ##########################################################
341  std::vector<float>::const_iterator timeIter; // iterator for time bins
342 
343  // ROI start time
344  raw::TDCtick_t roiFirstBinTick = range.begin_index();
345 
346  // ###########################################################
347  // ### Scan the waveform and find candidate peaks + merge ###
348  // ###########################################################
349 
352 
353  fHitFinderToolVec.at(plane)->findHitCandidates(signal, 0, channel, fEventCount, hitCandidateVec);
354  fHitFinderToolVec.at(plane)->MergeHitCandidates(signal, hitCandidateVec, mergedCandidateHitVec);
355 
356  // #######################################################
357  // ### Lets loop over the pulses we found on this wire ###
358  // #######################################################
359 
360  for(auto& mergedCands : mergedCandidateHitVec)
361  {
362  int startT= mergedCands.front().startTick;
363  int endT = mergedCands.back().stopTick;
364 
365  // ### Putting in a protection in case things went wrong ###
366  // ### In the end, this primarily catches the case where ###
367  // ### a fake pulse is at the start of the ROI ###
368  if (endT - startT < 5) continue;
369 
370  // #######################################################
371  // ### Clearing the parameter vector for the new pulse ###
372  // #######################################################
373 
374  // === Setting the number of Gaussians to try ===
375  int nGausForFit = mergedCands.size();
376 
377  // ##################################################
378  // ### Calling the function for fitting Gaussians ###
379  // ##################################################
380  double chi2PerNDF(0.);
381  int NDF(1);
383 
384  // #######################################################
385  // ### If # requested Gaussians is too large then punt ###
386  // #######################################################
387  if (mergedCands.size() <= fMaxMultiHit)
388  {
389  fPeakFitterTool->findPeakParameters(signal, mergedCands, peakParamsVec, chi2PerNDF, NDF);
390 
391  // If the chi2 is infinite then there is a real problem so we bail
392  if (!(chi2PerNDF < std::numeric_limits<double>::infinity()))
393  {
394  chi2PerNDF = 2.*fChi2NDF;
395  NDF = 2;
396  }
397 
398  fFirstChi2->Fill(chi2PerNDF);
399  }
400 
401  // #######################################################
402  // ### If too large then force alternate solution ###
403  // ### - Make n hits from pulse train where n will ###
404  // ### depend on the fhicl parameter fLongPulseWidth ###
405  // ### Also do this if chi^2 is too large ###
406  // #######################################################
407  if (mergedCands.size() > fMaxMultiHit || nGausForFit * chi2PerNDF > fChi2NDF)
408  {
409  int longPulseWidth = fLongPulseWidthVec.at(plane);
410  int nHitsThisPulse = (endT - startT) / longPulseWidth;
411 
412  if (nHitsThisPulse > fLongMaxHitsVec.at(plane))
413  {
414  nHitsThisPulse = fLongMaxHitsVec.at(plane);
415  longPulseWidth = (endT - startT) / nHitsThisPulse;
416  }
417 
418  if (nHitsThisPulse * longPulseWidth < endT - startT) nHitsThisPulse++;
419 
420  int firstTick = startT;
421  int lastTick = firstTick + std::min(endT,longPulseWidth);
422 
423  peakParamsVec.clear();
424  nGausForFit = nHitsThisPulse;
425  NDF = 1.;
426  chi2PerNDF = chi2PerNDF > fChi2NDF ? chi2PerNDF : -1.;
427 
428  for(int hitIdx = 0; hitIdx < nHitsThisPulse; hitIdx++)
429  {
430  // This hit parameters
431  double sumADC = std::accumulate(signal.begin() + firstTick, signal.begin() + lastTick, 0.);
432  double peakSigma = (lastTick - firstTick) / 3.; // Set the width...
433  double peakAmp = 0.3989 * sumADC / peakSigma; // Use gaussian formulation
434  double peakMean = (firstTick + lastTick) / 2.;
435 
436  // Store hit params
438 
439  peakParams.peakCenter = peakMean;
440  peakParams.peakCenterError = 0.1 * peakMean;
441  peakParams.peakSigma = peakSigma;
442  peakParams.peakSigmaError = 0.1 * peakSigma;
443  peakParams.peakAmplitude = peakAmp;
444  peakParams.peakAmplitudeError = 0.1 * peakAmp;
445 
446  peakParamsVec.push_back(peakParams);
447 
448  // set for next loop
449  firstTick = lastTick;
450  lastTick = std::min(lastTick + longPulseWidth, endT);
451  }
452  }
453 
454  // #######################################################
455  // ### Loop through returned peaks and make recob hits ###
456  // #######################################################
457 
458  int numHits(0);
459 
460  // Make a container for what will be the filtered collection
461  std::vector<recob::Hit> filteredHitVec;
462 
463  for(const auto& peakParams : peakParamsVec)
464  {
465  // Extract values for this hit
466  float peakAmp = peakParams.peakAmplitude;
467  float peakMean = peakParams.peakCenter;
468  float peakWidth = peakParams.peakSigma;
469 
470  // Place one bit of protection here
471  if (std::isnan(peakAmp))
472  {
473  std::cout << "**** hit peak amplitude is a nan! Channel: " << channel << ", start tick: " << startT << std::endl;
474  continue;
475  }
476 
477  // Extract errors
478  float peakAmpErr = peakParams.peakAmplitudeError;
479  float peakMeanErr = peakParams.peakCenterError;
480  float peakWidthErr = peakParams.peakSigmaError;
481 
482  // ### Charge ###
483  float charge = chargeFunc(peakMean, peakAmp, peakWidth, fAreaNormsVec[plane],startT,endT);;
484  float chargeErr = std::sqrt(TMath::Pi()) * (peakAmpErr*peakWidthErr + peakWidthErr*peakAmpErr);
485 
486  // ### limits for getting sums
487  std::vector<float>::const_iterator sumStartItr = signal.begin() + startT;
488  std::vector<float>::const_iterator sumEndItr = signal.begin() + endT;
489 
490  // ### Sum of ADC counts
491  double sumADC = std::accumulate(sumStartItr, sumEndItr, 0.);
492 
493  // ok, now create the hit
494  recob::HitCreator hitcreator(*wire, // wire reference
495  wid, // wire ID
496  startT+roiFirstBinTick, // start_tick TODO check
497  endT+roiFirstBinTick, // end_tick TODO check
498  peakWidth, // rms
499  peakMean+roiFirstBinTick, // peak_time
500  peakMeanErr, // sigma_peak_time
501  peakAmp, // peak_amplitude
502  peakAmpErr, // sigma_peak_amplitude
503  charge, // hit_integral
504  chargeErr, // hit_sigma_integral
505  sumADC, // summedADC FIXME
506  nGausForFit, // multiplicity
507  numHits, // local_index TODO check that the order is correct
508  chi2PerNDF, // goodness_of_fit
509  NDF // dof
510  );
511 
512  filteredHitVec.push_back(hitcreator.copy());
513 
514  const recob::Hit hit(hitcreator.move());
515 
516  // This loop will store ALL hits
517  allHitCol.emplace_back(std::move(hit), wire, rawdigits);
518  numHits++;
519  } // <---End loop over gaussians
520 
521  // Should we filter hits?
522  if (filteredHitCol && !filteredHitVec.empty())
523  {
524  // #######################################################################
525  // Is all this sorting really necessary? Would it be faster to just loop
526  // through the hits and perform simple cuts on amplitude and width on a
527  // hit-by-hit basis, either here in the module (using fPulseHeightCuts and
528  // fPulseWidthCuts) or in HitFilterAlg?
529  // #######################################################################
530 
531  // Sort in ascending peak height
532  std::sort(filteredHitVec.begin(),filteredHitVec.end(),[](const auto& left, const auto& right){return left.PeakAmplitude() > right.PeakAmplitude();});
533 
534  // Reject if the first hit fails the PH/wid cuts
535  if (filteredHitVec.front().PeakAmplitude() < fPulseHeightCuts.at(plane) || filteredHitVec.front().RMS() < fPulseWidthCuts.at(plane)) filteredHitVec.clear();
536 
537  // Now check other hits in the snippet
538  if (filteredHitVec.size() > 1)
539  {
540  // The largest pulse height will now be at the front...
541  float largestPH = filteredHitVec.front().PeakAmplitude();
542 
543  // Find where the pulse heights drop below threshold
544  float threshold(fPulseRatioCuts.at(plane));
545 
546  std::vector<recob::Hit>::iterator smallHitItr = std::find_if(filteredHitVec.begin(),filteredHitVec.end(),[largestPH,threshold](const auto& hit){return hit.PeakAmplitude() < 8. && hit.PeakAmplitude() / largestPH < threshold;});
547 
548  // Shrink to fit
549  if (smallHitItr != filteredHitVec.end()) filteredHitVec.resize(std::distance(filteredHitVec.begin(),smallHitItr));
550 
551  // Resort in time order
552  std::sort(filteredHitVec.begin(),filteredHitVec.end(),[](const auto& left, const auto& right){return left.PeakTime() < right.PeakTime();});
553  }
554 
555  // Copy the hits we want to keep to the filtered hit collection
556  for(const auto& filteredHit : filteredHitVec)
557  if (!fHitFilterAlg || fHitFilterAlg->IsGoodHit(filteredHit)) filteredHitCol->emplace_back(filteredHit, wire, rawdigits);
558  }
559 
560  fChi2->Fill(chi2PerNDF);
561 
562  }//<---End loop over merged candidate hits
563 
564  } //<---End looping over ROI's
565 
566  }//<---End looping over all the wires
567 
568 
569  //==================================================================================================
570  // End of the event -- move the hit collection and the associations into the event
571 
572  if ( filteredHitCol ){
573 
574  // If we filtered hits but no instance name was
575  // specified for the "all hits" collection, then
576  // only save the filtered hits to the event
577  if( fAllHitsInstanceName == "" ) {
578  filteredHitCol->put_into(evt);
579 
580  // otherwise, save both
581  } else {
582  filteredHitCol->put_into(evt);
583  allHitCol.put_into(evt);
584  }
585 
586  } else {
587  allHitCol.put_into(evt);
588  }
589 
590  // Keep track of events processed
591  fEventCount++;
592 
593 } // End of produce()
std::vector< double > fAreaNormsVec
factors for converting area to same units as peak height
size_t fMaxMultiHit
maximum hits for multi fit
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
intermediate_table::iterator iterator
std::unique_ptr< HitFilterAlg > fHitFilterAlg
algorithm used to filter out noise hits
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:211
std::vector< float > fPulseRatioCuts
std::vector< HitCandidate_t > HitCandidateVec
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
std::vector< int > fLongMaxHitsVec
Maximum number hits on a really long pulse train.
std::unique_ptr< reco_tool::IPeakFitter > fPeakFitterTool
Perform fit to candidate peaks.
struct PeakFitParams{float peakCenter PeakFitParams_t
Definition: IPeakFitter.h:31
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:24
Class managing the creation of a new recob::Hit object.
Definition: HitCreator.h:84
unsigned int PlaneID_t
Type for the ID number.
Definition: geo_types.h:251
int fAreaMethod
Type of area calculation.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:31
intermediate_table::const_iterator const_iterator
A class handling a collection of hits and its associations.
Definition: HitCreator.h:513
std::vector< float > fPulseWidthCuts
std::vector< int > fLongPulseWidthVec
Sets width of hits used to describe long pulses.
void emplace_back(recob::Hit &&hit, art::Ptr< recob::Wire > const &wire=art::Ptr< recob::Wire >(), art::Ptr< raw::RawDigit > const &digits=art::Ptr< raw::RawDigit >())
Adds the specified hit to the data collection.
Definition: HitCreator.cxx:245
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
void put_into(art::Event &)
Moves the data into an event.
Definition: HitCreator.h:663
Detector simulation of raw signals on wires.
std::vector< PeakFitParams_t > PeakParamsVec
Definition: IPeakFitter.h:39
std::vector< float > fPulseHeightCuts
maximum Chisquared / NDF allowed for a hit to be saved
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Int_t min
Definition: plot.C:26
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
std::vector< HitCandidateVec > MergeHitCandidateVec
std::string fAllHitsInstanceName
Definition: fwd.h:25
std::vector< std::unique_ptr< reco_tool::ICandidateHitFinder > > fHitFinderToolVec
For finding candidate hits.
void hit::GausHitFinder::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 160 of file GausHitFinder_module.cc.

References fAllHitsInstanceName, fAreaMethod, fAreaNormsVec, fCalDataModuleLabel, fChi2NDF, fFilterHits, fHitFilterAlg, fHitFinderToolVec, FillOutHitParameterVector(), fLongMaxHitsVec, fLongPulseWidthVec, fMaxMultiHit, fPeakFitterTool, fPulseHeightCuts, fPulseRatioCuts, fPulseWidthCuts, fTryNplus1Fits, and fhicl::ParameterSet::get().

Referenced by GausHitFinder().

161 {
162  // Implementation of optional member function here.
163  fCalDataModuleLabel = p.get< std::string >("CalDataModuleLabel");
164 
165  fAllHitsInstanceName = p.get< std::string >("AllHitsInstanceName","");
166 
167  fFilterHits = p.get< bool >("FilterHits",false);
168 
169  if (fFilterHits) {
170  if (fHitFilterAlg) { // reconfigure existing algorithm
171  fHitFilterAlg->reconfigure(p.get<fhicl::ParameterSet>("HitFilterAlg"));
172  }
173  else { // create a new algorithm instance
174  fHitFilterAlg = std::make_unique<HitFilterAlg>(p.get<fhicl::ParameterSet>("HitFilterAlg"));
175  }
176  }
177 
178  FillOutHitParameterVector(p.get< std::vector<double> >("AreaNorms"), fAreaNormsVec);
179 
180  fLongMaxHitsVec = p.get< std::vector<int>>("LongMaxHits", std::vector<int>() = {25,25,25});
181  fLongPulseWidthVec = p.get< std::vector<int>>("LongPulseWidth", std::vector<int>() = {16,16,16});
182  fMaxMultiHit = p.get< int >("MaxMultiHit");
183  fAreaMethod = p.get< int >("AreaMethod");
184  fTryNplus1Fits = p.get< bool >("TryNplus1Fits");
185  fChi2NDF = p.get< double >("Chi2NDF");
186 
187  fPulseHeightCuts = p.get< std::vector<float>>("PulseHeightCuts", std::vector<float>() = {3.0, 3.0, 3.0});
188  fPulseWidthCuts = p.get< std::vector<float>>("PulseWidthCuts", std::vector<float>() = {2.0, 1.5, 1.0});
189  fPulseRatioCuts = p.get< std::vector<float>>("PulseRatioCuts", std::vector<float>() = {0.35, 0.40, 0.20});
190 
191  // recover the tool to do the candidate hit finding
192  // Recover the vector of fhicl parameters for the ROI tools
193  const fhicl::ParameterSet& hitFinderTools = p.get<fhicl::ParameterSet>("HitFinderToolVec");
194 
195  fHitFinderToolVec.resize(hitFinderTools.get_pset_names().size());
196 
197  for(const std::string& hitFinderTool : hitFinderTools.get_pset_names())
198  {
199  const fhicl::ParameterSet& hitFinderToolParamSet = hitFinderTools.get<fhicl::ParameterSet>(hitFinderTool);
200  size_t planeIdx = hitFinderToolParamSet.get<size_t>("Plane");
201 
202  fHitFinderToolVec.at(planeIdx) = art::make_tool<reco_tool::ICandidateHitFinder>(hitFinderToolParamSet);
203  }
204 
205  // Recover the peak fitting tool
206  fPeakFitterTool = art::make_tool<reco_tool::IPeakFitter>(p.get<fhicl::ParameterSet>("PeakFitter"));
207 
208  return;
209 }
std::vector< double > fAreaNormsVec
factors for converting area to same units as peak height
size_t fMaxMultiHit
maximum hits for multi fit
std::unique_ptr< HitFilterAlg > fHitFilterAlg
algorithm used to filter out noise hits
std::vector< float > fPulseRatioCuts
std::vector< int > fLongMaxHitsVec
Maximum number hits on a really long pulse train.
std::unique_ptr< reco_tool::IPeakFitter > fPeakFitterTool
Perform fit to candidate peaks.
int fAreaMethod
Type of area calculation.
bool fTryNplus1Fits
whether we will (true) or won&#39;t (false) try n+1 fits
std::vector< float > fPulseWidthCuts
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::vector< int > fLongPulseWidthVec
Sets width of hits used to describe long pulses.
void FillOutHitParameterVector(const std::vector< double > &input, std::vector< double > &output)
std::vector< float > fPulseHeightCuts
maximum Chisquared / NDF allowed for a hit to be saved
std::string fAllHitsInstanceName
std::vector< std::unique_ptr< reco_tool::ICandidateHitFinder > > fHitFinderToolVec
For finding candidate hits.
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Definition at line 125 of file Consumer.cc.

Referenced by art::EDProducer::doEndJob(), art::EDFilter::doEndJob(), art::EDAnalyzer::doEndJob(), and art::RootOutput::endJob().

126 {
127  if (!moduleContext_)
128  return;
129 
130  // If none of the branches have missing consumes statements, exit early.
131  if (std::all_of(cbegin(missingConsumes_),
132  cend(missingConsumes_),
133  [](auto const& perBranch) { return perBranch.empty(); }))
134  return;
135 
136  constexpr cet::HorizontalRule rule{60};
137  mf::LogPrint log{"MTdiagnostics"};
138  log << '\n'
139  << rule('=') << '\n'
140  << "The following consumes (or mayConsume) statements are missing from\n"
141  << module_context(moduleDescription_) << '\n'
142  << rule('-') << '\n';
143 
144  cet::for_all_with_index(
145  missingConsumes_, [&log](std::size_t const i, auto const& perBranch) {
146  for (auto const& pi : perBranch) {
147  log << " "
148  << assemble_consumes_statement(static_cast<BranchType>(i), pi)
149  << '\n';
150  }
151  });
152  log << rule('=');
153 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139
void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Definition at line 101 of file Consumer.cc.

References art::errors::ProductRegistrationFailure.

103 {
104  // Early exits if consumes tracking has been disabled or if the
105  // consumed product is an allowed consumable.
106  if (!moduleContext_)
107  return;
108 
109  if (cet::binary_search_all(consumables_[bt], pi))
110  return;
111 
112  if (requireConsumes_) {
114  "Consumer: an error occurred during validation of a "
115  "retrieved product\n\n")
116  << "The following consumes (or mayConsume) statement is missing from\n"
117  << module_context(moduleDescription_) << ":\n\n"
118  << " " << assemble_consumes_statement(bt, pi) << "\n\n";
119  }
120 
121  missingConsumes_[bt].insert(pi);
122 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
bool requireConsumes_
Definition: Consumer.h:137
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139

Member Data Documentation

std::string hit::GausHitFinder::fAllHitsInstanceName
private

Definition at line 89 of file GausHitFinder_module.cc.

Referenced by GausHitFinder(), produce(), and reconfigure().

int hit::GausHitFinder::fAreaMethod
private

Type of area calculation.

Definition at line 95 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

std::vector<double> hit::GausHitFinder::fAreaNormsVec
private

factors for converting area to same units as peak height

Definition at line 96 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

std::string hit::GausHitFinder::fCalDataModuleLabel
private

Definition at line 87 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

TH1F* hit::GausHitFinder::fChi2
private

Definition at line 111 of file GausHitFinder_module.cc.

Referenced by beginJob(), and produce().

double hit::GausHitFinder::fChi2NDF
private

Definition at line 98 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

size_t hit::GausHitFinder::fEventCount
private

Definition at line 104 of file GausHitFinder_module.cc.

Referenced by produce().

bool hit::GausHitFinder::fFilterHits
private

Definition at line 85 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

TH1F* hit::GausHitFinder::fFirstChi2
private

Definition at line 110 of file GausHitFinder_module.cc.

Referenced by beginJob(), and produce().

std::unique_ptr<HitFilterAlg> hit::GausHitFinder::fHitFilterAlg
private

algorithm used to filter out noise hits

Definition at line 108 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

std::vector<std::unique_ptr<reco_tool::ICandidateHitFinder> > hit::GausHitFinder::fHitFinderToolVec
private

For finding candidate hits.

Definition at line 106 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

std::vector<int> hit::GausHitFinder::fLongMaxHitsVec
private

Maximum number hits on a really long pulse train.

Definition at line 91 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

std::vector<int> hit::GausHitFinder::fLongPulseWidthVec
private

Sets width of hits used to describe long pulses.

Definition at line 92 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

size_t hit::GausHitFinder::fMaxMultiHit
private

maximum hits for multi fit

Definition at line 94 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

std::unique_ptr<reco_tool::IPeakFitter> hit::GausHitFinder::fPeakFitterTool
private

Perform fit to candidate peaks.

Definition at line 107 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

std::vector<float> hit::GausHitFinder::fPulseHeightCuts
private

maximum Chisquared / NDF allowed for a hit to be saved

Definition at line 100 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

std::vector<float> hit::GausHitFinder::fPulseRatioCuts
private

Definition at line 102 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

std::vector<float> hit::GausHitFinder::fPulseWidthCuts
private

Definition at line 101 of file GausHitFinder_module.cc.

Referenced by produce(), and reconfigure().

bool hit::GausHitFinder::fTryNplus1Fits
private

whether we will (true) or won't (false) try n+1 fits

Definition at line 97 of file GausHitFinder_module.cc.

Referenced by reconfigure().


The documentation for this class was generated from the following file: