ProvidedPedestalAdditionService_service.cc
Go to the documentation of this file.
1 // ProvidedPedestalAdditionService.cxx
2 
7 #include "nurandom/RandomUtils/NuRandomService.h"
8 #include "art_root_io/TFileService.h"
9 #include "CLHEP/Random/JamesRandom.h"
10 #include "CLHEP/Random/RandGaussQ.h"
11 #include "TH1F.h"
12 
13 using std::ostream;
14 using std::cout;
15 using std::endl;
16 using std::string;
17 using rndm::NuRandomService;
18 using CLHEP::HepJamesRandom;
19 
20 //**********************************************************************
21 
24 : m_RandomSeed(0), m_LogLevel(1),
25  m_PedNoiseHist(nullptr),
26  m_pran(nullptr),
27  m_PedestalProvider(art::ServiceHandle<lariov::DetPedestalService>()->GetPedestalProvider()) {
28  const string myname = "ProvidedPedestalAdditionService::ctor: ";
29  m_NoiseScale = pset.get<float>("NoiseScale");
30  bool haveSeed = pset.get_if_present<int>("RandomSeed", m_RandomSeed);
31  pset.get_if_present<int>("LogLevel", m_LogLevel);
32  if ( m_RandomSeed == 0 ) haveSeed = false;
33  if ( haveSeed ) {
34  if ( m_LogLevel > 0 ) cout << myname << "WARNING: Using hardwired seed." << endl;
35  m_pran = new HepJamesRandom(m_RandomSeed);
36  } else {
37  string rname = "ProvidedPedestalAdditionService";
38  if ( m_LogLevel > 0 ) cout << myname << "Using NuRandomService." << endl;
40  m_pran = new HepJamesRandom;
41  if ( m_LogLevel > 0 ) cout << myname << " Initial seed: " << m_pran->getSeed() << endl;
42  seedSvc->registerEngine(NuRandomService::CLHEPengineSeeder(m_pran), rname);
43  }
44  if ( m_LogLevel > 0 ) cout << myname << " Registered seed: " << m_pran->getSeed() << endl;
46  m_PedNoiseHist = tfs->make<TH1F>("PedNoise", ";Pedestal noise (ADC);", 1000, -10., 10.);
47 }
48 
49 //**********************************************************************
50 
52  const string myname = "ProvidedPedestalAdditionService::dtor: ";
53  if ( m_LogLevel > 0 ) {
54  cout << myname << "Deleting random engine with seed " << m_pran->getSeed() << endl;
55  }
56  delete m_pran;
57 }
58 
59 //**********************************************************************
60 
62 addPedestal(Channel chan, AdcSignalVector& sigs, float& ped, float& pedrms) const {
63  // Fetch the pedestal for this channel.
64  float ped_mean = m_PedestalProvider.PedMean(chan);
65  float ped_rms = m_PedestalProvider.PedRms(chan);
66  for ( unsigned int itck=0; itck<sigs.size(); ++itck ) {
67  sigs[itck] += ped_mean;
68  }
69  if ( ped_rms > 0 && m_NoiseScale > 0 ) {
70  CLHEP::RandGaussQ rGauss_Ped(*m_pran, 0.0, m_NoiseScale*ped_rms);
71  for ( unsigned int itck=0; itck<sigs.size(); ++itck ) {
72  double ped_variation = rGauss_Ped.fire();
73  m_PedNoiseHist->Fill(ped_variation);
74  sigs[itck] += ped_variation;
75  }
76  }
77  ped = ped_mean;
78  pedrms = ped_rms;
79  return 0;
80 }
81 
82 //**********************************************************************
83 
84 ostream& ProvidedPedestalAdditionService::print(ostream& out, string prefix) const {
85  out << prefix << "ProvidedPedestalAdditionService:" << endl;
86  out << prefix << " Noise scale: " << m_NoiseScale;
87  return out;
88 }
89 
90 //**********************************************************************
91 
93 
94 //**********************************************************************
virtual float PedRms(raw::ChannelID_t ch) const =0
std::string string
Definition: nybbler.cc:12
TH1 * m_PedNoiseHist
Histogram of pedestal noise counts.
virtual std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
const lariov::DetPedestalProvider & m_PedestalProvider
T get(std::string const &key) const
Definition: ParameterSet.h:271
Filters for channels, events, etc.
int addPedestal(Channel chan, AdcSignalVector &sigs, float &ped, float &pedrms) const
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
virtual float PedMean(raw::ChannelID_t ch) const =0
Retrieve pedestal information.
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
ProvidedPedestalAdditionService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
QTextStream & endl(QTextStream &s)
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)